private void button2_Click(object sender, EventArgs e) { comboBox1.Enabled = false; RepresentitiveBillDetail newRepresentiveBd = new RepresentitiveBillDetail(); Representitive NameRep = (Representitive)comboBox1.SelectedItem; Representitive rep = context.Representitives.FirstOrDefault(r => r.Name == NameRep.Name); RepresentitiveBill newRepresentitveBill = new RepresentitiveBill() { Representitive_NationalID = rep.NationalID }; context.RepresentitiveBills.Add(newRepresentitveBill); context.SaveChanges(); RepresentitiveBill RepresentitveBillJustAdded = context.RepresentitiveBills.OrderByDescending(r => r.ID).FirstOrDefault(); foreach (var item in supproductlocalList) { newRepresentiveBd.GivenAmount = item.GivenAmount; newRepresentiveBd.Date = item.Date; newRepresentiveBd.ProductObj_ID = item.ProductObj_ID; newRepresentiveBd.GivenAmountPrice = item.GivenAmountPrice; newRepresentiveBd.RepresentitiveBillObj_ID = RepresentitveBillJustAdded.ID; context.RepresentitiveBillDetails.Add(newRepresentiveBd); context.SaveChanges(); Product pro = context.Products.FirstOrDefault(p => p.ID == item.ProductObj_ID); pro.AmountInStock = pro.AmountInStock - item.GivenAmount; context.SaveChanges(); } }
private void rpresentiveCombo_SelectedIndexChanged(object sender, EventArgs e) { x = (Representitive)rpresentiveCombo.SelectedItem; string repName = rpresentiveCombo.SelectedItem.ToString(); var y = context.RepresentitiveBillDetails .Where(p => p.RepresentitiveBill.Representitive_NationalID == x.NationalID); List <Product> ProductList = new List <Product>(); foreach (var item in y) { Product ProdcutOfRep = context.Products.FirstOrDefault(p => p.ID == item.ProductObj_ID); ProductList.Add(ProdcutOfRep); } productComboFromRepresentive.DataSource = ProductList; productComboFromRepresentive.DisplayMember = "Name"; }
private void button8_Click(object sender, EventArgs e) { // string RepresentiveName = null; if (TypeBillCombo.SelectedIndex == -1) { MessageBox.Show("لابد من ادخال نوع الفاتوره اولا"); return; } // if (labelRepresentitve.Text == "") //{ LabelTypeOfBill.Visible = true; LabelTypeOfBill.Text = TypeBillCombo.Text; TypeBillCombo.Visible = false; // } if (rpresentiveCombo.SelectedIndex == -1) { MessageBox.Show("لابد من أدخال أسم المندوب اولا"); return; } // if (.Text == "") // { //RepresentiveName= rpresentiveCombo.Text; labelRepresentitve.Visible = true; labelRepresentitve.Text = rpresentiveCombo.Text; rpresentiveCombo.Visible = false; // } x = (Representitive)rpresentiveCombo.SelectedItem; var prdN = productComboFromRepresentive.Text.ToString(); var prd = context.Products.Where(n => n.Name == prdN).FirstOrDefault(); var y = context.RepresentitiveBillDetails .Where(p => p.RepresentitiveBill.Representitive_NationalID == x.NationalID && p.ProductObj_ID == prd.ID).FirstOrDefault(); if (int.Parse(numericUQouantity.Value.ToString()) > int.Parse(y.GivenAmount.ToString())) { MessageBox.Show("الكميه غير متاحه عند المندوب"); return; } }