Beispiel #1
0
        public void showSuppliers(DataGridView gv, DataGridViewColumn suppIDGV, DataGridViewColumn conNameGV, DataGridViewColumn personGV, DataGridViewColumn phone1GV, DataGridViewColumn phone2GV,
                                  DataGridViewColumn addressGV, DataGridViewColumn ntnGV, DataGridViewColumn statusGV)
        {
            try
            {
                SqlCommand cmd = new SqlCommand("st_getSupplierData", MainClass.con);;
                //SqlCommand cmd = new SqlCommand("st_getUsersData", MainClass.con);
                cmd.CommandType = CommandType.StoredProcedure;
                SqlDataAdapter da = new SqlDataAdapter(cmd);
                DataTable      dt = new DataTable();
                da.Fill(dt);
                suppIDGV.DataPropertyName  = dt.Columns["ID"].ToString();
                conNameGV.DataPropertyName = dt.Columns["Company"].ToString();
                personGV.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();
                ntnGV.DataPropertyName     = dt.Columns["NTN #"].ToString();
                statusGV.DataPropertyName  = dt.Columns["Status"].ToString();


                gv.DataSource = dt;
            }
            catch (Exception)
            {
                MainClass.ShowMSG("Unable to load supplier data.", "Error", "Error");
            }
        }
Beispiel #2
0
        public void showProducts(DataGridView gv, DataGridViewColumn proIDGV, DataGridViewColumn proNameGV, DataGridViewColumn expiryGV, DataGridViewColumn catGV, DataGridViewColumn priceGV, DataGridViewColumn barcodeGV, DataGridViewColumn catIDGV)
        {
            try
            {
                SqlCommand cmd = new SqlCommand("st_getProductsData", MainClass.con);;
                //SqlCommand cmd = new SqlCommand("st_getUsersData", MainClass.con);
                cmd.CommandType = CommandType.StoredProcedure;
                SqlDataAdapter da = new SqlDataAdapter(cmd);
                DataTable      dt = new DataTable();
                da.Fill(dt);
                proIDGV.DataPropertyName   = dt.Columns["Product_ID"].ToString();
                proNameGV.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)
            {
                MainClass.ShowMSG("Unable to load categories data.", "Error", "Error");
            }
        }
Beispiel #3
0
        public void updateProduct(int proID, string product, string barcode, float price, int catID, DateTime?expiry = null)
        {
            try
            {
                SqlCommand cmd = new SqlCommand("st_productUpdate", MainClass.con); //Here we are using the stored procedure
                cmd.CommandType = CommandType.StoredProcedure;                      //We specify the type of command that is a stored procedure
                                                                                    //We proceed to fill the parameters
                cmd.Parameters.AddWithValue("@name", product);
                cmd.Parameters.AddWithValue("@barcode", barcode);
                cmd.Parameters.AddWithValue("@price", price);
                //We specify if the expiry date is null or if it has a value
                if (expiry == null)
                {
                    cmd.Parameters.AddWithValue("@expiry", DBNull.Value);
                }
                else
                {
                    cmd.Parameters.AddWithValue("@expiry", expiry);
                }
                cmd.Parameters.AddWithValue("@catID", catID);
                cmd.Parameters.AddWithValue("@prodID", 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");
            }
        }
Beispiel #4
0
        public Int64 insertPurchaseInvoice(DateTime date, int doneBy, int suppID)
        {
            try
            {
                SqlCommand cmd = new SqlCommand("st_inserPurchaseINvoice", MainClass.con); //Here we are using the stored procedure
                cmd.CommandType = CommandType.StoredProcedure;                             //We specify the type of command that is a stored procedure
                //We proceed to fill the parameters
                cmd.Parameters.AddWithValue("@date", date);
                cmd.Parameters.AddWithValue("@doneBy", doneBy);
                cmd.Parameters.AddWithValue("@suppID", suppID);
                MainClass.con.Open();
                cmd.ExecuteNonQuery();

                //here enters the multiple active result sets (MultipleActiveResultSets = true)
                cmd.CommandText = "st_getLastPurchaseID"; //get the last purchase for PurchaseInvoice table in the database
                cmd.Parameters.Clear();
                purchaseInvoiceID = Convert.ToInt64(cmd.ExecuteScalar());


                MainClass.con.Close();
            }
            catch (Exception ex)
            {
                MainClass.con.Close();
                MainClass.ShowMSG(ex.Message, "Error...", "Error");
            }
            return(purchaseInvoiceID);
        }
Beispiel #5
0
        public void updateUser(int id, string name, string username, string pass, string email, string phone, Int16 status)
        {
            try
            {
                SqlCommand cmd = new SqlCommand("st_updateUsers", MainClass.con); //Here we are using the stored procedure
                cmd.CommandType = CommandType.StoredProcedure;                    //We specify the type of command that is a stored procedure
                                                                                  //We proceed to fill the parameters
                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);
                cmd.Parameters.AddWithValue("@id", id);

                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");
            }
        }
