public void updateProduct(int id, string product, string barcode, float money, int catID, DateTime?date = null) { try { SqlCommand cmd = new SqlCommand("st_updateProduct", MainClass.connection); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@name", product); cmd.Parameters.AddWithValue("@barcode", barcode); cmd.Parameters.AddWithValue("@price", money); if (date == null) { cmd.Parameters.AddWithValue("@expiry", DBNull.Value); } else { cmd.Parameters.AddWithValue("@expiry", date); } cmd.Parameters.AddWithValue("@catID", catID); cmd.Parameters.AddWithValue("@id", catID); MainClass.connection.Open(); cmd.ExecuteNonQuery(); MainClass.connection.Close(); MainClass.showMessage(product + " " + "Updated Successfully", "Successfully....", "Success"); } catch (Exception e) { MainClass.connection.Close(); MainClass.showMessage(e.Message, "Error", "Error"); } }
private void loginBtn_Click(object sender, EventArgs e) { if (usernameTxt.Text == "") { unameErrorLabel.Visible = true; } else { unameErrorLabel.Visible = false; } if (passTxt.Text == "") { passErrorLabel.Visible = true; } else { passErrorLabel.Visible = false; } if (unameErrorLabel.Visible || passErrorLabel.Visible) { MainClass.showMessage("Fields with * are mandatory", "Stop", "Error"); } else { if (Retrieval.getUserDetail(usernameTxt.Text, passTxt.Text)) { HomeScreen obj = new HomeScreen(); MainClass.showWindow(obj, this, MDI.ActiveForm); } else { } } }
public void showProduct(DataGridView gv, DataGridViewColumn proidGV, DataGridViewColumn productGV, DataGridViewColumn barcodeGV, DataGridViewColumn expiryGV, DataGridViewColumn priceGV, DataGridViewColumn catGV, DataGridViewColumn catidGV) { try { SqlCommand cmd = new SqlCommand("st_getProductData", MainClass.connection); cmd.CommandType = CommandType.StoredProcedure; SqlDataAdapter da = new SqlDataAdapter(cmd); DataTable dt = new DataTable(); da.Fill(dt); proidGV.DataPropertyName = dt.Columns["Product ID"].ToString(); productGV.DataPropertyName = dt.Columns["Product"].ToString(); barcodeGV.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 e) { MainClass.showMessage("Error to load Data", "Error", "Error"); } }
public static bool getUserDetail(string username, string pass) { try { SqlCommand cmd = new SqlCommand("getUserDetail", MainClass.connection); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@name", username); cmd.Parameters.AddWithValue("@pass", pass); MainClass.connection.Open(); SqlDataReader dr = cmd.ExecuteReader(); if (dr.HasRows) { checklogin = true; while (dr.Read()) { USer_ID = Convert.ToInt32(dr["ID"].ToString()); EMP_NAME = dr["Name"].ToString(); user_name = dr["Username"].ToString(); pass_word = dr["Password"].ToString(); } } else { checklogin = false; if (username != null && pass != null) { if (user_name != username && pass_word == pass) { MainClass.showMessage("Invalied Username", "Error", "Error"); } else if (user_name == username && pass_word != pass) { MainClass.showMessage("Invalied Password", "Error", "Error"); } else if (user_name != username && pass_word != pass) { MainClass.showMessage("Invalied Username and Password", "Error", "Error"); } } } MainClass.connection.Close(); } catch (Exception ex) { MainClass.connection.Close(); MainClass.showMessage("Error in Login", "Error", "Error"); } return(checklogin); }
public void delete(object id, string proc, string param) { try { SqlCommand cmd = new SqlCommand(proc, MainClass.connection); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue(param, id); MainClass.connection.Open(); cmd.ExecuteNonQuery(); MainClass.connection.Close(); MainClass.showMessage("Deleted from System Successfully", "Successfully....", "Success"); } catch (Exception e) { MainClass.connection.Close(); MainClass.showMessage(e.Message, "Error", "Error"); } }
public void insertCat(string name, Int16 status) { try { SqlCommand cmd = new SqlCommand("st_insertCategory", MainClass.connection); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@name", name); cmd.Parameters.AddWithValue("@isActive", status); MainClass.connection.Open(); cmd.ExecuteNonQuery(); MainClass.connection.Close(); MainClass.showMessage(name + "Added to the System Successfully", "Successfully....", "Success"); } catch (Exception e) { MainClass.connection.Close(); MainClass.showMessage(e.Message, "Error", "Error"); } }
public void updateSupplier(int supId, string compnay, string contactperson, string phone1, string address, Int16 status, string phone2 = null, string ntn = null) { try { SqlCommand cmd = new SqlCommand("st_updateSupplier", MainClass.connection); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@company", compnay); cmd.Parameters.AddWithValue("@contactPerson", contactperson); cmd.Parameters.AddWithValue("@phone1", phone1); if (phone2 == null) { cmd.Parameters.AddWithValue("@phone2", DBNull.Value); } else { cmd.Parameters.AddWithValue("@phone2", phone2); } cmd.Parameters.AddWithValue("@address", address); if (ntn == null) { cmd.Parameters.AddWithValue("@ntn", DBNull.Value); } else { cmd.Parameters.AddWithValue("@ntn", ntn); } cmd.Parameters.AddWithValue("@status", status); cmd.Parameters.AddWithValue("@id", supId); MainClass.connection.Open(); cmd.ExecuteNonQuery(); MainClass.connection.Close(); MainClass.showMessage(compnay + " " + "Updated Successfully", "Successfully....", "Success"); } catch (Exception e) { MainClass.connection.Close(); MainClass.showMessage(e.Message, "Error", "Error"); } }
public void showCategories(DataGridView gv, DataGridViewColumn idGV, DataGridViewColumn nameGV, DataGridViewColumn statusGV) { try { SqlCommand cmd = new SqlCommand("st_getCategoriesData", MainClass.connection); cmd.CommandType = CommandType.StoredProcedure; SqlDataAdapter da = new SqlDataAdapter(cmd); DataTable dt = new DataTable(); da.Fill(dt); idGV.DataPropertyName = dt.Columns["ID"].ToString(); nameGV.DataPropertyName = dt.Columns["Category"].ToString(); statusGV.DataPropertyName = dt.Columns["Status"].ToString(); gv.DataSource = dt; } catch (Exception e) { MainClass.showMessage("Error to load Data", "Error", "Error"); } }
public void insertUser(string name, string username, string pass, string phone, string email, Int16 status) { try { SqlCommand cmd = new SqlCommand("st_insertUsers", MainClass.connection); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@name", name); cmd.Parameters.AddWithValue("@username", username); cmd.Parameters.AddWithValue("@pwd", pass); cmd.Parameters.AddWithValue("@phone", phone); cmd.Parameters.AddWithValue("@email", email); cmd.Parameters.AddWithValue("@status", status); MainClass.connection.Open(); cmd.ExecuteNonQuery(); MainClass.connection.Close(); MainClass.showMessage(name + "Added to the System Successfully", "Successfully....", "Success"); } catch (Exception e) { MainClass.connection.Close(); MainClass.showMessage(e.Message, "Error", "Error"); } }
private void cartBtn_Click(object sender, EventArgs e) { if (barcodeTxt.Text == "") { barErrorLabel.Visible = true; } else { barErrorLabel.Visible = false; } if (qunatityTxt.Text == "") { quantityErrorLabel.Visible = true; } else { quantityErrorLabel.Visible = false; } if (suppllierDD.SelectedIndex == -1 || suppllierDD.SelectedIndex == 0) { supErrorLabel.Visible = true; } else { supErrorLabel.Visible = false; } if (quantityErrorLabel.Visible || barErrorLabel.Visible || supErrorLabel.Visible) { MainClass.showMessage("Fields with * are mandatory", "Stop", "Error"); } else { dataGridView1.Rows.Add(productID, proTxt.Text, qunatityTxt.Text, pupTxt.Text, TotalLabe.Text); } }
public void showSupplier(DataGridView gv, DataGridViewColumn idGV, DataGridViewColumn companyGV, DataGridViewColumn contactpersonGV, DataGridViewColumn phone1GV, DataGridViewColumn phone2GV, DataGridViewColumn addressGV, DataGridViewColumn statusGV, DataGridViewColumn ntnGV) { try { SqlCommand cmd = new SqlCommand("st_geSupplierData", MainClass.connection); cmd.CommandType = CommandType.StoredProcedure; SqlDataAdapter da = new SqlDataAdapter(cmd); DataTable dt = new DataTable(); da.Fill(dt); idGV.DataPropertyName = dt.Columns["ID"].ToString(); companyGV.DataPropertyName = dt.Columns["Company"].ToString(); contactpersonGV.DataPropertyName = dt.Columns["Contact Person"].ToString(); phone1GV.DataPropertyName = dt.Columns["Phone 1"].ToString(); phone2GV.DataPropertyName = dt.Columns["Phone 2"].ToString(); addressGV.DataPropertyName = dt.Columns["Address"].ToString(); statusGV.DataPropertyName = dt.Columns["Status"].ToString(); ntnGV.DataPropertyName = dt.Columns["NTN"].ToString(); gv.DataSource = dt; } catch (Exception e) { MainClass.showMessage("Unable to load Suppliers", "Error", "Error"); } }
public override void saveBtn_Click(object sender, EventArgs e) { if (proTxt.Text == "") { proErrorLabel.Visible = true; } else { proErrorLabel.Visible = false; } if (barTxt.Text == "") { barErrorLabel.Visible = true; } else { barErrorLabel.Visible = false; } if (expireTxt.Value < DateTime.Now) { expErrorLabel.Visible = true; } else { expErrorLabel.Visible = false; } if (expireTxt.Value.Date == DateTime.Now.Date) { expErrorLabel.Visible = false; } if (priceTxt.Text == "") { priceErrorLabel.Visible = true; } else { priceErrorLabel.Visible = false; } if (categoryCombo.SelectedIndex == -1 || categoryCombo.SelectedIndex == 0) { catErrorLabel.Visible = true; } else { catErrorLabel.Visible = false; } if (proErrorLabel.Visible || barErrorLabel.Visible || priceErrorLabel.Visible || catErrorLabel.Visible) { MainClass.showMessage("Fields with * are mandatory", "Stop", "Error"); } else { if (edit == 0)//Code for Save Operation { Insertion i = new Insertion(); if (expireTxt.Value.Date == DateTime.Now.Date) { i.insertProduct(proTxt.Text, barTxt.Text, Convert.ToSingle(priceTxt.Text), Convert.ToInt32(categoryCombo.SelectedValue)); } else { i.insertProduct(proTxt.Text, barTxt.Text, Convert.ToSingle(priceTxt.Text), Convert.ToInt32(categoryCombo.SelectedValue), expireTxt.Value); } r.showProduct(dataGridView1, proidGV, productGV, barGV, expiryGV, priceGV, categoryGV, catidGV); MainClass.disable_reset(leftPanel); } else if (edit == 1)//Code for Update Operation { DialogResult dr = MessageBox.Show("Are you sure, you want to update recored", "Question", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dr == DialogResult.Yes) { Updation u = new Updation(); if (expireTxt.Value.Date == DateTime.Now.Date) { u.updateProduct(prodId, proTxt.Text, barTxt.Text, Convert.ToSingle(priceTxt.Text), Convert.ToInt32(categoryCombo.SelectedValue)); } else { u.updateProduct(prodId, proTxt.Text, barTxt.Text, Convert.ToSingle(priceTxt.Text), Convert.ToInt32(categoryCombo.SelectedValue), expireTxt.Value); } r.showProduct(dataGridView1, proidGV, productGV, barGV, expiryGV, priceGV, categoryGV, catidGV); MainClass.disable_reset(leftPanel); } } } }
public override void saveBtn_Click(object sender, EventArgs e) { if (supplierTxt.Text == "") { suppierErrorLabel.Visible = true; } else { suppierErrorLabel.Visible = false; } if (contactPersonTxt.Text == "") { contactpersonErrorlabe.Visible = true; } else { contactpersonErrorlabe.Visible = false; } if (phone1Txt.Text == "") { phone1ErrorLabel.Visible = true; } else { phone1ErrorLabel.Visible = false; } if (addressTxt.Text == "") { addressErrorLabel.Visible = true; } else { addressErrorLabel.Visible = false; } if (statusDD.SelectedIndex == -1) { statusErrorLabel.Visible = true; } else { statusErrorLabel.Visible = false; } if (suppierErrorLabel.Visible || contactpersonErrorlabe.Visible || phone1ErrorLabel.Visible || addressErrorLabel.Visible || statusErrorLabel.Visible) { MainClass.showMessage("Fields with * are mandatory", "Stop", "Error"); } else { if (statusDD.SelectedIndex == 0) { stat = 1; } else if (statusDD.SelectedIndex == 1) { stat = 0; } if (edit == 0)//Code for Save Operation { Insertion i = new Insertion(); if (phone2Txt.Text == "" && ntnTxt.Text != "") { i.insertSupplier(supplierTxt.Text, contactPersonTxt.Text, phone1Txt.Text, addressTxt.Text, stat, null, ntnTxt.Text); } else if (phone2Txt.Text != "" && ntnTxt.Text == "") { i.insertSupplier(supplierTxt.Text, contactPersonTxt.Text, phone1Txt.Text, addressTxt.Text, stat, phone2Txt.Text, null); } else if (phone2Txt.Text == "" && ntnTxt.Text == "") { i.insertSupplier(supplierTxt.Text, contactPersonTxt.Text, phone1Txt.Text, addressTxt.Text, stat, null, null); } else { i.insertSupplier(supplierTxt.Text, contactPersonTxt.Text, phone1Txt.Text, addressTxt.Text, stat, phone2Txt.Text, ntnTxt.Text); } r.showSupplier(dataGridView1, supidGV, companyGV, contactpersonGV, phone1GV, phone2GV, addressGV, StatusGV, NTNGV); MainClass.disable_reset(leftPanel); } else if (edit == 1)//Code for Update Operation { DialogResult dr = MessageBox.Show("Are you sure, you want to update recored", "Question", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dr == DialogResult.Yes) { Updation u = new Updation(); if (statusDD.SelectedIndex == 0) { stat = 1; } else if (statusDD.SelectedIndex == 1) { stat = 0; } if (edit == 1)//Code for Save Operation { if (phone2Txt.Text == "" && ntnTxt.Text != "") { u.updateSupplier(supplierId, supplierTxt.Text, contactPersonTxt.Text, phone1Txt.Text, addressTxt.Text, stat, null, ntnTxt.Text); } else if (phone2Txt.Text != "" && ntnTxt.Text == "") { u.updateSupplier(supplierId, supplierTxt.Text, contactPersonTxt.Text, phone1Txt.Text, addressTxt.Text, stat, phone2Txt.Text, null); } else if (phone2Txt.Text == "" && ntnTxt.Text == "") { u.updateSupplier(supplierId, supplierTxt.Text, contactPersonTxt.Text, phone1Txt.Text, addressTxt.Text, stat, null, null); } else { u.updateSupplier(supplierId, supplierTxt.Text, contactPersonTxt.Text, phone1Txt.Text, addressTxt.Text, stat, phone2Txt.Text, ntnTxt.Text); } r.showSupplier(dataGridView1, supidGV, companyGV, contactpersonGV, phone1GV, phone2GV, addressGV, StatusGV, NTNGV); MainClass.disable_reset(leftPanel); } } } } }
public override void saveBtn_Click(object sender, EventArgs e) { if (nameTxt.Text == "") { namelabelError.Visible = true; } else { namelabelError.Visible = false; } if (userTxt.Text == "") { usrlabelError.Visible = true; } else { usrlabelError.Visible = false; } if (passTxt.Text == "") { passlabelError.Visible = true; } else { passlabelError.Visible = false; } if (phoneTxt.Text == "") { phonelabelError.Visible = true; } else { phonelabelError.Visible = false; } if (emailTxt.Text == "") { emaillabelError.Visible = true; } else { emaillabelError.Visible = false; } if (statusCombo.SelectedIndex == -1) { statusErrorLabel.Visible = true; } else { statusErrorLabel.Visible = false; } if (namelabelError.Visible || usrlabelError.Visible || passlabelError.Visible || phonelabelError.Visible || emaillabelError.Visible || statusErrorLabel.Visible) { MainClass.showMessage("Fields with * are mandatory", "Stop", "Error"); } else { if (statusCombo.SelectedIndex == 0) { stat = 1; } else if (statusCombo.SelectedIndex == 1) { stat = 0; } if (edit == 0)//Code for Save Operation { Insertion i = new Insertion(); i.insertUser(nameTxt.Text, userTxt.Text, passTxt.Text, phoneTxt.Text, emailTxt.Text, stat); r.showUser(dataGridView1, USERGV, nameGV, usernameGV, passGV, EmailGV, PhoneGV, StatusGV); MainClass.disable_reset(leftPanel); } else if (edit == 1)//Code for Update Operation { DialogResult dr = MessageBox.Show("Are you sure, you want to update recored", "Question", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dr == DialogResult.Yes) { Updation u = new Updation(); if (statusCombo.SelectedIndex == 0) { stat = 1; } else if (statusCombo.SelectedIndex == 1) { stat = 0; } u.updateUser(userId, nameTxt.Text, userTxt.Text, passTxt.Text, phoneTxt.Text, emailTxt.Text, stat); r.showUser(dataGridView1, USERGV, nameGV, usernameGV, passGV, EmailGV, PhoneGV, StatusGV); MainClass.disable_reset(leftPanel); } } } }
public override void saveBtn_Click(object sender, EventArgs e) { if (catagoryTxt.Text == "") { catErrorLabel.Visible = true; } else { catErrorLabel.Visible = false; } if (catCombo.SelectedIndex == -1) { statusErrorLabel.Visible = true; } else { statusErrorLabel.Visible = false; } if (catErrorLabel.Visible || statusErrorLabel.Visible) { MainClass.showMessage("Fields with * are mandatory", "Stop", "Error"); } else { if (catCombo.SelectedIndex == 0) { stat = 1; } else if (catCombo.SelectedIndex == 1) { stat = 0; } if (edit == 0)//Code for Save Operation { Insertion i = new Insertion(); i.insertCat(catagoryTxt.Text, stat); r.showCategories(dataGridView1, catGV, 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 recored", "Question", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dr == DialogResult.Yes) { Updation u = new Updation(); if (catCombo.SelectedIndex == 0) { stat = 1; } else if (catCombo.SelectedIndex == 1) { stat = 0; } u.updateCat(catId, catagoryTxt.Text, stat); r.showCategories(dataGridView1, catGV, nameGV, StatusGV); MainClass.disable_reset(leftPanel); } } } }