Beispiel #1
0
        public bool DeleteRelease(int releaseID)
        {
            bool isSucess = true;

            using (var tran = DbContext.DbTransaction)
            {
                try
                {
                    var releaseQuery = new DapperExQuery <T_RELEASE>().AndWhere(s => s.ID, OperationMethod.Equal, releaseID);
                    DbContext.Delete <T_RELEASE>(releaseQuery.GetSqlQuery(DbContext));
                    var releaseSprintsQuery = new DapperExQuery <T_RELEASE_SPRINT>().AndWhere(s => s.R_RELEASE_ID, OperationMethod.Equal, releaseID);
                    DbContext.Delete <T_RELEASE_SPRINT>(releaseSprintsQuery.GetSqlQuery(DbContext));
                }
                catch (Exception e)
                {
                    isSucess = false;
                    throw e;
                }
                finally
                {
                    if (isSucess)
                    {
                        tran.Commit();
                    }
                    else
                    {
                        tran.Rollback();
                    }
                }
                return(isSucess);
            }
        }
        public List <BacklogInfoModel> GetBacklogInfoList(int teamID, int sprintID)
        {
            var query = new DapperExQuery <T_BACKLOG>();

            query.AndWhere(s => s.T_TEAM_ID, OperationMethod.Equal, teamID);
            query.AndWhere(s => s.B_STATE, OperationMethod.NotEqual, (int)BacklogState.REMOVE);
            string orderString = string.Empty;

            sprintID = sprintID < 0 ? 0 : sprintID;
            if (sprintID > 0 && this._scrumRepository.GetSprintInfoByTeamIDAndSprintID(teamID, sprintID) == null)
            {
                Enforce.Throw(new LogicErrorException("当前Sprint不存在"));
            }
            query.AndWhere(s => s.R_SPRINT_ID, OperationMethod.Equal, sprintID);
            if (sprintID > 0)
            {
                orderString = "B_LEVEL ASC";
            }
            else
            {
                orderString = "CREATE_TIME DESC";
            }

            var list            = this._backlogBll.GetList(query, orderString);
            var backlogInfoList = Mapper.Map <List <T_BACKLOG>, List <BacklogInfoModel> >(list);

            return(backlogInfoList);
        }
Beispiel #3
0
        public bool DeleteTeam(int teamID)
        {
            bool isSucess = true;

            using (var tran = DbContext.DbTransaction)
            {
                try
                {
                    var teamQuery = new DapperExQuery <T_TEAM>().AndWhere(s => s.ID, OperationMethod.Equal, teamID);
                    DbContext.Delete <T_TEAM>(teamQuery.GetSqlQuery(DbContext));
                    var teamMembersQuery = new DapperExQuery <T_TEAM_MEMBER>().AndWhere(s => s.T_TEAM_ID, OperationMethod.Equal, teamID);
                    DbContext.Delete <T_TEAM_MEMBER>(teamMembersQuery.GetSqlQuery(DbContext));
                }
                catch (Exception e)
                {
                    isSucess = false;
                    throw e;
                }
                finally
                {
                    if (isSucess)
                    {
                        tran.Commit();
                    }
                    else
                    {
                        tran.Rollback();
                    }
                }
                return(isSucess);
            }
        }
Beispiel #4
0
        public bool DeleteProject(int projectID)
        {
            bool isSucess = true;

            using (var tran = DbContext.DbTransaction)
            {
                try
                {
                    var projectQuery = new DapperExQuery <T_PROJECT>().AndWhere(s => s.ID, OperationMethod.Equal, projectID);
                    DbContext.Delete <T_PROJECT>(projectQuery.GetSqlQuery(DbContext));
                    var projectMembersQuery = new DapperExQuery <T_PROJECT_MEMBER>().AndWhere(s => s.P_PROJECT_ID, OperationMethod.Equal, projectID);
                    DbContext.Delete <T_PROJECT_MEMBER>(projectMembersQuery.GetSqlQuery(DbContext));
                }
                catch (Exception e)
                {
                    isSucess = false;
                    throw e;
                }
                finally
                {
                    if (isSucess)
                    {
                        tran.Commit();
                    }
                    else
                    {
                        tran.Rollback();
                    }
                }
                return(isSucess);
            }
        }
Beispiel #5
0
        /// <summary>
        /// 单行删除
        /// 创建  毛枫  2015-4-17
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Grid2_RowCommand(object sender, GridCommandEventArgs e)
        {
            object[] values = Grid2.DataKeys[e.RowIndex];
            string   A_CODE = values[1].ToString();

            //T_ADMIN T_ADMIN = new T_ADMIN();
            //var queryuser = new DapperExQuery<T_ADMIN>().AndWhere(n => n.ID, OperationMethod.Equal, userID);
            //T_ADMIN = T_ADMIN_BLL.GetEntity(queryuser);
            //string a_code = T_ADMIN.A_CODE;
            //判断点击的是删除
            if (e.CommandName == "Delete")
            {
                //// 在操作之前进行权限检查
                //if (!CheckPower("CoreRoleUserDelete"))
                //{
                //    CheckPowerFailWithAlert();
                //    return;
                //}
                string R_CODE = FineUITable.GetSelectedDataKeyCode(Grid1);
                var    query  = new DapperExQuery <T_ADMIN_ROLES>().AndWhere(n => n.R_CODE, OperationMethod.Equal, R_CODE)
                                .AndWhere(n => n.A_CODE, OperationMethod.Equal, A_CODE);
                var user_role = T_ADMIN_ROLES_BLL.GetEntity(query);
                if (user_role != null)
                {
                    T_ADMIN_ROLES_BLL.Delete(query);
                }
                //绑定刷新
                BindGrid2();
            }
        }
Beispiel #6
0
        public bool DeleteSprint(DapperExQuery <T_RELEASE_SPRINT> deleteQuery, T_RELEASE_SPRINT modifySprint)
        {
            bool isSucess = true;

            using (var tran = DbContext.DbTransaction)
            {
                try
                {
                    bool deleteResult = DbContext.Delete <T_RELEASE_SPRINT>(deleteQuery.GetSqlQuery(DbContext));
                    if (deleteResult && modifySprint != null)
                    {
                        this.Update(modifySprint);
                    }
                }
                catch (Exception e)
                {
                    isSucess = false;
                    throw e;
                }
                finally
                {
                    if (isSucess)
                    {
                        tran.Commit();
                    }
                    else
                    {
                        tran.Rollback();
                    }
                }
                return(isSucess);
            }
        }
