public void updateUser(int id, string name, string username, string password, string phone, string email, Int16 status) { try { SqlCommand cmd = new SqlCommand("st_updateUsers", MainClass.con); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@id", id); cmd.Parameters.AddWithValue("@name", name); cmd.Parameters.AddWithValue("@username", username); cmd.Parameters.AddWithValue("@password", password); cmd.Parameters.AddWithValue("@phone", phone); cmd.Parameters.AddWithValue("@email", email); cmd.Parameters.AddWithValue("@status", status); MainClass.con.Open(); cmd.ExecuteNonQuery(); MainClass.con.Close(); MainClass.ShowMsg(name + " Updated to the system successfully", "Success...", "Success"); } catch (Exception ex) { MainClass.con.Close(); MainClass.ShowMsg(ex.Message, "Error...", "Error"); } }
public void updateProduct(int proID, string product, string barcode, float price, DateTime?expiry, int catID) { try { SqlCommand cmd = new SqlCommand("st_productUpdate", MainClass.con); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@name", product); cmd.Parameters.AddWithValue("@barcode", barcode); cmd.Parameters.AddWithValue("@price", price); cmd.Parameters.AddWithValue("@expiry", expiry); cmd.Parameters.AddWithValue("@catID", catID); cmd.Parameters.AddWithValue("@proID", proID); MainClass.con.Open(); cmd.ExecuteNonQuery(); MainClass.con.Close(); MainClass.ShowMsg(product + " updated to the system successfully", "Success...", "Success"); } catch (Exception ex) { MainClass.con.Close(); MainClass.ShowMsg(ex.Message, "Error...", "Error"); } }
public void showProducts(DataGridView gv, DataGridViewColumn proIDGV, DataGridViewColumn pronameGV, DataGridViewColumn expiryGV, DataGridViewColumn priceGV, DataGridViewColumn barGV, DataGridViewColumn catGV, DataGridViewColumn catIDGV, string data = null) { try { SqlCommand cmd = new SqlCommand("st_getProductsData", MainClass.con); cmd.CommandType = CommandType.StoredProcedure; SqlDataAdapter sda = new SqlDataAdapter(cmd); DataTable dt = new DataTable(); sda.Fill(dt); proIDGV.DataPropertyName = dt.Columns["Product ID"].ToString(); pronameGV.DataPropertyName = dt.Columns["Product Name"].ToString(); barGV.DataPropertyName = dt.Columns["Barcode"].ToString(); expiryGV.DataPropertyName = dt.Columns["Expiry"].ToString(); priceGV.DataPropertyName = dt.Columns["Price"].ToString(); catGV.DataPropertyName = dt.Columns["Category"].ToString(); catIDGV.DataPropertyName = dt.Columns["Category ID"].ToString(); gv.DataSource = dt; } catch (Exception ex) { MainClass.ShowMsg(ex.Message, "Error in loading category data...", "Error"); } }
public override void saveBTN_Click(object sender, EventArgs e) { if (catTXT.Text == "") { catErrorLabel.Visible = true; } else { catErrorLabel.Visible = false; } if (isativeDD.SelectedIndex == -1) { isactiveErrorLabel.Visible = true; } else { isactiveErrorLabel.Visible = false; } if (catErrorLabel.Visible || isactiveErrorLabel.Visible) { MainClass.ShowMsg("Fields with * are mandatory", "Error", "Error"); //Error is the type of msg } else { if (isativeDD.SelectedIndex == 0) { stat = 1; } else if (isativeDD.SelectedIndex == 1) { stat = 0; } if (edit == 0) // Code for save operation { insertion i = new insertion(); i.CatInsertion(catTXT.Text, stat); r.showCategories(dataGridView1, catIDGV, NameGV, statusGV); MainClass.disable_reset(leftPanel); } else if (edit == 1) // Code for update operation { DialogResult dr = MessageBox.Show("Are you sure , you want to update record", "Question...", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dr == DialogResult.Yes) { updation u = new updation(); u.updateCat(catID, catTXT.Text, stat); r.showCategories(dataGridView1, catIDGV, NameGV, statusGV); MainClass.disable_reset(leftPanel); } } } }
public void delete(object id, string proc, string param) { try { SqlCommand cmd = new SqlCommand(proc, MainClass.con); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue(param, id); MainClass.con.Open(); cmd.ExecuteNonQuery(); MainClass.con.Close(); MainClass.ShowMsg("Data deleted successfully", "Success...", "Success"); } catch (Exception ex) { MainClass.con.Close(); MainClass.ShowMsg(ex.Message, "Error...", "Error"); } }
public void CatInsertion(string name, Int16 status) { try { SqlCommand cmd = new SqlCommand("st_insertCategory", MainClass.con); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@name", name); cmd.Parameters.AddWithValue("@isActive", status); MainClass.con.Open(); cmd.ExecuteNonQuery(); MainClass.con.Close(); MainClass.ShowMsg(name + " added to the system successfully", "Success...", "Success"); } catch (Exception ex) { MainClass.con.Close(); MainClass.ShowMsg(ex.Message, "Error...", "Error"); } }
public void showCategories(DataGridView gv, DataGridViewColumn catIDGV, DataGridViewColumn catnameGV, DataGridViewColumn statusGV, string data = null) { try { SqlCommand cmd = new SqlCommand("st_getCategoriesDate", MainClass.con); cmd.CommandType = CommandType.StoredProcedure; SqlDataAdapter sda = new SqlDataAdapter(cmd); DataTable dt = new DataTable(); sda.Fill(dt); catIDGV.DataPropertyName = dt.Columns["ID"].ToString(); catnameGV.DataPropertyName = dt.Columns["Category"].ToString(); statusGV.DataPropertyName = dt.Columns["Status"].ToString(); gv.DataSource = dt; } catch (Exception ex) { MainClass.ShowMsg(ex.Message, "Error in loading category data...", "Error"); } }
public void showUser(DataGridView gv, DataGridViewColumn userIDGV, DataGridViewColumn nameGV, DataGridViewColumn usernameGV, DataGridViewColumn passwordGV, DataGridViewColumn phoneGV, DataGridViewColumn emailGV, DataGridViewColumn statusGV, string data = null) { SqlCommand cmd; try { if (data == null) { cmd = new SqlCommand("st_getUserData", MainClass.con); } else { cmd = new SqlCommand("st_getUserDataLIKE", MainClass.con); cmd.Parameters.AddWithValue("@data", data); } cmd.CommandType = CommandType.StoredProcedure; SqlDataAdapter sda = new SqlDataAdapter(cmd); DataTable dt = new DataTable(); sda.Fill(dt); userIDGV.DataPropertyName = dt.Columns["ID"].ToString(); nameGV.DataPropertyName = dt.Columns["Name"].ToString(); usernameGV.DataPropertyName = dt.Columns["Username"].ToString(); passwordGV.DataPropertyName = dt.Columns["Password"].ToString(); phoneGV.DataPropertyName = dt.Columns["Phone"].ToString(); emailGV.DataPropertyName = dt.Columns["Email"].ToString(); statusGV.DataPropertyName = dt.Columns["Status"].ToString(); gv.DataSource = dt; } catch (Exception ex) { MainClass.ShowMsg(ex.Message, "Error in fetching...", "Error"); } }
public override void saveBTN_Click(object sender, EventArgs e) { if (proTXT.Text == "") { proNameErrorLabel.Visible = true; } else { proNameErrorLabel.Visible = false; } if (barcodeTXT.Text == "") { barcodeErrorLabel.Visible = true; } else { barcodeErrorLabel.Visible = false; } if (expiryPicker.Value < DateTime.Now) { proExpiryErrorLabel.Visible = true; invalidDateErrorLabel.Visible = true; } else { proExpiryErrorLabel.Visible = false; } if (expiryPicker.Value.Date == DateTime.Now.Date) { proExpiryErrorLabel.Visible = false; } if (priceTXT.Text == "") { proPriceErrorLabel.Visible = true; } else { proPriceErrorLabel.Visible = false; } if (categoryCB.SelectedIndex == -1 || categoryCB.SelectedIndex == 0) { cateErrorLabel.Visible = true; } else { cateErrorLabel.Visible = false; } if (proNameErrorLabel.Visible || cateErrorLabel.Visible || barcodeErrorLabel.Visible || proPriceErrorLabel.Visible || proExpiryErrorLabel.Visible) { MainClass.ShowMsg("Fields with * are mandatory", "Error", "Error"); //Error is the type of msg } else { if (edit == 0) // Code for save operation { insertion i = new insertion(); if (expiryPicker.Value == DateTime.Now) { i.productInsertion(proTXT.Text, barcodeTXT.Text, Convert.ToSingle(priceTXT.Text), null, Convert.ToInt32(categoryCB.SelectedValue)); } else { i.productInsertion(proTXT.Text, barcodeTXT.Text, Convert.ToSingle(priceTXT.Text), expiryPicker.Value, Convert.ToInt32(categoryCB.SelectedValue)); } r.showProducts(dataGridView1, proIDGV, proGV, expiryGV, priceGV, barcodeGV, catGV, catIDGV); MainClass.disable_reset(leftPanel); } else if (edit == 1) // Code for update operation { DialogResult dr = MessageBox.Show("Are you sure , you want to update record", "Question...", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dr == DialogResult.Yes) { updation u = new updation(); if (expiryPicker.Value == DateTime.Now) { u.updateProduct(prodID, proTXT.Text, barcodeTXT.Text, Convert.ToSingle(priceTXT.Text), null, Convert.ToInt32(categoryCB.SelectedValue)); } else { u.updateProduct(prodID, proTXT.Text, barcodeTXT.Text, Convert.ToSingle(priceTXT.Text), expiryPicker.Value, Convert.ToInt32(categoryCB.SelectedValue)); } r.showProducts(dataGridView1, proIDGV, proGV, barcodeGV, expiryGV, priceGV, catGV, catIDGV); MainClass.disable_reset(leftPanel); } } } }
public override void saveBTN_Click(object sender, EventArgs e) { if (nameTXT.Text == "") { nameErrorLabel.Visible = true; } else { nameErrorLabel.Visible = false; } if (usernameTXT.Text == "") { usernameErrorLabel.Visible = true; } else { usernameErrorLabel.Visible = false; } if (passwordTXT.Text == "") { passwordErrorLabel.Visible = true; } else { passwordErrorLabel.Visible = false; } if (phoneTXT.Text == "") { phoneErrorLabel.Visible = true; } else { phoneErrorLabel.Visible = false; } if (emailTXT.Text == "") { emailErrorLabel.Visible = true; } else { emailErrorLabel.Visible = false; } if (statusCB.SelectedIndex == -1) { statusErrorLabel.Visible = true; } else { statusErrorLabel.Visible = false; } if (nameErrorLabel.Visible || usernameErrorLabel.Visible || passwordErrorLabel.Visible || phoneErrorLabel.Visible || emailErrorLabel.Visible || statusErrorLabel.Visible) { MainClass.ShowMsg("Fields with * are mandatory", "Error", "Error"); //Error is the type of msg } else { if (statusCB.SelectedIndex == 0) { stat = 1; } else if (statusCB.SelectedIndex == 1) { stat = 0; } if (edit == 0) // Code for save operation { insertion i = new insertion(); i.userInsertion(nameTXT.Text, usernameTXT.Text, passwordTXT.Text, phoneTXT.Text, emailTXT.Text, stat); r.showUser(dataGridView1, userIDGV, NameGV, usernameGV, passwordGV, phoneGV, emailGV, statusGV); MainClass.disable_reset(leftPanel); } else if (edit == 1) // Code for update operation { DialogResult dr = MessageBox.Show("Are you sure , you want to update record", "Question...", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dr == DialogResult.Yes) { updation u = new updation(); u.updateUser(userID, nameTXT.Text, usernameTXT.Text, passwordTXT.Text, phoneTXT.Text, emailTXT.Text, stat); r.showUser(dataGridView1, userIDGV, NameGV, usernameGV, passwordGV, phoneGV, emailGV, statusGV); MainClass.disable_reset(leftPanel); } } } }