private void AddFactureBtn_Click(object sender, RoutedEventArgs e)
        {
            //facture adding
            //Verify that the invoice doesn't exist

            CustomerOrder order = (CustomerOrder)DgFactures.GetFocusedRow();
            // Get selected TVA

            TVA tva = (TVA)CbTva.EditValue;

            var facturesClient = new FacturesClient();
            Facture factures = new Facture
            {
                FactureDate = DtFactureDate.DateTime,
                TypePayment = CbPayment.Text,
                TVA = tva,
                Order = order.Order,
                FactureNum = facturesClient.RetrieveFactureNumber(NumTxtBox.Text)
            };

            //  f.Total = factures.GetSaleTotal(order,tva);
            facturesClient.AddFacture(factures);
            DXMessageBox.Show("Facture ajoutée avec success.");

            PrintBtn.IsEnabled = true;
        }
        private void PrintBtn_Click(object sender, RoutedEventArgs e)
        {
            if (DgFactures.VisibleRowCount == 0) return;
            int rowHandle = DgFactures.View.FocusedRowHandle;
            if (rowHandle < 0) return;
            var orderClient = new OrderClient();
            var ordre = orderClient.GetOrderById(Convert.ToInt32(DgFactures.GetCellValue(rowHandle, "OrderID")));

            if (ordre == null) return;

            /* la fcture dans la base de données */

            var factureClient = new FacturesClient();
            var facture = new Facture
            {
                FactureDate = DateTime.Now,
                Order = ordre,
                FactureNum = Convert.ToInt32(NumTxtBox.Text),
                TVA = _tvaClient.GetTvaByName(_tva.ToString()),
                TypePayment = CbPayment.Text,
                Status = 0,
                Type = TypeFacture
            };
            //ou facture proforma
            factureClient.AddFacture(facture);

            /* fin de l'ajout de la facture a la base de données */

            /* debut de l'impression de la facture */
            var settingsClient = new SettingsClient();
            Setting settings = settingsClient.GetSetting();

            FactureCase factureCase = new FactureCase
            {
                Order = ordre,
                TotalHt = _total,
                Ttc = _ttc,
                Tva = _tva,
                Timbre = _timbre,
                Numbre = NumTxtBox.Text,
                Facture = facture
            };

            //var report = new InvoiceReport(factureCase);

            //if (settings.Logo!= null)  report.Logo = Validator.ConvertByteArrayToImage(settings.Logo);
            ////report.HeaderContent = "ITCastle Company   Boumerdes";
            //report.PayMode = CbPayment.Text;
            //report.SetSettings();
            //PrintHelper.ShowPrintPreview(null, report).WindowState = WindowState.Maximized;

            /* fin de l'impression de la facture */

            /* debut de modifiction de l'après impression de la facture */

            settings.FactureNumber = (Convert.ToInt32(settings.FactureNumber) + 1).ToString();
            SettingsClient.MajSettings(settings);
            LoadGridFact();

            /* fin de modifiction de l'après impression de la facture */
        }