/// <summary> /// 查询 /// </summary> /// <returns></returns> public string Search_Search() { string TSpan = this.GetRequestVal("TSpan"); string FK_Flow = this.GetRequestVal("FK_Flow"); GenerWorkFlows gwfs = new GenerWorkFlows(); QueryObject qo = new QueryObject(gwfs); qo.AddWhere(GenerWorkFlowAttr.Emps, " LIKE ", "%" + BP.Web.WebUser.No + "%"); if (!DataType.IsNullOrEmpty(TSpan)) { qo.addAnd(); qo.AddWhere(GenerWorkFlowAttr.TSpan, this.GetRequestVal("TSpan")); } if (!DataType.IsNullOrEmpty(FK_Flow)) { qo.addAnd(); qo.AddWhere(GenerWorkFlowAttr.FK_Flow, this.GetRequestVal("FK_Flow")); } qo.Top = 50; if (SystemConfig.AppCenterDBType == DBType.Oracle || SystemConfig.AppCenterDBType == DBType.PostgreSQL) { qo.DoQuery(); DataTable dt = gwfs.ToDataTableField("Ens"); return(BP.Tools.Json.ToJson(dt)); } else { DataTable dt = qo.DoQueryToTable(); return(BP.Tools.Json.ToJson(dt)); } }
protected void Page_Load(object sender, EventArgs e) { // 求已经填写的默认值. Entities ens = BP.En.ClassFactory.GetEns(this.EnsName); Entity en = ens.GetNewEntity; BP.En.QueryObject qo = new QueryObject(ens); if (en.EnMap.Attrs.Contains("Rec") == true) { qo.AddWhere("Rec", BP.Web.WebUser.No); } qo.Top = 12; DataTable dt = qo.DoQueryToTable(); //求设置的默认值。 string sql = "SELECT a.CurValue, 1 as IsDef FROM Sys_DefVal a WHERE (A.FK_Emp='" + WebUser.No + "' OR A.FK_Emp='admin') AND FK_MapData='" + this.EnsName + "' AND NodeAttrKey='" + this.Field + "' "; DataTable mydt = BP.DA.DBAccess.RunSQLReturnTable(sql); foreach (DataRow dr in dt.Rows) { DataRow row = mydt.NewRow(); row[0] = dr[this.Field]; row[1] = 0; mydt.Rows.Add(row); } }
protected void Page_Load(object sender, EventArgs e) { Entities ens = BP.En.ClassFactory.GetEns(this.EnsName); Entity en = ens.GetNewEntity; // edit by stone : 增加了实施的获取map, 可以让用户动态的设置查询条件. Map map = en.EnMapInTime; //设置toolbar. this.ToolBar1.InitByMapV2(map, 1); QueryObject qo = new QueryObject(ens); qo = this.ToolBar1.GetnQueryObject(ens, en); //形成数据源. DataTable dt = qo.DoQueryToTable(); //找到导入导出的模版. //加载填充模版。 //让用户下载. //关闭当前窗口. BP.Sys.PubClass.WinClose(); }
/// <summary> /// 查询到我的任务. /// </summary> /// <returns></returns> public DataTable RetrieveMyTask(string flow, string flowSort) { QueryObject qo = new QueryObject(this); //qo.Top=50; qo.AddWhere(StartWorkAttr.OID, " IN ", " ( SELECT WorkID FROM V_WF_Msg WHERE (FK_Flow='" + flow + "' AND FK_Emp='" + Web.WebUser.No + "' ) AND ( FK_Flow in ( SELECT No from WF_Flow WHERE FK_FlowSort='" + flowSort + "' )) )"); return(qo.DoQueryToTable()); }
/// <summary> /// 查询到我的任务. /// </summary> /// <returns></returns> public DataTable RetrieveMyTask_del(string flow) { QueryObject qo = new QueryObject(this); //qo.Top=50; qo.AddWhere(StartWorkAttr.OID, " in ", " ( SELECT WorkID FROM V_WF_Msg WHERE FK_Flow='" + flow + "' AND FK_Emp='" + Web.WebUser.No + "' )"); return(qo.DoQueryToTable()); }
/// <summary> /// 查询到我的任务. /// </summary> /// <returns></returns> public DataTable RetrieveMyTask(string flow) { //string sql="SELECT OID AS WORKID, TITLE, "; QueryObject qo = new QueryObject(this); //qo.Top=50; if (BP.SystemConfig.AppCenterDBType == DBType.Oracle) { qo.AddWhere(StartWorkAttr.OID, " in ", " ( SELECT WorkID FROM WF_GenerWorkFlow WHERE FK_Node IN ( SELECT FK_Node FROM WF_GenerWorkerlist WHERE FK_Emp='" + Web.WebUser.No + "' AND FK_Flow='" + flow + "' AND WORKID=WF_GenerWorkFlow.WORKID ) )"); } else { qo.AddWhere(StartWorkAttr.OID, " in ", " ( SELECT WorkID FROM WF_GenerWorkFlow WHERE FK_Node IN ( SELECT FK_Node FROM WF_GenerWorkerlist WHERE FK_Emp='" + Web.WebUser.No + "' AND FK_Flow='" + flow + "' AND WORKID=WF_GenerWorkFlow.WORKID ) )"); } return(qo.DoQueryToTable()); }
private void ToolBar1_ButtonClick(object sender, System.EventArgs e) { try { Btn btn = (Btn)sender; switch (btn.ID) { case BP.Web.Controls.NamesOfBtn.Export: case NamesOfBtn.Excel: //数据导出 Bill en = new Bill(); Bills ens = new Bills(); QueryObject qo = new QueryObject(ens); if (this.DoType == "My") { qo.AddWhere(BillAttr.FK_Emp, WebUser.No); qo.addAnd(); qo.AddWhere(BillAttr.FK_Flow, this.FK_Flow); } else { qo = this.ToolBar1.GetnQueryObject(ens, en); } DataTable dt = qo.DoQueryToTable(); DataTable myDT = new DataTable(); Attrs attrs = en.EnMap.Attrs; foreach (Attr attr in attrs) { myDT.Columns.Add(new DataColumn(attr.Desc, typeof(string))); } foreach (DataRow dr in dt.Rows) { DataRow myDR = myDT.NewRow(); foreach (Attr attr in attrs) { myDR[attr.Desc] = dr[attr.Key]; } myDT.Rows.Add(myDR); } string file = ""; try { file = this.ExportDGToExcel(myDT, en.EnDesc); } catch (Exception ex) { try { file = this.ExportDGToExcel(ens.ToDataTableDescField(), en.EnDesc); } catch { throw new Exception("数据没有正确导出可能的原因之一是:系统管理员没正确的安装Excel组件,请通知他,参考安装说明书解决。@系统异常信息:" + ex.Message); } } this.SetDGData(); return; case NamesOfBtn.Excel_S: //数据导出. Entities ens1 = this.SetDGData(); try { this.ExportDGToExcel(ens1.ToDataTableDesc(), this.HisEn.EnDesc); } catch (Exception ex) { throw new Exception("数据没有正确导出可能的原因之一是:系统管理员没正确的安装Excel组件,请通知他,参考安装说明书解决。@系统异常信息:" + ex.Message); } this.SetDGData(); return; case NamesOfBtn.Xml: //数据导出 return; case "Btn_Print": //数据导出. return; default: this.PageIdx = 1; this.SetDGData(1); this.ToolBar1.SaveSearchState(this.EnsName, null); return; } } catch (Exception ex) { if (!(ex is System.Threading.ThreadAbortException)) { this.ResponseWriteRedMsg(ex); //在这里显示错误 } } }
public Entities SetDGData(int pageIdx) { Entities ens = this.HisEns; Entity en = ens.GetNewEntity; Map map = en.EnMapInTime; QueryObject qo = new QueryObject(ens); qo = this.ToolBar1.GetnQueryObject(ens, en); if (this.DoType == "Exp") { /*如果是导出,就把它导出到excel.*/ string filePath = this.ExportDGToExcel(qo.DoQueryToTable(), en.EnMap, en.EnDesc + "数据导出"); this.WinClose(filePath); return(null); } int maxPageNum = 0; try { this.UCSys2.Clear(); maxPageNum = this.UCSys2.BindPageIdx(qo.GetCount(), SystemConfig.PageSize, pageIdx, "Search.aspx?EnsName=" + this.EnsName); if (maxPageNum > 1) { this.UCSys2.Add("翻页键:← → PageUp PageDown"); } } catch { try { en.CheckPhysicsTable(); } catch (Exception wx) { BP.DA.Log.DefaultLogWriteLineError(wx.Message); } maxPageNum = this.UCSys2.BindPageIdx(qo.GetCount(), SystemConfig.PageSize, pageIdx, "Search.aspx?EnsName=" + this.EnsName); } qo.DoQuery(en.PK, SystemConfig.PageSize, pageIdx); if (map.IsShowSearchKey) { string keyVal = this.ToolBar1.GetTBByID("TB_Key").Text.Trim(); if (keyVal.Length >= 1) { Attrs attrs = map.Attrs; foreach (Entity myen in ens) { foreach (Attr attr in attrs) { if (attr.IsFKorEnum) { continue; } if (attr.IsPK) { continue; } switch (attr.MyDataType) { case DataType.AppRate: case DataType.AppMoney: case DataType.AppInt: case DataType.AppFloat: case DataType.AppDouble: case DataType.AppBoolean: continue; default: break; } myen.SetValByKey(attr.Key, myen.GetValStrByKey(attr.Key).Replace(keyVal, "<font color=red>" + keyVal + "</font>")); } } } } this.UCSys1.DataPanelDtl(ens, null); int ToPageIdx = this.PageIdx + 1; int PPageIdx = this.PageIdx - 1; this.UCSys1.Add("<SCRIPT language=javascript>"); this.UCSys1.Add("\t\n document.onkeydown = chang_page;"); this.UCSys1.Add("\t\n function chang_page() { "); // this.UCSys3.Add("\t\n alert(event.keyCode); "); if (this.PageIdx == 1) { this.UCSys1.Add("\t\n if (event.keyCode == 37 || event.keyCode == 33) alert('已经是第一页');"); } else { this.UCSys1.Add("\t\n if (event.keyCode == 37 || event.keyCode == 38 || event.keyCode == 33) "); this.UCSys1.Add("\t\n location='Search.aspx?EnsName=" + this.EnsName + "&PageIdx=" + PPageIdx + "';"); } if (this.PageIdx == maxPageNum) { this.UCSys1.Add("\t\n if (event.keyCode == 39 || event.keyCode == 40 || event.keyCode == 34) alert('已经是最后一页');"); } else { this.UCSys1.Add("\t\n if (event.keyCode == 39 || event.keyCode == 40 || event.keyCode == 34) "); this.UCSys1.Add("\t\n location='Search.aspx?EnsName=" + this.EnsName + "&PageIdx=" + ToPageIdx + "';"); } this.UCSys1.Add("\t\n } "); this.UCSys1.Add("</SCRIPT>"); return(ens); }
/// <summary> /// 产生一个WorkNode /// </summary> /// <param name="fk_flow">流程编号</param> /// <param name="fk_node">节点ID</param> /// <param name="workID">工作ID</param> /// <param name="fid">FID</param> /// <param name="userNo">用户编号</param> /// <returns>返回dataset</returns> public static DataSet GenerWorkNodeForAndroid(string fk_flow, int fk_node, Int64 workID, Int64 fid, string userNo) { if (fk_node == 0) { fk_node = int.Parse(fk_flow + "01"); } if (workID == 0) { workID = BP.WF.Dev2Interface.Node_CreateBlankWork(fk_flow, null, null, userNo, null); } try { Emp emp = new Emp(userNo); BP.Web.WebUser.SignInOfGener(emp); MapData md = new MapData(); md.No = "ND" + fk_node; if (md.RetrieveFromDBSources() == 0) { throw new Exception("装载错误,该表单ID=" + md.No + "丢失,请修复一次流程重新加载一次."); } //表单模版. DataSet myds = BP.Sys.CCFormAPI.GenerHisDataSet(md.No); return(myds); #region 流程设置信息. Node nd = new Node(fk_node); if (nd.IsStartNode == false) { BP.WF.Dev2Interface.Node_SetWorkRead(fk_node, workID); } // 节点数据. string sql = "SELECT * FROM WF_Node WHERE NodeID=" + fk_node; DataTable dt = BP.DA.DBAccess.RunSQLReturnTable(sql); dt.TableName = "WF_NodeBar"; myds.Tables.Add(dt); // 流程数据. Flow fl = new Flow(fk_flow); myds.Tables.Add(fl.ToDataTableField("WF_Flow")); #endregion 流程设置信息. #region 把主从表数据放入里面. //.工作数据放里面去, 放进去前执行一次装载前填充事件. BP.WF.Work wk = nd.HisWork; wk.OID = workID; wk.RetrieveFromDBSources(); // 处理传递过来的参数。 foreach (string k in System.Web.HttpContext.Current.Request.QueryString.AllKeys) { wk.SetValByKey(k, System.Web.HttpContext.Current.Request.QueryString[k]); } // 执行一次装载前填充. string msg = md.DoEvent(FrmEventList.FrmLoadBefore, wk); if (DataType.IsNullOrEmpty(msg) == false) { throw new Exception("错误:" + msg); } wk.ResetDefaultVal(); myds.Tables.Add(wk.ToDataTableField(md.No)); //把附件的数据放入. if (md.FrmAttachments.Count > 0) { sql = "SELECT * FROM Sys_FrmAttachmentDB where RefPKVal=" + workID + " AND FK_MapData='ND" + fk_node + "'"; dt = BP.DA.DBAccess.RunSQLReturnTable(sql); dt.TableName = "Sys_FrmAttachmentDB"; myds.Tables.Add(dt); } // 图片附件数据放入 if (md.FrmImgAths.Count > 0) { sql = "SELECT * FROM Sys_FrmImgAthDB where RefPKVal=" + workID + " AND FK_MapData='ND" + fk_node + "'"; dt = BP.DA.DBAccess.RunSQLReturnTable(sql); dt.TableName = "Sys_FrmImgAthDB"; myds.Tables.Add(dt); } //把从表的数据放入. if (md.MapDtls.Count > 0) { foreach (MapDtl dtl in md.MapDtls) { GEDtls dtls = new GEDtls(dtl.No); QueryObject qo = null; try { qo = new QueryObject(dtls); switch (dtl.DtlOpenType) { case DtlOpenType.ForEmp: // 按人员来控制. qo.AddWhere(GEDtlAttr.RefPK, workID); qo.addAnd(); qo.AddWhere(GEDtlAttr.Rec, WebUser.No); break; case DtlOpenType.ForWorkID: // 按工作ID来控制 qo.AddWhere(GEDtlAttr.RefPK, workID); break; case DtlOpenType.ForFID: // 按流程ID来控制. qo.AddWhere(GEDtlAttr.FID, workID); break; } } catch { dtls.GetNewEntity.CheckPhysicsTable(); } DataTable dtDtl = qo.DoQueryToTable(); // 为明细表设置默认值. MapAttrs dtlAttrs = new MapAttrs(dtl.No); foreach (MapAttr attr in dtlAttrs) { //处理它的默认值. if (attr.DefValReal.Contains("@") == false) { continue; } foreach (DataRow dr in dtDtl.Rows) { dr[attr.KeyOfEn] = attr.DefVal; } } dtDtl.TableName = dtl.No; //修改明细表的名称. myds.Tables.Add(dtDtl); //加入这个明细表, 如果没有数据,xml体现为空. } } #endregion #region 把外键表加入DataSet DataTable dtMapAttr = myds.Tables["Sys_MapAttr"]; foreach (DataRow dr in dtMapAttr.Rows) { string lgType = dr["LGType"].ToString(); if (lgType.Equals("2") == false) { continue; } string UIIsEnable = dr["UIIsEnable"].ToString(); if (UIIsEnable.Equals("0") == true) { continue; } string uiBindKey = dr["UIBindKey"].ToString(); if (DataType.IsNullOrEmpty(uiBindKey) == true) { string myPK = dr["MyPK"].ToString(); /*如果是空的*/ throw new Exception("@属性字段数据不完整,流程:" + fl.No + fl.Name + ",节点:" + nd.NodeID + nd.Name + ",属性:" + myPK + ",的UIBindKey IsNull "); } // 判断是否存在. if (myds.Tables.Contains(uiBindKey) == true) { continue; } myds.Tables.Add(BP.Sys.PubClass.GetDataTableByUIBineKey(uiBindKey)); } #endregion End把外键表加入DataSet #region 把流程信息放入里面. //把流程信息表发送过去. GenerWorkFlow gwf = new GenerWorkFlow(); gwf.WorkID = workID; gwf.RetrieveFromDBSources(); myds.Tables.Add(gwf.ToDataTableField("WF_GenerWorkFlow")); if (gwf.WFState == WFState.Shift) { //如果是转发. BP.WF.ShiftWorks fws = new ShiftWorks(); fws.Retrieve(ShiftWorkAttr.WorkID, workID, ShiftWorkAttr.FK_Node, fk_node); myds.Tables.Add(fws.ToDataTableField("WF_ShiftWork")); } if (gwf.WFState == WFState.ReturnSta) { //如果是退回. ReturnWorks rts = new ReturnWorks(); rts.Retrieve(ReturnWorkAttr.WorkID, workID, ReturnWorkAttr.ReturnToNode, fk_node, ReturnWorkAttr.RDT); myds.Tables.Add(rts.ToDataTableField("WF_ReturnWork")); } if (gwf.WFState == WFState.HungUp) { //如果是挂起. HungUps hups = new HungUps(); hups.Retrieve(HungUpAttr.WorkID, workID, HungUpAttr.FK_Node, fk_node); myds.Tables.Add(hups.ToDataTableField("WF_HungUp")); } //if (gwf.WFState == WFState.Askfor) //{ // //如果是加签. // BP.WF.ShiftWorks fws = new ShiftWorks(); // fws.Retrieve(ShiftWorkAttr.WorkID, workID, ShiftWorkAttr.FK_Node, fk_node); // myds.Tables.Add(fws.ToDataTableField("WF_ShiftWork")); //} Int64 wfid = workID; if (fid != 0) { wfid = fid; } //放入track信息. Paras ps = new Paras(); ps.SQL = "SELECT * FROM ND" + int.Parse(fk_flow) + "Track WHERE WorkID=" + BP.Sys.SystemConfig.AppCenterDBVarStr + "WorkID"; ps.Add("WorkID", wfid); DataTable dtNode = DBAccess.RunSQLReturnTable(ps); dtNode.TableName = "Track"; myds.Tables.Add(dtNode); //工作人员列表,用于审核组件. ps = new Paras(); ps.SQL = "SELECT * FROM WF_GenerWorkerlist WHERE WorkID=" + BP.Sys.SystemConfig.AppCenterDBVarStr + "WorkID"; ps.Add("WorkID", wfid); DataTable dtGenerWorkerlist = DBAccess.RunSQLReturnTable(ps); dtGenerWorkerlist.TableName = "WF_GenerWorkerlist"; myds.Tables.Add(dtGenerWorkerlist); //放入CCList信息. 用于审核组件. ps = new Paras(); ps.SQL = "SELECT * FROM WF_CCList WHERE WorkID=" + BP.Sys.SystemConfig.AppCenterDBVarStr + "WorkID"; ps.Add("WorkID", wfid); DataTable dtCCList = DBAccess.RunSQLReturnTable(ps); dtCCList.TableName = "WF_CCList"; myds.Tables.Add(dtCCList); //放入WF_SelectAccper信息. 用于审核组件. ps = new Paras(); ps.SQL = "SELECT * FROM WF_SelectAccper WHERE WorkID=" + BP.Sys.SystemConfig.AppCenterDBVarStr + "WorkID"; ps.Add("WorkID", wfid); DataTable dtSelectAccper = DBAccess.RunSQLReturnTable(ps); dtSelectAccper.TableName = "WF_SelectAccper"; myds.Tables.Add(dtSelectAccper); //放入所有的节点信息. 用于审核组件. ps = new Paras(); ps.SQL = "SELECT * FROM WF_Node WHERE FK_Flow=" + BP.Sys.SystemConfig.AppCenterDBVarStr + "FK_Flow ORDER BY " + NodeAttr.Step; ps.Add("FK_Flow", fk_flow); DataTable dtNodes = DBAccess.RunSQLReturnTable(ps); dtNodes.TableName = "Nodes"; myds.Tables.Add(dtNodes); #endregion 把流程信息放入里面. return(myds); } catch (Exception ex) { Log.DebugWriteError(ex.StackTrace); throw new Exception(ex.Message); } }
public DataTable Search_Data() { DataSet ds = new DataSet(); #region 查询语句 MapData md = new MapData(this.FrmID); //取出来查询条件. BP.Sys.UserRegedit ur = new UserRegedit(); ur.MyPK = WebUser.No + "_" + this.FrmID + "_SearchAttrs"; ur.RetrieveFromDBSources(); GEEntitys rpts = new GEEntitys(this.FrmID); Attrs attrs = rpts.GetNewEntity.EnMap.Attrs; QueryObject qo = new QueryObject(rpts); #region 关键字字段. string keyWord = ur.SearchKey; if (md.GetParaBoolen("IsSearchKey") && DataType.IsNullOrEmpty(keyWord) == false && keyWord.Length >= 1) { Attr attrPK = new Attr(); foreach (Attr attr in attrs) { if (attr.IsPK) { attrPK = attr; break; } } int i = 0; string enumKey = ","; //求出枚举值外键. foreach (Attr attr in attrs) { switch (attr.MyFieldType) { case FieldType.Enum: enumKey = "," + attr.Key + "Text,"; break; case FieldType.FK: continue; default: break; } if (attr.MyDataType != DataType.AppString) { continue; } //排除枚举值关联refText. if (attr.MyFieldType == FieldType.RefText) { if (enumKey.Contains("," + attr.Key + ",") == true) { continue; } } if (attr.Key == "FK_Dept") { continue; } i++; if (i == 1) { /* 第一次进来。 */ qo.addLeftBracket(); if (SystemConfig.AppCenterDBVarStr == "@" || SystemConfig.AppCenterDBVarStr == "?") { qo.AddWhere(attr.Key, " LIKE ", SystemConfig.AppCenterDBType == DBType.MySQL ? (" CONCAT('%'," + SystemConfig.AppCenterDBVarStr + "SKey,'%')") : (" '%'+" + SystemConfig.AppCenterDBVarStr + "SKey+'%'")); } else { qo.AddWhere(attr.Key, " LIKE ", " '%'||" + SystemConfig.AppCenterDBVarStr + "SKey||'%'"); } continue; } qo.addOr(); if (SystemConfig.AppCenterDBVarStr == "@" || SystemConfig.AppCenterDBVarStr == "?") { qo.AddWhere(attr.Key, " LIKE ", SystemConfig.AppCenterDBType == DBType.MySQL ? ("CONCAT('%'," + SystemConfig.AppCenterDBVarStr + "SKey,'%')") : ("'%'+" + SystemConfig.AppCenterDBVarStr + "SKey+'%'")); } else { qo.AddWhere(attr.Key, " LIKE ", "'%'||" + SystemConfig.AppCenterDBVarStr + "SKey||'%'"); } } qo.MyParas.Add("SKey", keyWord); qo.addRightBracket(); } else { qo.AddHD(); } #endregion 关键字段查询 #region 时间段的查询 if (md.GetParaInt("DTSearchWay") != (int)DTSearchWay.None && DataType.IsNullOrEmpty(ur.DTFrom) == false) { string dtFrom = ur.DTFrom; // this.GetTBByID("TB_S_From").Text.Trim().Replace("/", "-"); string dtTo = ur.DTTo; // this.GetTBByID("TB_S_To").Text.Trim().Replace("/", "-"); //按日期查询 if (md.GetParaInt("DTSearchWay") == (int)DTSearchWay.ByDate) { qo.addAnd(); qo.addLeftBracket(); dtTo += " 23:59:59"; qo.SQL = md.GetParaString("DTSearchKey") + " >= '" + dtFrom + "'"; qo.addAnd(); qo.SQL = md.GetParaString("DTSearchKey") + " <= '" + dtTo + "'"; qo.addRightBracket(); } if (md.GetParaInt("DTSearchWay") == (int)DTSearchWay.ByDateTime) { //取前一天的24:00 if (dtFrom.Trim().Length == 10) //2017-09-30 { dtFrom += " 00:00:00"; } if (dtFrom.Trim().Length == 16) //2017-09-30 00:00 { dtFrom += ":00"; } dtFrom = DateTime.Parse(dtFrom).AddDays(-1).ToString("yyyy-MM-dd") + " 24:00"; if (dtTo.Trim().Length < 11 || dtTo.Trim().IndexOf(' ') == -1) { dtTo += " 24:00"; } qo.addAnd(); qo.addLeftBracket(); qo.SQL = md.GetParaString("DTSearchKey") + " >= '" + dtFrom + "'"; qo.addAnd(); qo.SQL = md.GetParaString("DTSearchKey") + " <= '" + dtTo + "'"; qo.addRightBracket(); } } #endregion 时间段的查询 #region 外键或者枚举的查询 //获得关键字. AtPara ap = new AtPara(ur.Vals); foreach (string str in ap.HisHT.Keys) { var val = ap.GetValStrByKey(str); if (val.Equals("all")) { continue; } qo.addAnd(); qo.addLeftBracket(); qo.AddWhere(str, ap.GetValStrByKey(str)); qo.addRightBracket(); } #endregion 外键或者枚举的查询 #endregion 查询语句 qo.addOrderBy("OID"); return(qo.DoQueryToTable()); }
/// <summary> /// 仅获取表单数据 /// </summary> /// <param name="enName"></param> /// <param name="pkval"></param> /// <param name="atParas"></param> /// <param name="specDtlFrmID"></param> /// <returns></returns> private static DataSet GenerDBForVSTOExcelFrmModelOfEntity(string enName, object pkval, string atParas, string specDtlFrmID = null) { DataSet myds = new DataSet(); // 创建实体.. Entities myens = BP.En.ClassFactory.GetEns(enName + "s"); #region 主表 Entity en = myens.GetNewEntity; en.PKVal = pkval; en.RetrieveFromDBSources(); //设置外部传入的默认值. if (BP.Sys.SystemConfig.IsBSsystem == true) { // 处理传递过来的参数。 foreach (string k in System.Web.HttpContext.Current.Request.QueryString.AllKeys) { en.SetValByKey(k, System.Web.HttpContext.Current.Request.QueryString[k]); } } //主表数据放入集合. DataTable mainTable = en.ToDataTableField(); mainTable.TableName = "MainTable"; myds.Tables.Add(mainTable); #region 主表 Sys_MapData string sql = "SELECT * FROM Sys_MapData WHERE 1=2 "; DataTable dt = BP.DA.DBAccess.RunSQLReturnTable(sql); dt.TableName = "Sys_MapData"; Map map = en.EnMapInTime; DataRow dr = dt.NewRow(); dr[MapDataAttr.No] = enName; dr[MapDataAttr.Name] = map.EnDesc; dr[MapDataAttr.PTable] = map.PhysicsTable; dt.Rows.Add(dr); myds.Tables.Add(dt); #endregion 主表 Sys_MapData #region 主表 Sys_MapAttr sql = "SELECT * FROM Sys_MapAttr WHERE 1=2 "; dt = BP.DA.DBAccess.RunSQLReturnTable(sql); dt.TableName = "Sys_MapAttr"; foreach (Attr attr in map.Attrs) { dr = dt.NewRow(); dr[MapAttrAttr.MyPK] = enName + "_" + attr.Key; dr[MapAttrAttr.Name] = attr.Desc; dr[MapAttrAttr.MyDataType] = attr.MyDataType; //数据类型. dr[MapAttrAttr.MinLen] = attr.MinLength; //最小长度. dr[MapAttrAttr.MaxLen] = attr.MaxLength; //最大长度. // 设置他的逻辑类型. dr[MapAttrAttr.LGType] = 0; //逻辑类型. switch (attr.MyFieldType) { case FieldType.Enum: dr[MapAttrAttr.LGType] = 1; dr[MapAttrAttr.UIBindKey] = attr.UIBindKey; //增加枚举字段. if (myds.Tables.Contains(attr.UIBindKey) == false) { string mysql = "SELECT IntKey AS No, Lab as Name FROM Sys_Enum WHERE EnumKey='" + attr.UIBindKey + "' ORDER BY IntKey "; DataTable dtEnum = DBAccess.RunSQLReturnTable(mysql); dtEnum.TableName = attr.UIBindKey; myds.Tables.Add(dtEnum); } break; case FieldType.FK: dr[MapAttrAttr.LGType] = 2; Entities ens = attr.HisFKEns; dr[MapAttrAttr.UIBindKey] = ens.ToString(); //把外键字段也增加进去. if (myds.Tables.Contains(ens.ToString()) == false && attr.UIIsReadonly == false) { ens.RetrieveAll(); DataTable mydt = ens.ToDataTableDescField(); mydt.TableName = ens.ToString(); myds.Tables.Add(mydt); } break; default: break; } // 设置控件类型. dr[MapAttrAttr.UIContralType] = (int)attr.UIContralType; dt.Rows.Add(dr); } myds.Tables.Add(dt); #endregion 主表 Sys_MapAttr #region //主表 Sys_MapExt 扩展属性 ////主表的配置信息. //sql = "SELECT * FROM Sys_MapExt WHERE 1=2"; //dt = BP.DA.DBAccess.RunSQLReturnTable(sql); //dt.TableName = "Sys_MapExt"; //myds.Tables.Add(dt); #endregion //主表 Sys_MapExt 扩展属性 #endregion #region 从表 foreach (EnDtl item in map.Dtls) { #region 把从表的数据放入集合. Entities dtls = item.Ens; QueryObject qo = qo = new QueryObject(dtls); if (dtls.ToString().Contains("CYSheBeiUse") == true) { qo.addOrderBy("RDT"); //按照日期进行排序,不用也可以. } qo.AddWhere(item.RefKey, pkval); DataTable dtDtl = qo.DoQueryToTable(); dtDtl.TableName = item.EnsName; //修改明细表的名称. myds.Tables.Add(dtDtl); //加入这个明细表. #endregion 把从表的数据放入. #region 从表 Sys_MapDtl (相当于mapdata) Entity dtl = dtls.GetNewEntity; map = dtl.EnMap; //明细表的 描述 . sql = "SELECT * FROM Sys_MapDtl WHERE 1=2"; dt = BP.DA.DBAccess.RunSQLReturnTable(sql); dt.TableName = "Sys_MapDtl_For_" + item.EnsName; dr = dt.NewRow(); dr[MapDtlAttr.No] = item.EnsName; dr[MapDtlAttr.Name] = item.Desc; dr[MapDtlAttr.PTable] = dtl.EnMap.PhysicsTable; dt.Rows.Add(dr); myds.Tables.Add(dt); #endregion 从表 Sys_MapDtl (相当于mapdata) #region 明细表 Sys_MapAttr sql = "SELECT * FROM Sys_MapAttr WHERE 1=2"; dt = BP.DA.DBAccess.RunSQLReturnTable(sql); dt.TableName = "Sys_MapAttr_For_" + item.EnsName; foreach (Attr attr in map.Attrs) { dr = dt.NewRow(); dr[MapAttrAttr.MyPK] = enName + "_" + attr.Key; dr[MapAttrAttr.Name] = attr.Desc; dr[MapAttrAttr.MyDataType] = attr.MyDataType; //数据类型. dr[MapAttrAttr.MinLen] = attr.MinLength; //最小长度. dr[MapAttrAttr.MaxLen] = attr.MaxLength; //最大长度. // 设置他的逻辑类型. dr[MapAttrAttr.LGType] = 0; //逻辑类型. switch (attr.MyFieldType) { case FieldType.Enum: dr[MapAttrAttr.LGType] = 1; dr[MapAttrAttr.UIBindKey] = attr.UIBindKey; //增加枚举字段. if (myds.Tables.Contains(attr.UIBindKey) == false) { string mysql = "SELECT IntKey AS No, Lab as Name FROM Sys_Enum WHERE EnumKey='" + attr.UIBindKey + "' ORDER BY IntKey "; DataTable dtEnum = DBAccess.RunSQLReturnTable(mysql); dtEnum.TableName = attr.UIBindKey; myds.Tables.Add(dtEnum); } break; case FieldType.FK: dr[MapAttrAttr.LGType] = 2; Entities ens = attr.HisFKEns; dr[MapAttrAttr.UIBindKey] = ens.ToString(); //把外键字段也增加进去. if (myds.Tables.Contains(ens.ToString()) == false && attr.UIIsReadonly == false) { ens.RetrieveAll(); DataTable mydt = ens.ToDataTableDescField(); mydt.TableName = ens.ToString(); myds.Tables.Add(mydt); } break; default: break; } // 设置控件类型. dr[MapAttrAttr.UIContralType] = (int)attr.UIContralType; dt.Rows.Add(dr); } myds.Tables.Add(dt); #endregion 明细表 Sys_MapAttr } #endregion return(myds); }
/// <summary> /// 仅获取表单数据 /// </summary> /// <param name="frmID">表单ID</param> /// <param name="pkval">主键</param> /// <param name="atParas">参数</param> /// <param name="specDtlFrmID">指定明细表的参数,如果为空就标识主表数据,否则就是从表数据.</param> /// <returns>数据</returns> public static DataSet GenerDBForVSTOExcelFrmModel(string frmID, object pkval, string atParas, string specDtlFrmID = null) { //如果是一个实体类. if (frmID.Contains("BP.")) { // 执行map同步. Entities ens = BP.En.ClassFactory.GetEns(frmID + "s"); Entity en = ens.GetNewEntity; en.DTSMapToSys_MapData(); return(GenerDBForVSTOExcelFrmModelOfEntity(frmID, pkval, atParas, specDtlFrmID = null)); //上面这行代码的解释(2017-04-25): //若不加上这行,代码执行到“ MapData md = new MapData(frmID); ”会报错: //@没有找到记录[表单注册表 Sys_MapData, [ 主键=No 值=BP.LI.BZQX ]记录不存在,请与管理员联系, 或者确认输入错误.@在Entity(BP.Sys.MapData)查询期间出现错误@ 在 BP.En.Entity.Retrieve() 位置 D:\ccflow\Components\BP.En30\En\Entity.cs:行号 1051 //即使加上: //frmID = frmID.Substring(0, frmID.Length - 1); //也会出现该问题 //2017-04-25 15:26:34:new MapData(frmID)应传入“BZQX”,但考虑到 GenerDBForVSTOExcelFrmModelOfEntity()运行稳定,暂不采用『统一执行下方代码』的方案。 } //数据容器,就是要返回的对象. DataSet myds = new DataSet(); //映射实体. MapData md = new MapData(frmID); //实体. GEEntity wk = new GEEntity(frmID); wk.OID = int.Parse(pkval.ToString()); if (wk.RetrieveFromDBSources() == 0) { wk.Insert(); } //加载事件. md.DoEvent(FrmEventList.FrmLoadBefore, wk, null); //把参数放入到 En 的 Row 里面。 if (DataType.IsNullOrEmpty(atParas) == false) { AtPara ap = new AtPara(atParas); foreach (string key in ap.HisHT.Keys) { if (wk.Row.ContainsKey(key) == true) //有就该变. { wk.Row[key] = ap.GetValStrByKey(key); } else { wk.Row.Add(key, ap.GetValStrByKey(key)); //增加他. } } } //属性. MapExt me = null; DataTable dtMapAttr = null; MapExts mes = null; #region 表单模版信息.(含主、从表的,以及从表的枚举/外键相关数据). //增加表单字段描述. string sql = "SELECT * FROM Sys_MapData WHERE No='" + frmID + "' "; DataTable dt = BP.DA.DBAccess.RunSQLReturnTable(sql); dt.TableName = "Sys_MapData"; myds.Tables.Add(dt); //增加表单字段描述. sql = "SELECT * FROM Sys_MapAttr WHERE FK_MapData='" + frmID + "' "; dt = BP.DA.DBAccess.RunSQLReturnTable(sql); dt.TableName = "Sys_MapAttr"; myds.Tables.Add(dt); //增加从表信息. sql = "SELECT * FROM Sys_MapDtl WHERE FK_MapData='" + frmID + "' "; dt = BP.DA.DBAccess.RunSQLReturnTable(sql); dt.TableName = "Sys_MapDtl"; myds.Tables.Add(dt); //主表的配置信息. sql = "SELECT * FROM Sys_MapExt WHERE FK_MapData='" + frmID + "'"; dt = BP.DA.DBAccess.RunSQLReturnTable(sql); dt.TableName = "Sys_MapExt"; myds.Tables.Add(dt); #region 加载 从表表单模版信息.(含 从表的枚举/外键相关数据) foreach (MapDtl item in md.MapDtls) { #region 返回指定的明细表的数据. if (DataType.IsNullOrEmpty(specDtlFrmID) == true) { } else { if (item.No != specDtlFrmID) { continue; } } #endregion 返回指定的明细表的数据. //明细表的主表描述 sql = "SELECT * FROM Sys_MapDtl WHERE No='" + item.No + "'"; dt = BP.DA.DBAccess.RunSQLReturnTable(sql); dt.TableName = "Sys_MapDtl_For_" + (string.IsNullOrWhiteSpace(item.Alias) ? item.No : item.Alias); myds.Tables.Add(dt); //明细表的表单描述 sql = "SELECT * FROM Sys_MapAttr WHERE FK_MapData='" + item.No + "'"; dtMapAttr = BP.DA.DBAccess.RunSQLReturnTable(sql); dtMapAttr.TableName = "Sys_MapAttr_For_" + (string.IsNullOrWhiteSpace(item.Alias) ? item.No : item.Alias); myds.Tables.Add(dtMapAttr); //明细表的配置信息. sql = "SELECT * FROM Sys_MapExt WHERE FK_MapData='" + item.No + "'"; dt = BP.DA.DBAccess.RunSQLReturnTable(sql); dt.TableName = "Sys_MapExt_For_" + (string.IsNullOrWhiteSpace(item.Alias) ? item.No : item.Alias); myds.Tables.Add(dt); #region 从表的 外键表/枚举 mes = new MapExts(item.No); foreach (DataRow dr in dtMapAttr.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; myds.Tables.Add(dtEnum); continue; } #endregion string UIIsEnable = dr["UIIsEnable"].ToString(); if (UIIsEnable.Equals("0")) //字段未启用 { continue; } #region 外键字段 // 检查是否有下拉框自动填充。 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); dt = DBAccess.RunSQLReturnTable(fullSQL); dt.TableName = mypk; myds.Tables.Add(dt); continue; } #endregion 处理下拉框数据范围. else //无范围限制时 { // 判断是否存在. if (myds.Tables.Contains(uiBindKey) == true) { continue; } myds.Tables.Add(BP.Sys.PubClass.GetDataTableByUIBineKey(uiBindKey)); } #endregion 外键字段 } #endregion 从表的 外键表/枚举 } #endregion 加载 从表表单模版信息.(含 从表的枚举/外键相关数据) #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]); } } // 执行表单事件.. string msg = md.DoEvent(FrmEventList.FrmLoadBefore, wk); if (DataType.IsNullOrEmpty(msg) == false) { throw new Exception("err@错误:" + msg); } //重设默认值. wk.ResetDefaultVal(); //执行装载填充. me = new MapExt(); if (me.Retrieve(MapExtAttr.ExtType, MapExtXmlList.PageLoadFull, MapExtAttr.FK_MapData, frmID) == 1) { //执行通用的装载方法. MapAttrs attrs = new MapAttrs(frmID); MapDtls dtls = new MapDtls(frmID); wk = BP.WF.Glo.DealPageLoadFull(wk, me, attrs, dtls) as GEEntity; } //增加主表数据. DataTable mainTable = wk.ToDataTableField(md.No); mainTable.TableName = "MainTable"; myds.Tables.Add(mainTable); #endregion 主表数据 #region 从表数据 foreach (MapDtl dtl in md.MapDtls) { #region 返回指定的明细表的数据. if (DataType.IsNullOrEmpty(specDtlFrmID) == true) { } else { if (dtl.No != specDtlFrmID) { continue; } } #endregion 返回指定的明细表的数据. 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 { dtls.GetNewEntity.CheckPhysicsTable(); } //条件过滤. if (dtl.FilterSQLExp != "") { string[] strs = dtl.FilterSQLExp.Split('='); qo.addAnd(); qo.AddWhere(strs[0], strs[1]); } //从表 DataTable dtDtl = qo.DoQueryToTable(); // 为明细表设置默认值. MapAttrs dtlAttrs = new MapAttrs(dtl.No); foreach (MapAttr attr in dtlAttrs) { //处理它的默认值. if (attr.DefValReal.Contains("@") == false) { continue; } foreach (DataRow dr in dtDtl.Rows) { dr[attr.KeyOfEn] = attr.DefVal; } } dtDtl.TableName = string.IsNullOrWhiteSpace(dtl.Alias) ? dtl.No : dtl.Alias; //edited by liuxc,2017-10-10.如果有别名,则使用别名,没有则使用No myds.Tables.Add(dtDtl); //加入这个明细表, 如果没有数据,xml体现为空. } #endregion 从表数据 #region 主表的 外键表/枚举 dtMapAttr = myds.Tables["Sys_MapAttr"]; mes = md.MapExts; foreach (DataRow dr in dtMapAttr.Rows) { string uiBindKey = dr["UIBindKey"].ToString(); string myPK = dr["MyPK"].ToString(); string lgType = dr["LGType"].ToString(); 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; myds.Tables.Add(dtEnum); continue; } if (lgType.Equals("2") == false) { continue; } string UIIsEnable = dr["UIIsEnable"].ToString(); if (UIIsEnable.Equals("0")) { continue; } // 检查是否有下拉框自动填充。 string keyOfEn = dr["KeyOfEn"].ToString(); string fk_mapData = dr["FK_MapData"].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); dt = DBAccess.RunSQLReturnTable(fullSQL); dt.TableName = myPK; //可能存在隐患,如果多个字段,绑定同一个表,就存在这样的问题. myds.Tables.Add(dt); continue; } #endregion 处理下拉框数据范围. dt = BP.Sys.PubClass.GetDataTableByUIBineKey(uiBindKey); dt.TableName = uiBindKey; myds.Tables.Add(dt); } #endregion 主表的 外键表/枚举 //返回生成的dataset. return(myds); }
/// <summary> /// Entities 的基本应用. /// </summary> public void EntitiesBaseApp() { #region 查询全部 /* 查询全部分为两种方式,1 从缓存里查询全部。2,从数据库查询全部。 */ Emps emps = new Emps(); int num = emps.RetrieveAll(); //从缓存里查询全部数据. this.Response.Write("RetrieveAll查询出来(" + num + ")个"); foreach (Emp emp in emps) { this.Response.Write("<hr>人员名称:" + emp.Name); this.Response.Write("<br>人员编号:" + emp.No); this.Response.Write("<br>部门编号:" + emp.FK_Dept); this.Response.Write("<br>部门名称:" + emp.FK_DeptText); } //把entities 数据转入到DataTable里。 DataTable empsDTfield = emps.ToDataTableField(); //以英文字段做为列名。 DataTable empsDTDesc = emps.ToDataTableDesc(); //以中文字段做为列名。 // 从数据库里查询全部。 emps = new Emps(); num = emps.RetrieveAllFromDBSource(); this.Response.Write("RetrieveAllFromDBSource查询出来(" + num + ")个"); foreach (Emp emp in emps) { this.Response.Write("<hr>人员名称:" + emp.Name); this.Response.Write("<br>人员编号:" + emp.No); this.Response.Write("<br>部门编号:" + emp.FK_Dept); this.Response.Write("<br>部门名称:" + emp.FK_DeptText); } #endregion 查询全部 #region 条件查询 // 单个条件查询。 Emps myEmps = new Emps(); QueryObject qo = new QueryObject(myEmps); qo.AddWhere(EmpAttr.FK_Dept, "01"); qo.addOrderBy(EmpAttr.No); // 增加排序规则,Order OrderByDesc, addOrderByDesc addOrderByRandom. num = qo.DoQuery(); // 返回查询的个数. DataTable mydt = qo.DoQueryToTable(); // 查询出来的数据转入到datatable里。. this.Response.Write("查询出来(" + num + ")个,部门编号=01的人员。"); foreach (Emp emp in myEmps) { this.Response.Write("<hr>人员名称:" + emp.Name); this.Response.Write("<br>人员编号:" + emp.No); this.Response.Write("<br>部门编号:" + emp.FK_Dept); this.Response.Write("<br>部门名称:" + emp.FK_DeptText); } Emps myEmp1s = new Emps(); myEmp1s.Retrieve(EmpAttr.FK_Dept, "01"); foreach (Emp item in myEmp1s) { this.Response.Write("<hr>人员名称:" + item.Name); this.Response.Write("<br>人员编号:" + item.No); this.Response.Write("<br>部门编号:" + item.FK_Dept); this.Response.Write("<br>部门名称:" + item.FK_DeptText); } // 多个条件查询。 myEmps = new Emps(); qo = new QueryObject(myEmps); qo.AddWhere(EmpAttr.FK_Dept, "01"); qo.addAnd(); qo.AddWhere(EmpAttr.No, "guobaogen"); num = qo.DoQuery(); // 返回查询的个数. this.Response.Write("查询出来(" + num + ")个,部门编号=01并且编号=guobaogen的人员。"); foreach (Emp emp in myEmps) { this.Response.Write("<hr>人员名称:" + emp.Name); this.Response.Write("<br>人员编号:" + emp.No); this.Response.Write("<br>部门编号:" + emp.FK_Dept); this.Response.Write("<br>部门名称:" + emp.FK_DeptText); } // 具有括号表达式的查询。 myEmps = new Emps(); qo = new QueryObject(myEmps); qo.addLeftBracket(); // 加上左括号. qo.AddWhere(EmpAttr.FK_Dept, "01"); qo.addAnd(); qo.AddWhere(EmpAttr.No, "guobaogen"); qo.addRightBracket(); // 加上右括号. num = qo.DoQuery(); // 返回查询的个数. this.Response.Write("查询出来(" + num + ")个,部门编号=01并且编号=guobaogen的人员。"); foreach (Emp emp in myEmps) { this.Response.Write("<hr>人员名称:" + emp.Name); this.Response.Write("<br>人员编号:" + emp.No); this.Response.Write("<br>部门编号:" + emp.FK_Dept); this.Response.Write("<br>部门名称:" + emp.FK_DeptText); } // 具有where in 方式的查询。 myEmps = new Emps(); qo = new QueryObject(myEmps); qo.AddWhereInSQL(EmpAttr.No, "SELECT No FROM Port_Emp WHERE FK_Dept='02'"); num = qo.DoQuery(); // 返回查询的个数. this.Response.Write("查询出来(" + num + ")个,WHERE IN (SELECT No FROM Port_Emp WHERE FK_Dept='02')人员。"); foreach (Emp emp in myEmps) { this.Response.Write("<hr>人员名称:" + emp.Name); this.Response.Write("<br>人员编号:" + emp.No); this.Response.Write("<br>部门编号:" + emp.FK_Dept); this.Response.Write("<br>部门名称:" + emp.FK_DeptText); } // 具有LIKE 方式的查询。 myEmps = new Emps(); qo = new QueryObject(myEmps); qo.AddWhere(EmpAttr.No, " LIKE ", "guo"); num = qo.DoQuery(); // 返回查询的个数. this.Response.Write("查询出来(" + num + ")个,人员编号包含guo的人员。"); foreach (Emp emp in myEmps) { this.Response.Write("<hr>人员名称:" + emp.Name); this.Response.Write("<br>人员编号:" + emp.No); this.Response.Write("<br>部门编号:" + emp.FK_Dept); this.Response.Write("<br>部门名称:" + emp.FK_DeptText); } #endregion 条件查询 #region 集合业务处理. myEmps = new Emps(); myEmps.RetrieveAll(); // 查询全部出来. // 遍历集合是常用的处理方法。 foreach (Emp emp in myEmps) { this.Response.Write("<hr>人员名称:" + emp.Name); this.Response.Write("<br>人员编号:" + emp.No); this.Response.Write("<br>部门编号:" + emp.FK_Dept); this.Response.Write("<br>部门名称:" + emp.FK_DeptText); } // 判断是否包含是指定的主键值. bool isHave = myEmps.Contains("Name", "郭宝庚"); //判断是否集合里面包含Name=郭宝庚的实体. bool isHave1 = myEmps.Contains("guobaogeng"); //判断是否集合里面主键No=guobaogeng的实体. // 获取Name=郭宝庚的实体,如果没有就返回空。 Emp empFind = myEmps.GetEntityByKey("Name", "郭宝庚") as Emp; if (empFind == null) { this.Response.Write("<br>没有找到: Name =郭宝庚 的实体."); } else { this.Response.Write("<br>已经找到了: Name =郭宝庚 的实体. 他的部门编号=" + empFind.FK_Dept + ",部门名称=" + empFind.FK_DeptText); } // 批量更新实体。 myEmps.Update(); // 等同于下一个循环。 foreach (Emp emp in myEmps) { emp.Update(); } // 删除实体. myEmps.Delete(); // 等同于下一个循环。 foreach (Emp emp in myEmps) { emp.Delete(); } // 执行数据库删除,类于执行 DELETE Port_Emp WHERE FK_Dept='01' 的sql. myEmps.Delete("FK_Dept", "01"); #endregion }
private void ToolBar1_ButtonClick(object sender, System.EventArgs e) { try { var btn = (LinkBtn)sender; switch (btn.ID) { case NamesOfBtn.Export: //数据导出. case NamesOfBtn.Excel: //数据导出 MapData md = new MapData(this.RptNo); Entities ens = md.HisEns; Entity en = ens.GetNewEntity; QueryObject qo = new QueryObject(ens); qo = this.ToolBar1.GetnQueryObject(ens, en); DataTable dt = qo.DoQueryToTable(); DataTable myDT = new DataTable(); MapAttrs attrs = new MapAttrs(this.RptNo); foreach (MapAttr attr in attrs) { myDT.Columns.Add(new DataColumn(attr.Name, typeof(string))); } foreach (DataRow dr in dt.Rows) { DataRow myDR = myDT.NewRow(); foreach (MapAttr attr in attrs) { myDR[attr.Name] = dr[attr.Field]; } myDT.Rows.Add(myDR); } try { ExportDGToExcel(myDT, en.EnDesc); } catch (Exception ex) { throw new Exception("数据没有正确导出可能的原因之一是:系统管理员没正确的安装Excel组件,请通知他,参考安装说明书解决。@系统异常信息:" + ex.Message); } this.SetDGData(); return; default: this.PageIdx = 1; this.SetDGData(1); this.ToolBar1.SaveSearchState(this.RptNo, null); return; } } catch (Exception ex) { if (!(ex is System.Threading.ThreadAbortException)) { this.ResponseWriteRedMsg(ex); //在这里显示错误 } } }
public void BindData() { string ensname = this.Request.QueryString["EnsName"]; if (ensname == null) { ensname = this.Request.QueryString["EnsName"]; } Entities ens = BP.En.ClassFactory.GetEns(ensname); Entity en = ens.GetNewEntity; QueryObject qo = new QueryObject(ens); string[] strs = this.Request.RawUrl.Split('&'); string[] strs1 = this.Request.RawUrl.Split('&'); foreach (string str in strs) { if (str.IndexOf("EnsName") != -1) { continue; } string[] mykey = str.Split('='); string key = mykey[0]; if (key == "OID" || key == "MyPK") { continue; } if (key == "FK_Dept") { this.FK_Dept = mykey[1]; continue; } if (en.EnMap.Attrs.Contains(key) == false) { continue; } if (mykey[1] == "mvals") { //如果用户多项选择了,就要找到它的选择项目. UserRegedit sUr = new UserRegedit(); sUr.MyPK = WebUser.No + this.EnsName + "_SearchAttrs"; sUr.RetrieveFromDBSources(); /* 如果是多选值 */ string cfgVal = sUr.MVals; AtPara ap = new AtPara(cfgVal); string instr = ap.GetValStrByKey(key); string val = ""; if (instr == null || instr == "") { if (key == "FK_Dept" || key == "FK_Unit") { if (key == "FK_Dept") { val = WebUser.FK_Dept; } } else { continue; } } else { instr = instr.Replace("..", "."); instr = instr.Replace(".", "','"); instr = instr.Substring(2); instr = instr.Substring(0, instr.Length - 2); qo.AddWhereIn(mykey[0], instr); } } else { qo.AddWhere(mykey[0], mykey[1]); } qo.addAnd(); } if (this.FK_Dept != null && (this.Request.QueryString["FK_Emp"] == null || this.Request.QueryString["FK_Emp"] == "all")) { if (this.FK_Dept.Length == 2) { qo.AddWhere("FK_Dept", " = ", "all"); qo.addAnd(); } else { if (this.FK_Dept.Length == 8) { //if (this.Request.QueryString["ByLike"] != "1") qo.AddWhere("FK_Dept", " = ", this.FK_Dept); } else { qo.AddWhere("FK_Dept", " like ", this.FK_Dept + "%"); } qo.addAnd(); } } qo.AddHD(); if (this.DoType == "Exp") { /*如果是导出,就把它导出到excel.*/ this.ExportDGToExcel(qo.DoQueryToTable(), en.EnMap, en.EnDesc + "数据导出"); this.WinClose(); return; } int num = qo.DoQuery(); // Log.DebugWriteWarning(qo.SQL); // Log.DefaultLogWriteLineError(qo.SQL); this.ShowTitle = ens.GetNewEntity.EnMap.EnDesc + ",数据:" + num + " 条。"; this.UCSys1.DataPanelDtl(ens, null); }
public string GenerWorkNode(string fk_flow, int fk_node, Int64 workID, Int64 fid, string userNo) { try { Emp emp = new Emp(userNo); BP.Web.WebUser.SignInOfGener(emp); MapData md = new MapData(); md.No = "ND" + fk_node; if (md.RetrieveFromDBSources() == 0) { throw new Exception("装载错误,该表单ID=" + md.No + "丢失,请修复一次流程重新加载一次."); } DataSet myds = md.GenerHisDataSet(); // 节点数据. Node nd = new Node(fk_node); myds.Tables.Add(nd.ToDataTableField("WF_Node")); //节点标签数据. BtnLab btnLab = new BtnLab(fk_node); myds.Tables.Add(btnLab.ToDataTableField("WF_BtnLab")); // 流程数据. Flow fl = new Flow(fk_flow); myds.Tables.Add(fl.ToDataTableField("WF_Flow")); //.工作数据放里面去, 放进去前执行一次装载前填充事件. BP.WF.Work wk = nd.HisWork; wk.OID = workID; wk.RetrieveFromDBSources(); wk.ResetDefaultVal(); // 执行一次装载前填充. string msg = md.FrmEvents.DoEventNode(FrmEventList.FrmLoadBefore, wk); if (string.IsNullOrEmpty(msg) == false) { return(msg); } myds.Tables.Add(wk.ToDataTableField("Main")); #region 获取明细表数据,并把它加入dataset里. if (md.MapDtls.Count > 0) { foreach (MapDtl dtl in md.MapDtls) { GEDtls dtls = new GEDtls(dtl.No); QueryObject qo = null; try { qo = new QueryObject(dtl); switch (dtl.DtlOpenType) { case DtlOpenType.ForEmp: // 按人员来控制. qo.AddWhere(GEDtlAttr.RefPK, workID); qo.addAnd(); qo.AddWhere(GEDtlAttr.Rec, WebUser.No); break; case DtlOpenType.ForWorkID: // 按工作ID来控制 qo.AddWhere(GEDtlAttr.RefPK, workID); break; case DtlOpenType.ForFID: // 按流程ID来控制. qo.AddWhere(GEDtlAttr.FID, workID); break; } } catch { dtls.GetNewEntity.CheckPhysicsTable(); } DataTable dtDtl = qo.DoQueryToTable(); dtDtl.TableName = dtl.No; //修改明细表的名称. myds.Tables.Add(dtDtl); //加入这个明细表. } } #endregion //把流程信息表发送过去. GenerWorkFlow gwf = new GenerWorkFlow(); gwf.WorkID = workID; myds.Tables.Add(gwf.ToDataTableField("WF_GenerWorkFlow")); if (gwf.WFState == WFState.Forward) { //如果是转发. BP.WF.ForwardWorks fws = new ForwardWorks(); fws.Retrieve(ForwardWorkAttr.WorkID, workID, ForwardWorkAttr.FK_Node, fk_node); myds.Tables.Add(fws.ToDataTableField("WF_ForwardWork")); } if (gwf.WFState == WFState.ReturnSta) { //如果是退回. ReturnWorks rts = new ReturnWorks(); rts.Retrieve(ReturnWorkAttr.WorkID, workID, ReturnWorkAttr.ReturnToNode, fk_node); myds.Tables.Add(rts.ToDataTableField("WF_ForwardWork")); } if (gwf.WFState == WFState.HungUp) { //如果是挂起. HungUps hups = new HungUps(); hups.Retrieve(HungUpAttr.WorkID, workID, HungUpAttr.FK_Node, fk_node); myds.Tables.Add(hups.ToDataTableField("WF_HungUp")); } //放入track信息. Paras ps = new Paras(); ps.SQL = "SELECT * FROM ND" + int.Parse(fk_flow) + "Track WHERE WorkID=" + BP.SystemConfig.AppCenterDBVarStr + "WorkID"; ps.Add("WorkID", workID); DataTable dt = DBAccess.RunSQLReturnTable(ps); dt.TableName = "Track"; myds.Tables.Add(dt); //写入数据. myds.WriteXml("c:\\sss.xml"); //转化成它所能识别的格式. return(Silverlight.DataSetConnector.Connector.ToXml(myds)); } catch (Exception ex) { Log.DebugWriteError(ex.StackTrace); return("@生成工作FK_Flow=" + fk_flow + ",FK_Node=" + fk_node + ",WorkID=" + workID + ",FID=" + fid + "错误,错误信息:" + ex.Message); } }
/// <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); }