Beispiel #7
0
        //=========数据绑定

        #region 数据绑定
        /// <summary>
        /// 数据绑定
        /// 创建人:林以恒
        /// 2015年7月6日14:09:00
        /// </summary>
        private void LoadData()
        {
            if (!Request.QueryString["id"].IsNum())
            {
                return;
            }
            string id        = Request.QueryString["id"];
            var    query     = new DapperExQuery <T_ADMIN>().AndWhere(n => n.ID, OperationMethod.Equal, Int32.Parse(id));
            var    adminUser = _adminUserBll.GetEntity(query);

            tbxA_NAME.Text         = adminUser.A_NAME;
            tbxA_CHINESE_NAME.Text = adminUser.A_TRUE_NAME;
            tbxPassword.Text       = adminUser.PASSWORD;
            tbxCfm_Password.Text   = adminUser.PASSWORD;
            tbxPhone.Text          = adminUser.A_PHONE;
            if (adminUser.A_GENDER == 1)
            {
                rbtnFirst.Checked = true;
            }
            else
            {
                rbtnSecond.Checked = true;
            }
            //tbxAD_REMARK.Text = T_ADMIN_ROLES.AD_REMARK.ToString();
        }
        public IDictionary <int, List <ProjectInfoModel> > LoadProjectInfosByUserArray(List <int> userList)
        {
            IDictionary <int, List <ProjectInfoModel> > dict = new Dictionary <int, List <ProjectInfoModel> >();

            if (userList != null && userList.Count > 0)
            {
                userList = userList.Distinct().ToList();
                var query             = new DapperExQuery <T_PROJECT_MEMBER>().AndWhere(s => s.U_USER_ID, OperationMethod.In, userList.ToArray());
                var projectMembers    = this._projectMemberBll.GetList(query);
                var projectMemberList = Mapper.Map <List <T_PROJECT_MEMBER>, List <ProjectMemberModel> >(projectMembers);

                var projectInfos = this._projectBll.GetList(new DapperExQuery <T_PROJECT>().AndWhere(
                                                                s => s.ID,
                                                                OperationMethod.In,
                                                                projectMemberList.Select(s => s.projectID).Distinct().ToArray()));
                var projectInfoList = Mapper.Map <List <T_PROJECT>, List <ProjectInfoModel> >(projectInfos);

                dict = userList.ToDictionary(
                    s => s,
                    s => projectInfoList.Where(
                        n => projectMemberList.Where(m => m.userID.Equals(s)).Select(m => m.projectID).ToList().Contains(n.projectID)).ToList());
            }

            return(dict);
        }
 /// <summary>
 /// 获得单个实体
 /// </summary>
 /// <param name="expr">查询对象</param>
 /// <param name="operation"></param>
 /// <param name="value"></param>
 /// <returns></returns>
 public virtual T GetEntity(DapperExQuery <T> query)
 {
     using (DbBase DbContext = new DbBase(connectionName))
     {
         return(DbContext.SingleOrDefault <T>(query.GetSqlQuery(DbContext)));
     }
 }
        //=========数据绑定

        #region 数据绑定

        /// <summary>
        /// 添加或修改数据绑定
        /// </summary>
        private void LoadData()
        {
            if (Request.QueryString["id"].IsNum())
            {
                string   id     = Request.QueryString["id"].ToString();
                var      query  = new DapperExQuery <T_POWERS>().AndWhere(n => n.ID, OperationMethod.Equal, id);
                T_POWERS powers = null;
                powers = _powersBll.GetEntity(query);
                if (powers == null)
                {
                    return;
                }
                tbxP_Name.Text         = powers.P_NAME.ToString();
                tbxP_CHINESE_NAME.Text = powers.P_CHINESE_NAME != null?powers.P_CHINESE_NAME.ToString() : "";

                //tbx_groupname.Text = powers.GROUP_NAME != null ? powers.GROUP_NAME.ToString() : "";
                //tbxAP_GROUP_NAME.Text = (powers.AP_GROUP_NAME.ToString() != null
                //    ? powers.AP_GROUP_NAME.ToString()
                //    : "");
                //tbxAP_REMARK.Text = (powers.AP_REMARK.ToString() != null
                //    ? powers.AP_REMARK.ToString()
                //    : "");
                //tbxAP_TITLE.Text = (powers.AP_TITLE.ToString() != null ? powers.AP_TITLE.ToString() : "");
            }
        }
        //============操作方法===========
        #region 数据保存

        /// <summary>
        /// 数据保存按钮事件
        /// 创建 林以恒
        /// 2015年4月14日
        /// </summary>
        protected void btnSaveClose_Click(object sender, EventArgs e)
        {
            ////设置页面权限
            //Power.SetViewPower("mod_menu");
            ////验证权限
            //if (Power.VerifyPower() == false)
            //{
            //    return;
            //}
            string str;

            if (Request.QueryString["id"].IsNum())
            {
                string id = Request.QueryString["id"].ToString();
                //修改
                T_ADMIN_MENUS T_ADMIN_MENUS = new T_ADMIN_MENUS();
                var           q             = new DapperExQuery <T_ADMIN_MENUS>().AndWhere(n => n.ID, OperationMethod.Equal, id);
                T_ADMIN_MENUS = _adminMenusBll.GetEntity(q);
                T_ADMIN_MENUS = GetnewModel(T_ADMIN_MENUS);
                str           = _adminMenusBll.Update(T_ADMIN_MENUS) ? "修改成功!" : "修改失败!";
            }
            else
            {
                //添加
                T_ADMIN_MENUS adminMenus = new T_ADMIN_MENUS();
                adminMenus           = GetnewModel(adminMenus);
                adminMenus.PARENT_ID = Int32.Parse(Request.QueryString["fatherId"].ToString());
                str = _adminMenusBll.Add(adminMenus) ? "添加成功!" : "添加失败!";
            }
            // 2. 关闭本窗体,然后刷新父窗体
            PageContext.RegisterStartupScript(ActiveWindow.GetHideRefreshReference());
            Alert.ShowInTop(str);
        }
        //============操作方法===========
        #region 数据保存
        /// <summary>
        /// 数据保存按钮事件
        /// 创建人:林以恒
        /// 2015年7月6日21:28:17
        /// </summary>
        protected void btnSaveClose_Click(object sender, EventArgs e)
        {
            ////设置页面权限
            //Power.SetViewPower("mod_power");
            ////验证权限
            //if (Power.VerifyPower() == false)
            //{
            //    return;
            //}
            string str;

            if (Request.QueryString["id"].IsNum())
            {
                T_POWERS powers = null;
                string   id     = Request.QueryString["id"];
                //修改
                var query = new DapperExQuery <T_POWERS>().AndWhere(n => n.ID, OperationMethod.Equal, int.Parse(id));
                powers = _powersBll.GetEntity(query);
                powers = Save(powers);
                str    = _powersBll.Update(powers) ? "修改成功!" : "修改失败!";
            }
            else
            {
                T_POWERS powers = new T_POWERS();
                //添加
                powers = Save(powers);

                powers.FATHER_CODE = Request.QueryString["fathercode"].ToString();
                str = _powersBll.Add(powers) ? "添加成功!" : "添加失败!";
            }
            // 2. 关闭本窗体,然后刷新父窗体
            PageContext.RegisterStartupScript(ActiveWindow.GetHideRefreshReference());
            Alert.ShowInTop(str);
        }
Beispiel #13
0
        /// <summary>
        /// 分组绑定右侧权限
        /// 修改人:金协民 2015年7月29日
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Grid2_RowDataBound(object sender, GridRowEventArgs e)
        {
            AspNet.CheckBoxList ddlPowers = (AspNet.CheckBoxList)Grid2.Rows[e.RowIndex].FindControl("ddlPowers");
            var             GroupName     = e.DataItem.GetType().GetProperty("GroupName").GetValue(e.DataItem, null);
            List <T_POWERS> T_POWERS_LIST = new List <T_POWERS>();
            var             query         = new DapperExQuery <T_POWERS>().AndWhere(n => n.GROUP_NAME, OperationMethod.Equal, GroupName);

            T_POWERS_LIST = T_POWERS_BLL.GetAllList(query);
            foreach (var po in T_POWERS_LIST)
            {
                AspNet.ListItem item = new AspNet.ListItem
                {
                    Value = po.P_CODE.ToString(),
                    Text  = string.Format("{0}({1})", po.P_CHINESE_NAME, po.P_NAME)
                };
                item.Attributes["data-qtip"] = po.P_NAME;
                if (_currentRolePowers.ContainsKey(po.P_NAME))
                {
                    item.Selected = true;
                }
                else
                {
                    item.Selected = false;
                }
                ddlPowers.Items.Add(item);
            }
        }
Beispiel #14
0
        /// <summary>
        /// 根据用户角色code来获取权限列表
        /// 创建  毛枫  2015-4-21
        /// </summary>
        /// <param name="RoleId"></param>
        /// <returns></returns>
        public static List <T_POWERS> GetUserPower(string r_code)
        {
            List <T_POWERS>       T_POWERS_LIST      = new List <T_POWERS>();
            List <T_ROLES_POWERS> T_ROLES_POWER_LIST = new List <Mammothcode.Model.T_ROLES_POWERS>();
            var query = new DapperExQuery <T_ROLES_POWERS>().AndWhere(n => n.R_CODE, OperationMethod.Equal, r_code);

            //获取权限列表
            T_ROLES_POWER_LIST = T_ROLES_POWERS_BLL.GetAllList(query);
            if (T_ROLES_POWER_LIST != null)
            {
                foreach (T_ROLES_POWERS q in T_ROLES_POWER_LIST)
                {
                    string   powerCode  = q.P_CODE;
                    var      querypower = new DapperExQuery <T_POWERS>().AndWhere(n => n.P_CODE, OperationMethod.Equal, powerCode);
                    T_POWERS T_POWERS   = new T_POWERS();
                    //获取权限model
                    T_POWERS = T_POWERS_BLL.GetEntity(querypower);
                    T_POWERS_LIST.Add(T_POWERS);
                }
            }
            else
            {
                T_POWERS_LIST = null;
            }
            return(T_POWERS_LIST);
        }
Beispiel #15
0
 /// <summary>
 /// 统计指定条件的数据量
 /// </summary>
 /// <param name="queryList"></param>
 /// <returns></returns>
 public virtual long GetCount(DapperExQuery <T> query)
 {
     using (DbBase DbContext = new DbBase(connectionName))
     {
         return(DbContext.Count <T>(query.GetSqlQuery(DbContext)));
     }
 }
