/// <summary>
        /// Exports report in .xlsx file
        /// </summary>
        /// <param name="reportSearch">reportSearch contains which report to export and it filters values</param>
        /// <remark>This method export Announcement analysis report,Finance report,Cancel avail report,Date change report</remark>>
        /// <returns>FileResult which help to download report in browser</returns>
        public ActionResult Reports1(ReportSearch reportSearch)
        {
            string       path         = string.Empty;
            string       downloadFile = string.Empty;
            DownLoadFile downLoadFile = null;

            IExportReportService exportService = new ExportReportService();

            if (reportSearch.ReportTitleID.Equals(1))
            {
                int recordCount = exportService.GetAnnouncementAnalysisReportRecordCount(reportSearch);
                if (recordCount > App.Config.MaxAnnouncementAnalysisDownloadRecordLimit)
                {
                    TempData["ErrorMsg"] = string.Format("There are {0} records that you are trying to download. Record count should not exceed {1} records.", recordCount, App.Config.MaxAnnouncementAnalysisDownloadRecordLimit);
                    return(RedirectToAction("Reports", "Report", new { @reportSearch = reportSearch }));
                }
                downLoadFile = exportService.GenerateAnnouncementAnalysisReport(reportSearch);
            }

            else if (reportSearch.ReportTitleID.Equals(2))
            {
                downLoadFile = exportService.GenerateCancelAvailsReport(reportSearch);
            }
            else if (reportSearch.ReportTitleID.Equals(3))
            {
                downLoadFile = exportService.GenerateFinanceReport(reportSearch);
            }
            else if (reportSearch.ReportTitleID.Equals(4))
            {
                downLoadFile = exportService.GenerateAnnouncementChangeReport(reportSearch);
            }

            return(File(downLoadFile.bufferByte, "application/vnd.ms-excel", downLoadFile.FileName));
        }
Example #2
0
        public FileResult Reports1(ReportSearch reportSearch)
        {
            string       path         = string.Empty;
            string       downloadFile = string.Empty;
            DownLoadFile downLoadFile = null;

            ExportReportService exportService = new ExportReportService();

            if (reportSearch.ReportTitleID.Equals(1))
            {
                downLoadFile = exportService.GenerateAnnouncementAnalysisReport(reportSearch);
            }

            else if (reportSearch.ReportTitleID.Equals(2))
            {
                downLoadFile = exportService.GenerateCancelAvailsReport(reportSearch);
            }
            else if (reportSearch.ReportTitleID.Equals(3))
            {
                downLoadFile = exportService.GenerateFinanceReport(reportSearch);
            }
            else if (reportSearch.ReportTitleID.Equals(4))
            {
                downLoadFile = exportService.GenerateAnnouncementChangeReport(reportSearch);
            }

            //file = TempData["fileName"].ToString();
            //path = ConfigurationManager.AppSettings["directoryPath"];
            //path = App.Config.ReportDirectoryPath;
            //string fullPath = string.Format(path, file);
            return(File(downLoadFile.bufferByte, "application/vnd.ms-excel", downLoadFile.FileName));
            //TempData["fileName"] = file;
            //return RedirectToAction("Reports");
        }
        /// <summary>
        /// Export Announcement Analysis Report in .xlsx for selected filter criteria
        /// </summary>
        /// <param name="reportSearch">Filters values</param>
        /// <returns>File name and Bytestream</returns>
        public DownLoadFile GenerateAnnouncementAnalysisReport(ReportSearch reportSearch)
        {
            //string annoucementSourceFile = ConfigurationManager.AppSettings["annoucementSourceFile"];
            string annoucementSourceFile = App.Config.AnnouncementReportExportFilePath;
            //string annoucementCopyFile = ConfigurationManager.AppSettings["annoucementCopyFile"];
            string annoucementCopyFile = App.Config.AnnouncementReportExportCopyFilePath;
            string downloadedFileName  = "Annoucement Analysis Report" + DateTime.Now.ToString("yyyy_MM_dd_hh_mm_ss") + ".xlsx";
            //string path = ConfigurationManager.AppSettings["directoryPath"];
            string path         = App.Config.ReportDirectoryPath;
            string downloadFile = string.Format(path, downloadedFileName);

            File.Copy(annoucementSourceFile, annoucementCopyFile, true);
            //_repository.ExportAnnouncementAnalysisReport(reportSearch);
            string whereClause = this.getAnnouncementAnalysisReportWhereClause(reportSearch);

            _repository.ExportAnnouncementAnalysisReport(whereClause);

            File.Copy(annoucementSourceFile, downloadFile, true);
            if (File.Exists(annoucementSourceFile))
            {
                File.Delete(annoucementSourceFile);
            }
            File.Copy(annoucementCopyFile, annoucementSourceFile, true);
            if (File.Exists(annoucementCopyFile))
            {
                File.Delete(annoucementCopyFile);
            }
            DownLoadFile download = DownloadFile(downloadFile, downloadedFileName);

            return(download);
        }
