diff --git a/ETS-WS/ETS-WS/ETS-WS.csproj b/ETS-WS/ETS-WS/ETS-WS.csproj index bb0f513..6100098 100644 --- a/ETS-WS/ETS-WS/ETS-WS.csproj +++ b/ETS-WS/ETS-WS/ETS-WS.csproj @@ -654,6 +654,9 @@ Always + + + diff --git a/ETS-WS/ETS-WS/WebShipUtils.cs b/ETS-WS/ETS-WS/WebShipUtils.cs index 60d5649..6177b37 100644 --- a/ETS-WS/ETS-WS/WebShipUtils.cs +++ b/ETS-WS/ETS-WS/WebShipUtils.cs @@ -209,6 +209,22 @@ namespace ETS_WS { } 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 @@ -218,8 +234,10 @@ namespace ETS_WS /// path di destinazione del file /// nome del file da archiviare /// redattore - public static void archiviaFile(docMetaDataSet docsData, string pathOrig, string pathDest, string nomeFile, string 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 = ""; @@ -250,11 +268,14 @@ namespace ETS_WS { } } } + 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!) @@ -280,7 +301,7 @@ namespace ETS_WS 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); + lg.Info("Spostato file {0} per sostituzione", nomeFile); } } } diff --git a/ETS-WS/ETS-WS/WebUserControls/mod_pathAndDocs.ascx.cs b/ETS-WS/ETS-WS/WebUserControls/mod_pathAndDocs.ascx.cs index 2556767..802740c 100644 --- a/ETS-WS/ETS-WS/WebUserControls/mod_pathAndDocs.ascx.cs +++ b/ETS-WS/ETS-WS/WebUserControls/mod_pathAndDocs.ascx.cs @@ -72,7 +72,7 @@ namespace ETS_WS.WebUserControls protected void btnStaccaProto_Click(object sender, EventArgs e) { // effettua upload del documento "dummy" proto - string nomeFile = "Proto.txt"; + string nomeFile = "ETS-Proto.docx"; fileMover.obj.muoviFile("~/DocTemplates/", WebShipUtils.mng.UserTempPath, nomeFile, false); // stacco un nuovo protocollo! docMetaDataSet docsData = WebShipUtils.mng.currMetaData; @@ -82,15 +82,17 @@ namespace ETS_WS.WebUserControls { pathDest = string.Format("{0}{1}", utils.obj.confReadString("archiveDir"), docsData.path); string redattore = utils.obj.currUserCognomeNome; // usa utente corrente - WebShipUtils.archiviaFile(docsData, WebShipUtils.mng.UserTempPath, pathDest, nomeFile, redattore); - + 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=""; - string protocollo="1234"; + 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); // !!!FARE!!! - - // link: http://msdn.microsoft.com/en-us/library/bb508261.aspx + 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"); } diff --git a/ETS-WS/ETS-WS/bin/ETS-WS.dll b/ETS-WS/ETS-WS/bin/ETS-WS.dll index 29d8325..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 56921cf..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 350fa4f..48b91b6 100644 --- a/ETS_Data/ETS_Data.csproj +++ b/ETS_Data/ETS_Data.csproj @@ -59,6 +59,7 @@ + diff --git a/ETS_Data/officeXmlMan.cs b/ETS_Data/officeXmlMan.cs index 41f199a..f7efcfd 100644 --- a/ETS_Data/officeXmlMan.cs +++ b/ETS_Data/officeXmlMan.cs @@ -19,19 +19,25 @@ namespace ETS_Data /// /// /// - public static void replaceDocxText(string fullPathFile,string textOrig, string textNew) + public static void replaceDocxText(string fullPathFile, string textOrig, string textNew) { - // non va, controllare !!!FARE!!! - - //using (WordprocessingDocument wordDoc = WordprocessingDocument.Open(fullPathFile, true)) - //{ - // using (StreamReader sr = new StreamReader(wordDoc.MainDocumentPart.GetStream())) - // { - // string docText = sr.ReadToEnd(); - // Regex regexText = new Regex(textOrig); - // docText = regexText.Replace(docText, 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); + } + } }