Beispiel #16
0
        /// <summary>
        /// 右侧角色对应用户的数据绑定
        /// 创建  毛枫  2015-4-17
        /// </summary>
        private void BindGrid2()
        {
            string R_CODE = FineUITable.GetSelectedDataKeyCode(Grid1);

            if (R_CODE == "")
            {
                Grid2.RecordCount = 0;
                Grid2.DataSource  = null;
                Grid2.DataBind();
            }
            else
            {
                // 过滤选中角色下的所有用户
                long allcount           = 0;
                var  query              = new DapperExQuery <T_ADMIN_ROLES>().AndWhere(n => n.R_CODE, OperationMethod.Equal, R_CODE);
                int  PageIndex          = Grid2.PageIndex + 1;
                int  PageSize           = Grid2.PageSize;
                List <T_ADMIN_ROLES> qs = T_ADMIN_ROLES_BLL.GetListByPage(query, "", PageIndex, PageSize, out allcount);

                List <T_ADMIN> q = new List <T_ADMIN>();
                foreach (T_ADMIN_ROLES t in qs)
                {
                    var     query1  = new DapperExQuery <T_ADMIN>().AndWhere(n => n.A_CODE, OperationMethod.Equal, t.A_CODE);
                    T_ADMIN T_ADMIN = new T_ADMIN();
                    T_ADMIN = T_ADMIN_BLL.GetEntity(query1);
                    q.Add(T_ADMIN);
                }

                //获取总记录数
                Grid2.RecordCount = Int32.Parse(allcount.ToString());
                Grid2.DataSource  = q;
                Grid2.DataBind();
            }
        }
Beispiel #17
0
 /// <summary>
 /// 获得子查询条件
 /// </summary>
 /// <param name="query"></param>
 /// <returns></returns>
 public virtual InWhereQuery GetInWhereSql(string selectField, DapperExQuery <T> query)
 {
     using (DbBase DbContext = new DbBase(connectionName))
     {
         SqlQuery sql = query.GetSqlQuery(DbContext);
         return(query.TranInWhereQuery(selectField, sql));
     }
 }
Beispiel #18
0
 /// <summary>
 /// 分页_获取指定条件的数据集合(开始位置,结束位置)
 /// </summary>
 /// <param name="query">查询条件</param>
 /// <param name="pageIndex">开始位置(默认从1开始)</param>
 /// <param name="pageSize">当前页数</param>
 /// <param name="pageCount">总页数</param>
 /// <param name="dataCount">总查询数</param>
 /// <returns></returns>
 public virtual List <T> GetListByByRowNumber(DapperExQuery <T> query, string orderString, int startRowNumber, int endRowNumber, out long dataCount)
 {
     using (DbBase DbContext = new DbBase(connectionName))
     {
         //设置Order条件
         query.SetOrder(orderString);
         return(DbContext.PageDataByRowNumber <T>(startRowNumber, endRowNumber, out dataCount, query.GetSqlQuery(DbContext)));
     }
 }
Beispiel #19
0
 /// <summary>
 ///  获取指定条件的实体集合
 /// </summary>
 /// <param name="queryList"></param>
 /// <returns></returns>
 public virtual List <T> GetList(DapperExQuery <T> query, string orderString = "")
 {
     if (!string.IsNullOrEmpty(orderString))
     {
         //设置Order条件
         query.SetOrder(orderString);
     }
     return(DbContext.QueryData <T>(query.GetSqlQuery(DbContext)));
 }
Beispiel #20
0
 /// <summary>
 /// 分页_获取指定条件的数据集合(第几页,每页个数)
 /// </summary>
 /// <param name="query">查询条件</param>
 /// <param name="pageIndex">开始位置(默认从1开始)</param>
 /// <param name="pageSize">页面显示数量</param>
 /// <param name="pageCount">总页数</param>
 /// <param name="dataCount">总查询数</param>
 /// <returns></returns>
 public virtual List <T> GetListByPage(DapperExQuery <T> query, string orderString, int pageIndex, int pageSize, out long dataCount)
 {
     using (DbBase DbContext = new DbBase(connectionName))
     {
         //设置Order条件
         query.SetOrder(orderString);
         return(DbContext.PageData <T>(pageIndex, pageSize, out dataCount, query.GetSqlQuery(DbContext)));
     }
 }
Beispiel #21
0
        /// <summary>
        /// 私有方法:从数据库中判断用户是否登录
        /// 创建  毛枫  2015-4-21
        /// </summary>
        /// <param name="username"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        private static T_ADMIN IsLoginFromSql(string username, string password)
        {
            T_ADMIN_BLL T_ADMIN_BLL = new T_ADMIN_BLL();
            var         query       = new DapperExQuery <T_ADMIN>().AndWhere(n => n.A_NAME, OperationMethod.Equal, username)
                                      .AndWhere(n => n.PASSWORD, OperationMethod.Equal, EncryptUtil.Md5Encode(password.Trim(), 16));
            var admin = T_ADMIN_BLL.GetEntity(query);

            return(admin);
        }
Beispiel #22
0
        /// <summary>
        /// 删除实体
        /// </summary>
        /// <param name="expr"></param>
        /// <param name="operation"></param>
        /// <param name="value"></param>
        public virtual bool Delete(DapperExQuery <T> query, IDbTransaction transaction = null)
        {
            bool flag = false;

            using (DbBase DbContext = new DbBase(connectionName))
            {
                flag = DbContext.Delete <T>(query.GetSqlQuery(DbContext), transaction);
                DbContext.CloseConnection();
            }
            return(flag);
        }
        //=========数据绑定

        #region 修改数据绑定
        /// <summary>
        /// 数据绑定
        /// 创建人:林以恒
        /// 2015年7月12日15:21:16
        /// </summary>
        private void LoadData()
        {
            if (Request.QueryString["id"].IsNum())
            {
                T_ROLES roles = new T_ROLES();
                string id = Request.QueryString["id"].ToString();
                var query = new DapperExQuery<T_ROLES>().AndWhere(n => n.ID, OperationMethod.Equal, Int32.Parse(id));
                roles = _rolesBll.GetEntity(query);
                tbxR_Name.Text = roles.R_NAME.ToString();
                //tbxAD_REMARK.Text = T_ADMIN_ROLES.AD_REMARK.ToString();
            }
        }
Beispiel #24
0
        /// <summary>
        /// 获取第三方绑定信息
        /// </summary>
        /// <param name="userID"></param>
        /// <param name="from"></param>
        /// <returns></returns>
        private ThirdPartyInfoModel getThirdPartyInfoModel(int userID, string from)
        {
            ThirdPartyInfoModel thirdPartyInfoModel = null;
            var query = new DapperExQuery <T_THIRD_PARTY>().AndWhere(t => t.U_USER_ID, OperationMethod.Equal, userID).AndWhere(k => k.T_FROM, OperationMethod.Equal, from);
            var model = this._thirdBll.GetEntity(query);

            if (model != null)
            {
                thirdPartyInfoModel = Mapper.Map <T_THIRD_PARTY, ThirdPartyInfoModel>(model);
            }
            return(thirdPartyInfoModel);
        }
        //=========数据绑定

        #region 修改数据绑定
        /// <summary>
        /// 数据绑定
        /// 创建人:林以恒
        /// 2015年7月12日15:21:16
        /// </summary>
        private void LoadData()
        {
            if (Request.QueryString["id"].IsNum())
            {
                T_ROLES roles = new T_ROLES();
                string  id    = Request.QueryString["id"].ToString();
                var     query = new DapperExQuery <T_ROLES>().AndWhere(n => n.ID, OperationMethod.Equal, Int32.Parse(id));
                roles          = _rolesBll.GetEntity(query);
                tbxR_Name.Text = roles.R_NAME.ToString();
                //tbxAD_REMARK.Text = T_ADMIN_ROLES.AD_REMARK.ToString();
            }
        }
Beispiel #26
0
 /// <summary>
 ///  获取指定条件的所有数据集合
 /// </summary>
 /// <param name="queryList"></param>
 /// <returns></returns>
 public virtual List <T> GetAllList(DapperExQuery <T> query, string orderString = "")
 {
     using (DbBase DbContext = new DbBase(connectionName))
     {
         if (!string.IsNullOrEmpty(orderString))
         {
             //设置Order条件
             query.SetOrder(orderString);
         }
         return(DbContext.QueryData <T>(query.GetSqlQuery(DbContext)));
     }
 }
 /// <summary>
 /// 返回按钮事件
 ///创建 毛枫   2015-4-20
 /// </summary>
 protected void back_Click(object sender, EventArgs e)
 {
     if (fathercode != "0")
     {
         var query = new DapperExQuery <T_POWERS>().AndWhere(n => n.P_CODE, OperationMethod.Equal, fathercode);
         var q     = _powersbll.GetEntity(query);
         if (q != null)
         {
             fathercode = q.FATHER_CODE;
             Replace();
         }
     }
 }
