private void btnedite_Click(object sender, EventArgs e) { // updateuser_level(); if (TxtName.Equals("") || TxtFamily.Text.Equals("") || TxtCodeMeli.Text.Equals("") || TxtTavalod.Text.Equals("") || TxtMadrak.Text.Equals("") || TxtPhone.Text.Equals("") || TxtUsername.Text.Equals("") || CmbSatheDastrasi.Text.Equals("") || TxtPassword.Text.Equals("")) { MessageBox.Show(this, "اطلاعات ناقص هستند", "هشدار", MessageBoxButtons.OK, MessageBoxIcon.Stop, MessageBoxDefaultButton.Button1, MessageBoxOptions.RtlReading); return; } //try //{ //----------------------------------------------------- Classconn clscon = new Classconn(); SqlConnection con = new SqlConnection(clscon.connstr); //SqlCommand cmd = new SqlCommand("UPDATE tbl_user SET (name,family,sale_tavalod,shomare_meli,email,madrak,telephone,username,password) Values (@name,@family,@sale_tavalod,@shomare_meli,@email,@madrak,@telephone,@username,@password) WHERE id_user = id_user ", con); SqlCommand cmd = new SqlCommand("update tbl_user set name=@name,family=@family,sale_tavalod=@sale_tavalod,shomare_meli=@shomare_meli,email=@email,madrak=@madrak,telephone=@telephone,username=@username,password=@password where id_user= @id_user", con); cmd.CommandType = CommandType.Text; cmd.Parameters.AddWithValue("name", TxtName.Text); cmd.Parameters.AddWithValue("family", TxtFamily.Text); cmd.Parameters.AddWithValue("sale_tavalod", TxtTavalod.Text); cmd.Parameters.AddWithValue("shomare_meli", TxtCodeMeli.Text); cmd.Parameters.AddWithValue("email", TxtEmail.Text); cmd.Parameters.AddWithValue("madrak", TxtMadrak.Text); cmd.Parameters.AddWithValue("telephone", TxtPhone.Text); cmd.Parameters.AddWithValue("username", TxtUsername.Text); cmd.Parameters.AddWithValue("password", TxtPassword.Text); cmd.Parameters.AddWithValue("id_user", label13.Text); //cmd.Parameters.AddWithValue("id", label14.Text); //-------------------------------------------------- con.Open(); cmd.ExecuteNonQuery(); updateuser_level(); MessageBox.Show(this, "تغییرات با موفقیت به ثبت رسید", "اتمام عملیات", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, MessageBoxOptions.RtlReading); BtnOk.Enabled = true; BtnEdit.Enabled = false; TxtName.Text = ""; TxtFamily.Text = ""; TxtTavalod.Text = ""; TxtCodeMeli.Text = ""; TxtEmail.Text = ""; TxtMadrak.Text = ""; TxtPhone.Text = ""; TxtUsername.Text = ""; TxtPassword.Text = ""; this.view_user_levelTableAdapter.Fill(this.barghDataSet2.View_user_level); con.Close(); //} //catch //{ // MessageBox.Show(this, "برنامه قادر به ذخیره سازی اطلاعات نیست", "هشدار", MessageBoxButtons.OK, MessageBoxIcon.Stop, MessageBoxDefaultButton.Button1, MessageBoxOptions.RtlReading); //} }
private void BtnOk_Click_1(object sender, EventArgs e) { if (TxtName.Equals("") || TxtFamily.Text.Equals("") || TxtCodeMeli.Text.Equals("") || TxtTavalod.Text.Equals("") || TxtMadrak.Text.Equals("") || TxtPhone.Text.Equals("") || TxtUsername.Text.Equals("") || CmbSatheDastrasi.Text.Equals("") || TxtPassword.Text.Equals("")) { MessageBox.Show(this, "اطلاعات ناقص هستند", "هشدار", MessageBoxButtons.OK, MessageBoxIcon.Stop, MessageBoxDefaultButton.Button1, MessageBoxOptions.RtlReading); return; } //----------------------------------------------------------------- Classconn clscon = new Classconn(); SqlConnection con = new SqlConnection(clscon.connstr); SqlCommand com = new SqlCommand(); int i = 0; com = new SqlCommand("SELECT COUNT(*) FROM View_user_level WHERE username= '******' and password='******' ", con); if (con.State == ConnectionState.Closed) { con.Open(); i = (int)com.ExecuteScalar(); }//end if con.Close(); if (i > 0) { MessageBox.Show(this, "کاربر با این مشخصات قبلا ثبت نام شده است", "هشدار", MessageBoxButtons.OK, MessageBoxIcon.Stop, MessageBoxDefaultButton.Button1, MessageBoxOptions.RtlReading); return; } //------------------------------------------------------------ string cmdString = "INSERT INTO tbl_user (name,family,sale_tavalod,shomare_meli,email,madrak,telephone,username,password) Values (@name,@family,@sale_tavalod,@shomare_meli,@email,@madrak,@telephone,@username,@password)"; string connString = clscon.connstr; using (SqlConnection conn = new SqlConnection(connString)) { using (SqlCommand comm = new SqlCommand()) { comm.Connection = conn; //comm.CommandText = cmdString; comm.CommandText = cmdString; comm.Parameters.AddWithValue("name", TxtName.Text); comm.Parameters.AddWithValue("family", TxtFamily.Text); comm.Parameters.AddWithValue("sale_tavalod", TxtTavalod.Text); comm.Parameters.AddWithValue("shomare_meli", TxtCodeMeli.Text); comm.Parameters.AddWithValue("email", TxtEmail.Text); comm.Parameters.AddWithValue("madrak", TxtMadrak.Text); comm.Parameters.AddWithValue("telephone", TxtPhone.Text); comm.Parameters.AddWithValue("username", TxtUsername.Text); comm.Parameters.AddWithValue("password", TxtPassword.Text); try { conn.Open(); comm.ExecuteNonQuery(); //insert_level(); insertuser_level(); MessageBox.Show(this, "اطلاعات با موفقیت به ثبت رسید", "اتمام عملیات", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, MessageBoxOptions.RtlReading); //Bind(); this.view_user_levelTableAdapter.Fill(this.barghDataSet2.View_user_level); TxtName.Text = ""; TxtFamily.Text = ""; TxtTavalod.Text = ""; TxtCodeMeli.Text = ""; TxtEmail.Text = ""; TxtMadrak.Text = ""; TxtPhone.Text = ""; TxtUsername.Text = ""; TxtPassword.Text = ""; ////textBox9.Text = textBox1.Text; //comboBox6.Text = comboBox3.Text; //Bind(); //Clear(); } catch { MessageBox.Show(this, "برنامه قادر به ذخیره سازی اطلاعات نیست", "هشدار", MessageBoxButtons.OK, MessageBoxIcon.Stop, MessageBoxDefaultButton.Button1, MessageBoxOptions.RtlReading); } } } }