sistemata generazione docs con cambio segnaposto

This commit is contained in:
samuele
2012-10-15 08:33:10 +02:00
parent ffd64f4e45
commit 98529072ba
7 changed files with 55 additions and 22 deletions
+3
View File
@@ -654,6 +654,9 @@
<Content Include="NLog.config">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<None Include="DocTemplates\ETS-Fax.docx" />
<None Include="DocTemplates\ETS-Lettera.docx" />
<None Include="DocTemplates\ETS-Proto.docx" />
<None Include="DocTemplates\PlaceHolder.file" />
<None Include="logs\PlaceHolder.file" />
<None Include="NLog.xsd">
+23 -2
View File
@@ -209,6 +209,22 @@ namespace ETS_WS
{ }
return answ;
}
/// <summary>
/// protocollo del file da idx DB
/// </summary>
/// <param name="idxFile"></param>
/// <returns></returns>
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;
}
/// <summary>
/// effettua operazione di archiviazione file
@@ -218,8 +234,10 @@ namespace ETS_WS
/// <param name="pathDest">path di destinazione del file</param>
/// <param name="nomeFile">nome del file da archiviare</param>
/// <param name="redattore">redattore</param>
public static void archiviaFile(docMetaDataSet docsData, string pathOrig, string pathDest, string nomeFile, string redattore)
/// <returns>restituisce valore INT del nuovo file archiviato</returns>
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;
}
/// <summary>
/// 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);
}
}
}
@@ -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");
}
Binary file not shown.
Binary file not shown.
+1
View File
@@ -59,6 +59,7 @@
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
<Reference Include="WindowsBase" />
</ItemGroup>
<ItemGroup>
<Compile Include="DS_Anagrafica.Designer.cs">
+18 -12
View File
@@ -19,19 +19,25 @@ namespace ETS_Data
/// <param name="fullPathFile"></param>
/// <param name="textOrig"></param>
/// <param name="textNew"></param>
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);
}
}
}