Beispiel #28
0
        public virtual bool IsExist(DapperExQuery <T> query)
        {
            bool returnBool = false;

            using (DbBase DbContext = new DbBase(connectionName))
            {
                if (DbContext.SingleOrDefault <T>(query.GetSqlQuery(DbContext)) != null)
                {
                    returnBool = true;
                }
            }
            return(returnBool);
        }
Beispiel #29
0
 /// <summary>
 ///  获取指定条件的实体集合
 /// </summary>
 /// <param name="queryList"></param>
 /// <returns></returns>
 public virtual List <T> GetAllList(string orderString = "")
 {
     if (!string.IsNullOrEmpty(orderString))
     {
         DapperExQuery <T> query = new DapperExQuery <T>();
         query.SetOrder(orderString);
         return(DbContext.QueryData <T>(query.GetSqlQuery(DbContext)));
     }
     else
     {
         return(DbContext.QueryData <T>());
     }
 }
Beispiel #30
0
 /// <summary>
 /// 返回按钮事件
 ///创建 毛枫   2015-4-20
 /// </summary>
 protected void back_Click(object sender, EventArgs e)
 {
     if (fatherId != 0)
     {
         var query = new DapperExQuery <T_ADMIN_MENUS>().AndWhere(n => n.ID, OperationMethod.Equal, fatherId);
         var q     = _adminMenusBll.GetEntity(query);
         if (q != null)
         {
             fatherId = q.PARENT_ID;
             Replace();
         }
     }
 }