Beispiel #6
0
 private void loginBtn_Click(object sender, EventArgs e)
 {
     if (usernameTxt.Text == "")
     {
         usernameErrorLbl.Visible = true;
     }
     else
     {
         usernameErrorLbl.Visible = false;
     }
     if (passwordTxt.Text == "")
     {
         passErrorLbl.Visible = true;
     }
     else
     {
         passErrorLbl.Visible = false;
     }
     if (usernameErrorLbl.Visible || passErrorLbl.Visible)
     {
         MainClass.ShowMSG("Fields with * are mandatory", "Stop", "Error");
     }
     else
     {
         if (retrieval.getUserDetails(usernameTxt.Text, passwordTxt.Text))
         {
             HomeScreen hm = new HomeScreen();
             MainClass.showWindow(hm, this, MDI.ActiveForm);
         }
         else
         {
         }
     }
 }
Beispiel #7
0
 public static bool getUserDetails(string username, string password) //We get the username and password from the login screen
 {
     try
     {
         SqlCommand cmd = new SqlCommand("st_getUserDetails", MainClass.con);
         cmd.CommandType = CommandType.StoredProcedure;
         cmd.Parameters.AddWithValue("@user", username);
         cmd.Parameters.AddWithValue("@pass", password);
         MainClass.con.Open();
         SqlDataReader dr = cmd.ExecuteReader();
         if (dr.HasRows)
         {
             checkLogin = true;
             while (dr.Read()) //while the reader is reading something
             {
                 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 && password != null)               //if username and passworn are not null
             {
                 if (user_name != username && pass_word == password) //if the username is incorrect but the password is correct
                 {
                     MainClass.ShowMSG("Invalid Username", "Error", "Error");
                 }
                 else if (user_name == username && pass_word != password) //if the username is correct but the password is not
                 {
                     MainClass.ShowMSG("Invalid Password", "Error", "Error");
                 }
                 else if (user_name != username && pass_word != password) //if both username and password are incorrect
                 {
                     MainClass.ShowMSG("Invalid Username and Password", "Error", "Error");
                 }
             }
         }
         MainClass.con.Close();
     }
     catch (Exception)
     {
         MainClass.con.Close();
         MainClass.ShowMSG("Unable to login...", "Error", "Error");
     }
     return(checkLogin);
 }
Beispiel #8
0
        public void updateSupplier(int supID, string company, string person, string phone1, string address, Int16 status, string phone2 = null, string ntn = null)
        {
            try
            {
                SqlCommand cmd = new SqlCommand("st_updateSupplier", MainClass.con); //Here we are using the stored procedure
                cmd.CommandType = CommandType.StoredProcedure;                       //We specify the type of command that is a stored procedure
                                                                                     //We proceed to fill the parameters
                cmd.Parameters.AddWithValue("@company", company);
                cmd.Parameters.AddWithValue("@conPerson", person);
                cmd.Parameters.AddWithValue("@phone1", phone1);
                //phone 2 could get a null result, for that we make an if to prevente any error
                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("@suppID", supID);

                MainClass.con.Open();
                cmd.ExecuteNonQuery();
                MainClass.con.Close();
                MainClass.ShowMSG(company + " updated to the system successfully", "Success...", "Success");
            }
            catch (Exception ex)
            {
                MainClass.con.Close();
                MainClass.ShowMSG(ex.Message, "Error...", "Error");
            }
        }
Beispiel #9
0
        public void delete(object id, string proc, string param)
        {
            try
            {
                SqlCommand cmd = new SqlCommand(proc, MainClass.con); //Here we are using the stored procedure
                cmd.CommandType = CommandType.StoredProcedure;        //We specify the type of command that is a stored procedure
                                                                      //We proceed to fill the parameters
                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");
            }
        }