Example #4
0
        public FileResult ExportOrder(OrderSearch orderSearch)
        {
            ExportReportService _export      = new ExportReportService();
            DownLoadFile        downloadFile = _export.GenerateOrderReport(orderSearch);
            //string path = ConfigurationManager.AppSettings["directoryPath"];
            string path = App.Config.ReportDirectoryPath;

            //string downloadFile = string.Format(path, file);
            ////Stream fs = File.OpenRead(@"c:\testdocument.docx");
            //FileStream stream = new FileStream(downloadFile, FileMode.Open, FileAccess.Read);

            //byte[] buffer = new byte[2048];
            //byte[] bufferByte;
            //using (MemoryStream ms = new MemoryStream())
            //{
            //    int read;
            //    while ((read = stream.Read(buffer, 0, buffer.Length)) > 0)
            //    {
            //        ms.Write(buffer, 0, read);
            //    }
            //    bufferByte = ms.ToArray();
            //};
            //stream.Close();
            //_export.DeleteFile(downloadFile);
            return(File(downloadFile.bufferByte, "application/vnd.ms-excel", downloadFile.FileName));
        }
        /// <summary>
        /// Export Cancel Avails Report in .xlsx for selected filter criteria
        /// </summary>
        /// <param name="reportSearch">Filters values</param>
        /// <returns>File name and Byte stream</returns>
        public DownLoadFile GenerateCancelAvailsReport(ReportSearch reportSearch)
        {
            //string cancelAvailsSourceFile = ConfigurationManager.AppSettings["cancelAvailsSourceFile"];
            string cancelAvailsSourceFile = App.Config.CancelReportExportFilePath;
            //string cancelAvailsCopyFile = ConfigurationManager.AppSettings["cancelAvailsCopyFile"];
            string cancelAvailsCopyFile = App.Config.CancelReportExportCopyFilePath;
            string downloadedFileName   = "Cancel Avails Report" + DateTime.Now.ToString("yyyy_MM_dd_hh_mm_ss") + ".xlsx";
            //string path = ConfigurationManager.AppSettings["directoryPath"];
            string path         = App.Config.ReportDirectoryPath;
            string downloadFile = string.Format(path, downloadedFileName);

            File.Copy(cancelAvailsSourceFile, cancelAvailsCopyFile, true);
            _repository.ExportCancelAvailsReport(reportSearch);

            File.Copy(cancelAvailsSourceFile, downloadFile, true);
            if (File.Exists(cancelAvailsSourceFile))
            {
                File.Delete(cancelAvailsSourceFile);
            }
            File.Copy(cancelAvailsCopyFile, cancelAvailsSourceFile, true);
            if (File.Exists(cancelAvailsCopyFile))
            {
                File.Delete(cancelAvailsCopyFile);
            }
            DownLoadFile download = DownloadFile(downloadFile, downloadedFileName);

            return(download);
        }
Example #6
0
        public FileResult ExportTitle(TitleSearch titleSearch)
        {
            ExportReportService _export      = new ExportReportService();
            DownLoadFile        downloadFile = _export.GenerateTitleReport(titleSearch);

            //string path = ConfigurationManager.AppSettings["directoryPath"];
            //string path = App.Config.ReportDirectoryPath;
            //string downloadFile = string.Format(path, file);
            return(File(downloadFile.bufferByte, "application/vnd.ms-excel", downloadFile.FileName));
        }
        /// <summary>
        /// Export VID to .xlsx file
        /// </summary>
        /// <param name="vidSearch">VidSearch contains the filter value to export VID. If vidSearch is null then all VID data get exported</param>
        /// <returns>FileResult which help to download file in browser</returns>
        public ActionResult Export(VIDSearch vidSearch)
        {
            var vid             = new VIDMgt();
            var vidSearchValues = _service.GetSearchValue();

            vid.VIDSearch = vidSearchValues;
            DownLoadFile downloadFile = _export.ExportVidReport(vidSearch);
            var          vidModel     = _service.GetDropDownValue();

            vid.VID       = vidModel;
            vid.VIDSearch = vidSearch;
            //return View("Vid", vid);
            string path = App.Config.ReportDirectoryPath;

            return(File(downloadFile.bufferByte, "application/vnd.ms-excel", downloadFile.FileName));
        }
        public ActionResult DownLoad(string tableName)
        {
            DataTable dt;

            if (tableName == "待付清单")
            {
                dt = this.GetCache <DataTable>(CurrentSession.UserName + "V1");
            }
            else
            {
                dt = this.GetCache <DataTable>(CurrentSession.UserName);
            }

            var name = DownLoadFile.ExportExcel(dt, tableName);

            return(Content(name));
        }