Beispiel #31
0
        public bool TransformTeam(int teamID, string oldOwnerMail, string newOwnerMail)
        {
            bool isSucess = true;

            using (var tran = DbContext.DbTransaction)
            {
                try
                {
                    var oldTeamOwnerQuery = new DapperExQuery <T_TEAM_MEMBER>()
                                            .AndWhere(s => s.T_TEAM_ID, OperationMethod.Equal, teamID)
                                            .AndWhere(s => s.U_USER_EMAIL, OperationMethod.Equal, oldOwnerMail)
                                            .AndWhere(s => s.R_USER_ROLE_CODE, OperationMethod.Equal, RoleCode.Owner);
                    var oldTeamOwner = DbContext.SingleOrDefault <T_TEAM_MEMBER>(oldTeamOwnerQuery.GetSqlQuery(DbContext));

                    var newTeamOwnerQuery = new DapperExQuery <T_TEAM_MEMBER>()
                                            .AndWhere(s => s.T_TEAM_ID, OperationMethod.Equal, teamID)
                                            .AndWhere(s => s.U_USER_EMAIL, OperationMethod.Equal, newOwnerMail);
                    var newTeamOwner = DbContext.SingleOrDefault <T_TEAM_MEMBER>(newTeamOwnerQuery.GetSqlQuery(DbContext));
                    if (oldTeamOwner != null && newTeamOwner != null)
                    {
                        oldTeamOwner.R_USER_ROLE_CODE = RoleCode.Member;
                        newTeamOwner.R_USER_ROLE_CODE = RoleCode.Owner;
                        DbContext.Update(oldTeamOwner);
                        DbContext.Update(newTeamOwner);
                        isSucess = true;
                    }
                    else
                    {
                        isSucess = false;
                    }
                }
                catch (Exception e)
                {
                    isSucess = false;
                    throw e;
                }
                finally
                {
                    if (isSucess)
                    {
                        tran.Commit();
                    }
                    else
                    {
                        tran.Rollback();
                    }
                }
                return(isSucess);
            }
        }
        //=========数据绑定

        #region 数据绑定

        /// <summary>
        /// 修改数据绑定
        /// 创建 林以恒 
        /// 2015年4月14日
        /// </summary>
        private void LoadData()
        {
            if (!Request.QueryString["id"].IsNum()) return;
            string id = Request.QueryString["id"].ToString();
            var query = new DapperExQuery<T_ADMIN_MENUS>().AndWhere(n => n.ID, OperationMethod.Equal, id);
            _adminMenus = _adminMenusBll.GetEntity(query);
            tbxAM_NAME.Text = (_adminMenus.AM_NAME != null ? _adminMenus.AM_NAME.ToString() : "");
            tbxAM_NAVIGATE_URL.Text = (_adminMenus.AM_NAVIGATE_URL != null ? _adminMenus.AM_NAVIGATE_URL.ToString() : "");
            tbxAM_REMARK.Text = (_adminMenus.AM_REMARK != null ? _adminMenus.AM_REMARK.ToString() : "");
            tbxAM_SORTINDEX.Text = _adminMenus.AM_SORTINDEX.ToString();
            if (_adminMenus.P_CODE != null && _adminMenus.P_CODE != "")
            {
                tbxVIEWPOWER_ID.Text = _powersBll.GetEntity(new DapperExQuery<T_POWERS>().AndWhere(n => n.P_CODE, OperationMethod.Equal, _adminMenus.P_CODE)).P_NAME;
            }
        }
        //=========数据绑定

        #region 数据绑定

        /// <summary>
        /// 添加或修改数据绑定
        /// </summary>
        private void LoadData()
        {
            if (Request.QueryString["id"].IsNum())
            {
                string id = Request.QueryString["id"].ToString();
                var query = new DapperExQuery<T_POWERS>().AndWhere(n => n.ID, OperationMethod.Equal, id);
                T_POWERS powers = null;
                powers = _powersBll.GetEntity(query);
                if (powers == null) return;
                tbxP_Name.Text = powers.P_NAME.ToString();
                tbxP_CHINESE_NAME.Text = powers.P_CHINESE_NAME != null ? powers.P_CHINESE_NAME.ToString() : "";
                //tbx_groupname.Text = powers.GROUP_NAME != null ? powers.GROUP_NAME.ToString() : "";
                //tbxAP_GROUP_NAME.Text = (powers.AP_GROUP_NAME.ToString() != null
                //    ? powers.AP_GROUP_NAME.ToString()
                //    : "");
                //tbxAP_REMARK.Text = (powers.AP_REMARK.ToString() != null
                //    ? powers.AP_REMARK.ToString()
                //    : "");
                //tbxAP_TITLE.Text = (powers.AP_TITLE.ToString() != null ? powers.AP_TITLE.ToString() : "");
            }
        }
        //=========数据绑定

        #region 数据绑定
        /// <summary>
        /// 数据绑定
        /// 创建人:林以恒
        /// 2015年7月6日14:09:00
        /// </summary>
        private void LoadData()
        {
            if (!Request.QueryString["id"].IsNum()) return;
            string id = Request.QueryString["id"];
            var query = new DapperExQuery<T_ADMIN>().AndWhere(n => n.ID, OperationMethod.Equal, Int32.Parse(id));
            var adminUser = _adminUserBll.GetEntity(query);
            tbxA_NAME.Text = adminUser.A_NAME;
            tbxA_CHINESE_NAME.Text = adminUser.A_TRUE_NAME;
            tbxPassword.Text = adminUser.PASSWORD;
            tbxCfm_Password.Text = adminUser.PASSWORD;
            tbxPhone.Text = adminUser.A_PHONE;
            if (adminUser.A_GENDER == 1)
            {
                rbtnFirst.Checked = true;
            }
            else
            {
                rbtnSecond.Checked = true;
            }
            //tbxAD_REMARK.Text = T_ADMIN_ROLES.AD_REMARK.ToString();
        }
 /// <summary>
 /// 初始化数据绑定
 /// 创建 2015-4-17
 /// </summary>
 private void LoadData()
 {
     btnClose.OnClientClick = ActiveWindow.GetHideReference();
     int rolesid = 0;
     if (Request.QueryString[requestStr].IsNum())
     {
         rolesid = Int32.Parse(Request.QueryString[requestStr]);
     }
     T_ROLES T_ROLES = new T_ROLES();
     var query = new DapperExQuery<T_ROLES>().AndWhere(n => n.ID, OperationMethod.Equal, rolesid);
     T_ROLES = T_ROLES_BLL.GetEntity(query);
     if (T_ROLES == null)
     {
         // 参数错误,首先弹出Alert对话框然后关闭弹出窗口
         Alert.Show("参数错误!", String.Empty, ActiveWindow.GetHideReference());
         return;
     }
     // 每页记录数
     Grid1.PageSize = 10;
     //ddlGridPageSize.SelectedValue = ConfigHelper.PageSize.ToString();
     BindGrid();
 }
        /// <summary>
        ///右侧分组权限绑定,并显示对应角色有哪些权限
        /// 修改人:金协民 2015年7月29日
        /// </summary>
        private void BindGrid2()
        {
            var roleId = GetSelectedDataKeyID(Grid1);
            if (string.IsNullOrEmpty(roleId))
            {
                Grid2.DataSource = null;
                Grid2.DataBind();
            }
            else
            {
                // 当前选中角色拥有的权限列表
                _currentRolePowers.Clear();
                List<T_ROLES_POWERS> T_ADMIN_ROLE_POWER_LIST = new List<T_ROLES_POWERS>();
                var query = new DapperExQuery<T_ROLES_POWERS>().AndWhere(n => n.R_CODE, OperationMethod.Equal, roleId);
                //拿到角色对应的权限,标记为选中
                T_ADMIN_ROLE_POWER_LIST = T_ROLES_POWERS_BLL.GetAllList(query);
                if (T_ADMIN_ROLE_POWER_LIST != null)
                {
                    foreach (var power in T_ADMIN_ROLE_POWER_LIST)
                    {
                        var powersId = power.P_CODE;
                        var query1 = new DapperExQuery<T_POWERS>().AndWhere(n => n.P_CODE, OperationMethod.Equal, powersId);
                        T_POWERS T_POWERS = new Model.T_POWERS();
                        T_POWERS = T_POWERS_BLL.GetEntity(query1);
                        string powerName = T_POWERS.P_NAME;
                        if (!_currentRolePowers.ContainsKey(powerName))
                        {
                            _currentRolePowers.Add(powerName, true);
                        }
                    }
                }
                //分组拿到所有权限
                var q = T_POWERS_BLL.GetAllList().GroupBy(n => n.GROUP_NAME);
                //自定数据结构,包括组名,组内权限集
                var powers = q.Select(g => new
                {
                    GroupName = g.Key,
                    Powers = g
                });
                Grid2.DataSource = powers;
                Grid2.DataBind();
            }

        }
        //============操作方法===========

        #region 删除
        /// <summary>
        /// 删除后台用户
        /// 创建人: 林以恒  
        /// 2015年7月29日11:46:14
        /// </summary>
        protected void Grid1_RowCommand(object sender, GridCommandEventArgs e)
        {
            //设置页面权限
            power.SetViewPower("mod_admin");
            //验证权限
            if (power.VerifyPower() == false)
            {
                return;
            }
            object[] keys = Grid1.DataKeys[e.RowIndex];
            int id = int.Parse(keys[0].ToString());
            if (e.CommandName != "Delete") return;
            var query = new DapperExQuery<T_ADMIN>().AndWhere(n => n.ID, OperationMethod.Equal, id);
            Alert.ShowInTop(t_admin_bll.Delete(query) ? "删除成功!" : "删除失败!");
            BindGrid();
        }
        /// <summary>
        /// 右侧角色对应用户的数据绑定
        /// 创建  毛枫  2015-4-17
        /// </summary>
        private void BindGrid2()
        {
            string R_CODE = FineUITable.GetSelectedDataKeyCode(Grid1);
            if (R_CODE =="")
            {
                Grid2.RecordCount = 0;
                Grid2.DataSource = null;
                Grid2.DataBind();
            }
            else
            {
                // 过滤选中角色下的所有用户
                long allcount = 0;
                var query = new DapperExQuery<T_ADMIN_ROLES>().AndWhere(n => n.R_CODE, OperationMethod.Equal, R_CODE);
                int PageIndex = Grid2.PageIndex + 1;
                int PageSize = Grid2.PageSize;
                List<T_ADMIN_ROLES> qs = T_ADMIN_ROLES_BLL.GetListByPage(query, "", PageIndex, PageSize, out allcount);

                List<T_ADMIN> q = new List<T_ADMIN>();
                foreach (T_ADMIN_ROLES t in qs)
                {
                    var query1 = new DapperExQuery<T_ADMIN>().AndWhere(n => n.A_CODE, OperationMethod.Equal, t.A_CODE);
                    T_ADMIN T_ADMIN = new T_ADMIN();
                    T_ADMIN = T_ADMIN_BLL.GetEntity(query1);
                    q.Add(T_ADMIN);
                }

                //获取总记录数
                Grid2.RecordCount = Int32.Parse(allcount.ToString());
                Grid2.DataSource = q;
                Grid2.DataBind();
            }

        }
 /// <summary>
 /// 返回按钮事件
 ///创建 毛枫   2015-4-20
 /// </summary>
 protected void back_Click(object sender, EventArgs e)
 {
     if (fathercode != "0")
     {
         var query = new DapperExQuery<T_POWERS>().AndWhere(n => n.P_CODE, OperationMethod.Equal, fathercode);
         var q = _powersbll.GetEntity(query);
         if (q != null)
         {
             fathercode = q.FATHER_CODE;
             Replace();
         }
     }
 }
        //============ GRID事件==========
        #region 删除

        /// <summary>
        /// 删除
        /// 修改:林以恒 2015-4-19
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Grid1_RowCommand(object sender, GridCommandEventArgs e)
        {
            ////设置页面权限
            //Power.SetViewPower("mod_role");
            ////验证权限
            //if (Power.VerifyPower() == false)
            //{
            //    return;
            //}
            object[] keys = Grid1.DataKeys[e.RowIndex];
            int id = Int32.Parse(keys[0].ToString());
            if (e.CommandName != "Delete") return;
            var query = new DapperExQuery<T_ROLES>().AndWhere(n => n.ID, OperationMethod.Equal, id);
            Alert.ShowInTop(_rolesBll.Delete(query) ? "删除成功!" : "删除失败!");
            //页面刷新
            Bind();
        }
 /// <summary>
 /// 返回按钮事件
 ///创建 毛枫   2015-4-20
 /// </summary>
 protected void back_Click(object sender, EventArgs e)
 {
     if (fatherId != 0)
     {
         var query = new DapperExQuery<T_ADMIN_MENUS>().AndWhere(n => n.ID, OperationMethod.Equal, fatherId);
         var q = _adminMenusBll.GetEntity(query);
         if (q != null)
         {
             fatherId = q.PARENT_ID;
             Replace();
         }
     }
 }
        /// <summary>
        /// 添加角色对应的用户
        /// 创建 2015-4-17
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnSaveClose_Click(object sender, EventArgs e)
        {
            SyncSelectedRowIndexArrayToHiddenField();
            string str = "";

            // 排除已经属于本角色的用户
            int roleID = 0;
            if (Request.QueryString[requestStr].IsNum())
            {
                roleID = Int32.Parse(Request.QueryString[requestStr]);
                T_ROLES T_ROLES = new T_ROLES();
                var queryrole = new DapperExQuery<T_ROLES>().AndWhere(n => n.ID, OperationMethod.Equal, roleID);
                T_ROLES = T_ROLES_BLL.GetEntity(queryrole);
                var r_code = T_ROLES.R_CODE;
                // 从每个选中的行中获取ID(在Grid1中定义的DataKeyNames)
                List<int> userids = FineUITable.GetSelectedDataKeyIDs(Grid1);
                foreach (int userID in userids)
                {
                    var queryAdmin = new DapperExQuery<T_ADMIN>().AndWhere(n => n.ID, OperationMethod.Equal, userID);
                    T_ADMIN T_ADMIN = new Model.T_ADMIN();
                    T_ADMIN = T_ADMIN_BLL.GetEntity(queryAdmin);
                    T_ADMIN_ROLES T_ADMIN_ROLES = new T_ADMIN_ROLES();
                    T_ADMIN_ROLES.R_CODE = r_code;
                    T_ADMIN_ROLES.A_CODE = T_ADMIN.A_CODE;
                    T_ADMIN_ROLES.CREATE_TIME = DateTime.Parse("2015-10-9");
                    T_ADMIN_ROLES.CREATE_USER = "";
                    T_ADMIN_ROLES.CREATE_USER_NAME = "";

                    if (T_ADMIN_ROLES_BLL.Add(T_ADMIN_ROLES))
                    {
                        str = "添加成功!";
                    }
                    else
                    {
                        str = "添加失败!";
                    }
                }
                //DB.SaveChanges();

                PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference());
                Alert.Show("str");
            }
        }
 /// <summary>
 /// 根据登入的用户ID,获取用户角色ID列表
 /// 创建  金协民  2015-7-3
 /// </summary>
 /// <param name="userId"></param>
 /// <returns></returns>
 private static List<string> GetUserRole(string adminCode)
 {
     List<string> RoleList = new List<string>();
     var query = new DapperExQuery<T_ADMIN_ROLES>().AndWhere(n => n.A_CODE, OperationMethod.Equal, adminCode);
     List<T_ADMIN_ROLES> ROLE_USERS_LIST = new List<T_ADMIN_ROLES>();
     //获取用户角色CODE列表
     ROLE_USERS_LIST = new T_ADMIN_ROLES_BLL().GetAllList(query);
     if (ROLE_USERS_LIST != null)
     {
         RoleList.AddRange(ROLE_USERS_LIST.Select(q => q.R_CODE));
     }
     else
     {
         RoleList = null;
     }
     return RoleList;
 }
        /// <summary>
        /// 用户数据绑定
        /// 创建 2015-4-17
        /// </summary>
        private void BindGrid()
        {
            List<T_ADMIN> T_ADMIN_LIST = new List<T_ADMIN>();
            //当前页数
            int PageIndex = Grid1.PageIndex + 1;
            //一页的数据条数
            int PageSize = Grid1.PageSize;
            //数据总条数
            long allcount;
            //分页拿到总数据
            var queryall = new DapperExQuery<T_ADMIN>();
            T_ADMIN_LIST = T_ADMIN_BLL.GetListByPage(queryall, "", PageIndex, PageSize, out allcount);
            // 在名称中搜索
            string searchText = ttbSearchMessage.Text.Trim();
            if (!String.IsNullOrEmpty(searchText))
            {
                var query = new DapperExQuery<T_ADMIN>().AndWhere(n => n.A_NAME, OperationMethod.Equal, searchText)
                 .AndWhere(n => n.A_TRUE_NAME, OperationMethod.Equal, searchText);
                T_ADMIN_LIST = T_ADMIN_LIST.Where(n => n.A_TRUE_NAME.Contains(searchText) || n.A_NAME.Contains(searchText)).ToList();
            }
            // 排除已经属于本角色的用户
            int rolesid = 0;
            if (Request.QueryString[requestStr].IsNum())
            {
                rolesid = Int32.Parse(Request.QueryString[requestStr]);

                T_ROLES T_ROLES = new T_ROLES();
                var queryrole = new DapperExQuery<T_ROLES>().AndWhere(n => n.ID, OperationMethod.Equal, rolesid);
                T_ROLES = T_ROLES_BLL.GetEntity(queryrole);
                List<T_ADMIN_ROLES> T_ADMIN_ROLES_LIST = new List<T_ADMIN_ROLES>();
                var query1 = new DapperExQuery<T_ADMIN_ROLES>().AndWhere(n => n.R_CODE, OperationMethod.Equal, T_ROLES.R_CODE);
                T_ADMIN_ROLES_LIST = T_ADMIN_ROLES_BLL.GetAllList(query1);
                for (var i = 0; i < T_ADMIN_ROLES_LIST.Count; i++)
                {
                    T_ADMIN_LIST = T_ADMIN_LIST.Where(n => n.A_CODE != T_ADMIN_ROLES_LIST[i].A_CODE).ToList();
                }
                // 在查询添加之后,获取总记录数
                Grid1.RecordCount = Int32.Parse(allcount.ToString());
                Grid1.DataSource = T_ADMIN_LIST;
                Grid1.DataBind();
            }
        }
        /// <summary>
        /// 根据用户角色code来获取权限列表
        /// 创建  毛枫  2015-4-21
        /// </summary>
        /// <param name="RoleId"></param>
        /// <returns></returns>
        public static List<T_POWERS> GetUserPower(string r_code)
        {
            List<T_POWERS> T_POWERS_LIST = new List<T_POWERS>();
            List<T_ROLES_POWERS> T_ROLES_POWER_LIST = new List<Mammothcode.Model.T_ROLES_POWERS>();
            var query = new DapperExQuery<T_ROLES_POWERS>().AndWhere(n => n.R_CODE, OperationMethod.Equal, r_code);
            //获取权限列表
            T_ROLES_POWER_LIST = T_ROLES_POWERS_BLL.GetAllList(query);
            if (T_ROLES_POWER_LIST != null)
            {
                foreach (T_ROLES_POWERS q in T_ROLES_POWER_LIST)
                {
                    string powerCode = q.P_CODE;
                    var querypower = new DapperExQuery<T_POWERS>().AndWhere(n => n.P_CODE, OperationMethod.Equal, powerCode);
                    T_POWERS T_POWERS = new T_POWERS();
                    //获取权限model
                    T_POWERS = T_POWERS_BLL.GetEntity(querypower);
                    T_POWERS_LIST.Add(T_POWERS);
                }

            }
            else
            {
                T_POWERS_LIST = null;
            }
            return T_POWERS_LIST;
        }
 /// <summary>
 /// 私有方法:从数据库中判断用户是否登录
 /// 创建  毛枫  2015-4-21
 /// </summary>
 /// <param name="username"></param>
 /// <param name="password"></param>
 /// <returns></returns>
 private static T_ADMIN IsLoginFromSql(string username, string password)
 {
     T_ADMIN_BLL T_ADMIN_BLL = new T_ADMIN_BLL();
     var query = new DapperExQuery<T_ADMIN>().AndWhere(n => n.A_NAME, OperationMethod.Equal, username)
         .AndWhere(n => n.PASSWORD, OperationMethod.Equal, EncryptUtil.Md5Encode(password.Trim(), 16));
     var admin = T_ADMIN_BLL.GetEntity(query);
     return admin;
 }
 /// <summary>
 /// 更新实体
 /// 创建人:林以恒
 /// 2015年7月6日21:30:29
 /// </summary>
 /// <returns></returns>
 private T_POWERS Save(T_POWERS powers)
 {
     powers.P_NAME = tbxP_Name.Text.Trim();
     powers.P_CHINESE_NAME = tbxP_CHINESE_NAME.Text.Trim();
     if (powers.ID == 0)
     {
         //获取随机码
         powers.P_CODE = StringRandomUtil.GuidTo16String();
         powers.CREATE_TIME = DateTime.Now;
         var creatAdminUser = AdminwebUserManager.GetCurrentAdminUser();
         if (creatAdminUser != null)
         {
             powers.CREATE_USER = creatAdminUser.A_NAME;
             powers.CREATE_USER_NAME = creatAdminUser.A_CHINESE_NAME;
         }
     }
     //组别
     T_POWERS entity = new T_POWERS();
     var F_CODE = Request.QueryString["fathercode"];
     if (F_CODE != null)
     {
         if (F_CODE != "0")
         {
             var fatherquery = new DapperExQuery<T_POWERS>().AndWhere(n => n.P_CODE, OperationMethod.Equal,
                 F_CODE);
             entity = _powersBll.GetEntity(fatherquery);
             powers.GROUP_NAME = entity.P_CHINESE_NAME;
         }
         else
         {
             powers.GROUP_NAME = powers.P_CHINESE_NAME;
         }
     }
     return powers;
 }
 /// <summary>
 /// 编辑角色对应的权限 (待优化)
 /// 修改人:金协民 2015年7月29日
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 protected void btnGroupUpdate_Click(object sender, EventArgs e)
 {
     var currentUser = AdminwebUserManager.GetCurrentAdminUser();
     var roleId = GetSelectedDataKeyID(Grid1);
     if (string.IsNullOrEmpty(roleId))
     {
         return;
     }
     // 当前角色新的权限列表
     List<string> newPowerIDs = new List<string>();
     for (int i = 0; i < Grid2.Rows.Count; i++)
     {
         AspNet.CheckBoxList ddlPowers = (AspNet.CheckBoxList)Grid2.Rows[i].FindControl("ddlPowers");
         foreach (AspNet.ListItem item in ddlPowers.Items)
         {
             if (item.Selected)
             {
                 newPowerIDs.Add((item.Value));
             }
         }
     }
     //删除原有权限
     var query = new DapperExQuery<T_ROLES_POWERS>().AndWhere(n => n.R_CODE, OperationMethod.Equal, roleId);
     if (T_ROLES_POWERS_BLL.GetEntity(query) != null)
     {
         T_ROLES_POWERS_BLL.Delete(query);
     }
     int newPowerLen = newPowerIDs.Count;
     //新增权限
     for (var i = 0; i < newPowerLen; i++)
     {
         T_ROLES_POWERS T_ROLES_POWERS = new T_ROLES_POWERS
         {
             P_CODE = newPowerIDs[i],
             R_CODE = roleId,
             CREATE_TIME = DateTime.Now,
             CREATE_USER = currentUser.A_NAME,
             CREATE_USER_NAME = currentUser.A_CHINESE_NAME
         };
         T_ROLES_POWERS_BLL.Add(T_ROLES_POWERS);
     }
     //Alert.Show(str);
 }
        //============操作方法===========
        #region 数据保存

        /// <summary>
        /// 数据保存按钮事件
        /// 创建 林以恒 
        /// 2015年4月14日
        /// </summary>
        protected void btnSaveClose_Click(object sender, EventArgs e)
        {
            ////设置页面权限
            //Power.SetViewPower("mod_menu");
            ////验证权限
            //if (Power.VerifyPower() == false)
            //{
            //    return;
            //}
            string str;
            if (Request.QueryString["id"].IsNum())
            {
                string id = Request.QueryString["id"].ToString();
                //修改
                T_ADMIN_MENUS T_ADMIN_MENUS = new T_ADMIN_MENUS();
                var q = new DapperExQuery<T_ADMIN_MENUS>().AndWhere(n => n.ID, OperationMethod.Equal, id);
                T_ADMIN_MENUS = _adminMenusBll.GetEntity(q);
                T_ADMIN_MENUS = GetnewModel(T_ADMIN_MENUS);
                str = _adminMenusBll.Update(T_ADMIN_MENUS) ? "修改成功!" : "修改失败!";
            }
            else
            {
                //添加
                T_ADMIN_MENUS adminMenus = new T_ADMIN_MENUS();
                adminMenus = GetnewModel(adminMenus);
                adminMenus.PARENT_ID = Int32.Parse(Request.QueryString["fatherId"].ToString());
                str = _adminMenusBll.Add(adminMenus) ? "添加成功!" : "添加失败!";
            }
            // 2. 关闭本窗体,然后刷新父窗体
            PageContext.RegisterStartupScript(ActiveWindow.GetHideRefreshReference());
            Alert.ShowInTop(str);
        }
 /// <summary>
 /// 分组绑定右侧权限
 /// 修改人:金协民 2015年7月29日
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 protected void Grid2_RowDataBound(object sender, GridRowEventArgs e)
 {
     AspNet.CheckBoxList ddlPowers = (AspNet.CheckBoxList)Grid2.Rows[e.RowIndex].FindControl("ddlPowers");
     var GroupName = e.DataItem.GetType().GetProperty("GroupName").GetValue(e.DataItem, null);
     List<T_POWERS> T_POWERS_LIST = new List<T_POWERS>();
     var query = new DapperExQuery<T_POWERS>().AndWhere(n => n.GROUP_NAME, OperationMethod.Equal, GroupName);
     T_POWERS_LIST = T_POWERS_BLL.GetAllList(query);
     foreach (var po in T_POWERS_LIST)
     {
         AspNet.ListItem item = new AspNet.ListItem
         {
             Value = po.P_CODE.ToString(),
             Text = string.Format("{0}({1})", po.P_CHINESE_NAME, po.P_NAME)
         };
         item.Attributes["data-qtip"] = po.P_NAME;
         if (_currentRolePowers.ContainsKey(po.P_NAME))
         {
             item.Selected = true;
         }
         else
         {
             item.Selected = false;
         }
         ddlPowers.Items.Add(item);
     }
 }
 /// <summary>
 /// 更新实体
 /// 创建人:林以恒
 /// 2015年7月6日18:16:18
 /// </summary>
 /// <param name="adminMenus"></param>
 /// <returns></returns>
 private T_ADMIN_MENUS GetnewModel(T_ADMIN_MENUS adminMenus)
 {
     adminMenus.AM_NAME = tbxAM_NAME.Text.Trim();
     adminMenus.AM_NAVIGATE_URL = tbxAM_NAVIGATE_URL.Text.Trim();
     adminMenus.AM_REMARK = tbxAM_REMARK.Text.Trim();
     adminMenus.AM_SORTINDEX = int.Parse(tbxAM_SORTINDEX.Text.Trim());
     var queryPower = new DapperExQuery<T_POWERS>().AndWhere(n => n.P_NAME, OperationMethod.Equal, tbxVIEWPOWER_ID.Text.ToString());
     var powerid = _powersBll.GetEntity(queryPower);
     adminMenus.P_CODE= powerid != null ? powerid.P_CODE : "";
     adminMenus.AM_ISTREELEAF = tbxAM_NAVIGATE_URL.Text.Trim() == "" ? 0 : 1;
     if (adminMenus.ID == 0)
     {
         //获取登入用户信息
         var AdminUserModel = AdminwebUserManager.GetCurrentAdminUser();
         if (AdminUserModel != null)
         {
             adminMenus.CREATE_USER = AdminUserModel.A_NAME;
             adminMenus.CREATE_USER_NAME = AdminUserModel.A_CHINESE_NAME;
         }
         adminMenus.CREATE_TIME = DateTime.Now;
     }
     return adminMenus;
 }
        //============ GRID事件==========
        #region Grid事件

        /// <summary>
        /// 删除
        /// 创建 林以恒 
        /// 2015年4月14日
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Grid1_RowCommand(object sender, GridCommandEventArgs e)
        {
            object[] keys = Grid1.DataKeys[e.RowIndex];
            int id = int.Parse(keys[0].ToString());
            if (e.CommandName == "Delete")
            {
                var query = new DapperExQuery<T_ADMIN_MENUS>().AndWhere(n => n.ID, OperationMethod.Equal, id);
                Alert.ShowInTop(_adminMenusBll.Delete(query) ? "删除成功!" : "删除失败!");
                Replace();
            }
            else
            {
                Alert.ShowInTop("点击成功!");
            }
        }
        /// <summary>
        /// 删除选中的用户
        /// 创建  毛枫  2015-4-17
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnDeleteSelected_Click(object sender, EventArgs e)
        {
            //// 在操作之前进行权限检查
            //if (!CheckPower("CoreRoleUserDelete"))
            //{
            //    CheckPowerFailWithAlert();
            //    return;
            //}
            // 从每个选中的行中获取ID(在Grid1中定义的DataKeyNames)
            string R_CODE = FineUITable.GetSelectedDataKeyCode(Grid1);
            //T_ROLES T_ROLES = new Model.T_ROLES();
            //var queryrole = new DapperExQuery<T_ROLES>().AndWhere(n => n.ID, OperationMethod.Equal, roleID);
            //T_ROLES = T_ROLES_BLL.GetEntity(queryrole);
            //string r_code = T_ROLES.R_CODE;
           List<string> A_CODES = FineUITable.GetSelectedDataKeyCODES(Grid2);
            foreach (string  A_CODE in A_CODES)
            {
                //T_ADMIN T_ADMIN = new T_ADMIN();
                //var queryuser= new DapperExQuery<T_ADMIN>().AndWhere(n => n.ID, OperationMethod.Equal, userID);
                //T_ADMIN = T_ADMIN_BLL.GetEntity(queryuser);
                //string a_code = T_ROLES.R_CODE;
                
                var query = new DapperExQuery<T_ADMIN_ROLES>().AndWhere(n => n.R_CODE, OperationMethod.Equal, R_CODE)
              .AndWhere(n => n.A_CODE, OperationMethod.Equal,A_CODE);
                var user_role = T_ADMIN_ROLES_BLL.GetEntity(query);
                if (user_role != null)
                {
                    T_ADMIN_ROLES_BLL.Delete(query);
                }
            }

            //DB.SaveChanges();

            // 清空当前选中的项
            Grid2.SelectedRowIndexArray = null;

            // 重新绑定表格
            BindGrid2();
        }
        //============操作方法===========
        #region 数据保存按钮事件
        /// <summary>
        /// 保存
        /// 创建人:林以恒
        /// 2015年7月6日14:24:11
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnSaveClose_Click(object sender, EventArgs e)
        {
            //设置页面权限
            power.SetViewPower("mod_admin");
            //验证权限
            if (power.VerifyPower() == false)
            {
                return;
            }
            string str;
            if (Request.QueryString["id"].IsNum())
            {
                string id = Request.QueryString["id"];
                //修改
                var query = new DapperExQuery<T_ADMIN>().AndWhere(n => n.ID, OperationMethod.Equal, int.Parse(id));
                var adminUser = _adminUserBll.GetEntity(query);
                if (tbxPassword.Text != adminUser.PASSWORD && tbxPassword.Text == tbxCfm_Password.Text)
                {
                    adminUser.PASSWORD = EncryptUtil.Md5Encode(tbxPassword.Text.Trim(), 16);
                }
                else if (tbxPassword.Text != adminUser.PASSWORD && tbxPassword.Text != tbxCfm_Password.Text)
                {
                    Alert.Show("确认密码与填写密码不匹配");
                }
                adminUser = Save(adminUser);

                str = _adminUserBll.Update(adminUser) ? "修改成功!" : "修改失败!";
            }
            else
            {
                T_ADMIN adminUser = new T_ADMIN();
                //添加
                adminUser = Save(adminUser);
                if (tbxPassword.Text != tbxCfm_Password.Text)
                {
                    Alert.Show("确认密码与填写密码不匹配");
                }
                else
                {
                    adminUser.PASSWORD = EncryptUtil.Md5Encode(tbxPassword.Text.Trim(), 16);
                }
                str = _adminUserBll.Add(adminUser) ? "添加成功!" : "添加失败!";
            }
            // 2. 关闭本窗体,然后刷新父窗体
            PageContext.RegisterStartupScript(ActiveWindow.GetHideRefreshReference());
            Alert.ShowInTop(str);
        }
 /// <summary>
 /// 单行删除 
 /// 创建  毛枫  2015-4-17
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 protected void Grid2_RowCommand(object sender, GridCommandEventArgs e)
 {
     object[] values = Grid2.DataKeys[e.RowIndex];
     string  A_CODE =values[1].ToString();
     //T_ADMIN T_ADMIN = new T_ADMIN();
     //var queryuser = new DapperExQuery<T_ADMIN>().AndWhere(n => n.ID, OperationMethod.Equal, userID);
     //T_ADMIN = T_ADMIN_BLL.GetEntity(queryuser);
     //string a_code = T_ADMIN.A_CODE;
     //判断点击的是删除
     if (e.CommandName == "Delete")
     {
         //// 在操作之前进行权限检查
         //if (!CheckPower("CoreRoleUserDelete"))
         //{
         //    CheckPowerFailWithAlert();
         //    return;
         //}
         string R_CODE = FineUITable.GetSelectedDataKeyCode(Grid1);
         var query = new DapperExQuery<T_ADMIN_ROLES>().AndWhere(n => n.R_CODE, OperationMethod.Equal, R_CODE)
          .AndWhere(n => n.A_CODE, OperationMethod.Equal, A_CODE);
         var user_role = T_ADMIN_ROLES_BLL.GetEntity(query);
         if (user_role != null)
         {
             T_ADMIN_ROLES_BLL.Delete(query);
         }
         //绑定刷新
         BindGrid2();
     }
 }
 //============ GRID事件==========
 #region 删除
 /// <summary>
 /// 列表数据绑定
 /// 创建 林以恒   2015-4-13  
 /// 修改:林以恒  2015-4-18
 /// </summary>
 protected void Grid1_RowCommand(object sender, GridCommandEventArgs e)
 {
     object[] keys = Grid1.DataKeys[e.RowIndex];
     int id = Int32.Parse(keys[0].ToString());
     if (e.CommandName != "Delete") return;
     var query = new DapperExQuery<T_POWERS>().AndWhere(n => n.ID, OperationMethod.Equal, id);
     Alert.ShowInTop(_powersbll.Delete(query) ? "删除成功!" : "删除失败!");
     BindGrid();
 }
        /// <summary>
        /// 保存修改
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnSave_OnClick(object sender, EventArgs e)
        {
            string message = "";
            T_ADMIN_BLL T_ADMIN_BLL = new T_ADMIN_BLL();
            try
            {
                //①获取当前登录用户
                AdminUserModel adminInfo = AdminwebUserManager.GetCurrentAdminUser();
                //②判断当前登录用户原密码
                var query = new DapperExQuery<T_ADMIN>().AndWhere(n => n.A_CODE, OperationMethod.Equal, adminInfo.A_CODE)
                    .AndWhere(n => n.PASSWORD, OperationMethod.Equal, EncryptUtil.Md5Encode(tbxOriPassword.Text.Trim(), 16));
                var entity = T_ADMIN_BLL.GetEntity(query);
                if (entity != null)
                {
                    //③判断确认密码是否等于密码
                    if (tbxPassword.Text == tbxCfm_Password.Text)
                    {
                        //④保存新密码
                        entity.PASSWORD = EncryptUtil.Md5Encode(tbxPassword.Text.Trim(), 16);

                        if (new T_ADMIN_BLL().Update(entity))
                        {
                            message = "修改成功";
                            updateWindow.Hidden = true;
                        }
                        else
                        {
                            message = "修改失败";
                        }
                    }
                    else
                    {
                        message = "确认密码错误";
                    }
                }
                else
                {
                    message = "用户密码错误,请输入原密码";
                }
            }
            catch (Exception ex)
            {
                message = ex.ToString();
            }
            Alert.Show(message);
        }
        //============操作方法===========
        #region 数据保存
        /// <summary>
        /// 数据保存按钮事件
        /// 创建人:林以恒
        /// 2015年7月6日21:28:17
        /// </summary>
        protected void btnSaveClose_Click(object sender, EventArgs e)
        {
            ////设置页面权限
            //Power.SetViewPower("mod_power");
            ////验证权限
            //if (Power.VerifyPower() == false)
            //{
            //    return;
            //}
            string str;
            if (Request.QueryString["id"].IsNum())
            {
                T_POWERS powers = null;
                string id = Request.QueryString["id"];
                //修改
                var query = new DapperExQuery<T_POWERS>().AndWhere(n => n.ID, OperationMethod.Equal, int.Parse(id));
                powers = _powersBll.GetEntity(query);
                powers = Save(powers);
                str = _powersBll.Update(powers) ? "修改成功!" : "修改失败!";
            }
            else
            {
                T_POWERS powers = new T_POWERS();
                //添加
                powers = Save(powers);

                powers.FATHER_CODE = Request.QueryString["fathercode"].ToString();
                str = _powersBll.Add(powers) ? "添加成功!" : "添加失败!";
            }
            // 2. 关闭本窗体,然后刷新父窗体
            PageContext.RegisterStartupScript(ActiveWindow.GetHideRefreshReference());
            Alert.ShowInTop(str);
        }
        /// <summary>
        ///  根据用户权限,获取菜单列表 
        /// </summary>
        /// <returns></returns>
        public List<T_ADMIN_MENUS> Get_PowerMenu()
        {
            List<T_ADMIN_MENUS> T_ADMIN_MENUS_LIST = new List<T_ADMIN_MENUS>();
            List<T_POWERS> T_POWERS_LIST = new List<T_POWERS>();
            T_POWERS_LIST = T_POWERS_BLL.GetAllList();
            int count = T_POWERS_LIST.Count;
            int j = 0;
            for (int i = 0; i < count; i++)
            {
                if (AdminwebUserManager.CompareRole(T_POWERS_LIST[i].P_NAME))
                {
                    string p_code = T_POWERS_LIST[i].P_CODE;
                    var query = new DapperExQuery<T_ADMIN_MENUS>().AndWhere(n => n.P_CODE, OperationMethod.Equal, p_code);
                    T_ADMIN_MENUS T_ADMIN_MENUS = new T_ADMIN_MENUS();
                    T_ADMIN_MENUS = T_ADMIN_MENUS_BLL.GetEntity(query);
                    if (T_ADMIN_MENUS != null)
                    {
                        T_ADMIN_MENUS_LIST.Add(T_ADMIN_MENUS);
                    }
                }
            }
            //排序
            T_ADMIN_MENUS q = new T_ADMIN_MENUS();
            for (int i = 0; i < T_ADMIN_MENUS_LIST.Count - 1; i++)
            {

                for (j = 0; j < T_ADMIN_MENUS_LIST.Count - 1 - i; j++)
                {
                    if (T_ADMIN_MENUS_LIST[j].AM_SORTINDEX > T_ADMIN_MENUS_LIST[j + 1].AM_SORTINDEX)
                    {
                        q = T_ADMIN_MENUS_LIST[j];
                        T_ADMIN_MENUS_LIST[j] = T_ADMIN_MENUS_LIST[j + 1];
                        T_ADMIN_MENUS_LIST[j + 1] = q;
                    }
                }
            }
            //T_ADMIN_MENUS_LIST = T_ADMIN_MENUS_LIST.OrderBy(n => n.AM_SORTINDEX) as List<T_ADMIN_MENUS>;
            return T_ADMIN_MENUS_LIST;
        }