Пример #1
0
        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            int Item_Id    = int.Parse(ItemCombo.SelectedValue.ToString());
            var SelectItem = context.Items.Where(item => item.ID == Item_Id).FirstOrDefault();

            int                  No              = int.Parse(NoOfInvoice.Text);
            ReceiptInvoice       CurrentEdit     = context.ReceiptInvoices.Where(recip => recip.ID == No).FirstOrDefault();
            ItemInReceiptInvoice CurrentEditQuan = context.ItemInReceiptInvoices.Where(recip => recip.ReceiptInvoice_Id == CurrentEdit.ID && recip.Item_Id == Item_Id).FirstOrDefault();

            if (CurrentEdit == null)
            {
                return;
            }
            SelectItem.Quantity     += CurrentEditQuan.Quantity;
            CurrentEditQuan.Quantity = int.Parse(Quantity.Text);
            SelectItem.Quantity     -= CurrentEditQuan.Quantity;
            ListViewRecipt Row = ListView.SelectedItem as ListViewRecipt;

            if (Row == null)
            {
                return;
            }
            SubtractTotal(Row.Quantity, Row.PriceForPiece);
            Row.Quantity = int.Parse(Quantity.Text);
            ListView.Items.Remove(ListView.SelectedItem);
            Total.Text              = calculateTotal(Row.Quantity, Row.PriceForPiece).ToString();
            Row.TotalPrice          = Row.Quantity * Row.PriceForPiece;
            CategoryCombo.IsEnabled = true;
            ItemCombo.IsEnabled     = true;

            ListView.Items.Add(Row);
            context.SaveChanges();
        }
Пример #2
0
        public ItemInReceiptInvoice CreateInvoice(int SelectItem, int recipt, int QuantityValue)
        {
            ItemInReceiptInvoice itemsRecipted = new ItemInReceiptInvoice();

            itemsRecipted.Item_Id           = SelectItem;
            itemsRecipted.ReceiptInvoice_Id = recipt;
            itemsRecipted.Quantity          = QuantityValue;

            context.ItemInReceiptInvoices.Add(itemsRecipted);
            context.SaveChanges();
            return(itemsRecipted);
        }
Пример #3
0
 public void AddReciptToItem(Item SelectItem, ItemInReceiptInvoice recipt)
 {
     SelectItem.ItemInReceiptInvoices.Add(recipt);
 }
Пример #4
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            try
            { int result = 0;

              if (CategoryCombo.SelectedIndex != -1 && ItemCombo.SelectedIndex != -1 && int.TryParse(Quantity.Text, out result) && SalesManCombo.SelectedIndex != -1 && Quantity.Text != "")
              {
                  int Item_Id           = int.Parse(ItemCombo.SelectedValue.ToString());
                  var SelectItem        = context.Items.Where(item => item.ID == Item_Id).FirstOrDefault();
                  int AvailableQuantity = SelectItem.Quantity;
                  if (int.Parse(Quantity.Text) > AvailableQuantity)
                  {
                      MessageBox.Show("There aren't This Quantity In Store"); return;
                  }
                  if (result < 0)
                  {
                      MessageBox.Show("This Quantity is not Valid Should Be Positive Num Only");
                      return;
                  }
                  else
                  {
                      int QuantityValue = int.Parse(Quantity.Text);
                      int Sales_id      = int.Parse(SalesManCombo.SelectedValue.ToString());
                      if (CreateObject == false)
                      {
                          recipt = new ReceiptInvoice()
                          {
                              Date     = DateTime.Now,
                              salesman = context.salesmans.Where(sales => sales.ID == Sales_id).FirstOrDefault(),
                              ItemInReceiptInvoices = new List <ItemInReceiptInvoice>()
                          };
                          context.ReceiptInvoices.Add(recipt);
                          CreateObject = true;
                      }
                      ItemInReceiptInvoice itemsRecipted = new ItemInReceiptInvoice();

                      itemsRecipted.Item           = SelectItem;
                      itemsRecipted.ReceiptInvoice = recipt;
                      itemsRecipted.Quantity       = QuantityValue;

                      recipt.ItemInReceiptInvoices.Add(itemsRecipted);
                      SelectItem.ItemInReceiptInvoices.Add(itemsRecipted);
                      SelectItem.Quantity -= int.Parse(Quantity.Text);
                      TotalValues         += (int.Parse(Quantity.Text) * SelectItem.SellPrice);
                      var saller = context.salesmans.Where(sallr => sallr.ID == Sales_id).First();

                      saller.ReceiptInvoices.Add(recipt);

                      context.SaveChanges();
                      Total.Text       = TotalValues.ToString();
                      NoOfInvoice.Text = (context.ReceiptInvoices.Where(recip => recip.ID == recipt.ID).Select(re => re.ID).First()).ToString();
                      salesMan.Text    = SalesManCombo.Text;
                      this.ListView.Items.Add(new ListViewRecipt {
                            ID = int.Parse(NoOfInvoice.Text), Category = CategoryCombo.Text, Item_Name = ItemCombo.Text, Quantity = int.Parse(Quantity.Text), PriceForPiece = SelectItem.SellPrice, TotalPrice = double.Parse(Quantity.Text) * SelectItem.SellPrice
                        });
                      Edit.IsEnabled          = true;
                      Delete.IsEnabled        = true;
                      SalesManCombo.IsEnabled = false;
                      Quantity.Text           = "";
                  }
              }
              else
              {
                  MessageBox.Show("Enter Correct Data");
              } }
            catch
            {
                MessageBox.Show("Enter Valid Data");
            }
        }
Пример #5
0
 public void AddItemInReciptToReceipt(ReceiptInvoice recipt, ItemInReceiptInvoice itemReceipt)
 {
     recipt.ItemInReceiptInvoices.Add(itemReceipt);
 }