예제 #1
0
        private void btnSure_Click(object sender, EventArgs e)
        {
            string paramRoleName = this.txtRoleName.Text.Trim();
            string paramRemark   = this.txtRemark.Text.Trim();

            if (paramRoleName.Length == 0)
            {
                MessageBox.Show("权限名称不能为空!");
                return;
            }
            BLIRoleInfo myBLIRoleInfo = new BLIRoleInfo();
            MoIRoleInfo myMoIRoleInfo = new MoIRoleInfo();

            //添加操作
            if (paramRoleID.Length == 0)
            {
                myMoIRoleInfo = GetModelData();
                myBLIRoleInfo.Add(myMoIRoleInfo);
                this.DialogResult = DialogResult.Yes;
            }
            else
            {
                myMoIRoleInfo = GetModelData();
                myBLIRoleInfo.Update(myMoIRoleInfo);
                this.DialogResult = DialogResult.Yes;
            }
        }
        private void btnSetRole_Click(object sender, EventArgs e)
        {
            try
            {
                DataTable    MyModelInfo = new DataTable();
                BLLModelInfo myBLModule  = new BLLModelInfo();
                MoRole       MoIRole     = new MoRole();
                BLIRoleInfo  myBLIRole   = new BLIRoleInfo();
                int          paramUpdate = 0;//记录加载次数

                MyModelInfo = myBLModule.GetModuleIDList().Tables[0];
                //开始循环现有的权限值(即共计多少个角色)
                for (int i = 0; i < myDtN.Rows.Count; i++)
                {
                    //循环计算是否有该角色的数据

                    for (int j = 0; j < MyModelInfo.Rows.Count; j++)
                    {
                        //第一步:去查找该角色是否有该模块权限,有则PSS,无则Update
                        if (!myBLModule.Exists(myDtN.Rows[i]["RoleID"].ToString(), MyModelInfo.Rows[j]["ID"].ToString()))
                        {
                            MoIRole.RoleID   = myDtN.Rows[i]["RoleID"].ToString();
                            MoIRole.ModuleID = MyModelInfo.Rows[j]["ID"].ToString();
                            MoIRole.Enable   = 0;
                            myBLIRole.Add(MoIRole);
                        }
                    }
                }
                if (paramUpdate == 0)
                {
                    this.Cursor = Cursors.Default;
                    MessageBox.Show("权限已是最新,不需要加载", "温馨提示!");
                }
                if (paramUpdate > 0)
                {
                    this.Cursor = Cursors.Default;
                    MessageBox.Show("已成功加载['" + paramUpdate + "']项权限值", "温馨提示!");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }