private void Change() { DbConnection.checkConnection(); if (textBoxCurrent.Text == "" || textBoxnew.Text == "" || textBoxrepass.Text == "") { Verification.Input(); } else if (textBoxnew.Text != textBoxrepass.Text) { Verification.PasswordMatch(); } else { try { DbConnection.con.Open(); SqlCommand cmd = new SqlCommand("SELECT Password FROM Admin WHERE Password='******';", DbConnection.con); SqlDataReader read; read = cmd.ExecuteReader(); if (read.Read()) { DbConnection.checkConnection(); DbConnection.con.Open(); SqlCommand change = new SqlCommand(); change.Connection = DbConnection.con; change.CommandType = CommandType.StoredProcedure; change.CommandText = "UpdatePassword"; change.Parameters.AddWithValue("@password", textBoxnew.Text); change.ExecuteNonQuery(); DbConnection.con.Close(); Verification.Update(); } else { MessageBox.Show("Invalid Current password", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); DbConnection.con.Close(); } } catch (Exception ex) { MessageBox.Show(ex.Message); } } }
private void btnupdate_Click(object sender, EventArgs e) { if (IdUpdate.Text == "") { MessageBox.Show("Please select Row that you want update", "Selection error", MessageBoxButtons.OK, MessageBoxIcon.Stop); } else { Gender(); Account(); if (textBoxName.Text == "" || TextBoxcnic.Text == "" || textBoxaddress.Text == "" || textBoxcity.Text == "" || textBoxmail.Text == "" || textBoxphone.Text == "" || comboBoxjobType.Text == "" || comboBoxempType.Text == "") { Verification.Input(); } //else if (imageLocation == "") //{ // Verification.Picture(); //} else if (gender == "") { Verification.Gender(); } else if (account == "") { Verification.AccountStatus(); } else { try { if (DbConnection.con.State != ConnectionState.Open) { DbConnection.con.Open(); } //byte[] image = null; //FileStream fs = new FileStream(imageLocation, FileMode.Open, FileAccess.Read); //BinaryReader br = new BinaryReader(fs); //image = br.ReadBytes((int)fs.Length); ////////////////////////////////////////////////////////////////////////////// SqlCommand cmd = new SqlCommand(); cmd.Connection = DbConnection.con; cmd.CommandType = CommandType.StoredProcedure; cmd.CommandText = "EmpUpdate"; cmd.Parameters.AddWithValue("@name", textBoxName.Text); //cmd.Parameters.AddWithValue("@cnic", TextBoxcnic.Text); cmd.Parameters.AddWithValue("@cnic1", IdUpdate.Text); //cmd.Parameters.AddWithValue("@gender", gender); cmd.Parameters.AddWithValue("@address", textBoxaddress.Text); cmd.Parameters.AddWithValue("@city", textBoxcity.Text); cmd.Parameters.AddWithValue("@accountStatus", account); cmd.Parameters.AddWithValue("@email", textBoxmail.Text); cmd.Parameters.AddWithValue("@mobile", textBoxphone.Text); cmd.Parameters.AddWithValue("@dob", dateTimedob.Text); cmd.Parameters.AddWithValue("@joinDate", dateTimejoin.Text); cmd.Parameters.AddWithValue("@jobType", comboBoxjobType.Text); cmd.Parameters.AddWithValue("@empType", comboBoxempType.Text); //cmd.Parameters.Add(new SqlParameter("@picture", image)); //cmd.Parameters.Add(new SqlParameter("@picture", image)); cmd.ExecuteNonQuery(); Verification.Update(); DbConnection.con.Close(); gridView(); Reset(); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } }