private void Changepwdtab_Load(object sender, EventArgs e) { gunaComboBox1.SelectedIndex = 0; textBox1.Visible = false; currentPass.Visible = false; using (MySqlConnection conn = DBUtils.GetDBConnection()) { conn.Open(); using (var cmd = new MySqlCommand("Select * FROM Users WHERE username = '******'", conn)) { MySqlDataReader Reader; Reader = cmd.ExecuteReader(); while (Reader.Read()) { string sname = (string)Reader["staffname"]; staffName.Text = sname; int phone = (int)Reader["staffphone"]; staffPhone.Text = phone.ToString(); string address = (string)Reader["address"]; staffAddress.Text = address; string curent = (string)Reader["password"]; currentPass.Text = curent; int sexget = (int)Reader["sex"]; if (sexget == 1) { gunaComboBox1.SelectedIndex = 0; } else { gunaComboBox1.SelectedIndex = 1; } } } conn.Close(); } }
private void Paynow_Click(object sender, EventArgs e) { int _min = 1111; int _max = 9999; Random _rdm = new Random(); int billrandom = _rdm.Next(_min, _max); MySqlConnection conn = DBUtils.GetDBConnection(); if (string.IsNullOrEmpty(txtadressship.Text) || txtadressship.Text == "Press your Address") { Alert.ThatShow("PLS enter your Address", Alert.AlertType.warning); } else { Alert.ThatShow("Pay Success", Alert.AlertType.success); for (int i = 0; i < buyorderlist.Rows.Count; i++) { conn.Open(); MySqlCommand command = new MySqlCommand("INSERT INTO Salelog (bid, pname, pid, staffid, amount, dofsale, totals, address) VALUES (@bid,@pname,@pid,@staffid,@amount,@dofsale,@totals,@address)", conn); MySqlDataReader myReader; command.Parameters.Add("@bid", MySqlDbType.Int32).Value = billrandom; // bill random command.Parameters.AddWithValue("@pname", buyorderlist.Rows[i].Cells[1].Value); command.Parameters.AddWithValue("@pid", buyorderlist.Rows[i].Cells[5].Value); command.Parameters.AddWithValue("@staffid", getUserSeed.Text); command.Parameters.AddWithValue("@amount", buyorderlist.Rows[i].Cells[2].Value); command.Parameters.AddWithValue("@dofsale", DateTime.Now); command.Parameters.AddWithValue("@totals", buyorderlist.Rows[i].Cells[4].Value); command.Parameters.AddWithValue("@address", txtadressship.Text); myReader = command.ExecuteReader(); while (myReader.Read()) { } conn.Close(); } this.Close(); } }
private void BunifuImageButton2_Click_1(object sender, EventArgs e) { MySqlConnection conn = DBUtils.GetDBConnection(); conn.Open(); MySqlCommand command = new MySqlCommand("SELECT * FROM Products WHERE pid = @pid", conn); command.Parameters.Add("@pid", MySqlDbType.VarChar).Value = txtProductid.Text; MySqlDataAdapter adapter = new MySqlDataAdapter(command); DataTable table = new DataTable(); adapter.Fill(table); if (table.Rows.Count <= 0) { MessageBox.Show("Empty"); Clear(); } else { txtProductid.Text = table.Rows[0][1].ToString(); txtProductname.Text = table.Rows[0][2].ToString(); comboType.SelectedIndex = comboType.Items.IndexOf(table.Rows[0][3].ToString()); comboBrand.SelectedIndex = comboBrand.Items.IndexOf(table.Rows[0][4].ToString()); txtWholeprice.Text = table.Rows[0][5].ToString(); txtRetailprice.Text = table.Rows[0][6].ToString(); txtQty.Text = table.Rows[0][7].ToString(); txtDateadd.Text = table.Rows[0][9].ToString(); byte[] img = (byte[])table.Rows[0][8]; MemoryStream ms = new MemoryStream(img); pictureBox1.Image = Image.FromStream(ms); btnDelete.Enabled = true; btnUpdate.Enabled = true; bunifuDatepicker1.Enabled = true; } conn.Close(); }
private void BtnUpdate_Click(object sender, EventArgs e) { MySqlConnection conn = DBUtils.GetDBConnection(); conn.Open(); MemoryStream ms = new MemoryStream(); pictureBox1.Image.Save(ms, pictureBox1.Image.RawFormat); byte[] img = ms.ToArray(); MySqlCommand command = new MySqlCommand("UPDATE Products SET pid=@pid, pname=@pname, typename=@typename, brandname=@brandname, wholeprice=@wholeprice, retailprice = @retailprice, qty = @qty, dateadd = @dateadd, image=@image WHERE id=@id", conn); command.Parameters.Add("@id", MySqlDbType.VarChar).Value = dataGridView1.CurrentRow.Cells[0].Value.ToString(); command.Parameters.Add("@pid", MySqlDbType.VarChar).Value = txtProductid.Text; command.Parameters.Add("@pname", MySqlDbType.VarChar).Value = txtProductname.Text; Object typecb = comboType.SelectedItem; command.Parameters.Add("@typename", MySqlDbType.VarChar).Value = typecb.ToString(); Object brandcb = comboBrand.SelectedItem; command.Parameters.Add("@brandname", MySqlDbType.VarChar).Value = brandcb.ToString(); command.Parameters.Add("@wholeprice", MySqlDbType.Int32).Value = txtWholeprice.Text; command.Parameters.Add("@retailprice", MySqlDbType.Int32).Value = txtRetailprice.Text; command.Parameters.Add("@qty", MySqlDbType.Int32).Value = txtQty.Text; command.Parameters.Add("@dateadd", MySqlDbType.DateTime).Value = bunifuDatepicker1.Value; command.Parameters.Add("@image", MySqlDbType.Blob).Value = img; if (string.IsNullOrEmpty(txtProductid.Text) || txtProductid.Text == "Product ID" || string.IsNullOrEmpty(txtProductname.Text) || txtProductname.Text == "Product Name" || comboType.SelectedIndex == 0 || comboBrand.SelectedIndex == 0 || string.IsNullOrEmpty(txtWholeprice.Text) || txtWholeprice.Text == "Wholesale Price" || string.IsNullOrEmpty(txtRetailprice.Text) || txtRetailprice.Text == "Retail Price" || string.IsNullOrEmpty(txtQty.Text) || txtQty.Text == "Qty.") { Alert.ThatShow("Don't leave blank", Alert.AlertType.error); } else { ExecMyQuery(command, "Updated Successfuly"); } conn.Close(); }
void btn_Click(object sender, EventArgs e) { Button btn_item = sender as Button; NamedProduct.Text = btn_item.Text.ToString(); preNameP.Text = NamedProduct.Text + "xxx"; using (MySqlConnection conn = DBUtils.GetDBConnection()) { conn.Open(); using (var cmd = new MySqlCommand("Select pid,pname,retailprice,qty FROM Products WHERE pname = '" + btn_item.Text.ToString() + "'", conn)) { MySqlDataReader Reader; Reader = cmd.ExecuteReader(); while (Reader.Read()) { string pidd = (string)Reader["pid"]; txtpid.Text = pidd; int retailprice = (int)Reader["retailprice"]; txtRetail.Text = retailprice.ToString(); int qty = (int)Reader["qty"]; txtQty.Text = qty.ToString(); txtLeftqty.Text = qty.ToString(); } if (sumqty.Text != "") { int stock = int.Parse(txtQty.Text) - int.Parse(sumqty.Text); txtLeftqty.Text = stock.ToString(); if (txtLeftqty.Text == "0") { panel2.Visible = false; Alert.ThatShow("OutStock", Alert.AlertType.warning); } } else if (txtQty.Text == "0") { panel2.Visible = false; Alert.ThatShow("OutStock", Alert.AlertType.warning); } else { panel2.Visible = true; } if (preNameP.Text != btn_item.Text.ToString()) { sumqty.Text = ""; } int sum = 0; for (int j = 0; j < dataGridView1.Rows.Count; j++) { if (dataGridView1[1, j].Value.ToString() == btn_item.Text.ToString()) { sum = sum + Convert.ToInt32(dataGridView1[2, j].Value); sumqty.Text = sum.ToString(); } } // int count = Convert.ToInt32(cmd.ExecuteScalar()); // totalusers.Text = count.ToString(); } conn.Close(); } }
private void BtnInsert_Click(object sender, EventArgs e) { int tempstaffid = 0; int tempname = 0; MySqlConnection conn = DBUtils.GetDBConnection(); conn.Open(); MemoryStream ms = new MemoryStream(); pictureBox1.Image.Save(ms, pictureBox1.Image.RawFormat); byte[] img = ms.ToArray(); MySqlCommand command = new MySqlCommand("INSERT INTO Products (pid, pname, typename, brandname, wholeprice, retailprice, qty, image, dateadd) VALUES (@pid, @pname, @typename, @brandname, @wholeprice, @retailprice, @qty, @image, @dateadd)", conn); command.Parameters.Add("@pid", MySqlDbType.VarChar).Value = txtProductid.Text; command.Parameters.Add("@pname", MySqlDbType.VarChar).Value = txtProductname.Text; Object typecb = comboType.SelectedItem; command.Parameters.Add("@typename", MySqlDbType.VarChar).Value = typecb.ToString(); Object brandcb = comboBrand.SelectedItem; command.Parameters.Add("@brandname", MySqlDbType.VarChar).Value = brandcb.ToString(); command.Parameters.Add("@wholeprice", MySqlDbType.Int32).Value = txtWholeprice.Text; command.Parameters.Add("@retailprice", MySqlDbType.Int32).Value = txtRetailprice.Text; command.Parameters.Add("@qty", MySqlDbType.Int32).Value = txtQty.Text; command.Parameters.Add("@dateadd", MySqlDbType.DateTime).Value = DateTime.Now; command.Parameters.Add("@image", MySqlDbType.Blob).Value = img; using (var cmd = new MySqlCommand("Select pid from Products WHERE pid = '" + txtProductid.Text + "'", conn)) { string reid = Convert.ToString(cmd.ExecuteScalar()); resultpname.Text = reid; if (resultpname.Text.Length > 0) { Alert.ThatShow("Products ID already exists", Alert.AlertType.warning); } else { tempstaffid = 1; } } using (var cmd1 = new MySqlCommand("Select pname from Products WHERE pid = '" + txtProductname.Text + "'", conn)) { string repname = Convert.ToString(cmd1.ExecuteScalar()); resultpid.Text = repname; if (resultpid.Text.Length > 0) { Alert.ThatShow("Product Name already exists", Alert.AlertType.warning); } else { tempname = 1; } } if (string.IsNullOrEmpty(txtProductid.Text) || txtProductid.Text == "Product ID" || string.IsNullOrEmpty(txtProductname.Text) || txtProductname.Text == "Product Name" || comboType.SelectedIndex == 0 || comboBrand.SelectedIndex == 0 || string.IsNullOrEmpty(txtWholeprice.Text) || txtWholeprice.Text == "Wholesale Price" || string.IsNullOrEmpty(txtRetailprice.Text) || txtRetailprice.Text == "Retail Price" || string.IsNullOrEmpty(txtQty.Text) || txtQty.Text == "Qty.") { Alert.ThatShow("Don't leave blank", Alert.AlertType.error); } else if (tempstaffid == 1 && tempname == 1) { ExecMyQuery(command, "Inserted Successfuly"); } conn.Close(); }