Beispiel #10
0
        public void insertCat(string name, Int16 status)
        {
            try
            {
                SqlCommand cmd = new SqlCommand("st_insertCategory", MainClass.con); //Here we are using the stored procedure
                cmd.CommandType = CommandType.StoredProcedure;                       //We specify the type of command that is a stored procedure
                                                                                     //We proceed to fill the parameters
                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");
            }
        }
Beispiel #11
0
        public void showCategories(DataGridView gv, DataGridViewColumn catIDGV, DataGridViewColumn catNameGV, DataGridViewColumn statGV)
        {
            try
            {
                SqlCommand cmd = new SqlCommand("st_getCategoriesData", MainClass.con);;
                //SqlCommand cmd = new SqlCommand("st_getUsersData", MainClass.con);
                cmd.CommandType = CommandType.StoredProcedure;
                SqlDataAdapter da = new SqlDataAdapter(cmd);
                DataTable      dt = new DataTable();
                da.Fill(dt);
                catIDGV.DataPropertyName   = dt.Columns["ID"].ToString();
                catNameGV.DataPropertyName = dt.Columns["Category"].ToString();
                statGV.DataPropertyName    = dt.Columns["Status"].ToString();

                gv.DataSource = dt;
            }
            catch (Exception)
            {
                MainClass.ShowMSG("Unable to load categories data.", "Error", "Error");
            }
        }
Beispiel #12
0
        public override void saveBtn_Click(object sender, EventArgs e)
        {
            if (dataGridView1.Rows.Count > 0)//if the dgv is not empty
            {
                Int64     purchaseInvoiceID;
                insertion i = new insertion();

                using (TransactionScope sc = new TransactionScope())
                {
                    purchaseInvoiceID = i.insertPurchaseInvoice(DateTime.Today, retrieval.USER_ID, Convert.ToInt32(supplierDD.SelectedValue));

                    foreach (DataGridViewRow row in dataGridView1.Rows)
                    {
                        co += i.insertPurchaseInvoiceDetails(purchaseInvoiceID, Convert.ToInt32(row.Cells["proIDGV"].Value.ToString()), Convert.ToInt32(row.Cells["quantGV"].Value.ToString()), Convert.ToSingle(row.Cells["totGV"].Value.ToString()));
                        int    q;
                        object ob = r.getProductQuantity(Convert.ToInt32(row.Cells["proIDGV"].Value.ToString()));
                        if (ob != null)
                        {
                            q  = Convert.ToInt32(ob);
                            q += Convert.ToInt32(row.Cells["quantGV"].Value.ToString());
                            u.updateStock(Convert.ToInt32(row.Cells["proIDGV"].Value.ToString()), q);
                        }
                        else
                        {
                            i.insertStock(Convert.ToInt32(row.Cells["proIDGV"].Value.ToString()), Convert.ToInt32(row.Cells["quantGV"].Value.ToString()));
                        }
                    }
                    if (co > 0)
                    {
                        MainClass.ShowMSG("Purchase Invoice Created Successfully.", "Success", "Success");
                    }
                    else
                    {
                        MainClass.ShowMSG("Unable to create purchaice Invoice", "Error", "Error");
                    }
                    sc.Complete();
                }
            }
        }
Beispiel #13
0
        public void showPurchaseInvoiceDetails(Int64 pid, DataGridView gv, DataGridViewColumn proIDGV, DataGridViewColumn proNameGV, DataGridViewColumn quantGV, DataGridViewColumn pupGV, DataGridViewColumn totGV)
        {
            try
            {
                SqlCommand cmd = new SqlCommand("st_getPurchaseInvoiceDetails", MainClass.con);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@pid", pid);
                SqlDataAdapter da = new SqlDataAdapter(cmd);
                DataTable      dt = new DataTable();
                da.Fill(dt);
                proIDGV.DataPropertyName   = dt.Columns["Product ID"].ToString();
                proNameGV.DataPropertyName = dt.Columns["Product"].ToString();
                quantGV.DataPropertyName   = dt.Columns["Quantity"].ToString();
                pupGV.DataPropertyName     = dt.Columns["Total Price"].ToString();
                totGV.DataPropertyName     = dt.Columns["Per Unit Price"].ToString();

                gv.DataSource = dt;
            }
            catch (Exception)
            {
                MainClass.ShowMSG("Unable to load categories data.", "Error", "Error");
            }
        }
