Esempio n. 1
0
 public static int InsertRole(Role newRole)
 {
     String sqlInsert = @"INSERT INTO Role (RoleNAME)
                         VALUES        (@RoleNAME)";
     SqlParameter[] sqlParameters = { new SqlParameter("@RoleNAME", newRole.RoleName) };
     return SqlResult.ExecuteNonQuery(sqlInsert, sqlParameters);
 }
Esempio n. 2
0
        public void SetRoleDetail(Role roledetail)
        {
            this.roleDetail = roledetail;

            textBoxRoleID.Text = roleDetail.RoleID.ToString();
            textBoxRoleName.Text = roleDetail.RoleName;

            DataTable dtCurrentFunction = RoleDetail.GetListStaffFunction(roledetail.RoleID);
            for (int i = 0; i < dtCurrentFunction.Rows.Count; i++)
            { 
                RoleFunction tempRF=new RoleFunction(int.Parse(dtCurrentFunction.Rows[i][0].ToString()),dtCurrentFunction.Rows[i][1].ToString(),"");
                listBoxCurrentFunction.Items.Add(tempRF.FucntionName);
                listBoxCurrentFunctionID.Items.Add(tempRF.FunctionID);
            }
            DataTable dtSystemFunction = RoleFunction.GetListFunction();
            for (int i = 0; i < dtSystemFunction.Rows.Count; i++)
            {
                RoleFunction tempRF = new RoleFunction(int.Parse(dtSystemFunction.Rows[i][0].ToString()), dtSystemFunction.Rows[i][1].ToString(), dtSystemFunction.Rows[i][2].ToString());
                listBoxSystemFunction.Items.Add(tempRF.FucntionName);
                listBoxSystemFunctionID.Items.Add(tempRF.FunctionID);
            }
            ListBox lstTemp = new ListBox();
            for (int i = 0; i < listBoxCurrentFunctionID.Items.Count; i++)
            {
                for (int j = 0; j < listBoxSystemFunctionID.Items.Count; j++)
                {
                    if (listBoxCurrentFunctionID.Items[i].ToString() == listBoxSystemFunctionID.Items[j].ToString())
                    {
                        listBoxSystemFunctionID.Items.RemoveAt(j);
                        listBoxSystemFunction.Items.RemoveAt(j);
                        break;
                    }
                }
            }
        }
Esempio n. 3
0
 public FormRoleDetail(Role roledetail, String usertAction)
 {
     InitializeComponent();
     this.roleDetail = roledetail;
     this.UserAction = usertAction;
     if (usertAction.Equals("edit"))
         SetRoleDetail(roleDetail);
 }
Esempio n. 4
0
 public static int UpdateRole(Role updateRole)
 {
     string sqlUpdate = @"UPDATE       Role
                         SET                RoleNAME =@RoleNAME
                         WHERE          (RoleID=@RoleID)";
     SqlParameter[] sqlParameters = { new SqlParameter("@RoleNAME", updateRole.RoleName),
                                    new SqlParameter("@RoleID", updateRole.RoleID)};
     return SqlResult.ExecuteNonQuery(sqlUpdate, sqlParameters);
 }
Esempio n. 5
0
 public static Role GetRole(int roleID)
 {
     int tempInterger;
     Role newRole =new Role();
     string sqlSelect = @"SELECT        ROLEID, ROLENAME
                         FROM            ROLE
                         WHERE (ROLEID = @ROLEID)";
     SqlParameter[] sqlParameters = { new SqlParameter("@ROLEID", roleID) };
     DataTable dataTable = SqlResult.ExecuteQuery(sqlSelect,sqlParameters);
     if (dataTable.Rows.Count > 0)
     {
         int.TryParse(dataTable.Rows[0][0].ToString(), out tempInterger);
         newRole.RoleID = tempInterger;
         newRole.RoleName = dataTable.Rows[0][1].ToString();
     }
     return newRole;
 }
Esempio n. 6
0
        private void buttonOk_Click(object sender, EventArgs e)
        {
            if (!superValidator1.Validate())
                return;
            try
            {
                if ("edit".Equals(this.UserAction))
                {
                    DialogResult dialogResult = MessageBox.Show("Xác nhận cập nhập thông tin phân quyền", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                    if (dialogResult == DialogResult.Yes)
                    {
                        Role editRole = new Role(int.Parse(textBoxRoleID.Text), textBoxRoleName.Text);

                        if (Role.UpdateRole(editRole) > 0)
                        {
                            RoleDetail.DeleteRoleDetail(roleDetail.RoleID);
                            for (int i = 0; i < listBoxCurrentFunctionID.Items.Count; i++)
                            {
                                RoleDetail newRD = new RoleDetail(roleDetail.RoleID, int.Parse(listBoxCurrentFunctionID.Items[i].ToString()));
                                RoleDetail.InsertRoleDetail(newRD);
                            }
                            MessageBox.Show("Cập nhập cập nhập thông tin phân quyền thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                    }
                }
                else
                {
                    Role newRole = new Role(0, textBoxRoleName.Text);
                    if (Role.InsertRole(newRole) > 0)
                    {
                        int currentIdent = Role.GetCurrentIdentity();
                        for (int i = 0; i < listBoxCurrentFunctionID.Items.Count; i++)
                        {
                            RoleDetail newRD = new RoleDetail(currentIdent, int.Parse(listBoxCurrentFunctionID.Items[i].ToString()));
                            RoleDetail.InsertRoleDetail(newRD);
                        }
                        MessageBox.Show("Thêm phân quyền thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
            }
            catch
            {
                MessageBox.Show("Lỗi dữ liệu", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
                       
            this.Close();
        }