示例#1
0
 private void buttonPrint_Click(object sender, EventArgs e)
 {
     if (printingWorker.IsBusy)
     {
         return;
     }
     ErrorLog.LogMessage("lunching printing version 2.5.3");
     printingWorker.RunWorkerAsync();
 }
示例#2
0
        private void printingWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            try
            {
                ErrorLog.LogMessage("Begin Printing Work...");

                var reportViewer = new ReportViewer {
                    ProcessingMode = ProcessingMode.Remote
                };
                var uri = new Uri(Settings.Default.reportServerURL);
                reportViewer.ServerReport.ReportServerUrl = uri;


                ErrorLog.LogMessage($"Server registred {Settings.Default.reportServerURL}");

                // Get a reference to the default credentials
                ICredentials credentials = CredentialCache.DefaultCredentials;

                // Get a reference to the report server credentials
                var rsCredentials = reportViewer.ServerReport.ReportServerCredentials;

                // Set the credentials for the server report
                rsCredentials.NetworkCredentials = credentials;


                //I'm really sorry for doing this but i had to :'( :'( :'(
                //may god forgive me
                rsCredentials.NetworkCredentials = new NetworkCredential("erpadmin", "Heavy.all2016@", "GHP");
                reportViewer.ZoomMode            = ZoomMode.PageWidth;


                var from = (int)numericFrom.Value;
                var to   = (int)numericTo.Value;

                var documents = new PrintDocument[1000];
                var i         = 0;
                ErrorLog.LogMessage($"Begin Rendering");
                for (var avoir = from; avoir <= to; avoir++)
                {
                    switch (_viewModel.GetTypeAvoir(avoir))
                    {
                    case 0:
                        reportViewer.ServerReport.ReportPath = "/ExpFinance/AvoirFinancier";
                        break;

                    case 1:
                        reportViewer.ServerReport.ReportPath = "/ExpFinance/AvoirFinancier_libre";
                        break;

                    case 2:
                        reportViewer.ServerReport.ReportPath = "/ExpFinance/AvoirFinancier_ant";
                        break;

                    case 3:
                        reportViewer.ServerReport.ReportPath = "/ExpFinance/AvoirFinancier_EF";
                        break;
                    }

                    ErrorLog.LogMessage($"Printing From {reportViewer.ServerReport.ReportPath}");
                    _numAvoir   = avoir;
                    _codeClient = _viewModel.GetCodeClient(avoir);
                    _montant    = _viewModel.GetAvoirFinancier(avoir).montant.ToString("N2");


                    if (string.IsNullOrEmpty(_codeClient))
                    {
                        continue;
                    }
                    var parameters = new[]
                    {
                        new ReportParameter("client", _codeClient),
                        new ReportParameter("numAvoir", _numAvoir.ToString()),

                        // new ReportParameter("montant", _montant)
                    };

                    //_reportViewer.ShowCredentialPrompts = true;
                    reportViewer.ServerReport.SetParameters(parameters);
                    reportViewer.RefreshReport();

                    var printabledocument = new ReportPrintDocument(reportViewer.ServerReport)
                    {
                        PrinterSettings =
                        {
                            FromPage    = 1,
                            ToPage      = 1,
                            MinimumPage = 1,
                            MaximumPage = 1
                        }
                    };

                    documents[i] = printabledocument;
                    var progress = (decimal)(avoir - from + 1) / (decimal)(to - from + 1) * 100;
                    printingWorker.ReportProgress((int)progress);
                    i++;
                }

                ErrorLog.LogMessage("All pages done");
                var printingDocuments = new MultiPrintDocument(documents)
                {
                    PrinterSettings = { Copies = (short)numericCopies.Value }
                };


                //set printing settings
                if (string.IsNullOrEmpty(_printerName))
                {
                    var printerDialog = new PrintDialog();
                    var result        = printerDialog.ShowDialog();

                    if (result == DialogResult.OK)
                    {
                        _printerName = printerDialog.PrinterSettings.PrinterName;
                        printingDocuments.PrinterSettings.PrinterName = _printerName;
                    }
                }
                else
                {
                    printingDocuments.PrinterSettings.PrinterName = _printerName;
                }

                ErrorLog.LogMessage("Begin Printing");

                printingDocuments.Print();
            }
            catch (Exception ex)
            {
                Messages.Error("Une erreur s'est produite !");
                ErrorLog.LogError($"Impression de {Settings.Default.reportServerURL}", ex);
            }
        }
