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();
                }
            }
        }
        private void SaveTheIncomeOrder()
        {
            if (RemovedIncomeOrderProducts.Count == 0)
            {
                if (StoreWillPayNowValue.Value > 0)
                {
                    IncomeOrderPaymentModel incomeOrderPayment = new IncomeOrderPaymentModel();
                    incomeOrderPayment.Staff = PublicVariables.Staff;
                    incomeOrderPayment.Store = PublicVariables.Store;
                    incomeOrderPayment.Paid  = StoreWillPayNowValue.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);
                    }
                    else
                    {
                        GlobalConfig.Connection.AddIncomeOrderPaymentToTheDatabase(IncomeOrder, incomeOrderPayment);
                    }
                }
                else if (StoreShouldReceiveValue.Value > 0)
                {
                    GlobalConfig.Connection.SupplierPayment(IncomeOrder, SupplierWillPayNowValue.Value.Value);
                }

                SetInitialValues();
            }
            else
            {
                /*  if (CustomerWillPayNowValue.Value > 0)
                 * {
                 *    OrderPaymentModel orderPayment = new OrderPaymentModel();
                 *    orderPayment.Staff = PublicVariables.Staff;
                 *    orderPayment.Store = PublicVariables.Store;
                 *    orderPayment.Paid = CustomerWillPayNowValue.Value.Value;
                 *    orderPayment.Date = DateTime.Now;
                 *
                 *    GlobalConfig.OrderPaymentValidator = new OrderPaymentValidator();
                 *
                 *    ValidationResult result = GlobalConfig.OrderPaymentValidator.Validate(orderPayment);
                 *
                 *    if (result.IsValid == false)
                 *    {
                 *
                 *        MessageBox.Show(result.Errors[0].ErrorMessage);
                 *
                 *    }
                 *    else
                 *    {
                 *
                 *        GlobalConfig.Connection.AddOrderPaymentToTheDatabase(Order, orderPayment);
                 *
                 *        if (MessageBox.Show("Do you want to print the order ?", "Printing...", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
                 *        {
                 *            PrintTheOrder();
                 *        }
                 *
                 *    }
                 * }
                 * else if (StoreWillPayNowValue.Value > 0)
                 * {
                 *
                 *    GlobalConfig.Connection.StorePayment(Order, StoreWillPayNowValue.Value.Value);
                 * }
                 *
                 * GlobalConfig.Connection.UpdateOrder(Order, RemovedOrderProducts);
                 *
                 *
                 *
                 * SetInitialValues();*/
            }
        }