Exemplo n.º 1
0
        /// <summary>
        /// 批量导出
        /// </summary>
        /// <param name="ids"></param>
        /// <returns></returns>
        public FilePathResult ExpAllPDF(string ids)
        {
            DataTable dt       = new DataTable();
            int       total    = 0;
            string    strWhere = "";

            if (!string.IsNullOrEmpty(ids))
            {
                strWhere = PageTools.AddWhere(strWhere, $"T.ReportID in ({ids})");
            }
            //添加数据权限判断
            switch (CurrentUserInfo.DataRange)
            {
            case 2:    //区域
                strWhere = PageTools.AddWhere(strWhere, "T.AreaID=" + CurrentUserInfo.AreaID + " ");
                break;

            case 3:    //个人
                strWhere = PageTools.AddWhere(strWhere, "T.EditPersonnelID=" + CurrentUserInfo.PersonnelID + " ");
                break;
            }
            dt = tTestReport.GetListByPage(strWhere, "TestTime DESC", 1, 10000, ref total).Tables[0];
            var strs = "批量下载-";

            string[] iFile = new string[1];
            if (dt != null && dt.Rows.Count > 0)
            {
                iFile = new string[dt.Rows.Count];
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    ProcessStartInfo Pss = new ProcessStartInfo();
                    Pss.FileName = Server.MapPath("/HtmlToPDF/wkhtmltopdf.exe");
                    string strUrl      = System.Configuration.ConfigurationManager.AppSettings["HostName"].ToString() + "/ReportView/TestReportView?ReportID=" + dt.Rows[i]["ReportID"];//Request.UserHostName
                    var    eTestReport = tTestReport.GetModel(Convert.ToInt32(dt.Rows[i]["ReportID"]));
                    if (i == 0)
                    {
                        strs += eTestReport.SampleName;
                    }
                    string FileName = UrnHtml(eTestReport.SampleNum) + ".pdf";
                    string FilePath = Server.MapPath("/TestReportPDF/" + FileName);
                    Pss.Arguments              = string.Format("{0} {1}", "\"" + strUrl + "\"", "\"" + FilePath + "\"");
                    Pss.UseShellExecute        = false;
                    Pss.RedirectStandardInput  = true;
                    Pss.RedirectStandardOutput = true;

                    bool bresult = false;
                    using (Process PS = new Process())
                    {
                        PS.StartInfo = Pss;
                        PS.Start();
                        PS.WaitForExit();
                        if (PS.ExitCode == 0)
                        {
                            bresult = true;
                            PS.Close();
                        }
                    }
                    iFile[i] = FilePath;
                }
            }

            string oFile = AppDomain.CurrentDomain.BaseDirectory + "UpFile//DownLoads//" + strs + ".zip";

            PublicClass.CompressFiles(iFile, oFile);
            return(File(oFile, "application/octet-stream", strs + ".zip"));
        }
