public void MenuPreView() { REPAR02 report = new REPAR02(); report.SetFilter = " XA001 = '" + mXA001 + "'"; report.SetDate = mDate; report.ShowRibbonPreview(); }
private void btnOK_Click(object sender, EventArgs e) { if (main == null) { (Parent.Parent as RESMain).SetMarqueeStr("正在傳送郵件"); (Parent.Parent as RESMain).ShowMarqueeStr(true); } else { main.SetMarqueeStr("正在傳送郵件"); main.ShowMarqueeStr(true); } string MailServer = "mail-tchdb1.digiwin.biz"; //string MailServer = "mail-tch.digiwin.biz"; if (FXM003 != XM003.Text) { XM003.Text = fc.FDes.EncryptString(XM003.Text, fc.FDes.GenerateKey()); } string pw = fc.FDes.DecryptString(XM003.Text, fc.FDes.GenerateKey()); string MailtoDigiwin = ""; string MailtoGMail = ""; for (int i = 0; i < GV_Main.RowCount; i++) { if (GV_Main.GetRowCellValue(i, "XM002").ToString().ToLower().Contains("digiwin.biz")) { MailtoDigiwin += GV_Main.GetRowCellValue(i, "XM002") + ","; } else if (GV_Main.GetRowCellValue(i, "XM002").ToString().ToLower().Contains("gmail.com")) { MailtoGMail += GV_Main.GetRowCellValue(i, "XM002") + ","; } } if (MailtoDigiwin.EndsWith(",")) { MailtoDigiwin = MailtoDigiwin.Substring(0, MailtoDigiwin.Length - 1); } if (MailtoGMail.EndsWith(",")) { MailtoGMail = MailtoGMail.Substring(0, MailtoGMail.Length - 1); } //DSC REPAR02 report = new REPAR02(); report.SetFilter = " XA001 = '" + mXA001 + "'"; report.SetDate = mDate; //report.ShowPreviewDialog(); // Create a new memory stream and export the report into it as PDF. MemoryStream mem = new MemoryStream(); report.ExportToPdf(mem); // Create a new attachment and put the PDF report into it. mem.Seek(0, System.IO.SeekOrigin.Begin); System.Net.Mail.Attachment att = new System.Net.Mail.Attachment(mem, DateTime.Now.ToString("yyyyMMdd") + "_Menu.pdf", "application/pdf"); System.Net.Mail.Attachment imageAttachment = null; if (buffer != null) { MemoryStream ms = new MemoryStream(buffer); System.Net.Mime.ContentType contentType = new System.Net.Mime.ContentType(); contentType.MediaType = System.Net.Mime.MediaTypeNames.Image.Jpeg; contentType.Name = "menu.jpg"; imageAttachment = new System.Net.Mail.Attachment(ms, contentType); } if (MailtoDigiwin.Trim() != "") { SmtpClient client = new SmtpClient(MailServer); client.DeliveryMethod = SmtpDeliveryMethod.Network; client.UseDefaultCredentials = false; client.Credentials = new NetworkCredential(XM002.Text, pw, MailServer); MailMessage message = new MailMessage(); message.Attachments.Add(att); if (imageAttachment != null) { message.Attachments.Add(imageAttachment); } message.From = new MailAddress(XM002.Text, mName); message.To.Add(MailtoDigiwin); message.Subject = tb01.Text; message.Body = rd01.HtmlText; message.IsBodyHtml = true; message = rd01.CreateExporter(rd01.GetRC, message); //client.Send(message); client.SendCompleted += new SendCompletedEventHandler(SendCompletedCallback);//回调函数 string userState = "寄出郵件"; client.SendAsync(message, userState); } //mem.Close(); //mem.Flush(); // Create a new attachment and put the PDF report into it. if (MailtoGMail.Trim() != "") { //GMAIL MailMessage mail = new MailMessage(); mail.From = new MailAddress("*****@*****.**", "郭育宏"); mail.To.Add(MailtoGMail); mail.Subject = tb01.Text; mail.Body = rd01.RCText; mail.IsBodyHtml = true; mail.Attachments.Add(att); if (imageAttachment != null) { mail.Attachments.Add(imageAttachment); } NetworkCredential cred = new NetworkCredential("*****@*****.**", "zz10121205"); SmtpClient smtp = new SmtpClient("smtp.gmail.com", 587); //smtp.UseDefaultCredentials = false; smtp.EnableSsl = true; smtp.Credentials = cred; //smtp.Send(mail); mail = rd01.CreateExporter(rd01.GetRC, mail); smtp.SendCompleted += new SendCompletedEventHandler(SendCompletedCallback2);//回调函数 string userState = "寄出郵件"; smtp.SendAsync(mail, userState); } //mem.Close(); //mem.Flush(); if (mWriteData) { string mXP002 = ""; using (SqlConnection conn = new SqlConnection(fc.makeConnectString(fc.FDBInfo))) { conn.Open(); try { string SQL = "SELECT TOP 1 XP002 FROM POSXP WHERE XP001=@XP001 ORDER BY XP002 DESC"; using (SqlCommand cmd = new SqlCommand(SQL, conn)) { cmd.Parameters.AddWithValue("@XP001", pdfName); SqlDataReader rd = cmd.ExecuteReader(); if (rd.Read()) { mXP002 = string.Format("{0:0000}", Int32.Parse(rd["XP002"].ToString()) + 1); } else { mXP002 = "0001"; } rd.Close(); cmd.Cancel(); } SQL = "INSERT INTO POSXP (XP001,XP002,XP003) VALUES(@XP001,@XP002,@XP003)"; using (SqlCommand cmd = new SqlCommand(SQL, conn)) { cmd.Parameters.AddWithValue("@XP001", pdfName); cmd.Parameters.AddWithValue("@XP002", mXP002); cmd.Parameters.AddWithValue("@XP003", mID); cmd.ExecuteNonQuery(); } conn.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message.ToString()); fc.ErrorLog(ex.Message); } } DataTable dt = new DataTable("POSXQ"); dt.Columns.Add("XQ001", typeof(string)); dt.Columns.Add("XQ002", typeof(string)); dt.Columns.Add("XQ003", typeof(string)); for (int i = 0; i < GV_Main.RowCount; i++) { dt.Rows.Add(pdfName, mXP002, GV_Main.GetRowCellValue(i, "XM001")); } DataView dv = dt.DefaultView; DataTable dtsort = dv.ToTable(); Stopwatch sw = new Stopwatch(); sw.Reset(); sw.Start(); InsertV4(dtsort); //using SqlBulkCopy } // Create a new memory stream and export the report into it as PDF. /*MemoryStream mem = new MemoryStream(); * report.ExportToPdf(mem); * // Create a new attachment and put the PDF report into it. * mem.Seek(0, System.IO.SeekOrigin.Begin); * System.Net.Mail.Attachment att = new System.Net.Mail.Attachment(mem, "TestReport.pdf", "application/pdf"); * * SmtpClient client = new SmtpClient("mail-tchdb1.digiwin.biz"); * client.DeliveryMethod = SmtpDeliveryMethod.Network; * * client.UseDefaultCredentials = false; * client.Credentials = new NetworkCredential("erric", "zz10121205", "mail-tchdb1.digiwin.biz"); * * MailMessage message = new MailMessage(); * message.Attachments.Add(att); * * // Specify sender and recipient options for the e-mail message. * message.From = new MailAddress("*****@*****.**", "erricguo"); * message.To.Add("[email protected],[email protected]"); * // Specify other e-mail options. * message.Subject = "Subject"; * message.Body = "This is a test e-mail message sent by an application."; * client.Send(message); * // Close the memory stream. * mem.Close(); * mem.Flush();*/ // Create a new report. /*RESAR02 report = new RESAR02(); * report.SetFilter = " XA001 = '" + mXA001 + "'"; * report.SetDate = mDate; * report.ShowPreviewDialog(); * //if (report.ShowPageSetupDialog() == DialogResult.OK) * { * // Create a new memory stream and export the report into it as PDF. * MemoryStream mem = new MemoryStream(); * report.ExportToPdf(mem); * * // Create a new attachment and put the PDF report into it. * mem.Seek(0, System.IO.SeekOrigin.Begin); * System.Net.Mail.Attachment att = new System.Net.Mail.Attachment(mem, DateTime.Now.ToString("yyyyMMdd") + "_Menu.pdf", "application/pdf"); * * // Create a new message and attach the PDF report to it. * MailMessage mail = new MailMessage(); * mail.Attachments.Add(att); * * // Specify sender and recipient options for the e-mail message. * mail.From = new MailAddress("*****@*****.**", "erricguo"); * mail.To.Add(Mailto); * // Specify other e-mail options. * mail.Subject = tb01.Text; * mail.Body = rd01.Text; * * //設定SMTP * NetworkCredential cred = new NetworkCredential("*****@*****.**", pw); * SmtpClient smtp = new SmtpClient("smtp.gmail.com"); * smtp.UseDefaultCredentials = false; * smtp.EnableSsl = true; * smtp.Credentials = cred; * smtp.Port = 587; * smtp.Send(mail); * * // Close the memory stream. * mem.Close(); * mem.Flush(); * }*/ }