public Add_Product(int PID) { InitializeComponent(); ID = PID; cmbCategory.DataSource = GeneralMethods.GetCategories(); cmbCategory.DisplayMember = "catname"; cmbCategory.SelectedIndex = -1; cmbVendor.DataSource = GeneralMethods.GetVendors(); cmbVendor.DisplayMember = "vname"; cmbVendor.SelectedIndex = -1; DataTable ProductDetails = new DataTable(); ProductDetails = GeneralMethods.GetProductByID(PID); cmbCategory.Text = (string)ProductDetails.Rows[0][0]; cmbVendor.Text = (string)ProductDetails.Rows[0][1]; txtName.Text = (string)ProductDetails.Rows[0][2]; txtProfit.Text = Convert.ToString(ProductDetails.Rows[0][3]); rtxtDescription.Text = Convert.ToString(ProductDetails.Rows[0][4]); btnAddProduct.Visible = false; btnUpdateProduct.Visible = true; }
private void btnAdd_Click(object sender, EventArgs e) { int q, p; if (String.IsNullOrWhiteSpace(txtQuantity.Text)) { MessageBox.Show("Please enter quantity first!", "Error!"); } else if (!(Int32.TryParse(txtQuantity.Text, out q))) { MessageBox.Show("Please enter a valid quantity!", "Error!"); } else if (String.IsNullOrWhiteSpace(txtPrice.Text)) { MessageBox.Show("Please enter price first!", "Error!"); } else if (!(Int32.TryParse(txtPrice.Text, out p))) { MessageBox.Show("Please enter a valid price!", "Error!"); } else { int pid = (int)(dgvProducts.SelectedRows[0].Cells[0].Value), rotquantity = Convert.ToInt32(txtQuantity.Text); float rottotalamount = Convert.ToSingle(txtPrice.Text); string pname = ((GeneralMethods.GetProductByID(pid)).Rows[0][2]).ToString(); ProductsReceivedTable.Rows.Add(pid, pname, rotquantity, rottotalamount); } }
private void btnAdd_Click(object sender, EventArgs e) { int q; if (String.IsNullOrWhiteSpace(txtQuantity.Text)) { MessageBox.Show("Please enter quantity first!", "Error"); } else if (!(Int32.TryParse(txtQuantity.Text, out q))) { MessageBox.Show("Please enter valid quantity!", "Error!"); } else { int CheckID = Convert.ToInt32(dgvProducts.SelectedRows[0].Cells[0].Value); foreach (DataRow row in CartTable.Rows) { if (Convert.ToInt32(row[0]) == CheckID) { int Pid = Convert.ToInt32(dgvProducts.SelectedRows[0].Cells[0].Value); int Rotquantity = Convert.ToInt32(txtQuantity.Text); int AvailableQuantity = (int)(dgvProducts.SelectedRows[0].Cells[5].Value); if (Rotquantity > AvailableQuantity) { if (MessageBox.Show(GeneralMethods.GetProductNameByID(Pid) + " is not available in the desired quantity. Do you wish to add the complete quantity avaialable i.e " + AvailableQuantity + " to the cart?", "Oops", MessageBoxButtons.YesNo) == DialogResult.Yes) { Rotquantity = AvailableQuantity; //float a = Convert.ToSingle(dgvProducts.SelectedRows[0].Cells[4].Value); ////float b = Convert.ToInt32(txtQuantity.Text); //float rottotalamount = a * Rotquantity; //string pname = ((GeneralMethods.GetProductByID(Pid)).Rows[0][2]).ToString(); //CartTable.Rows.Add(Pid, pname, Rotquantity, rottotalamount); int Amount = Convert.ToInt32(dgvProducts.SelectedRows[0].Cells[4].Value); //int Quantity = Convert.ToInt32(dgvProducts.SelectedRows[0].Cells[5].Value); int Quantity = AvailableQuantity; float Price = Amount; //int Profit = GeneralMethods.GetProfitRate(CheckID); //float SellingPrice = ((Price / 100) * Profit) + Price; row[2] = Quantity; row[3] = Price * Quantity; //dgvProducts.SelectedRows[0].Cells[5].Value = (Convert.ToInt32(dgvProducts.SelectedRows[0].Cells[5].Value)) - (Convert.ToInt32(txtQuantity.Text)); return; //break; } } else { int Amount = Convert.ToInt32(dgvProducts.SelectedRows[0].Cells[4].Value); int Quantity = Convert.ToInt32(dgvProducts.SelectedRows[0].Cells[5].Value); //int Quantity = AvailableQuantity; float Price = Amount; //int Profit = GeneralMethods.GetProfitRate(CheckID); //float SellingPrice = ((Price / 100) * Profit) + Price; row[2] = txtQuantity.Text; row[3] = Price * Convert.ToInt32(txtQuantity.Text); //dgvProducts.SelectedRows[0].Cells[5].Value = (Convert.ToInt32(dgvProducts.SelectedRows[0].Cells[5].Value)) - (Convert.ToInt32(txtQuantity.Text)); return; } } } int pid = (int)(dgvProducts.SelectedRows[0].Cells[0].Value), rotquantity = Convert.ToInt32(txtQuantity.Text); int availableQuantity = (int)(dgvProducts.SelectedRows[0].Cells[5].Value); if (rotquantity > availableQuantity) { if (availableQuantity == 0) { MessageBox.Show("Sorry! The selected product is Out of Stock..\nPlease Try again later..", "Sorry!"); } else if (MessageBox.Show(GeneralMethods.GetProductNameByID(pid) + " is not available in the desired quantity. Do you wish to add the complete quantity avaialable i.e " + availableQuantity + " to the cart?", "Oops", MessageBoxButtons.YesNo) == DialogResult.Yes) { rotquantity = availableQuantity; float a = Convert.ToSingle(dgvProducts.SelectedRows[0].Cells[4].Value); //float b = Convert.ToInt32(txtQuantity.Text); float rottotalamount = a * rotquantity; string pname = ((GeneralMethods.GetProductByID(pid)).Rows[0][2]).ToString(); CartTable.Rows.Add(pid, pname, rotquantity, rottotalamount); } } else { float a = Convert.ToSingle(dgvProducts.SelectedRows[0].Cells[4].Value); //float b = Convert.ToInt32(txtQuantity.Text); float rottotalamount = a * rotquantity; string pname = ((GeneralMethods.GetProductByID(pid)).Rows[0][2]).ToString(); CartTable.Rows.Add(pid, pname, rotquantity, rottotalamount); //dgvProducts.SelectedRows[0].Cells[5].Value = (Convert.ToInt32(dgvProducts.SelectedRows[0].Cells[5].Value)) - (Convert.ToInt32(txtQuantity.Text)); } } }