private void btnNew_Click(object sender, EventArgs e) { if (!MainForm.isPowerUser) { return; } FormMemorandum form = new FormMemorandum(); if (form.ShowDialog() == DialogResult.OK) { OleDbCommand cmd = new OleDbCommand("", connection); cmd.CommandText = "insert into MEMORANDUMS (MEMORANDUM_TYPE) \n" + "values('" + MainForm.StrToSQLStr(form.memorandumText) + "')"; if (MainForm.cmdExecute(cmd) < 0) { MessageBox.Show("Failed to create new record", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } FillList(); MainForm.LocateGridRecord(form.memorandumText, "MEMORANDUM_TYPE", 1, dgvMemorandums); } }
private void EditRecord() { if (!MainForm.isPowerUser) { return; } if (dgvMemorandums.Rows.Count == 0) { return; } FormMemorandum form = new FormMemorandum(); int id = Convert.ToInt32(dgvMemorandums.CurrentRow.Cells["MEMORANDUM_ID"].Value); string mem = dgvMemorandums.CurrentRow.Cells["MEMORANDUM_TYPE"].Value.ToString(); form.memorandumId = id; form.memorandumText = mem; if (form.ShowDialog() == DialogResult.OK) { if (string.Compare(mem, form.memorandumText) != 0) { OleDbCommand cmd = new OleDbCommand("", connection); cmd.CommandText = "update MEMORANDUMS set \n" + "MEMORANDUM_TYPE='" + MainForm.StrToSQLStr(form.memorandumText) + "' \n" + "where MEMORANDUM_ID=" + id.ToString(); if (MainForm.cmdExecute(cmd) < 0) { MessageBox.Show("Failed to update record", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } FillList(); MainForm.LocateGridRecord(form.memorandumText.Trim(), "MEMORANDUM_TYPE", 1, dgvMemorandums); } } }