public void PrintBill() { BP.WF.Node nd = new BP.WF.Node(this.FK_Node); string path = ApplicationPath + "\\DataUser\\CyclostyleFile\\FlowFrm\\" + nd.FK_Flow + "\\" + nd.NodeID + "\\"; if (System.IO.Directory.Exists(path) == false) { this.Pub1.AddMsgOfWarning("获取模版错误", "模版文件没有找到。" + path); return; } string[] fls = System.IO.Directory.GetFiles(path); string file = fls[int.Parse(this.BillIdx)]; file = file.Replace(ApplicationPath + @"DataUser\CyclostyleFile", ""); FileInfo finfo = new FileInfo(file); string tempName = finfo.Name.Split('.')[0]; string tempNameChinese = finfo.Name.Split('.')[1]; string toPath = ApplicationPath + @"DataUser\Bill\FlowFrm\" + DateTime.Now.ToString("yyyyMMdd") + "\\"; if (System.IO.Directory.Exists(toPath) == false) { System.IO.Directory.CreateDirectory(toPath); } // string billFile = toPath + "\\" + tempName + "." + this.FID + ".doc"; string billFile = toPath + "\\" + Server.UrlDecode(tempNameChinese) + "." + this.WorkID + ".doc"; BP.Pub.RTFEngine engine = new BP.Pub.RTFEngine(); if (tempName.ToLower() == "all") { /* 说明要从所有的流程表单上取数据.*/ FrmNodes fns = new FrmNodes(this.FK_Flow, this.FK_Node); foreach (FrmNode fn in fns) { GEEntity ge = new GEEntity(fn.FK_Frm, this.WorkID); engine.AddEn(ge); MapDtls mdtls = new MapDtls(fn.FK_Frm); foreach (MapDtl dtl in mdtls) { GEDtls enDtls = dtl.HisGEDtl.GetNewEntities as GEDtls; enDtls.Retrieve(GEDtlAttr.RefPK, this.WorkID); engine.EnsDataDtls.Add(enDtls); } } // 增加主表. GEEntity myge = new GEEntity("ND" + nd.NodeID, this.WorkID); engine.AddEn(myge); MapDtls mymdtls = new MapDtls("ND" + nd.NodeID); foreach (MapDtl dtl in mymdtls) { GEDtls enDtls = dtl.HisGEDtl.GetNewEntities as GEDtls; enDtls.Retrieve(GEDtlAttr.RefPK, this.WorkID); engine.EnsDataDtls.Add(enDtls); } // engine.MakeDoc(file, toPath, tempName + "." + this.WorkID + ".doc", null, false); engine.MakeDoc(file, toPath, Server.UrlDecode(tempNameChinese) + "." + this.WorkID + ".doc", null, false); } else { // 增加主表. GEEntity myge = new GEEntity(tempName, this.WorkID); engine.HisGEEntity = myge; engine.AddEn(myge); MapDtls mymdtls = new MapDtls(tempName); foreach (MapDtl dtl in mymdtls) { GEDtls enDtls = dtl.HisGEDtl.GetNewEntities as GEDtls; enDtls.Retrieve(GEDtlAttr.RefPK, this.WorkID); engine.EnsDataDtls.Add(enDtls); } //engine.MakeDoc(file, toPath, tempName + "." + this.FID + ".doc", null, false); engine.MakeDoc(file, toPath, Server.UrlDecode(tempNameChinese) + "." + this.WorkID + ".doc", null, false); } #region 保存单据,以方便查询. Bill bill = new Bill(); bill.MyPK = this.FID + "_" + this.WorkID + "_" + this.FK_Node + "_" + this.BillIdx; bill.WorkID = this.WorkID; bill.FK_Node = this.FK_Node; bill.FK_Dept = WebUser.FK_Dept; bill.FK_Emp = WebUser.No; bill.Url = "/DataUser/Bill/FlowFrm/" + DateTime.Now.ToString("yyyyMMdd") + "/" + Server.UrlDecode(tempNameChinese) + "." + this.WorkID + ".doc"; bill.FullPath = toPath + file; bill.RDT = DataType.CurrentDataTime; bill.FK_NY = DataType.CurrentYearMonth; bill.FK_Flow = this.FK_Flow; if (this.WorkID != 0) { GenerWorkFlow gwf = new GenerWorkFlow(); gwf.WorkID = this.WorkID; if (gwf.RetrieveFromDBSources() == 1) { bill.Emps = gwf.Emps; bill.FK_Starter = gwf.Starter; bill.StartDT = gwf.RDT; bill.Title = gwf.Title; bill.FK_Dept = gwf.FK_Dept; } } try { bill.Insert(); } catch { bill.Update(); } #endregion BP.Sys.PubClass.OpenWordDocV2(billFile, tempNameChinese + ".doc"); }
public void PrintDoc(BillTemplate en) { Node nd = new Node(this.FK_Node); Work wk = nd.HisWork; wk.OID = this.WorkID; wk.Retrieve(); string msg = ""; string file = DataType.CurrentYear + "_" + WebUser.FK_Dept + "_" + en.No + "_" + this.WorkID + ".doc"; BP.Pub.RTFEngine rtf = new BP.Pub.RTFEngine(); // Works works; string[] paths; string path; try { #region 生成单据 rtf.HisEns.Clear(); rtf.EnsDataDtls.Clear(); rtf.AddEn(wk); rtf.ensStrs += ".ND" + wk.NodeID; ArrayList al = wk.GetDtlsDatasOfArrayList(); foreach (Entities ens in al) { rtf.AddDtlEns(ens); } BP.Sys.GEEntity ge = new BP.Sys.GEEntity("ND" + int.Parse(nd.FK_Flow) + "Rpt"); ge.Copy(wk); rtf.HisGEEntity = ge; paths = file.Split('_'); path = paths[0] + "/" + paths[1] + "/" + paths[2] + "/"; path = BP.WF.Glo.FlowFileBill + DataType.CurrentYear + "\\" + WebUser.FK_Dept + "\\" + en.No + "\\"; if (System.IO.Directory.Exists(path) == false) { System.IO.Directory.CreateDirectory(path); } // rtf.ensStrs = ".ND"; rtf.MakeDoc(en.Url + ".rtf", path, file, en.ReplaceVal, false); #endregion #region 转化成pdf. if (en.HisBillFileType == BillFileType.PDF) { string rtfPath = path + file; string pdfPath = rtfPath.Replace(".doc", ".pdf"); try { BP.WF.Glo.Rtf2PDF(rtfPath, pdfPath); file = file.Replace(".doc", ".pdf"); System.IO.File.Delete(rtfPath); file = file.Replace(".doc", ".pdf"); //System.IO.File.Delete(rtfPath); } catch (Exception ex) { msg += ex.Message; } } #endregion string url = BP.WF.Glo.CCFlowAppPath + "DataUser/Bill/" + DataType.CurrentYear + "/" + WebUser.FK_Dept + "/" + en.No + "/" + file; this.Response.Redirect(url, false); // BP.Sys.PubClass.OpenWordDocV2( path+file, en.Name); } catch (Exception ex) { BP.WF.DTS.InitBillDir dir = new BP.WF.DTS.InitBillDir(); dir.Do(); path = BP.WF.Glo.FlowFileBill + DataType.CurrentYear + "\\" + WebUser.FK_Dept + "\\" + en.No + "\\"; string msgErr = "@生成单据失败,请让管理员检查目录设置 [" + BP.WF.Glo.FlowFileBill + "]。@Err:" + ex.Message + " @File=" + file + " @Path:" + path; throw new Exception(msgErr + "@其它信息:" + ex.Message); } }