public bool insertClient(String fname, String lname, String phon, String country) { MySqlCommand command = new MySqlCommand(); String insertQuery = "INSERT INTO `clientperson`( `first_name`, `last_name`, `phone`, `country`) VALUES (@fnm,@lfm,@phn,@cnt)"; command.CommandText = insertQuery; command.Connection = conn.getConnection(); command.Parameters.Add("@fnm", MySqlDbType.VarChar).Value = fname; command.Parameters.Add("@lfm", MySqlDbType.VarChar).Value = lname; command.Parameters.Add("@phn", MySqlDbType.VarChar).Value = phon; command.Parameters.Add("@cnt", MySqlDbType.VarChar).Value = country; conn.openConnection(); if (command.ExecuteNonQuery() == 1) { conn.closeConnection(); return(true); } else { conn.openConnection(); return(false); } }
public bool editPassword(String username, String password, String passwordnew) { MySqlCommand command = new MySqlCommand(); String editQuery = "UPDATE `users` SET `password`= @passnew WHERE `username`=@uname AND `password`=@pass"; command.CommandText = editQuery; command.Connection = conn.getConnection(); command.Parameters.Add("@uname", MySqlDbType.VarChar).Value = username; command.Parameters.Add("@pass", MySqlDbType.VarChar).Value = password; command.Parameters.Add("@passnew", MySqlDbType.VarChar).Value = passwordnew; conn.openConnection(); if (command.ExecuteNonQuery() == 1) { conn.closeConnection(); return(true); } else { conn.openConnection(); return(false); } }
public bool insertProducts(String name, String cate, String price, MemoryStream picture) { MySqlCommand command = new MySqlCommand(); String insertProducts = "INSERT INTO `product`(`name`,`category`, `price`, `image`) VALUES (@name,@cate,@price,@image)"; command.CommandText = insertProducts; command.Connection = conn.getConnection(); command.Parameters.Add("@name", MySqlDbType.VarChar).Value = name; command.Parameters.Add("@cate", MySqlDbType.VarChar).Value = cate; command.Parameters.Add("@price", MySqlDbType.VarChar).Value = price; command.Parameters.Add("@image", MySqlDbType.LongBlob).Value = picture.ToArray(); conn.openConnection(); if (command.ExecuteNonQuery() == 1) { conn.closeConnection(); return(true); } else { conn.closeConnection(); return(false); } }
private void buttonsignup_Click(object sender, EventArgs e) { CONNECT conn = new CONNECT(); MySqlCommand command = new MySqlCommand("INSERT INTO `users`(`username`, `password`) VALUES (@usn, @pass)", conn.getConnection()); command.Parameters.Add("@usn", MySqlDbType.VarChar).Value = textBoxUsername.Text; command.Parameters.Add("@pass", MySqlDbType.VarChar).Value = textBoxPassword.Text; conn.openConnection(); if (textBoxUsername.Text.Trim().Equals("")) { MessageBox.Show("Enter Your Username to Register", "Empty Username", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (textBoxPassword.Text.Trim().Equals("")) { MessageBox.Show("Enter Your Password to Register", "Empty Password", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (textBoxPasswordConfirm.Text.Trim().Equals("")) { MessageBox.Show("Enter Your Confirm Password to Register", "Empty Data", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (!checkTextBoxesValues()) { // check if the password equal the confirm password if (textBoxPassword.Text.Equals(textBoxPasswordConfirm.Text)) { // check if this username already exists if (checkUsername()) { MessageBox.Show("This Username Already Exists, Select A Different One", "Duplicate Username", MessageBoxButtons.OKCancel, MessageBoxIcon.Error); } else { // execute the query if (command.ExecuteNonQuery() == 1) { this.Close(); MessageBox.Show("Your Account Has Been Created", "Account Created", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("ERROR"); } } } else { MessageBox.Show("Wrong Confirmation Password", "Password Error", MessageBoxButtons.OKCancel, MessageBoxIcon.Error); } } else { MessageBox.Show("Enter Your Informations First", "Empty Data", MessageBoxButtons.OKCancel, MessageBoxIcon.Error); } // close the connection conn.closeConnection(); }