Beispiel #1
0
        public void AddSellClient(int id, Sell sell)
        {
            var client = from c in context.Client
                         where c.Id == id
                         select c;

            Client clientNew = client.FirstOrDefault();
            clientNew.Sells.Add(sell);
            clientNew.TotalOWe += sell.TotalPrice - sell.Paid;
            context.Entry(clientNew).State = EntityState.Modified;
            context.SaveChanges();
        }
        private void SaveSellButton_Click(object sender, RoutedEventArgs e)
        {
            if (ControlValidation.IsEmpty(new TextBox[] {DateSell,IdProductSell,PriceSell,QuantitySell,TotalPriceSell}))
            {
                Sell sell = new Sell();
                Client client = ClientComboBox.Items[ClientComboBox.SelectedIndex] as Client;
                int idClientSelected = client.Id;
                string nameClient = client.Name;
                sell.DateSell = DateTime.Parse(DateSell.Text.ToString());
                sell.IdTrouser = int.Parse(IdProductSell.Text);
                sell.UnitPrice = double.Parse(PriceSell.Text);
                sell.Quantity = int.Parse(QuantitySell.Text);
                sell.TotalPrice = double.Parse(TotalPriceSell.Text);

                sell.Client = nameClient;
                if (PostponePayCheckBox.IsChecked == true)
                {
                    if(ControlValidation.IsEmpty(new TextBox[] {PaidClient}))
                    {
                        DateTime datePaid;
                        if(DateTime.TryParse(PayDay.Text,out datePaid))
                        {
                            sell.Paid = double.Parse(PaidClient.Text);
                            sell.DatePaid = datePaid;
                            sell.TotalOwe = double.Parse(TotalPriceSell.Text) - double.Parse(PaidClient.Text);
                            sell.Owe = true;
                            dataSource.AddNewSell(sell);
                            dataSource.AddSellClient(idClientSelected, sell);
                            SellsListView.ItemsSource = dataSource.GetSells();
                            ClientListView.ItemsSource = dataSource.GetClients();
                        }
                    }
                }
                else
                {
                    sell.Paid = double.Parse(TotalPriceSell.Text);
                    sell.DatePaid = DateTime.Parse(DateSell.Text);
                    sell.Owe = false;
                    dataSource.AddNewSell(sell);
                    dataSource.AddSellClient(idClientSelected, sell);
                    SellsListView.ItemsSource = dataSource.GetSells();
                    ClientListView.ItemsSource = dataSource.GetClients();
                }
            }
        }
Beispiel #3
0
 public void AddNewSell(Sell sell)
 {
     context.Sell.Add(sell);
     context.SaveChanges();
 }