예제 #1
0
        /// <summary>
        /// 重新生成PDF
        /// </summary>
        /// <param name="FileID">节点ID</param>
        private void ConvertAllEFileToPDF(string FileID)
        {
            BLL.T_FileList_BLL         fileBLL  = new ERM.BLL.T_FileList_BLL();
            MDL.T_FileList             fileMDL  = fileBLL.Find(FileID, Globals.ProjectNO);
            BLL.T_CellAndEFile_BLL     cellBLL  = new ERM.BLL.T_CellAndEFile_BLL();
            IList <MDL.T_CellAndEFile> cellList =
                cellBLL.FindByGdFileID(FileID, Globals.ProjectNO);

            System.Collections.ArrayList fileArryList = new System.Collections.ArrayList();
            bool isUpdateFileSelect_flg = false;

            foreach (MDL.T_CellAndEFile cellMDL in cellList)
            {
                string pdfPath = "";
                if (cellMDL.DocYs == null || cellMDL.DocYs == 1 || cellMDL.fileTreePath == String.Empty || cellMDL.fileTreePath == "")
                {
                    if (!isUpdateFileSelect_flg)
                    {
                        isUpdateFileSelect_flg = true;
                    }

                    using (ConvertCell2PDF c1 = new ConvertCell2PDF())
                    {
                        try
                        {
                            int iPageCount = c1.PrintCellToPDF(Globals.ProjectPath + cellMDL.filepath, Globals.ProjectPath + "PDF\\" + cellMDL.CellID + ".pdf");
                            if (iPageCount == 0)
                            {
                                cellMDL.fileTreePath = "";
                            }
                            else
                            {
                                cellMDL.fileTreePath = "PDF\\" + cellMDL.CellID + ".pdf";
                            }
                            cellMDL.DocYs    = 0;
                            cellMDL.DoStatus = 1;
                            cellMDL.ys       = iPageCount;
                            cellBLL.Update(cellMDL);
                        }
                        catch (Exception e)
                        {
                            cellMDL.fileTreePath = "";
                            MyCommon.WriteLog("PDF转换失败!错误信息:" + e.Message);
                        }
                        pdfPath = cellMDL.fileTreePath;
                    }
                }
                else
                {
                    pdfPath = cellMDL.fileTreePath;
                }

                if (!System.IO.File.Exists(Globals.ProjectPath + pdfPath))
                {
                    continue;
                }
                fileArryList.Add(Globals.ProjectPath + pdfPath);
            }
            string[] FileList = new string[fileArryList.Count];
            for (int i = 0; i < fileArryList.Count; i++)
            {
                FileList[i] = fileArryList[i].ToString();
            }
            using (ConvertCell2PDF c1 = new ConvertCell2PDF())
            {
                int iPageCount = 0;
                if (FileList.Length > 0)
                {
                    try
                    {
                        iPageCount = c1.MergePDF(FileList, Globals.ProjectPath + "MPDF\\" + FileID + ".pdf");
                        if (iPageCount == 0)
                        {
                            fileMDL.filepath = "";
                        }
                        else
                        {
                            fileMDL.filepath = "MPDF\\" + FileID + ".pdf";
                        }
                    }
                    catch (Exception ex)
                    {
                        iPageCount       = 0;
                        fileMDL.filepath = "";
                        MyCommon.WriteLog("合并PDF失败!错误信息:" + ex.Message);
                    }
                }
                else
                {
                    fileMDL.filepath = "";
                }

                //1 文字数量  2声像 3照片数量
                int         EFileType_flg = 1;
                TreeFactory treeFactory   = new TreeFactory();
                treeFactory.GetParentNodeType(FileID, ref EFileType_flg);
                if (EFileType_flg == 1)
                {
                    fileMDL.sl = iPageCount;
                }
                else if (EFileType_flg == 3)
                {
                    int tzz = MyCommon.ToInt(fileMDL.tzz);
                    int dtz = MyCommon.ToInt(fileMDL.dtz);
                    int zpz = MyCommon.ToInt(fileMDL.zpz);
                    int dpz = MyCommon.ToInt(fileMDL.dpz);

                    fileMDL.dw  = (iPageCount + dtz).ToString();
                    fileMDL.tzz = (iPageCount).ToString();
                    fileMDL.dtz = dtz.ToString();

                    fileMDL.wzz = (zpz + dpz).ToString();
                    fileMDL.zpz = zpz.ToString();
                    fileMDL.dpz = dpz.ToString();
                }
                else if (EFileType_flg == 2)
                {
                    int tzz = MyCommon.ToInt(fileMDL.tzz);
                    int dtz = MyCommon.ToInt(fileMDL.dtz);
                    int zpz = MyCommon.ToInt(fileMDL.zpz);
                    int dpz = MyCommon.ToInt(fileMDL.dpz);

                    fileMDL.dw  = (tzz + dtz).ToString();
                    fileMDL.tzz = tzz.ToString();
                    fileMDL.dtz = dtz.ToString();

                    fileMDL.wzz = (iPageCount + dpz).ToString();
                    fileMDL.zpz = (iPageCount).ToString();
                    fileMDL.dpz = dpz.ToString();
                }
                fileMDL.selected = 0;
                fileBLL.Update(fileMDL);
            }
        }
