示例#1
0
        public RepAnalyseFichiers AnalyseFichiers(ParamAnalyseFichiers param)
        {
            repAnalyseFichiers = new RepAnalyseFichiers()
            {
                listIdFichiers = new List <IdFichiers>()
            };
            string sPathDirectory = System.AppDomain.CurrentDomain.BaseDirectory;

            sPathDirectory += "\\Files\\UpLoad\\Relevé digital détail mensuel";
            var listFiles = Directory.GetFiles(sPathDirectory).ToList();
            int idxinc    = 0;

            foreach (var v in listFiles)
            {
                IdFichiers idFichiers = new IdFichiers()
                {
                    Id = idxinc++, sPAth = v, sFileName = Path.GetFileName(v), extension = Path.GetExtension(v)
                };
                if (idFichiers.extension == ".xlsx")
                {
                    Stopwatch sw  = Stopwatch.StartNew();
                    var       res = SingleExcel.Instance().GetPeriodFile(v);
                    idFichiers.sPeriode = res.sPeriode;
                    idFichiers.sMessage = res.Message;
                    idFichiers.delayMs  = sw.ElapsedMilliseconds;
                }
                else
                {
                    idFichiers.Error    = 1;
                    idFichiers.sMessage = "Bad Extension must be xlsx ";
                }
                repAnalyseFichiers.listIdFichiers.Add(idFichiers);
            }
            return(repAnalyseFichiers);
        }
 public static SingleExcel Instance()
 {
     if (instance == null)
     {
         instance = new SingleExcel();
     }
     return(instance);
 }
        public RepTest AnalyseFichier(ParamTest param)
        {
            RepTest rep = new RepTest()
            {
                listInfosArtiste = new List <InfosArtiste>()
            };
            string sPathDirectory = System.AppDomain.CurrentDomain.BaseDirectory;

            sPathDirectory += "\\Files\\UpLoad\\Relevé digital détail mensuel\\";
            string sPathFile = sPathDirectory + param.NomFichier;
            var    repExcel  = SingleExcel.Instance().AnalyseFichier(sPathFile, param.NomFichier);

            CurrentlistLinePayLoad = repExcel.listLinePayLoad;
            rep.sMessage           = repExcel.Message;
            string sPeriode = repExcel.sPeriode;

            if (CurrentlistLinePayLoad != null)
            {
                var listArtiste = CurrentlistLinePayLoad.Select(c => c.Artist).Distinct().ToList();
                foreach (var art in listArtiste)
                {
                    InfosArtiste infosArtiste = new InfosArtiste()
                    {
                        NomArtiste = art, UrlImage = ""
                    };

                    infosArtiste.UrlImage = GetUrlImageArtiste(art, ref infosArtiste.NomRecherche);

                    if (param.WithDetails)
                    {
                        var listInfos = CurrentlistLinePayLoad.Where(c => c.Artist == art).ToList();

                        infosArtiste.DownLoadQuantity = listInfos.Sum(c => c.DownloadQty);
                        infosArtiste.GrossRevenue     = listInfos.Sum(c => c.GrossRevenue);
                        infosArtiste.NetRevenue       = listInfos.Sum(c => c.NetRevenue);
                        infosArtiste.TotalFee         = listInfos.Sum(c => c.TotalFee);
                        infosArtiste.TotalPayable     = listInfos.Sum(c => c.TotalPayable);

                        rep.TotalDownload          += infosArtiste.DownLoadQuantity;
                        rep.TotalTotalGrossRevenue += infosArtiste.GrossRevenue;
                        rep.TotalTotalNetRevenue   += infosArtiste.NetRevenue;
                        rep.TotalTotalFee          += infosArtiste.TotalFee;
                        rep.TotalTotalPayable      += infosArtiste.TotalPayable;
                    }

                    rep.listInfosArtiste.Add(infosArtiste);
                }

                int CptUpdate = 0;
                if (globalLinePayLoad != null && globalLinePayLoad.listLine != null)
                {
                    var prelist = globalLinePayLoad.listLine.Where(c => c.sFile == param.NomFichier && c.sPeriode == sPeriode).ToList();
                    foreach (var line in CurrentlistLinePayLoad)
                    {
                        var exist = prelist.Where(c => c.Line == line.Line && c.TotalPayable == line.TotalPayable).FirstOrDefault();
                        if (exist == null)
                        {
                            globalLinePayLoad.listLine.Add(line);
                            CptUpdate++;
                        }
                    }
                    if (CptUpdate > 0)
                    {
                        SaveRepository();
                    }
                }
            }
            return(rep);
        }