Example #9
0
        public ActionResult ExportTitle(TitleSearch titleSearch)
        {
            //Titles(TitleSearch titleSearch, int? pageNumber)
            IExportReportService _export = new ExportReportService();
            int recordCount = _export.GetTitleReportRecordCount(titleSearch);

            if (recordCount > App.Config.MaxTitleReportDownloadRecordLimit)
            {
                titleSearch.Territory = string.IsNullOrEmpty(titleSearch.TerritoryConcat) ? titleSearch.Territory : titleSearch.TerritoryConcat.Split('|');
                titleSearch.Language  = string.IsNullOrEmpty(titleSearch.LanguageConcate) ? titleSearch.Language : titleSearch.LanguageConcate.Split('|');
                titleSearch.Region    = string.IsNullOrEmpty(titleSearch.RegionConcat) ? titleSearch.Region : titleSearch.RegionConcat.Split('|');
                TempData["ErrorMsg"]  = string.Format("There are {0} records that you are trying to download. Record count should not exceed {1} records.", recordCount, App.Config.MaxTitleReportDownloadRecordLimit);
                return(RedirectToAction("Titles", "Title", new { @titleSearch = titleSearch }));
                //return RedirectToAction("Index");
            }

            DownLoadFile downloadFile = _export.GenerateTitleReport(titleSearch);

            return(File(downloadFile.bufferByte, "application/vnd.ms-excel", downloadFile.FileName));
        }
        /// <summary>
        /// Covert .xlsx file to byte stream
        /// </summary>
        /// <param name="file">file path</param>
        /// <param name="downloadedFileName">ile name</param>
        /// <returns>File name and Byte stream</returns>
        public DownLoadFile DownloadFile(string file, string downloadedFileName)
        {
            FileStream stream = new FileStream(file, FileMode.Open, FileAccess.Read);

            byte[] buffer = new byte[2048];
            byte[] bufferByte;
            using (MemoryStream ms = new MemoryStream())
            {
                int read;
                while ((read = stream.Read(buffer, 0, buffer.Length)) > 0)
                {
                    ms.Write(buffer, 0, read);
                }
                bufferByte = ms.ToArray();
            };
            stream.Close();
            File.Delete(file);
            DownLoadFile downloadFile = new DownLoadFile()
            {
                bufferByte = bufferByte, FileName = downloadedFileName
            };

            return(downloadFile);
        }
        public void  GetPrintTaskInfo()
        {
            string       orderid        = "";
            string       copies         = "";
            string       fileid         = "";
            string       filetype       = "";
            string       filename       = "";
            string       printer        = "";
            string       page           = "";
            string       peisong        = "";
            string       time           = "";
            bool         isdouble       = false;
            bool         iscolor        = false;
            int          flag           = 0;
            String       post_send_data = "userID=" + c_userID + "&" + "licenseCode=" + c_licenseCode;
            HttpRsepData RespData       = Post2ReceiveData(this.url_GetTask, post_send_data);

            if (Jsontext != "" && Jsontext != null)
            {
                GetPrintTask  obj       = new GetPrintTask();
                List <Object> orderlist = obj.getTaskFromCloud(Jsontext);//获得云中任务
                List <report> r         = new List <report>();
                if (orderlist.Count != 0)
                {
                    for (int i = 0; i < orderlist.Count; i++)
                    {
                        Orders order = (Orders)orderlist[i];


                        if (order.IsDuplex == "1")
                        {
                            isdouble = false;
                        }
                        if (order.IsDuplex == "2")
                        {
                            isdouble = true;
                        }
                        if (order.Iscolor == "黑白")
                        {
                            iscolor = false;
                        }
                        else
                        {
                            iscolor = true;
                        }
                        copies   = order.Printcopies;
                        fileid   = order.FileID;
                        filetype = order.Filetype;
                        page     = order.Prtpage;
                        filename = order.Filename;
                        peisong  = order.Peisong;
                        printer  = order.Printer;

                        string   printers = PCLConvertCS.PCLToPrinter.GetAllPrinter();
                        string[] all      = printers.Split(';');
                        string   x        = "";
                        string   murl     = url;
                        murl += "/machine/privateDownloadFileHandler.ashx";
                        DownLoadFile obj2 = new DownLoadFile(@murl);
                        obj2.getFileFromCloud(orderlist);
                        string FilePath = System.IO.Directory.GetCurrentDirectory() + @"\下载文档\";
                        FilePath += fileid + "." + filetype;
                        string fileOut                = System.IO.Directory.GetCurrentDirectory() + @"\PCL\" + fileid + ".prn";//移动到哪里
                        PCLConvertCS.PCLConvert pc    = new PCLConvertCS.PCLConvert();
                        PCLConvertCS.PDFConvert pcpdf = new PCLConvertCS.PDFConvert();
                        string fileOutFJ              = System.IO.Directory.GetCurrentDirectory() + @"\PCL\" + fileid + "FJ" + ".prn";

                        if (FilePath.ToLower().EndsWith("doc") || FilePath.ToLower().EndsWith("docx"))
                        {
                            string result = pc.WordToPCL(readArgs(FilePath, copies, iscolor, isdouble, page), fileOut, printer);
                            if (result == null)
                            {
                                flag = 1;
                            }
                        }
                        if (FilePath.ToLower().EndsWith("pdf"))
                        {
                            string result = pcpdf.ConvertPdf2pcl(readArgs(FilePath, copies, iscolor, isdouble, page), fileOut);
                            if (result == null)
                            {
                                flag = 1;
                            }
                        }
                        if (FilePath.ToLower().EndsWith("jpg") || FilePath.ToLower().EndsWith("jpeg") || FilePath.ToLower().EndsWith("JPEG"))
                        {
                            string result = pc.JPGToPCL(FilePath, fileOut);
                            if (result == null)
                            {
                                flag = 1;
                            }
                        }
                        if (FilePath.ToLower().EndsWith("xlsx") || FilePath.ToLower().EndsWith("xlsm"))
                        {
                            string sPath = System.IO.Directory.GetCurrentDirectory() + @"\下载文档\" + "\\" + orderid + "\\" + fileid;
                            if (XLSConvertToPDF(FilePath, sPath))
                            {
                                FilePath = sPath + ".pdf";
                                string result = pcpdf.ConvertPdf2pcl(readArgs(FilePath, copies, iscolor, isdouble, page), fileOut);
                                if (result == null)
                                {
                                    flag = 1;
                                }
                            }
                        }
                        if (flag == 1)
                        {
                            string fileOut1 = System.IO.Directory.GetCurrentDirectory() + @"\PCL\" + fileid + ".prn";
                            PCLConvertCS.PCLToPrinter pcl = new PCLConvertCS.PCLToPrinter();
                            // 设置事件触发间隔
                            pcl.SetEventTimeout(2000);
                            // 添加打印监控事件处理handler
                            pcl.OnPCLResult += new PCLConvertCS.PCLToPrinter.PCLResult(pcl_OnPCLResult);
                            string result1 = pcl.SendFileToPrinter(printer, fileOut1);
                            string userid  = order.OrderID;
                            countpage(FilePath);
                            int xpage = 0;
                            if (page == "全部")
                            {
                                xpage = mnum;
                            }
                            else
                            {
                                xpage = m_lastPage - m_firstPage + 1;
                            }
                            int    totalPage = Convert.ToInt32(copies) * xpage;
                            report a         = new report();
                            a.Orderid = order.OrderID;
                            a.Pagenum = totalPage;
                            DirectoryInfo dirInfo = new DirectoryInfo(System.IO.Directory.GetCurrentDirectory() + @"\PCL\");
                            FileInfo[]    files   = dirInfo.GetFiles(); // 获取该目录下的所有文件
                            foreach (FileInfo file in files)
                            {
                                file.Delete();
                            }

                            r.Add(a);
                        }
                    }

                    ReportData R = new ReportData();
                    R.ReportCloud(CreateJsonParameters(r), @url);
                }
            }
        }
Example #12
0
 /// <summary>
 /// 初始化下载
 /// </summary>
 private void InitDownLoadFile()
 {
     downLoadFile            = new DownLoadFile();
     downLoadFile.doSendMsg += SendMsgHander;
 }
        /// <summary>
        /// Export VID Report in .xlsx for selected filter criteria
        /// </summary>
        /// <param name="reportSearch">Filters values</param>
        /// <returns>File name and Byte stream</returns>
        public DownLoadFile ExportVidReport(VIDSearch vidSearch)
        {
            string whrSQLquery = string.Empty;

            if (vidSearch.TitleName != null && vidSearch.TitleName.Any())
            {
                var    titleNames  = vidSearch.TitleName.Select(x => x.Replace("'", "\''")).ToList();
                string concattitle = titleNames.Aggregate((current, next) => current + "', '" + next);
                concattitle = string.Format("{0}{1}{0}", "'", concattitle);

                whrSQLquery += string.IsNullOrEmpty(whrSQLquery) ? string.Empty : " AND ";
                whrSQLquery += " TitleName IN (" + concattitle + ")";
                //whrSQLquery = string.IsNullOrEmpty(whrSQLquery) ? " T.WBTerritory ='" + orderSearch.Territory + "'  " : whrSQLquery + " AND T.WBTerritory = '" + orderSearch.Territory + "' ";
            }

            if (vidSearch.VideoVersion != null && vidSearch.VideoVersion.Any())
            {
                string videoVersion = vidSearch.VideoVersion.Aggregate((current, next) => current + "', '" + next);
                videoVersion = string.Format("{0}{1}{0}", "'", videoVersion);

                whrSQLquery += string.IsNullOrEmpty(whrSQLquery) ? string.Empty : " AND ";
                whrSQLquery += " VideoVersion IN (" + videoVersion + ")";
                //whrSQLquery = string.IsNullOrEmpty(whrSQLquery) ? " T.WBTerritory ='" + orderSearch.Territory + "'  " : whrSQLquery + " AND T.WBTerritory = '" + orderSearch.Territory + "' ";
            }

            if (vidSearch.VendorId != null && vidSearch.VendorId.Any())
            {
                string vendorId = vidSearch.VendorId.Aggregate((current, next) => current + "', '" + next);
                vendorId = string.Format("{0}{1}{0}", "'", vendorId);

                whrSQLquery += string.IsNullOrEmpty(whrSQLquery) ? string.Empty : " AND ";
                whrSQLquery += " VendorId IN (" + vendorId + ")";
                //whrSQLquery = string.IsNullOrEmpty(whrSQLquery) ? " T.WBTerritory ='" + orderSearch.Territory + "'  " : whrSQLquery + " AND T.WBTerritory = '" + orderSearch.Territory + "' ";
            }

            if (!string.IsNullOrEmpty(vidSearch.VidStatus))
            {
                whrSQLquery = string.IsNullOrEmpty(whrSQLquery) ? " VIDStatus ='" + vidSearch.VidStatus + "'  " : whrSQLquery + " AND VIDStatus = '" + vidSearch.VidStatus + "' ";
            }

            if (!string.IsNullOrEmpty(whrSQLquery))
            {
                whrSQLquery = "where" + whrSQLquery;
            }
            string VidReportSourceFile = App.Config.VidReportExportFilePath;
            string VidReportCopyFile   = App.Config.VidReportExportCopyFilePath;

            string downloadedFileName = "Vid Report" + DateTime.Now.ToString("yyyy_MM_dd_hh_mm_ss") + ".xlsx";
            string path         = App.Config.ReportDirectoryPath;
            string downloadFile = string.Format(path, downloadedFileName);

            File.Copy(VidReportSourceFile, VidReportCopyFile, true);
            _repository.ExportVidReport(whrSQLquery);

            File.Copy(VidReportSourceFile, downloadFile, true);
            if (File.Exists(VidReportSourceFile))
            {
                File.Delete(VidReportSourceFile);
            }
            File.Copy(VidReportCopyFile, VidReportSourceFile, true);
            if (File.Exists(VidReportCopyFile))
            {
                File.Delete(VidReportCopyFile);
            }
            DownLoadFile download = DownloadFile(downloadFile, downloadedFileName);

            return(download);
        }
        /// <summary>
        /// Export Title Report in .xlsx for selected filter criteria
        /// </summary>
        /// <param name="reportSearch">Filters values</param>
        /// <returns>File name and Byte stream</returns>
        public DownLoadFile GenerateTitleReport(TitleSearch titleSearch)
        {
            string whrSQLquery = this.getTitleReportWhereClause(titleSearch);

            #region Moved to GetTitleWhereClause()
            //string temp = string.Empty;
            //if (!string.IsNullOrEmpty(titleSearch.StartDate) && !string.IsNullOrEmpty(titleSearch.EndDate))
            //{
            //    //titleSearch.ESTStartDate = Convert.ToDateTime(titleSearch.StartDate);
            //    //titleSearch.ESTEndDate = Convert.ToDateTime(titleSearch.EndDate);
            //    titleSearch.ESTStartDate = DateTime.ParseExact(titleSearch.StartDate, "MM/dd/yyyy", null);
            //    titleSearch.ESTEndDate = DateTime.ParseExact(titleSearch.EndDate, "MM/dd/yyyy", null);
            //}

            //if (!string.IsNullOrEmpty(titleSearch.SelectedTitle))
            //{
            //    temp = titleSearch.SelectedTitle;
            //    titleSearch.SelectedTitle = titleSearch.SelectedTitle.Replace("'", "\''");
            //    whrSQLquery = string.IsNullOrEmpty(whrSQLquery) ? " TitleName ='" + titleSearch.SelectedTitle + "'  " : whrSQLquery + " AND TitleName = '" + titleSearch.SelectedTitle + "' ";
            //}
            //if (!string.IsNullOrEmpty(titleSearch.EditType))
            //{
            //    whrSQLquery = string.IsNullOrEmpty(whrSQLquery) ? " Category ='" + titleSearch.EditType + "'  " : whrSQLquery + " AND Category = '" + titleSearch.EditType + "' ";
            //}
            //if (!string.IsNullOrEmpty(titleSearch.Territory))
            //{
            //    whrSQLquery = string.IsNullOrEmpty(whrSQLquery) ? " AppleTerritory ='" + titleSearch.Territory + "'  " : whrSQLquery + " AND AppleTerritory = '" + titleSearch.Territory + "' ";
            //}

            //if (!string.IsNullOrEmpty(titleSearch.Language))
            //{
            //    whrSQLquery = string.IsNullOrEmpty(whrSQLquery) ? " LanguageName ='" + titleSearch.Language + "'  " : whrSQLquery + " AND LanguageName = '" + titleSearch.Language + "' ";
            //}

            //if (!string.IsNullOrEmpty(titleSearch.VideoVersion))
            //{
            //    whrSQLquery = string.IsNullOrEmpty(whrSQLquery) ? " VideoVersion ='" + titleSearch.VideoVersion + "'  " : whrSQLquery + " AND VideoVersion = '" + titleSearch.VideoVersion + "' ";
            //}

            //if ((titleSearch.ESTStartDate != null && !(titleSearch.ESTStartDate.Equals(DateTime.MinValue))) && (titleSearch.ESTEndDate != null && !(titleSearch.ESTEndDate.Equals(DateTime.MinValue))))
            //{
            //    string estStartDate = titleSearch.ESTStartDate.Date.ToString("yyyy-MM-dd");
            //    string estEndDate = titleSearch.ESTEndDate.AddDays(1).Date.ToString("yyyy-MM-dd");
            //    whrSQLquery = string.IsNullOrEmpty(whrSQLquery) ? " (ESTStartDate >='" + estStartDate + "' AND ESTEndDate <'" + estEndDate + "')  " : whrSQLquery + " AND (ESTStartDate >='" + estStartDate + "' AND ESTEndDate <'" + estEndDate + "') ";
            //}

            //if (!string.IsNullOrEmpty(titleSearch.MPM))
            //{
            //    whrSQLquery = string.IsNullOrEmpty(whrSQLquery) ? " MPM ='" + titleSearch.MPM + "'  " : whrSQLquery + " AND MPM = '" + titleSearch.MPM + "' ";
            //}

            //if (!string.IsNullOrEmpty(titleSearch.VendorId))
            //{
            //    whrSQLquery = string.IsNullOrEmpty(whrSQLquery) ? " VendorId ='" + titleSearch.VendorId + "'  " : whrSQLquery + " AND VendorId = '" + titleSearch.VendorId + "' ";
            //}

            //if (!string.IsNullOrEmpty(titleSearch.ComponentType))
            //{
            //    string componentTypes = string.Empty;
            //    if (titleSearch.ComponentType.Equals("Audio"))
            //    {
            //        componentTypes = "'AUDIO'" + "," + "'FORCED_SUBTITLES'" + "," + "'DUB_CREDIT'" + "," + "'AUDIO_DESCRIPTION'";
            //    }
            //    else if (titleSearch.ComponentType.Equals("Sub"))
            //    {
            //        componentTypes = "'SUBTITLES'" + "," + "'CAPTIONS'";
            //    }
            //    else if (titleSearch.ComponentType.Equals("Video"))
            //    {
            //        componentTypes = "'VIDEO'";
            //    }
            //    whrSQLquery = string.IsNullOrEmpty(whrSQLquery) ? " ComponentType IN(" + componentTypes + ")" : whrSQLquery + " AND ComponentType IN(" + componentTypes + ") ";
            //}

            //if (!string.IsNullOrEmpty(whrSQLquery))
            //{
            //    whrSQLquery = "where" + whrSQLquery;
            //}

            //if (!string.IsNullOrEmpty(titleSearch.SortBy))
            //{
            //    whrSQLquery = whrSQLquery + " ORDER BY " + " " + titleSearch.SortBy + " " + titleSearch.SortOrder;
            //}
            //// this if block is to resore title name which is modified for search title with '
            //if (!string.IsNullOrEmpty(temp))
            //{
            //    titleSearch.SelectedTitle = temp;
            //}
            #endregion


            //string TitleReportSourceFile = ConfigurationManager.AppSettings["TitleReportSourceFile"];
            string TitleReportSourceFile = App.Config.TitleReportExportFilePath;
            //string TitleReportCopyFile = ConfigurationManager.AppSettings["TitleReportCopyFile"];
            string TitleReportCopyFile = App.Config.TitleReportExportCopyFilePath;

            string downloadedFileName = "Title Report" + DateTime.Now.ToString("yyyy_MM_dd_hh_mm_ss") + ".xlsx";
            //string path = ConfigurationManager.AppSettings["directoryPath"];
            string path         = App.Config.ReportDirectoryPath;
            string downloadFile = string.Format(path, downloadedFileName);
            File.Copy(TitleReportSourceFile, TitleReportCopyFile, true);
            _repository.GenerateTitleReport(whrSQLquery);

            File.Copy(TitleReportSourceFile, downloadFile, true);
            if (File.Exists(TitleReportSourceFile))
            {
                File.Delete(TitleReportSourceFile);
            }
            File.Copy(TitleReportCopyFile, TitleReportSourceFile, true);
            if (File.Exists(TitleReportCopyFile))
            {
                File.Delete(TitleReportCopyFile);
            }
            DownLoadFile download = DownloadFile(downloadFile, downloadedFileName);
            return(download);
        }
        private void DownLoad(DownLoadFile downLoadFile)
        {
            try
            {
                List <Proxy> proxyList = proxyHelper.Get();

                if (proxyList is null)
                {
                    return;
                }

                string url        = downLoadFile.Address;
                string folderName = downLoadFile.FileName;

                if (string.IsNullOrEmpty(folderName))
                {
                    folderName = "Unknown";
                }

                logger.InfoFormat("开始下载: {0}, {1}", url, folderName);
                downLoadFile.DownLoading = true;

                StringBuilder folderPath = new StringBuilder(folderName.Length + 15);
                StringBuilder filePath   = new StringBuilder(folderName.Length + 37);

                string pattern = string.Empty;
                Regex  regex   = null;

                // 删除尾部限定大小
                regex = new Regex(@"((http|https)://)(([a-zA-Z0-9\._-]+)/)+(w\d+)");
                if (regex.IsMatch(url))
                {
                    url = url.Substring(0, url.LastIndexOf('/'));
                }

                // 拼接生成文件路径
                folderPath.Append("DownLoad/coser/").Append(folderName);
                regex = new Regex(@"((http|https)://)(([a-zA-Z0-9\._-]+)/)+");
                filePath.Append("DownLoad/coser/").Append(folderName).Append('/').Append(url.Substring(regex.Match(url).Value.Length));

                string path     = folderPath.ToString();
                string fileName = filePath.ToString();

                bool isExists = false;
                if (FileUtil.CheckPathExists(path, fileName))
                {
                    isExists = true;
                    if (!FileUtil.IsJpeg(fileName))
                    {
                        isExists = false;
                    }
                }

                if (isExists)
                {
                    return;
                }

                httpUtil.DownLoad(url, fileName, proxyList, o =>
                {
                    try
                    {
                        if (o)
                        {
                            logger.InfoFormat("下载完成: {0}, {1}", url, fileName);
                            this.downLoadHelper.Remove(downLoadFile);
                            Wait();
                            downLoadFiles.Remove(downLoadFile);
                        }
                        else
                        {
                            logger.InfoFormat("下载失败: {0}, {1}", url, fileName);
                            downLoadFile.DownLoading = false;
                        }
                    }
                    catch (Exception ex)
                    {
                        logger.Error(ex);
                        downLoadFile.DownLoading = false;
                    }
                });
            }
            catch (Exception ex)
            {
                logger.Error(ex);
                downLoadFile.DownLoading = false;
            }
        }
        /// <summary>
        /// Export Order Report in .xlsx for selected filter criteria
        /// </summary>
        /// <param name="reportSearch">Filters values</param>
        /// <returns>File name and Byte stream</returns>
        public DownLoadFile GenerateOrderReport(OrderSearch orderSearch)
        {
            string whrSQLquery = string.Empty;
            string channel     = string.Empty;
            string temp        = string.Empty;

            if (!string.IsNullOrEmpty(orderSearch.StartDate) && !string.IsNullOrEmpty(orderSearch.EndDate))
            {
                //orderSearch.ESTStartDate = Convert.ToDateTime(orderSearch.StartDate);
                //orderSearch.ESTEndDate = Convert.ToDateTime(orderSearch.EndDate);
                orderSearch.ESTStartDate = DateTime.ParseExact(orderSearch.StartDate, "MM/dd/yyyy", null);
                orderSearch.ESTEndDate   = DateTime.ParseExact(orderSearch.EndDate, "MM/dd/yyyy", null);
            }
            if (!string.IsNullOrEmpty(orderSearch.SelectedTitle))
            {
                temp = orderSearch.SelectedTitle;
                orderSearch.SelectedTitle = orderSearch.SelectedTitle.Replace("'", "\''");
                whrSQLquery = string.IsNullOrEmpty(whrSQLquery) ? " AG.VideoVersion ='" + orderSearch.SelectedTitle + "'  " : whrSQLquery + " AND AG.VideoVersion = '" + orderSearch.SelectedTitle + "' ";
            }
            if (!string.IsNullOrEmpty(orderSearch.EditType))
            {
                whrSQLquery = string.IsNullOrEmpty(whrSQLquery) ? " O.Category ='" + orderSearch.EditType + "'  " : whrSQLquery + " AND O.Category = '" + orderSearch.EditType + "' ";
            }
            if (!string.IsNullOrEmpty(orderSearch.LocalEdit))
            {
                whrSQLquery = string.IsNullOrEmpty(whrSQLquery) ? " AG.LocalEdit ='" + orderSearch.LocalEdit + "'  " : whrSQLquery + " AND AG.LocalEdit = '" + orderSearch.LocalEdit + "' ";
            }
            if (!string.IsNullOrEmpty(orderSearch.OrderStatus))
            {
                whrSQLquery = string.IsNullOrEmpty(whrSQLquery) ? " O.OrderStatus ='" + orderSearch.OrderStatus + "'  " : whrSQLquery + " AND O.OrderStatus = '" + orderSearch.OrderStatus + "' ";
            }
            if (!string.IsNullOrEmpty(orderSearch.GreenLightSent))
            {
                if (orderSearch.GreenLightSent.Equals("Yes"))
                {
                    whrSQLquery = string.IsNullOrEmpty(whrSQLquery) ? " O.GreenlightSenttoPackaging IS NOT NULL " : whrSQLquery + " AND O.GreenlightSenttoPackaging IS NOT NULL ";
                    //whrSQLquery = string.IsNullOrEmpty(whrSQLquery) ? " O.GreenlightSenttoPackaging IS NOT NULL OR O.GreenlightSenttoPackaging <>'" + blanks + "'" : whrSQLquery + "AND O.GreenlightSenttoPackaging IS NOT NULL OR O.GreenlightSenttoPackaging <>'" + blanks + "'";
                }
                else if (orderSearch.GreenLightSent.Equals("No"))
                {
                    whrSQLquery = string.IsNullOrEmpty(whrSQLquery) ? " O.GreenlightSenttoPackaging IS NULL " : whrSQLquery + " AND O.GreenlightSenttoPackaging IS NULL ";
                    //whrSQLquery = string.IsNullOrEmpty(whrSQLquery) ? " O.GreenlightSenttoPackaging IS NULL OR O.GreenlightSenttoPackaging ='" + blanks + "'" : whrSQLquery + "AND O.GreenlightSenttoPackaging IS NULL OR O.GreenlightSenttoPackaging ='" + blanks + "'";
                }
            }
            if (!string.IsNullOrEmpty(orderSearch.GreenLightReceived))
            {
                if (orderSearch.GreenLightReceived.Equals("Yes"))
                {
                    whrSQLquery = string.IsNullOrEmpty(whrSQLquery) ? " (O.GreenlightValidatedbyDMDM IS NOT NULL ) " : whrSQLquery + " AND (O.GreenlightValidatedbyDMDM IS NOT NULL ) ";
                }
                else if (orderSearch.GreenLightReceived.Equals("No"))
                {
                    whrSQLquery = string.IsNullOrEmpty(whrSQLquery) ? " (O.GreenlightValidatedbyDMDM IS NULL ) " : whrSQLquery + " AND (O.GreenlightValidatedbyDMDM IS NULL ) ";
                }
            }
            if (!string.IsNullOrEmpty(orderSearch.Region))
            {
                whrSQLquery = string.IsNullOrEmpty(whrSQLquery) ? " R.NAME ='" + orderSearch.Region + "'  " : whrSQLquery + " AND R.NAME = '" + orderSearch.Region + "' ";
            }
            if (orderSearch.Territory != null && orderSearch.Territory.Any())
            {
                string concatterritory = orderSearch.Territory.Aggregate((current, next) => current + "', '" + next);
                concatterritory = string.Format("{0}{1}{0}", "'", concatterritory);

                whrSQLquery += string.IsNullOrEmpty(whrSQLquery) ? string.Empty : " AND ";
                whrSQLquery += " T.WBTerritory IN (" + concatterritory + ") ";
                //whrSQLquery = string.IsNullOrEmpty(whrSQLquery) ? " T.WBTerritory ='" + orderSearch.Territory + "'  " : whrSQLquery + " AND T.WBTerritory = '" + orderSearch.Territory + "' ";
            }
            if ((orderSearch.ESTStartDate != null && !(orderSearch.ESTStartDate.Equals(DateTime.MinValue))) && (orderSearch.ESTEndDate != null && !(orderSearch.ESTEndDate.Equals(DateTime.MinValue))))
            {
                string startDate = orderSearch.ESTStartDate.Date.ToString("yyyy-MM-dd");
                string endDate   = orderSearch.ESTEndDate.AddDays(1).Date.ToString("yyyy-MM-dd");
                whrSQLquery = string.IsNullOrEmpty(whrSQLquery) ? " (CF.MinClientStartDate >='" + startDate + "' AND CF.MaxClientEndDate <'" + endDate + "')  " : whrSQLquery + " AND (CF.MinClientStartDate >='" + startDate + "' AND CF.MaxClientEndDate <'" + endDate + "') ";
            }
            if (!string.IsNullOrEmpty(orderSearch.OrderType))
            {
                whrSQLquery = string.IsNullOrEmpty(whrSQLquery) ? " O.FileType ='" + orderSearch.OrderType + "'  " : whrSQLquery + " AND O.FileType = '" + orderSearch.OrderType + "' ";
            }
            //if (orderSearch.Territory != null && orderSearch.Territory.Count() != 0)
            //{
            //    string territories = null;
            //    foreach (var x in orderSearch.Territory)
            //    {
            //        territories += "'" + x + "'" + ",";
            //    }
            //    territories = territories.Substring(0, territories.Length - 1);
            //    whrSQLquery = string.IsNullOrEmpty(whrSQLquery) ? " T.WBTerritory IN(" + territories + ")  " : whrSQLquery + " AND T.WBTerritory IN(" + territories + ") ";
            //}
            if (!string.IsNullOrEmpty(orderSearch.MediaType))
            {
                channel = string.IsNullOrEmpty(channel) ? " C.Channel ='" + orderSearch.MediaType + "'  " : whrSQLquery + " AND C.Channel = '" + orderSearch.MediaType + "' ";
            }


            if (!string.IsNullOrEmpty(whrSQLquery))
            {
                whrSQLquery = "where" + whrSQLquery;
            }

            if (!string.IsNullOrEmpty(channel))
            {
                channel = "where" + channel;
            }

            if (!string.IsNullOrEmpty(orderSearch.SortBy))
            {
                whrSQLquery = whrSQLquery + " ORDER BY " + " " + orderSearch.SortBy + " " + orderSearch.SortOrder;
            }

            // this if block is to resore title name which is modified for search title with '
            if (!string.IsNullOrEmpty(temp))
            {
                orderSearch.SelectedTitle = temp;
            }

            //string orderReportSourceFile = ConfigurationManager.AppSettings["OrderReportSourceFile"];
            string orderReportSourceFile = App.Config.OrderReportExportFilePath;
            //string orderReportCopyFile = ConfigurationManager.AppSettings["OrderReportCopyFile"];
            string orderReportCopyFile = App.Config.OrderReportExportCopyFilePath;
            string downloadedFileName  = "Order Report" + DateTime.Now.ToString("yyyy_MM_dd_hh_mm_ss") + ".xlsx";
            //string path = ConfigurationManager.AppSettings["directoryPath"];
            string path         = App.Config.ReportDirectoryPath;
            string downloadFile = string.Format(path, downloadedFileName);

            File.Copy(orderReportSourceFile, orderReportCopyFile, true);
            _repository.GenerateOrderReport(whrSQLquery, channel);

            File.Copy(orderReportSourceFile, downloadFile, true);
            if (File.Exists(orderReportSourceFile))
            {
                File.Delete(orderReportSourceFile);
            }
            File.Copy(orderReportCopyFile, orderReportSourceFile, true);
            if (File.Exists(orderReportCopyFile))
            {
                File.Delete(orderReportCopyFile);
            }
            DownLoadFile download = DownloadFile(downloadFile, downloadedFileName);

            return(download);
        }
        public void ProcessRequest(HttpContext context)
        {
            DownLoadFile Dlf = new DownLoadFile();

            Dlf.ProcessRequest(context);
        }