Exemplo n.º 1
0
        protected void Grid2_RowCommand(object sender, GridCommandEventArgs e)
        {
            object[] values = Grid2.DataKeys[e.RowIndex];
            int      userID = Convert.ToInt32(values[0]);

            if (e.CommandName == "Delete")
            {
                // 在操作之前进行权限检查
                if (!CheckPower("CoreRoleUserDelete"))
                {
                    CheckPowerFailWithAlert();
                    return;
                }

                int roleID = GetSelectedDataKeyID(Grid1);

                IList <ICriterion> qryList = new List <ICriterion>();
                qryList.Add(Expression.Eq("RoleID", roleID));
                qryList.Add(Expression.Eq("UserID", userID));
                roleusers entity = Core.Container.Instance.Resolve <IServiceRoleUsers>().GetEntityByFields(qryList);

                if (entity != null)
                {
                    Core.Container.Instance.Resolve <IServiceRoleUsers>().Delete(entity);
                }

                BindGrid2();
            }
        }
Exemplo n.º 2
0
        protected void btnDeleteSelected_Click(object sender, EventArgs e)
        {
            // 在操作之前进行权限检查
            if (!CheckPower("CoreRoleUserDelete"))
            {
                CheckPowerFailWithAlert();
                return;
            }

            // 从每个选中的行中获取ID(在Grid1中定义的DataKeyNames)
            int        roleID  = GetSelectedDataKeyID(Grid1);
            List <int> userIDs = GetSelectedDataKeyIDs(Grid2);

            //role.Users.Where(u => userIDs.Contains(u.ID)).ToList().ForEach(u => role.Users.Remove(u));
            foreach (int userID in userIDs)
            {
                IList <ICriterion> qryList = new List <ICriterion>();
                qryList.Add(Expression.Eq("RoleID", roleID));
                qryList.Add(Expression.Eq("UserID", userID));
                roleusers entity = Core.Container.Instance.Resolve <IServiceRoleUsers>().GetEntityByFields(qryList);

                if (entity != null)
                {
                    Core.Container.Instance.Resolve <IServiceRoleUsers>().Delete(entity);
                }
            }

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

            // 重新绑定表格
            BindGrid2();
        }
Exemplo n.º 3
0
        protected void btnSaveClose_Click(object sender, EventArgs e)
        {
            int   id   = GetQueryIntValue("id");
            users item = Core.Container.Instance.Resolve <IServiceUsers>().GetEntity(id);

            //User item = DB.Users
            //    .Include(u => u.Dept)
            //    .Include(u => u.Roles)
            //    .Include(u => u.Titles)
            //    .Where(u => u.ID == id).FirstOrDefault();
            //item.Name = tbxName.Text.Trim();
            item.ChineseName    = tbxRealName.Text.Trim();
            item.Gender         = ddlGender.SelectedValue;
            item.CompanyEmail   = tbxCompanyEmail.Text.Trim();
            item.Email          = tbxEmail.Text.Trim();
            item.CellPhone      = tbxCellPhone.Text.Trim();
            item.OfficePhone    = tbxOfficePhone.Text.Trim();
            item.OfficePhoneExt = tbxOfficePhoneExt.Text.Trim();
            item.HomePhone      = tbxHomePhone.Text.Trim();
            item.Remark         = tbxRemark.Text.Trim();
            item.Enabled        = cbxEnabled.Checked;

            if (String.IsNullOrEmpty(hfSelectedDept.Text))
            {
                item.DeptID = 0;
            }
            else
            {
                item.DeptID = Convert.ToInt32(hfSelectedDept.Text);
            }

            // 添加所有角色
            if (!String.IsNullOrEmpty(hfSelectedRole.Text))
            {
                //删除原来的用户角色关系
                IList <ICriterion> qryList = new List <ICriterion>();
                qryList.Add(Expression.Eq("UserID", item.ID));
                IList <roleusers> entityList = Core.Container.Instance.Resolve <IServiceRoleUsers>().GetAllByKeys(qryList);
                foreach (roleusers obj in entityList)
                {
                    Core.Container.Instance.Resolve <IServiceRoleUsers>().Delete(obj);
                }
                //创建用户角色关系
                int[] roleIDs = StringUtil.GetIntArrayFromString(hfSelectedRole.Text);
                foreach (int rolsid in roleIDs)
                {
                    roleusers obj = new roleusers {
                        RoleID = rolsid, UserID = item.ID
                    };
                    Core.Container.Instance.Resolve <IServiceRoleUsers>().Create(obj);
                }
            }

            Core.Container.Instance.Resolve <IServiceUsers>().Update(item);


            PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference());
        }
Exemplo n.º 4
0
        protected void btnSaveClose_Click(object sender, EventArgs e)
        {
            int roleID = GetQueryIntValue("id");

            // 从每个选中的行中获取ID(在Grid1中定义的DataKeyNames)
            List <int> ids = GetSelectedIDsFromHiddenField(hfSelectedIDS);

            foreach (int userID in ids)
            {
                roleusers user = new roleusers {
                    UserID = userID, RoleID = roleID
                };
                Core.Container.Instance.Resolve <IServiceRoleUsers>().Create(user);
            }
            PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference());
        }
Exemplo n.º 5
0
        private void SaveItem()
        {
            users item = new users();

            item.Name           = tbxName.Text.Trim();
            item.Password       = PasswordUtil.CreateDbPassword(tbxPassword.Text.Trim());
            item.ChineseName    = tbxRealName.Text.Trim();
            item.Gender         = ddlGender.SelectedValue;
            item.CompanyEmail   = tbxCompanyEmail.Text.Trim();
            item.Email          = tbxEmail.Text.Trim();
            item.OfficePhone    = tbxOfficePhone.Text.Trim();
            item.OfficePhoneExt = tbxOfficePhoneExt.Text.Trim();
            item.HomePhone      = tbxHomePhone.Text.Trim();
            item.CellPhone      = tbxCellPhone.Text.Trim();
            item.Remark         = tbxRemark.Text.Trim();
            item.Enabled        = cbxEnabled.Checked;
            item.CreateTime     = DateTime.Now;

            // 添加所有部门
            if (!String.IsNullOrEmpty(hfSelectedDept.Text))
            {
                item.DeptID = Convert.ToInt32(hfSelectedDept.Text);
            }

            Core.Container.Instance.Resolve <IServiceUsers>().Create(item);

            item = new users();
            IList <ICriterion> qryList = new List <ICriterion>();

            qryList.Add(Expression.Eq("Name", tbxName.Text.Trim()));
            item = Core.Container.Instance.Resolve <IServiceUsers>().GetEntityByFields(qryList);


            // 添加所有角色
            if (!String.IsNullOrEmpty(hfSelectedRole.Text))
            {
                int[] roleIDs = StringUtil.GetIntArrayFromString(hfSelectedRole.Text);
                foreach (int rolsid in roleIDs)
                {
                    roleusers obj = new roleusers {
                        RoleID = rolsid, UserID = item.ID
                    };
                    Core.Container.Instance.Resolve <IServiceRoleUsers>().Create(obj);
                }
            }
        }