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) { } 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"; BP.Rpt.RTF.RTFEngine engine = new BP.Rpt.RTF.RTFEngine(); if (tempName.ToLower() == "all") { FrmNodes fns = new FrmNodes(this.FK_Node); foreach (FrmNode fn in fns) { GEEntity ge = new GEEntity(fn.FK_Frm, this.WorkID); engine.AddEn(ge); MapDtls mdtls = new MapDtls(tempName); 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); } else { // 增加主表. GEEntity myge = new GEEntity(tempName, this.FID); 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); } BP.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.Rpt.RTF.RTFEngine rtf = new BP.Rpt.RTF.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 { 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 = this.Request.ApplicationPath + "/DataUser/Bill/" + DataType.CurrentYear + "/" + WebUser.FK_Dept + "/" + en.No + "/" + file; this.Response.Redirect(url, false); // BP.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); } }