/// <summary> /// Modify the bill or delete it from the database /// </summary> /// <param name="shopBill"></param> public ModifyBillUC(ShopBillModel shopBill) { InitializeComponent(); ShopBill = shopBill; SetInitialValues(); }
private void ConfirmButton_Click(object sender, RoutedEventArgs e) { ShopBillModel shopBill = new ShopBillModel(); shopBill.Store = PublicVariables.Store; shopBill.Staff = PublicVariables.Staff; shopBill.TotalMoney = TotalPriceValue.Value.Value; shopBill.Date = DateTime.Now; shopBill.Details = BillDetailsValue.Text; GlobalConfig.ShopBillValidator = new ShopBillValidator(); ValidationResult result = GlobalConfig.ShopBillValidator.Validate(shopBill); if (result.IsValid == false) { MessageBox.Show(result.Errors[0].ErrorMessage); } else { GlobalConfig.Connection.AddShopBillToTheDatabase(shopBill); SetInitialValues(); } }
private void ConfirmButton_Click(object sender, RoutedEventArgs e) { bool valid = true; List <StockModel> newStocks = new List <StockModel>(); IncomeOrderModel incomeOrder = new IncomeOrderModel(); incomeOrder.Supplier = (SupplierModel)SupplierSearchValue.SelectedItem; incomeOrder.BillNumber = BillNumberValue.Text; incomeOrder.Date = (DateTime)DateValue.SelectedDate; incomeOrder.Store = PublicVariables.Store; incomeOrder.Staff = PublicVariables.Staff; incomeOrder.IncomeOrderPayments = new List <IncomeOrderPaymentModel>(); if (StoreWillPayNowValue.Value.Value > 0) { IncomeOrderPaymentModel incomeOrderPayment = new IncomeOrderPaymentModel(); incomeOrderPayment.Staff = PublicVariables.Staff; incomeOrderPayment.Store = PublicVariables.Store; incomeOrderPayment.Paid = StoreWillPayNowValue.Value.Value - (decimal)ShippingExpensesValue.Value.Value; incomeOrderPayment.Date = DateTime.Now; GlobalConfig.IncomeOrderPaymentValidator = new IncomeOrderPaymentValidator(); ValidationResult result = GlobalConfig.IncomeOrderPaymentValidator.Validate(incomeOrderPayment); if (result.IsValid == false) { MessageBox.Show(result.Errors[0].ErrorMessage); valid = false; } else { incomeOrder.IncomeOrderPayments.Add(incomeOrderPayment); } } incomeOrder.Details = IncomeOrderDetailsValue.Text; incomeOrder.IncomeOrderProducts = new List <IncomeOrderProductModel>(); foreach (IncomeOrderProductRecordModel incomeOrderProductRecord in IncomeOrderProductRecords) { GlobalConfig.IncomeOrderProductValidator = new IncomeOrderProductValidator(); ValidationResult result = GlobalConfig.IncomeOrderProductValidator.Validate(incomeOrderProductRecord.IncomeOrderProduct); if (result.IsValid == false) { MessageBox.Show(result.Errors[0].ErrorMessage); valid = false; } else { incomeOrder.IncomeOrderProducts.Add(incomeOrderProductRecord.IncomeOrderProduct); newStocks.Add(incomeOrderProductRecord.Stock); } } GlobalConfig.IncomeOrderValidator = new IncomeOrderValidator(); ValidationResult IncomeOrderResult = GlobalConfig.IncomeOrderValidator.Validate(incomeOrder); if (IncomeOrderResult.IsValid == false) { MessageBox.Show(IncomeOrderResult.Errors[0].ErrorMessage); valid = false; } else { if (valid == true) { incomeOrder = GlobalConfig.Connection.AddIncomeOrderToTheDatabase(incomeOrder, newStocks); if (ShippingExpensesValue.Value.Value > 0) { ShopBillModel shopBill = new ShopBillModel(); shopBill.Date = DateTime.Now; shopBill.Staff = PublicVariables.Staff; shopBill.Store = PublicVariables.Store; shopBill.TotalMoney = ShippingExpensesValue.Value.Value; shopBill.Details = "Shipping expense of the income Order ID : " + incomeOrder.Id + " ."; GlobalConfig.Connection.AddShopBillToTheDatabase(shopBill); } ClearProduct(); SetInitialValues(); } } }