private void EditEmail() { if (lbEMails.Items.Count == 0) { return; } if (tbFleetID.Text.Trim().Length == 0) { MessageBox.Show("Please provide fleet code", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (WasIDChanged()) { var rst = MessageBox.Show("Fleet code was changed. It is necessary to save new code before edit email. \n" + "Would you like to save code now?", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (rst != DialogResult.Yes) { MessageBox.Show("You are unable to edit email address without fleet code saving", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (!SaveNewID()) { MessageBox.Show("Failed to save new ID", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } FrmFleetEmail form = new FrmFleetEmail(this.Font, this.Icon); form.fleetID = tbFleetID.Text.Trim(); form.fleetEmail = lbEMails.SelectedItem.ToString(); form.EMails = lbEMails; var rslt = form.ShowDialog(); if (rslt == DialogResult.OK) { if (form.needSave) { OleDbCommand cmd = new OleDbCommand("", connection); cmd.CommandText = "update FLEET_EMAILS set \n" + "FLEET_EMAIL='" + MainForm.StrToSQLStr(form.fleetEmail) + "' \n" + "where FLEET_ID='" + MainForm.StrToSQLStr(_fleetID) + "' \n" + "and FLEET_EMAIL='" + MainForm.StrToSQLStr(lbEMails.SelectedItem.ToString()) + "'"; MainForm.cmdExecute(cmd); FillEmails(); UpdateFleetEmails(); } } }
private void btnNew_Click(object sender, EventArgs e) { if (tbFleetID.Text.Trim().Length == 0) { MessageBox.Show("Please provide fleet code", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (WasIDChanged()) { var rst = MessageBox.Show("Fleet code was changed. It is necessary to save new code before adding new email. \n" + "Would you like to save code now?", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (rst != DialogResult.Yes) { MessageBox.Show("You are unable to add email address without fleet code saving", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (!SaveNewID()) { MessageBox.Show("Failed to save new ID", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } FrmFleetEmail form = new FrmFleetEmail(this.Font, this.Icon); form.fleetID = tbFleetID.Text.Trim(); form.fleetEmail = ""; form.EMails = lbEMails; var rslt = form.ShowDialog(); if (rslt == DialogResult.OK) { if (form.needSave) { OleDbCommand cmd = new OleDbCommand("", connection); cmd.CommandText = "insert into FLEET_EMAILS (FLEET_ID, FLEET_EMAIL) \n" + "values('" + MainForm.StrToSQLStr(_fleetID) + "','" + MainForm.StrToSQLStr(form.fleetEmail) + "')"; MainForm.cmdExecute(cmd); FillEmails(); UpdateFleetEmails(); } } }