163 lines
5.3 KiB
C#
163 lines
5.3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Web;
|
|
using System.Web.UI;
|
|
using System.Web.UI.WebControls;
|
|
using System.IO;
|
|
using System.Data;
|
|
using System.Data.SqlClient;
|
|
using System.Configuration;
|
|
using CMS_SC_Data;
|
|
using System.Text;
|
|
using SteamWare;
|
|
|
|
namespace CMS_SC.WebUserControls
|
|
{
|
|
public partial class mod_fileUpload : SteamWare.UserControl
|
|
{
|
|
/// <summary>
|
|
/// selezione valore in DettScheda
|
|
/// </summary>
|
|
public event EventHandler eh_fileMod;
|
|
/// <summary>
|
|
/// sollevo evento selezione
|
|
/// </summary>
|
|
protected void raiseEvent()
|
|
{
|
|
// sollevo evento nuovo valore...
|
|
if (eh_fileMod != null)
|
|
{
|
|
eh_fileMod(this, new EventArgs());
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// abilita modifica/cancellazione allegati
|
|
/// </summary>
|
|
public bool enableMod { get; set; }
|
|
/// <summary>
|
|
/// caricamento pagina
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void Page_Load(object sender, EventArgs e)
|
|
{
|
|
this.Page.Form.Enctype = "multipart/form-data";
|
|
fisVisFU(enableMod);
|
|
if (!IsPostBack)
|
|
{
|
|
fisVisFU(false);
|
|
grView.DataBind();
|
|
}
|
|
divNewEdit.Visible = isWriteEnabled && enableMod;
|
|
btnAdd.DataBind();
|
|
}
|
|
/// <summary>
|
|
/// Chiave di filtraggio dati...
|
|
/// </summary>
|
|
public string filtKey
|
|
{
|
|
get
|
|
{
|
|
return hfFiltKey.Value;
|
|
}
|
|
set
|
|
{
|
|
hfFiltKey.Value = value;
|
|
}
|
|
}
|
|
|
|
protected void Upload(object sender, EventArgs e)
|
|
{
|
|
if (FileUploadControl.HasFile)
|
|
{
|
|
string filename = Path.GetFileName(FileUploadControl.PostedFile.FileName);
|
|
string contentType = FileUploadControl.PostedFile.ContentType;
|
|
using (Stream fs = FileUploadControl.PostedFile.InputStream)
|
|
{
|
|
using (BinaryReader br = new BinaryReader(fs))
|
|
{
|
|
byte[] bytes = br.ReadBytes((Int32)fs.Length);
|
|
// PROCEDO SOLO SE HO UN FILE!!!! ovvero bytes <> null
|
|
if (bytes.Length > 0)
|
|
{
|
|
// controllo se sia caricamento o update...
|
|
if (grView.SelectedIndex != -1)
|
|
{
|
|
try
|
|
{
|
|
int orig_idxFile = Convert.ToInt32(grView.SelectedValue);
|
|
DtProxy.man.taFiles.updateQuery(filename, filtKey, contentType, bytes, orig_idxFile);
|
|
}
|
|
catch
|
|
{ }
|
|
}
|
|
else
|
|
{
|
|
DtProxy.man.taFiles.insertQuery(filename, filtKey, contentType, bytes);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
grView.DataBind();
|
|
raiseEvent();
|
|
#if false
|
|
Response.Redirect(Request.Url.AbsoluteUri);
|
|
#endif
|
|
}
|
|
}
|
|
|
|
protected void DownloadFile(object sender, EventArgs e)
|
|
{
|
|
int idxFile = int.Parse((sender as LinkButton).CommandArgument);
|
|
byte[] bytes;
|
|
string fileName, contentType;
|
|
DS_Utility.tblFilesRow fileRow = DtProxy.man.taFiles.getByKey(idxFile)[0];
|
|
bytes = fileRow.Data;
|
|
contentType = fileRow.ContentType;
|
|
fileName = fileRow.FileName;
|
|
Response.Clear();
|
|
Response.Buffer = true;
|
|
Response.Charset = "";
|
|
Response.Cache.SetCacheability(HttpCacheability.NoCache);
|
|
Response.ContentType = contentType;
|
|
Response.AppendHeader("Content-Disposition", "attachment; filename=" + fileName);
|
|
Response.BinaryWrite(bytes);
|
|
Response.Flush();
|
|
Response.End();
|
|
}
|
|
|
|
protected void grView_SelectedIndexChanged(object sender, EventArgs e)
|
|
{
|
|
// mostro controllo x edit...
|
|
fisVisFU(true);
|
|
btnUpload.Text = "Sostituisci File";
|
|
}
|
|
|
|
protected void btnAdd_Click(object sender, EventArgs e)
|
|
{
|
|
fisVisFU(true);
|
|
btnUpload.Text = "Carica Nuovo File";
|
|
}
|
|
/// <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;
|
|
if (grView.SelectedIndex != -1 && !showAdd)
|
|
{
|
|
grView.SelectedIndex = -1;
|
|
}
|
|
}
|
|
|
|
protected void btnCancel_Click(object sender, EventArgs e)
|
|
{
|
|
fisVisFU(false);
|
|
}
|
|
|
|
}
|
|
} |