diff --git a/ETS-WS/ETS-WS/DocTemplates/ETS-Fax.docx b/ETS-WS/ETS-WS/DocTemplates/ETS-Fax.docx new file mode 100644 index 0000000..ca52986 Binary files /dev/null and b/ETS-WS/ETS-WS/DocTemplates/ETS-Fax.docx differ diff --git a/ETS-WS/ETS-WS/DocTemplates/ETS-Lettera.docx b/ETS-WS/ETS-WS/DocTemplates/ETS-Lettera.docx new file mode 100644 index 0000000..dd2cd90 Binary files /dev/null and b/ETS-WS/ETS-WS/DocTemplates/ETS-Lettera.docx differ diff --git a/ETS-WS/ETS-WS/DocTemplates/ETS-Proto.docx b/ETS-WS/ETS-WS/DocTemplates/ETS-Proto.docx new file mode 100644 index 0000000..ccee374 Binary files /dev/null and b/ETS-WS/ETS-WS/DocTemplates/ETS-Proto.docx differ diff --git a/ETS-WS/ETS-WS/DocTemplates/Proto.txt b/ETS-WS/ETS-WS/DocTemplates/Proto.txt new file mode 100644 index 0000000..5f28270 --- /dev/null +++ b/ETS-WS/ETS-WS/DocTemplates/Proto.txt @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/ETS-WS/ETS-WS/ETS-WS.csproj b/ETS-WS/ETS-WS/ETS-WS.csproj index 2cf981d..6100098 100644 --- a/ETS-WS/ETS-WS/ETS-WS.csproj +++ b/ETS-WS/ETS-WS/ETS-WS.csproj @@ -158,6 +158,7 @@ + @@ -653,6 +654,9 @@ Always + + + diff --git a/ETS-WS/ETS-WS/Web.config b/ETS-WS/ETS-WS/Web.config index 16e8f01..4fe7f14 100644 --- a/ETS-WS/ETS-WS/Web.config +++ b/ETS-WS/ETS-WS/Web.config @@ -28,7 +28,7 @@ - + diff --git a/ETS-WS/ETS-WS/WebShipUtils.cs b/ETS-WS/ETS-WS/WebShipUtils.cs index 2bba66e..6177b37 100644 --- a/ETS-WS/ETS-WS/WebShipUtils.cs +++ b/ETS-WS/ETS-WS/WebShipUtils.cs @@ -182,7 +182,7 @@ namespace ETS_WS /// /// /// - public string nomeFileFromIdxFile(int idxFile) + public static string nomeFileFromIdxFile(int idxFile) { string answ = ""; try @@ -193,6 +193,117 @@ namespace ETS_WS { } return answ; } + /// + /// nome del file da idx DB + /// + /// + /// + public static string nomeFileFullFromIdxFile(int idxFile) + { + string answ = ""; + try + { + answ = utils.obj.taDoc.getByIdxFile(idxFile)[0].Nome; + } + catch + { } + return answ; + } + /// + /// protocollo del file da idx DB + /// + /// + /// + public static string protocolloFromIdxFile(int idxFile) + { + string answ = ""; + try + { + answ = string.Format("{0}-{1}", utils.obj.taDoc.getByIdxFile(idxFile)[0].Numero, utils.obj.taDoc.getByIdxFile(idxFile)[0].Anno); + } + catch + { } + return answ; + } + + /// + /// effettua operazione di archiviazione file + /// + /// oggetto metadati documento + /// path origine del file + /// path di destinazione del file + /// nome del file da archiviare + /// redattore + /// restituisce valore INT del nuovo file archiviato + public static int archiviaFile(docMetaDataSet docsData, string pathOrig, string pathDest, string nomeFile, string redattore) + { + int answ = 0; + string autore = ""; // tolto! + string numComm = ""; + string annoComm = ""; + // ricavo num ed anno commessa... + try + { + numComm = docsData.commessa.Substring(0, docsData.commessa.IndexOf("-")); + annoComm = docsData.commessa.Substring(docsData.commessa.IndexOf("-") + 1); + } + catch + { } + // salvo su db le info del file... + int? newIdxFile = 0; + utils.obj.taDoc.insertQuery(nomeFile, pathDest, utils.obj.currUserAD, docsData.reqProto, docsData.dataRic, docsData.dataDoc, numComm, annoComm, docsData.fase, docsData.fonte, docsData.oggetto, docsData.InOut, autore, redattore, docsData.isRed, ref newIdxFile); + // salvo i tags! + if (newIdxFile > 0) + { + // se ho tags... + if (docsData.tags.Count > 0) + { + foreach (string tag in docsData.tags) + { + try + { + utils.obj.taTags2Doc.Insert((int)newIdxFile, Convert.ToInt32(tag)); + } + catch + { } + } + } + answ = (int)newIdxFile; + } + // ricalcolo nome file + string newFileName = WebShipUtils.nomeFileFullFromIdxFile((int)newIdxFile); + // sposto file + fileMover.obj.muoviFile(pathOrig, pathDest, nomeFile, newFileName, true); + // restituisco idxFile... + return answ; + } + /// + /// aggiorna file archiviato (prendendo da temp utente!) + /// + /// + public void aggiornaFileArchiviato(string nomeFile) + { + lg.Info("Caricato file {0} per sostituzione", nomeFile); + int idxFile = WebShipUtils.mng.idxFileEdit; + // effettuo operazioni sostituzione file! + docMetaDataSet docsData = WebShipUtils.mng.docMetaFromIdxFile(idxFile); + string path = docsData.path; + if (path != "") + { + // calcolo path + path = string.Format("{0}{1}", utils.obj.confReadString("archiveDir"), docsData.path); + // elimino file vecchio + fileMover.obj.eliminaFile(path, WebShipUtils.nomeFileFullFromIdxFile(idxFile)); + // aggiorno su DB + utils.obj.taDoc.updateFile(idxFile, utils.obj.currUserAD, nomeFile, path); + lg.Info("Aggiornato in db nome file {0} per sostituzione", nomeFile); + // ricalcolo nome file + string newFileName = WebShipUtils.nomeFileFullFromIdxFile(idxFile); + // sposto file + fileMover.obj.muoviFile(WebShipUtils.mng.UserTempPath, path, nomeFile, newFileName, true); + lg.Info("Spostato file {0} per sostituzione", nomeFile); + } + } } /// diff --git a/ETS-WS/ETS-WS/WebUserControls/mod_archivioDocumenti.ascx.cs b/ETS-WS/ETS-WS/WebUserControls/mod_archivioDocumenti.ascx.cs index 639a587..0c6ae5f 100644 --- a/ETS-WS/ETS-WS/WebUserControls/mod_archivioDocumenti.ascx.cs +++ b/ETS-WS/ETS-WS/WebUserControls/mod_archivioDocumenti.ascx.cs @@ -244,26 +244,11 @@ namespace ETS_WS.WebUserControls grView.SelectedIndex = grView.EditIndex; WebShipUtils.mng.idxFileEdit = Convert.ToInt32(grView.SelectedDataKey["idxFile"]); string nomeFile = mod_singleFileUpload1.newFileName; - lg.Info("Caricato file {0} per sostituzione", nomeFile); - int idxFile = WebShipUtils.mng.idxFileEdit; - // effettuo operazioni sostituzione file! - docMetaDataSet docsData = WebShipUtils.mng.docMetaFromIdxFile(idxFile); - string path = docsData.path; - if (path != "") - { - // calcolo path - path = string.Format("{0}{1}", utils.obj.confReadString("archiveDir"), docsData.path); - // elimino file vecchio - fileMover.obj.eliminaFile(path, WebShipUtils.mng.nomeFileFromIdxFile(idxFile)); - // sposto file - fileMover.obj.muoviFile(WebShipUtils.mng.UserTempPath, path, nomeFile); - lg.Info("Spostato file {0} per sostituzione", nomeFile); - // aggiorno su DB - utils.obj.taDoc.updateFile(WebShipUtils.mng.idxFileEdit, utils.obj.currUserAD, nomeFile, path); - lg.Info("Aggiornato in db nome file {0} per sostituzione", nomeFile); - // update gridview! - grView.DataBind(); - } + WebShipUtils.mng.aggiornaFileArchiviato(nomeFile); + // update gridview! + grView.DataBind(); } + + } } \ No newline at end of file diff --git a/ETS-WS/ETS-WS/WebUserControls/mod_inputDati.ascx.cs b/ETS-WS/ETS-WS/WebUserControls/mod_inputDati.ascx.cs index db7f1f2..a44377b 100644 --- a/ETS-WS/ETS-WS/WebUserControls/mod_inputDati.ascx.cs +++ b/ETS-WS/ETS-WS/WebUserControls/mod_inputDati.ascx.cs @@ -80,7 +80,7 @@ namespace ETS_WS.WebUserControls /// protected void rblProto_SelectedIndexChanged(object sender, EventArgs e) { - showProto(); + updateVisual(); } /// /// controlla visualizzazione protocollo @@ -153,7 +153,7 @@ namespace ETS_WS.WebUserControls // popolo! try { - answ.reqProto = Convert.ToBoolean(rblInOut.SelectedValue); + answ.reqProto = Convert.ToBoolean(rblProto.SelectedValue); } catch { diff --git a/ETS-WS/ETS-WS/WebUserControls/mod_myTempFile.ascx.cs b/ETS-WS/ETS-WS/WebUserControls/mod_myTempFile.ascx.cs index e9d7e7a..33eb6f7 100644 --- a/ETS-WS/ETS-WS/WebUserControls/mod_myTempFile.ascx.cs +++ b/ETS-WS/ETS-WS/WebUserControls/mod_myTempFile.ascx.cs @@ -200,19 +200,16 @@ namespace ETS_WS.WebUserControls // recupero metadati da sessione... docMetaDataSet docsData = WebShipUtils.mng.currMetaData; //check del path - string path = docsData.path; + string pathDest = docsData.path; // verifico path presente - if (path != "") + if (pathDest != "") { // aggiunto al path cartella archivio... - path = string.Format("{0}{1}", utils.obj.confReadString("archiveDir"), docsData.path); + pathDest = string.Format("{0}{1}", utils.obj.confReadString("archiveDir"), docsData.path); // verifico path valido o creo... - fileMover.checkDir(path); + fileMover.checkDir(pathDest); string nomeFile = ""; - string autore = ""; // tolto! string redattore = utils.obj.currUserCognomeNome; // usa utente corrente - string numComm = ""; - string annoComm = ""; // sposto i files selezionati secondo i dati in sessione foreach (GridViewRow riga in grView.Rows) { @@ -220,36 +217,7 @@ namespace ETS_WS.WebUserControls { // devo salvare file con le info relative... nomeFile = ((HyperLink)riga.FindControl("hlNome")).Text; - // ricavo num ed anno commessa... - try - { - numComm = docsData.commessa.Substring(0, docsData.commessa.IndexOf("-")); - annoComm = docsData.commessa.Substring(docsData.commessa.IndexOf("-") + 1); - } - catch - { } - // salvo su db le info del file... - int? newIdxFile = 0; - utils.obj.taDoc.insertQuery(nomeFile, path, utils.obj.currUserAD, docsData.reqProto, docsData.dataRic, docsData.dataDoc, numComm, annoComm, docsData.fase, docsData.fonte, docsData.oggetto, docsData.InOut, autore, redattore, docsData.isRed, ref newIdxFile); - // salvo i tags! - if (newIdxFile > 0) - { - // se ho tags... - if (docsData.tags.Count > 0) - { - foreach (string tag in docsData.tags) - { - try - { - utils.obj.taTags2Doc.Insert((int)newIdxFile, Convert.ToInt32(tag)); - } - catch - { } - } - } - } - // sposto il file! - fileMover.obj.muoviFile(WebShipUtils.mng.UserTempPath, path, nomeFile); + WebShipUtils.archiviaFile(docsData, WebShipUtils.mng.UserTempPath, pathDest, nomeFile, redattore); } } } diff --git a/ETS-WS/ETS-WS/WebUserControls/mod_pathAndDocs.ascx b/ETS-WS/ETS-WS/WebUserControls/mod_pathAndDocs.ascx index b7b4498..218910c 100644 --- a/ETS-WS/ETS-WS/WebUserControls/mod_pathAndDocs.ascx +++ b/ETS-WS/ETS-WS/WebUserControls/mod_pathAndDocs.ascx @@ -22,12 +22,14 @@
- generatore:   - -   - -   - -   - + + generatore protocolli:   + +   + +   + +   + +
diff --git a/ETS-WS/ETS-WS/WebUserControls/mod_pathAndDocs.ascx.cs b/ETS-WS/ETS-WS/WebUserControls/mod_pathAndDocs.ascx.cs index 7a01905..802740c 100644 --- a/ETS-WS/ETS-WS/WebUserControls/mod_pathAndDocs.ascx.cs +++ b/ETS-WS/ETS-WS/WebUserControls/mod_pathAndDocs.ascx.cs @@ -33,6 +33,8 @@ namespace ETS_WS.WebUserControls lblFullPath.Text = WebShipUtils.mng.path(WebShipUtils.mng.currMetaData); // verifico attivazione button submin (ovvero ci sono tutti i valori...) btnSubmit.Visible = WebShipUtils.mng.metaPresent; + // mostro gen protocolli SE ho richiesta di generare protocollo + pnlGenDocs.Visible = (WebShipUtils.mng.metaPresent && WebShipUtils.mng.currMetaData.reqProto); } /// /// richiesta update @@ -69,7 +71,30 @@ namespace ETS_WS.WebUserControls /// protected void btnStaccaProto_Click(object sender, EventArgs e) { - + // effettua upload del documento "dummy" proto + string nomeFile = "ETS-Proto.docx"; + fileMover.obj.muoviFile("~/DocTemplates/", WebShipUtils.mng.UserTempPath, nomeFile, false); + // stacco un nuovo protocollo! + docMetaDataSet docsData = WebShipUtils.mng.currMetaData; + //check del path + string pathDest = docsData.path; + if (pathDest != "") + { + pathDest = string.Format("{0}{1}", utils.obj.confReadString("archiveDir"), docsData.path); + string redattore = utils.obj.currUserCognomeNome; // usa utente corrente + int idxFile = WebShipUtils.archiviaFile(docsData, WebShipUtils.mng.UserTempPath, pathDest, nomeFile, redattore); + // recupero dati documento + docsData = WebShipUtils.mng.docMetaFromIdxFile(idxFile); + // recupero full path del documento + string fullPath = Server.MapPath(string.Format("{0}{1}", pathDest, WebShipUtils.nomeFileFullFromIdxFile(idxFile))); + string protocollo = WebShipUtils.protocolloFromIdxFile(idxFile); + // prendo il nuovo file generato e sostituisco parte del nome con il codice protocollo + officeXmlMan.replaceDocxText(fullPath, "{{Protocollo}}", protocollo); + officeXmlMan.replaceDocxText(fullPath, "{{DataDoc}}", docsData.dataDoc.ToShortDateString()); + officeXmlMan.replaceDocxText(fullPath, "{{Redattore}}", utils.obj.currUserCognomeNome); + // link: msdn.microsoft.com/en-us/library/bb508261.aspx + } + Response.Redirect("~/GestioneDocumenti.aspx"); } } } \ No newline at end of file diff --git a/ETS-WS/ETS-WS/WebUserControls/mod_pathAndDocs.ascx.designer.cs b/ETS-WS/ETS-WS/WebUserControls/mod_pathAndDocs.ascx.designer.cs index ac87103..930c5c0 100644 --- a/ETS-WS/ETS-WS/WebUserControls/mod_pathAndDocs.ascx.designer.cs +++ b/ETS-WS/ETS-WS/WebUserControls/mod_pathAndDocs.ascx.designer.cs @@ -57,6 +57,15 @@ namespace ETS_WS.WebUserControls { /// protected global::System.Web.UI.WebControls.Button btnSubmit; + /// + /// pnlGenDocs control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::System.Web.UI.WebControls.Panel pnlGenDocs; + /// /// btnStaccaProto control. /// diff --git a/ETS-WS/ETS-WS/bin/ETS-WS.dll b/ETS-WS/ETS-WS/bin/ETS-WS.dll index 0402565..60c5795 100644 Binary files a/ETS-WS/ETS-WS/bin/ETS-WS.dll and b/ETS-WS/ETS-WS/bin/ETS-WS.dll differ diff --git a/ETS-WS/ETS-WS/bin/ETS_Data.dll b/ETS-WS/ETS-WS/bin/ETS_Data.dll index eaaef2c..e13bf1f 100644 Binary files a/ETS-WS/ETS-WS/bin/ETS_Data.dll and b/ETS-WS/ETS-WS/bin/ETS_Data.dll differ diff --git a/ETS_Data/ETS_Data.csproj b/ETS_Data/ETS_Data.csproj index 248ea80..48b91b6 100644 --- a/ETS_Data/ETS_Data.csproj +++ b/ETS_Data/ETS_Data.csproj @@ -47,6 +47,7 @@ true + ..\ETS-WS\packages\NLog.2.0.0.2000\lib\net40\NLog.dll @@ -58,6 +59,7 @@ + @@ -76,6 +78,7 @@ DS_WebScip.xsd + True diff --git a/ETS_Data/officeXmlMan.cs b/ETS_Data/officeXmlMan.cs new file mode 100644 index 0000000..f7efcfd --- /dev/null +++ b/ETS_Data/officeXmlMan.cs @@ -0,0 +1,45 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.IO; +using System.Text.RegularExpressions; +using DocumentFormat.OpenXml.Packaging; + +namespace ETS_Data +{ + /// + /// gestioen documetni office/xml + /// + public class officeXmlMan + { + /// + /// fa sostituzioni di testo in un doc .docx + /// + /// + /// + /// + public static void replaceDocxText(string fullPathFile, string textOrig, string textNew) + { + using (WordprocessingDocument wordDoc = WordprocessingDocument.Open(fullPathFile, true)) + { + // lettura + string docText = null; + using (StreamReader sr = new StreamReader(wordDoc.MainDocumentPart.GetStream())) + { + docText = sr.ReadToEnd(); + } + // sostituzione + Regex regexText = new Regex(textOrig); + docText = regexText.Replace(docText, textNew); + // scrittura + using (StreamWriter sw = new StreamWriter(wordDoc.MainDocumentPart.GetStream(FileMode.Create))) + { + sw.Write(docText); + } + } + } + + + } +}