private void sendEmailButton_Click(object sender, EventArgs e) { var attr = ((ToolStripButton)sender).Tag as API.Printer.RowPrintTemplateAttribute; var service = Enova.API.EnovaService.Instance; var sendInfo = ((API.CRM.ISendEmail) this.DataContext.Current).GetEmail(); if (attr != null && sendInfo != null && service != null && service.IsLogined) { string fileName = "tmp\\" + Guid.NewGuid().ToString() + ".pdf"; System.Windows.Forms.Form progressForm = new System.Windows.Forms.Form(); progressForm.FormClosing += new System.Windows.Forms.FormClosingEventHandler((owner, args) => { }); progressForm.Text = "Progress FORM"; service.DrukujRow(progressForm, (API.Business.Row)DataContext.Current, attr.Template, API.Printer.Destinations.PDF, fileName); var form = new AbakTools.Web.EmailSendForm(); form.MailTo = sendInfo.Email; form.MailToName = sendInfo.To; form.MailSubject = sendInfo.Subject; DateTime now = DateTime.Now; while (true) { try { var attach = new System.Net.Mail.Attachment(fileName); attach.Name = sendInfo.AttachName.Replace('/', '_') + ".pdf"; form.Attachments.Add(attach); break; } catch (Exception ex) { var diff = DateTime.Now - now; if (diff > TimeSpan.FromSeconds(15)) { throw new Exception("Przekroczono limit czasu dostepnego na wygenerowanie wydruku", ex); } } } form.ShowDialog(); } }
private void sendEmailButton_Click(object sender, EventArgs e) { if (!drukowanoRaport) { MessageBox.Show("Musisz najpierw wygenerować raport"); return; } this.Cursor = Cursors.WaitCursor; this.Enabled = false; Enova.API.CRM.Kontrahent kontrahent = null; var service = Enova.API.EnovaService.Instance; using (var session = service.CreateSession()) { if (kontrahentSelect.Kontrahent != null) { try { kontrahent = session.GetModule <Enova.API.CRM.CRMModule>().Kontrahenci[kontrahentSelect.Kontrahent.Guid]; } catch { } } Warning[] warnings; string[] streamIds; string mimeType = string.Empty; string encoding = string.Empty; string extension = string.Empty; string fileName = "tmp\\" + Guid.NewGuid().ToString() + ".pdf"; byte[] bytes = this.reportViewer.LocalReport.Render("PDF", null, out mimeType, out encoding, out extension, out streamIds, out warnings); using (System.IO.FileStream fs = new System.IO.FileStream(fileName, System.IO.FileMode.Create)) { fs.Write(bytes, 0, bytes.Length); } var form = new AbakTools.Web.EmailSendForm(); if (kontrahent != null) { if (!string.IsNullOrEmpty(kontrahent.KontaktEMAIL)) { form.MailTo = kontrahent.KontaktEMAIL; } form.MailToName = kontrahent.Kod; } form.MailSubject = "ABAK - PŁATNOŚCI"; form.Attachments.Add(new System.Net.Mail.Attachment(fileName) { Name = "Abak_Platnosci_" + DateTime.Now.ToShortDateString() + ".pdf" }); this.Enabled = true; this.Cursor = Cursors.Default; var result = form.ShowDialog(); if (kontrahent != null && result == System.Windows.Forms.DialogResult.OK) { if (!string.IsNullOrEmpty(form.MailTo)) { bool flag = false; if (string.IsNullOrEmpty(kontrahent.KontaktEMAIL)) { if (MessageBox.Show("Dodać adres email do kartoteki klienta", "AbakTools", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == DialogResult.Yes) { flag = true; } } else if (form.MailTo.ToLower() != kontrahent.KontaktEMAIL.ToLower()) { if (MessageBox.Show("Wprowadzony adres email jest różny od adresu w kartotece.\r\nCzy chcesz go podmienić?", "AbakTools", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.Yes) { flag = true; } } if (flag) { using (var t = session.CreateTransaction()) { kontrahent.KontaktEMAIL = form.MailTo.ToLower(); t.Commit(); } session.Save(); } } } } }