private void addUser() { string username = txtUserName.Text; string role = cmbRole.Text; string block = cmbBlock.Text; string password = "******"; int block_status = 0; if (username == "") { ErrorMsg.msg("Username can't be empty"); Error er = new Error(); er.ShowDialog(); return; } if (role == "") { ErrorMsg.msg("Please select role"); Error er = new Error(); er.ShowDialog(); return; } if (block == "") { ErrorMsg.msg("Please select block status"); Error er = new Error(); er.ShowDialog(); return; } else { if (block == "Block") { block_status = 1; } else if (block == "Unblock") { block_status = 0; } } con = new MySqlConnection(cs); string query = "insert into user(username,password,role,block)values(@user,@pass,@role,@block)"; try { con.Open(); MySqlCommand cmd = new MySqlCommand(query, con); cmd.Parameters.AddWithValue("@user", username); cmd.Parameters.AddWithValue("@block", block_status); cmd.Parameters.AddWithValue("@role", role); cmd.Parameters.AddWithValue("@pass", password); int a = cmd.ExecuteNonQuery(); if (a > 0) { getUers(); resetUser(); ErrorMsg.msg("User add succesfully!!"); Error er = new Error(); er.ShowDialog(); } } catch (MySqlException) { ErrorMsg.msg("Check internet connection"); Error er = new Error(); er.ShowDialog(); return; } finally { if (con.State == ConnectionState.Open) { con.Close(); } } }
private void updateCustomer() { string name = txtNameUP.Text; string device = txtDevice.Text; string note = txtNote.Text; string fault = txtFault.Text; string number = txtNumber.Text; string date = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"); string status = cmbStatus.Text; string query; if (name == "") { ErrorMsg.msg("Please enter name"); Error er = new Error(); er.ShowDialog(); return; } if (device == "") { ErrorMsg.msg("Please enter device"); Error er = new Error(); er.ShowDialog(); return; } if (note == "") { note = "No note"; } if (fault == "") { ErrorMsg.msg("Please enter fault"); Error er = new Error(); er.ShowDialog(); return; } if (number != "") { if (number.Length != 10) { ErrorMsg.msg("Number should be 10 digit"); Error er = new Error(); er.ShowDialog(); return; } } else { ErrorMsg.msg("Please enter number"); Error er = new Error(); er.ShowDialog(); return; } if (status == "" || status == "--Select--") { ErrorMsg.msg("Please select status"); Error er = new Error(); er.ShowDialog(); return; } try { con = new MySqlConnection(cs); query = "update customer set Name=@name,Device=@device,Fault=@fault,Paid=@paid,status=@status,number=@number,Close_date=@close where id = @id"; con.Open(); MySqlCommand cmd = new MySqlCommand(query, con); cmd.Parameters.AddWithValue("@name", name); cmd.Parameters.AddWithValue("@device", device); cmd.Parameters.AddWithValue("@fault", fault); cmd.Parameters.AddWithValue("@paid", Convert.ToInt32(txtPaid.Text)); if (status == "Complete") { cmd.Parameters.AddWithValue("@status", 1); cmd.Parameters.AddWithValue("@close", date); } else { cmd.Parameters.AddWithValue("@status", 0); cmd.Parameters.AddWithValue("@close", "-"); } cmd.Parameters.AddWithValue("@number", Convert.ToInt64(number)); cmd.Parameters.AddWithValue("@id", _cust_id); int a = cmd.ExecuteNonQuery(); if (a > 0) { ErrorMsg.msg("Update successfully"); Error er = new Error(); er.ShowDialog(); } } catch (MySqlException) { MessageBox.Show("No internet connection"); } finally { if (con.State == ConnectionState.Open) { con.Close(); this.Hide(); } } }
private void updateUser() { string username = txtUserName.Text; string role = cmbRole.Text; string block = cmbBlock.Text; int block_status = 0; if (username == "") { ErrorMsg.msg("Username can't be empty"); Error er = new Error(); er.ShowDialog(); return; } if (role == "") { ErrorMsg.msg("Please select role"); Error er = new Error(); er.ShowDialog(); return; } if (block == "") { ErrorMsg.msg("Please select block status"); Error er = new Error(); er.ShowDialog(); return; } else { if (block == "Block") { block_status = 1; } else if (block == "Unblock") { block_status = 0; } } con = new MySqlConnection(cs); string query = "update user set username=@user,block=@block,role=@role where id=@id"; try { con.Open(); MySqlCommand cmd = new MySqlCommand(query, con); cmd.Parameters.AddWithValue("@user", username); cmd.Parameters.AddWithValue("@block", block_status); cmd.Parameters.AddWithValue("@role", role); cmd.Parameters.AddWithValue("@id", user_id); int a = cmd.ExecuteNonQuery(); if (a > 0) { getUers(); resetUser(); ErrorMsg.msg("Update succesfully!!"); Error er = new Error(); er.ShowDialog(); } } catch (MySqlException) { ErrorMsg.msg("Check internet connection"); Error er = new Error(); er.ShowDialog(); return; } finally { if (con.State == ConnectionState.Open) { con.Close(); } } }
private void loginForm(string user, string pass) { con = new MySqlConnection(cs); string dd = DateTime.Now.ToString("dd-MM-yyyy hh:mm"); string query = "SELECT * FROM user where binary username=@user and binary password=@pass limit 1"; con.Open(); try { MySqlCommand cmd = new MySqlCommand(query, con); cmd.Parameters.AddWithValue("@user", user); cmd.Parameters.AddWithValue("@pass", pass); MySqlDataReader dr = cmd.ExecuteReader(); dr.Read(); if (dr.HasRows) { if (dr.GetInt32(5) == 0) { user_name = dr.GetString(1); id = dr.GetInt32(0); last_login = dr.GetString(4); user_type = dr.GetString(3); MySqlConnection con2 = new MySqlConnection(cs); con2.Open(); string query1 = "update user set last_login=@dt"; MySqlCommand cd = new MySqlCommand(query1, con2); cd.Parameters.AddWithValue("dt", dd); int a = cd.ExecuteNonQuery(); if (a > 0) { Form1 f1 = new Form1(); this.Hide(); f1.Show(); } con2.Close(); } else { ErrorMsg.msg("You are blocked"); Error er = new Error(); er.ShowDialog(); return; } } else { ErrorMsg.msg("Enter valid credential"); Error er = new Error(); er.ShowDialog(); return; } } catch (MySqlException) { ErrorMsg.msg("Check internet connection"); Error er = new Error(); er.ShowDialog(); return; } finally { if (con.State == ConnectionState.Open) { con.Close(); } } }