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;
        }
 public FactureView(string animationName)
 {
     InitializeComponent();
     _factureclient = new FacturesClient();
     if (string.IsNullOrEmpty(animationName)) return;
     Storyboard animation = (Storyboard) Application.Current.Resources[animationName];
     LayoutRoot.BeginStoryboard(animation);
 }
        private void InvoiceReport_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e)
        {
            //****************
            examenTable1.DataTable1.FillTable(InvoiceTable);
            //****************

            if (TheFactureCase == null) return;
            FacturesClient invoices = new FacturesClient();
            Details = invoices.GetFactureDetails(TheFactureCase);

            //Test
            //txtItem.DataBindings.Add("Text", Details, "ProductName");
            //txtItem.Summary = new XRSummary(SummaryRunning.Report, SummaryFunc.RecordNumber, "{0}");
            //txtProductName.DataBindings.Add("Text", Details, "ProductName");
            //txtQuantity.DataBindings.Add("Text", Details, "Quantity");
            //txtUnitPrice.DataBindings.Add("Text", Details, "UnitPrice");
            //txtUnitPrice.DataBindings[0].FormatString = "{0:n2}";
            // Amount.Expression = "[Quantity]*[UnitPrice]";
            //txtAmount.DataBindings.Add("Text", Details, "Amount");
            //txtAmount.DataBindings[0].FormatString = "{0:n2}";

            //txtUnit.DataBindings.Add("Text", Details, "Unite");

            //txtPTva.DataBindings.Add("Text", Details, "PTVA");
            //txtTotalNoTax.DataBindings.Add("Text", Details, "TotalHT");
            //txtTimbre.DataBindings.Add("Text", Details, "Timbre");
            //txtTotal.DataBindings.Add("Text", Details, "Total");
            //txtDate.DataBindings.Add("Text", Details, "InvoiceDate");
            //txtDate.DataBindings[0].FormatString = "{0:dd-MMM-yyyy}";
            //txtPayMode.DataBindings.Add("Text", Details, "PayMode");

            //txtTotalNoTax.DataBindings[0].FormatString = "{0:n2}";
            //txtPTva.DataBindings[0].FormatString = "{0:n2}";
            //txtTotal.DataBindings[0].FormatString = "{0:n2}";
        }
        private void TableView_FocusedRowChanged(object sender, FocusedRowChangedEventArgs e)
        {
            var facturesClient = new FacturesClient();
            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;
            if (ordre.OrderDate != null) DtFactureDate.DateTime = (DateTime)ordre.OrderDate;
            CbCustomerAddress.Text = ordre.Customer.Address;
            CbSecurityNum.Text = ordre.Customer.RC;       // a revoir
            NumTxtBox.Text = facturesClient.GetFactureNumber().ToString();
            CbRs.Text = ordre.Customer.CompanyName;
            Calculate(ordre);
            Afficher();
        }
        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 */
        }
        private void TableView_FocusedRowChanged(object sender, FocusedRowChangedEventArgs e)
        {
            FacturesClient fc = new FacturesClient();
            if (DgFactures.VisibleRowCount == 0) return;
            int rowHandle = DgFactures.View.FocusedRowHandle;
            if (rowHandle >= 0)
            {

                OrderClient oc = new OrderClient();
                Order ordre = oc.GetOrderById(Convert.ToInt32(DgFactures.GetCellValue(rowHandle, "OrderID")));
                FacturesClient factureClient = new FacturesClient();
                Facture facture = factureClient.GetFactureByOrdre(ordre);
                if (ordre.Status == 10) {PrintBtn.IsEnabled = false;  PrintProBtn.IsEnabled = true;}
                if (ordre.Status == 0) {PrintProBtn.IsEnabled = false; PrintBtn.IsEnabled = true;}

                //////////////////////

                if (ordre.OrderDate != null) DtFactureDate.DateTime = (DateTime)ordre.OrderDate;
                CbCustomerAddress.Text = ordre.Customer.Address;
                CbSecurityNum.Text = ordre.Customer.RC;       // a revoir
                CbRs.Text = ordre.Customer.CompanyName;
                NumTxtBox.Text = facture.FactureNum.ToString();
                Calculate(ordre);
                Afficher();
            }
        }
        private void PrintProBtn_Click(object sender, RoutedEventArgs e)
        {
            if (DgFactures.VisibleRowCount == 0) return;
            int rowHandle = DgFactures.View.FocusedRowHandle;
            if (rowHandle >= 0)
            {
                OrderClient oc = new OrderClient();
                Order ordre = oc.GetOrderById(Convert.ToInt32(DgFactures.GetCellValue(rowHandle, "OrderID")));

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

                var factureClient = new FacturesClient();
                var facture = factureClient.GetFactureByOrdre(ordre);

                var settingsClient = new SettingsClient();
                var settings = settingsClient.GetSetting();

                var factureCase = new FactureCase
                {
                    Order = ordre,
                    TotalHt = _total,
                    Ttc = _ttc,
                    Tva = _tva,
                    Timbre = _timbre,
                    Numbre = facture.FactureNum.ToString(),
                    Facture = facture
                };

                //var report = new InvoiceReport(factureCase);

                //if (settings.Logo != null) report.Logo = Validator.ConvertByteArrayToImage(settings.Logo);

                //report.PayMode = facture.TypePayment;
                //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 */

                LoadGridFact();

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