200 lines
8.6 KiB
C#
200 lines
8.6 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;
|
|
|
|
namespace ETS_WS.WebUserControls
|
|
{
|
|
public partial class mod_pathAndDocs : System.Web.UI.UserControl
|
|
{
|
|
/// <summary>
|
|
/// evento richiesta salvataggio files
|
|
/// </summary>
|
|
public event EventHandler eh_reqSalva;
|
|
/// <summary>
|
|
/// caricamento pagina
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void Page_Load(object sender, EventArgs e)
|
|
{
|
|
updateVisual();
|
|
}
|
|
|
|
/// <summary>
|
|
/// aggiorna tutti i valori visualizzati
|
|
/// </summary>
|
|
public void updateVisual()
|
|
{
|
|
// sistemo valori...
|
|
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);
|
|
// ricavo dati x email ed aggiorno
|
|
string dest = "info@steamware.net";
|
|
string subject = "test";
|
|
string body = "test email";
|
|
aggiornaDatiMailTo(dest, subject, body);
|
|
}
|
|
/// <summary>
|
|
/// richiesta update
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void btnUpdate_Click(object sender, EventArgs e)
|
|
{
|
|
// aggiorno
|
|
updateVisual();
|
|
}
|
|
/// <summary>
|
|
/// aggiorna dati e sposta file
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void btnSubmit_Click(object sender, EventArgs e)
|
|
{
|
|
// aggiorno
|
|
updateVisual();
|
|
// indico evento di richeista spostamento
|
|
if (eh_reqSalva != null)
|
|
{
|
|
eh_reqSalva(this, new EventArgs());
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// genera un doc da template, tramite
|
|
/// - salvataggio
|
|
/// - spostamento "dummy file"
|
|
/// - enter in modalità editing
|
|
/// </summary>
|
|
/// <param name="nomeTemplate">file TEMPLATE</param>
|
|
private int generaDocDaTemplate(string nomeTemplate)
|
|
{
|
|
int idxFile = 0;
|
|
fileMover.obj.muoviFile("~/DocTemplates/", WebShipUtils.mng.UserTempPath, nomeTemplate, 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
|
|
idxFile = WebShipUtils.archiviaFile(docsData, WebShipUtils.mng.UserTempPath, pathDest, nomeTemplate, 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);
|
|
// se il nome contiene "docx" faccio sostituzioni...
|
|
if (nomeTemplate.IndexOf("docx") >= 0)
|
|
{
|
|
// prendo il nuovo file generato e sostituisco parte del nome con il codice protocollo // link: 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);
|
|
}
|
|
else if (nomeTemplate.IndexOf("eml") >= 0)
|
|
{
|
|
// creo un NUOVO file alla destinazione sostituendo l'esistente con apposita classe
|
|
string mittente = utils.obj.currUserEmail;
|
|
string destinatario = WebShipUtils.emailDaCodForn(docsData.fonte);
|
|
string subject = string.Format("{0}, prot. num {1}", docsData.oggetto, protocollo);
|
|
string body = string.Format("Commessa: {1}{0}Fase: {2}{0}Oggetto: {3}{0}prot. num: {4}", Environment.NewLine, docsData.commessa, docsData.fase, docsData.oggetto, protocollo);
|
|
string newFileName = WebShipUtils.CreaEml(mittente, destinatario, subject, body, null, Server.MapPath(pathDest));
|
|
// sostituisco file appena creato con quello nuovo
|
|
fileMover.obj.muoviFile(pathDest, pathDest, newFileName, WebShipUtils.nomeFileFullFromIdxFile(idxFile), true);
|
|
}
|
|
}
|
|
return idxFile;
|
|
}
|
|
/// <summary>
|
|
/// richiede salvataggio del protocollo, tramite
|
|
/// - salvataggio
|
|
/// - spostamento "dummy file"
|
|
/// - enter in modalità editing
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void btnStaccaProto_Click(object sender, EventArgs e)
|
|
{
|
|
// effettua upload del documento "dummy" proto
|
|
string nomeFile = "ETS-Proto.docx";
|
|
generaDocDaTemplate(nomeFile);
|
|
Response.Redirect("~/GestioneDocumenti.aspx");
|
|
}
|
|
/// <summary>
|
|
/// richiede salvataggio lettera
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void btnGenLettera_Click(object sender, EventArgs e)
|
|
{
|
|
// effettua upload del documento "dummy" lettera
|
|
string nomeFile = "ETS-Lettera.docx";
|
|
generaDocDaTemplate(nomeFile);
|
|
Response.Redirect("~/GestioneDocumenti.aspx");
|
|
}
|
|
/// <summary>
|
|
/// chiede salvataggio fax
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void btnGenFax_Click(object sender, EventArgs e)
|
|
{
|
|
// effettua upload del documento "dummy" fax
|
|
string nomeFile = "ETS-Fax.docx";
|
|
generaDocDaTemplate(nomeFile);
|
|
Response.Redirect("~/GestioneDocumenti.aspx");
|
|
}
|
|
/// <summary>
|
|
/// chiede salvataggio email + generazione doc mailto
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void btnGenMail_Click(object sender, EventArgs e)
|
|
{
|
|
// effettua upload del documento "dummy" fax
|
|
string nomeFile = "email.eml";
|
|
generaDocDaTemplate(nomeFile);
|
|
Response.Redirect("~/GestioneDocumenti.aspx");
|
|
#if false
|
|
// effettua upload del documento "dummy" proto
|
|
string nomeFile = "ETS-Proto.docx";
|
|
int idxFile = generaDocDaTemplate(nomeFile);
|
|
// ricavo dati x email
|
|
string dest = "info@steamware.net";
|
|
string subject = "test";
|
|
string body = "test email";
|
|
aggiornaDatiMailTo(dest, subject, body);
|
|
#endif
|
|
}
|
|
/// <summary>
|
|
/// script che aggiorna la funzione "mailto" dato idxFile e dati connessi
|
|
/// </summary>
|
|
/// <param name="dest"></param>
|
|
/// <param name="subject"></param>
|
|
/// <param name="body"></param>
|
|
private void aggiornaDatiMailTo(string dest, string subject, string body)
|
|
{
|
|
//String csName = "mailToCS";
|
|
//Type csType = this.GetType();
|
|
//ClientScriptManager cs = Page.ClientScript;
|
|
//if (!cs.IsClientScriptBlockRegistered(csType, csName))
|
|
//{
|
|
// string pre = "<script type='text/javascript'>";
|
|
// string scrVal = "function mailTo() { ";
|
|
// scrVal += string.Format(" location.href = 'mailto:{0}?subject={1}body={2}'", dest, subject, body);
|
|
// scrVal += " }";
|
|
// string post = "</script>";
|
|
// string fullScript = string.Format("{0} {1} {2}", pre, scrVal, post);
|
|
// cs.RegisterClientScriptBlock(csType, csName, fullScript);
|
|
//}
|
|
}
|
|
}
|
|
} |