private void ReadFromAppSettings() { InitComponents(); var envId = ((ComboboxItem)comboBoxEnv.SelectedItem).Value; using (var dbContext = new AlisDbContext("CompactDBContext")) { var queryResult = dbContext.SavedCredentialses.Find(envId); if (queryResult == null) { return; } textBoxServerAddress.Text = queryResult.Host; if (!queryResult.Saved) { return; } checkBoxSave.Checked = queryResult.Saved; textBoxPassword.Text = string.IsNullOrEmpty(queryResult.Password) ? "" : queryResult.Password.Unprotect(); textBoxUser.Text = queryResult.Username; } }
private void MainForm_Load(object sender, EventArgs e) { SavedCredentials restoreFromDb; using (var db = new AlisDbContext("CompactDBContext")) { //db.Database.Initialize(true); restoreFromDb = db.SavedCredentialses.FirstOrDefault(i => i.ChoseLast && i.Saved); } Global.PropSetter(restoreFromDb); }
private void PopulateDistList() { inDistList.DataSource = null; using (var db = new AlisDbContext("CompactDBContext")) { var inList = db.Distributions.Where(dist => dist.DistFlag).ToList(); var bs = new BindingSource { DataSource = inList }; inDistList.DisplayMember = "DisplayMember"; inDistList.DataSource = bs; } }
private void removeMemberButton_Click(object sender, EventArgs e) { using (var db = new AlisDbContext()) { var foundItemFromDb = db.Distributions.FirstOrDefault(i => i.Id == ((Distribution)inDistList.SelectedItem).Id); if (foundItemFromDb != null) { db.Distributions.Remove(foundItemFromDb); db.SaveChanges(); PopulateDistList(); ClearBoxes(); } } }
private void saveButton_Click(object sender, EventArgs e) { if (!ValidateForm(false)) { return; } if (string.IsNullOrEmpty(senderUserTxtBox.Text)) { errorProvider1.SetError(senderUserTxtBox, "field required!"); tabControl1.SelectedTab = tabControl1.TabPages["distPage"]; senderUserTxtBox.Focus(); return; } var envId = ((ComboboxItem)comboBoxEnv.SelectedItem).Value; var user = textBoxUser.Text; var pass = textBoxPassword.Text.Protect(); var envName = ((ComboboxItem)comboBoxEnv.SelectedItem).Text; var serverAddress = textBoxServerAddress.Text; var db = (string)comboBoxDb.SelectedItem; UpdateConnString(); using (var dbContext = new AlisDbContext()) { dbContext.SavedCredentialses.ToList().ForEach(c => c.ChoseLast = false); dbContext.SaveChanges(); var toUpdate = dbContext.SavedCredentialses.Find(envId); if (toUpdate != null) { toUpdate.Username = user; toUpdate.Password = pass; toUpdate.Host = serverAddress; toUpdate.Db = db; toUpdate.Name = envName; toUpdate.ConnString = _connString.ToString(); toUpdate.ChoseLast = true; toUpdate.Saved = checkBoxSave.Checked; if (checkBoxSave.Checked) { dbContext.SaveChanges(); } } Global.PropSetter(toUpdate); dbContext.SaveChanges(); } Settings.Default.SenderMail = senderUserTxtBox.Text; Settings.Default.SharingFolder = sharingFolderTxtBox.Text; Settings.Default.Save(); Close(); }
private void button1_Click(object sender, EventArgs e) { var confirmResult = MessageBox.Show($@"Send Report To Distribution List?", @"Confirm Send", MessageBoxButtons.YesNo); if (confirmResult == DialogResult.No) { return; } distributionProcessTxt.Visible = true; distributionProcessTxt.Text += @"Creating Report..."; var attachment = ExportToExcel(); distributionProcessTxt.Text += $@"Done!{Environment.NewLine}"; if (!string.IsNullOrEmpty(attachment)) { List <string> to; using (var db = new AlisDbContext()) { to = db.Distributions.Where(d => d.DistFlag).Select(d => d.EmailAddress).ToList(); } if (to.Any()) { distributionProcessTxt.Text += @"Sending Mails To Distribution List..."; var body = $@"Hello, Attached the daily batches error report for: Date: {DateTime.Today:D} Environment: {Global.SavedCredentials.Name} DB: {Global.SavedCredentials.Db}"; MailModule.SendEmailFromAccount( new Microsoft.Office.Interop.Outlook.Application(), $@"Daily Report - {Global.SavedCredentials.Name}, {Global.SavedCredentials.Db} - { DateTime.Today :D}", to, body, "*****@*****.**", attachment); MessageBox.Show(@"Mail Sent!"); } else { distributionProcessTxt.Text += $@"Empty Distribution List, Mail Was Not Sent, Please Add Receipients On Settings."; } } distributionProcessTxt.Visible = false; }
private void refreshButton_Click(object sender, EventArgs e) { var confirmResult = MessageBox.Show(@"To Delete Saved Credentials??", @"Confirm Delete!", MessageBoxButtons.YesNo); if (confirmResult == DialogResult.Yes) { using (var dbContext = new AlisDbContext()) { dbContext.SavedCredentialses.ToList().ForEach(cred => cred.Saved = false); dbContext.SaveChanges(); } InitComponents(); } }
private void addMemberButton_Click(object sender, EventArgs e) { if (!ValidateAddMember()) { return; } if (string.IsNullOrEmpty(idTextBox.Text) || idTextBox.Value < 0) { Distribution dist = new Distribution { FirstName = firstNameTextBox.Text, LastName = lastNameTextBox.Text, EmailAddress = emailTextBox.Text, DistFlag = true }; dist.DisplayMember = dist.ToString(); using (var db = new AlisDbContext()) { db.Distributions.Add(dist); try { db.SaveChanges(); } catch (DbUpdateException) { MessageBox.Show(@"Email Address Already Exists, Please Add A Different One", @"Duplicate Email Error"); } } } else { using (var db = new AlisDbContext()) { var foundItemFromDb = db.Distributions.FirstOrDefault(i => i.Id.ToString().Equals(idTextBox.Text)); if (foundItemFromDb != null) { foundItemFromDb.FirstName = firstNameTextBox.Text; foundItemFromDb.LastName = lastNameTextBox.Text; foundItemFromDb.EmailAddress = emailTextBox.Text; foundItemFromDb.DisplayMember = foundItemFromDb.ToString(); } db.SaveChanges(); } } PopulateDistList(); ClearBoxes(); }