Exemplo n.º 2
0
        public FilePathResult ExpAllPDF()
        {
            string AreaID           = Session["_AreaID"].ToString();
            string StartTime        = Session["_StartTime"].ToString();
            string EndTime          = Session["_EndTime"].ToString();
            string SampleNum        = Session["_SampleNum"].ToString();
            string SampleName       = Session["_SampleName"].ToString();
            string Department       = Session["_Department"].ToString();
            string MainTestPersonne = Session["_MainTestPersonne"].ToString();
            string SamplingTimes    = Session["_SamplingTimes"].ToString();
            string SamplingTimee    = Session["_SamplingTimee"].ToString();

            string ReportID = "";

            if (Session["_ReportID"] != null)
            {
                ReportID = Session["_ReportID"].ToString();
            }


            DataTable dt       = new DataTable();
            int       total    = 0;
            string    strWhere = "";

            if (!string.IsNullOrEmpty(ReportID) && ReportID != "0")
            {
                strWhere = PageTools.AddWhere(strWhere, "T.ReportID=" + ReportID);
            }
            if (!string.IsNullOrEmpty(AreaID) && AreaID != "-1")
            {
                strWhere = PageTools.AddWhere(strWhere, "T.AreaID=" + AreaID);
            }
            if (!string.IsNullOrEmpty(StartTime))
            {
                strWhere = PageTools.AddWhere(strWhere, "T.IssuedTime>=cast('" + StartTime + "' as datetime)");
            }
            if (!string.IsNullOrEmpty(EndTime))
            {
                strWhere = PageTools.AddWhere(strWhere, "T.IssuedTime<=cast('" + EndTime + "' as datetime)");
            }
            if (!string.IsNullOrEmpty(SampleNum))
            {
                strWhere = PageTools.AddWhere(strWhere, "T.SampleNum like  '%" + SampleNum + "%'");
            }
            if (!string.IsNullOrEmpty(SampleName))
            {
                strWhere = PageTools.AddWhere(strWhere, "T.SampleName like  '%" + SampleName + "%'");
            }
            if (!string.IsNullOrEmpty(Department))
            {
                strWhere = PageTools.AddWhere(strWhere, "T.Department like  '%" + Department + "%'");
            }
            if (!string.IsNullOrEmpty(MainTestPersonne))
            {
                strWhere = PageTools.AddWhere(strWhere, "D.PersonnelName like '%" + MainTestPersonne + "%'");
            }

            if (!string.IsNullOrEmpty(SamplingTimes))
            {
                strWhere = PageTools.AddWhere(strWhere, "SamplingTime>=cast('" + SamplingTimes + "' as datetime)");
            }
            if (!string.IsNullOrEmpty(SamplingTimee))
            {
                strWhere = PageTools.AddWhere(strWhere, "SamplingTime<=cast('" + SamplingTimee + "' as datetime)");
            }

            //添加数据权限判断
            switch (CurrentUserInfo.DataRange)
            {
            case 2:    //区域
                strWhere = PageTools.AddWhere(strWhere, "T.AreaID=" + CurrentUserInfo.AreaID + " ");
                break;

            case 3:    //个人
                strWhere = PageTools.AddWhere(strWhere, "T.EditPersonnelID=" + CurrentUserInfo.PersonnelID + " ");
                break;
            }

            try
            {
                //dt = tTestReport.GetListByPage(strWhere, "UpdateTime DESC,T.SampleName ASC", pageNumber * pageSize - (pageSize - 1), pageNumber * pageSize, ref total).Tables[0];
                dt = tTestReport.GetListByPage(strWhere, "TestTime DESC", 1, 10000, ref total).Tables[0];
            }
            catch { }
            string[] iFile = new string[1];
            if (dt != null && dt.Rows.Count > 0)
            {
                iFile = new string[dt.Rows.Count];
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    ProcessStartInfo Pss = new ProcessStartInfo();
                    Pss.FileName = Server.MapPath("/HtmlToPDF/wkhtmltopdf.exe");
                    string strUrl      = System.Configuration.ConfigurationManager.AppSettings["HostName"].ToString() + "/ReportView/TestReportView?ReportID=" + dt.Rows[i]["ReportID"];//Request.UserHostName
                    var    eTestReport = tTestReport.GetModel(Convert.ToInt32(dt.Rows[i]["ReportID"]));
                    //string FileName = Guid.NewGuid() + ".pdf";

                    string FileName = UrnHtml(eTestReport.SampleNum) + ".pdf";
                    string FilePath = Server.MapPath("/TestReportPDF/" + FileName);
                    Pss.Arguments              = string.Format("{0} {1}", "\"" + strUrl + "\"", "\"" + FilePath + "\"");
                    Pss.UseShellExecute        = false;
                    Pss.RedirectStandardInput  = true;
                    Pss.RedirectStandardOutput = true;

                    bool bresult = false;
                    using (Process PS = new Process())
                    {
                        PS.StartInfo = Pss;
                        PS.Start();
                        PS.WaitForExit();
                        if (PS.ExitCode == 0)
                        {
                            bresult = true;
                            PS.Close();
                        }
                    }
                    iFile[i] = FilePath;
                }
            }

            var    strs  = DateTime.Now.ToFileTime().ToString();
            string oFile = AppDomain.CurrentDomain.BaseDirectory + "UpFile//DownLoads//" + strs + ".zip";

            PublicClass.CompressFiles(iFile, oFile);
            return(File(oFile, "application/octet-stream", strs + ".zip"));
        }