private void btnCreate_Click(object sender, EventArgs e)
        {
            if (CartTable.Rows.Count != 0)
            {
                GeneralMethods.CreateSalesOrder(CustID);
                SOID = GeneralMethods.GetSalesOrderID();
                int Sum = 0;

                foreach (DataRow row in CartTable.Rows)
                {
                    int   pid         = (Convert.ToInt32(row["ID"]));
                    int   quantity    = (Convert.ToInt32(row[2]));
                    float amount      = (Convert.ToSingle(row[3]));
                    int   OldQuantity = GeneralMethods.GetQuantity(pid);

                    Sum += (int)amount;



                    GeneralMethods.CreateSalesOrderTransaction(SOID, pid, quantity, amount);

                    float Price        = amount / quantity;
                    int   Profit       = GeneralMethods.GetProfitRate(pid);
                    float SellingPrice = ((Price / 100) * Profit) + Price;

                    GeneralMethods.UpdateProductQuantityOnSale(pid, (OldQuantity - quantity));
                    GeneralMethods.CreatePurchaseOrderMethod();


                    //if ((GeneralMethods.GetPreviousPurchaseOrderQuantity(pid) - quantity) > 0)
                    //{
                    //    GeneralMethods.CreatePurchaseOrderAfterReceive(GeneralMethods.GetProductVendor(pid), pid, (GeneralMethods.GetPreviousPurchaseOrderQuantity(pid) - quantity));

                    //}

                    //GeneralMethods.CreatePurchaseOrderMethod();
                }

                MessageBox.Show("Your total bill:\t" + Sum + "\nThank You For Shopping!", "Success!");
            }

            else
            {
                MessageBox.Show("Please add some items to cart first!", "Error!");
            }
        }
        private void btnAddProduct_Click(object sender, EventArgs e)
        {
            string ProductName, Description;
            int    CategoryID = 0, VendorID = 0, ProfitRate;
            bool   ValidSubmission = true;

            if (String.IsNullOrWhiteSpace(cmbCategory.Text))
            {
                ValidSubmission = false;
                MessageBox.Show("Please select a category for the product!", "Error");
            }

            else if (String.IsNullOrWhiteSpace(cmbVendor.Text))
            {
                ValidSubmission = false;
                MessageBox.Show("Please select a vendor for the product!", "Error");
            }

            else if (String.IsNullOrWhiteSpace(txtName.Text))
            {
                ValidSubmission = false;
                MessageBox.Show("Please enter a name for the product!", "Error");
            }

            else if (String.IsNullOrWhiteSpace(txtProfit.Text))
            {
                ValidSubmission = false;
                MessageBox.Show("Please enter a profit rate for the product!", "Error");
            }

            else if (!(Int32.TryParse(txtProfit.Text, out ProfitRate)))
            {
                ValidSubmission = false;
                MessageBox.Show("Please enter a valid profit rate!", "Error");
            }



            if (!(GeneralMethods.CheckCategory(cmbCategory.Text)))
            {
                if (MessageBox.Show("Are you sure you want to add a new category?", "Add New Category", MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes)
                {
                    GeneralMethods.AddCategory(cmbCategory.Text);
                    MessageBox.Show("Category added successfuly!", "Success");
                }
                CategoryID = GeneralMethods.GetCategory(cmbCategory.Text);
            }

            else if (GeneralMethods.CheckCategory(cmbCategory.Text))
            {
                CategoryID = GeneralMethods.GetCategory(cmbCategory.Text);
            }



            if (!(GeneralMethods.CheckVendor(cmbVendor.Text)))
            {
                if (MessageBox.Show("Are you sure you want to add a new vendor?", "Add New Vendor", MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes)
                {
                    GeneralMethods.AddVendor(cmbVendor.Text);
                    MessageBox.Show("Vendor added successfuly!", "Success");
                }
                VendorID = GeneralMethods.GetVendor(cmbVendor.Text);
            }

            else if (GeneralMethods.CheckVendor(cmbVendor.Text))
            {
                VendorID = GeneralMethods.GetVendor(cmbVendor.Text);
            }

            if (ValidSubmission)
            {
                ProductName = txtName.Text;
                ProfitRate  = Convert.ToInt32(txtProfit.Text);
                Description = rtxtDescription.Text;
                GeneralMethods.AddProduct(CategoryID, VendorID, ProductName, ProfitRate, Description);
                GeneralMethods.CreatePurchaseOrderMethod();
                MessageBox.Show("Product added successfully!", "Success");


                //int id = GeneralMethods.GetPurchaseOrderID();
                //GeneralMethods.CreatePurchaseOrderTransaction(id, VendorID, GeneralMethods.GetProductID(), 10);
            }
        }
        private void btnCreate_Click(object sender, EventArgs e)
        {
            if (ProductsReceivedTable.Rows.Count != 0)
            {
                //if (GeneralMethods.CreateNewReceieveOrder())
                //{
                GeneralMethods.CreateReceiveOrder(UserID);
                ROID = GeneralMethods.GetReceiveOrderID();
                //GeneralMethods.CreatePurchaseOrder();

                foreach (DataRow row in ProductsReceivedTable.Rows)
                {
                    int   pid      = (Convert.ToInt32(row["ID"]));
                    int   quantity = (Convert.ToInt32(row[2]));
                    float amount   = (Convert.ToSingle(row[3]));
                    GeneralMethods.CreateReceiveOrderTransaction(ROID, UserID, pid, quantity, amount);

                    float Price        = amount / quantity;
                    int   Profit       = GeneralMethods.GetProfitRate(pid);
                    float SellingPrice = ((Price / 100) * Profit) + Price;
                    int   OldQuantity  = GeneralMethods.GetQuantity(pid);
                    GeneralMethods.UpdateProductQuantityAndPrice(pid, (quantity + OldQuantity), Price, SellingPrice);


                    //if ((GeneralMethods.GetPreviousPurchaseOrderQuantity(pid) - quantity) > 0)
                    //{
                    //    GeneralMethods.CreatePurchaseOrderAfterReceive(GeneralMethods.GetProductVendor(pid), pid, (GeneralMethods.GetPreviousPurchaseOrderQuantity(pid) - quantity));

                    //}
                }

                //DataTable LastPurchaseOrder = new DataTable();
                //DataTable NewPurchaseOrder = new DataTable();
                //LastPurchaseOrder = GeneralMethods.GetPurchaseOrderTransactionTable((GeneralMethods.GetPurchaseOrderID() - 1));
                //NewPurchaseOrder = GeneralMethods.GetPurchaseOrderTransactionTable(GeneralMethods.GetPurchaseOrderID());

                //foreach (DataRow row in LastPurchaseOrder.Rows)
                //{
                //    bool Present = false;
                //    int VendorID = 0;
                //    int Quantity = 0;

                //    int pid = Convert.ToInt32(row["pid"]);
                //    foreach (DataRow NewRow in NewPurchaseOrder.Rows)
                //    {
                //        int npid = Convert.ToInt32(NewRow["pid"]);

                //        if (npid == pid)
                //        {
                //            Present = true;
                //            break;
                //        }

                //        VendorID = Convert.ToInt32(row["vid"]);
                //        Quantity = Convert.ToInt32(row["potquantity"]);

                //        if (!Present)
                //        {
                //            GeneralMethods.CreatePurchaseOrderAfterReceive(VendorID, pid, Quantity);
                //        }
                //    }


                //}

                GeneralMethods.CreatePurchaseOrderMethod();
                MessageBox.Show("Receive Order Successfully Created!", "Success!");
                //}
            }

            else
            {
                MessageBox.Show("Please select some items first!", "Error!");
            }
        }