/// <summary> /// 根据用户名称查询用户 /// </summary> /// <param name="UserName"></param> /// <returns></returns> public virtual IUser QueryUserName(string UserName) { IUser user = entityfactory.CreateEntityInstance <IUser>(); IDvTable dvt = entityfactory.CreateDriveTable(user); user.UserName = UserName; dvt.WhereClause("UserName", Operator.Deng, LinkOperator.nul); DataSet ds = dvt.Select(); user = this.dh.Convert <IUser>(user.GetType(), ds, 0); return(user); }
/// <summary> /// 根据指定的权限项编码查询权限项对象 /// </summary> /// <param name="AuthItemCode"></param> /// <returns></returns> public virtual IAuthItem QueryAuthItem(string AuthItemCode) { IAuthItem item = this.entityfactory.CreateEntityInstance <IAuthItem>(); item.AuthItemCode = AuthItemCode; IDvTable dvt = this.entityfactory.CreateDriveTable(item); dvt.WhereClause("AuthItemCode", Operator.Deng, LinkOperator.nul); DataSet ds = dvt.Select(); DataHelper dte = new DataHelper(); return(dte.Convert <IAuthItem>(item.GetType(), ds, 0));; }
protected virtual void button1_Click(object sender, EventArgs e) { //ProteinCustomSection config // = (ProteinCustomSection)System.Configuration.ConfigurationManager.GetSection("Protein"); //ProteinConfig pconfig = ProteinConfig.GetInstance(); throw new Exception("测试"); /// ILHTDZS_ManagerUser user = this.entityfactory.CreateEntityInstance <ILHTDZS_ManagerUser>(); IDvTable dvt = this.entityfactory.CreateDriveTable(user); DataSet ds = dvt.Select(); //List<LHTDZS_ManagerUser> list = this.dh.Convert<LHTDZS_ManagerUser>(user.GetType(), ds); }
/// <summary> /// 创建命令 /// </summary> /// <param name="Table"></param> public override void CreateCmd(IDvTable Table) { string cmd = "SELECT " + SetFilter(Table) + " FROM " + SetEntity(Table) + " " + SetGroupByKey(Table) + SetGroupBy(Table); if (Table.Wherelist.Count > 0) { this.Cmd = SetWhere(Table, cmd); } else { this.Cmd = cmd; } }
/// <summary> /// 创建命令 /// </summary> /// <param name="Table"></param> public override void CreateCmd(IDvTable Table) { string cmd = "DELETE FROM [" + Table.Entity.GetType().Name + "] "; if (Table.Wherelist.Count > 0) { this.Cmd = SetWhere(Table, cmd); } else { this.Cmd = cmd; } }
/// <summary> /// 查询菜单编码 /// </summary> /// <param name="MenuCode"></param> /// <returns></returns> public virtual IMenu QueryCode(string MenuCode) { IMenu menu = this.entityfactory.CreateEntityInstance <IMenu>(); menu.MENUCODE = MenuCode; IDvTable dvt = this.entityfactory.CreateDriveTable(menu); dvt.WhereClause("MENUCODE", Operator.Deng, LinkOperator.nul); DataSet ds = dvt.Select(); DataHelper dte = new DataHelper(); return(dte.Convert <IMenu>(menu.GetType(), ds, 0));; }
/// <summary> /// 根据单位查询用户 /// </summary> /// <param name="Units"></param> /// <returns></returns> public virtual List <IUser> QueryUser(IUnits Units) { IUser user = entityfactory.CreateEntityInstance <IUser>(); user.UnitCode = Units.UnitCode; IDvTable dvt = entityfactory.CreateDriveTable(user); dvt.WhereClause("UnitCode", Operator.Deng, LinkOperator.nul); DataSet ds = dvt.Select(); List <IUser> list = this.dh.Convert <IUser>(user.GetType(), ds); return(list); }
/// <summary> /// 创建命令 /// </summary> /// <param name="Table"></param> public override void CreateCmd(IDvTable Table) { string cmd = "SELECT " + SetFilter(Table) + " FROM " + SetEntity(Table) + " ";//Table.Entity.GetType().Name if (Table.Wherelist.Count > 0) { this.Cmd = SetWhere(Table, cmd); } else { this.Cmd = cmd; } }
/// <summary> /// 批量更新用户 /// </summary> /// <param name="UserList"></param> /// <returns></returns> public int Update(List <IUser> UserList) { IDvTableBatch dvtb = entityfactory.CreateDriveTableBatch(); foreach (IUser user in UserList) { IDvTable dvt = dvtb.CreateDriveTable(user); dvt.WhereClause("UserCode", Operator.Deng, LinkOperator.nul); dvtb.AddUpdate(dvt); } int i = dvtb.Execute(); return(i); }
/// <summary> /// 移除指定用户下的指定权限控制项编码的控制项 /// </summary> /// <param name="Role"></param> /// <param name="FItemCode"></param> /// <returns></returns> public int RemoveAuthCtrl(IRole Role, string FItemCode) { IAuthControl auth = entityfactory.CreateEntityInstance <IAuthControl>(); auth.RoleCode = Role.RoleCode; auth.FItemCode = FItemCode; IDvTable dvt = entityfactory.CreateDriveTable(auth); dvt.WhereClause("FItemCode", Operator.Deng, LinkOperator.and); dvt.WhereClause("RoleCode", Operator.Deng, LinkOperator.nul); int i = dvt.Delete(); return(i); }
/// <summary> /// 根据权限项和角色查询权限控制项 /// </summary> /// <param name="AuthItem"></param> /// <param name="Role"></param> /// <returns></returns> public IAuthControl QueryAuthCtrl(IAuthItem AuthItem, IRole Role) { IAuthControl actrl = entityfactory.CreateEntityInstance <IAuthControl>(); IDvTable dvt = entityfactory.CreateDriveTable(actrl); actrl.FItemCode = AuthItem.AuthItemCode.ToString(); actrl.RoleCode = Role.RoleCode; dvt.WhereClause("FItemCode", Operator.Deng, LinkOperator.and); dvt.WhereClause("RoleCode", Operator.Deng, LinkOperator.nul); DataSet ds = dvt.Select(); actrl = this.dh.Convert <IAuthControl>(actrl.GetType(), ds, 0); return(actrl); }
/// <summary> /// 根据角色查询权限项 /// 角色关联权限控制项 权限控制项关联权限项 /// </summary> /// <param name="Role"></param> /// <returns></returns> public List <IAuthItem> QueryAuthItem(IRole Role) { IAuthItem item = this.entityfactory.CreateEntityInstance <IAuthItem>(); IAuthControl actrl = entityfactory.CreateEntityInstance <IAuthControl>(); actrl.RoleCode = Role.RoleCode; IDvTable dvt = entityfactory.CreateDriveTable(item); dvt.Join.Entitys.Add(actrl); dvt.WhereClause(actrl, "RoleCode", Operator.Deng, LinkOperator.nul); DataSet ds = dvt.Select(); List <IAuthItem> list = this.dh.Convert <IAuthItem>(item.GetType(), ds); return(list); }
/// <summary> /// 保存日志对象实例 /// </summary> protected virtual void SaveLog(object Message, LogType Type) { //if (Type <= this.ReadinLogLevel) //{ // return; //} DataHelper dh = new DataHelper(); ILog log = this.entityfactory.CreateEntityInstance <ILog>(); log.LOGCODE = (dh.GetMaxField(log, "LOGCODE", this.entityfactory) + 1); log.LOGTIME = DateTime.Now; log.CONTENT = Message.ToString(); log.LOGTYPE = Type.ToString(); IDvTable dvt = entityfactory.CreateDriveTable(log); int i = dvt.Insert(); }
/// <summary> /// 设置联立表外键关联字符串 /// </summary> /// <param name="Table"></param> /// <returns></returns> protected string SetJoinChar(IDvTable Table) { string result = ""; foreach (IEntityBase eb in Table.Join.Entitys) { if (result == "") { result = Table.Join.JoinField(Table.Entity, eb); } else { result = result + "AND" + Table.Join.JoinField(Table.Entity, eb); } } return(result); }
/// <summary> /// 更新实体数据 /// </summary> /// <param name="Entity"></param> /// <param name="Clauses"></param> /// <returns></returns> public virtual int UpdateEntityData(IEntityBase Entity, List <ClauseElement> Clauses) { int result = 0; if (Clauses.Count == 0) { return(result); } IDvTable dvt = DalCreateDriveTable(Entity); foreach (ClauseElement ce in Clauses) { dvt.WhereClause(ce.FieldName, ce.Opr, ce.LinkOpr); } result = dvt.Update(); return(result); }
/// <summary> /// 设置条件子语句 /// </summary> /// <param name="Table"></param> /// <param name="Cmd"></param> /// <returns></returns> protected string SetWhere(IDvTable Table, string Cmd) { Type t = Table.Entity.GetType(); string lastopr = ""; string cul = SetJoinChar(Table); if (cul != "") { cul = "WHERE " + cul + " AND "; } foreach (IDvWhere pw in Table.Wherelist) { //添加重复的键值 主键无法update 或者说是无法根据自己更新自己 base.AddParWhere(pw.Usefield, pw.Entity); if (cul == "") { cul = "WHERE "; if (pw.LinknextOperator != "null") { lastopr = pw.LinknextOperator; cul = cul + pw.Clause + " " + pw.LinknextOperator; } else { cul = cul + pw.Clause; break; } } else { if (pw.LinknextOperator != "null") { lastopr = pw.LinknextOperator; cul = cul + " " + pw.Clause + " " + pw.LinknextOperator; } else { lastopr = pw.LinknextOperator; cul = cul + " " + pw.Clause; break; } } } cul = Cmd + " " + cul; return(cul); }
/// <summary> /// 批量更新实体 /// </summary> /// <param name="EntityClause">实体列表</param> /// <param name="IsRollBack">是否回滚</param> /// <returns></returns> public virtual int UpdateEntityDataTran <T>(Dictionary <T, List <ClauseElement> > EntityClause, bool IsRollBack) { List <IDvTable> tableList = new List <IDvTable>(); foreach (IEntityBase eb in EntityClause.Keys) { IDvTable dvt = this.EntityFact.CreateDriveTable(eb); foreach (ClauseElement ce in EntityClause[(T)eb]) { dvt.WhereClause(ce.FieldName, ce.Opr, ce.LinkOpr); } tableList.Add(dvt); } IDvTableBatch dvtb = this.EntityFact.CreateDriveTableBatch(); int i = dvtb.ExecuteUpdate(tableList, IsRollBack); return(i); }
/// <summary> /// 设置更新值 /// </summary> protected void UpdateValue(IDvTable Table) { string cmd = ""; foreach (PropertyInfo pi in Table.Entity.GetFields()) { base.AddPar(pi, Table.Entity); if (cmd == "") { cmd = " SET " + pi.Name + "=:" + pi.Name; } else { cmd = cmd + "," + pi.Name + "=:" + pi.Name; } } this.Cmd = this.Cmd + cmd; }
/// <summary> /// 根据角色编码查询用户 /// </summary> /// <param name="RoleCode"></param> /// <returns></returns> public List <IUser> QueryUserRoleCode(long RoleCode) { IUser user = entityfactory.CreateEntityInstance <IUser>(); IDvTable dvt = entityfactory.CreateDriveTable(user); user.RoleCode = RoleCode; dvt.WhereClause("UserName", Operator.Deng, LinkOperator.nul); DataSet ds = dvt.Select(); DataHelper dte = new DataHelper(); List <object> userlist = dte.ConvertToEntity(user.GetType(), ds); List <IUser> result = new List <IUser>(); foreach (object obj in userlist) { result.Add((IUser)obj); } return(result); }
/// <summary> /// 根据角色名和菜单类型查询菜单 /// </summary> /// <param name="Role">角色</param> /// <param name="MType">菜单类型</param> /// <returns></returns> public List <IMenu> QueryMenus(IRole Role, MenuType MType) { IMenu menu = entityfactory.CreateEntityInstance <IMenu>(); menu.MENUTYPE = MType.ToString(); IAuthControl actrl = entityfactory.CreateEntityInstance <IAuthControl>(); actrl.RoleCode = Role.RoleCode; IDvTable dvt = entityfactory.CreateDriveTable(menu); dvt.Join.Entitys.Add(actrl); dvt.WhereClause("MENUTYPE", Operator.Deng, LinkOperator.and); dvt.WhereClause(actrl, "RoleCode", Operator.Deng, LinkOperator.nul); DataSet ds = dvt.Select(); List <IMenu> list = this.dh.Convert <IMenu>(menu.GetType(), ds); List <IMenu> result = RefactoringMenu(list); return(result); }
/// <summary> /// 根据多个条件子语句查询指定实体对象的所有值 当条件子语句数量为0时返回值为空列表 此方法不考虑联立表查询情况 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="EntityInstance"></param> /// <param name="Clauses"></param> /// <returns></returns> public virtual List <T> QueryEntityList <T>(IEntityBase EntityInstance, List <ClauseElement> Clauses) { List <T> result = new List <T>(); if (Clauses.Count == 0) { return(result); } IDvTable dvt = DalCreateDriveTable(EntityInstance); foreach (ClauseElement ce in Clauses) { dvt.WhereClause(ce.FieldName, ce.Opr, ce.LinkOpr); } DataSet ds = dvt.Select(); result = this.dh.Convert <T>(EntityInstance.GetType(), ds); return(result); }
/// <summary> /// 设置分组字段 /// </summary> /// <param name="Table"></param> /// <returns></returns> protected string SetGroupBy(IDvTable Table) { string result = ""; if (Table.GetGroupBy == null) { return(result); } for (int i = 0; i < Table.GetGroupBy.UseField.Count; i++) { if (i == 0) { result = Table.GetGroupBy.UseField[i]; } else { result = result + "," + Table.GetGroupBy.UseField[i]; } } return(result); }
/// <summary> /// 根据用户编码查询用户 /// </summary> /// <param name="UserCode"></param> /// <returns></returns> public virtual IUser QueryUserCode(long UserCode) { IUser user = entityfactory.CreateEntityInstance <IUser>(); IDvTable dvt = entityfactory.CreateDriveTable(user); user.UserCode = UserCode; dvt.WhereClause("UserCode", Operator.Deng, LinkOperator.nul); DataSet ds = dvt.Select(); DataHelper dte = new DataHelper(); List <object> userlist = dte.ConvertToEntity(user.GetType(), ds); if (userlist.Count > 0) { user = (IUser)userlist[0]; } else { user = null; } return(user); }
/// <summary> /// 设置语句的字段 /// </summary> /// <param name="Table"></param> /// <param name="Cmd"></param> /// <returns></returns> protected string SetFilter(IDvTable Table) { string result = ""; foreach (IFilter fl in Table.Filterlist) { string tmp = Oprator(fl); if (result == "") { result = tmp; } else { result = result + "," + tmp; } } if (result == "") { result = "*"; } return(result); }
/// <summary> /// 获取指定对象字段的最大值 /// </summary> /// <param name="Entity">实体</param> /// <param name="FieldName">字段名</param> /// <param name="Entityfactory">字段名</param> /// <returns></returns> public virtual Int64 GetMaxField(IEntityBase Entity, string FieldName, IEntityFactory Entityfactory) { Regex re = new Regex("^[0-9]*[1-9][0-9]*$"); Int64 i = -99999; IDvTable dvt = Entityfactory.CreateDriveTable(Entity); dvt.SetFilter(Operator.Fun_Max, FieldName); DataSet ds = dvt.Select(); if (ds.Tables.Count > 0) { if (re.IsMatch(ds.Tables[0].Rows[0][0].ToString())) { i = Int64.Parse(ds.Tables[0].Rows[0][0].ToString()); } } if (i == -99999) { i = 0; } return(i); }
/// <summary> /// 根据用户名称和密码查询用户 /// </summary> /// <param name="UserName"></param> /// <param name="UserPassword"></param> /// <returns></returns> public IUser QueryUserInfo(string UserName, string UserPassword) { IUser user = entityfactory.CreateEntityInstance <IUser>(); IDvTable dvt = entityfactory.CreateDriveTable(user); user.UserName = UserName; user.Userpd = UserPassword; dvt.WhereClause("UserName", Operator.Deng, LinkOperator.and); dvt.WhereClause("Userpd", Operator.Deng, LinkOperator.nul); DataSet ds = dvt.Select(); DataHelper dte = new DataHelper(); List <object> userlist = dte.ConvertToEntity(user.GetType(), ds); if (userlist.Count > 0) { user = (IUser)userlist[0]; } else { user = null; } return(user); }
/// <summary> /// 创建sql命令 /// </summary> /// <param name="Table"></param> public abstract void CreateCmd(IDvTable Table);
/// <summary> /// 添加更新操作 /// </summary> /// <param name="Table"></param> public void AddUpdate(IDvTable Table) { this.updateList.Add(Table); }
/// <summary> /// 创建实体表格驱动对象 /// </summary> public virtual IDvTable DalCreateDriveTable(IEntityBase EntityInstance) { IDvTable dvt = this.EntityFact.CreateDriveTable(EntityInstance); return(dvt); }
/// <summary> /// 添加删除操作 /// </summary> /// <param name="Table"></param> public void AddDelete(IDvTable Table) { this.deleteList.Add(Table); }