private void SaveButton_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(DeptNameTextBox.Text)) { MessageBox.Show("Opps! Something went wrong!", "There's an Empty Field." + Environment.NewLine + "Please Fill-up the form and Try again!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); DeptNameTextBox.Focus(); } else { /* * int adminid = 1; * string add = "Add"; * int id = 1; * string comment = "Added Successfully"; */ cmd = new OleDbCommand("insert into department(deptname) values(@deptname)", con); //cmd1 = new OleDbCommand("insert into audittrail(action,tableid,comment) values(@add,@id,@comment)", con); con.Open(); cmd.Parameters.AddWithValue("@deptname", DeptNameTextBox.Text); //cmd1.Parameters.AddWithValue("@add",add); //cmd1.Parameters.AddWithValue("@id", id); //cmd1.Parameters.AddWithValue("@comment", comment); cmd.ExecuteNonQuery(); //cmd1.ExecuteNonQuery(); con.Close(); MessageBox.Show("Record Saved Successfully!", "Success!", MessageBoxButtons.OK, MessageBoxIcon.Information); Form1 form = new Form1(); this.Hide(); form.Show(); } }
private void CancelButton_Click(object sender, EventArgs e) { if (string.IsNullOrWhiteSpace(DeptNameTextBox.Text)) { this.Hide(); } else { var result = MessageBox.Show("There are still unsaved changes." + Environment.NewLine + "are you sure you want to continue?", "Textbox has been filled!", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result == DialogResult.Yes) { this.Close(); } else if (result == DialogResult.No) { DeptNameTextBox.Focus(); } } }
private void SaveButton_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(DeptNameTextBox.Text)) { MessageBox.Show("There's an Empty Field." + Environment.NewLine + "Please Fill-up the form and Try again!", "Opps! Something went wrong!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); DeptNameTextBox.Focus(); } else { string adminid = "admin"; string action = "Add Department Record"; string table = "dept"; string eid = "N/A"; string today = DateTime.Now.ToString("dd/MM/yyyy h:mm tt"); const string sql1 = "insert into audittrail (adminname,[action],[tablename],eid,[accesstime]) values (@adminname,@action,@tablename,@eid,@accesstime)"; cmd1 = new OleDbCommand(sql1, con); cmd1.Parameters.AddWithValue("@adminname", adminid); cmd1.Parameters.AddWithValue("[@action]", action); cmd1.Parameters.AddWithValue("[@tablename]", table); cmd1.Parameters.AddWithValue("[@eid]", eid); cmd1.Parameters.AddWithValue("[@accesstime]", today); const string sql = "insert into dept(dept) values(@deptname)"; cmd = new OleDbCommand(sql, Con); Con.Open(); cmd.Parameters.AddWithValue("@deptname", DeptNameTextBox.Text); cmd1.ExecuteNonQuery(); int result = cmd.ExecuteNonQuery(); if (result > 0) { MessageBox.Show("Record Saved Successfully!", "Success!", MessageBoxButtons.OK, MessageBoxIcon.Information); Con.Close(); DeptForm form = new DeptForm(); form.Show(); Hide(); } } }