public static int Retrieve(Entity en, string sql, Paras paras) { DataTable dt; switch (en.EnMap.EnDBUrl.DBUrlType) { case DBUrlType.AppCenterDSN: dt = DBAccess.RunSQLReturnTable(sql, paras); break; case DBUrlType.DBAccessOfMSMSSQL: dt = DBAccessOfMSMSSQL.RunSQLReturnTable(sql); break; case DBUrlType.DBAccessOfOracle: dt = DBAccessOfOracle.RunSQLReturnTable(sql); break; default: throw new Exception("@没有设置DB类型。"); } if (dt.Rows.Count == 0) { return(0); } Attrs attrs = en.EnMap.Attrs; EntityDBAccess.fullDate(dt, en, attrs); int i = dt.Rows.Count; dt.Dispose(); return(i); }
/// <summary> /// LoadAttrs /// </summary> /// <param name="attrs"></param> public void LoadAttrs(Attrs attrs) { this.Clear(); foreach (Attr attr in attrs) { switch (attr.MyDataType) { case BP.DA.DataType.AppInt: this.Add(attr.Key, int.Parse(attr.DefaultVal.ToString())); break; case BP.DA.DataType.AppFloat: this.Add(attr.Key, float.Parse(attr.DefaultVal.ToString())); break; case BP.DA.DataType.AppMoney: this.Add(attr.Key, decimal.Parse(attr.DefaultVal.ToString())); break; case BP.DA.DataType.AppDouble: this.Add(attr.Key, double.Parse(attr.DefaultVal.ToString())); break; default: this.Add(attr.Key, attr.DefaultVal); break; } } }
private static void fullDate(DataTable dt, Entity en, Attrs attrs) { foreach (Attr attr in attrs) { en.Row.SetValByKey(attr.Key, dt.Rows[0][attr.Key]); } }
public static int Retrieve(Entities ens, string sql) { try { DataTable dt = new DataTable(); switch (ens.GetNewEntity.EnMap.EnDBUrl.DBUrlType) { case DBUrlType.AppCenterDSN: dt = DBAccess.RunSQLReturnTable(sql); break; case DBUrlType.DBAccessOfMSMSSQL: dt = DBAccessOfMSMSSQL.RunSQLReturnTable(sql); break; case DBUrlType.DBAccessOfOracle: dt = DBAccessOfOracle.RunSQLReturnTable(sql); break; case DBUrlType.DBAccessOfOLE: dt = DBAccessOfOLE.RunSQLReturnTable(sql); break; default: throw new Exception("@没有设置DB类型。"); } if (dt.Rows.Count == 0) { return(0); } Map enMap = ens.GetNewEntity.EnMap; Attrs attrs = enMap.Attrs; //Entity en1 = ens.GetNewEntity; foreach (DataRow dr in dt.Rows) { Entity en = ens.GetNewEntity; //Entity en = en1.CreateInstance(); foreach (Attr attr in attrs) { en.Row.SetValByKey(attr.Key, dr[attr.Key]); } ens.AddEntity(en); } int i = dt.Rows.Count; dt.Dispose(); return(i); //return dt.Rows.Count; } catch (System.Exception ex) { // ens.GetNewEntity.CheckPhysicsTable(); throw new Exception("@在[" + ens.GetNewEntity.EnDesc + "]查询时出现错误:" + ex.Message); } }
public Attrs Clone() { Attrs attrs = new Attrs(); foreach (Attr attr in this) { attrs.Add(attr); } return(attrs); }
/// <summary> /// 执行 /// </summary> /// <param name="paras"></param> /// <returns></returns> public object Do(object[] paras) { string str = this.ClassMethodName.Trim(' ', ';', '.'); int pos = str.LastIndexOf("."); string clas = str.Substring(0, pos); string meth = str.Substring(pos, str.Length - pos).Trim('.', ' ', '(', ')'); if (this.HisEn == null) { this.HisEn = BP.En.ClassFactory.GetEn(clas); Attrs attrs = this.HisEn.EnMap.Attrs; //if (SystemConfig.IsBSsystem) //{ // //string val = BP.Sys.Glo.Request.QueryString["No"]; // //if (val == null) // //{ // // val = BP.Sys.Glo.Request.QueryString["PK"]; // //} // this.HisEn.PKVal = BP.Sys.Glo.Request.QueryString[this.HisEn.PK]; //} //else // this.HisEn.PKVal = this.PKVal; //this.HisEn.Retrieve(); } Type tp = this.HisEn.GetType(); MethodInfo mp = tp.GetMethod(meth); if (mp == null) { throw new Exception("@对象实例[" + tp.FullName + "]中没有找到方法[" + meth + "]!"); } try { return(mp.Invoke(this.HisEn, paras)); //调用由此 MethodInfo 实例反射的方法或构造函数。 } catch (System.Reflection.TargetException ex) { string strs = ""; if (paras == null) { throw new Exception(ex.Message); } else { foreach (object obj in paras) { strs += "para= " + obj.ToString() + " type=" + obj.GetType().ToString() + "\n<br>"; } } throw new Exception(ex.Message + " more info:" + strs); } }
public DataTable DoGroupReturnTable(Entity en, Attrs attrsOfGroupKey, Attr attrGroup, GroupWay gw, OrderWay ow) { switch (en.EnMap.EnDBUrl.DBType) { case DBType.Oracle: return(DoGroupReturnTableOracle(en, attrsOfGroupKey, attrGroup, gw, ow)); default: return(DoGroupReturnTableSqlServer(en, attrsOfGroupKey, attrGroup, gw, ow)); } }
/// <summary> /// 查询 /// </summary> /// <param name="en">实体</param> /// <param name="sql">组织的查询语句</param> /// <returns></returns> public static int Retrieve(Entity en, string sql) { try { DataTable dt = new DataTable(); switch (en.EnMap.EnDBUrl.DBUrlType) { case DBUrlType.AppCenterDSN: dt = DBAccess.RunSQLReturnTable(sql); break; case DBUrlType.DBAccessOfMSSQL1: dt = DBAccessOfMSSQL1.RunSQLReturnTable(sql); break; case DBUrlType.DBAccessOfMSSQL2: dt = DBAccessOfMSSQL2.RunSQLReturnTable(sql); break; case DBUrlType.DBAccessOfOracle1: dt = DBAccessOfOracle1.RunSQLReturnTable(sql); break; case DBUrlType.DBAccessOfOracle2: dt = DBAccessOfOracle2.RunSQLReturnTable(sql); break; default: throw new Exception("@没有设置DB类型。"); } if (dt.Rows.Count == 0) { return(0); } Attrs attrs = en.EnMap.Attrs; EntityDBAccess.fullDate(dt, en, attrs); int i = dt.Rows.Count; dt.Dispose(); return(i); } catch (System.Exception ex) { throw ex; } }
/// <summary> /// 把所有的值都设置成默认值,但是主键除外。 /// </summary> public void ResetDefaultValAllAttr() { Attrs attrs = this.EnMap.Attrs; foreach (Attr attr in attrs) { if (attr.UIIsReadonly == false && attr.DefaultValOfReal != null) { continue; } if (attr.IsPK) { continue; } string v = attr.DefaultValOfReal as string; if (v == null) { this.SetValByKey(attr.Key, ""); continue; } if (v.Contains("@") == false && v != null) { this.SetValByKey(attr.Key, v); continue; } // 设置默认值. switch (v) { case "@WebUser.No": this.SetValByKey(attr.Key, Web.WebUser.No); continue; case "@WebUser.Name": this.SetValByKey(attr.Key, Web.WebUser.Name); continue; case "@WebUser.FK_Dept": this.SetValByKey(attr.Key, Web.WebUser.FK_Dept); continue; case "@WebUser.FK_DeptName": this.SetValByKey(attr.Key, Web.WebUser.FK_DeptName); continue; case "@WebUser.FK_DeptNameOfFull": this.SetValByKey(attr.Key, Web.WebUser.FK_DeptNameOfFull); continue; case "@RDT": if (attr.MyDataType == DataType.AppDate) { this.SetValByKey(attr.Key, DataType.CurrentData); } else { this.SetValByKey(attr.Key, DataType.CurrentDataTime); } continue; default: continue; } } }
/// <summary> /// 重新设置默信息. /// </summary> public void ResetDefaultVal() { // this.Row.Clear(); Attrs attrs = this.EnMap.Attrs; foreach (Attr attr in attrs) { if (attr.IsRefAttr) { this.SetValRefTextByKey(attr.Key, ""); } string v = attr.DefaultValOfReal as string; if (v == null) { continue; } if (attr.DefaultValOfReal.Contains("@") == false) { //added by liuxc,2015-7-13,字符串类型的字段,如果有默认值的,按默认值填写值,比如审批意见默认为“同意”的等等 if (attr.UITBShowType == Web.Controls.TBType.TB && attr.UIVisible && string.IsNullOrWhiteSpace(this.GetValByKey(attr.Key) as string) && !string.IsNullOrWhiteSpace(attr.DefaultValOfReal)) { this.SetValByKey(attr.Key, attr.DefaultVal); } continue; } string myval = this.GetValStrByKey(attr.Key); // 设置默认值. switch (v) { case "@WebUser.No": if (attr.UIIsReadonly == true) { this.SetValByKey(attr.Key, Web.WebUser.No); } else { if (string.IsNullOrEmpty(myval) || myval == v) { this.SetValByKey(attr.Key, Web.WebUser.No); } } continue; case "@WebUser.Name": if (attr.UIIsReadonly == true) { this.SetValByKey(attr.Key, Web.WebUser.Name); } else { if (string.IsNullOrEmpty(myval) || myval == v) { this.SetValByKey(attr.Key, Web.WebUser.Name); } } continue; case "@WebUser.FK_Dept": if (attr.UIIsReadonly == true) { this.SetValByKey(attr.Key, Web.WebUser.FK_Dept); } else { if (string.IsNullOrEmpty(myval) || myval == v) { this.SetValByKey(attr.Key, Web.WebUser.FK_Dept); } } continue; case "@WebUser.FK_DeptName": if (attr.UIIsReadonly == true) { this.SetValByKey(attr.Key, Web.WebUser.FK_DeptName); } else { if (string.IsNullOrEmpty(myval) || myval == v) { this.SetValByKey(attr.Key, Web.WebUser.FK_DeptName); } } continue; case "@WebUser.FK_DeptNameOfFull": if (attr.UIIsReadonly == true) { this.SetValByKey(attr.Key, Web.WebUser.FK_DeptNameOfFull); } else { if (string.IsNullOrEmpty(myval) || myval == v) { this.SetValByKey(attr.Key, Web.WebUser.FK_DeptNameOfFull); } } continue; case "@RDT": if (attr.UIIsReadonly == true) { if (attr.MyDataType == DataType.AppDate || myval == v) { this.SetValByKey(attr.Key, DataType.CurrentData); } if (attr.MyDataType == DataType.AppDateTime || myval == v) { this.SetValByKey(attr.Key, DataType.CurrentDataTime); } } else { if (string.IsNullOrEmpty(myval) || myval == v) { if (attr.MyDataType == DataType.AppDate) { this.SetValByKey(attr.Key, DataType.CurrentData); } else { this.SetValByKey(attr.Key, DataType.CurrentDataTime); } } } continue; default: continue; } } }
void btn_Click(object sender, EventArgs e) { Button btn = sender as Button; try { BP.Web.Controls.DDL DDL_ImpWay = (BP.Web.Controls.DDL) this.Pub1.FindControl("DDL_ImpWay"); System.Web.UI.WebControls.FileUpload fuit = (System.Web.UI.WebControls.FileUpload) this.Pub1.FindControl("fup"); if (DDL_ImpWay.SelectedIndex == 0) { this.Alert("请选择导入方式."); return; } string tempPath = this.Request.PhysicalApplicationPath + "\\Temp\\"; if (System.IO.Directory.Exists(tempPath) == false) { System.IO.Directory.CreateDirectory(tempPath); } MapDtl dtl = new MapDtl(this.FK_MapDtl); //求出扩展名. string fileName = fuit.FileName.ToLower(); if (fileName.Contains(".xls") == false) { this.Alert("上传的文件必须是excel文件."); return; } string ext = ".xls"; if (fileName.Contains(".xlsx")) { ext = ".xlsx"; } //保存临时文件. string file = tempPath + WebUser.No + ext; fuit.SaveAs(file); GEDtls dtls = new GEDtls(this.FK_MapDtl); System.Data.DataTable dt = BP.DA.DBLoad.GetTableByExt(file); file = this.Request.PhysicalApplicationPath + "\\DataUser\\DtlTemplete\\" + this.FK_MapDtl + ext; if (System.IO.File.Exists(file) == false) { if (ext == ".xlsx") { file = this.Request.PhysicalApplicationPath + "\\DataUser\\DtlTemplete\\" + this.FK_MapDtl + ".xls"; } else { file = this.Request.PhysicalApplicationPath + "\\DataUser\\DtlTemplete\\" + this.FK_MapDtl + ".xls"; } } System.Data.DataTable dtTemplete = BP.DA.DBLoad.GetTableByExt(file); #region 检查两个文件是否一致。 foreach (DataColumn dc in dtTemplete.Columns) { bool isHave = false; foreach (DataColumn mydc in dt.Columns) { if (dc.ColumnName == mydc.ColumnName) { isHave = true; break; } } if (isHave == false) { throw new Exception("@您导入的excel文件不符合系统要求的格式,请下载模版文件重新填入。"); } } #endregion 检查两个文件是否一致。 #region 生成要导入的属性. BP.En.Attrs attrs = dtls.GetNewEntity.EnMap.Attrs; BP.En.Attrs attrsExp = new BP.En.Attrs(); foreach (DataColumn dc in dtTemplete.Columns) { foreach (Attr attr in attrs) { if (attr.UIVisible == false) { continue; } if (attr.IsRefAttr) { continue; } if (attr.Desc == dc.ColumnName.Trim()) { attrsExp.Add(attr); break; } } } #endregion 生成要导入的属性. #region 执行导入数据. if (DDL_ImpWay.SelectedIndex == 1) { BP.DA.DBAccess.RunSQL("DELETE FROM " + dtl.PTable + " WHERE RefPK='" + this.WorkID + "'"); } int i = 0; Int64 oid = BP.DA.DBAccess.GenerOID("Dtl", dt.Rows.Count); string rdt = BP.DA.DataType.CurrentData; string errMsg = ""; foreach (DataRow dr in dt.Rows) { GEDtl dtlEn = dtls.GetNewEntity as GEDtl; dtlEn.ResetDefaultVal(); foreach (BP.En.Attr attr in attrsExp) { if (attr.UIVisible == false || dr[attr.Desc] == DBNull.Value) { continue; } string val = dr[attr.Desc].ToString(); if (val == null) { continue; } val = val.Trim(); switch (attr.MyFieldType) { case FieldType.Enum: case FieldType.PKEnum: SysEnums ses = new SysEnums(attr.UIBindKey); bool isHavel = false; foreach (SysEnum se in ses) { if (val == se.Lab) { val = se.IntKey.ToString(); isHavel = true; break; } } if (isHavel == false) { errMsg += "@数据格式不规范,第(" + i + ")行,列(" + attr.Desc + "),数据(" + val + ")不符合格式,改值没有在枚举列表里."; val = attr.DefaultVal.ToString(); } break; case FieldType.FK: case FieldType.PKFK: Entities ens = null; if (attr.UIBindKey.Contains(".")) { ens = BP.En.ClassFactory.GetEns(attr.UIBindKey); } else { ens = new GENoNames(attr.UIBindKey, "desc"); } ens.RetrieveAll(); bool isHavelIt = false; foreach (Entity en in ens) { if (val == en.GetValStrByKey("Name")) { val = en.GetValStrByKey("No"); isHavelIt = true; break; } } if (isHavelIt == false) { errMsg += "@数据格式不规范,第(" + i + ")行,列(" + attr.Desc + "),数据(" + val + ")不符合格式,改值没有在外键数据列表里."; } break; default: break; } if (attr.MyDataType == BP.DA.DataType.AppBoolean) { if (val.Trim() == "是" || val.Trim().ToLower() == "yes") { val = "1"; } if (val.Trim() == "否" || val.Trim().ToLower() == "no") { val = "0"; } } dtlEn.SetValByKey(attr.Key, val); } dtlEn.RefPKInt = (int)this.WorkID; dtlEn.SetValByKey("RDT", rdt); dtlEn.SetValByKey("Rec", WebUser.No); i++; dtlEn.InsertAsOID(oid); oid++; } #endregion 执行导入数据. if (string.IsNullOrEmpty(errMsg) == true) { this.Alert("共有(" + i + ")条数据导入成功。"); } else { this.Alert("共有(" + i + ")条数据导入成功,但是出现如下错误:" + errMsg); } } catch (Exception ex) { string msg = ex.Message.Replace("'", "‘"); this.Alert(msg); } }
void btn_Copy_Click(object sender, EventArgs e) { BP.WF.Node nd = new BP.WF.Node(this.FK_Node); Node sNd = new Node(this.NodeOfSelect); BP.En.Attrs attrs = sNd.HisWork.EnMap.Attrs; BP.En.Attrs attrsCopy = nd.HisWork.EnMap.Attrs; // 开始copy 分组的节点。 GroupFields gfs = new GroupFields(this.NodeOfSelect); MapDtls dtls = new MapDtls(this.NodeOfSelect); MapM2Ms m2ms = new MapM2Ms(this.NodeOfSelect); MapFrames frms = new MapFrames(this.NodeOfSelect); foreach (GroupField gf in gfs) { CheckBox cb = this.Pub2.GetCBByID("CB" + gf.OID); if (cb.Checked == false) { continue; } // 生成一个分组实体. GroupField mygf = new GroupField(); mygf.Lab = gf.Lab; mygf.EnName = this.FK_Node; mygf.Idx = gf.Idx; mygf.Insert(); foreach (MapM2M m2m in m2ms) { if (m2m.GroupID != gf.OID) { continue; } MapM2M mym2m = new MapM2M(); mym2m.MyPK = m2m.MyPK.Replace(this.NodeOfSelect, this.FK_Node); // mym2m.FK_MapData =this if (mym2m.IsExits) { continue; } mym2m.Copy(m2m); mym2m.FK_MapData = this.FK_Node; mym2m.GroupID = mygf.OID; mym2m.MyPK = m2m.MyPK.Replace(this.NodeOfSelect, this.FK_Node); mym2m.Insert(); } foreach (MapFrame frm in frms) { if (frm.GroupID != gf.OID) { continue; } MapFrame myen = new MapFrame(); myen.MyPK = frm.MyPK.Replace(this.NodeOfSelect, this.FK_Node); if (myen.IsExits) { continue; } myen.Copy(frm); myen.FK_MapData = this.FK_Node; myen.GroupID = mygf.OID; myen.MyPK = frm.MyPK.Replace(this.NodeOfSelect, this.FK_Node); myen.Insert(); } // 复制从表. foreach (MapDtl dtl in dtls) { cb = this.Pub2.GetCBByID("CB_" + dtl.No + gf.OID); MapDtl dtlNew = new MapDtl(); dtlNew.No = dtl.No.Replace(this.NodeOfSelect, this.FK_Node); if (dtlNew.IsExits) { continue; } dtlNew.Copy(dtl); dtlNew.FK_MapData = this.FK_Node; dtlNew.No = dtl.No.Replace(this.NodeOfSelect, this.FK_Node); // dtlNew.No = this.FK_Node + "Dtl"; // dtlNew.No = dtl.No.Replace(this.FK_Node, this.NodeOfSelect); dtlNew.IsInsert = false; dtlNew.IsUpdate = false; dtlNew.IsDelete = false; dtlNew.GroupID = mygf.OID; dtlNew.PTable = dtlNew.No; dtlNew.Insert(); // 复制从表里面的明细。 int idx = 0; MapAttrs mattrs = new MapAttrs(dtl.No); foreach (MapAttr attr in mattrs) { MapAttr attrNew = new MapAttr(); attrNew.Copy(attr); attrNew.FK_MapData = dtlNew.No; attrNew.UIIsEnable = false; if (attrNew.DefVal.Contains("@")) { attrNew.DefVal = ""; } dtlNew.RowIdx = idx; attrNew.HisEditType = EditType.Edit; attrNew.Insert(); } } // copy his fields. MapAttrs willCopyAttrs = new MapAttrs(); willCopyAttrs.Retrieve(MapAttrAttr.GroupID, gf.OID, MapAttrAttr.Idx); int idx1 = 0; foreach (MapAttr attr in willCopyAttrs) { MapAttr attrNew = new MapAttr(); if (attrNew.IsExit(MapAttrAttr.FK_MapData, this.FK_Node, MapAttrAttr.KeyOfEn, attr.KeyOfEn) == true) { continue; } if (attr.UIVisible == false) { continue; } idx1++; attrNew.Copy(attr); attrNew.GroupID = mygf.OID; attrNew.FK_MapData = this.FK_Node; attrNew.UIIsEnable = false; attrNew.Idx = idx1; if (attrNew.KeyOfEn == "Title") { attrNew.HisEditType = EditType.Edit; } attrNew.HisEditType = EditType.Edit; attrNew.DefVal = ""; attrNew.Insert(); } } int GroupField = this.Pub2.GetDDLByID("DDL_GroupField").SelectedItemIntVal; foreach (Attr attr in attrs) { if (this.Pub2.IsExit(attr.Key) == false) { continue; } CheckBox cb = this.Pub2.GetCBByID(attr.Key); if (cb.Checked == false) { continue; } BP.Sys.MapAttr ma = new BP.Sys.MapAttr(); int i = ma.Retrieve(BP.Sys.MapAttrAttr.KeyOfEn, attr.Key, BP.Sys.MapAttrAttr.FK_MapData, this.NodeOfSelect); BP.Sys.MapAttr ma1 = new BP.Sys.MapAttr(); bool ishavle = ma1.IsExit(BP.Sys.MapAttrAttr.KeyOfEn, attr.Key, BP.Sys.MapAttrAttr.FK_MapData, this.FK_Node); if (ishavle) { continue; } ma1.Copy(ma); ma1.FK_MapData = this.FK_Node; ma1.KeyOfEn = ma.KeyOfEn; ma1.Name = ma.Name; ma1.GroupID = GroupField; ma1.UIIsEnable = false; ma1.HisEditType = EditType.Edit; if (ma1.DefVal != null && ma1.DefVal.Contains("@")) { ma1.DefVal = ""; } ma1.Insert(); } if (this.Pub2.IsExit("CB_Table")) { if (this.Pub2.GetCBByID("CB_Table").Checked) { MapData md1 = new MapData(this.NodeOfSelect); MapData md2 = new MapData(this.FK_Node); //md2.CellsX = md1.CellsX; //md2.CellsY = md1.CellsY; md2.Update(); //MapAttrs ma1 = md1.GenerHisTableCells; // 删除历史数据。 //ma1.Delete(MapAttrAttr.FK_MapData, this.FK_Node + "T"); //foreach (MapAttr attr in ma1) //{ // MapAttr attr2 = new MapAttr(); // attr2.Copy(attr); // // attr2.OID = 0; // attr2.GroupID = 0; // attr2.Idx = 0; // attr2.FK_MapData = this.FK_Node + "T"; // attr2.UIIsEnable = false; // attr2.Insert(); //} } } this.WinClose(); //this.WinCloseWithMsg("复制成功"); //this.Response.Redirect("MapDef.aspx?PK=" + this.FK_Node + "&NodeOfSelect=" + this.NodeOfSelect); }
/// <summary> /// 分组查询,返回datatable. /// </summary> /// <param name="attrsOfGroupKey"></param> /// <param name="groupValField"></param> /// <param name="gw"></param> /// <returns></returns> public DataTable DoGroupReturnTable1(Entity en, Attrs attrsOfGroupKey, Attr attrGroup, GroupWay gw, OrderWay ow) { #region 生成要查询的语句 string fields = ""; string str = ""; foreach (Attr attr in attrsOfGroupKey) { if (attr.Field == null) { continue; } str = "," + attr.Field; fields += str; } if (attrGroup.Key == "MyNum") { switch (gw) { case GroupWay.BySum: fields += ", COUNT(*) AS MyNum"; break; case GroupWay.ByAvg: fields += ", AVG(*) AS MyNum"; break; default: throw new Exception("no such case:"); } } else { switch (gw) { case GroupWay.BySum: fields += ",SUM(" + attrGroup.Field + ") AS " + attrGroup.Key; break; case GroupWay.ByAvg: fields += ",AVG(" + attrGroup.Field + ") AS " + attrGroup.Key; break; default: throw new Exception("no such case:"); } } string by = ""; foreach (Attr attr in attrsOfGroupKey) { if (attr.Field == null) { continue; } str = "," + attr.Field; by += str; } by = by.Substring(1); //string sql string sql = "SELECT " + fields.Substring(1) + " FROM " + this.En.EnMap.PhysicsTable + " WHERE " + this._sql + " Group BY " + by; #endregion #region Map map = new Map(); map.PhysicsTable = "@VT@"; map.Attrs = attrsOfGroupKey; map.Attrs.Add(attrGroup); #endregion . //string sql1=SqlBuilder.SelectSQLOfMS( map )+" "+SqlBuilder.GenerFormWhereOfMS( en,map) + " AND ( " + this._sql+" ) "+_endSql; string sql1 = SqlBuilder.SelectSQLOfMS(map) + " " + SqlBuilder.GenerFormWhereOfMS(en, map); sql1 = sql1.Replace("@TopNum", ""); sql1 = sql1.Replace("FROM @VT@", "FROM (" + sql + ") VT"); sql1 = sql1.Replace("@VT@", "VT"); sql1 = sql1.Replace("TOP", ""); if (ow == OrderWay.OrderByUp) { sql1 += " ORDER BY " + attrGroup.Key + " DESC "; } else { sql1 += " ORDER BY " + attrGroup.Key; } return(DBAccess.RunSQLReturnTable(sql1)); }
void btn_Click(object sender, EventArgs e) { Button btn = sender as Button; try { BP.Web.Controls.DDL DDL_ImpWay = (BP.Web.Controls.DDL) this.Pub1.FindControl("DDL_ImpWay"); System.Web.UI.WebControls.FileUpload fuit = (System.Web.UI.WebControls.FileUpload) this.Pub1.FindControl("fup"); if (DDL_ImpWay.SelectedIndex == 0) { this.Alert("请选择导入方式."); return; } MapDtl dtl = new MapDtl(this.FK_MapDtl); string file = this.Request.PhysicalApplicationPath + "\\Temp\\" + WebUser.No + ".xls"; fuit.SaveAs(file); GEDtls dtls = new GEDtls(this.FK_MapDtl); System.Data.DataTable dt = BP.DBLoad.GetTableByExt(file); file = this.Request.PhysicalApplicationPath + "\\DataUser\\DtlTemplete\\" + this.FK_MapDtl + ".xls"; System.Data.DataTable dtTemplete = BP.DBLoad.GetTableByExt(file); #region 检查两个文件是否一致。 foreach (DataColumn dc in dtTemplete.Columns) { bool isHave = false; foreach (DataColumn mydc in dt.Columns) { if (dc.ColumnName == mydc.ColumnName) { isHave = true; break; } } if (isHave == false) { throw new Exception("@您导入的excel文件不符合系统要求的格式,请下载模版文件重新填入。"); } } #endregion 检查两个文件是否一致。 #region 生成要导入的属性. BP.En.Attrs attrs = dtls.GetNewEntity.EnMap.Attrs; BP.En.Attrs attrsExp = new BP.En.Attrs(); foreach (DataColumn dc in dtTemplete.Columns) { foreach (Attr attr in attrs) { if (attr.UIVisible == false) { continue; } if (attr.IsRefAttr) { continue; } if (attr.Desc == dc.ColumnName.Trim()) { attrsExp.Add(attr); break; } } } #endregion 生成要导入的属性. #region 执行导入数据. if (DDL_ImpWay.SelectedIndex == 1) { BP.DA.DBAccess.RunSQL("DELETE " + dtl.PTable + " WHERE RefPK='" + this.WorkID + "'"); } int i = 0; Int64 oid = BP.DA.DBAccess.GenerOID(this.FK_MapDtl, dt.Rows.Count); string rdt = BP.DA.DataType.CurrentData; foreach (DataRow dr in dt.Rows) { GEDtl dtlEn = dtls.GetNewEntity as GEDtl; dtlEn.ResetDefaultVal(); foreach (BP.En.Attr attr in attrsExp) { if (attr.UIVisible == false || dr[attr.Desc] == DBNull.Value) { continue; } string val = dr[attr.Desc].ToString(); if (val == null) { continue; } val = val.Trim(); switch (attr.MyFieldType) { case FieldType.Enum: case FieldType.PKEnum: SysEnums ses = new SysEnums(attr.UIBindKey); foreach (SysEnum se in ses) { if (val == se.Lab) { val = se.IntKey.ToString(); break; } } break; case FieldType.FK: case FieldType.PKFK: break; default: break; } dtlEn.SetValByKey(attr.Key, val); } dtlEn.RefPKInt = (int)this.WorkID; dtlEn.SetValByKey("RDT", rdt); dtlEn.SetValByKey("Rec", WebUser.No); i++; dtlEn.InsertAsOID(oid); oid++; } #endregion 执行导入数据. this.Alert("共有(" + i + ")条数据导入成功。"); } catch (Exception ex) { string msg = ex.Message.Replace("'", "‘"); this.Alert(msg); } }
/// <summary> /// 重新设置默信息. /// </summary> public void ResetDefaultVal() { Attrs attrs = this.EnMap.Attrs; foreach (Attr attr in attrs) { string v = attr.DefaultValOfReal as string; if (v == null) { continue; } if (attr.DefaultValOfReal.Contains("@") == false) { continue; } string myval = this.GetValStrByKey(attr.Key); // 设置默认值. switch (v) { case "@WebUser.No": if (attr.UIIsReadonly == true) { this.SetValByKey(attr.Key, Web.WebUser.No); } else { if (string.IsNullOrEmpty(myval) || myval == v) { this.SetValByKey(attr.Key, Web.WebUser.No); } } continue; case "@WebUser.Name": if (attr.UIIsReadonly == true) { this.SetValByKey(attr.Key, Web.WebUser.Name); } else { if (string.IsNullOrEmpty(myval) || myval == v) { this.SetValByKey(attr.Key, Web.WebUser.Name); } } continue; case "@WebUser.FK_Dept": if (attr.UIIsReadonly == true) { this.SetValByKey(attr.Key, Web.WebUser.FK_Dept); } else { if (string.IsNullOrEmpty(myval) || myval == v) { this.SetValByKey(attr.Key, Web.WebUser.FK_Dept); } } continue; case "@WebUser.FK_DeptName": if (attr.UIIsReadonly == true) { this.SetValByKey(attr.Key, Web.WebUser.FK_DeptName); } else { if (string.IsNullOrEmpty(myval) || myval == v) { this.SetValByKey(attr.Key, Web.WebUser.FK_DeptName); } } continue; case "@WebUser.FK_DeptNameOfFull": if (attr.UIIsReadonly == true) { this.SetValByKey(attr.Key, Web.WebUser.FK_DeptNameOfFull); } else { if (string.IsNullOrEmpty(myval) || myval == v) { this.SetValByKey(attr.Key, Web.WebUser.FK_DeptNameOfFull); } } continue; case "@RDT": if (attr.UIIsReadonly == true) { if (attr.MyDataType == DataType.AppDate || myval == v) { this.SetValByKey(attr.Key, DataType.CurrentData); } if (attr.MyDataType == DataType.AppDateTime || myval == v) { this.SetValByKey(attr.Key, DataType.CurrentDataTime); } } else { if (string.IsNullOrEmpty(myval) || myval == v) { if (attr.MyDataType == DataType.AppDate) { this.SetValByKey(attr.Key, DataType.CurrentData); } else { this.SetValByKey(attr.Key, DataType.CurrentDataTime); } } } continue; default: continue; } } }