Beispiel #14
0
        public override void saveBtn_Click(object sender, EventArgs e)
        {
            //Here we enable and disable the red asterisc "*" in the form, validating that no txt left unfilled
            if (supplierCompanyTxt.Text == "")
            {
                supplierNameErrorLbl.Visible = true;
            }
            else
            {
                supplierNameErrorLbl.Visible = false;
            }
            if (personNameTxt.Text == "")
            {
                contactPersonErrorLbl.Visible = true;
            }
            else
            {
                contactPersonErrorLbl.Visible = false;
            }
            if (Phone1Txt.Text == "")
            {
                phone1ErrorLbl.Visible = true;
            }
            else
            {
                phone1ErrorLbl.Visible = false;
            }
            if (addressTxt.Text == "")
            {
                addressErrorLbl.Visible = true;
            }
            else
            {
                addressErrorLbl.Visible = false;
            }
            if (statusDD.SelectedIndex == -1)
            {
                statusErrorLbl.Visible = true;
            }
            else
            {
                statusErrorLbl.Visible = false;
            }

            if (supplierNameErrorLbl.Visible || contactPersonErrorLbl.Visible || phone1ErrorLbl.Visible || addressErrorLbl.Visible || statusErrorLbl.Visible)
            {
                MainClass.ShowMSG("Fields with * are mandatory", "Stop", "Error"); //Error is the type of msg
            }
            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();
                    //validating the null fields
                    if (phone2Txt.Text == "" && ntnTxt.Text != "")
                    {
                        i.insertSupplier(supplierCompanyTxt.Text, personNameTxt.Text, Phone1Txt.Text, addressTxt.Text, stat, null, ntnTxt.Text);
                    }
                    else if (phone2Txt.Text != "" && ntnTxt.Text == "")
                    {
                        i.insertSupplier(supplierCompanyTxt.Text, personNameTxt.Text, Phone1Txt.Text, addressTxt.Text, stat, phone2Txt.Text, null);
                    }
                    else if (phone2Txt.Text == "" && ntnTxt.Text == "")
                    {
                        i.insertSupplier(supplierCompanyTxt.Text, personNameTxt.Text, Phone1Txt.Text, addressTxt.Text, stat, null, null);
                    }
                    else
                    {
                        i.insertSupplier(supplierCompanyTxt.Text, personNameTxt.Text, Phone1Txt.Text, addressTxt.Text, stat, phone2Txt.Text, ntnTxt.Text);
                    }

                    r.showSuppliers(dataGridView1, SuppIDGV, companyGV, personGV, phone1GV, phone2GV, addressGV, ntnGV, 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();
                        if (statusDD.SelectedIndex == 0)
                        {
                            stat = 1;
                        }
                        else if (statusDD.SelectedIndex == 1)
                        {
                            stat = 0;
                        }
                        //validating the null fields
                        if (phone2Txt.Text == "" && ntnTxt.Text != "")
                        {
                            u.updateSupplier(supplierID, supplierCompanyTxt.Text, personNameTxt.Text, Phone1Txt.Text, addressTxt.Text, stat, null, ntnTxt.Text);
                        }
                        else if (phone2Txt.Text != "" && ntnTxt.Text == "")
                        {
                            u.updateSupplier(supplierID, supplierCompanyTxt.Text, personNameTxt.Text, Phone1Txt.Text, addressTxt.Text, stat, phone2Txt.Text, null);
                        }
                        else if (phone2Txt.Text == "" && ntnTxt.Text == "")
                        {
                            u.updateSupplier(supplierID, supplierCompanyTxt.Text, personNameTxt.Text, Phone1Txt.Text, addressTxt.Text, stat, null, null);
                        }
                        else
                        {
                            u.updateSupplier(supplierID, supplierCompanyTxt.Text, personNameTxt.Text, Phone1Txt.Text, addressTxt.Text, stat, phone2Txt.Text, ntnTxt.Text);
                        }

                        r.showSuppliers(dataGridView1, SuppIDGV, companyGV, personGV, phone1GV, phone2GV, addressGV, ntnGV, StatusGV);
                        MainClass.disable_reset(leftPanel);
                    }
                }
            }
        }
