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 { /// /// evento richiesta salvataggio files /// public event EventHandler eh_reqEdit; /// /// logger class /// protected Logger lg = LogManager.GetCurrentClassLogger(); /// /// caricamento pagina /// /// /// 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); } /// /// restituisce il nome di un icona (nel formato nome_icona.png) dal filetype (*.fileType) /// /// /// 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); } /// /// accoda 2 oggetti in un unica stringa /// /// Formato della stringa richiesta (formato x string.format) /// valori comma delimited /// /// public string accoda(object stringFormat, object[] args) { return string.Format(stringFormat.ToString(), args).Replace("//","/"); } /// /// restituisce stringa del path da filesystem completo /// /// /// se true in modalità http (path da webserver) se false path completo da filesystem /// 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; } } /// /// aggiornamento controllo /// public void doUpdate() { try { grView.DataBind(); } catch (Exception exc) { } } /// /// restituisce una stringa di max "maxChar caratteri tenendo gli ultimi lastChar /// /// /// /// 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; } /// /// gestione update ods /// /// /// 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); } /// /// mostro button x sostituzione file /// /// /// 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); } /// /// nascondo button sostituzione file /// /// /// protected void grView_RowUpdated(object sender, GridViewUpdatedEventArgs e) { grView.SelectedIndex = -1; pnlRTUpdate.CssClass = ""; showHideEditRecord(false); } /// /// nascondo button sostituzione file /// /// /// protected void grView_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e) { grView.SelectedIndex = -1; pnlRTUpdate.CssClass = ""; showHideEditRecord(false); } /// /// mostra/nasconde controllo sostituzione file /// /// 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; } } } } /// /// file caricato! effettuo sostituzione! /// /// /// 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(); } /// /// update dei tags selezionati /// /// /// 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 { } } } } /// /// 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 /// /// /// 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; } /// /// formatta protocollo come numero/anno /// /// /// /// public string nrProtoAnno(object numero, object anno) { return string.Format("{0}-{1}", numero, anno); } /// /// "svuota la riga" resettando metadati ed eliminando file... /// /// /// 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(); } /// /// risposta doc a fine editing in nuova directory... /// /// /// 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); } } }