149 lines
3.8 KiB
C#
149 lines
3.8 KiB
C#
using AppData;
|
|
using SteamWare;
|
|
using System;
|
|
using System.IO;
|
|
using System.Web;
|
|
using System.Web.UI.WebControls;
|
|
|
|
namespace NKC_WF.WebUserContols
|
|
{
|
|
public partial class cmp_fileUpload : System.Web.UI.UserControl
|
|
{
|
|
public event EventHandler eh_doRefresh;
|
|
/// <summary>
|
|
/// Wrapper traduzione termini
|
|
/// </summary>
|
|
/// <param name="lemma"></param>
|
|
/// <returns></returns>
|
|
public string traduci(string lemma)
|
|
{
|
|
return user_std.UtSn.Traduci(lemma);
|
|
}
|
|
|
|
#if false
|
|
public int idxRichiesta
|
|
{
|
|
get
|
|
{
|
|
int answ = 0;
|
|
int.TryParse(Request.QueryString["idxRichiesta"], out answ);
|
|
return answ;
|
|
}
|
|
}
|
|
public string filtroRich
|
|
{
|
|
get
|
|
{
|
|
string answ = "###";
|
|
if (idxRichiesta > 0) answ = idxRichiesta.ToString();
|
|
return answ;
|
|
}
|
|
}
|
|
#endif
|
|
/// <summary>
|
|
/// permesso scrittura SE E' abilitato a aprtire dalla tab diritti...
|
|
/// </summary>
|
|
public bool userIsAuth
|
|
{
|
|
get
|
|
{
|
|
return true;
|
|
//return (idxAmm + idxFornitore > 0);
|
|
}
|
|
}
|
|
public bool isWriteEnabled
|
|
{
|
|
get
|
|
{
|
|
bool answ = false;
|
|
bool.TryParse(hfWriteEnabled.Value, out answ);
|
|
return answ;
|
|
}
|
|
set
|
|
{
|
|
hfWriteEnabled.Value = value.ToString();
|
|
}
|
|
}
|
|
protected void Page_Load(object sender, EventArgs e)
|
|
{
|
|
if (!IsPostBack)
|
|
{
|
|
fisVisFU(false);
|
|
deleteOldFiles();
|
|
}
|
|
divNewEdit.Visible = userIsAuth && isWriteEnabled;
|
|
}
|
|
/// <summary>
|
|
/// Procedee a bonificare la cartella di upload dei files + vecchi di 3 mesi
|
|
/// </summary>
|
|
private void deleteOldFiles()
|
|
{
|
|
string dirPath = Server.MapPath("/FileUpload");
|
|
// elenco files nella directory
|
|
string[] files = Directory.GetFiles(dirPath);
|
|
// li guardo tutti e se vecchi li elimino...
|
|
foreach (string file in files)
|
|
{
|
|
FileInfo fi = new FileInfo(file);
|
|
if (fi.LastAccessTime < DateTime.Now.AddMonths(-3))
|
|
fi.Delete();
|
|
}
|
|
}
|
|
|
|
protected void Upload(object sender, EventArgs e)
|
|
{
|
|
// se c'è un file
|
|
if (FileUpload1.PostedFile != null)
|
|
{
|
|
string uploadedFilename = Path.GetFileName(FileUpload1.PostedFile.FileName);
|
|
string savedFilename = Server.MapPath($"/FileUpload/{DateTime.Now.ToString("yyyy-MM-dd")}_{uploadedFilename}");
|
|
string contentType = FileUpload1.PostedFile.ContentType;
|
|
// accedo allo stream del file allegato
|
|
using (Stream fs = FileUpload1.PostedFile.InputStream)
|
|
{
|
|
// scrivo su file
|
|
FileStream file = new FileStream(savedFilename, FileMode.Create, FileAccess.Write);
|
|
fs.CopyTo(file);
|
|
file.Close();
|
|
// chiamo procedura SQL x import... !!!FIXME!!!
|
|
|
|
|
|
// !!!HARD CODED!!!
|
|
int batchID = 2;
|
|
// alla fine ottengo da SQL un BatchID univoco... salvo in SESSIONE!!!
|
|
memLayer.ML.setSessionVal("batchID", batchID);
|
|
// se qualcuno ascolta sollevo evento nuovo valore...
|
|
if (eh_doRefresh != null)
|
|
{
|
|
eh_doRefresh(this, new EventArgs());
|
|
}
|
|
}
|
|
}
|
|
Response.Redirect(Request.RawUrl);
|
|
}
|
|
|
|
|
|
|
|
protected void btnAdd_Click(object sender, EventArgs e)
|
|
{
|
|
fisVisFU(true);
|
|
btnUpload.Text = "Carica Nuovo";
|
|
}
|
|
/// <summary>
|
|
/// fix visibilità controllo file upload
|
|
/// </summary>
|
|
/// <param name="showAdd">mostra controlli add=true oppure nasconde = false</param>
|
|
private void fisVisFU(bool showAdd)
|
|
{
|
|
divFileUpl.Visible = showAdd;
|
|
btnAdd.Visible = !showAdd;
|
|
btnCancel.Visible = showAdd;
|
|
}
|
|
|
|
protected void btnCancel_Click(object sender, EventArgs e)
|
|
{
|
|
fisVisFU(false);
|
|
}
|
|
|
|
}
|
|
} |