private void SetGridView() { GridViewDef view = new GridViewDef(GridViewDef.DefaultViewName); ObservableList <GridColView> viewCols = new ObservableList <GridColView>(); view.GridColsView = viewCols; viewCols.Add(new GridColView() { Field = EmailAttachment.Fields.AttachmentType, WidthWeight = 100, BindingMode = BindingMode.OneTime }); viewCols.Add(new GridColView() { Field = EmailAttachment.Fields.Name, WidthWeight = 200 }); viewCols.Add(new GridColView() { Field = "...", Header = "...", WidthWeight = 20, StyleType = GridColView.eGridColStyleType.Template, CellTemplate = (DataTemplate)this.GridAttachment.Resources["ParamValueExpressionButton"] }); viewCols.Add(new GridColView() { Field = EmailAttachment.Fields.ExtraInformation, WidthWeight = 250 }); viewCols.Add(new GridColView() { Field = EmailAttachment.Fields.ZipIt, WidthWeight = 50, Header = "Zip It", HorizontalAlignment = System.Windows.HorizontalAlignment.Center, StyleType = GridColView.eGridColStyleType.Template, CellTemplate = (DataTemplate)this.GridAttachment.Resources["ReportAttachment"] }); AttachmentsGrid.SetAllColumnsDefaultView(view); AttachmentsGrid.InitViewItems(); }
private void materialFlatButton1_Click_1(object sender, EventArgs e) { try { EmailAttachments emailAttachments = new EmailAttachments(); var attach = emailAttachments.BrowseForFile(); var notAddedList = new List <string>(); if (attach != (null, null)) { foreach (var files in attach.Item1.Zip(attach.Item2, (paths, names) => (paths, names))) { var bytes = File.ReadAllBytes(files.paths); var file = Convert.ToBase64String(bytes); var type = emailAttachments.GetMIMEType(files.paths); if (type == null) { notAddedList.Add(files.names); continue; } SendGrid.Helpers.Mail.Attachment attachment = new SendGrid.Helpers.Mail.Attachment() { Content = file, Filename = files.names, Type = type }; attachmentList.Add(attachment); } if (attachmentList.Count >= 1) { AttachmentsGrid.DataSource = null; AttachmentsGrid.DataSource = attachmentList; AttachmentsGrid.Columns["Content"].Visible = false; AttachmentsGrid.Columns["Type"].Visible = false; AttachmentsGrid.Columns["ContentId"].Visible = false; AttachmentsGrid.Columns["Disposition"].Visible = false; } if (notAddedList.Count >= 1) { string list = null; foreach (var x in notAddedList) { list += x + " "; } var msg = $"Súbor/y {list} nebol pridaný, lebo tento typ súboru nie je možné odoslať emailom. Pre informácie o tom, ktoré " + "súbory nie je možné odoslať otvorte BlockedExtensions.txt"; MessageBox.Show(msg); } AttachmentsGrid.ClearSelection(); } else { return; } }
private void InitAttachmentsGrid() { SetGridView(); AttachmentsGrid.AddButton("Add Report", AddReport); AttachmentsGrid.AddButton("Add File", AddFile); if (runSetActionEmailReport.EmailAttachments == null) { runSetActionEmailReport.EmailAttachments = new ObservableList <EmailAttachment>(); } AttachmentsGrid.DataSourceList = runSetActionEmailReport.EmailAttachments; }
private void InitAttachmentsGrid() { SetGridView(); AttachmentsGrid.AddToolbarTool("@AddHTMLReport_16x16.png", "Add Report", HTMLReportsConfigurationConfigWindow); AttachmentsGrid.AddToolbarTool("@AddScript_16x16.png", "Add File", new RoutedEventHandler(AddFile)); if (runSetActionHTMLReportSendEmail.EmailAttachments == null) { runSetActionHTMLReportSendEmail.EmailAttachments = new ObservableList <EmailAttachment>(); } AttachmentsGrid.RowDoubleClick += HTMLReportsConfigurationConfigWindow; AttachmentsGrid.DataSourceList = runSetActionHTMLReportSendEmail.EmailAttachments; DefaultTemplatePickerCbx_Binding(); }
private void CreateEmailTempBtn_Click(object sender, EventArgs e) { try { using (StudentDBDataContext con = new StudentDBDataContext(conn_str)) { var exists = con.GetTable <EmailTemplate>().Where(x => x.EmailTemplateName == NameOfTempTextBox.Text && x.IdUser == currentUser.Id); if (exists.Count().Equals(0)) { if (!string.IsNullOrEmpty(SubjectTextbox.Text) && !string.IsNullOrEmpty(ContentTextBox.Text) && !string.IsNullOrEmpty(NameOfTempTextBox.Text)) { var newTemp = new EmailTemplate() { EmailTemplateName = NameOfTempTextBox.Text, EmailSubject = SubjectTextbox.Text, EmailContent = ContentTextBox.Text, IdUser = currentUser.Id }; con.EmailTemplates.InsertOnSubmit(newTemp); con.SubmitChanges(); SaveAttachmentsToDB(newTemp); } else { MessageBox.Show("Subjekt alebo správa nie sú vyplnené, pred uložením je potrebné vyplniť tieto polia", "Prázdne polia"); return; } } else { var exisEmail = con.EmailTemplates.Where(x => x.IdUser == currentUser.Id && x.Id == (int)TempGridView.CurrentRow.Cells[2].Value); exisEmail.FirstOrDefault().EmailSubject = SubjectTextbox.Text; exisEmail.FirstOrDefault().EmailContent = ContentTextBox.Text; SaveAttachmentsToDB(exisEmail.FirstOrDefault()); con.SubmitChanges(); } GetEmailTemps(currentUser); AttachmentsGrid.ClearSelection(); } } catch (Exception ex) { Logger logger = new Logger(); logger.LogError(ex); } }
/// <summary> /// Load email template /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void materialFlatButton2_Click(object sender, EventArgs e) { try { using (StudentDBDataContext con = new StudentDBDataContext(conn_str)) { if (TempGridView.Rows.Count <= 0) { MessageBox.Show("Nie je vytvorená žiadna emailová šablóna"); return; } var loadTemplate = con.GetTable <EmailTemplate>().Where(x => x.IdUser == currentUser.Id && x.Id == (int)TempGridView.CurrentRow.Cells[2].Value); foreach (var mail in loadTemplate) { AttachmentsGrid.DataSource = null; ContentTextBox.Text = string.Empty; SubjectTextbox.Text = string.Empty; NameOfTempTextBox.Text = string.Empty; NameOfTempTextBox.Text = mail.EmailTemplateName; ContentTextBox.Text = mail.EmailContent; SubjectTextbox.Text = mail.EmailSubject; AttachmentsGrid.DataSource = mail.Attachments; } AttachmentsGrid.Columns["FilePath"].Visible = false; AttachmentsGrid.Columns["IdUSer"].Visible = false; AttachmentsGrid.Columns["IdEmailTemplate"].Visible = false; AttachmentsGrid.Columns["Id"].Visible = false; AttachmentsGrid.Columns["EmailTemplate"].Visible = false; AttachmentsGrid.Columns["User"].Visible = false; AttachmentsGrid.ClearSelection(); editMode = true; } } catch (Exception ex) { Logger logger = new Logger(); logger.LogError(ex); } }
private void SetGridView() { GridViewDef view = new GridViewDef(GridViewDef.DefaultViewName); ObservableList <GridColView> viewCols = new ObservableList <GridColView>(); view.GridColsView = viewCols; viewCols.Add(new GridColView() { Field = EmailAttachment.Fields.AttachmentType, WidthWeight = 50, BindingMode = BindingMode.OneTime }); viewCols.Add(new GridColView() { Field = EmailAttachment.Fields.Name, WidthWeight = 300 }); viewCols.Add(new GridColView() { Field = EmailAttachment.Fields.ZipIt, WidthWeight = 50, StyleType = GridColView.eGridColStyleType.CheckBox }); AttachmentsGrid.SetAllColumnsDefaultView(view); AttachmentsGrid.InitViewItems(); }
//private void materialFlatButton1_Click(object sender, EventArgs e) //{ // this.Close(); //} private void AddEmailTemplateAttachmentsBtn_Click(object sender, EventArgs e) { try { EmailAttachments emailAttachments = new EmailAttachments(); var attach = emailAttachments.BrowseForFile(); var notAddedList = new List <string>(); if (attach != (null, null)) { foreach (var files in attach.Item1.Zip(attach.Item2, (paths, names) => (paths, names))) { var type = emailAttachments.GetMIMEType(files.paths); if (type == null) { notAddedList.Add(files.names); continue; } Attachment attachment = new Attachment() { FilePath = files.paths, FileName = files.names, IdUser = currentUser.Id, }; if (editMode) { using (StudentDBDataContext con = new StudentDBDataContext(conn_str)) { var att = attachment; att.IdEmailTemplate = (int)TempGridView.CurrentRow.Cells[2].Value; var emailTemp = con.GetTable <EmailTemplate>().First(x => x.Id == (int)TempGridView.CurrentRow.Cells[2].Value); if (!AttachmentExists(att, emailTemp)) { con.Attachments.InsertOnSubmit(att); con.SubmitChanges(); AttachmentsGrid.DataSource = null; AttachmentsGrid.DataSource = con.GetTable <Attachment>().Where(x => x.IdEmailTemplate == (int)TempGridView.CurrentRow.Cells[2].Value); AttachmentsGrid.Columns["FilePath"].Visible = false; AttachmentsGrid.Columns["IdUSer"].Visible = false; AttachmentsGrid.Columns["IdEmailTemplate"].Visible = false; AttachmentsGrid.Columns["Id"].Visible = false; AttachmentsGrid.Columns["EmailTemplate"].Visible = false; AttachmentsGrid.Columns["User"].Visible = false; if (notAddedList.Count >= 1) { string list = null; foreach (var x in notAddedList) { list += x + " "; } var msg = $"Súbor/y {list} nebol pridaný, lebo tento typ súboru nie je možné odoslať emailom. Pre informácie o tom, ktoré " + "súbory nie je možné odoslať otvorte BlockedExtensions.txt"; MessageBox.Show(msg); } } return; } } else if (!attachmentList.Contains(attachment)) { attachmentList.Add(attachment); } } if (attachmentList.Count >= 1) { AttachmentsGrid.DataSource = null; AttachmentsGrid.DataSource = attachmentList; AttachmentsGrid.Columns["FilePath"].Visible = false; AttachmentsGrid.Columns["IdUSer"].Visible = false; AttachmentsGrid.Columns["IdEmailTemplate"].Visible = false; AttachmentsGrid.Columns["Id"].Visible = false; AttachmentsGrid.Columns["EmailTemplate"].Visible = false; AttachmentsGrid.Columns["User"].Visible = false; } if (notAddedList.Count >= 1) { string list = null; foreach (var x in notAddedList) { list += x + " "; } var msg = $"Súbor/y {list} nebol pridaný, lebo tento typ súboru nie je možné odoslať emailom. Pre informácie o tom, ktoré " + "súbory nie je možné odoslať otvorte BlockedExtensions.txt"; MessageBox.Show(msg); } } else { return; } AttachmentsGrid.ClearSelection(); }