private void btnNew_Click(object sender, EventArgs e) { if (!MainForm.isPowerUser) { return; } FormInspectionType form = new FormInspectionType(); if (form.ShowDialog() == DialogResult.OK) { OleDbCommand cmd = new OleDbCommand("", connection); cmd.CommandText = "insert into INSPECTION_TYPES (INSPECTION_TYPE) \n" + "values('" + MainForm.StrToSQLStr(form.inspectionType) + "')"; if (MainForm.cmdExecute(cmd) >= 0) { FillTypes(); MainForm.LocateGridRecord(form.inspectionType, "INSPECTION_TYPE", 1, dgvInspectionTypes); } else { MessageBox.Show("Failed to create new record", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
private void EditRecord() { if (!MainForm.isPowerUser) { return; } if (dgvInspectionTypes.Rows.Count == 0) { return; } FormInspectionType form = new FormInspectionType(); form.inspectionType = dgvInspectionTypes.CurrentRow.Cells["INSPECTION_TYPE"].Value.ToString(); int id = Convert.ToInt32(dgvInspectionTypes.CurrentRow.Cells["INSPECTION_TYPE_ID"].Value); form.InspectionTypeID = id; if (form.ShowDialog() == DialogResult.OK) { OleDbCommand cmd = new OleDbCommand("", connection); cmd.CommandText = "update INSPECTION_TYPES set \n" + "INSPECTION_TYPE='" + MainForm.StrToSQLStr(form.inspectionType) + "' \n" + "where \n" + "INSPECTION_TYPE_ID=" + id.ToString(); if (MainForm.cmdExecute(cmd) >= 0) { FillTypes(); MainForm.LocateGridRecord(form.inspectionType, "INSPECTION_TYPE_ID", 1, dgvInspectionTypes); } else { MessageBox.Show("Failed to update record", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }