public StatisticsView(string animationName)
 {
     InitializeComponent();
     _purchaseClient = new PurchaseClient();
     _orderClient = new OrderClient();
     _productClient = new ProductManger();
     _suppliersManager = new SuppliersManager();
     _customersManager = new CustomersManager();
     if (string.IsNullOrEmpty(animationName)) return;
     Storyboard animation = (Storyboard)Application.Current.Resources[animationName];
     LayoutRoot.BeginStoryboard(animation);
 }
 private int calculeOrdre()
 {
     var oc = new OrderClient();
     return 20 - oc.GetCountOrder();
 }
        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)
        {
            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 LoadGridFact()
        {
            Dispatcher.BeginInvoke(new Action(() =>
            {

                var oc = new OrderClient();
                var listeOrdersNonFactured = oc.GetOrderNotFactured();
                if (listeOrdersNonFactured != null)
                    DgFactures.ItemsSource = (from t in listeOrdersNonFactured

                        select new
                        {
                            OrderID = t.OrderID,
                            OrderDate = t.OrderDate,
                            RequiredDate = t.CommandeDate,
                            CompanyName = t.Customer.CompanyName,
                            Description = t.Description,
                        }
                        ).ToList();
            }));
        }
 private static int CalculeOrdre()
 {
     OrderClient oc = new OrderClient();
     return 20 - oc.GetCountOrder();
 }
        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 */
            }
        }
        private void InvoiceBtn_Click(object sender, RoutedEventArgs e)
        {
            String message = Enregistrer();
               if (!message.Equals("Votre commande a été enregistrer avec succes")) return;
                OrderClient oc = new OrderClient();
                Order ordre = oc.GetOrderById(theOrder.OrderID);

                if (ordre == null) return;

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

                var settingsClient = new SettingsClient();
             //   Setting settings = settingsClient.GetSetting();
                Order getOrder = GetTheOrder(ordre);
            var facture = new Facture
            {
                FactureDate = DateTime.Now,
                Order = getOrder,
               // FactureNum = Convert.ToInt32(settings.FactureNumber),
                TVA = _tvaClient.GetTvaByName(_tvaValue.ToString(CultureInfo.InvariantCulture)),
                TypePayment = "Espèce",
                Status = 0,
                Type = "Facture"
            };
            gestionDb.Factures.Add(facture);
            gestionDb.SaveChanges();
            //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 */

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

            //InvoiceReport report = new InvoiceReport(factureCase)
            //{
            //    PayMode = facture.TypePayment
            //};

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

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

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