Beispiel #15
0
        public override void saveBtn_Click(object sender, EventArgs e)
        {
            if (catTxt.Text == "")
            {
                catErrorLabel.Visible = true;
            }
            else
            {
                catErrorLabel.Visible = false;
            }
            if (activeDD.SelectedIndex == -1)
            {
                activeErrorLabel.Visible = true;
            }
            else
            {
                activeErrorLabel.Visible = false;
            }

            if (catErrorLabel.Visible || activeErrorLabel.Visible)
            {
                MainClass.ShowMSG("Fields with * are mandatory", "Stop", "Error"); //Error is the type of msg
            }
            else
            {
                if (activeDD.SelectedIndex == 0)
                {
                    stat = 1; //this is sent to the stored procedure: status = 1 then 'Yes'
                }
                else if (activeDD.SelectedIndex == 1)
                {
                    stat = 0;
                }
                if (edit == 0) //Code for SAVE operation
                {
                    insertion i = new insertion();

                    i.insertCat(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();
                        if (activeDD.SelectedIndex == 0)
                        {
                            stat = 1; //this is sent to the stored procedure: status = 1 then 'Yes'
                        }
                        else if (activeDD.SelectedIndex == 1)
                        {
                            stat = 0;
                        }
                        u.updateCat(catID, catTxt.Text, stat);
                        r.showCategories(dataGridView1, catIDGV, NameGV, StatusGV);
                        MainClass.disable_reset(leftPanel);
                    }
                }
            }
        }
Beispiel #16
0
 private void cartBtn_Click(object sender, EventArgs e)
 {
     if (supplierDD.SelectedIndex == -1)
     {
         suppErrorLbl.Visible = true;
     }
     else
     {
         suppErrorLbl.Visible = false;
     }
     if (quanTxt.Text == "")
     {
         quantErrorLbl.Visible = true;
     }
     else
     {
         quantErrorLbl.Visible = false;
     }
     if (barcodeTxt.Text == "")
     {
         barcodeErrorLbl.Visible = true;
     }
     else
     {
         barcodeErrorLbl.Visible = false;
     }
     if (suppErrorLbl.Visible || quantErrorLbl.Visible || barcodeErrorLbl.Visible)
     {
         MainClass.ShowMSG("Fields with * are mandatory", "Stop", "Error");
     }
     else
     {
         dataGridView1.Rows.Add(productID, productTxt.Text, quanTxt.Text, pupTxt.Text, totLbl.Text);
         gt += Convert.ToSingle(totLbl.Text);
         grossTotalLbl.Text = gt.ToString();
         productID          = 0;
         productTxt.Text    = "";
         pupTxt.Text        = "";
         barcodeTxt.Text    = "";
         totLbl.Text        = "0.00";
         quanTxt.Text       = "";
         Array.Clear(prodARR, 0, prodARR.Length);
     }
     //else //section where we restrict the product quantity entered in the datagridview purchase
     //{
     //    if (dataGridView1.Rows.Count == 0) // if the datagridview is empty, we add the purchase
     //    {
     //        dataGridView1.Rows.Add(productID, productTxt.Text, quanTxt.Text, pupTxt.Text, totLbl.Text);
     //        //fields reset
     //        productID = 0;
     //        productTxt.Text = "";
     //        pupTxt.Text = "";
     //        Array.Clear(prodARR, 0, prodARR.Length);
     //    }
     //    else
     //    {
     //        foreach (DataGridViewRow row in dataGridView1.Rows)
     //        {
     //            if (row.Cells["proIDGV"].Value.ToString() != productID.ToString()) //if the product ID entered is different from the other products, we add. Else we don't add.
     //            {
     //                dataGridView1.Rows.Add(productID, productTxt.Text, quanTxt.Text, pupTxt.Text, totLbl.Text);
     //                //fields reset
     //                productID = 0;
     //                productTxt.Text = "";
     //                pupTxt.Text = "";
     //                Array.Clear(prodARR, 0, prodARR.Length);
     //                break;
     //            }
     //        }
     //    }
     //}
 }
