/// <summary> /// 获取从表数据,用于显示dtl.htm /// </summary> /// <param name="frmID">表单ID</param> /// <param name="pkval">主键</param> /// <param name="atParas">参数</param> /// <param name="specDtlFrmID">指定明细表的参数,如果为空就标识主表数据,否则就是从表数据.</param> /// <returns>数据</returns> public static DataSet GenerDBForCCFormDtl(string frmID, MapDtl dtl, int pkval, string atParas) { //数据容器,就是要返回的对象. DataSet myds = new DataSet(); //映射实体. MapData md = new MapData(frmID); //实体. GEEntity wk = new GEEntity(frmID); wk.OID = pkval; if (wk.RetrieveFromDBSources() == 0) { wk.Insert(); } //把参数放入到 En 的 Row 里面。 if (DataType.IsNullOrEmpty(atParas) == false) { AtPara ap = new AtPara(atParas); foreach (string key in ap.HisHT.Keys) { try { if (wk.Row.ContainsKey(key) == true) //有就该变. { wk.Row[key] = ap.GetValStrByKey(key); } else { wk.Row.Add(key, ap.GetValStrByKey(key)); //增加他. } } catch (Exception ex) { throw new Exception(key); } } } #region 加载从表表单模版信息. DataTable Sys_MapDtl = dtl.ToDataTableField("Sys_MapDtl"); myds.Tables.Add(Sys_MapDtl); //明细表的表单描述 DataTable Sys_MapAttr = dtl.MapAttrs.ToDataTableField("Sys_MapAttr"); myds.Tables.Add(Sys_MapAttr); //明细表的配置信息. DataTable Sys_MapExt = dtl.MapExts.ToDataTableField("Sys_MapExt"); myds.Tables.Add(Sys_MapExt); #region 把从表的- 外键表/枚举 加入 DataSet. MapExts mes = dtl.MapExts; MapExt me = null; foreach (DataRow dr in Sys_MapAttr.Rows) { string lgType = dr["LGType"].ToString(); //不是枚举/外键字段 if (lgType.Equals("0")) { continue; } string uiBindKey = dr["UIBindKey"].ToString(); var mypk = dr["MyPK"].ToString(); #region 枚举字段 if (lgType.Equals("1")) { // 如果是枚举值, 判断是否存在. if (myds.Tables.Contains(uiBindKey) == true) { continue; } string mysql = "SELECT IntKey AS No, Lab as Name FROM Sys_Enum WHERE EnumKey='" + uiBindKey + "' ORDER BY IntKey "; DataTable dtEnum = DBAccess.RunSQLReturnTable(mysql); dtEnum.TableName = uiBindKey; dtEnum.Columns[0].ColumnName = "No"; dtEnum.Columns[1].ColumnName = "Name"; myds.Tables.Add(dtEnum); continue; } #endregion #region 外键字段 string UIIsEnable = dr["UIIsEnable"].ToString(); if (UIIsEnable.Equals("0")) //字段未启用 { continue; } // 检查是否有下拉框自动填充。 string keyOfEn = dr["KeyOfEn"].ToString(); #region 处理下拉框数据范围. for 小杨. me = mes.GetEntityByKey(MapExtAttr.ExtType, MapExtXmlList.AutoFullDLL, MapExtAttr.AttrOfOper, keyOfEn) as MapExt; if (me != null) //有范围限制时 { string fullSQL = me.Doc.Clone() as string; fullSQL = fullSQL.Replace("~", ","); fullSQL = BP.WF.Glo.DealExp(fullSQL, wk, null); DataTable dt = DBAccess.RunSQLReturnTable(fullSQL); dt.TableName = uiBindKey; dt.Columns[0].ColumnName = "No"; dt.Columns[1].ColumnName = "Name"; myds.Tables.Add(dt); continue; } #endregion 处理下拉框数据范围. // 判断是否存在. if (myds.Tables.Contains(uiBindKey) == true) { continue; } myds.Tables.Add(BP.Sys.PubClass.GetDataTableByUIBineKey(uiBindKey)); #endregion 外键字段 } #endregion 把从表的- 外键表/枚举 加入 DataSet. #endregion 加载从表表单模版信息. #region 把主表数据放入. if (BP.Sys.SystemConfig.IsBSsystem == true) { // 处理传递过来的参数。 foreach (string k in System.Web.HttpContext.Current.Request.QueryString.AllKeys) { wk.SetValByKey(k, System.Web.HttpContext.Current.Request.QueryString[k]); } } //重设默认值. wk.ResetDefaultVal(); //增加主表数据. DataTable mainTable = wk.ToDataTableField(md.No); mainTable.TableName = "MainTable"; myds.Tables.Add(mainTable); #endregion 把主表数据放入. #region 把从表的数据放入. GEDtls dtls = new GEDtls(dtl.No); QueryObject qo = null; try { qo = new QueryObject(dtls); switch (dtl.DtlOpenType) { case DtlOpenType.ForEmp: // 按人员来控制. qo.AddWhere(GEDtlAttr.RefPK, pkval); qo.addAnd(); qo.AddWhere(GEDtlAttr.Rec, WebUser.No); break; case DtlOpenType.ForWorkID: // 按工作ID来控制 qo.AddWhere(GEDtlAttr.RefPK, pkval); break; case DtlOpenType.ForFID: // 按流程ID来控制. qo.AddWhere(GEDtlAttr.FID, pkval); break; } } catch (Exception ex) { dtls.GetNewEntity.CheckPhysicsTable(); throw ex; } //条件过滤. if (dtl.FilterSQLExp != "") { string[] strs = dtl.FilterSQLExp.Split('='); qo.addAnd(); qo.AddWhere(strs[0], strs[1]); } //增加排序. // qo.addOrderByDesc( dtls.GetNewEntity.PKField ); //从表 DataTable dtDtl = qo.DoQueryToTable(); //查询所有动态SQL查询类型的字典表记录 SFTable sftable = null; DataTable dtsftable = null; DataRow[] drs = null; SFTables sftables = new SFTables(); sftables.Retrieve(SFTableAttr.SrcType, (int)SrcType.SQL); // 为明细表设置默认值. MapAttrs dtlAttrs = new MapAttrs(dtl.No); foreach (MapAttr attr in dtlAttrs) { #region 修改区分大小写. if (BP.DA.DBType.Oracle == SystemConfig.AppCenterDBType) { foreach (DataColumn dr in dtDtl.Columns) { var a = attr.KeyOfEn; var b = dr.ColumnName; if (attr.KeyOfEn.ToUpper().Equals(dr.ColumnName)) { dr.ColumnName = attr.KeyOfEn; continue; } if (attr.LGType == FieldTypeS.Enum || attr.LGType == FieldTypeS.FK) { if (dr.ColumnName.Equals(attr.KeyOfEn.ToUpper() + "TEXT")) { dr.ColumnName = attr.KeyOfEn + "Text"; } } } foreach (DataRow dr in dtDtl.Rows) { //本身是大写的不进行修改 if (DataType.IsNullOrEmpty(dr[attr.KeyOfEn] + "")) { dr[attr.KeyOfEn] = dr[attr.KeyOfEn.ToUpper()]; dr[attr.KeyOfEn.ToUpper()] = null; } } } #endregion 修改区分大小写. //处理增加动态SQL查询类型的下拉框选中值Text值,added by liuxc,2017-9-22 if (attr.LGType == FieldTypeS.FK && attr.UIIsEnable == false) { sftable = sftables.GetEntityByKey(attr.UIBindKey) as SFTable; if (sftable != null) { dtsftable = sftable.GenerHisDataTable; //为Text赋值 foreach (DataRow dr in dtDtl.Rows) { drs = dtsftable.Select("No='" + dr[attr.KeyOfEn] + "'"); if (drs.Length == 0) { continue; } dr[attr.KeyOfEn + "Text"] = drs[0]["Name"]; } } } //处理它的默认值. if (attr.DefValReal.Contains("@") == false) { continue; } foreach (DataRow dr in dtDtl.Rows) { dr[attr.KeyOfEn] = attr.DefVal; } } dtDtl.TableName = "DBDtl"; //修改明细表的名称. myds.Tables.Add(dtDtl); //加入这个明细表, 如果没有数据,xml体现为空. #endregion 把从表的数据放入. //放入一个空白的实体,用与获取默认值. GEDtl dtlBlank = dtls.GetNewEntity as GEDtl; dtlBlank.ResetDefaultVal(); myds.Tables.Add(dtlBlank.ToDataTableField("Blank")); return(myds); }