/// <summary> /// 改写BasePage起点定位单元规则,不继承父类规则 /// </summary> /// <param name="e"></param> override protected void OnInit(EventArgs e) { // // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。 // if (Session["userid"] == null) { this.Response.Write("<script language=\"javascript\">"); this.Response.Write("alert('您未正常登录,请登录后再使用,谢谢!')"); this.Response.Write("</script>"); this.Response.Redirect("default.htm"); } this.PgInitRequestParams(); this.PgUnitName = BuildParamList.getValue(this.PgParamXmlDoc, "UnitName"); UnitItem parentUnit = new UnitItem(DataAccRes.AppSettings("WorkConfig"), this.PgUnitName); AppendItem appendItem = parentUnit.GetAppendItem( BuildParamList.getValue(this.PgParamXmlDoc,"AppendItem")); if (null != appendItem && (null == appendItem.UnitName || "" == appendItem.UnitName.Trim())) { this.PgUnitItem = new UnitItem(); WorkItem workitem = new WorkItem(); this.PgUnitItem.UnitName = appendItem.ItemName; this.PgUnitItem.DataSrcFile = parentUnit.DataSrcFile; this.PgUnitItem.DictColSrcFile = parentUnit.DictColSrcFile; workitem.ItemName = appendItem.ItemName; workitem.DataSrc = appendItem.DataSrc; workitem.ItemType = WorkItemType.MasterData; workitem.AliasList = new System.Collections.Specialized.NameValueCollection(); workitem.DictCol = new DictColumn[0]; workitem.Validities = new Validity[0]; this.PgUnitItem.WorkItemList = new WorkItem[1]; this.PgUnitItem.WorkItemList[0] = workitem; string strXmlItem = "<Item name='{0}' relation='D' linkcol='' dataitem='{1}'/>"; strXmlItem = string.Format(strXmlItem, workitem.ItemName, workitem.DataSrc); this.PgUnitItem.UnitNode.InnerXml = strXmlItem; } else if (null != appendItem) { this.PgUnitItem = new UnitItem(DataAccRes.AppSettings("WorkConfig"), appendItem.UnitName); this.PgUnitName = appendItem.UnitName; BuildParamList.setValue(this.PgParamXmlDoc, ParamRangeType.Page, ParamUseType.Data, "UnitName", appendItem.UnitName); } else if (null == appendItem) { this.PgUnitItem = parentUnit; this.PgUnitName = parentUnit.UnitName; } this.PgQuery = new QueryDataRes(this.PgUnitItem.DataSrcFile); this.PgDictQuery = new QueryDataRes(this.PgUnitItem.DictColSrcFile); this.PgWorkItemList = this.PgUnitItem.WorkItemList; this.PgUserRight = new Estar.Business.UserRight.User(this.Session["userid"].ToString()); //动态创建控件 this.PgWfInit(e); InitializeComponent(); //base.OnInit(e); }
/// <summary> /// 设计器支持所需的方法 - 不要使用代码编辑器 /// 修改此方法的内容。 /// </summary> private void InitializeComponent() { BasePage page = this.Page as BasePage; //表格行集合的key要与数据源的绑定DataTable名称一致 this._workItem = page.PgGetWorkItem(this.CtrlItemName); //Grid行更新的关联事件 this.Load += new EventHandler(GridLand_Load); this.PreRender += new EventHandler(GridLand_PreRender); //this.ltbCmd.SelectedIndexChanged += new EventHandler(ltbCmd_Command); }
/// <summary> /// 打印函数说明 /// 设置说明:<明细>起始行,起始列,字段数量,分页数 /// </summary> /// <param name="SourceFile">打印模板文件</param> /// <param name="destFile">结果存贮文件,暂无用</param> /// <param name="oData">打印数据明细表 DataTable</param> /// <param name="MData">主表 DataTable</param> /// <param name="mcurrow">主表当前行</param> /// <param name="userid">用户ID</param> /// <param name="paramlist">打印参数集</param> /// 修改:<明细>改为@dataitem name,每个记录改为@dataitem name.字段,包括合计项 /// 对应修改:传入项为: /// 1 计算最多页数:分析所有DATAITEM项,根据定义的每页数量和记录总数计算出需要的总页面数,maxpage /// 2 开始循环,以 ///<returns></returns> public static XmlDocument makeprint(WorkItem masterItem, WorkItem workitem, string SourceFile, string destFile, DataTable oData, DataTable MData, int mcurrow, string userid, NameObjectList paramlist) { //写入Excel的方法: //定义需要参数。<明细>5,2,10,15; string TemplatePath = HttpContext.Current.Server.MapPath(DataAccRes.AppSettings("TpFilePath")); //存放源文件的文件夹路径。 //副本的文件名,不带路径。 string TempFileName = destFile; //初始化XML命名空间 string nsp = "urn:schemas-microsoft-com:office:spreadsheet"; XmlDocument xmldoc=new XmlDocument(); try { xmldoc.Load(TemplatePath+"\\"+SourceFile); } catch { string strMSG = "请关闭正在打开的模板文件"+SourceFile+"!"; System.Web.HttpContext.Current.Response.Write(" <script language=\"javascript\"> "); System.Web.HttpContext.Current.Response.Write("alert('"+ strMSG +"')"); System.Web.HttpContext.Current.Response.Write(" </script> "); return null; } XmlNamespaceManager xmlNsmgl=new XmlNamespaceManager(xmldoc.NameTable); xmlNsmgl.AddNamespace("docpro",nsp); User userRight = null; bool isbad = false; if (string.IsNullOrEmpty(Convert.ToString(paramlist["DWName"]))) userRight = new User(userid, ref isbad); //读出"Cell"节点中的定义值,得到循环数据区位置值 XmlNodeList xmlNodes=xmldoc.DocumentElement.SelectNodes("//docpro:Cell",xmlNsmgl); //取出第一个有值单元格的数据,解读即定参数 string[] arrPos = leofun.getArrayFromString(xmlNodes[0].InnerText,";"); xmlNodes[0].InnerText=""; //得到明细的区域位置值 //修改:<明细>改为@dataitem name string[] arrDetail = masterdatas(arrPos, "<明细>"); int startrow = (arrDetail == null || arrDetail.Length < 1) ? 0 : toInt(arrDetail[0]) - 1; //起始行号 6,2,3,23,5(并列从第5列开始第二次),8(从8列开始第三次); int startcol = (arrDetail == null || arrDetail.Length < 2) ? 0 : toInt(arrDetail[1]); //起始列号 int fldcount = (arrDetail == null || arrDetail.Length < 3) ? 0 : toInt(arrDetail[2]); //字段数量 int prnPageSize = (arrDetail == null || arrDetail.Length < 4) ? 0 : toInt(arrDetail[3]); //每页行数(分页数量) int startcol2 = 0; int startcol3 = 0; int startcol4 = 0; int repeatcols = (arrDetail == null || arrDetail.Length < 3) ? 0 : (arrDetail.Length - 3); if(repeatcols==2) startcol2 = toInt(arrDetail[4]); if (repeatcols == 3) { startcol2 = toInt(arrDetail[4]); startcol3 = toInt(arrDetail[5]); } if (repeatcols == 4) { startcol2 = toInt(arrDetail[4]); startcol3 = toInt(arrDetail[5]); startcol4 = toInt(arrDetail[6]); } //得到模板用到的所有参数 string sparam = ""; if (paramlist != null) { for (int i = 0; i < paramlist.Count; i++) { sparam = sparam + ",&[" + paramlist.AllKeys[i] + "]"; } } string[] arrParams = leofun.getArrayFromString(prnparamlist()+sparam,","); string[] arrMData = masterdatas(arrPos, "<主表>"); int EmptyCol = otherdatas(arrPos, "<空列>"); int PrnType = otherdatas(arrPos, "<方式>"); //新的处理方式:搜索参数,用数据代替 //搜索主表及参数,用实际数据代替 //搜索页合计及合计行,分别复制到模板node,在数据循环至该页最大行数前,算出页合计值,并插入到最后一行,同时,累计总数,插入最后行。 //subsumNode //sumNode XmlNode subsumNode = null; XmlNode subgsumNode = null; XmlNode sumNode = null; XmlNode avgNode = null; for(int i=0;i<xmlNodes.Count;i++) { if(arrParams==null) continue; for(int j=0;j<arrParams.Length;j++) { if(xmlNodes[i].InnerText.IndexOf(arrParams[j])>-1) { string nval = xmlNodes[i].ChildNodes[0].InnerText.Trim(); string strParam = getParam(arrParams[j],userRight,paramlist); nval = nval.Replace(arrParams[j],strParam); xmlNodes[i].ChildNodes[0].InnerText = nval; } } if(MData == null || arrMData==null) continue; if(mcurrow > MData.Rows.Count) mcurrow=0; for(int m=0;m<arrMData.Length;m++) { string strM = arrMData[m]; string strM1 = strM.Replace("[",""); strM1 = strM1.Replace("]",""); if(xmlNodes[i].InnerText.IndexOf(strM)>-1 || xmlNodes[i].InnerText.IndexOf(strM1)>-1) { strM1 = strM1.Replace("#",""); if(MData.Rows[mcurrow][strM1]==null) continue; string valfld = (null == MData.Rows[mcurrow][strM1]) ? "" : MData.Rows[mcurrow][strM1].ToString(); string fieldname = MData.Columns[strM1].DataType.Name; switch (MData.Columns[strM1].DataType.Name) { case "Double": case "Decimal": if (valfld != "") { if (Convert.ToDouble(valfld) == 0) valfld = ""; else valfld = Convert.ToDouble(valfld).ToString("#0.00"); } break; case "DateTime": if (valfld == "") break; valfld = Convert.ToDateTime(valfld).ToString("yyyy-MM-dd"); if (fieldname == "年" || fieldname == "年份") valfld = Convert.ToDateTime(valfld).ToString("yyyy"); if (fieldname.IndexOf("月份") > -1 || fieldname.IndexOf("月度") > -1 || fieldname.IndexOf("年月") > -1) valfld = Convert.ToDateTime(valfld).ToString("yyyy-MM"); break; } string str = xmlNodes[i].ChildNodes[0].InnerText.Replace(arrMData[m],valfld); str = str.Replace("#", ""); xmlNodes[i].ChildNodes[0].InnerText=str; } } } //得到循环区的节点,并替换成实际的数据 XmlNodeList xmlNodesRow=xmldoc.DocumentElement.SelectNodes("//docpro:Row",xmlNsmgl); string strExprgroup=""; for(int i=0;i<xmlNodesRow.Count;i++) { if(xmlNodesRow[i].InnerText.IndexOf("S页合计")>-1 || xmlNodesRow[i].InnerText.IndexOf("S页合计")>-1) subsumNode = xmlNodesRow[i]; if(xmlNodesRow[i].InnerText.IndexOf("S组合计")>-1 || xmlNodesRow[i].InnerText.IndexOf("S组合计")>-1) { subgsumNode = xmlNodesRow[i]; for(int j=0; j<subgsumNode.ChildNodes.Count; j++) { if(subgsumNode.ChildNodes[j].InnerText.IndexOf("S组合计:")>-1) { string[] arrSUMCndition = leofun.getArrayFromString(subgsumNode.ChildNodes[j].InnerText,";"); for(int m=0; m<arrSUMCndition.Length;m++) { if(arrSUMCndition[m].IndexOf("<范围>")>-1) strExprgroup = arrSUMCndition[m].Replace("<范围>",""); } } } } if (xmlNodesRow[i].InnerText.IndexOf("S合计:") > -1 || xmlNodesRow[i].InnerText.IndexOf("S合计:")>-1 || xmlNodesRow[i].InnerText.IndexOf("S合计") > -1) sumNode = xmlNodesRow[i]; else if(xmlNodesRow[i].InnerText.IndexOf("S平均值:")>-1 || xmlNodesRow[i].InnerText.IndexOf("S平均值:")>-1) avgNode = xmlNodesRow[i]; } //获的合计分组条件: strExprgroup = strExprgroup.Replace(" ","").Trim(); strExprgroup = strExprgroup.Replace("[",""); strExprgroup = strExprgroup.Replace("]",""); string[] arrExprgroup = leofun.getArrayFromString(strExprgroup,","); string[] arrExprgroup_field = null; string[] arrExprgroup_val = null; if(arrExprgroup!=null) { arrExprgroup_field = new string[arrExprgroup.Length]; arrExprgroup_val = new string[arrExprgroup.Length]; for(int i=0;i<arrExprgroup.Length;i++) { string[] arr=leofun.getArrayFromString(arrExprgroup[i],"="); arrExprgroup_field[i] = arr[0]; arrExprgroup_val[i] = arr[1]; } } // xmlNodesRow=xmldoc.DocumentElement.SelectNodes("//docpro:Row",xmlNsmgl); if(xmlNodesRow[startrow]==null) { string strMSG = "起始行="+(startrow+1).ToString()+" 引起字段定位错误: !"; System.Web.HttpContext.Current.Response.Write(" <script language=\"javascript\"> "); System.Web.HttpContext.Current.Response.Write("alert('"+ strMSG +"')"); System.Web.HttpContext.Current.Response.Write(" </script> "); return null; } XmlNode rowboot = xmlNodesRow[startrow].ParentNode; string[] arrfld = null; string[] arrsubsumfld = null; string[] arrsubgsumfld = null; string[] arrsumfld = null; string[] arravgfld = null; arrfld = getExcelFields(xmlNodesRow[startrow]); if (subsumNode != null) arrsubsumfld = getExcelFields(subsumNode); if (subgsumNode != null) arrsubgsumfld = getExcelFields(subgsumNode); if (sumNode != null) arrsumfld = getExcelFields(sumNode); if (avgNode != null) arravgfld = getExcelFields(avgNode); //定义分页行 string pagebreakRows=""; //写明细数据,返回插入的辅助行数 int seprow = 0; int xmod=0; int printnum = 0; if(prnPageSize!=0) printnum = (oData == null) ? 0 : oData.Rows.Count + (prnPageSize - ((oData == null) ? 0 : oData.Rows.Count) % prnPageSize); if (repeatcols > 1) printnum = prnPageSize; if(PrnType!=1) { for (int i = 1; i < printnum; i++) { XmlNode baknode = xmlNodesRow[startrow].CloneNode(true); int icurrow = startrow + i + seprow -1 ; rowboot.InsertAfter(baknode,xmlNodesRow[icurrow]); xmod = (i+1) % prnPageSize; if(i == printnum + seprow -1) break; if(xmod==0 && i!=0) { if(subsumNode!=null) { XmlNode xsub = subsumNode.Clone(); rowboot.InsertAfter(xsub,xmlNodesRow[startrow+i+seprow]); seprow=seprow+1; } int pagenum = startrow+seprow + i + 1 ; pagebreakRows = pagebreakRows + ";" + pagenum.ToString(); } } } //建立分页 if(pagebreakRows.Length>0) { pagebreakRows = pagebreakRows.Remove(0,1); creatpagebreak(pagebreakRows,xmldoc); } XmlNodeList xnode = null; //初始化合计数组 double[] sumfld = null; double[] subsumfld = null; double[] avgfld = null; double[] subgsumfld = null; if(arrsumfld!=null) { sumfld = new double[arrsumfld.Length]; for(int i=0;i<arrsumfld.Length;i++) sumfld[i]=0.0; } if(arravgfld!=null) { sumfld = new double[arravgfld.Length]; for(int i=0;i<arravgfld.Length;i++) sumfld[i]=0.0; } if(arrsubsumfld!=null) { subsumfld = new double[arrsubsumfld.Length]; for(int i=0;i<arrsubsumfld.Length;i++) subsumfld[i]=0; } if(arrsubgsumfld!=null) { subgsumfld = new double[arrsubgsumfld.Length]; for(int i=0;i<arrsubgsumfld.Length;i++) subgsumfld[i]=0.0; } string fldname=""; //取最大的数据记录数量 int rowcount=prnPageSize; if(prnPageSize < ((oData==null)?0:oData.Rows.Count)) rowcount=(oData==null)?0:oData.Rows.Count; rowcount = printnum; seprow =0; if (repeatcols > 1) rowcount = prnPageSize; //如果多列打印,则最大循环行数为分页数 for (int ir = 0; ir < repeatcols; ir++) { for (int i = 0; i < rowcount; i++) { //ROW为空时,中断循环 switch (ir) { case 2: EmptyCol = ir * EmptyCol; break; case 3: EmptyCol = ir * EmptyCol; break; case 4: EmptyCol = ir * EmptyCol; break; } int idata = (i + ir * prnPageSize); if (xmlNodesRow[startrow + i + seprow] == null) break; //如果存在页合计 if (xmlNodesRow[startrow + i + seprow].InnerText.IndexOf("S页合计") > -1 || xmlNodesRow[startrow + i + seprow].InnerText.IndexOf("S组合计") > -1) { //写入页合计: if (arrsubsumfld != null) { setsummary(startrow + i + seprow - prnPageSize, startrow + i + seprow, xmlNodesRow, "S页合计", subsumfld, arrsubsumfld, oData); //页合计清0 for (int k = 0; k < arrsubsumfld.Length; k++) subsumfld[k] = 0; } if (arrsubgsumfld != null) { setsummary(startrow + i + seprow - prnPageSize, startrow + i + seprow, xmlNodesRow, "S组合计", subgsumfld, arrsubgsumfld, oData); //组合计清0 for (int k = 0; k < arrsumfld.Length; k++) subgsumfld[k] = 0; } seprow = seprow + 1; //列数 xnode = xmlNodesRow[startrow + i + seprow].ChildNodes; if (fldcount > xnode.Count) fldcount = xnode.Count; for (int j = 0 + ir * fldcount; j < (ir+1) * fldcount - EmptyCol; j++) { fldname = xnode[j + EmptyCol].InnerText.ToString().Trim(); if (fldname == "序号") { xnode[j + EmptyCol].ChildNodes[0].InnerText=(idata + 1).ToString(); fldname = "SN"; } for (int ic = 0; ic < ((oData==null)?0:oData.Columns.Count); ic++) { string strColumnName = oData.Columns[ic].ColumnName; if (fldname == strColumnName) break; else if (ic == oData.Columns.Count - 1) fldname = ""; } if (fldname == "") continue; string valfld = ""; string fm = ""; if (i < rowcount) { valfld = (oData==null || null == oData.Rows[idata][fldname]) ? "" : oData.Rows[idata][fldname].ToString(); switch ((oData==null)?"":oData.Columns[fldname].DataType.Name) { case "Double": case "Decimal": if (valfld != "") { if (workitem != null) { for (int ix = 0; ix < workitem.DictCol.Length; ix++) { if (fldname == workitem.DictCol[ix].ColumnName && workitem.DictCol[ix].Formate != "") { fm = workitem.DictCol[ix].Formate; break; } } } if (fm != "" && fm.IndexOf(".") > -1) { fm = fm.Substring(fm.IndexOf(".") + 1, fm.Length - fm.IndexOf(".") - 1); if (fm.Length > 0) valfld = Convert.ToDouble(valfld).ToString("#0." + fm); else valfld = Convert.ToDouble(valfld).ToString("#0"); } else valfld = Convert.ToDouble(valfld).ToString("#0.00"); if (Convert.ToDouble(valfld) == 0) valfld = ""; } break; case "DateTime": if (valfld == "") break; if (fldname == "年" || fldname == "年份") { valfld = Convert.ToDateTime(valfld).ToString("yyyy"); break; } if (fldname.IndexOf("月份") > -1 || fldname.IndexOf("月度") > -1 || fldname.IndexOf("年月") > -1) { valfld = Convert.ToDateTime(valfld).ToString("yyyy-MM"); break; } if (workitem != null) { for (int ix = 0; ix < workitem.DictCol.Length; ix++) { if (fldname == workitem.DictCol[ix].ColumnName && workitem.DictCol[ix].Formate != "") { fm = workitem.DictCol[ix].Formate; break; } } } if (fm != "") valfld = Convert.ToDateTime(valfld).ToString(fm); //valfld = Convert.ToDateTime(valfld).ToString("yyyy-MM-dd hh:mm:ss"); else valfld = Convert.ToDateTime(valfld).ToString("yyyy-MM-dd"); break; } } if (valfld.Trim().Length == 0) xnode[j + EmptyCol].ChildNodes[0].InnerText = " "; else xnode[j + EmptyCol].ChildNodes[0].InnerText = valfld; if (EmptyCol == 0) { if (xnode[0].ChildNodes[0].InnerText == "序号") xnode[0].ChildNodes[0].InnerText = (i + 1).ToString(); } else if (xnode[EmptyCol - 1].ChildNodes[0] != null) { if (xnode[EmptyCol - 1].ChildNodes[0].InnerText == "序号") xnode[EmptyCol - 1].ChildNodes[0].InnerText = (i + 1).ToString(); } //计算合计 if (i > rowcount) continue; if (arrsumfld != null) { for (int m = 0; m < arrsumfld.Length; m++) { if (fldname != arrsumfld[m]) continue; if (valfld == null || valfld == "") valfld = "0"; sumfld[m] = sumfld[m] + double.Parse(valfld); if (subsumfld != null) subsumfld[m] = subsumfld[m] + double.Parse(valfld); if (subgsumfld != null) { if (oData.Columns["分类"] != null) if (null != oData.Rows[idata]["分类"] && oData.Rows[idata]["分类"].ToString() == "总计") subsumfld[m] = subsumfld[m] + double.Parse(valfld); else subgsumfld[m] = subgsumfld[m] + double.Parse(valfld); } } } else if (arrsubsumfld != null) { for (int m = 0; m < arrsubsumfld.Length; m++) { if (fldname != arrsubsumfld[m]) continue; if (valfld == null || valfld == "") valfld = "0"; sumfld[m] = sumfld[m] + double.Parse(valfld); if (subsumfld != null) subsumfld[m] = subsumfld[m] + double.Parse(valfld); if (subgsumfld != null) { if (oData.Columns["分类"] != null) if (null != oData.Rows[idata]["分类"] && oData.Rows[idata]["分类"].ToString() == "总计") subsumfld[m] = subsumfld[m] + double.Parse(valfld); else subgsumfld[m] = subgsumfld[m] + double.Parse(valfld); } } } } } else { xnode = xmlNodesRow[startrow + i + seprow].ChildNodes; if (fldcount > xnode.Count) fldcount = xnode.Count; for (int j = 0 + ir * fldcount; j < (ir + 1) * fldcount - EmptyCol; j++) { fldname = xnode[j + EmptyCol].InnerText.ToString().Trim(); if (fldname == "序号") { xnode[j + EmptyCol].ChildNodes[0].InnerText = (idata + 1).ToString(); fldname = "SN"; } for (int ic = 0; ic < oData.Columns.Count; ic++) { string strColumnName = oData.Columns[ic].ColumnName; if (fldname == strColumnName) break; else if (ic == oData.Columns.Count - 1) fldname = ""; } if (fldname == "") continue; string valfld = ""; string fm = ""; if (i < rowcount) { if (idata > oData.Rows.Count - 1) valfld = ""; else valfld = (null == oData.Rows[idata][fldname]) ? "" : oData.Rows[idata][fldname].ToString(); switch (oData.Columns[fldname].DataType.Name) { case "Double": case "Decimal": if (valfld != "") { if (workitem != null) { for (int ix = 0; ix < workitem.DictCol.Length; ix++) { if (fldname == workitem.DictCol[ix].ColumnName && workitem.DictCol[ix].Formate != "") { fm = workitem.DictCol[ix].Formate; break; } } } if (fm != "" && fm.IndexOf(".") > -1) { fm = fm.Substring(fm.IndexOf(".") + 1, fm.Length - fm.IndexOf(".") - 1); if (fm.Length > 0) valfld = Convert.ToDouble(valfld).ToString("#0." + fm); else valfld = Convert.ToDouble(valfld).ToString("#0"); } else valfld = Convert.ToDouble(valfld).ToString("#0.00"); if (Convert.ToDouble(valfld) == 0) valfld = ""; } break; case "DateTime": if (valfld == "") break; if (fldname == "年" || fldname == "年份") { valfld = Convert.ToDateTime(valfld).ToString("yyyy"); break; } if (fldname.IndexOf("月份") > -1 || fldname.IndexOf("月度") > -1 || fldname.IndexOf("年月") > -1) { valfld = Convert.ToDateTime(valfld).ToString("yyyy-MM"); break; } if (workitem != null) { for (int ix = 0; ix < workitem.DictCol.Length; ix++) { if (fldname == workitem.DictCol[ix].ColumnName && workitem.DictCol[ix].Formate != "") { fm = workitem.DictCol[ix].Formate; break; } } } if (fm != "") valfld = Convert.ToDateTime(valfld).ToString(fm); //valfld = Convert.ToDateTime(valfld).ToString("yyyy-MM-dd hh:mm:ss"); else valfld = Convert.ToDateTime(valfld).ToString("yyyy-MM-dd"); break; } } if (valfld.Trim().Length == 0) xnode[j + EmptyCol].ChildNodes[0].InnerText = " "; else xnode[j + EmptyCol].ChildNodes[0].InnerText = valfld; if (EmptyCol == 0) { if (xnode[0].ChildNodes[0].InnerText == "序号") xnode[0].ChildNodes[0].InnerText = (i + 1).ToString(); } else if (xnode[EmptyCol - 1].ChildNodes[0] != null) { if (xnode[EmptyCol - 1].ChildNodes[0].InnerText == "序号") xnode[EmptyCol - 1].ChildNodes[0].InnerText = (i + 1).ToString(); } //计算合计 if (i >= rowcount) continue; if (arrsumfld != null) { for (int m = 0; m < arrsumfld.Length; m++) { if (fldname == arrsumfld[m]) { if (valfld == null || valfld == "") valfld = "0"; sumfld[m] = sumfld[m] + double.Parse(valfld); if (subsumfld != null) subsumfld[m] = subsumfld[m] + double.Parse(valfld); if (subgsumfld != null && arrExprgroup_field != null) { if (arrExprgroup_field.Length == 1) if (null != oData.Rows[idata][arrExprgroup_field[0]] && oData.Rows[idata][arrExprgroup_field[0]].ToString() == arrExprgroup_val[0]) subgsumfld[m] = subgsumfld[m] + double.Parse(valfld); if (arrExprgroup_field.Length == 2) if ((null != oData.Rows[idata][arrExprgroup_field[0]] && oData.Rows[idata][arrExprgroup_field[0]].ToString() == arrExprgroup_val[0]) || (null != oData.Rows[idata][arrExprgroup_field[1]] && oData.Rows[idata][arrExprgroup_field[1]].ToString() == arrExprgroup_val[1])) subgsumfld[m] = subgsumfld[m] + double.Parse(valfld); } } } } else if (arravgfld != null) { for (int m = 0; m < arravgfld.Length; m++) { if (fldname == arravgfld[m]) { if (valfld == null || valfld == "") valfld = "0"; sumfld[m] = sumfld[m] + double.Parse(valfld); if (subsumfld != null) subsumfld[m] = subsumfld[m] + double.Parse(valfld); if (subgsumfld != null && arrExprgroup_field != null) { if (arrExprgroup_field.Length == 1) if (null != oData.Rows[idata][arrExprgroup_field[0]] && oData.Rows[idata][arrExprgroup_field[0]].ToString() == arrExprgroup_val[0]) subgsumfld[m] = subgsumfld[m] + double.Parse(valfld); if (arrExprgroup_field.Length == 2) if ((null != oData.Rows[idata][arrExprgroup_field[0]] && oData.Rows[idata][arrExprgroup_field[0]].ToString() == arrExprgroup_val[0]) || (null != oData.Rows[idata][arrExprgroup_field[1]] && oData.Rows[idata][arrExprgroup_field[1]].ToString() == arrExprgroup_val[1])) subgsumfld[m] = subgsumfld[m] + double.Parse(valfld); } } } } } } } } if(subsumfld!=null) { //置入最后一个分页合计 setsummary(startrow + printnum + seprow - 1, xmlNodesRow.Count - 1, xmlNodesRow, "S页合计", subsumfld, arrsubsumfld, oData); } if(subgsumfld!=null) { //置入最后一个分组合计 setsummary(startrow + printnum + seprow - 1, xmlNodesRow.Count - 1, xmlNodesRow, "S组合计", subgsumfld, arrsubgsumfld, oData); } if(sumfld!=null) { //置入合计项 setsummary(startrow + printnum + seprow, xmlNodesRow.Count - 1, xmlNodesRow, "S合计", sumfld, arrsumfld, oData); } if(sumfld!=null) { //置入平均值 setsummary(startrow + printnum + seprow, xmlNodesRow.Count - 1, xmlNodesRow, "S平均值", sumfld, arravgfld, oData); } //得到Table节点的ss:ExpandedRowCount属性,随着循环区行数的增加页增值 if (startrow != 0) { XmlNode xn = xmldoc.DocumentElement.SelectSingleNode("//docpro:Table", xmlNsmgl); xn.Attributes["ss:ExpandedRowCount"].Value = Convert.ToString((Convert.ToInt32(xn.Attributes["ss:ExpandedRowCount"].Value) + printnum + seprow - 1)); } //给<PageSetup>赋值 setpageSetup(xmldoc,userRight,paramlist); //string DownloadFilePath=DownloadPath+"\\"+destFile; //string strpath= "ExcelDownload/"+TempFileName; //outXML2Excel(xmldoc,"print.xls"); return xmldoc; }
/// <summary> /// 对于需要字符宏替换的:分页参数,过滤查询参数,Chart图参数 /// 参数的类型要声明为宏: type="macro"; /// </summary> /// <param name="xmldoc">参数文档</param> /// <returns></returns> private static string[] getStrParams(XmlDocument xmldoc, WorkItem workItem) { string[] strParams ={ "", "", "", "", "", "", "", "", "" }; NameObjectList macroParam = BuildParamList.BuildParamMacro(xmldoc, workItem.ItemName); for (int i = 0; i < macroParam.Count; i++) { string strName = macroParam.Keys[i]; if ("firstrowold" == strName.ToLower()) strParams[1] = macroParam[i].ToString(); if ("firstrow" == strName.ToLower()) strParams[1] = macroParam[i].ToString(); if ("lastrow" == strName.ToLower()) strParams[7] = macroParam[i].ToString(); if ("filterfast" == strName.ToLower()) strParams[2] = macroParam[i].ToString(); if ("filter" == strName.ToLower()) strParams[3] = macroParam[i].ToString(); } if (null != workItem) { strParams[8] = workItem.InitFilter; if ("" != workItem.PageSize) strParams[0] = workItem.PageSize; } if ("" == strParams[0]) strParams[0] = "10"; if ("" == strParams[1]) strParams[1] = "0"; if ("" == strParams[7]) strParams[7] = strParams[0]; string recordcount = BuildParamList.getValue(xmldoc, workItem.ItemName, "RecordCount"); if (string.IsNullOrEmpty(recordcount)) recordcount = BuildParamList.getValue(xmldoc, "RecordCount"); if (!string.IsNullOrEmpty(recordcount)) { strParams[1] = "0"; strParams[7] = strParams[0] = recordcount; } return strParams; }
/// <summary> /// ��ȡҵ��Ԫ����ϸ��Ŀ /// </summary> /// <returns>������ϸ��Ŀ����</returns> private WorkItem[] GetWorkItemList() { if (null == this._xmlnode) return (new WorkItem[0]); XmlNodeList itemlist = this._xmlnode.SelectNodes("Item"); WorkItem[] workItemList = new WorkItem[itemlist.Count]; for (int i = 0; i < itemlist.Count; i++) { WorkItem item = new WorkItem(); item.ItemName = itemlist[i].Attributes["name"].Value; workItemList[i] = item; if (null != itemlist[i].Attributes["alias"] && "" != itemlist[i].Attributes["alias"].Value) { string[] aliasList = itemlist[i].Attributes["alias"].Value.Split(";".ToCharArray()); for (int ialias = 0; ialias < aliasList.Length; ialias++) if ("" != aliasList[ialias] && null != aliasList[ialias]) item.AliasList[aliasList[ialias]] = aliasList[ialias]; } #region ��ϵ���� string strRlt = ""; if (null == itemlist[i].Attributes["relation"] || "" == itemlist[i].Attributes["relation"].Value) strRlt = "G"; else strRlt = itemlist[i].Attributes["relation"].Value.ToUpper(); switch (strRlt) { case "M": item.ItemType = WorkItemType.MasterData; if (null != this._xmlnode.Attributes["billtype"]) item.BillType = this._xmlnode.Attributes["billtype"].Value; break; case "D": item.ItemType = WorkItemType.DetailData; break; case "G": item.ItemType = WorkItemType.GeneralData; break; default: throw (new Exception("��ϸ��Ŀ������������" + this.UnitName)); } #endregion #region ��ӡ���� string strPrintType = ""; if (null != itemlist[i].Attributes["printtype"]) strPrintType = itemlist[i].Attributes["printtype"].Value.ToUpper(); switch (strPrintType) { case "WORD": item.PrintType = PrintType.Word; break; case "EXCEL": item.PrintType = PrintType.Excel; break; case "HTML": item.PrintType = PrintType.HTML; break; default: item.PrintType = PrintType.HTML; break; } if (null != itemlist[i].Attributes["printitem"]) item.printitem = itemlist[i].Attributes["printitem"].Value; if (null != itemlist[i].Attributes["printname"]) item.printname = itemlist[i].Attributes["printname"].Value; if (null != itemlist[i].Attributes["printcount"] && null != itemlist[i].Attributes["printcount"].Value) item.printcountmin = itemlist[i].Attributes["printcount"].Value; if (itemlist[i].Attributes["print"] != null && itemlist[i].Attributes["print"].Value.ToLower() == "true") item.print = true; else item.print = false; #endregion #region Chartͼ������ string strCharType = ""; if (null != itemlist[i].Attributes["charttype"]) strCharType = itemlist[i].Attributes["charttype"].Value.ToLower(); if (itemlist[i].Attributes["chartleft"] != null) item.ChartTitleLeft = itemlist[i].Attributes["chartleft"].Value; if (itemlist[i].Attributes["chartbottom"] != null) item.ChartTitleBottom = itemlist[i].Attributes["chartbottom"].Value; if (itemlist[i].Attributes["charttop"] != null) item.ChartTitleTop = itemlist[i].Attributes["charttop"].Value; if (itemlist[i].Attributes["chartvaluetype"] != null) item.ChartValueType = itemlist[i].Attributes["chartvaluetype"].Value; #endregion if (null != itemlist[i].Attributes["extentx"] && null != itemlist[i].Attributes["extentx"].Value && "" != itemlist[i].Attributes["extentx"].Value) try { item.ExtentX = int.Parse(itemlist[i].Attributes["extentx"].Value); } catch { } if (null != itemlist[i].Attributes["extenty"] && null != itemlist[i].Attributes["extenty"].Value && "" != itemlist[i].Attributes["extenty"].Value) try { item.ExtentY = int.Parse(itemlist[i].Attributes["extenty"].Value); } catch { } #region ������Ŀ����Դ���� if (null != itemlist[i].Attributes["dataitem"]) item.DataSrc = itemlist[i].Attributes["dataitem"].Value; if (itemlist[i].Attributes["dataitempage"] != null) item.DataSrcPage = itemlist[i].Attributes["dataitempage"].Value; if (itemlist[i].Attributes["countdataitem"] != null) item.CountDataSrc = itemlist[i].Attributes["countdataitem"].Value; if (null != itemlist[i].Attributes["linkcol"]) item.LinkCol = itemlist[i].Attributes["linkcol"].Value; if (null != itemlist[i].Attributes["columnkey"]) item.ColumnKey = itemlist[i].Attributes["columnkey"].Value; if (null != itemlist[i].Attributes["gridtemplate"]) item.TemplateEdit = itemlist[i].Attributes["gridtemplate"].Value; if (null != itemlist[i].Attributes["headtemplate"]) item.TemplateHead = itemlist[i].Attributes["headtemplate"].Value; if (null != itemlist[i].Attributes["headheight"]) item.HeadHeight = itemlist[i].Attributes["headheight"].Value; if (null != itemlist[i].Attributes["pagesize"]) item.PageSize = itemlist[i].Attributes["pagesize"].Value; if (null != itemlist[i].Attributes["group"]) item.Group = itemlist[i].Attributes["group"].Value; if (null != itemlist[i].Attributes["sumcol"]) item.SumCol = itemlist[i].Attributes["sumcol"].Value; if (null != itemlist[i].Attributes["where"]) item.Where = itemlist[i].Attributes["where"].Value; if (null != itemlist[i].Attributes["filter"]) item.InitFilter = itemlist[i].Attributes["filter"].Value; if (null != itemlist[i].Attributes["idfld"]) item.IDField = itemlist[i].Attributes["idfld"].Value; if (null != itemlist[i].Attributes["pidfld"]) item.PIDField = itemlist[i].Attributes["pidfld"].Value; if (null != itemlist[i].Attributes["txtfld"]) item.TxtField = itemlist[i].Attributes["txtfld"].Value; if (null != itemlist[i].Attributes["namefld"]) item.NameField = itemlist[i].Attributes["namefld"].Value; if (null != itemlist[i].Attributes["selfid"]) item.SIDField = itemlist[i].Attributes["selfid"].Value; if (null != itemlist[i].Attributes["keyfid"]) item.KEYField = itemlist[i].Attributes["keyfid"].Value; if (null != itemlist[i].Attributes["valuefld"]) item.ValueField = itemlist[i].Attributes["valuefld"].Value; if (null != itemlist[i].Attributes["typefld"]) item.TypeField = itemlist[i].Attributes["typefld"].Value; if (null != itemlist[i].Attributes["orderfld"]) item.OrderField = itemlist[i].Attributes["orderfld"].Value; if (null != itemlist[i].Attributes["ntag"]) item.Ntag = itemlist[i].Attributes["ntag"].Value; if (itemlist[i].Attributes["noexpand"] != null && itemlist[i].Attributes["noexpand"].Value.ToLower() == "true") item.NoExpand = true; if (itemlist[i].Attributes["import"] != null && itemlist[i].Attributes["import"].Value == "1") item.IsImport = true; if (itemlist[i].Attributes["manualrefresh"] != null && itemlist[i].Attributes["manualrefresh"].Value.ToLower() == "true") item.ManualRefresh = true; if (null != itemlist[i].Attributes["tpid"]) item.TempId = itemlist[i].Attributes["tpid"].Value; #endregion #region ��ͼ���������� if (null != itemlist[i].Attributes["barstep"] && "" != itemlist[i].Attributes["barstep"].Value) try { item.BarStep = int.Parse(itemlist[i].Attributes["barstep"].Value); } catch { } if (null != itemlist[i].Attributes["baroffsetx"] && "" != itemlist[i].Attributes["baroffsetx"].Value) try { item.BarOffsetX = int.Parse(itemlist[i].Attributes["baroffsetx"].Value); } catch { } if (null != itemlist[i].Attributes["baroffsety"] && "" != itemlist[i].Attributes["baroffsety"].Value) try { item.BarOffsetY = int.Parse(itemlist[i].Attributes["baroffsety"].Value); } catch { } #endregion XmlNodeList colnodeList = itemlist[i].SelectNodes("Column"); item.DictCol = new DictColumn[colnodeList.Count]; for (int j = 0; j < colnodeList.Count; j++) { item.DictCol[j] = new DictColumn(); #region �ֵ�������Դ item.DictCol[j].ColumnName = colnodeList[j].Attributes["name"].Value; item.DictCol[j].Title = item.DictCol[j].ColumnName; if (null != colnodeList[j].Attributes["dataitem"] && null != colnodeList[j].Attributes["textcol"] && null != colnodeList[j].Attributes["valuecol"]) { item.DictCol[j].DataSrc = colnodeList[j].Attributes["dataitem"].Value; item.DictCol[j].TextCol = colnodeList[j].Attributes["textcol"].Value; item.DictCol[j].ValueCol = colnodeList[j].Attributes["valuecol"].Value; } if (null != colnodeList[j].Attributes["filteritem"] && null != colnodeList[j].Attributes["filterdata"]) item.DictCol[j].FilterItem = colnodeList[j].Attributes["filteritem"].Value; if (null != colnodeList[j].Attributes["filterdata"]) item.DictCol[j].FilterData = colnodeList[j].Attributes["filterdata"].Value; if (null != colnodeList[j].Attributes["title"] && !string.IsNullOrEmpty(colnodeList[j].Attributes["title"].Value)) item.DictCol[j].Title = colnodeList[j].Attributes["title"].Value; #endregion #region �м���,У��,�༭,��ʽ,�������� //������,���Ƿ����,�еĵ�Ԫ����֤ if (null != colnodeList[j].Attributes["expression"]) item.DictCol[j].Expression = colnodeList[j].Attributes["expression"].Value; if (null != colnodeList[j].Attributes["redword"]) item.DictCol[j].RedWord = colnodeList[j].Attributes["redword"].Value; if (null != colnodeList[j].Attributes["bhrule"]) item.DictCol[j].BHRule = colnodeList[j].Attributes["bhrule"].Value; if (null != colnodeList[j].Attributes["zeroflag"]) item.DictCol[j].ZeroFlag = colnodeList[j].Attributes["zeroflag"].Value; if (null != colnodeList[j].Attributes["validity"]) item.DictCol[j].ValidateCell = colnodeList[j].Attributes["validity"].Value; if (null != colnodeList[j].Attributes["calcol"] && "1" == colnodeList[j].Attributes["calcol"].Value) item.DictCol[j].CalType = CalculateType.Dynamic; else item.DictCol[j].CalType = CalculateType.Init; if (null != colnodeList[j].Attributes["fcalcol"] && "1" == colnodeList[j].Attributes["fcalcol"].Value) item.DictCol[j].FCalType = FCalculateType.Dynamic; else item.DictCol[j].FCalType = FCalculateType.Init; if (null != colnodeList[j].Attributes["width"]) item.DictCol[j].Width = int.Parse(colnodeList[j].Attributes["width"].Value); if (null != colnodeList[j].Attributes["height"]) item.DictCol[j].Height = int.Parse(colnodeList[j].Attributes["height"].Value); //��ע if (null != colnodeList[j].Attributes["footer"]) item.DictCol[j].Footer = colnodeList[j].Attributes["footer"].Value; // 0 - ����������, 1- ��ʾ����Ϊ�� if (null != colnodeList[j].Attributes["chkcol"] && "1" == colnodeList[j].Attributes["chkcol"].Value) item.DictCol[j].IsNeed = true; else item.DictCol[j].IsNeed = false; if (null != colnodeList[j].Attributes["merge"] && "1" == colnodeList[j].Attributes["merge"].Value) item.DictCol[j].MergeCell = true; else item.DictCol[j].MergeCell = false; if (null != colnodeList[j].Attributes["isreadonly"] && "1" == colnodeList[j].Attributes["isreadonly"].Value) item.DictCol[j].IsReadOnly = true; else item.DictCol[j].IsReadOnly = false; if (null != colnodeList[j].Attributes["format"] && string.Empty != colnodeList[j].Attributes["format"].Value && "" != colnodeList[j].Attributes["format"].Value.ToLower()) item.DictCol[j].Formate = colnodeList[j].Attributes["format"].Value; //1 - ���ɼ���0����Ϊ������ʾ if (null != colnodeList[j].Attributes["visible"] && "1" == colnodeList[j].Attributes["visible"].Value) item.DictCol[j].Visible = false; else item.DictCol[j].Visible = true; //1 - ���ɼ���0����Ϊ������ʾ if (null != colnodeList[j].Attributes["evisible"] && "1" == colnodeList[j].Attributes["evisible"].Value) item.DictCol[j].EVisible = false; else item.DictCol[j].EVisible = true; #endregion #region ��ͼ���� if (null != colnodeList[j].Attributes["barheight"] && "" != colnodeList[j].Attributes["barheight"].Value) try { item.DictCol[j].BarHeight = int.Parse(colnodeList[i].Attributes["barheight"].Value); } catch { } if (null != colnodeList[j].Attributes["barwidth"] && "" != colnodeList[j].Attributes["barwidth"].Value) try { item.DictCol[j].BarWidth = int.Parse(colnodeList[i].Attributes["barwidth"].Value); } catch { } if (null != colnodeList[j].Attributes["barcolor"] && "" != colnodeList[j].Attributes["barcolor"].Value) try { item.DictCol[j].BarColor = colnodeList[i].Attributes["barcolor"].Value; } catch { } if (null != colnodeList[j].Attributes["bartitle"] && "" != colnodeList[j].Attributes["bartitle"].Value) try { item.DictCol[j].BarTitle = colnodeList[i].Attributes["bartitle"].Value; } catch { } #endregion } //������У�� XmlNodeList valiNodeList = itemlist[i].SelectNodes("Validity"); item.Validities = new Validity[valiNodeList.Count]; for (int j = 0; j < valiNodeList.Count; j++) { item.Validities[j] = new Validity(); if (null != valiNodeList[j].Attributes["comment"]) item.Validities[j].Comment = valiNodeList[j].Attributes["comment"].Value; if (null != valiNodeList[j].Attributes["expression"]) item.Validities[j].Expression = valiNodeList[j].Attributes["expression"].Value; if (null != valiNodeList[j].Attributes["alertmsg"]) item.Validities[j].AlterMsg = valiNodeList[j].Attributes["alertmsg"].Value; } } return workItemList; }
/// <summary> /// 设计器支持所需的方法 - 不要使用代码编辑器 /// 修改此方法的内容。 /// gd_work.InitializeRow += new Infragistics.WebUI.UltraWebGrid.InitializeRowEventHandler(this.gd_work_InitializeRow); /// </summary> private void InitializeComponent() { BasePage page=this.Page as BasePage; //表格行集合的key要与数据源的绑定DataTable名称一致 this._workItem=page.PgGetWorkItem(this.CtrlItemName); }
protected void Page_Load(object sender, System.EventArgs e) { // 在此处放置用户代码以初始化页面 //读取用户参数 string strCommand = "",strDataItem=""; StreamReader streamreader=new StreamReader(this.Request.InputStream,Encoding.UTF8); //if (streamreader.ReadToEnd() == "") return; //try //{ this.xmlDocParam.LoadXml(streamreader.ReadToEnd()); //} //catch //{ // return; //} this.paramlist=BuildParamList.BuildParams(this.xmlDocParam); try { if (null==this.paramlist["UnitName"]) return; if (null==this.paramlist["Command"]) return; string unitName=this.paramlist["UnitName"].ToString(); strCommand = this.paramlist["Command"].ToString(); if (null==this.paramlist["DataItem"]) strDataItem = ""; else strDataItem = this.paramlist["DataItem"].ToString(); unitItem = new UnitItem(DataAccRes.AppSettings("WorkConfig"), unitName); //unitItem = new UnitItem(paramlist, unitName); } catch ( Exception ex ) { ExceptionManager.Publish( ex ); return; } string workItemName=""; if (null != paramlist["WorkItem"]) workItemName=paramlist["WorkItem"].ToString(); for (int i = 0; i < unitItem.WorkItemList.Length; i++) if (workItemName == unitItem.WorkItemList[i].ItemName) { workitem = unitItem.WorkItemList[i]; break; } if (workitem==null) { string strResult = leofun.setvaltag("", "成功", "false"); this.Response.Write(leofun.Escape(strResult)); return; } query = new QueryDataRes(unitItem.DataSrcFile); if (unitItem.DataSrcFile == unitItem.DictColSrcFile) dictQuery = query; else dictQuery = new QueryDataRes(unitItem.DictColSrcFile); switch (strCommand.ToLower()) { case "query": this.QueryData(strDataItem); break; case "queryincserialwatch": //this.QueryIncSerialWatch(); break; case "cmd_cmd": this.ExcutCmd(strDataItem); break; case "cmd_cmdbits": //首先执行命令,然后根据数据库表记录的需要备份文件列表,把列表传送给目地服务器,目地服务器调用后台智能传输服务备份文件。 //WSBits 是WebService对象,调用远程方法 this.ExcutCmd(strDataItem); QueryDataRes querySys = QueryDataRes.CreateQuerySys(); NameObjectList paramBits = new NameObjectList(); string struri = this.Request.Url.AbsoluteUri; paramBits["地址"] = struri.Substring(0, struri.IndexOf(this.Request.Url.LocalPath)); DataTable tabTrans = querySys.getTable("后台文件归档", paramBits); WSBits bitsTrans = new WSBits(); if (bitsTrans.AddFileList(tabTrans)) querySys.ExecuteDelete("后台文件归档", paramBits); break; case "switchmodel": bool bSucc = false; string strResult = ""; if (null != paramlist["WorkItem"] && "SetModel" == paramlist["WorkItem"].ToString()) bSucc = DataAccRes.SwitchModelConfig(strDataItem); else bSucc = DataAccRes.SwitchDefaultModel(); if (bSucc) strResult = leofun.setvaltag("", "成功", "true"); else { strResult = leofun.setvaltag("", "成功", "false"); strResult = leofun.setvaltag(strResult, "提示", "执行命令失败,请查找原因再重试!"); } this.Response.Write(leofun.Escape(strResult)); break; default: break; } }
/// <summary> /// 获取参数数组 /// </summary> private string[] getStrParams(WorkItem workItem) { string datasrc = workItem.DataSrc; string QW = "", FW = "", FGroup = "", FSumcol = "", FWhere = "", spagesize = "10", spageindex = "1"; //取页面参数 basePage if (null != this.ViewStates["QW" + datasrc]) QW = this.ViewStates["QW" + datasrc].ToString(); if (null != this.ViewStates["FW" + datasrc]) FW = this.ViewStates["FW" + datasrc].ToString(); if (null != this.ViewStates["FG" + datasrc]) FGroup = this.ViewStates["FG" + datasrc].ToString(); if (null != this.ViewStates["SumCol" + datasrc]) FSumcol = this.ViewStates["SumCol" + datasrc].ToString(); if (null != this.ViewStates["Where" + datasrc]) FWhere = this.ViewStates["Where" + datasrc].ToString(); //取用户控件参数 if (null != this.ViewState["PageSize" + datasrc]) spagesize = this.ViewState["PageSize" + datasrc].ToString(); if (null != this.ViewState["PageIndex" + datasrc]) spageindex = this.ViewState["PageIndex" + datasrc].ToString(); int pageindex = Convert.ToInt32(spageindex); int valx = (pageindex - 1) * (Convert.ToInt32(spagesize)); int topnum = (pageindex) * (Convert.ToInt32(spagesize)); int endnum = valx; string[] strParams = new string[] { spagesize, valx.ToString(), QW, FW, FGroup, FSumcol, FWhere, topnum.ToString(), workItem.InitFilter }; return strParams; }
/// <summary> /// 获取业务单元的明细项目 /// </summary> /// <returns>返回明细项目数组</returns> private WorkItem[] GetWorkItemList() { if (null == this.dtWorkItem) return (new WorkItem[0]); DataRow[] itemlist = this.dtWorkItem.Select(); WorkItem[] workItemList=new WorkItem[itemlist.Length]; for (int i = 0; i < itemlist.Length; i++) { WorkItem item = new WorkItem(); item.ItemName = itemlist[i]["name"].ToString(); workItemList[i] = item; if (null != itemlist[i]["alias"] && "" != itemlist[i]["alias"].ToString()) { string[] aliasList = itemlist[i]["alias"].ToString().Split(";".ToCharArray()); for (int ialias = 0; ialias < aliasList.Length; ialias++) if ("" != aliasList[ialias] && null != aliasList[ialias]) item.AliasList[aliasList[ialias]] = aliasList[ialias]; } #region 关系类型 string strRlt = ""; if (null == itemlist[i]["relation"] || "" == itemlist[i]["relation"].ToString()) strRlt = "G"; else strRlt = itemlist[i]["relation"].ToString().ToUpper(); switch (strRlt) { case "M": item.ItemType = WorkItemType.MasterData; if (null != _drnode["billtype"]) item.BillType = _drnode["billtype"].ToString(); break; case "D": item.ItemType = WorkItemType.DetailData; break; case "G": item.ItemType = WorkItemType.GeneralData; break; default: throw (new Exception("明细项目类型设置有误:" + this.UnitName)); } #endregion #region 打印类型 string strPrintType = ""; if (null != itemlist[i]["printtype"]) strPrintType = itemlist[i]["printtype"].ToString(); switch (strPrintType) { case "WORD": item.PrintType = PrintType.Word; break; case "EXCEL": item.PrintType = PrintType.Excel; break; case "HTML": item.PrintType = PrintType.HTML; break; default: item.PrintType = PrintType.HTML; break; } if (null != itemlist[i]["printitem"]) item.printitem = itemlist[i]["printitem"].ToString(); if (null != itemlist[i]["printname"]) item.printname = itemlist[i]["printname"].ToString(); if (null != itemlist[i]["printcount"] && null != itemlist[i]["printcount"].ToString()) item.printcountmin = itemlist[i]["printcount"].ToString(); if (itemlist[i]["print"] != null && itemlist[i]["print"].ToString().ToLower() == "true") item.print = true; else item.print = false; #endregion #region Chart图表类型 string strCharType = ""; if (null != itemlist[i]["charttype"]) strCharType = itemlist[i]["charttype"].ToString().ToLower(); if (itemlist[i]["chartleft"] != null) item.ChartTitleLeft = itemlist[i]["chartleft"].ToString(); if (itemlist[i]["chartbottom"] != null) item.ChartTitleBottom = itemlist[i]["chartbottom"].ToString(); if (itemlist[i]["charttop"] != null) item.ChartTitleTop = itemlist[i]["charttop"].ToString(); if (itemlist[i]["chartvaluetype"] != null) item.ChartValueType = itemlist[i]["chartvaluetype"].ToString(); #endregion if (null != itemlist[i]["extentx"] && null != itemlist[i]["extentx"].ToString() && "" != itemlist[i]["extentx"].ToString()) try { item.ExtentX = int.Parse(itemlist[i]["extentx"].ToString()); } catch { } if (null != itemlist[i]["extenty"] && null != itemlist[i]["extenty"].ToString() && "" != itemlist[i]["extenty"].ToString()) try { item.ExtentY = int.Parse(itemlist[i]["extenty"].ToString()); } catch { } #region 工作项目数据源属性 if (null != itemlist[i]["dataitem"]) item.DataSrc = itemlist[i]["dataitem"].ToString(); if (itemlist[i]["dataitempage"] != null) item.DataSrcPage = itemlist[i]["dataitempage"].ToString(); if (itemlist[i]["countdataitem"] != null) item.CountDataSrc = itemlist[i]["countdataitem"].ToString(); if (null != itemlist[i]["linkcol"]) item.LinkCol = itemlist[i]["linkcol"].ToString(); if (null != itemlist[i]["columnkey"]) item.ColumnKey = itemlist[i]["columnkey"].ToString(); if (null != itemlist[i]["gridtemplate"]) item.TemplateEdit = itemlist[i]["gridtemplate"].ToString(); //if (null != itemlist[i]["headtemplate"]) // item.TemplateHead = itemlist[i]["headtemplate"].ToString(); //if (null != itemlist[i]["headheight"]) // item.HeadHeight = itemlist[i]["headheight"].ToString(); if (null != itemlist[i]["pagesize"]) item.PageSize = itemlist[i]["pagesize"].ToString(); if (null != itemlist[i]["group"]) item.Group = itemlist[i]["group"].ToString(); if (null != itemlist[i]["sumcol"]) item.SumCol = itemlist[i]["sumcol"].ToString(); if (null != itemlist[i]["where"]) item.Where = itemlist[i]["where"].ToString(); if (null != itemlist[i]["filter"]) item.InitFilter = itemlist[i]["filter"].ToString(); if (itemlist[i]["import"] != null && itemlist[i]["import"].ToString() == "1") item.IsImport = true; if (null != itemlist[i]["tpid"]) item.TempId = itemlist[i]["tpid"].ToString(); #endregion #region 地图数据柱属性 if (null != itemlist[i]["barstep"] && "" != itemlist[i]["barstep"].ToString()) try { item.BarStep = int.Parse(itemlist[i]["barstep"].ToString()); } catch { } if (null != itemlist[i]["baroffsetx"] && "" != itemlist[i]["baroffsetx"].ToString()) try { item.BarOffsetX = int.Parse(itemlist[i]["baroffsetx"].ToString()); } catch { } if (null != itemlist[i]["baroffsety"] && "" != itemlist[i]["baroffsety"].ToString()) try { item.BarOffsetY = int.Parse(itemlist[i]["baroffsety"].ToString()); } catch { } #endregion //取对应的列属性 //XmlNodeList colnodeList = itemlist[i].SelectNodes("Column"); OpenDatabase(); string sqltext = "select name, format, validity, merge, alertexpr, chkcol, expression, datastyle, visible, barheight, barwidth, barcolor, bartitle, dataitem, textcol,"+ "valuecol, calcol, title, isreadonly, valuefld, href, target, onclick, footer,filterdata,filteritem" + " FROM [HMSYS].[dbo].columns where code='" + itemlist[i]["code"].ToString() + "'"; this.dtColumn = BindGrid(sqltext); if (this.myConnection.State == ConnectionState.Open) this.myConnection.Close(); if (dtColumn == null) continue; DataRow[] colnodeList = dtColumn.Select(); item.DictCol = new DictColumn[colnodeList.Length]; for (int j = 0; j < colnodeList.Length; j++) { item.DictCol[j] = new DictColumn(); #region 字典列数据源 item.DictCol[j].ColumnName = colnodeList[j]["name"].ToString(); if (null != colnodeList[j]["dataitem"] && null != colnodeList[j]["textcol"] && null != colnodeList[j]["valuecol"]) { item.DictCol[j].DataSrc = colnodeList[j]["dataitem"].ToString(); item.DictCol[j].TextCol = colnodeList[j]["textcol"].ToString(); item.DictCol[j].ValueCol = colnodeList[j]["valuecol"].ToString(); } if (null != colnodeList[j]["filteritem"] && null != colnodeList[j]["filteritem"]) item.DictCol[j].FilterItem = colnodeList[j]["filteritem"].ToString(); if (null != colnodeList[j]["filterdata"]) item.DictCol[j].FilterData = colnodeList[j]["filterdata"].ToString(); #endregion #region 列计算,校验,编辑,格式,可视属性 //计算列,列是否必填,列的单元格验证 if (null != colnodeList[j]["expression"]) item.DictCol[j].Expression = colnodeList[j]["expression"].ToString(); if (null != colnodeList[j]["validity"]) item.DictCol[j].ValidateCell = colnodeList[j]["validity"].ToString(); if (null != colnodeList[j]["calcol"] && "1" == colnodeList[j]["calcol"].ToString()) item.DictCol[j].CalType = CalculateType.Dynamic; else item.DictCol[j].CalType = CalculateType.Init; //脚注 if (null != colnodeList[j]["footer"]) item.DictCol[j].Footer = colnodeList[j]["footer"].ToString(); // 0 - 非限制输入, 1- 表示不能为空 if (null != colnodeList[j]["chkcol"] && "1" == colnodeList[j]["chkcol"].ToString()) item.DictCol[j].IsNeed = true; else item.DictCol[j].IsNeed = false; if (null != colnodeList[j]["merge"] && "1" == colnodeList[j]["merge"].ToString()) item.DictCol[j].MergeCell = true; else item.DictCol[j].MergeCell = false; if (null != colnodeList[j]["isreadonly"] && "1" == colnodeList[j]["isreadonly"].ToString()) item.DictCol[j].IsReadOnly = true; else item.DictCol[j].IsReadOnly = false; if (null != colnodeList[j]["format"] && string.Empty != colnodeList[j]["format"].ToString() && "" != colnodeList[j]["format"].ToString().ToLower()) item.DictCol[j].Formate = colnodeList[j]["format"].ToString(); //1 - 不可见,0,空为正常显示 if (null != colnodeList[j]["visible"] && "1" == colnodeList[j]["visible"].ToString()) item.DictCol[j].Visible = false; else item.DictCol[j].Visible = true; #endregion #region 地图属性 if (null != colnodeList[j]["barheight"] && "" != colnodeList[j]["barheight"].ToString()) try { item.DictCol[j].BarHeight = int.Parse(colnodeList[i]["barheight"].ToString()); } catch { } if (null != colnodeList[j]["barwidth"] && "" != colnodeList[j]["barwidth"].ToString()) try { item.DictCol[j].BarWidth = int.Parse(colnodeList[i]["barwidth"].ToString()); } catch { } if (null != colnodeList[j]["barcolor"] && "" != colnodeList[j]["barcolor"].ToString()) try { item.DictCol[j].BarColor = colnodeList[i]["barcolor"].ToString(); } catch { } if (null != colnodeList[j]["bartitle"] && "" != colnodeList[j]["bartitle"].ToString()) try { item.DictCol[j].BarTitle = colnodeList[i]["bartitle"].ToString(); } catch { } #endregion } //行数据校验 //XmlNodeList valiNodeList = itemlist[i].SelectNodes("Validity"); //item.Validities = new Validity[valiNodeList.Count]; //for (int j = 0; j < valiNodeList.Count; j++) //{ // item.Validities[j] = new Validity(); // if (null != valiNodeList[j].Attributes["comment"]) // item.Validities[j].Comment = valiNodeList[j].Attributes["comment"].Value; // if (null != valiNodeList[j].Attributes["expression"]) // item.Validities[j].Expression = valiNodeList[j].Attributes["expression"].Value; // if (null != valiNodeList[j].Attributes["alertmsg"]) // item.Validities[j].AlterMsg = valiNodeList[j].Attributes["alertmsg"].Value; //} }//for(int i=0;i<itemlist.Count;i++) return workItemList; }
//为什么是PgWorkItemList[1].ItemType ? private void printword(string mrowIndex,WorkItem workitem) { string TemplatePath = this.Server.MapPath(DataAccRes.AppSettings("TpFilePath")); //存放源文件的文件夹路径。 string printname = "", itemname=""; printname = workitem.printname; itemname = workitem.ItemName; if(string.IsNullOrEmpty(printname)) printname= itemname; string SourceFile = printname + ".XML"; //源文件名称 string SrcFile = TemplatePath +"\\"+ SourceFile; //源文件名称 string DestFile = printname + Session["userid"] + ".XLS"; string schemaFile = TemplatePath + "\\" + printname + ".xsd"; if (!File.Exists(SrcFile)) { string strMSG = "打印模板 [" + SourceFile + "] 不存在,请联系系统管理员建立打印模板!"; this.Response.Write("<script language=\"javascript\">"); this.Response.Write("alert('" + strMSG + "')"); this.Response.Write("</script>"); return; } QueryDataRes query = this.PgQuery; NameObjectList paramlist = BuildParamList.BuildParams(this.PgParamXmlDoc); DataSet ds = new DataSet(this.PgUnitItem.UnitName); if (File.Exists(schemaFile)) { ds.ReadXmlSchema(schemaFile); for (int i = 0; i < ds.Tables.Count; i++) { WorkItem tabItem = null; for (int j = 0; j < this.PgUnitItem.WorkItemList.Length; j++) if (ds.Tables[i].TableName == this.PgUnitItem.WorkItemList[j].DataSrc) { tabItem = this.PgUnitItem.WorkItemList[j]; break; } if (null == tabItem) query.FillDataSet(ds.Tables[i].TableName, paramlist, ds); else { query.FillDataSet(ds.Tables[i].TableName, paramlist, this.getStrParams(this.PgParamXmlDoc,tabItem), ds); if (!string.IsNullOrEmpty(tabItem.printcountmin)) ds.Tables[i].ExtendedProperties[PrintWord.ExProMinRowCountName] = tabItem.printcountmin; } }///for (int i = 0; i < ds.Tables.Count; i++) } else { query.FillDataSet(workitem.DataSrc, paramlist, this.getStrParams(this.PgParamXmlDoc,workitem), ds); if (null != ds.Tables[workitem.DataSrc] && !string.IsNullOrEmpty(workitem.printcountmin)) ds.Tables[workitem.DataSrc].ExtendedProperties[PrintWord.ExProMinRowCountName] = workitem.printcountmin; } if (ds == null) return; if (ds.Tables[0] == null) return; if (ds.Tables[0].Rows.Count < 1) return; PrintWord printdoc = new PrintWord(); printdoc.TemplateFileName = SrcFile; printdoc.DataSource = ds; printdoc.DataBind(); printdoc.RemoveXmlLable(); csPrint.outXML2Word(printdoc.PrintXmlDoc, printname + ".doc"); }
private string getRecordCountParam(WorkItem workitem) { return BuildParamList.getValue(this.PgParamXmlDoc, "RecordCount", workitem.ItemName); //////wrcawrca //string strParam=string.Empty; //XmlDocument xmldoc=new XmlDocument(); //XmlElement xmlele=null; //if(null==this.PgRequestParams["QueryStr"] || ""==this.PgRequestParams["QueryStr"]) // xmldoc.LoadXml("<ParameterList/>"); //else // xmldoc.LoadXml(this.PgRequestParams["QueryStr"]); //xmlele=xmldoc.DocumentElement.SelectSingleNode("Parameter[@name='RecordCount"+datasrc+"']") as XmlElement; // if(null==xmlele) // strParam=""; // else // strParam=xmlele.Attributes["value"].Value; //return strParam; }
private void printexcel(string mrowIndex, WorkItem workitem) { QueryDataRes query = this.PgQuery; if (!string.IsNullOrEmpty(BuildParamList.getValue(this.PgParamXmlDoc, "MIndex"))) mrowIndex = BuildParamList.getValue(this.PgParamXmlDoc, "MIndex"); //获取模板中的原始SQL, 得到从表TAB //需要知道itemName string printname = "", itemname = ""; printname = workitem.printname; itemname = workitem.ItemName; if (printname == "" || printname == null) printname = itemname; string TemplatePath = this.Server.MapPath(DataAccRes.AppSettings("TpFilePath")); //存放源文件的文件夹路径。 string SourceFile = printname + ".XML"; //源文件名称 string SrcFile = TemplatePath + "\\" + SourceFile; //源文件名称 string DestFile = printname + Session["userid"] + ".XLS"; if (!File.Exists(SrcFile) == true) { SourceFile = printname + ".xls"; if (!File.Exists(SrcFile) == true) { string strMSG = "打印模板 [" + SourceFile + "] 不存在,请联系系统管理员建立打印模板!"; this.Response.Write("<script language=\"javascript\">"); this.Response.Write("alert('" + strMSG + "')"); this.Response.Write("</script>"); return; } } NameObjectList paramlist = BuildParamList.BuildParams(this.PgParamXmlDoc); //得到主表TAB WorkItem masterItem = new WorkItem(); DataTable tabMaster = null; if (this.PgWorkItemList.Length > 1) { for (int i = 0; i < this.PgWorkItemList.Length; i++) { if (WorkItemType.MasterData != this.PgWorkItemList[i].ItemType) continue; masterItem = this.PgWorkItemList[i]; string[] strParams = getStrParams(this.PgParamXmlDoc, this.PgWorkItemList[i]); strParams[8] = workitem.InitFilter; tabMaster = this.PgQuery.getTable(this.PgWorkItemList[i].DataSrc, paramlist, strParams); break; } if (workitem.LinkCol != "" && workitem.LinkCol != null && tabMaster.Rows[0][workitem.LinkCol] != null) paramlist.Add(workitem.LinkCol, tabMaster.Rows[0][workitem.LinkCol]); } DataTable tab = query.getTable(workitem.DataSrc, paramlist, this.getStrParams(this.PgParamXmlDoc, workitem)); if (tab == null) { leofun.Alert("[" + workitem.DataSrc + "]数据发生错误,请检查!", this); return; } if (tabMaster == null) tabMaster = tab; if (null == tab) return; if (tab.Rows.Count < 1) return; XmlDocument xmldoc = csPrintData.makeprint(masterItem, workitem, SourceFile, DestFile, tab, tabMaster, leofun.toIntval(mrowIndex), this.Session["userid"].ToString(), paramlist); csPrintData.outXML2Excel(xmldoc, printname + ".xls"); }