Exemple #1
0
        public override void delete_button_Click(object sender, EventArgs e)
        {
            if (category_name_textBox.Text == "" || is_active_category_comboBox.SelectedIndex == -1)
            {
                MainClass.ShowMsg("Please enter a record to delete.", "error");

                reset_disable();

                enable_crude_buttons();
            }
            else if (category_name_textBox.Enabled == true || is_active_category_comboBox.Enabled == true)
            {
                MainClass.ShowMsg("Please select record from the table.", "error");

                reset_disable();

                enable_crude_buttons();
            }
            else if ((category_name_textBox.Enabled == false && is_active_category_comboBox.Enabled == false) && (category_name_textBox.Text != "" && is_active_category_comboBox.SelectedIndex != -1))
            {
                try
                {
                    DialogResult ans = MessageBox.Show("Are you sure you want to delete current record.", "CONFIRM?", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

                    if (ans == DialogResult.Yes)
                    {
                        Hashtable ht = new Hashtable();

                        ht.Add("@id", categoryID);

                        if (SQL_TASKS.insert_update_delete("st_deletecategories", ht) > 0)
                        {
                            MainClass.ShowMsg(category_name_textBox.Text + " deleted successfully.", "Success");

                            reset_disable();

                            enable_crude_buttons();

                            LoadCategory();
                        }
                        else
                        {
                            MainClass.ShowMsg("Unable to save record.", "Error");

                            reset_disable();

                            enable_crude_buttons();
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);

                    reset_disable();

                    sql_con.Close();

                    enable_crude_buttons();
                }
            }
        }
Exemple #2
0
        private void purchaseinvoice_dataGridView_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                if (LoginCodeClass.isAdmin != true)
                {
                    if (e.RowIndex != -1 && e.ColumnIndex != -1)
                    {
                        if (e.ColumnIndex == 6)
                        {
                            DataGridViewRow row = purchaseinvoice_dataGridView.Rows[e.RowIndex];

                            DialogResult dr = MessageBox.Show("Are you sure you want to delete?\n\nIt will affect your stock.", "PRODUCT DELETION", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

                            if (dr == DialogResult.Yes)
                            {
                                using (TransactionScope sc = new TransactionScope())
                                {
                                    Hashtable ht = new Hashtable();

                                    ht.Add("@purchID", Convert.ToInt64(purchaseinvoice_comboBox.SelectedValue.ToString()));

                                    ht.Add("@userID", LoginCodeClass.USERID);

                                    ht.Add("@proID", Convert.ToInt32(row.Cells["productIDGV"].Value));

                                    ht.Add("@quan", Convert.ToInt32(row.Cells["productquantityGV"].Value));

                                    ht.Add("@date", DateTime.Today);

                                    SQL_TASKS.insert_update_delete("st_insertDeletedItemPI", ht);

                                    int q; object ob;

                                    ob = SQL_TASKS.getProductQuantity(Convert.ToInt32(row.Cells["productIDGV"].Value.ToString()));

                                    bool update = true;

                                    if (ob != null || Convert.ToInt32(ob) != 0)
                                    {
                                        update = true;
                                    }
                                    else
                                    {
                                        update = false;
                                    }

                                    if (update)
                                    {
                                        //update

                                        q = Convert.ToInt32(ob);

                                        q -= Convert.ToInt32(row.Cells["productquantityGV"].Value.ToString());

                                        Hashtable ht1 = new Hashtable();

                                        ht1.Add("@prodID", Convert.ToInt32(row.Cells["productIDGV"].Value.ToString()));

                                        ht1.Add("@quan", q);

                                        SQL_TASKS.insert_update_delete("st_updateSTOCK", ht1);

                                        Hashtable ht3 = new Hashtable();

                                        ht3.Add("@purchaseinvoicedetailsID", Convert.ToInt64(row.Cells["purchaseinvoiceIDGV"].Value.ToString()));

                                        if (SQL_TASKS.insert_update_delete("st_deletePRODUCTSfromPURCHASEINVOICEDETAILS", ht3) > 0)
                                        {
                                            MainClass.ShowMsg("Deleted successfully.", "Success");

                                            gross_total_price_label.Text = "0.00";

                                            LoadPurchaseInvoiceDetails(); purchaseinvoice_comboBox.SelectedIndex = -1;
                                        }
                                        else
                                        {
                                            MainClass.ShowMsg("Unable to delete.", "Error");

                                            gross_total_price_label.Text = "0.00";

                                            purchaseinvoice_comboBox.SelectedIndex = -1;
                                        }

                                        sc.Complete();
                                    }
                                }
                            }
                        }
                    }
                }
                else
                {
                    throw new Exception("Admin cannot delete purchase invoice details.To delete purchase invoice details login with an user account.");
                }
            }
            catch (Exception ex)
            {
                MainClass.ShowMsg(ex.Message, "Error");
            }
        }
Exemple #3
0
        public override void save_button_Click(object sender, EventArgs e)
        {
            if (category_name_textBox.Text == "" || is_active_category_comboBox.SelectedIndex == -1)
            {
                MainClass.ShowMsg("Please enter all required information.", "error");

                reset_disable();

                enable_crude_buttons();
            }
            else
            {
                if (Convert.ToString(is_active_category_comboBox.SelectedItem) == "Yes")
                {
                    stat = 1; //active
                }
                else if (Convert.ToString(is_active_category_comboBox.SelectedItem) == "No")
                {
                    stat = 0; //in-active
                }

                if (edit == 0) //0 to add record
                {
                    try
                    {
                        Hashtable ht = new Hashtable();

                        ht.Add("@name", category_name_textBox.Text);

                        ht.Add("@isActive", stat);

                        if (SQL_TASKS.insert_update_delete("st_insertcategories", ht) > 0)
                        {
                            MainClass.ShowMsg(category_name_textBox.Text + " added successfully to the system.", "Success");

                            reset_disable();

                            enable_crude_buttons();

                            LoadCategory();
                        }
                        else
                        {
                            MainClass.ShowMsg("Unable to save record.", "Error");

                            reset_disable();

                            enable_crude_buttons();
                        }

                        LoadCategory();

                        enable_crude_buttons();

                        reset_disable();
                    }
                    catch (Exception ex)
                    {
                        MainClass.ShowMsg(ex.Message, "error");

                        reset_disable();

                        enable_crude_buttons();
                    }
                }
                else if (edit == 1) // to update record
                {
                    if (Convert.ToString(is_active_category_comboBox.SelectedItem) == "Yes")
                    {
                        stat = 1; //active
                    }
                    else if (Convert.ToString(is_active_category_comboBox.SelectedItem) == "No")
                    {
                        stat = 0; //in-active
                    }

                    try
                    {
                        Hashtable ht = new Hashtable();

                        ht.Add("@id", categoryID);

                        ht.Add("@name", category_name_textBox.Text);

                        ht.Add("@isActive", stat);

                        if (SQL_TASKS.insert_update_delete("st_updatecategories", ht) > 0)
                        {
                            MainClass.ShowMsg(category_name_textBox.Text + " updated successfully to the system.", "Success");

                            reset_disable();

                            enable_crude_buttons();

                            LoadCategory();
                        }
                        else
                        {
                            MainClass.ShowMsg("Unable to save record.", "Error");

                            reset_disable();

                            enable_crude_buttons();
                        }

                        LoadCategory();

                        edit = 0;
                    }
                    catch (Exception ex)
                    {
                        MainClass.ShowMsg(ex.Message, "error");

                        reset_disable();

                        enable_crude_buttons();
                    }
                }
            }
        }
Exemple #4
0
        public override void delete_button_Click(object sender, EventArgs e)
        {
            if (supplier_name_textBox.Text == "" || contact_person_textBox.Text == "" || phone1_textBox.Text == "" || address_textBox_suppliers.Text == "" || NTN_textBox.Text == "" || supplier_status_comboBox.SelectedIndex == -1)
            {
                MainClass.ShowMsg("Please enter a record to delete.", "error");

                MainClass.disbale_reset(left_panel_sample2);

                enable_crude_buttons();
            }
            else if (supplier_name_textBox.Enabled == true || contact_person_textBox.Enabled == true || phone1_textBox.Enabled == true || address_textBox_suppliers.Enabled == true || NTN_textBox.Enabled == true || supplier_status_comboBox.Enabled == true)
            {
                MainClass.ShowMsg("Please select record from the table.", "error");

                MainClass.disbale_reset(left_panel_sample2);

                enable_crude_buttons();
            }
            else if ((supplier_name_textBox.Enabled == false || contact_person_textBox.Enabled == false || phone1_textBox.Enabled == false || address_textBox_suppliers.Enabled == false || NTN_textBox.Enabled == false || supplier_status_comboBox.Enabled == false) && (supplier_name_textBox.Text != "" || contact_person_textBox.Text != "" || phone1_textBox.Text != "" || address_textBox_suppliers.Text != "" || NTN_textBox.Text != "" || supplier_status_comboBox.SelectedIndex != -1))
            {
                try
                {
                    DialogResult ans = MessageBox.Show("Are you sure you want to delete current record.", "CONFIRM?", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

                    if (ans == DialogResult.Yes)
                    {
                        Hashtable ht = new Hashtable();

                        ht.Add("@supp_id", supplierID);

                        if (SQL_TASKS.insert_update_delete("st_deleteSUPPLIERS", ht) > 0)
                        {
                            MainClass.ShowMsg(supplier_name_textBox.Text + " deleted successfully.", "Success");

                            MainClass.disbale_reset(left_panel_sample2);

                            enable_crude_buttons();

                            loadSuppliers();
                        }
                        else
                        {
                            MainClass.ShowMsg("Unable to save record.", "Error");

                            MainClass.disbale_reset(left_panel_sample2);

                            enable_crude_buttons();
                        }

                        MainClass.disbale_reset(left_panel_sample2);

                        enable_crude_buttons();

                        loadSuppliers();
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);

                    MainClass.disbale_reset(left_panel_sample2);

                    enable_crude_buttons();
                }
            }
        }
        public override void save_button_Click(object sender, EventArgs e)
        {
            if (product_name_textBox.Text == "" || barcode_textBox.Text == "" || dateTimePicker_expiry_products.Value < DateTime.Today || categories_comboBox.SelectedIndex == -1)
            {
                MainClass.ShowMsg("Please enter all required information.", "Error");

                reset_disable();

                enable_crude_buttons();
            }
            else
            {
                if (edit == 0) //0 to add record
                {
                    try
                    {
                        Hashtable ht = new Hashtable();

                        ht.Add("@productname", product_name_textBox.Text);

                        ht.Add("@productbarcode", barcode_textBox.Text);

                        ht.Add("@productexpirydate", dateTimePicker_expiry_products.Value);

                        ht.Add("@productcategoryID", Convert.ToInt32(categories_comboBox.SelectedValue.ToString()));

                        if (SQL_TASKS.insert_update_delete("st_insertPRODUCTS", ht) > 0)
                        {
                            MainClass.ShowMsg(product_name_textBox.Text + " added successfully to the system.", "Success");

                            reset_disable();

                            enable_crude_buttons();

                            LoadProducts();
                        }
                        else
                        {
                            MainClass.ShowMsg("Unable to save record.", "Error");

                            reset_disable();

                            enable_crude_buttons();
                        }

                        LoadProducts();

                        enable_crude_buttons();

                        reset_disable();
                    }
                    catch (Exception ex)
                    {
                        MainClass.ShowMsg(ex.Message, "Error");

                        reset_disable();

                        enable_crude_buttons();
                    }
                }
                else if (edit == 1) // to update record
                {
                    try
                    {
                        Hashtable ht = new Hashtable();

                        ht.Add("@productid", productID);

                        ht.Add("@productname", product_name_textBox.Text);

                        ht.Add("@productbarcode", barcode_textBox.Text);

                        ht.Add("@productexpirydate", dateTimePicker_expiry_products.Value);

                        ht.Add("@productcategoryID", Convert.ToInt32(categories_comboBox.SelectedValue.ToString()));

                        if (SQL_TASKS.insert_update_delete("st_updatePRODUCTS", ht) > 0)
                        {
                            MainClass.ShowMsg(product_name_textBox.Text + " updated successfully to the system.", "Success");

                            reset_disable();

                            enable_crude_buttons();

                            LoadProducts();
                        }
                        else
                        {
                            MainClass.ShowMsg("Unable to save record.", "Error");

                            reset_disable();

                            enable_crude_buttons();
                        }

                        edit = 0;
                    }
                    catch (Exception ex)
                    {
                        MainClass.ShowMsg(ex.Message, "Error");

                        reset_disable();

                        enable_crude_buttons();
                    }
                }
            }
        }
        public override void delete_button_Click(object sender, EventArgs e)
        {
            if (name_textBox.Text == "" || phone_number_textBox.Text == "" || password_textBox.Text == "" || email_textBox.Text == "")
            {
                MainClass.ShowMsg("Please enter a record to delete.", "error");

                MainClass.disbale_reset(left_panel_sample2);

                enable_crude_buttons();
            }
            else if (name_textBox.Enabled == true || phone_number_textBox.Enabled == true || password_textBox.Enabled == true || email_textBox.Enabled == true)
            {
                MainClass.ShowMsg("Please select record from the table.", "error");

                MainClass.disbale_reset(left_panel_sample2);

                enable_crude_buttons();
            }
            else if ((name_textBox.Enabled == false && phone_number_textBox.Enabled == false && password_textBox.Enabled == false && email_textBox.Enabled == false) && (name_textBox.Text != "" && phone_number_textBox.Text != "" && password_textBox.Text != "" && email_textBox.Text != ""))
            {
                try
                {
                    DialogResult ans = MessageBox.Show("Are you sure you want to delete current record.", "CONFIRM?", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

                    if (ans == DialogResult.Yes)
                    {
                        Hashtable ht = new Hashtable();

                        ht.Add("@id", USERID);

                        if (SQL_TASKS.insert_update_delete("st_deleteusers", ht) > 0)
                        {
                            MainClass.ShowMsg("User deleted successfully.", "Success");

                            MainClass.disbale_reset(left_panel_sample2);

                            enable_crude_buttons();

                            loadUsers();
                        }
                        else
                        {
                            MainClass.ShowMsg("Unable to save record.", "Error");

                            MainClass.disbale_reset(left_panel_sample2);

                            enable_crude_buttons();
                        }

                        MainClass.disbale_reset(left_panel_sample2);

                        enable_crude_buttons();

                        loadUsers();
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);

                    MainClass.disbale_reset(left_panel_sample2);

                    enable_crude_buttons();
                }
            }
        }
Exemple #7
0
        public override void save_button_Click(object sender, EventArgs e)
        {
            if (supplier_name_textBox.Text == "" || contact_person_textBox.Text == "" || phone1_textBox.Text == "" || address_textBox_suppliers.Text == "" || NTN_textBox.Text == "" || supplier_status_comboBox.SelectedIndex == -1)
            {
                MainClass.ShowMsg("Please enter all required information.", "error");

                MainClass.disbale_reset(left_panel_sample2);

                enable_crude_buttons();
            }
            else
            {
                if (Convert.ToString(supplier_status_comboBox.SelectedItem) == "Active")
                {
                    stat = 1; //active
                }
                else if (Convert.ToString(supplier_status_comboBox.SelectedItem) == "In-active")
                {
                    stat = 0; //in-active
                }

                if (edit == false) //0 to add record
                {
                    try
                    {
                        Hashtable ht = new Hashtable();

                        ht.Add("@suppliername", supplier_name_textBox.Text);

                        ht.Add("@contactpersonname", contact_person_textBox.Text);

                        ht.Add("@phone1", phone1_textBox.Text);

                        ht.Add("@phone2", phone2_textBox.Text);

                        ht.Add("@address", address_textBox_suppliers.Text);

                        ht.Add("@ntn", NTN_textBox.Text);

                        ht.Add("@status", stat);

                        if (SQL_TASKS.insert_update_delete("st_insertSUPPLIERS", ht) > 0)
                        {
                            MainClass.ShowMsg(supplier_name_textBox.Text + " added successfully to the system.", "Success");

                            MainClass.disbale_reset(left_panel_sample2);

                            enable_crude_buttons();

                            loadSuppliers();
                        }
                        else
                        {
                            MainClass.ShowMsg("Unable to save record.", "Error");

                            MainClass.disbale_reset(left_panel_sample2);

                            enable_crude_buttons();
                        }
                    }
                    catch (Exception ex)
                    {
                        MainClass.ShowMsg(ex.Message, "Error");

                        MainClass.disbale_reset(left_panel_sample2);

                        enable_crude_buttons();
                    }
                }
                else if (edit == true) // to update record
                {
                    if (Convert.ToString(supplier_status_comboBox.SelectedItem) == "Active")
                    {
                        stat = 1; //active
                    }
                    else if (Convert.ToString(supplier_status_comboBox.SelectedItem) == "In-active")
                    {
                        stat = 0; //in-active
                    }

                    try
                    {
                        Hashtable ht = new Hashtable();

                        ht.Add("@suppliername", supplier_name_textBox.Text);

                        ht.Add("@contactpersonname", contact_person_textBox.Text);

                        ht.Add("@phone1", phone1_textBox.Text);

                        ht.Add("@phone2", phone2_textBox.Text);

                        ht.Add("@address", address_textBox_suppliers.Text);

                        ht.Add("@ntn", NTN_textBox.Text);

                        ht.Add("@status", stat);

                        ht.Add("@supp_id", supplierID);

                        if (SQL_TASKS.insert_update_delete("st_updateSUPPLIERS", ht) > 0)
                        {
                            MainClass.ShowMsg(supplier_name_textBox.Text + " updated successfully.", "Success");

                            MainClass.disbale_reset(left_panel_sample2);

                            enable_crude_buttons();

                            loadSuppliers();
                        }
                        else
                        {
                            MainClass.ShowMsg("Unable to save record.", "Error");

                            MainClass.disbale_reset(left_panel_sample2);

                            enable_crude_buttons();
                        }
                        edit = false;

                        loadSuppliers();
                    }
                    catch (Exception ex)
                    {
                        MainClass.ShowMsg(ex.Message, "error");

                        MainClass.disbale_reset(left_panel_sample2);

                        enable_crude_buttons();
                    }
                }
            }
        }
        public override void save_button_Click(object sender, EventArgs e)
        {
            if (name_textBox.Text == "" || password_textBox.Text == "" || email_textBox.Text == "" || phone_number_label.Text == "" || status_comboBox.SelectedIndex == -1)
            {
                MainClass.ShowMsg("Please enter all required information.", "error");

                MainClass.disbale_reset(left_panel_sample2);

                enable_crude_buttons();
            }
            else
            {
                if (Convert.ToString(status_comboBox.SelectedItem) == "Active")
                {
                    stat = 1; //active
                }
                else if (Convert.ToString(status_comboBox.SelectedItem) == "In-active")
                {
                    stat = 0; //in-active
                }

                if (edit == 0) //0 to add record
                {
                    try
                    {
                        Hashtable ht = new Hashtable();

                        ht.Add("@name", name_textBox.Text);

                        ht.Add("@email", email_textBox.Text);

                        ht.Add("@password", password_textBox.Text);

                        ht.Add("@phone", phone_number_textBox.Text);

                        ht.Add("@status", stat);

                        ht.Add("@role", role_textBox.Text);

                        if (SQL_TASKS.insert_update_delete("st_insertusers", ht) > 0)
                        {
                            MainClass.ShowMsg("User added successfully to the system.", "Success");

                            MainClass.disbale_reset(left_panel_sample2);

                            enable_crude_buttons();

                            loadUsers();
                        }
                        else
                        {
                            MainClass.ShowMsg("Unable to save record.", "Error");

                            MainClass.disbale_reset(left_panel_sample2);

                            enable_crude_buttons();
                        }
                    }
                    catch (Exception ex)
                    {
                        MainClass.ShowMsg(ex.Message, "Error");

                        MainClass.disbale_reset(left_panel_sample2);

                        enable_crude_buttons();
                    }
                }
                else if (edit == 1) // to update record
                {
                    if (Convert.ToString(status_comboBox.SelectedItem) == "Active")
                    {
                        stat = 1; //active
                    }
                    else if (Convert.ToString(status_comboBox.SelectedItem) == "In-active")
                    {
                        stat = 0; //in-active
                    }

                    try
                    {
                        if (name_textBox.Text == temp_name && phone_number_textBox.Text == temp_phone && password_textBox.Text == temp_password && email_textBox.Text == temp_mail && status_comboBox.Text == temp_status)
                        {
                            MainClass.ShowMsg("This record is already saved.", "error");

                            MainClass.disbale_reset(left_panel_sample2);

                            enable_crude_buttons();
                        }

                        Hashtable ht = new Hashtable();

                        ht.Add("@name", name_textBox.Text);

                        ht.Add("@email", email_textBox.Text);

                        ht.Add("@password", password_textBox.Text);

                        ht.Add("@phone", phone_number_textBox.Text);

                        ht.Add("@status", stat);

                        ht.Add("@role", role_textBox.Text);

                        ht.Add("@id", USERID);

                        if (SQL_TASKS.insert_update_delete("st_updateusers", ht) > 0)
                        {
                            MainClass.ShowMsg("User updated successfully.", "Success");

                            MainClass.disbale_reset(left_panel_sample2);

                            enable_crude_buttons();

                            loadUsers();
                        }
                        else
                        {
                            MainClass.ShowMsg("Unable to save record.", "Error");

                            MainClass.disbale_reset(left_panel_sample2);

                            enable_crude_buttons();
                        }
                        edit = 0;

                        loadUsers();
                    }
                    catch (Exception ex)
                    {
                        MainClass.ShowMsg(ex.Message, "error");

                        MainClass.disbale_reset(left_panel_sample2);

                        enable_crude_buttons();
                    }
                }
            }
        }
Exemple #9
0
        public override void save_button_Click(object sender, EventArgs e)
        {
            bool success = false;

            int che = 0;

            try
            {
                if (category_comboBox_product_pricing.SelectedIndex != -1 && product_pricing_dataGridView.Rows.Count != 0)
                {
                    foreach (DataGridViewRow row in product_pricing_dataGridView.Rows)
                    {
                        if ((bool)row.Cells["selectGV"].FormattedValue == true)
                        {
                            ++che;

                            float disc, pm, sp;

                            disc = row.Cells["discountGV"].Value == null ? 0 : Convert.ToSingle(row.Cells["discountGV"].Value.ToString());

                            pm = row.Cells["profitmarginGV"].Value == null ? 0 : Convert.ToSingle(row.Cells["profitmarginGV"].Value.ToString());

                            Hashtable ht = new Hashtable();

                            ht.Add("@prodID", row.Cells["productIDGV"].Value.ToString());

                            ht.Add("@bp", Convert.ToSingle(row.Cells["buyingpriceGV"].Value.ToString()));

                            if (disc == 0 && pm == 0)
                            {
                                sp = Convert.ToSingle(row.Cells["buyingpriceGV"].Value.ToString());
                            }
                            else
                            {
                                sp = Convert.ToSingle(row.Cells["finalpriceGV"].Value.ToString());
                            }

                            ht.Add("@sp", sp);

                            ht.Add("@buyingdate", DateTime.Today);

                            ht.Add("@profitper", pm);

                            ht.Add("@discount", disc);

                            ht.Add("@productbarcode", row.Cells["BarcodeGV"].Value.ToString());

                            if (SQL_TASKS.insert_update_delete("st_updatePRODUCTPRICE", ht) > 0)
                            {
                                success = true;
                            }
                            else
                            {
                                success = false;
                            }
                        }
                    }
                    if (success && che > 0)
                    {
                        MainClass.ShowMsg("Updated successfully...", "Success"); enable_crude_buttons(); che = 0;
                    }
                    else
                    {
                        throw new Exception("Unbale to update.Verify if the product is checked."); che = 0;
                    }
                }
                else
                {
                    throw new Exception("Select a product first!"); che = 0;
                }
            }
            catch (Exception ex)
            {
                MainClass.ShowMsg(ex.Message, "Error");

                enable_crude_buttons();

                che = 0;
            }
        }
        public override void save_button_Click(object sender, EventArgs e)
        {
            if (purchase_dataGridView.Rows.Count == 0 || purchase_dataGridView.Rows.Count < 0)
            {
                MainClass.ShowMsg("Please enter all required information.", "error");

                MainClass.disbale_reset(left_panel_sample2);

                enable_crude_buttons();
            }
            else
            {
                MainClass.disbale_reset(left_panel_sample2); enable_crude_buttons();

                try
                {
                    using (TransactionScope sc = new TransactionScope())
                    {
                        int compare, compareTO;

here:

                        for (int i = 0; i < purchase_dataGridView.Rows.Count; ++i)
                        {
                            compare = Convert.ToInt32(purchase_dataGridView.Rows[i].Cells["productIDGV"].Value);

                            for (int j = i + 1; j < purchase_dataGridView.Rows.Count; ++j)
                            {
                                compareTO = Convert.ToInt32(purchase_dataGridView.Rows[j].Cells["productIDGV"].Value);

                                if (compare == compareTO)
                                {
                                    if (correctIT == false)
                                    {
                                        DialogResult dr = MessageBox.Show("You added a duplicate product which is not allowed.\n\nDo you want to remove that duplicate product and add its quantity?", "Duplicate product(s) encountered!", MessageBoxButtons.YesNo, MessageBoxIcon.Error);

                                        if (DialogResult.Yes == dr)
                                        {
                                            correctIT = true;

                                            goto here;
                                        }
                                        else
                                        {
                                            correctIT = false;

                                            throw new Exception("Duplicate products are not allowed!");
                                        }
                                    }
                                    else
                                    {
                                        Int32 originalproductTOTAL, originalproductVALUE, dupliactedproductVALUE, dupliactedproductTOTAL;

                                        originalproductVALUE = Convert.ToInt32(purchase_dataGridView.Rows[i].Cells["productquantityGV"].Value);

                                        dupliactedproductVALUE = Convert.ToInt32(purchase_dataGridView.Rows[j].Cells["productquantityGV"].Value);

                                        originalproductTOTAL = Convert.ToInt32(purchase_dataGridView.Rows[i].Cells["totalGV"].Value);

                                        dupliactedproductTOTAL = Convert.ToInt32(purchase_dataGridView.Rows[j].Cells["totalGV"].Value);

                                        originalproductVALUE += dupliactedproductVALUE;

                                        originalproductTOTAL += dupliactedproductTOTAL;

                                        purchase_dataGridView.Rows[i].Cells["productquantityGV"].Value = originalproductVALUE;

                                        purchase_dataGridView.Rows[i].Cells["totalGV"].Value = originalproductTOTAL;

                                        int beforeREMOVE = purchase_dataGridView.Rows.Count; int afterREMOVE;

                                        purchase_dataGridView.Rows.Remove(purchase_dataGridView.Rows[j]);

                                        afterREMOVE = purchase_dataGridView.Rows.Count;

                                        if (afterREMOVE < beforeREMOVE)
                                        {
                                            MainClass.ShowMsg("Operation successfull.", "Success");
                                        }
                                        else
                                        {
                                            throw new Exception("An error occured during removing duplicated products!");
                                        }
                                    }
                                }
                            }
                        }

                        SQL_TASKS ss = new SQL_TASKS();

                        foreach (DataGridViewRow row in purchase_dataGridView.Rows)
                        {
                            //inserting purchase invoice

                            purchaseinvoiceID_FROM_SQL_TASKS = ss.InsertPurchaseinvoice(DateTime.Today, LoginCodeClass.USERID, Convert.ToInt32(row.Cells["supplierIDGV"].Value));

                            //inserting purchase invoice details

                            count += ss.insertPurchaseinvoicedetails(purchaseinvoiceID_FROM_SQL_TASKS, Convert.ToInt32(row.Cells["productIDGV"].Value.ToString()), Convert.ToInt32(row.Cells["productquantityGV"].Value.ToString()), Convert.ToSingle(row.Cells["totalGV"].Value.ToString()));

                            SqlConnection sql_con = new SqlConnection(MainClass.connection());

                            SqlCommand cmd = new SqlCommand();

                            cmd.Connection = sql_con;

                            cmd.CommandType = CommandType.Text;

                            cmd.CommandText = "select pp_prodID from ProductPrice where pp_ProductBarcode='" + row.Cells["productbarcodeGV"].Value.ToString() + "' ";

                            sql_con.Open();
                            object check = cmd.ExecuteScalar();

                            sql_con.Close();

                            if (check == null) //product not present
                            {
                                Hashtable ht1 = new Hashtable();

                                ht1.Add("@prodID", row.Cells["productIDGV"].Value.ToString());

                                ht1.Add("@bp", Convert.ToSingle(row.Cells["totalGV"].Value.ToString()));

                                ht1.Add("@sp", DBNull.Value);

                                ht1.Add("@buyingdate", DateTime.Today);

                                ht1.Add("@profitper", DBNull.Value);

                                ht1.Add("@discount", DBNull.Value);

                                ht1.Add("@productbarcode", row.Cells["productbarcodeGV"].Value.ToString());

                                // inserting product price:

                                if (SQL_TASKS.insert_update_delete("st_insertPRODUCTPRICE", ht1) > 0)
                                {
                                    success = true;
                                }
                                else
                                {
                                    success = false;
                                }
                            }
                            else //product present
                            {
                                Hashtable ht2 = new Hashtable();

                                ht2.Add("@prodID", row.Cells["productIDGV"].Value.ToString());

                                cmd.CommandText = "select pp_buyingPrice from ProductPrice where pp_prodID='" + row.Cells["productIDGV"].Value.ToString() + "' ";

                                sql_con.Open();

                                Int64 ExistingProductBuyingPrice = Convert.ToInt64(cmd.ExecuteScalar());

                                sql_con.Close();

                                Int64 finalp = Convert.ToInt64(row.Cells["totalGV"].Value) + ExistingProductBuyingPrice;

                                Hashtable htx = new Hashtable();

                                htx.Add("@prodID", row.Cells["productIDGV"].Value.ToString());

                                htx.Add("@bp", finalp);

                                if (SQL_TASKS.insert_update_delete("st_updatePRODUCTPRICEforPURCHASEINVOICE", htx) > 0)
                                {
                                    success = true;
                                }
                                else
                                {
                                    success = false;
                                }
                            }

                            int q;

                            object stockcount;

                            bool DoesExist = SQL_TASKS.IfProductExist(Convert.ToInt64(row.Cells["productIDGV"].Value.ToString()));

                            if (DoesExist) //if product does exist
                            {
                                //update stock

                                stockcount = SQL_TASKS.getProductQuantityfromSTOCK(Convert.ToInt32(row.Cells["productIDGV"].Value.ToString()));

                                q = Convert.ToInt32(stockcount);

                                q += Convert.ToInt32(row.Cells["productquantityGV"].Value.ToString());

                                Hashtable hta = new Hashtable();

                                hta.Add("@prodID", Convert.ToInt32(row.Cells["productIDGV"].Value.ToString()));

                                hta.Add("@quan", q);

                                //updating stock:

                                if (SQL_TASKS.insert_update_delete("st_updateSTOCK", hta) > 0)
                                {
                                    success = true;
                                }
                            }
                            else //if product does not exist
                            {
                                //insert

                                Hashtable htb = new Hashtable();

                                htb.Add("@prodID", Convert.ToInt32(row.Cells["productIDGV"].Value.ToString()));

                                htb.Add("@quan", Convert.ToInt32(row.Cells["productquantityGV"].Value.ToString()));

                                // inserting stock:

                                if (SQL_TASKS.insert_update_delete("st_insertSTOCK", htb) > 0)
                                {
                                    success = true;
                                }
                                else
                                {
                                    success = false;
                                }
                            }
                        }

                        if (count > 0 && success == true)
                        {
                            MainClass.ShowMsg("Purchase Invoice created successfully.", "Success");

                            MainClass.disbale_reset(left_panel_sample2);

                            enable_crude_buttons();

                            purchase_dataGridView.Rows.Clear(); gross_total_price_label.Text = "";
                        }
                        else
                        {
                            MainClass.ShowMsg("Unable to create Purchase Invoice", "Error");

                            MainClass.disbale_reset(left_panel_sample2);

                            enable_crude_buttons();

                            purchase_dataGridView.Rows.Clear(); gross_total_price_label.Text = "";
                        }

                        sc.Complete();
                    }
                }
                catch (Exception ex)
                {
                    MainClass.ShowMsg(ex.Message, "Error");

                    MainClass.disbale_reset(left_panel_sample2);

                    enable_crude_buttons();
                }
            }
        }
Exemple #11
0
        private void pay_button_Click(object sender, EventArgs e)
        {
            try
            {
                if (gross_textBox.Text != "" && discount_textBox.Text != "" && payment_Type_comboBox.SelectedIndex != -1 && change_to_give_textBox.Text != "" && amount_given_textBox.Text != "")
                {
                    Hashtable ht = new Hashtable();

                    ht.Add("@done", LoginCodeClass.USERID);

                    ht.Add("@date", DateTime.Now);

                    ht.Add("@totalamt", Convert.ToSingle(gross_textBox.Text));

                    ht.Add("@totaldisc", Convert.ToSingle(discount_textBox.Text));

                    ht.Add("@givenamt", Convert.ToSingle(amount_given_textBox.Text));

                    ht.Add("@return", Convert.ToSingle(change_to_give_textBox.Text));

                    if (payment_Type_comboBox.SelectedIndex == 0)
                    {
                        ht.Add("@payType", 0); //0 means cash
                    }
                    else if (payment_Type_comboBox.SelectedIndex == 1)
                    {
                        ht.Add("@payType", 1);//1 means debit
                    }
                    else
                    {
                        ht.Add("@payType", 2);
                    }                               //2 means credit

                    DialogResult dr = MessageBox.Show("\n\tTotal Amount: " + gross_textBox.Text + "\n\tTotal Discount: " + discount_textBox.Text + "\n\tAmount Given: " + amount_given_textBox.Text + "\n\tAmount to return: " + change_to_give_textBox.Text + "\n\tPayment Type: " + payment_Type_comboBox.SelectedItem.ToString() + " \n\nAre you sure you want to submit current sales?", "Question...", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

                    if (DialogResult.Yes == dr)
                    {
                        using (TransactionScope sc = new TransactionScope())
                        {
                            if (SQL_TASKS.insert_update_delete("st_insertSALES", ht) > 0)
                            {
                                foreach (DataGridViewRow row in sales_dataGridView.Rows)
                                {
                                    int CurrentProductQuan = SQL_TASKS.getStockwrtProduct(Convert.ToInt32(row.Cells["ProductIDGV"].Value));

                                    Hashtable ht1 = new Hashtable();

                                    int x = CurrentProductQuan - Convert.ToInt32(row.Cells["ProductquantityGV"].Value);

                                    ht1.Add("@prodID", Convert.ToInt32(row.Cells["ProductIDGV"].Value));

                                    ht1.Add("@quan", x);

                                    SQL_TASKS.insert_update_delete("st_updateSTOCK", ht1);

                                    Hashtable ht2 = new Hashtable();

                                    ht2.Add("@saleID", SQL_TASKS.getLASTID("st_getSalesID"));

                                    ht2.Add("@prodID", Convert.ToInt64(row.Cells["productIDGV"].Value.ToString()));

                                    ht2.Add("@quantity", Convert.ToInt32(row.Cells["productquantityGV"].Value.ToString()));

                                    ht2.Add("@discount", Convert.ToSingle(row.Cells["discountGV"].Value.ToString()));

                                    ht2.Add("@sellingprice", Convert.ToSingle(row.Cells["TotalAmountGV"].Value.ToString()));

                                    SQL_TASKS.insert_update_delete("st_insertSalesDetails", ht2);
                                }

                                MainClass.ShowMsg("Record saved successfully.", "Success");

                                MainClass.disbale_reset(left_panel_sample2);

                                sales_dataGridView.Rows.Clear();

                                SALES_REPORT sr = new SALES_REPORT();

                                sr.ShowDialog();

                                gross_total_price_label.Text = "0.00";
                            }
                            else
                            {
                                throw new Exception("Unable to save record.");
                            }
                            sc.Complete();
                        }
                    }
                }
                else
                {
                    throw new Exception("Please fill all required fields.");
                }
            }
            catch (Exception ex)
            {
                MainClass.ShowMsg(ex.Message, "Error");
            }
        }
        //private void barcode_textBox_Validating(object sender, System.ComponentModel.CancelEventArgs e)
        //{
        //    try
        //    {
        //        if (barcode_textBox.Text != "")
        //        {
        //            if (sales_return_dataGridView.Rows.Count > 0)
        //            {
        //                using (TransactionScope sc = new TransactionScope())
        //                {
        //                    foreach (DataGridViewRow row in sales_return_dataGridView.Rows)
        //                    {
        //                        if (barcode_textBox.Text == row.Cells["BarcodeGV"].Value.ToString())
        //                        {
        //                            DialogResult dr = MessageBox.Show("Are you sure you want to return " + row.Cells["ProductGV"].Value.ToString() + "?", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

        //                            if (dr == DialogResult.Yes)
        //                            {
        //                                //----------------------INSERTING RECORD TO REFUND TABLE------------------
        //                                Hashtable htx = new Hashtable();

        //                                htx.Add("@refSaleID", Convert.ToInt64(row.Cells["ProductIDGV"].Value.ToString()));

        //                                htx.Add("@refDate", DateTime.Now);

        //                                htx.Add("@refDoneBy", Convert.ToInt64(row.Cells["UserIDGV"].Value.ToString()));

        //                                htx.Add("@refProdID", Convert.ToInt64(row.Cells["ProductIDGV"].Value.ToString()));

        //                                htx.Add("@refQuantity", Convert.ToInt64(row.Cells["QuantityGV"].Value.ToString()));

        //                                htx.Add("@refAmount", Convert.ToSingle(row.Cells["ProductPriceGV"].Value.ToString()));

        //                                int x = 0;

        //                                x += SQL_TASKS.insert_update_delete("st_insertRefundReturn", htx);

        //                                if (x > 0)
        //                                {
        //                                    MainClass.ShowMsg("Return and Refund Successfull", "Success");
        //                                    x = 0;
        //                                    ht.Clear();
        //                                }
        //                                else
        //                                {
        //                                    throw new Exception("Something went wrong");
        //                                }

        //                                //----------------------UPDATING STOCK------------------

        //                                int currentQuantity = (int)SQL_TASKS.getProductQuantity(Convert.ToInt32((row.Cells["ProductIDGV"].Value.ToString())));

        //                                int finalQuantity = currentQuantity - Convert.ToInt32(row.Cells["QuantityGV"].Value.ToString());

        //                                Hashtable htinsetrStock = new Hashtable();

        //                                htinsetrStock.Add("@prodID", Convert.ToInt64(row.Cells["ProductIDGV"].Value.ToString()));

        //                                htinsetrStock.Add("@quan", finalQuantity);

        //                                SQL_TASKS.insert_update_delete("st_updateSTOCK", htinsetrStock);

        //                                Int64 productID = Convert.ToInt64(row.Cells["ProductIDGV"].Value.ToString());

        //                                float productPrice = Convert.ToSingle(row.Cells["ProductPriceGV"].Value.ToString());

        //                                int product_quantity = Convert.ToInt32(row.Cells["QuantityGV"].Value.ToString());

        //                                amount_refund += productPrice;

        //                                amount_to_refund_textBox.Text = Math.Round(amount_refund, 0).ToString();

        //                                if (product_quantity == 0)
        //                                {
        //                                    if (ht.ContainsKey(row.Cells["ProductIDGV"].Value))
        //                                    {
        //                                        Int64 prodIDht = Convert.ToInt64(row.Cells["ProductIDGV"].Value.ToString());

        //                                        ht[prodIDht] = Convert.ToInt32(ht[prodIDht]) - 1;
        //                                    }
        //                                    else
        //                                    {
        //                                        ht.Add(row.Cells["ProductIDGV"].Value, 1);
        //                                    }

        //                                    sales_return_dataGridView.Rows.Remove(row);
        //                                }
        //                                else
        //                                {
        //                                    row.Cells["QuantityGV"].Value = product_quantity;

        //                                    row.Cells["PerProductTotalGV"].Value = Convert.ToSingle(row.Cells["PerProductTotalGV"].Value.ToString());

        //                                    if (ht.ContainsKey(row.Cells["ProductIDGV"].Value))
        //                                    {
        //                                        Int64 prodIDht = Convert.ToInt64(row.Cells["ProductIDGV"].Value.ToString());

        //                                        ht[prodIDht] = Convert.ToInt32(ht[prodIDht]) + 1;
        //                                    }
        //                                    else
        //                                    {
        //                                        ht.Add(row.Cells["ProductIDGV"].Value, 1);
        //                                    }
        //                                    sales_return_dataGridView.Rows.Remove(row);
        //                                }

        //                            }

        //                        }
        //                        break;
        //                    }
        //                    sc.Complete();
        //                }
        //            }
        //        }
        //    }
        //    catch (Exception ex)
        //    {
        //        MainClass.ShowMsg(ex.Message, "Error");
        //    }
        //}

        private void return_button_Click(object sender, EventArgs e)
        {
            try
            {
                bool found = false;

                if (barcode_textBox.Text != "")
                {
                    if (sales_return_dataGridView.Rows.Count > 0)
                    {
                        using (TransactionScope sc = new TransactionScope())
                        {
                            foreach (DataGridViewRow row in sales_return_dataGridView.Rows)
                            {
                                if (barcode_textBox.Text == row.Cells["BarcodeGV"].Value.ToString())
                                {
                                    DialogResult dr = MessageBox.Show("Are you sure you want to return " + row.Cells["ProductGV"].Value.ToString() + "?", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

                                    if (dr == DialogResult.Yes)
                                    {
                                        //----------------------INSERTING RECORD TO REFUND TABLE------------------
                                        Hashtable htx = new Hashtable();

                                        htx.Add("@refSaleID", Convert.ToInt64(row.Cells["saleIDGV"].Value.ToString()));

                                        htx.Add("@refDate", DateTime.Now);

                                        htx.Add("@refDoneBy", Convert.ToInt64(row.Cells["UserIDGV"].Value.ToString()));

                                        htx.Add("@refProdID", Convert.ToInt64(row.Cells["ProductIDGV"].Value.ToString()));

                                        htx.Add("@refQuantity", Convert.ToInt64(row.Cells["QuantityGV"].Value.ToString()));

                                        htx.Add("@refAmount", Convert.ToSingle(row.Cells["ProductPriceGV"].Value.ToString()));

                                        int x = 0;

                                        x += SQL_TASKS.insert_update_delete("st_insertRefundReturn", htx);

                                        if (x > 0)
                                        {
                                            MainClass.ShowMsg("Return and Refund Successfull", "Success");
                                            x = 0;
                                            ht.Clear();
                                        }
                                        else
                                        {
                                            throw new Exception("Something went wrong");
                                        }


                                        //----------------------UPDATING STOCK------------------

                                        int currentQuantity = (int)SQL_TASKS.getProductQuantityfromSTOCK(Convert.ToInt64((row.Cells["ProductIDGV"].Value.ToString())));

                                        int finalQuantity = currentQuantity - Convert.ToInt32(row.Cells["QuantityGV"].Value.ToString());

                                        Hashtable htinsertStock = new Hashtable();

                                        htinsertStock.Add("@prodID", row.Cells["ProductIDGV"].Value.ToString());

                                        htinsertStock.Add("@quan", finalQuantity);

                                        SQL_TASKS.insert_update_delete("st_updateSTOCK", htinsertStock);

                                        Int64 productID = Convert.ToInt64(row.Cells["ProductIDGV"].Value.ToString());

                                        float productPrice = Convert.ToSingle(row.Cells["ProductPriceGV"].Value.ToString());

                                        int product_quantity = Convert.ToInt32(row.Cells["QuantityGV"].Value.ToString());

                                        amount_refund += productPrice;

                                        amount_to_refund_textBox.Text = Math.Round(amount_refund, 0).ToString();

                                        if (product_quantity == 0)
                                        {
                                            if (ht.ContainsKey(row.Cells["ProductIDGV"].Value))
                                            {
                                                Int64 prodIDht = Convert.ToInt64(row.Cells["ProductIDGV"].Value.ToString());

                                                ht[prodIDht] = Convert.ToInt32(ht[prodIDht]) - 1;
                                            }
                                            else
                                            {
                                                ht.Add(row.Cells["ProductIDGV"].Value, 1);
                                            }

                                            sales_return_dataGridView.Rows.Remove(row);

                                            SalesReturnReceipt srr = new SalesReturnReceipt();

                                            srr.ShowDialog();
                                        }
                                        else
                                        {
                                            row.Cells["QuantityGV"].Value = product_quantity;

                                            row.Cells["PerProductTotalGV"].Value = Convert.ToSingle(row.Cells["PerProductTotalGV"].Value.ToString());

                                            if (ht.ContainsKey(row.Cells["ProductIDGV"].Value))
                                            {
                                                Int64 prodIDht = Convert.ToInt64(row.Cells["ProductIDGV"].Value.ToString());

                                                ht[prodIDht] = Convert.ToInt32(ht[prodIDht]) + 1;
                                            }
                                            else
                                            {
                                                ht.Add(row.Cells["ProductIDGV"].Value, 1);
                                            }

                                            sales_return_dataGridView.Rows.Remove(row);

                                            SalesReturnReceipt srr = new SalesReturnReceipt();

                                            srr.ShowDialog();
                                        }
                                    }
                                    found = true;
                                }
                                if (found)
                                {
                                    break;
                                }
                            }

                            sc.Complete();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MainClass.ShowMsg(ex.Message, "Error");
            }
        }