private void Button_Click_1(object sender, RoutedEventArgs e) { try { int No = int.Parse(NoOfInvoice.Text); SalesInvoice CurrentEdit = context.SalesInvoices.Where(sales => sales.ID == No).FirstOrDefault(); ItemInSalesInvoice CurrentEditQuan = context.ItemInSalesInvoices.Where(recip => recip.SalesInvoice_Id == CurrentEdit.ID).FirstOrDefault(); if (CurrentEdit == null) { return; } if (int.Parse(Quantity.Text) <= 0) { MessageBox.Show("Enter Positive number"); return; } CurrentEditQuan.Quantity = int.Parse(Quantity.Text); CurrentEdit.KindOfInvoice = (KindOfinvoice.Text.ToString() == invoicedata.KindOfInvoice[true]) ? true : false; CurrentEdit.TypeOfPay = (KindOfPay.Text.ToString() == invoicedata.KindOfPay[true]) ? true : false; ListViewSell Row = ListView.SelectedItem as ListViewSell; if (Row == null) { MessageBox.Show("Please Select row To Edit"); return; } bool KindInvoice = KeyByValue(invoicedata.KindOfInvoice, Row.KindOfInvoice.ToString()); bool KindPay = KeyByValue(invoicedata.KindOfPay, Row.KindOfPay.ToString()); if ((KindInvoice == true && KindPay == true)) { SubtractTotal(Row.Quantity, Row.PriceForPiece); } Row.Quantity = int.Parse(Quantity.Text); Row.Customer = CustomerCombo.Text; Row.TotalPrice = Row.PriceForPiece * Row.Quantity; Row.KindOfInvoice = invoicedata.KindOfInvoice[CurrentEdit.KindOfInvoice]; Row.KindOfPay = invoicedata.KindOfPay[CurrentEdit.TypeOfPay]; ListView.Items.Remove(ListView.SelectedItem); if (KindInvoice == true && KindPay == true) { calculateTotal(Row.Quantity, Row.PriceForPiece); } Total.Text = TotalValues.ToString(); ListView.Items.Add(Row); context.SaveChanges(); CategoryCombo.IsEnabled = true; ItemCombo.IsEnabled = true; CustomerCombo.IsEnabled = true; Quantity.Text = ""; } catch { MessageBox.Show("Enter Valid Data"); } }
private void Button_Click(object sender, RoutedEventArgs e) { try { int result; if (!int.TryParse(Quantity.Text, out result)) { MessageBox.Show("This Quantity is not Valid"); } else if (CategoryCombo.SelectedIndex != -1 && ItemCombo.SelectedIndex != -1 && CustomerCombo.SelectedIndex != -1 && KindOfPay.SelectedIndex != -1 && KindOfinvoice.SelectedIndex != -1 && SalesManCombo.SelectedIndex != -1 && result > 0) { int Cus_Id = int.Parse(CustomerCombo.SelectedValue.ToString()); int Saller_Id = int.Parse(SalesManCombo.SelectedValue.ToString()); var custommer = context.Customers.Where(custome => custome.ID == Cus_Id).FirstOrDefault(); var Seller = context.salesmans.Where(saler => saler.ID == Saller_Id).FirstOrDefault(); int Item_Id = int.Parse(ItemCombo.SelectedValue.ToString()); var Item = context.Items.Where(it => it.ID == Item_Id).FirstOrDefault(); ListViewSell list = ReturnsValues(); if (CreateObject == false) { SellInv = new SalesInvoice() { TotalPrice = list.TotalPrice, Date = DateTime.Now, KindOfInvoice = KeyByValue(invoicedata.KindOfInvoice, list.KindOfInvoice.ToString()), TypeOfPay = KeyByValue(invoicedata.KindOfPay, list.KindOfPay.ToString()), Customer = custommer, salesman = Seller, ItemInSalesInvoices = new List <ItemInSalesInvoice>() }; CreateObject = true; } ItemInSalesInvoice salesitem = new ItemInSalesInvoice() { Item = Item, SalesInvoice = SellInv, Quantity = list.Quantity, }; SellInv.ItemInSalesInvoices.Add(salesitem); Item.ItemInSalesInvoices.Add(salesitem); custommer.SalesInvoices.Add(SellInv); Seller.SalesInvoices.Add(SellInv); context.SaveChanges(); NoOfInvoice.Text = (context.SalesInvoices.Where(sal => sal.ID == SellInv.ID).Select(re => re.ID).First()).ToString(); bool KindInvoice = KeyByValue(invoicedata.KindOfInvoice, list.KindOfInvoice.ToString()); bool KindPay = KeyByValue(invoicedata.KindOfPay, list.KindOfPay.ToString()); salesMan.Text = SalesManCombo.Text; if (KindInvoice == true && KindPay == true) { TotalValues += list.TotalPrice; } Total.Text = TotalValues.ToString(); list.ID = context.SalesInvoices.Where(inv => inv.ID == SellInv.ID).Select(se => se.ID).FirstOrDefault(); ListView.Items.Add(list); Edit.IsEnabled = true; Delete.IsEnabled = true; SalesManCombo.IsEnabled = false; CustomerCombo.IsEnabled = false; KindOfinvoice.IsEnabled = false; KindOfPay.IsEnabled = false; Quantity.Text = ""; } else { MessageBox.Show("add All Data And Number Should Be Positive"); } } catch { MessageBox.Show("Enter Valid Data"); } }