410 lines
15 KiB
C#
410 lines
15 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Web;
|
|
using System.Web.UI;
|
|
using System.Web.UI.WebControls;
|
|
using ETS_Data;
|
|
using NLog;
|
|
|
|
namespace ETS_WS.WebUserControls
|
|
{
|
|
public partial class mod_archivioDocumenti : System.Web.UI.UserControl
|
|
{
|
|
/// <summary>
|
|
/// evento richiesta salvataggio files
|
|
/// </summary>
|
|
public event EventHandler eh_reqEdit;
|
|
/// <summary>
|
|
/// logger class
|
|
/// </summary>
|
|
protected Logger lg = LogManager.GetCurrentClassLogger();
|
|
/// <summary>
|
|
/// caricamento pagina
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void Page_Load(object sender, EventArgs e)
|
|
{
|
|
if (!Page.IsPostBack)
|
|
{
|
|
showHideEditRecord(false);
|
|
bool showRed = WebShipUtils.mng.userCanSeeRed;
|
|
utils.obj.setSessionVal("showRed", showRed);
|
|
}
|
|
mod_singleFileUpload1.tempArea = WebShipUtils.mng.UserTempPath;
|
|
mod_singleFileUpload1.eh_fileUploaded += new EventHandler(mod_singleFileUpload1_eh_fileUploaded);
|
|
}
|
|
/// <summary>
|
|
/// restituisce il nome di un icona (nel formato nome_icona.png) dal filetype (*.fileType)
|
|
/// </summary>
|
|
/// <param name="nome"></param>
|
|
/// <returns></returns>
|
|
public string imgFromName(object nome)
|
|
{
|
|
string answ = "undef.png";
|
|
string tipo = "";
|
|
int posPunto = -1;
|
|
try
|
|
{
|
|
tipo = nome.ToString();
|
|
posPunto = tipo.LastIndexOf(".");
|
|
tipo = tipo.Substring(posPunto, tipo.Length - posPunto).Replace(".", "");
|
|
// ora faccio switch x "raggruppare" tipo di files
|
|
switch (tipo)
|
|
{
|
|
case "jpg":
|
|
case "png":
|
|
case "tif":
|
|
case "gif":
|
|
tipo = "image";
|
|
break;
|
|
case "txt":
|
|
case "doc":
|
|
case "rtf":
|
|
case "docx":
|
|
case "odt":
|
|
case "xls":
|
|
case "xlsx":
|
|
case "ods":
|
|
case "ppt":
|
|
case "pptx":
|
|
case "odx":
|
|
tipo = "office";
|
|
break;
|
|
case "zip":
|
|
case "rar":
|
|
case "7zip":
|
|
case "gz":
|
|
case "tgz":
|
|
tipo = "compress";
|
|
break;
|
|
case "avi":
|
|
case "divx":
|
|
case "xvid":
|
|
tipo = "video";
|
|
break;
|
|
case "eml":
|
|
tipo = "email";
|
|
break;
|
|
case "exe":
|
|
case "msi":
|
|
tipo = "program";
|
|
break;
|
|
case "pdf":
|
|
case "eps":
|
|
tipo = "pdf";
|
|
break;
|
|
default:
|
|
tipo = "unknown";
|
|
break;
|
|
}
|
|
answ = string.Format("{0}.png", tipo);
|
|
}
|
|
catch
|
|
{ }
|
|
return string.Format(@"~\images\{0}", answ);
|
|
}
|
|
/// <summary>
|
|
/// accoda 2 oggetti in un unica stringa
|
|
/// </summary>
|
|
/// <param name="stringFormat">Formato della stringa richiesta (formato x string.format)</param>
|
|
/// <param name="args">valori comma delimited</param>
|
|
/// <param name="obj2"></param>
|
|
/// <returns></returns>
|
|
public string accoda(object stringFormat, object[] args)
|
|
{
|
|
return string.Format(stringFormat.ToString(), args).Replace("//","/");
|
|
}
|
|
/// <summary>
|
|
/// restituisce stringa del path da filesystem completo
|
|
/// </summary>
|
|
/// <param name="fullPath"></param>
|
|
/// <param name="httpMode">se true in modalità http (path da webserver) se false path completo da filesystem</param>
|
|
/// <returns></returns>
|
|
public string filePath(object fullPath, object httpMode)
|
|
{
|
|
string answ = "";
|
|
if (Convert.ToBoolean(httpMode))
|
|
{
|
|
answ = string.Format("{0}", fullPath.ToString());
|
|
}
|
|
else
|
|
{
|
|
answ = string.Format("{0}", Server.MapPath(fullPath.ToString()));
|
|
}
|
|
return answ;
|
|
}
|
|
public int pageSize
|
|
{
|
|
set
|
|
{
|
|
grView.PageSize = value;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// aggiornamento controllo
|
|
/// </summary>
|
|
public void doUpdate()
|
|
{
|
|
try
|
|
{
|
|
grView.DataBind();
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// restituisce una stringa di max "maxChar caratteri tenendo gli ultimi lastChar
|
|
/// </summary>
|
|
/// <param name="stringa"></param>
|
|
/// <param name="maxChar"></param>
|
|
/// <returns></returns>
|
|
public string shortMe(object _strOrig, object _maxChar, object _lastChar)
|
|
{
|
|
string answ = _strOrig.ToString();
|
|
int maxChar = Convert.ToInt32(_maxChar);
|
|
int lastChar = Convert.ToInt32(_lastChar);
|
|
if (answ.Length > maxChar)
|
|
{
|
|
answ = answ.Substring(0, maxChar - lastChar) + "..." + answ.Substring(answ.Length - lastChar);
|
|
}
|
|
return answ;
|
|
}
|
|
/// <summary>
|
|
/// gestione update ods
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void ods_Updating(object sender, ObjectDataSourceMethodEventArgs e)
|
|
{
|
|
// completo set di parametri x update...
|
|
e.InputParameters["userId"] = utils.obj.currUserAD;
|
|
// calcolo dati commessa
|
|
string commessa = e.InputParameters["Commessa"].ToString();
|
|
e.InputParameters["NumeroCommessa"] = commessa.Substring(0, commessa.IndexOf("-"));
|
|
e.InputParameters["AnnoCommessa"] = commessa.Substring(commessa.IndexOf("-") + 1);
|
|
// tolgo commessa che non c'è su query
|
|
e.InputParameters.Remove("Commessa");
|
|
// carico altri valori x avere metadati x calcoli successivi
|
|
string Fase = e.InputParameters["Fase"].ToString();
|
|
string Fonte = e.InputParameters["Fonte"].ToString();
|
|
string InOut = e.InputParameters["InOut"].ToString();
|
|
string Oggetto = e.InputParameters["Oggetto"].ToString();
|
|
bool isRed = Convert.ToBoolean(e.InputParameters["isRed"]);
|
|
// ricalcolo il path!
|
|
int idxFile = -1;
|
|
try
|
|
{
|
|
idxFile = Convert.ToInt32(e.InputParameters["Original_idxFile"]);
|
|
}
|
|
catch
|
|
{ }
|
|
docMetaDataSet answ = WebShipUtils.mng.docMetaFromIdxFile(idxFile);
|
|
// aggiorno valori metadati x calcolare nuovo path
|
|
answ.commessa = commessa;
|
|
answ.fase = Fase;
|
|
answ.fonte = Fonte;
|
|
answ.InOut = InOut;
|
|
answ.oggetto = Oggetto;
|
|
answ.isRed = isRed;
|
|
// calcolo la NUOVA directory
|
|
string newPath = WebShipUtils.path(answ);
|
|
if (isRed)
|
|
{
|
|
newPath = string.Format("{0}{1}", utils.obj.confReadString("archiveDirRed"), newPath);
|
|
}
|
|
else
|
|
{
|
|
newPath = string.Format("{0}{1}", utils.obj.confReadString("archiveDir"), newPath);
|
|
}
|
|
// sposto file a nuova dest...
|
|
fileMover.obj.muoviFile(WebShipUtils.pathFromIdxFile(WebShipUtils.mng.idxFileEdit), WebShipUtils.mng.UserTempPath, WebShipUtils.nomeFileFullFromIdxFile(WebShipUtils.mng.idxFileEdit), WebShipUtils.nomeFileFromIdxFile(WebShipUtils.mng.idxFileEdit), true);
|
|
// ora aggiorno PATH del file
|
|
utils.obj.taDoc.updateFile(idxFile, utils.obj.currUserAD, WebShipUtils.nomeFileFromIdxFile(idxFile), newPath);
|
|
}
|
|
/// <summary>
|
|
/// mostro button x sostituzione file
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void grView_RowEditing(object sender, GridViewEditEventArgs e)
|
|
{
|
|
// fix riga in edit...
|
|
grView.SelectedIndex = e.NewEditIndex;
|
|
pnlRTUpdate.CssClass = "rltUpdate";
|
|
WebShipUtils.mng.idxFileEdit = Convert.ToInt32(grView.SelectedDataKey["idxFile"]);
|
|
// fix btn cambio file
|
|
showHideEditRecord(true);
|
|
}
|
|
/// <summary>
|
|
/// nascondo button sostituzione file
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void grView_RowUpdated(object sender, GridViewUpdatedEventArgs e)
|
|
{
|
|
grView.SelectedIndex = -1;
|
|
pnlRTUpdate.CssClass = "";
|
|
showHideEditRecord(false);
|
|
}
|
|
/// <summary>
|
|
/// nascondo button sostituzione file
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void grView_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
|
|
{
|
|
grView.SelectedIndex = -1;
|
|
pnlRTUpdate.CssClass = "";
|
|
showHideEditRecord(false);
|
|
}
|
|
/// <summary>
|
|
/// mostra/nasconde controllo sostituzione file
|
|
/// </summary>
|
|
/// <param name="p"></param>
|
|
private void showHideEditRecord(bool p)
|
|
{
|
|
mod_singleFileUpload1.btnEnabled = p;
|
|
cblTags.Visible = p;
|
|
if (p)
|
|
{
|
|
docMetaDataSet currData = WebShipUtils.mng.docMetaFromIdxFile(WebShipUtils.mng.idxFileEdit);
|
|
// calcolo i tags "da accendere"...
|
|
if (currData.tags.Count > 0)
|
|
{
|
|
cblTags.DataBind();
|
|
foreach (string tag in currData.tags)
|
|
{
|
|
cblTags.Items.FindByValue(tag).Selected = true;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// file caricato! effettuo sostituzione!
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
void mod_singleFileUpload1_eh_fileUploaded(object sender, EventArgs e)
|
|
{
|
|
// setto selezione=edit
|
|
grView.SelectedIndex = grView.EditIndex;
|
|
WebShipUtils.mng.idxFileEdit = Convert.ToInt32(grView.SelectedDataKey["idxFile"]);
|
|
string nomeFile = mod_singleFileUpload1.newFileName;
|
|
WebShipUtils.mng.aggiornaFileArchiviato(nomeFile);
|
|
// update gridview!
|
|
grView.DataBind();
|
|
}
|
|
/// <summary>
|
|
/// update dei tags selezionati
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void cblTags_SelectedIndexChanged(object sender, EventArgs e)
|
|
{
|
|
// elimino i tags "vecchi"
|
|
utils.obj.taTags2Doc.deleteByIdxFile(WebShipUtils.mng.idxFileEdit);
|
|
// salvo nuovi tags associati
|
|
foreach (ListItem tag in cblTags.Items)
|
|
{
|
|
if (tag.Selected)
|
|
{
|
|
try
|
|
{
|
|
utils.obj.taTags2Doc.Insert(WebShipUtils.mng.idxFileEdit, Convert.ToInt32(tag.Value));
|
|
}
|
|
catch
|
|
{ }
|
|
}
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// calcola la visibilità del button di edit dati
|
|
/// - utente corrente (e quindi suoi diritti red/non red)
|
|
/// - ruoli utente (user/poweruser) x cui può editare solo i suoi o tutti
|
|
/// </summary>
|
|
/// <param name="idxFile"></param>
|
|
/// <returns></returns>
|
|
public bool showEditButton(object _idxFile)
|
|
{
|
|
bool answ = false;
|
|
int idxFile = 0;
|
|
try
|
|
{
|
|
idxFile = Convert.ToInt32(_idxFile);
|
|
}
|
|
catch
|
|
{ }
|
|
if (idxFile > 0)
|
|
{
|
|
// controllo condizioni: in primis è lui che ha creato record
|
|
if (WebShipUtils.redattoreFromIdxFile(idxFile) == utils.obj.currUserNomeCognome)
|
|
{
|
|
answ = true;
|
|
}
|
|
else
|
|
{
|
|
// se non è lui controllo se sia record Red
|
|
if (WebShipUtils.isRedFromIdxFile(idxFile)) // è record Red
|
|
{
|
|
// controllo se sia powerUserRed
|
|
answ = WebShipUtils.mng.userIsPowerUserRed;
|
|
}
|
|
else // non è record Red
|
|
{
|
|
// controllo se sia powerUser
|
|
answ = WebShipUtils.mng.userIsPowerUser;
|
|
}
|
|
}
|
|
}
|
|
return answ;
|
|
}
|
|
/// <summary>
|
|
/// formatta protocollo come numero/anno
|
|
/// </summary>
|
|
/// <param name="numero"></param>
|
|
/// <param name="anno"></param>
|
|
/// <returns></returns>
|
|
public string nrProtoAnno(object numero, object anno)
|
|
{
|
|
return string.Format("{0}-{1}", numero, anno);
|
|
}
|
|
/// <summary>
|
|
/// "svuota la riga" resettando metadati ed eliminando file...
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void imgSvuota_Click(object sender, EventArgs e)
|
|
{
|
|
// salvo
|
|
ImageButton lbtn = (ImageButton)sender;
|
|
int idxFile = 0;
|
|
try
|
|
{
|
|
idxFile = Convert.ToInt32(lbtn.CommandArgument);
|
|
}
|
|
catch
|
|
{ }
|
|
// svuoto metadati ed elimino file...
|
|
WebShipUtils.mng.deleteRecordAndFile(idxFile);
|
|
// chiudo edit...
|
|
pnlRTUpdate.CssClass = "";
|
|
showHideEditRecord(false);
|
|
grView.EditIndex = -1;
|
|
grView.DataBind();
|
|
}
|
|
/// <summary>
|
|
/// risposta doc a fine editing in nuova directory...
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void ods_Updated(object sender, ObjectDataSourceStatusEventArgs e)
|
|
{
|
|
// risposto file da area temp ad area corretta
|
|
fileMover.obj.muoviFile(WebShipUtils.mng.UserTempPath, WebShipUtils.pathFromIdxFile(WebShipUtils.mng.idxFileEdit), WebShipUtils.nomeFileFromIdxFile(WebShipUtils.mng.idxFileEdit), WebShipUtils.nomeFileFullFromIdxFile(WebShipUtils.mng.idxFileEdit), true);
|
|
}
|
|
}
|
|
} |