public void BindData() { string ensname = this.Request.QueryString["EnsName"]; if (ensname == null) { ensname = this.Request.QueryString["EnsName"]; } Entities ens = DA.ClassFactory.GetEns(ensname); Entity en = ens.GetNewEntity; QueryObject qo = new QueryObject(ens); string[] strs = this.Request.RawUrl.Split('&'); string[] strs1 = this.Request.RawUrl.Split('&'); int i = 0; 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; } 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(); int num = qo.DoQuery(); // Log.DebugWriteWarning(qo.SQL); // Log.DefaultLogWriteLineError(qo.SQL); this.Label1.Text = this.GenerCaption(ens.GetNewEntity.EnMap.EnDesc + ",数据:" + num + " 条"); this.UCSys1.DataPanelDtl(ens, null); }
public void BindData() { string ensname = this.Request.QueryString["EnsName"]; if (ensname == null) { ensname = this.Request.QueryString["EnsName"]; } Entities ens = BP.DA.ClassFactory.GetEns(ensname); Entity en = ens.GetNewEntity; this.FK_Flow = ensname; this.FK_Flow = FK_Flow.Replace("Rpt", ""); this.FK_Flow = FK_Flow.Replace("ND", ""); this.FK_Flow = this.FK_Flow.PadLeft(3, '0'); QueryObject qo = new QueryObject(ens); string[] strs = this.Request.RawUrl.Split('&'); string[] strs1 = this.Request.RawUrl.Split('&'); int i = 0; 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; } 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(); #region 加上日期时间段. if (en.EnMap.DTSearchWay != DTSearchWay.None) { string field = en.EnMap.DTSearchKey; qo.addAnd(); qo.addLeftBracket(); if (en.EnMap.DTSearchWay == DTSearchWay.ByDate) { qo.AddWhere(field, " >= ", this.DTFrom + " 01:01"); qo.addAnd(); qo.AddWhere(field, " >= ", this.DTTo + " 23:59"); } else { qo.AddWhere(field, " >= ", this.DTFrom); qo.addAnd(); qo.AddWhere(field, " >= ", this.DTTo); } qo.addRightBracket(); } #endregion int num = qo.DoQuery(); this.DataPanelDtl(ens, null); }
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 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()); }
public string Search_Init() { DataSet ds = new DataSet(); #region 查询显示的列 MapAttrs mapattrs = new MapAttrs(); mapattrs.Retrieve(MapAttrAttr.FK_MapData, this.FrmID, MapAttrAttr.Idx); DataRow row = null; DataTable dt = new DataTable("Attrs"); dt.Columns.Add("KeyOfEn", typeof(string)); dt.Columns.Add("Name", typeof(string)); dt.Columns.Add("Width", typeof(int)); dt.Columns.Add("UIContralType", typeof(int)); dt.Columns.Add("LGType", typeof(int)); //设置标题、单据号位于开始位置 foreach (MapAttr attr in mapattrs) { string searchVisable = attr.atPara.GetValStrByKey("SearchVisable"); if (searchVisable == "0") { continue; } if (attr.UIVisible == false) { continue; } row = dt.NewRow(); row["KeyOfEn"] = attr.KeyOfEn; row["Name"] = attr.Name; row["Width"] = attr.UIWidthInt; row["UIContralType"] = attr.UIContralType; row["LGType"] = attr.LGType; dt.Rows.Add(row); } ds.Tables.Add(dt); #endregion 查询显示的列 #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 查询语句 //获得行数. ur.SetPara("RecCount", qo.GetCount()); ur.Save(); qo.DoQuery("OID", this.PageSize, this.PageIdx); DataTable mydt = rpts.ToDataTableField(); mydt.TableName = "DT"; ds.Tables.Add(mydt); //把数据加入里面. return(BP.Tools.Json.ToJson(ds)); }
/// <summary> /// 单据初始化 /// </summary> /// <returns></returns> public string RefBill_Init() { DataSet ds = new DataSet(); #region 查询显示的列 MapAttrs mapattrs = new MapAttrs(); mapattrs.Retrieve(MapAttrAttr.FK_MapData, this.FrmID, MapAttrAttr.Idx); DataRow row = null; DataTable dt = new DataTable("Attrs"); dt.Columns.Add("KeyOfEn", typeof(string)); dt.Columns.Add("Name", typeof(string)); dt.Columns.Add("Width", typeof(int)); dt.Columns.Add("UIContralType", typeof(int)); dt.Columns.Add("LGType", typeof(int)); //设置标题、单据号位于开始位置 foreach (MapAttr attr in mapattrs) { string searchVisable = attr.atPara.GetValStrByKey("SearchVisable"); if (searchVisable == "0") { continue; } if (attr.UIVisible == false) { continue; } row = dt.NewRow(); row["KeyOfEn"] = attr.KeyOfEn; row["Name"] = attr.Name; row["Width"] = attr.UIWidthInt; row["UIContralType"] = attr.UIContralType; row["LGType"] = attr.LGType; dt.Rows.Add(row); } ds.Tables.Add(dt); #endregion 查询显示的列 #region 查询语句 MapData md = new MapData(this.FrmID); GEEntitys rpts = new GEEntitys(this.FrmID); Attrs attrs = rpts.GetNewEntity.EnMap.Attrs; QueryObject qo = new QueryObject(rpts); #region 关键字字段. string keyWord = this.GetRequestVal("SearchKey"); if (DataType.IsNullOrEmpty(keyWord) == false && keyWord.Length >= 1) { qo.addLeftBracket(); if (SystemConfig.AppCenterDBVarStr == "@" || SystemConfig.AppCenterDBVarStr == "?") { qo.AddWhere("Title", " LIKE ", SystemConfig.AppCenterDBType == DBType.MySQL ? (" CONCAT('%'," + SystemConfig.AppCenterDBVarStr + "SKey,'%')") : (" '%'+" + SystemConfig.AppCenterDBVarStr + "SKey+'%'")); } else { qo.AddWhere("Title", " LIKE ", " '%'||" + SystemConfig.AppCenterDBVarStr + "SKey||'%'"); } qo.addOr(); if (SystemConfig.AppCenterDBVarStr == "@" || SystemConfig.AppCenterDBVarStr == "?") { qo.AddWhere("BillNo", " LIKE ", SystemConfig.AppCenterDBType == DBType.MySQL ? ("CONCAT('%'," + SystemConfig.AppCenterDBVarStr + "SKey,'%')") : ("'%'+" + SystemConfig.AppCenterDBVarStr + "SKey+'%'")); } else { qo.AddWhere("BillNo", " LIKE ", "'%'||" + SystemConfig.AppCenterDBVarStr + "SKey||'%'"); } qo.MyParas.Add("SKey", keyWord); qo.addRightBracket(); } else { qo.AddHD(); } #endregion 关键字段查询 #region 时间段的查询 string dtFrom = this.GetRequestVal("DTFrom"); string dtTo = this.GetRequestVal("DTTo"); if (DataType.IsNullOrEmpty(dtFrom) == false) { //取前一天的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 = " RDT>= '" + dtFrom + "'"; qo.addAnd(); qo.SQL = "RDT <= '" + dtTo + "'"; qo.addRightBracket(); } #endregion 时间段的查询 qo.DoQuery("OID", this.PageSize, this.PageIdx); #endregion DataTable mydt = rpts.ToDataTableField(); mydt.TableName = "DT"; ds.Tables.Add(mydt); //把数据加入里面. return(BP.Tools.Json.ToJson(ds)); }