예제 #2
0
        private void btnPrint_Click(object sender, EventArgs e)
        {
            try
            {
                if (lstFiles.CheckedItems.Count == 0)
                {
                    return;
                }
                DataTable dt = ((DataView)lstFiles.DataSource).ToTable();
                for (int j = lstFiles.Items.Count - 1; j >= 0; j--)
                {
                    if (!lstFiles.GetItemChecked(j))
                    {
                        dt.Rows[j].Delete();
                    }
                }
                if (!CheckFileExist(dt))
                {
                    return;
                }
                if (dt.Rows.Count == 0)
                {
                    TXMessageBoxExtensions.Info("没有要打印的文件!");
                    return;
                }
                string PrintMode = "2";
                if (PrintMode.Equals("2") && tn != null)
                {
                    string[] printFileList = new string[dt.Rows.Count];
                    string   tempFolder    =
                        System.IO.Path.Combine(System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "erm_print");
                    if (!System.IO.Directory.Exists(tempFolder))
                    {
                        MyCommon.DeleteAndCreateEmptyDirectory(tempFolder, true);
                    }
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        /*
                         * * 拷贝到临时目录进行打印,因为隐藏章打印会删除掉,影响系统查看
                         * * */
                        string tempFile = System.IO.Path.Combine(tempFolder, dt.Rows[i]["title"].ToString() + ".pdf");
                        System.IO.File.Copy(dt.Rows[i]["filed"].ToString(), tempFile, true);
                        printFileList[i] = tempFile;
                    }

                    using (ConvertCell2PDF cl_print = new ConvertCell2PDF())
                    {
                        MyCommon.DeleteAndCreateEmptyDirectory(Application.StartupPath + @"\Reports\printPdf_temp", true);
                        cl_print.MergePDF(printFileList, Application.StartupPath + @"\Reports\printPdf_temp\printFile.pdf");
                        frmReport frmReports = new frmReport("printFile.pdf");
                        frmReports.ShowDialog();
                        //cl_print.BathPrintPDF(printFileList);
                    }
                    //switch (tn.ImageIndex)
                    //{
                    //    case 0://所有
                    //        string[] printFileList = new string[dt.Rows.Count];
                    //        for (int i = 0; i < dt.Rows.Count; i++)
                    //        {
                    //            printFileList[i] = dt.Rows[i]["filed"].ToString();
                    //        }
                    //        break;
                    //    case 1://案卷
                    //        //OperatorFile(dt, printername, ref hMenu, strDefault, dtNew, tn, StartPageNo);
                    //        break;
                    //    case 2://文件
                    //        //hMenu = OperatorTem(dt, printername, hMenu, strDefault, dtNew, StartPageNo);
                    //        break;
                    //    default:
                    //        break;
                    //}
                }
                else
                {
                    frmPrinterList frm = new frmPrinterList();
                    DialogResult   drs = frm.ShowDialog();
                    if (drs != DialogResult.OK)
                    {
                        return;
                    }
                    string printername = frm.GetSelected;
                    btnPrint.Enabled  = false;
                    btnCancel.Enabled = false;
                    lstFiles.Enabled  = false;
                    chkAll.Enabled    = false;
                    IntPtr hMenu = GetSystemMenu(this.Handle, 0);
                    EnableMenuItem(hMenu, SC_CLOSE, MF_DISABLED | MF_GRAYED);
                    string strDefault = "";
                    if (setDefaultPrinter)
                    {
                        strDefault = PrinterOperate.GetDefaultPrinterName();
                        if (string.Compare(strDefault, printername, true) != 0)
                        {
                            PrinterOperate.SetPrinter(printername);
                        }
                    }

                    hMenu = PrintFile(dt, printername, hMenu, strDefault);
                    if (setDefaultPrinter)//设回来
                    {
                        if (string.Compare(strDefault, printername, true) != 0)
                        {
                            PrinterOperate.SetPrinter(strDefault);
                        }
                    }
                    btnCancel.Enabled = true;
                    hMenu             = GetSystemMenu(this.Handle, 0);
                    EnableMenuItem(hMenu, SC_CLOSE, MF_ENABLED);
                    if (TXMessageBoxExtensions.Question("打印任务已经全部输送到打印机,现在可以关闭窗口了,请耐心等待打印机的处理。\n 是否继续打印?") != DialogResult.OK)
                    {
                        this.Close();
                    }
                    else
                    {
                        btnPrint.Enabled  = true;
                        btnCancel.Enabled = true;
                        lstFiles.Enabled  = true;
                        chkAll.Enabled    = true;
                    }
                }
                btnPrint.Enabled  = true;
                btnCancel.Enabled = true;
                lstFiles.Enabled  = true;
                chkAll.Enabled    = true;
            }
            catch (Exception ex)
            {
                btnPrint.Enabled  = true;
                btnCancel.Enabled = true;
            }
        }