示例#1
0
        /// <summary>
        /// Crea il File EXCEL XLS
        /// </summary>
        /// <param name="Out">Path di destinazione del file creato</param>
        /// <param name="CodEdi">Codice Edificio</param>
        /// <param name="Mese">Mese di creazione del Piano</param>
        /// <param name="Anno">Anno di creazione del Piano</param>
        /// <returns>Nome del File Excel creato comprensivo di percorso fisico</returns>
        private string CreaFileXLS(string Out, string CodEdi, int Mese, int Anno)
        {
            string        ConnectionStr = System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"];
            string        Master        = Server.MapPath("../MasterExcel");
            string        FileExcel     = "";
            ExcelWritePMP exc           = new ExcelWritePMP(Master, Out, ConnectionStr);

            try
            {
                FileExcel = exc.WriteFilePMP(CodEdi, Mese, Anno);
            }

            finally
            {
                if (exc != null)
                {
                    ((IDisposable)exc).Dispose();
                }
            }
            return(FileExcel);
        }
示例#2
0
        private void SendMail(string FileName)
        {
            string[] CodEdi      = DrEdifici.Items[DrEdifici.SelectedIndex].Text.Split(' ');
            int      Id_progetto = _inviodoc.GetIdProgetto(CodEdi[0].Trim());
            string   FileZip     = "";

            //Se il piano è eseguito ricreo il file A8 ed XSL
            if (DrTipoDocumenti.SelectedValue == "4")
            {
                string ConnectionStr = System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"];
                string Master        = Server.MapPath("../MasterExcel");
                string Out           = Path.GetDirectoryName(FileName);
                string FileExcel     = "";
                string FileExcelA8   = "";
                //CREAZIONE DEL FILE EXCEL PME
                ExcelWritePMP exc = new ExcelWritePMP(Master, Out, ConnectionStr);
                try
                {
                    FileExcel = exc.WriteFilePMP(CodEdi[0].Trim(), Convert.ToInt32(DropMese.SelectedValue), Convert.ToInt32(DropAnno.SelectedValue));
                }
                finally
                {
                    if (exc != null)
                    {
                        ((IDisposable)exc).Dispose();
                    }
                }
//				if(Id_progetto==1)
//				{
//					MP_RPT_XLS.MPRPT rpt=new MP_RPT_XLS.MPRPT();
//					try
//					{
//						rpt.Anno =Convert.ToInt32(DropAnno.SelectedValue);
//						rpt.CodSede =CodEdi[0].Trim();
//						rpt.Mese =Convert.ToInt32(DropMese.SelectedValue);
//						rpt.PathFileOutPut = Out;
//						rpt.StrDataDdb =ConnectionStr;
//						rpt.GeneraRptXlsMp(Master,CodEdi[0].Trim(),
//							Convert.ToInt32(DropMese.SelectedValue),Convert.ToInt32(DropAnno.SelectedValue));
//
//						FileExcelA8=rpt.NomeFileCompleto;
//
//					}
//					finally
//					{
//						if (rpt != null)
//							((IDisposable)rpt).Dispose();
//
//					}
//
//				}

                FileZip = Path.GetDirectoryName(FileExcel) + @"\" + Path.GetFileNameWithoutExtension(FileExcel) + ".zip";

                if (File.Exists(FileZip))
                {
                    File.Delete(FileZip);
                }

                ZipOutputStream s = new ZipOutputStream(File.Create(FileZip));
                s.SetLevel(5);                 // 0 - store only to 9 - means best compression
                FileStream fs     = File.OpenRead(FileExcel);
                byte[]     buffer = new byte[fs.Length];
                fs.Read(buffer, 0, buffer.Length);
                ZipEntry entry = new ZipEntry(Path.GetFileName(FileExcel));
                s.PutNextEntry(entry);
                s.Write(buffer, 0, buffer.Length);


//				if(File.Exists(FileExcelA8))
//				{
//					fs = File.OpenRead(FileExcelA8);
//					buffer = new byte[fs.Length];
//					fs.Read(buffer, 0, buffer.Length);
//					entry = new ZipEntry(Path.GetFileName(FileExcelA8));
//					s.PutNextEntry(entry);
//					s.Write(buffer, 0, buffer.Length);
//				}

                s.Finish();
                s.Close();
                fs.Close();
                FileExcelA8 = "";
                SalvaEseguito(FileExcel, FileExcelA8);
            }
            else
            {
//				string FileExcelA8="";
//				if(Id_progetto==1)
//				{
//					string ConnectionStr =System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"];
//					string Master=Server.MapPath("../MasterExcel");
//					string Out=Path.GetDirectoryName(FileName);
//
//					MP_RPT_XLS.MPRPT rpt=new MP_RPT_XLS.MPRPT();
//					try
//					{
//						rpt.Anno =Convert.ToInt32(DropAnno.SelectedValue);
//						rpt.CodSede =CodEdi[0].Trim();
//						rpt.Mese =Convert.ToInt32(DropMese.SelectedValue);
//						rpt.PathFileOutPut = Out;
//						rpt.StrDataDdb =ConnectionStr;
//						rpt.GeneraRptXlsMp(Master,CodEdi[0].Trim(),
//							Convert.ToInt32(DropMese.SelectedValue),Convert.ToInt32(DropAnno.SelectedValue));
//
//						FileExcelA8=rpt.NomeFileCompleto;
//					//	SalvaA8(FileExcelA8);
//					}
//					finally
//					{
//						if (rpt != null)
//							((IDisposable)rpt).Dispose();
//
//					}
//				}

                FileZip = Path.GetDirectoryName(FileName) + @"\" + Path.GetFileNameWithoutExtension(FileName) + ".zip";

                if (File.Exists(FileZip))
                {
                    File.Delete(FileZip);
                }

                ZipOutputStream s = new ZipOutputStream(File.Create(FileZip));
                s.SetLevel(5);                 // 0 - store only to 9 - means best compression
                FileStream fs     = File.OpenRead(FileName);
                byte[]     buffer = new byte[fs.Length];
                fs.Read(buffer, 0, buffer.Length);
                ZipEntry entry = new ZipEntry(Path.GetFileName(FileName));
                s.PutNextEntry(entry);
                s.Write(buffer, 0, buffer.Length);

//				if(File.Exists(FileExcelA8))
//				{
//					fs = File.OpenRead(FileExcelA8);
//					buffer = new byte[fs.Length];
//					fs.Read(buffer, 0, buffer.Length);
//					entry = new ZipEntry(Path.GetFileName(FileExcelA8));
//					s.PutNextEntry(entry);
//					s.Write(buffer, 0, buffer.Length);
//				}

                s.Finish();
                s.Close();
                fs.Close();
            }
            DataSet _Ds;

            if (DrTipoDocumenti.SelectedValue == "4")
            {
                _Ds = _inviodoc.GetDestinatari(int.Parse(DrEdifici.SelectedValue), true);
            }
            else
            {
                _Ds = _inviodoc.GetDestinatari(int.Parse(DrEdifici.SelectedValue), false);
            }

            DataColumn dc = new DataColumn("IsExecute", System.Type.GetType("System.Int32"));

            dc.DefaultValue = 0;
            DataTable dt = _Ds.Tables[0];

            dt.Columns.Add(dc);

            bool   flag_mail = false;
            string MailUser  = _inviodoc.GetMailByUser();

            foreach (DataRow riga in  dt.Rows)
            {
                if (MailUser.Trim().ToLower() == riga["email"].ToString().Trim().ToLower())
                {
                    flag_mail         = true;
                    riga["IsExecute"] = 1;
                    break;
                }
            }

            if (flag_mail == false && MailUser != "")
            {
                DataRow riga = dt.NewRow();
                riga["email"]     = MailUser;
                riga["IsExecute"] = 1;
                dt.Rows.Add(riga);
            }
            dt.AcceptChanges();

            int    Count = 0;
            string Dest  = "";

            foreach (DataRow riga in dt.Rows)
            {
//				MailMessage mailMessage = new MailMessage();
//				mailMessage.BodyFormat = MailFormat.Html;
//				mailMessage.BodyEncoding=System.Text.Encoding.UTF8;
//				mailMessage.From = ConfigurationSettings.AppSettings["MailFrom"].ToString();
//				mailMessage.To = riga["email"].ToString();
//				mailMessage.Cc ="*****@*****.**";


                Count++;
                if (riga["id_utente"].ToString() != "")
                {
                    Dest = riga["email"].ToString();
                }
                else
                {
                    Dest += riga["email"].ToString() + "; ";
                    if (Count != dt.Rows.Count)
                    {
                        continue;
                    }
                }


                MailMessage mailMessage = new MailMessage();
                mailMessage.BodyFormat   = MailFormat.Html;
                mailMessage.BodyEncoding = System.Text.Encoding.UTF8;
                mailMessage.From         = ConfigurationSettings.AppSettings["MailFrom"].ToString();
                mailMessage.To           = Dest;
                mailMessage.Cc           = "*****@*****.**";
                Dest = "";


                string Body = "";
                //Se è un piano Mensile
                if (DrTipoDocumenti.SelectedValue == "3" || DrTipoDocumenti.SelectedValue == "4" || DrTipoDocumenti.SelectedValue == "5")
                {
                    string Lk  = "";
                    string Lk1 = "";

                    if (DrTipoDocumenti.SelectedValue == "3")                   //Proposto
                    {
                        string tipo = "";
                        if (riga["id_utente"].ToString() != "")
                        {
                            tipo = "&t=m&e=" + DrEdifici.SelectedValue;
                            Lk   = "<DIV>&nbsp;</DIV><DIV>&nbsp;</DIV><DIV><A href=\"http://www.cft-sir.it/MEHV/default.aspx?u=" + riga["id_utente"].ToString() + tipo + "&s=3&id=" + Result.ToString() + "\">Programma Accettato </A></DIV>";
                            Lk  += "<DIV>&nbsp;</DIV><DIV><A href=\"http://www.cft-sir.it/MEHV/default.aspx?u=" + riga["id_utente"].ToString() + tipo + "&s=4&id=" + Result.ToString() + "\">Programma Accettato con Riserva</A></DIV>";
                            Lk  += "<DIV>&nbsp;</DIV><DIV><A href=\"http://www.cft-sir.it/MEHV/default.aspx?u=" + riga["id_utente"].ToString() + tipo + "&s=2&id=" + Result.ToString() + "\">Programma Rifiutato</A></DIV><DIV>&nbsp;</DIV>";

                            //						Lk="<DIV>&nbsp;</DIV><DIV>&nbsp;</DIV><DIV><A href=\"http://192.168.143.180/MEHV/default.aspx?u=" +  riga["id_utente"].ToString() + tipo + "&s=3&id=" + Result.ToString() + "\">Programma Acettato </A></DIV>";
                            //						Lk+="<DIV>&nbsp;</DIV><DIV><A href=\"http://192.168.143.180/MEHV/default.aspx?u=" +  riga["id_utente"].ToString() + tipo + "&s=4&id=" + Result.ToString() + "\">Programma Acettato con Riserva</A></DIV>";
                            //						Lk+="<DIV>&nbsp;</DIV><DIV><A href=\"http://192.168.143.180/MEHV/default.aspx?u=" +  riga["id_utente"].ToString() + tipo + "&s=2&id=" + Result.ToString()+ "\">Programma Rifiutato</A></DIV><DIV>&nbsp;</DIV>";

                            Lk1 = "<DIV>Sono predisposti i seguenti link per <STRONG>Approvare</STRONG>,&nbsp;<STRONG>Approvare con promessa di aggiustamento</STRONG>&nbsp;o&nbsp;<STRONG>Respingere</STRONG> il programma di manutenzione.</DIV>";
                        }
                    }
                    string CodiceEdi = DrEdifici.Items[DrEdifici.SelectedIndex].Text.Substring(0, DrEdifici.Items[DrEdifici.SelectedIndex].Text.IndexOf("-") - 1);
                    mailMessage.Subject = string.Format(DrTipoDocumenti.Items[DrTipoDocumenti.SelectedIndex].Text + " mese " + DropMese.Items[DropMese.SelectedIndex].Text + " " + DropAnno.Items[DropAnno.SelectedIndex].Text.Substring(2) + " Sede: " + CodiceEdi + " Data invio: {0} Ora: {1}", DateTime.Now.ToLongDateString(), DateTime.Now.ToLongTimeString());

                    string Destinatari = "";
                    foreach (DataRow riga2 in  dt.Rows)
                    {
                        Destinatari += riga2["email"].ToString() + "; ";
                    }


                    Body  = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">";
                    Body += "<HTML><HEAD><META http-equiv=Content-Type content=\"text/html; charset=iso-8859-1\">";
                    Body += "<BODY bgColor=#ffffff><DIV>Altri destinatari: " + Destinatari + "</DIV>";
                    Body += "<DIV>E' stato inserito un nuovo documento del " + DrTipoDocumenti.Items[DrTipoDocumenti.SelectedIndex].Text + " relativo alla sede " + DrEdifici.Items[DrEdifici.SelectedIndex].Text;
                    Body += "	del mese di "+ DropMese.Items[DropMese.SelectedIndex].Text + " " + DropAnno.Items[DropAnno.SelectedIndex].Text + "</DIV>";
                    Body += "<DIV>con le seguenti annotazioni:</DIV><DIV>" + TxtAnnotazioni.Text + "</DIV>";
                    Body += Lk1;
                    Body += Lk;
                    Body += "<DIV>&nbsp;</DIV>";


                    if (riga["IsExecute"].ToString() == "1")
                    {
                        Body += "</br>Rapporto del File inviato:</br>";
                        Body += lblMessage.Text;
                    }
                    Body += "<DIV>SIR Cofathec Servizi S.p.a.</DIV><DIV>&nbsp;</DIV></BODY></HTML>";

                    mailMessage.Body = Body;

                    //mailMessage.Fields["http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"] = 1;
                    mailMessage.Fields["http://schemas.microsoft.com/cdo/configuration/sendusername"] = ConfigurationSettings.AppSettings["usersmtp"].ToString();
                    mailMessage.Fields["http://schemas.microsoft.com/cdo/configuration/sendpassword"] = ConfigurationSettings.AppSettings["pwdsmtp"].ToString();

                    MailAttachment attach = new MailAttachment(FileZip);
                    mailMessage.Attachments.Add(attach);
                    SmtpMail.SmtpServer = ConfigurationSettings.AppSettings["SmtpServer2"].ToString();
                    SmtpMail.Send(mailMessage);
                }
                else                //Piano annuale
                {
                    string Lk  = "";
                    string Lk1 = "";
                    if (DrTipoDocumenti.SelectedValue == "1")                   //Proposto
                    {
                        string tipo = "";
                        if (riga["id_utente"].ToString() != "")
                        {
                            tipo = "&t=a&e=" + DrEdifici.SelectedValue;
                            Lk   = "<DIV>&nbsp;</DIV><DIV><A href=\"http://www.cft-sir.it/MEHV/default.aspx?u=" + riga["id_utente"].ToString() + tipo + "&s=3&id=" + Result.ToString() + "\">Piano Accettato </A></DIV>";
                            Lk  += "<DIV>&nbsp;</DIV><DIV><A href=\"http://www.cft-sir.it/MEHV/default.aspx?u=" + riga["id_utente"].ToString() + tipo + "&s=4&id=" + Result.ToString() + "\">Piano Accettato con Riserva</A></DIV>";
                            Lk  += "<DIV>&nbsp;</DIV><DIV><A href=\"http://www.cft-sir.it/MEHV/default.aspx?u=" + riga["id_utente"].ToString() + tipo + "&s=2&id=" + Result.ToString() + "\">Piano Rifiutato</A></DIV><DIV>&nbsp;</DIV>";

                            Lk1 = "<DIV>Sono predisposti i seguenti link per <STRONG>Approvare</STRONG>,&nbsp;<STRONG>Approvare con promessa di aggiustamento</STRONG>&nbsp;o&nbsp;<STRONG>Respingere</STRONG> il piano di manutenzione Annuale.</DIV>";
                        }
                    }


                    string CodiceEdi = DrEdifici.Items[DrEdifici.SelectedIndex].Text.Substring(1, DrEdifici.Items[DrEdifici.SelectedIndex].Text.IndexOf("-") - 1);
                    mailMessage.Subject = string.Format(DrTipoDocumenti.Items[DrTipoDocumenti.SelectedIndex].Text + " anno " + DropAnno.Items[DropAnno.SelectedIndex].Text.Substring(2) + " Sede: " + CodiceEdi + " Data invio: {0} Ora: {1}", DateTime.Now.ToLongDateString(), DateTime.Now.ToLongTimeString());

                    string Destinatari = "";
                    foreach (DataRow riga2 in  dt.Rows)
                    {
                        Destinatari += riga2["email"].ToString() + "; ";
                    }
                    Body  = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">";
                    Body += "<HTML><HEAD><META http-equiv=Content-Type content=\"text/html; charset=iso-8859-1\">";
                    Body += "<BODY bgColor=#ffffff><DIV>Altri destinatari: " + Destinatari + "</DIV>";
                    Body += "<DIV>E' stato inserito un nuovo documento del " + DrTipoDocumenti.Items[DrTipoDocumenti.SelectedIndex].Text + " relativo alla sede " + DrEdifici.Items[DrEdifici.SelectedIndex].Text;
                    Body += "	"+ DropAnno.Items[DropAnno.SelectedIndex].Text + "</DIV>";
                    Body += "<DIV>con le seguenti annotazioni:</DIV><DIV>" + TxtAnnotazioni.Text + "</DIV>";
                    Body += Lk1;
                    Body += Lk;
                    Body += "<DIV>&nbsp;</DIV>";


                    if (riga["IsExecute"].ToString() == "1")
                    {
                        Body += "</br>Rapporto del File inviato:</br>";
                        Body += lblMessage.Text;
                    }
                    Body += "<DIV>SIR Cofathec Servizi S.p.a.</DIV><DIV>&nbsp;</DIV></BODY></HTML>";

                    mailMessage.Body = Body;
                    MailAttachment attach = new MailAttachment(FileZip);
                    mailMessage.Attachments.Add(attach);

                    //mailMessage.Fields["http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"] = 1;
                    mailMessage.Fields["http://schemas.microsoft.com/cdo/configuration/sendusername"] = ConfigurationSettings.AppSettings["usersmtp"].ToString();
                    mailMessage.Fields["http://schemas.microsoft.com/cdo/configuration/sendpassword"] = ConfigurationSettings.AppSettings["pwdsmtp"].ToString();

                    SmtpMail.SmtpServer = ConfigurationSettings.AppSettings["SmtpServer2"].ToString();
                    SmtpMail.Send(mailMessage);
                }
            }            //Ciclo for
        }