/// <summary> /// /// </summary> /// <param name="cfile"></param> /// <param name="path"></param> /// <param name="file"></param> /// <param name="isOpen"></param> public void MakeDoc002_del(string cfile, string path, string file, bool isOpen) { string str = Cash.GetBillStr(cfile, false); this.TempFilePath = path + file; try { string key = ""; #region 主表 char[] chars = str.ToCharArray(); string para = ""; string strs = ""; foreach (Entity en in this.HisEns) { strs += en.ToString(); } //string mainEnName=this.hisen foreach (char c in chars) { if (c == '>') { if (strs.IndexOf("." + para.Substring(0, para.IndexOf('.'))) == -1) { if (para.IndexOf("C.") == -1) { continue; } } try { /* 读到了最后,就开始执行替换 */ str = str.Replace("<" + para + ">", this.GetCode(this.GetValueByKey(para))); } catch (Exception ex) { throw new Exception("取参数[" + para + "]出现错误:有以下情况导致此错误;1你用Text取值时间,此属性不是外键。2,类无此属性。<br>更详细的信息:<br>" + ex.Message); } } if (c == '<') { para = ""; // 如果遇到了 '<' 开始记录 } else { if (c.ToString() == "") { continue; } para += c.ToString(); } } #endregion #region 从表 string shortName = ""; ArrayList al = this.EnsDataDtls; foreach (Entities dtls in al) { shortName = dtls.GetNewEntity.ToString().Substring(dtls.GetNewEntity.ToString().LastIndexOf(".") + 1); if (str.IndexOf(shortName) == -1) { continue; } int pos_rowKey = str.IndexOf(shortName); int row_start = -1, row_end = -1; if (pos_rowKey != -1) { row_start = str.Substring(0, pos_rowKey).LastIndexOf("\\row"); row_end = str.Substring(pos_rowKey).IndexOf("\\row"); } if (row_start != -1 && row_end != -1) { string row = str.Substring(row_start, (pos_rowKey - row_start) + row_end); str = str.Replace(row, ""); Map map = dtls.GetNewEntity.EnMap; int i = dtls.Count; while (i > 0) { i--; string rowData = row.Clone() as string; Entity dtl = dtls[i]; foreach (Attr attr in map.Attrs) { switch (attr.MyDataType) { case DataType.AppDouble: case DataType.AppFloat: case DataType.AppRate: rowData = rowData.Replace("<" + shortName + "." + attr.Key + ">", dtl.GetValStringByKey(attr.Key)); break; case DataType.AppMoney: rowData = rowData.Replace("<" + shortName + "." + attr.Key + ">", dtl.GetValDecimalByKey(attr.Key).ToString("0.00")); break; case DataType.AppInt: rowData = rowData.Replace("<" + shortName + "." + attr.Key + ">", dtl.GetValStringByKey(attr.Key)); break; default: rowData = rowData.Replace("<" + shortName + "." + attr.Key + ">", GetCode(dtl.GetValStringByKey(attr.Key))); break; } } str = str.Insert(row_start, rowData); } } } #endregion 从表 #region 明细 合计信息。 al = this.EnsDataDtls; foreach (Entities dtls in al) { shortName = dtls.ToString().Substring(dtls.ToString().LastIndexOf(".") + 1); Map map = dtls.GetNewEntity.EnMap; foreach (Attr attr in map.Attrs) { switch (attr.MyDataType) { case DataType.AppDouble: case DataType.AppFloat: case DataType.AppMoney: case DataType.AppRate: key = "<" + shortName + "." + attr.Key + ".SUM>"; if (str.IndexOf(key) != -1) { str = str.Replace(key, dtls.GetSumFloatByKey(attr.Key).ToString()); } key = "<" + shortName + "." + attr.Key + ".SUM.RMB>"; if (str.IndexOf(key) != -1) { str = str.Replace(key, dtls.GetSumFloatByKey(attr.Key).ToString("0.00")); } key = "<" + shortName + "." + attr.Key + ".SUM.RMBDX>"; if (str.IndexOf(key) != -1) { str = str.Replace(key, GetCode(DA.DataType.ParseFloatToCash(dtls.GetSumFloatByKey(attr.Key)))); } break; case DataType.AppInt: key = "<" + shortName + "." + attr.Key + ".SUM>"; if (str.IndexOf(key) != -1) { str = str.Replace(key, dtls.GetSumIntByKey(attr.Key).ToString()); } break; default: break; } } } #endregion 从表合计 StreamWriter wr = new StreamWriter(this.TempFilePath, false, Encoding.ASCII); wr.Write(str); wr.Close(); } catch (Exception ex) { throw new Exception("生成文档失败:单据名称[" + this.CyclostyleFilePath + "] 异常信息:" + ex.Message); } if (isOpen) { PubClass.Print(System.Web.HttpContext.Current.Request.ApplicationPath + "Temp/" + file); } }
/// <summary> /// 单据生成 /// </summary> /// <param name="cfile">模板文件</param> /// <param name="path">生成路径</param> /// <param name="file">生成文件</param> /// <param name="isOpen">是否用IE打开?</param> public void MakeDoc(string cfile, string path, string file, string replaceVals, bool isOpen) { string str = Cash.GetBillStr(cfile, false).Substring(0); if (this.HisEns.Count == 0) { if (this.HisGEEntity == null) { throw new Exception("@您没有为报表设置数据源..."); } } this.ensStrs = ""; if (this.HisEns.Count != 0) { foreach (Entity en in this.HisEns) { ensStrs += en.ToString(); } } else { ensStrs = this.HisGEEntity.ToString(); } string error = ""; string[] paras = null; if (this.HisGEEntity != null) { paras = Cash.GetBillParas(cfile, ensStrs, this.HisGEEntity); } else { paras = Cash.GetBillParas(cfile, ensStrs, this.HisEns); } this.TempFilePath = path + file; try { string key = ""; string ss = ""; #region 替换主表标记 foreach (string para in paras) { if (para == null || para == "") { continue; } try { if (para.Contains("ImgAth")) { str = str.Replace("<" + para + ">", this.GetValueByKey(para)); } else if (para.Contains("Siganture")) { str = str.Replace("<" + para + ">", this.GetValueByKey(para)); } else if (para.Contains("Img@AppPath")) { str = str.Replace("<" + para + ">", this.GetValueImgStrs(para)); } else if (para.Contains(".BPPaint")) { str = str.Replace("<" + para + ">", this.GetValueBPPaintStrs(para)); } else if (para.Contains(".M2M")) { str = str.Replace("<" + para + ">", this.GetValueM2MStrs(para)); } else if (para.Contains(".RMB")) { str = str.Replace("<" + para + ">", this.GetValueByKey(para)); } else if (para.Contains(".RMBDX")) { str = str.Replace("<" + para + ">", this.GetValueByKey(para)); } else if (para.Contains(".Boolen")) { str = str.Replace("<" + para + ">", this.GetValueByKey(para)); } else if (para.Contains(".BoolenText")) { str = str.Replace("<" + para + ">", this.GetValueByKey(para)); } else if (para.Contains(".NYR")) { str = str.Replace("<" + para + ">", this.GetCode(this.GetValueByKey(para))); } else if (para.Contains(".Yes") == true) { str = str.Replace("<" + para + ">", this.GetCode(this.GetValueByKey(para))); } else if (para.Contains(".") == true) { continue; /*有可能是明细表数据.*/ } else { str = str.Replace("<" + para + ">", this.GetCode(this.GetValueByKey(para))); } } catch (Exception ex) { error += "替换主表标记取参数[" + para + "]出现错误:有以下情况导致此错误;1你用Text取值时间,此属性不是外键。2,类无此属性。3,该字段是明细表字段但是丢失了明细表标记.<br>更详细的信息:<br>" + ex.Message; if (SystemConfig.IsDebug) { throw new Exception(error); } Log.DebugWriteError(error); } } #endregion 替换主表标记 #region 从表 string shortName = ""; ArrayList al = this.EnsDataDtls; foreach (Entities dtls in al) { Entity dtl = dtls.GetNewEntity; string dtlEnName = dtl.ToString(); shortName = dtlEnName.Substring(dtlEnName.LastIndexOf(".") + 1); if (str.IndexOf(shortName) == -1) { continue; } int pos_rowKey = str.IndexOf(shortName); int row_start = -1, row_end = -1; if (pos_rowKey != -1) { row_start = str.Substring(0, pos_rowKey).LastIndexOf("\\row"); row_end = str.Substring(pos_rowKey).IndexOf("\\row"); } if (row_start != -1 && row_end != -1) { string row = str.Substring(row_start, (pos_rowKey - row_start) + row_end); str = str.Replace(row, ""); Map map = dtls.GetNewEntity.EnMap; int i = dtls.Count; while (i > 0) { i--; string rowData = row.Clone() as string; dtl = dtls[i]; //替换序号 int rowIdx = i + 1; rowData = rowData.Replace("<IDX>", rowIdx.ToString()); foreach (Attr attr in map.Attrs) { switch (attr.MyDataType) { case DataType.AppDouble: case DataType.AppFloat: case DataType.AppRate: rowData = rowData.Replace("<" + shortName + "." + attr.Key + ">", dtl.GetValStringByKey(attr.Key)); break; case DataType.AppMoney: rowData = rowData.Replace("<" + shortName + "." + attr.Key + ">", dtl.GetValDecimalByKey(attr.Key).ToString("0.00")); break; case DataType.AppInt: if (attr.MyDataType == DataType.AppBoolean) { rowData = rowData.Replace("<" + shortName + "." + attr.Key + ">", dtl.GetValStrByKey(attr.Key)); int v = dtl.GetValIntByKey(attr.Key); if (v == 1) { rowData = rowData.Replace("<" + shortName + "." + attr.Key + "Text>", "是"); } else { rowData = rowData.Replace("<" + shortName + "." + attr.Key + "Text>", "否"); } } else { if (attr.IsEnum) { rowData = rowData.Replace("<" + shortName + "." + attr.Key + "Text>", GetCode(dtl.GetValRefTextByKey(attr.Key))); } else { rowData = rowData.Replace("<" + shortName + "." + attr.Key + ">", dtl.GetValStrByKey(attr.Key)); } } break; default: rowData = rowData.Replace("<" + shortName + "." + attr.Key + ">", GetCode(dtl.GetValStrByKey(attr.Key))); break; } } str = str.Insert(row_start, rowData); } } } #endregion 从表 #region 明细 合计信息。 al = this.EnsDataDtls; foreach (Entities dtls in al) { Entity dtl = dtls.GetNewEntity; string dtlEnName = dtl.ToString(); shortName = dtlEnName.Substring(dtlEnName.LastIndexOf(".") + 1); //shortName = dtls.ToString().Substring(dtls.ToString().LastIndexOf(".") + 1); Map map = dtl.EnMap; foreach (Attr attr in map.Attrs) { switch (attr.MyDataType) { case DataType.AppDouble: case DataType.AppFloat: case DataType.AppMoney: case DataType.AppRate: key = "<" + shortName + "." + attr.Key + ".SUM>"; if (str.IndexOf(key) != -1) { str = str.Replace(key, dtls.GetSumFloatByKey(attr.Key).ToString()); } key = "<" + shortName + "." + attr.Key + ".SUM.RMB>"; if (str.IndexOf(key) != -1) { str = str.Replace(key, dtls.GetSumFloatByKey(attr.Key).ToString("0.00")); } key = "<" + shortName + "." + attr.Key + ".SUM.RMBDX>"; if (str.IndexOf(key) != -1) { str = str.Replace(key, GetCode(DA.DataType.ParseFloatToCash(dtls.GetSumFloatByKey(attr.Key)))); } break; case DataType.AppInt: key = "<" + shortName + "." + attr.Key + ".SUM>"; if (str.IndexOf(key) != -1) { str = str.Replace(key, dtls.GetSumIntByKey(attr.Key).ToString()); } break; default: break; } } } #endregion 从表合计 #region 要替换的字段 if (replaceVals != null && replaceVals.Contains("@")) { string[] vals = replaceVals.Split('@'); foreach (string val in vals) { if (val == null || val == "") { continue; } if (val.Contains("=") == false) { continue; } string myRep = val.Clone() as string; myRep = myRep.Trim(); myRep = myRep.Replace("null", ""); string[] myvals = myRep.Split('='); str = str.Replace("<" + myvals[0] + ">", "<" + myvals[1] + ">"); } } #endregion StreamWriter wr = new StreamWriter(this.TempFilePath, false, Encoding.ASCII); str = str.Replace("<", ""); str = str.Replace(">", ""); wr.Write(str); wr.Close(); } catch (Exception ex) { string msg = ""; if (SystemConfig.IsDebug) { // 异常可能与单据的配置有关系。 try { this.CyclostyleFilePath = SystemConfig.PathOfDataUser + "\\CyclostyleFile\\" + cfile; str = Cash.GetBillStr(cfile, false); string s = RepBill.RepairBill(this.CyclostyleFilePath); msg = "@已经成功的执行修复线 RepairLineV2,您重新发送一次或者,退后重新在发送一次,是否可以解决此问题。@" + s; } catch (Exception ex1) { msg = "执行修复线失败. RepairLineV2 " + ex1.Message; } } throw new Exception("生成文档失败:单据名称[" + this.CyclostyleFilePath + "] 异常信息:" + ex.Message + " @自动修复单据信息:" + msg); } if (isOpen) { PubClass.Print(BP.Sys.Glo.Request.ApplicationPath + "Temp/" + file); } }
/// <summary> /// 生成单据根据 /// </summary> /// <param name="templeteFile">模板文件</param> /// <param name="saveToFile"></param> /// <param name="mainDT"></param> /// <param name="dtls"></param> public void MakeDoc(string templeteFile, string saveToFile, DataTable mainDT, DataSet dtlsDS) { this.mainDT = mainDT; this.dtlsDS = dtlsDS; #region 生成参数。 string str = Cash.GetBillStr(templeteFile, false).Substring(0); string error = ""; string[] paras = null; DataSet dsTemp = new DataSet(); dsTemp.Tables.Add(mainDT); foreach (DataTable dttemp in dsTemp.Tables) { dsTemp.Tables.Add(dttemp); } Attrs attrs = new Attrs(); foreach (DataTable dt in dsTemp.Tables) { foreach (DataColumn dc in dt.Columns) { Attr attr = new Attr(); attr.Field = dc.ColumnName; attr.Key = dc.ColumnName; switch (dc.DataType.ToString()) { case "int": attr.MyDataType = DataType.AppInt; break; case "decimal": case "float": attr.MyDataType = DataType.AppFloat; break; case "string": default: attr.MyDataType = DataType.AppString; break; } } } paras = Cash.GetBillParas_Gener(templeteFile, attrs); #endregion try { string key = ""; string ss = ""; #region 主表 foreach (string para in paras) { if (para == null || para == "") { continue; } try { if (para.Contains("ImgAth")) { str = str.Replace("<" + para + ">", this.GetValueByKey(para)); } else if (para.Contains("Siganture")) { str = str.Replace("<" + para + ">", this.GetValueByKey(para)); } else if (para.Contains("Img@AppPath")) { str = str.Replace("<" + para + ">", this.GetValueImgStrs(para)); } else if (para.Contains(".BPPaint")) { str = str.Replace("<" + para + ">", this.GetValueBPPaintStrs(para)); } else if (para.Contains(".M2M")) { str = str.Replace("<" + para + ">", this.GetValueM2MStrs(para)); } else { str = str.Replace("<" + para + ">", this.GetCode(this.GetValueByKey(para))); } } catch (Exception ex) { error += "取参数[" + para + "]出现错误:有以下情况导致此错误;1你用Text取值时间,此属性不是外键。2,类无此属性。<br>更详细的信息:<br>" + ex.Message; if (SystemConfig.IsDebug) { throw new Exception(error); } Log.DebugWriteError(error); } } #endregion #region 从表 string shortName = ""; ArrayList al = this.EnsDataDtls; foreach (Entities dtls in al) { // shortName = dtls.GetNewEntity.ToString().Substring(dtls.GetNewEntity.ToString().LastIndexOf(".") + 1); Entity dtl = dtls.GetNewEntity; string dtlEnName = dtl.ToString(); shortName = dtlEnName.Substring(dtlEnName.LastIndexOf(".") + 1); if (str.IndexOf(shortName) == -1) { continue; } int pos_rowKey = str.IndexOf(shortName); int row_start = -1, row_end = -1; if (pos_rowKey != -1) { row_start = str.Substring(0, pos_rowKey).LastIndexOf("\\row"); row_end = str.Substring(pos_rowKey).IndexOf("\\row"); } if (row_start != -1 && row_end != -1) { string row = str.Substring(row_start, (pos_rowKey - row_start) + row_end); str = str.Replace(row, ""); Map map = dtls.GetNewEntity.EnMap; int i = dtls.Count; while (i > 0) { i--; string rowData = row.Clone() as string; dtl = dtls[i]; foreach (Attr attr in map.Attrs) { switch (attr.MyDataType) { case DataType.AppDouble: case DataType.AppFloat: case DataType.AppRate: rowData = rowData.Replace("<" + shortName + "." + attr.Key + ">", dtl.GetValStringByKey(attr.Key)); break; case DataType.AppMoney: rowData = rowData.Replace("<" + shortName + "." + attr.Key + ">", dtl.GetValDecimalByKey(attr.Key).ToString("0.00")); break; case DataType.AppInt: if (attr.MyDataType == DataType.AppBoolean) { rowData = rowData.Replace("<" + shortName + "." + attr.Key + ">", dtl.GetValStrByKey(attr.Key)); int v = dtl.GetValIntByKey(attr.Key); if (v == 1) { rowData = rowData.Replace("<" + shortName + "." + attr.Key + "Text>", "是"); } else { rowData = rowData.Replace("<" + shortName + "." + attr.Key + "Text>", "否"); } } else { rowData = rowData.Replace("<" + shortName + "." + attr.Key + ">", dtl.GetValStrByKey(attr.Key)); } break; default: rowData = rowData.Replace("<" + shortName + "." + attr.Key + ">", GetCode(dtl.GetValStrByKey(attr.Key))); break; } } str = str.Insert(row_start, rowData); } } } #endregion 从表 #region 明细 合计信息。 al = this.EnsDataDtls; foreach (Entities dtls in al) { Entity dtl = dtls.GetNewEntity; string dtlEnName = dtl.ToString(); shortName = dtlEnName.Substring(dtlEnName.LastIndexOf(".") + 1); //shortName = dtls.ToString().Substring(dtls.ToString().LastIndexOf(".") + 1); Map map = dtl.EnMap; foreach (Attr attr in map.Attrs) { switch (attr.MyDataType) { case DataType.AppDouble: case DataType.AppFloat: case DataType.AppMoney: case DataType.AppRate: key = "<" + shortName + "." + attr.Key + ".SUM>"; if (str.IndexOf(key) != -1) { str = str.Replace(key, dtls.GetSumFloatByKey(attr.Key).ToString()); } key = "<" + shortName + "." + attr.Key + ".SUM.RMB>"; if (str.IndexOf(key) != -1) { str = str.Replace(key, dtls.GetSumFloatByKey(attr.Key).ToString("0.00")); } key = "<" + shortName + "." + attr.Key + ".SUM.RMBDX>"; if (str.IndexOf(key) != -1) { str = str.Replace(key, GetCode(DA.DataType.ParseFloatToCash(dtls.GetSumFloatByKey(attr.Key)))); } break; case DataType.AppInt: key = "<" + shortName + "." + attr.Key + ".SUM>"; if (str.IndexOf(key) != -1) { str = str.Replace(key, dtls.GetSumIntByKey(attr.Key).ToString()); } break; default: break; } } } #endregion 从表合计 StreamWriter wr = new StreamWriter(this.TempFilePath, false, Encoding.ASCII); str = str.Replace("<", ""); str = str.Replace(">", ""); wr.Write(str); wr.Close(); } catch (Exception ex) { string msg = ""; if (SystemConfig.IsDebug) { // 异常可能与单据的配置有关系。 try { this.CyclostyleFilePath = SystemConfig.PathOfDataUser + "\\CyclostyleFile\\" + templeteFile; str = Cash.GetBillStr(templeteFile, false); string s = RepBill.RepairBill(this.CyclostyleFilePath); msg = "@已经成功的执行修复线 RepairLineV2,您重新发送一次或者,退后重新在发送一次,是否可以解决此问题。@" + s; } catch (Exception ex1) { msg = "执行修复线失败. RepairLineV2 " + ex1.Message; } } throw new Exception("生成文档失败:单据名称[" + this.CyclostyleFilePath + "] 异常信息:" + ex.Message + " @自动修复单据信息:" + msg); } }