示例#3
0
        private bool InsertAnte()
        {
            try
            {
                using (var model = new ExpFinanceEntities())
                {
                    var detail = new DetailsDossier();

                    var tempdata = (from temp in model.AF_TEMP_DATA_ANT
                                    where temp.entite == _entite
                                    select temp);


                    foreach (var temp in tempdata)
                    {
                        //EXERCICE ANTERIEUR
                        ErrorLog.LogMessage($"treating avoir{temp.numAvoir}");
                        var year     = temp.Exercice;
                        var factures = temp.factures.Split('-').ToList();


                        //Get the liste of facture
                        var liste = detail.GetListeFacturesClientAllYears(factures, year.Value.Year);

                        if (liste.Count == 0 || liste.All(f => f == null))
                        {
                            ErrorLog.LogMessage($"No factures in avoir{temp.numAvoir}");
                        }
                        //Creating Groupe Details
                        //var entite = liste.Where(f=>f!=null).Select(f => f.entite).First();
                        //var codeClient = liste.Where(f => f != null).Select(f => f.code_clien).First();
                        decimal?mntHt = 0, mntRz = 0, mntTtc = 0, mntTva = 0, marge = 0;

                        if (liste.Count != 0 || liste.All(f => f != null))
                        {
                            //calculating totales in factures
                            liste.ForEach(f =>
                            {
                                mntHt  += f?.total_HT; //this is HTR !!
                                mntRz  += f?.T_remise;
                                mntTtc += f?.total_TTC;
                                mntTva += f?.total_TVA;
                                marge  += f?.Marge;
                            });
                        }

                        var newGroupeCvn = new AF_TEMP_GROUPE_FACTURE
                        {
                            ID_GROUPE_FACT = temp.idgroupe ?? 0,
                            DATE_CADEAU    = year,
                            DATE_DOSSIER   = DateTime.Today,
                            ENTITE         = _entite,
                            CODE_CLIENT    = temp.codeClient,
                            //MNT_HT = temp.CA, //this info is given by entite (we switch to avoid to insert les avoirs clients)
                            MNT_HT         = mntHt,
                            MNT_RZ         = mntRz,
                            MNT_TVA        = mntTva,
                            MNT_TTC        = mntTtc,
                            MONTANT_CHEQUE = mntHt,//this by the db
                            MARGE          = marge,
                            ETAT           = 20,
                        };

                        model.AF_TEMP_GROUPE_FACTURE.Add(newGroupeCvn);


                        if (liste.Count != 0 || liste.All(f => f != null))
                        {
                            liste.ForEach(facture =>
                            {
                                if (facture != null)
                                {
                                    var newFacture = new AF_TEMP_FACTURE
                                    {
                                        NUM_FACT       = facture.num_trans,
                                        CODE_CLIENT    = facture.code_clien,
                                        DATE_FACT      = facture.date_trans ?? default(DateTime),
                                        ENTITE         = facture.entite,
                                        MARGE          = facture.Marge,
                                        MNT_HT_RZ      = facture.total_HT - facture.T_remise,
                                        MNT_TTC        = facture.total_TTC,
                                        MNT_RZ         = facture.T_remise,
                                        MNT_TVA        = facture.total_TVA,
                                        ID_GROUPE_FACT = temp.idgroupe ?? 0,
                                    };

                                    model.AF_TEMP_FACTURE.Add(newFacture);
                                }
                            });
                        }

                        //model.SaveChanges();
                        //_numGroupe = newGroupeCvn.ID_GROUPE_FACT;



                        //Insert AVOIR


                        _numAvoir = temp.numAvoir;


                        var avoir = new AF_TEMP_AVOIR_FINANCIER
                        {
                            numAvoir          = _numAvoir,
                            montant           = temp.Montant ?? 0,
                            dateAvoir         = temp.dateAvoir ?? DateTime.Now,
                            designation       = "REMISE FINANCIERE",
                            montantCheque     = temp.cheque ?? 0,
                            montantCreance    = temp.creance ?? 0,
                            Observation       = "",
                            typeAvoir         = byte.Parse(temp.typeAvoir),
                            numAvoirComptable = 20,
                        };


                        var libre = (byte)2;

                        //insert the related group
                        var avoirGroupe = new AF_TEMP_AVOIR_GROUPE
                        {
                            numAvoir = avoir.numAvoir,
                            IDG      = temp.idgroupe ?? 0,
                            Libre    = libre
                        };

                        model.AF_TEMP_AVOIR_GROUPE.Add(avoirGroupe);


                        //Insert in the etat table
                        var etat = new AF_TEMP_ETAT_AVOIR
                        {
                            numDossier = temp.refAvoir,
                            numAvoir   = avoir.numAvoir,
                            IDG        = temp.idgroupe ?? 0,
                            Etat       = 3,
                            dateHeure  = DateTime.Today
                        };

                        model.AF_TEMP_ETAT_AVOIR.Add(etat);

                        model.AF_TEMP_AVOIR_FINANCIER.Add(avoir);

                        //model.SaveChanges();
                    }
                    model.SaveChanges();

                    return(true);
                }
            }
            catch (Exception e)
            {
                Messages.Error(@"Erreur insertion factures: " + e.Message);
                ErrorLog.LogError(@"Erreur insertion factures: ", e);
                return(false);
            }
        }
示例#4
0
 private void printingWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
 {
     ErrorLog.LogMessage("Work done.");
 }
