private void button4_Click(object sender, EventArgs e) { frmScanQR scan = new frmScanQR(); scan.ShowDialog(); var q = db.Client_Purchase_Order.Where(po => po.PO_Number == scan.DecodeID).First(); q.Purchase_Order_Status_ID = 2; var q2 = db.Load_Purcase_Order_Line().Where(x => x.Purhcase_Order_Number == q.PO_Number).First(); var q3 = db.Getpoduct().Where(x => x.Product_Description == q2.Product).First(); //int w = Convert.ToInt32(q.Available_Quantity); //q3.Available_Quantity +; db.Products.Where(x => x.Product_ID == q3.Product_ID).First().Available_Quantity -= q2.Quantity; db.SaveChanges(); frmPOLine f = new frmPOLine(scan.DecodeID); var q1 = db.Purchase_Order_Status.Where(pos => pos.Purchase_Order_Status_ID == q.Purchase_Order_Status_ID).First(); dgvPackaged.DataSource = db.Load_Purchase_Order_1(). Where(lpo => lpo.Purchase_Order_Status_Description == q1.Purchase_Order_Status_Description).ToList(); dataGridView1.DataSource = db.Load_Purchase_Order_1().Where(lpo => lpo.Purchase_Order_Status_Description == "Placed").ToList(); }
private void button2_Click(object sender, EventArgs e) { try { if (newPO != null) { int prid = Convert.ToInt32(comboBox1.SelectedValue); var q = db.Products.Where(p => p.Product_ID == prid).FirstOrDefault(); var q1 = db.Client_Purchase_Order_Line.Where(cpol => cpol.Product_ID == prid && cpol.Client_Purchase_Id == newPO.Client_Purchase_Id).FirstOrDefault(); if (pol == null) { pol = new Client_Purchase_Order_Line() { Client_Purchase_Id = newPO.Client_Purchase_Id, Product_ID = Convert.ToInt32(comboBox1.SelectedValue), Quantity = Convert.ToInt32(txtQuantity.Text), }; db.Client_Purchase_Order_Line.Add(pol); db.SaveChanges(); var q3 = db.Client_Purchase_Order.Where(x => x.Client_Purchase_Id == newPO.Client_Purchase_Id).First(); dataGridView1.DataSource = db.Load_Purcase_Order_Line().Where(x => x.Purhcase_Order_Number == q3.PO_Number).ToList(); var q2 = db.Company_Information.Select(ci => ci.VAT_Percentage).First(); txtCreditBalance.Text = (Convert.ToDecimal(txtCreditBalance.Text) + pa).ToString(); txtGrossTotalVI.Text = Convert.ToDecimal(db.Load_Purcase_Order_Line().Where(x => x.Purhcase_Order_Number == q3.PO_Number).Sum(pol => pol.Subtotal)).ToString(); txtGrossTotalVE.Text = Decimal.Round(Convert.ToDecimal(db.Load_Purcase_Order_Line().Where(x => x.Purhcase_Order_Number == q3.PO_Number). Sum(pol => pol.Subtotal)) * (1 - (q2 / 100)), 2).ToString(); txtVAT.Text = Decimal.Round(Convert.ToDecimal(db.Load_Purcase_Order_Line().Where(x => x.Purhcase_Order_Number == q3.PO_Number).Sum(pol => pol.Subtotal)) * (q2 / 100), 2).ToString(); ca = Convert.ToDecimal(txtGrossTotalVI.Text); txtCreditBalance.Text = (Convert.ToDecimal(txtCreditBalance.Text) - ca).ToString(); pa = ca; } else { var q3 = db.Client_Purchase_Order.Where(x => x.Client_Purchase_Id == newPO.Client_Purchase_Id).First(); if (q1 == null) { pol = new Client_Purchase_Order_Line() { Client_Purchase_Id = newPO.Client_Purchase_Id, Product_ID = Convert.ToInt32(comboBox1.SelectedValue), Quantity = Convert.ToInt32(txtQuantity.Text), }; db.Client_Purchase_Order_Line.Add(pol); db.SaveChanges(); dataGridView1.DataSource = db.Load_Purcase_Order_Line().Where(x => x.Purhcase_Order_Number == q3.PO_Number).ToList(); var q2 = db.Company_Information.Select(ci => ci.VAT_Percentage).FirstOrDefault(); txtCreditBalance.Text = (Convert.ToDecimal(txtCreditBalance.Text) + pa).ToString(); txtGrossTotalVI.Text = Convert.ToDecimal(db.Load_Purcase_Order_Line().Where(x => x.Purhcase_Order_Number == q3.PO_Number).Sum(pol => pol.Subtotal)).ToString(); txtGrossTotalVE.Text = Decimal.Round(Convert.ToDecimal(db.Load_Purcase_Order_Line().Where(x => x.Purhcase_Order_Number == q3.PO_Number). Sum(pol => pol.Subtotal)) * (1 - (q2 / 100)), 2).ToString(); txtVAT.Text = Decimal.Round(Convert.ToDecimal(db.Load_Purcase_Order_Line().Where(x => x.Purhcase_Order_Number == q3.PO_Number).Sum(pol => pol.Subtotal)) * (q2 / 100), 2).ToString(); ca = Convert.ToDecimal(txtGrossTotalVI.Text); txtCreditBalance.Text = (Convert.ToDecimal(txtCreditBalance.Text) - ca).ToString(); pa = ca; } else { var q4 = db.Client_Purchase_Order_Line.Where(cpol => cpol.Client_Purchase_Id == newPO.Client_Purchase_Id && cpol.Client_Purchase_Order_Line_ID == q1.Client_Purchase_Order_Line_ID). FirstOrDefault(); q4.Quantity += Convert.ToInt32(txtQuantity.Text); db.SaveChanges(); dataGridView1.DataSource = db.Load_Purcase_Order_Line().Where(x => x.Purhcase_Order_Number == q3.PO_Number).ToList(); var q2 = db.Company_Information.Select(ci => ci.VAT_Percentage).FirstOrDefault(); txtCreditBalance.Text = (Convert.ToDecimal(txtCreditBalance.Text) + pa).ToString(); txtGrossTotalVI.Text = Decimal.Round(Convert.ToDecimal(db.Load_Purcase_Order_Line().Where(x => x.Purhcase_Order_Number == q3.PO_Number).Sum(pol => pol.Subtotal)), 2).ToString(); txtGrossTotalVE.Text = Decimal.Round(Convert.ToDecimal(db.Load_Purcase_Order_Line().Where(x => x.Purhcase_Order_Number == q3.PO_Number). Sum(pol => pol.Subtotal)) * (1 - (q2 / 100)), 2).ToString(); txtVAT.Text = Decimal.Round(Convert.ToDecimal(db.Load_Purcase_Order_Line().Where(x => x.Purhcase_Order_Number == q3.PO_Number).Sum(pol => pol.Subtotal)) * (q2 / 100), 2).ToString(); ca = Convert.ToDecimal(txtGrossTotalVI.Text); txtCreditBalance.Text = (Convert.ToDecimal(txtCreditBalance.Text) - ca).ToString(); pa = ca; } } } else if (xPO != null) { int prid = Convert.ToInt32(comboBox1.SelectedValue); pol = new Client_Purchase_Order_Line() { Client_Purchase_Id = newPO.Client_Purchase_Id, Product_ID = Convert.ToInt32(comboBox1.SelectedValue), Quantity = Convert.ToInt32(txtQuantity.Text), }; db.Client_Purchase_Order_Line.Add(pol); } else { MessageBox.Show("Please select a client"); } } catch (Exception ex) { MessageBox.Show("Something went wrong!,Please try again " + ex.ToString()); } groupBox3.Enabled = true; }
public frmPOLine(string ponum) { InitializeComponent(); dataGridView1.DataSource = db.Load_Purcase_Order_Line().Where(x => x.Purhcase_Order_Number == ponum).ToList(); }