private void Button_Click_2(object sender, RoutedEventArgs e)
 {
     try {
         ListViewSell Row = ListView.SelectedItem as ListViewSell;
         if (Row == null)
         {
             MessageBox.Show("Please Select row To Remove");
             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);
         }
         Total.Text = TotalValues.ToString();
         ListView.Items.Remove(ListView.SelectedItem);
         var Current      = context.SalesInvoices.Where(recip => recip.ID == Row.ID).First();
         var CurrentItems = context.ItemInSalesInvoices.Where(recip => recip.SalesInvoice_Id == Row.ID).FirstOrDefault();
         if (CurrentItems == null)
         {
             return;
         }
         context.ItemInSalesInvoices.Remove(CurrentItems);
         context.SaveChanges();
         CategoryCombo.IsEnabled = true;
         ItemCombo.IsEnabled     = true;
         CustomerCombo.IsEnabled = true;
         Quantity.Text           = "";
     }
     catch
     {
         MessageBox.Show("Enter Valid Data");
     }
 }
        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 ListView_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (ListView.Items.Count == 0)
            {
                Edit.IsEnabled   = false;
                Delete.IsEnabled = false;
                return;
            }
            else
            {
                Edit.IsEnabled   = true;
                Delete.IsEnabled = true;
            }
            CategoryCombo.IsEnabled = false;
            ItemCombo.IsEnabled     = false;
            SalesManCombo.IsEnabled = false;
            CustomerCombo.IsEnabled = false;
            ListViewSell Row = ListView.SelectedItem as ListViewSell;

            if (Row == null)
            {
                return;
            }
            CategoryCombo.Text = Row.Category;
            ItemCombo.Text     = Row.Item_Name;
            Quantity.Text      = Row.Quantity.ToString();
            bool KindInvoice = KeyByValue(invoicedata.KindOfInvoice, Row.KindOfInvoice.ToString());
            bool KindPay     = KeyByValue(invoicedata.KindOfPay, Row.KindOfPay.ToString());

            CustomerCombo.Text = Row.Customer;
            if (KindPay == true)
            {
                KindOfPay.Text = invoicedata.KindOfPay[true];
            }
            else
            {
                KindOfPay.Text = invoicedata.KindOfPay[false];
            }

            if (KindInvoice == true)
            {
                KindOfinvoice.Text = invoicedata.KindOfInvoice[true];
            }
            else
            {
                KindOfinvoice.Text = invoicedata.KindOfInvoice[false];
            }

            NoOfInvoice.Text = (context.SalesInvoices.Where(sales => sales.ID == Row.ID).Select(re => re.ID).FirstOrDefault()).ToString();
        }
示例#4
0
        public ListViewSell ReturnsValues()
        {
            ListViewSell list = new ListViewSell();

            list.Category  = CategoryCombo.Text;
            list.Item_Name = ItemCombo.Text;
            list.Quantity  = int.Parse(Quantity.Text);
            int ID = int.Parse(ItemCombo.SelectedValue.ToString());

            list.PriceForPiece = context.Items.Where(item => item.ID == ID).Select(item => item.BuyPrice).FirstOrDefault();
            list.TotalPrice    = list.Quantity * list.PriceForPiece;
            list.KindOfInvoice = KindOfinvoice.Text.ToString();
            list.KindOfPay     = KindOfPay.Text.ToString();
            list.Customer      = CustomerCombo.Text;
            return(list);
        }
        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");
            }
        }