示例#5
0
        private bool InsertAvoir2016()
        {
            try
            {
                using (var model = new ExpFinanceEntities())
                {
                    var detail = new DetailsDossier();

                    var tempdata = (from temp in model.AF_TEMP_DATA
                                    where temp.entite == _entite
                                    select temp);

                    foreach (var temp in tempdata)
                    {
                        //EXERCICE 2016
                        var factures = temp.factures.Split('-').ToList();
                        ErrorLog.LogMessage($"treating avoir{temp.numAvoir}");


                        //Get the liste of facture
                        var liste = detail.GetListeFacturesClientAll(factures);
                        if (liste.Count == 0 || liste.All(f => f == null))
                        {
                            ErrorLog.LogMessage($"No factures in avoir{temp.numAvoir}");
                        }
                        //Creating Groupe Details
                        //var entite = liste.Where(f => f != null).Select(f => f.entite).First();
                        //var codeClient = liste.Where(f => f != null).Select(f => f.code_clien).First();
                        decimal?mntHt = 0, mntRz = 0, mntTtc = 0, mntTva = 0, marge = 0;

                        //calculating totales in factures
                        if (liste.Count != 0 || liste.All(f => f != null))
                        {
                            //calculating totales in factures
                            liste.ForEach(f =>
                            {
                                mntHt  += f?.total_HT; //this is HTR !!
                                mntRz  += f?.T_remise;
                                mntTtc += f?.total_TTC;
                                mntTva += f?.total_TVA;
                                marge  += f?.Marge;
                            });
                        }


                        var newGroupeCvn = new AF_TEMP_GROUPE_FACTURE
                        {
                            ID_GROUPE_FACT = temp.idgroupe ?? 0,
                            DATE_DOSSIER   = DateTime.Today,
                            ENTITE         = _entite,
                            CODE_CLIENT    = temp.codeClient,
                            MNT_HT         = mntHt,
                            MNT_RZ         = mntRz,
                            MNT_TVA        = mntTva,
                            MNT_TTC        = mntTtc,
                            MARGE          = marge,
                            ETAT           = 10,
                        };

                        model.AF_TEMP_GROUPE_FACTURE.Add(newGroupeCvn);

                        if (liste.Count != 0 || liste.All(f => f != null))
                        {
                            liste.ForEach(facture =>
                            {
                                if (facture != null)
                                {
                                    var newFacture = new AF_TEMP_FACTURE
                                    {
                                        NUM_FACT       = facture.num_trans,
                                        CODE_CLIENT    = facture.code_clien,
                                        DATE_FACT      = facture.date_trans ?? default(DateTime),
                                        ENTITE         = facture.entite,
                                        MARGE          = facture.Marge,
                                        MNT_HT_RZ      = facture.total_HT - facture.T_remise,
                                        MNT_TTC        = facture.total_TTC,
                                        MNT_RZ         = facture.T_remise,
                                        MNT_TVA        = facture.total_TVA,
                                        ID_GROUPE_FACT = temp.idgroupe ?? 0,
                                    };

                                    model.AF_TEMP_FACTURE.Add(newFacture);
                                }
                            });
                        }

                        //Insert AVOIR


                        _numAvoir = temp.numAvoir;


                        var avoir = new AF_TEMP_AVOIR_FINANCIER
                        {
                            numAvoir          = _numAvoir,
                            montant           = temp.Montant ?? 0,
                            dateAvoir         = temp.dateAvoir,
                            designation       = "REMISE FINANCIERE",
                            montantCheque     = temp.cheque ?? 0,
                            montantCreance    = temp.creance ?? 0,
                            Observation       = "",
                            typeAvoir         = byte.Parse(temp.typeAvoir),
                            numAvoirComptable = 10,
                        };


                        var libre = (byte)1;

                        //insert the related group
                        var avoirGroupe = new AF_TEMP_AVOIR_GROUPE
                        {
                            numAvoir = avoir.numAvoir,
                            IDG      = temp.idgroupe ?? 0,
                            Libre    = libre
                        };

                        model.AF_TEMP_AVOIR_GROUPE.Add(avoirGroupe);


                        //Insert in the etat table
                        var etat = new AF_TEMP_ETAT_AVOIR
                        {
                            numDossier = temp.refAvoir,
                            numAvoir   = avoir.numAvoir,
                            IDG        = temp.idgroupe ?? 0,
                            Etat       = 3,
                            dateHeure  = DateTime.Today
                        };

                        model.AF_TEMP_ETAT_AVOIR.Add(etat);

                        model.AF_TEMP_AVOIR_FINANCIER.Add(avoir);
                    }

                    model.SaveChanges();
                    return(true);
                }
            }
            catch (Exception e)
            {
                Messages.Error(@"Erreur insertion factures: " + e.Message);
                ErrorLog.LogError(@"Erreur insertion factures: ", e);
                return(false);
            }

            //catch (DbEntityValidationException e)
            //{
            //    foreach (var eve in e.EntityValidationErrors)
            //    {
            //        ErrorLog.LogError($"Entity of type \"{ eve.Entry.Entity.GetType().Name}\" in state \"{eve.Entry.State}\" has the following validation errors:");
            //        foreach (var ve in eve.ValidationErrors)
            //        {
            //            ErrorLog.LogError($"- Property: \"{ ve.PropertyName}\", Error: \"{ve.ErrorMessage}\"");
            //        }
            //    }
            //    throw;
            //}
        }