/// <summary> /// 生成报表 /// </summary> /// <param name="templeteFilePath">模版路径</param> /// <param name="ds">数据源</param> /// <returns>生成单据的路径</returns> public static void Frm_GenerBill(string templeteFullFile, string saveToDir, string saveFileName, BillFileType fileType, DataSet ds, string fk_mapData) { MapData md = new MapData(fk_mapData); GEEntity entity = md.GenerGEEntityByDataSet(ds); BP.Pub.RTFEngine rtf = new BP.Pub.RTFEngine(); rtf.HisEns.Clear(); rtf.EnsDataDtls.Clear(); rtf.HisEns.AddEntity(entity); var dtls = entity.Dtls; foreach (var item in dtls) { rtf.EnsDataDtls.Add(item); } rtf.MakeDoc(templeteFullFile, saveToDir, saveFileName, null, false); }
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); } }
/// <summary> /// 打印单据 /// </summary> /// <param name="func"></param> public void PrintDocV2(BillTemplate func) { string billInfo = ""; Node nd = new Node(this.FK_Node); Work wk = nd.HisWork; wk.OID = this.WorkID; wk.Retrieve(); wk.ResetDefaultVal(); string file = DateTime.Now.Year + "_" + WebUser.FK_Dept + "_" + func.No + "_" + WorkID + ".doc"; BP.Pub.RTFEngine rtf = new BP.Pub.RTFEngine(); string[] paths; string path; try { #region 生成单据 rtf.HisEns.Clear(); rtf.EnsDataDtls.Clear(); if (func.NodeID == 0) { } else { //WorkNodes wns = new WorkNodes(); //if (nd.HisRunModel == RunModel.FL // || nd.HisRunModel == RunModel.FHL // || nd.HisRunModel == RunModel.HL) // wns.GenerByFID(nd.HisFlow, this.WorkID); //else // wns.GenerByWorkID(nd.HisFlow, this.WorkID); //把流程主表数据放入里面去. GEEntity ndxxRpt = new GEEntity("ND" + int.Parse(nd.FK_Flow) + "Rpt"); ndxxRpt.PKVal = this.WorkID; ndxxRpt.Retrieve(); ndxxRpt.Copy(wk); //把数据赋值给wk. wk.Row = ndxxRpt.Row; rtf.HisGEEntity = wk; //加入他的明细表. List <Entities> al = wk.GetDtlsDatasOfList(); foreach (Entities ens in al) { rtf.AddDtlEns(ens); } //rtf.AddEn(wk); ////if (wns.Count == 0) //// works = nd.HisWorks; ////else //// works = wns.GetWorks; //foreach (Work mywk in works) //{ // if (mywk.OID == 0) // continue; // rtf.AddEn(mywk); // rtf.ensStrs += ".ND" + mywk.NodeID; //} } paths = file.Split('_'); path = paths[0] + "/" + paths[1] + "/" + paths[2] + "/"; string billUrl = BP.WF.Glo.CCFlowAppPath + "DataUser/Bill/" + path + file; if (func.HisBillFileType == BillFileType.PDF) { billUrl = billUrl.Replace(".doc", ".pdf"); billInfo += "<img src='/WF/Img/FileType/PDF.gif' /><a href='" + billUrl + "' target=_blank >" + func.Name + "</a>"; } else { billInfo += "<img src='/WF/Img/FileType/doc.gif' /><a href='" + billUrl + "' target=_blank >" + func.Name + "</a>"; } path = BP.WF.Glo.FlowFileBill + DateTime.Now.Year + "\\" + WebUser.FK_Dept + "\\" + func.No + "\\"; // path = Server.MapPath(path); if (System.IO.Directory.Exists(path) == false) { System.IO.Directory.CreateDirectory(path); } rtf.MakeDoc(func.Url + ".rtf", path, file, func.ReplaceVal, false); #endregion #region 转化成pdf. if (func.HisBillFileType == BillFileType.PDF) { string rtfPath = path + file; string pdfPath = rtfPath.Replace(".doc", ".pdf"); try { BP.WF.Glo.Rtf2PDF(rtfPath, pdfPath); } catch (Exception ex) { billInfo = ex.Message; //this.addMsg("RptError", "产生报表数据错误:" + ex.Message); } } #endregion #region 保存单据 Bill bill = new Bill(); bill.MyPK = wk.FID + "_" + wk.OID + "_" + nd.NodeID + "_" + func.No; bill.FID = wk.FID; bill.WorkID = wk.OID; bill.FK_Node = wk.NodeID; bill.FK_Dept = WebUser.FK_Dept; bill.FK_Emp = WebUser.No; bill.Url = billUrl; bill.RDT = DataType.CurrentDataTime; bill.FullPath = path + file; bill.FK_NY = DataType.CurrentYearMonth; bill.FK_Flow = nd.FK_Flow; bill.FK_BillType = func.FK_BillType; bill.Emps = rtf.HisGEEntity.GetValStrByKey("Emps"); bill.FK_Starter = rtf.HisGEEntity.GetValStrByKey("Rec"); bill.StartDT = rtf.HisGEEntity.GetValStrByKey("RDT"); bill.Title = rtf.HisGEEntity.GetValStrByKey("Title"); bill.FK_Dept = rtf.HisGEEntity.GetValStrByKey("FK_Dept"); try { bill.Save(); } catch { bill.Update(); } #endregion } catch (Exception ex) { BP.WF.DTS.InitBillDir dir = new BP.WF.DTS.InitBillDir(); dir.Do(); path = BP.WF.Glo.FlowFileBill + DateTime.Now.Year + "\\" + WebUser.FK_Dept + "\\" + func.No + "\\"; string msgErr = "@" + string.Format("生成单据失败,请让管理员检查目录设置") + "[" + BP.WF.Glo.FlowFileBill + "]。@Err:" + ex.Message + " @File=" + file + " @Path:" + path; billInfo += "@<font color=red>" + msgErr + "</font>"; throw new Exception(msgErr + "@其它信息:" + ex.Message); } this.Pub1.AddFieldSet("打印单据"); this.Pub1.AddUL(); this.Pub1.AddLi(billInfo); this.Pub1.AddULEnd(); this.Pub1.AddFieldSetEnd(); return; }