Beispiel #17
0
        public override void saveBtn_Click(object sender, EventArgs e)
        {
            if (proTxt.Text == "")
            {
                proErrorLabel.Visible = true;
            }
            else
            {
                proErrorLabel.Visible = false;
            }
            if (barcodeTxt.Text == "")
            {
                barcodeErrorLabel.Visible = true;
            }
            else
            {
                barcodeErrorLabel.Visible = false;
            }
            if (expiryPicker.Value < DateTime.Now)
            {
                expiryErrorLabel.Visible = true; expiryErrorLabel.Text = "Invalid Date";
            }
            else
            {
                expiryErrorLabel.Visible = false;
            }
            if (expiryPicker.Value.Date == DateTime.Now.Date)
            {
                expiryErrorLabel.Visible = false;
            }                                                                                       //this fix the problem that we can use the current date
            if (priceTxt.Text == "")
            {
                priceErrorLabel.Visible = true;
            }
            else
            {
                priceErrorLabel.Visible = false;
            }
            if (categoryDD.SelectedIndex == -1 || categoryDD.SelectedIndex == 0)
            {
                catErrorLabel.Visible = true;
            }
            else
            {
                catErrorLabel.Visible = false;
            }

            //final if
            if (proErrorLabel.Visible || barcodeErrorLabel.Visible || expiryErrorLabel.Visible || priceErrorLabel.Visible || catErrorLabel.Visible)
            {
                MainClass.ShowMSG("Fields with * are mandatory", "Stop", "Error");
            }
            else
            {
                if (edit == 0) //Code for SAVE operation
                {
                    insertion i = new insertion();
                    if (expiryPicker.Value.Date == DateTime.Now.Date) //if the expiry date is set now, then we set the value null
                    {
                        i.insertProduct(proTxt.Text, barcodeTxt.Text, Convert.ToSingle(priceTxt.Text), Convert.ToInt32(categoryDD.SelectedValue));
                    }
                    else //if the expiry date is set in another date different from now, we save the value
                    {
                        i.insertProduct(proTxt.Text, barcodeTxt.Text, Convert.ToSingle(priceTxt.Text), Convert.ToInt32(categoryDD.SelectedValue), expiryPicker.Value);
                    }
                    r.showProducts(dataGridView1, proIDGV, proGV, expiryGV, catGV, priceGV, barcodeGV, 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.Date == DateTime.Now.Date) //if the expiry date is set now, then we set the value null
                        {
                            u.updateProduct(prodID, proTxt.Text, barcodeTxt.Text, Convert.ToSingle(priceTxt.Text), Convert.ToInt32(categoryDD.SelectedValue));
                        }
                        else //if the expiry date is set in another date different from now, we save the value
                        {
                            u.updateProduct(prodID, proTxt.Text, barcodeTxt.Text, Convert.ToSingle(priceTxt.Text), Convert.ToInt32(categoryDD.SelectedValue), expiryPicker.Value);
                        }
                        r.showProducts(dataGridView1, proIDGV, proGV, expiryGV, catGV, priceGV, barcodeGV, catIDGV);
                        MainClass.disable_reset(leftPanel);
                    }
                }
            }
        }
Beispiel #18
0
        public override void saveBtn_Click(object sender, EventArgs e)
        {
            //Here we enable and disable the red asterisc "*" in the form, validating that no txt left unfilled
            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 (emailTxt.Text == "")
            {
                emailErrorLabel.Visible = true;
            }
            else
            {
                emailErrorLabel.Visible = false;
            }
            if (phoneTxt.Text == "")
            {
                phoneErrorLabel.Visible = true;
            }
            else
            {
                phoneErrorLabel.Visible = false;
            }
            if (statusDD.SelectedIndex == -1)
            {
                statusErrorLabel.Visible = true;
            }
            else
            {
                statusErrorLabel.Visible = false;
            }

            if (nameErrorLabel.Visible || usernameErrorLabel.Visible || passwordErrorLabel.Visible || emailErrorLabel.Visible || phoneErrorLabel.Visible || statusErrorLabel.Visible)
            {
                MainClass.ShowMSG("Fields with * are mandatory", "Stop", "Error"); //Error is the type of msg
            }
            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();

                    i.insertUser(nameTxt.Text, usernameTxt.Text, passwordTxt.Text, emailTxt.Text, phoneTxt.Text, stat);
                    r.showUsers(dataGridView1, UserIDGV, 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 record?", "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;
                        }
                        u.updateUser(userID, nameTxt.Text, usernameTxt.Text, passwordTxt.Text, emailTxt.Text, phoneTxt.Text, stat);
                        r.showUsers(dataGridView1, UserIDGV, NameGV, UserNameGV, PassGV, EmailGV, PhoneGV, StatusGV);
                        MainClass.disable_reset(leftPanel);
                    }
                }
            }
        }