private void textBoxSnoDefective_Leave(object sender, EventArgs e) { SqlDataReader dr = dbConnection.query("select sales.billno,billdetails.billdate,sales.productID,billdetails.custID from sales,billdetails where sales.billno=billdetails.billno and sales.serialno='" + textBoxSnoDefective.Text + "'"); if (dr.Read()) { textBoxBillNo.Text = dr[0].ToString(); textBoxBillDate.Text = dr[1].ToString(); prodid=dr[2].ToString(); int stockcount =Convert.ToInt32( dbConnection.executescalar("select count(product.productID) from product where productID='" + dr[2].ToString() + "' and salestatus='INSTOCK'")); customerid = dr[3].ToString(); if (stockcount == 0) { insufficientstock=true; DialogResult rs = MessageBox.Show("The Product is currently out of stock.\nDo you want to place an order?", "Out of stock", MessageBoxButtons.YesNo); if (rs == DialogResult.Yes) { OrderProducts ordprod = new OrderProducts(prodid, "1", customerid); ordprod.Show(); } } } else { MessageBox.Show("Product Not found in sold products. Please try again."); textBoxSnoDefective.Text = ""; textBoxSnoDefective.Focus(); } }
private void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e) { //MessageBox.Show(sender.GetType().ToString()); int col = e.ColumnIndex; try { if (e.ColumnIndex == 3&& oldbill==false) { if (false == FieldValidation.integervalidation(dataGridView1.Rows[e.RowIndex].Cells[3].Value.ToString())) { string productid = ""; int availableproduct; string customername = textBoxdealerID.Text; int prodqty = Convert.ToInt32(dataGridView1.Rows[e.RowIndex].Cells[3].Value.ToString()); SqlDataReader dr = dbConnection.query("select productdetails.productID,count(product.productID) from product,productdetails where product.productID=productdetails.productID group by product.productID,productdetails.itemname,productdetails.productID,product.salestatus having productdetails.itemname='" + dataGridView1.Rows[e.RowIndex].Cells[1].Value.ToString() + "' and product.salestatus='INSTOCK'"); if (dr.Read()) { productid = dr[0].ToString(); availableproduct = Convert.ToInt32(dr[1].ToString()); } else { SqlDataReader proid = dbConnection.query("select productID from productdetails where itemname='" + dataGridView1.Rows[e.RowIndex].Cells[1].Value.ToString() + "'"); if (proid.Read()) { productid = proid[0].ToString(); } availableproduct = 0; } if (availableproduct < prodqty) { dataGridView1.Rows[e.RowIndex].Cells[3].Value = availableproduct.ToString(); int requiredproductcount = prodqty - availableproduct; DialogResult res = MessageBox.Show("There is a shortage of " + requiredproductcount.ToString() + " units in the stock\nDo you want to place an order for the same?", "Confirm Order Placement", MessageBoxButtons.YesNo); if (res == DialogResult.Yes) { OrderProducts ord = new OrderProducts(productid, requiredproductcount.ToString(), customername); ord.ShowDialog(); } prodqty = availableproduct; } dataGridView1.Rows[e.RowIndex].Cells[3].Value = prodqty.ToString(); float productrate = (float)Convert.ToDecimal(dataGridView1.Rows[e.RowIndex].Cells[2].Value.ToString()); float prodprice = (float)productrate * ((float)prodqty); if (replacementbill == true && e.RowIndex == 0) { dataGridView1.Rows[0].Cells[4].Value = "0"; } else dataGridView1.Rows[e.RowIndex].Cells[4].Value = prodprice.ToString(); int rowindex = dataGridView1.RowCount - 2; //if (parameterconstructorinvoke) // rowindex = dataGridView1.RowCount - 1; decimal currenttotal = 0; while (rowindex >= 0) { if (dataGridView1.Rows[rowindex].Cells[4].Value.ToString() != "") { currenttotal = currenttotal + Convert.ToDecimal(dataGridView1.Rows[rowindex].Cells[4].Value.ToString()); } rowindex--; } textBoxTotal.Text = currenttotal.ToString(); decimal taxamount = Convert.ToDecimal((float)(((decimal)taxpercent) / 100 * (decimal)currenttotal)); decimal discountamount = Convert.ToDecimal((decimal)(discountpercent / (decimal)100) * (decimal)currenttotal); textBoxTax.Text = taxamount.ToString(); textBoxDiscount.Text = discountamount.ToString(); currenttotal = currenttotal + taxamount - discountamount; textBoxGrandTotal.Text = currenttotal.ToString(); } else MessageBox.Show("Enter valid quantity"); } } catch (Exception exp) { MessageBox.Show("error " + exp.Message); } }
private void placeOrderToolStripMenuItem_Click(object sender, EventArgs e) { OrderProducts ordprods = new OrderProducts(); ordprods.MdiParent= MDImainwnd.ActiveForm; ordprods.Show(); }