Пример #1
0
        public int AddNewCustomPermission(TBL_User_CustomPermissions permission)
        {
            int newID = 0;

            try
            {
                TBL_User_CustomPermissions newPermission = new TBL_User_CustomPermissions()
                {
                    CanAddNew     = permission.CanAddNew,
                    CanApprove    = permission.CanApprove,
                    CanAuthorize  = permission.CanAuthorize,
                    CanCheck      = permission.CanCheck,
                    CanDelete     = permission.CanDelete,
                    CanModify     = permission.CanModify,
                    CanPrint      = permission.CanPrint,
                    CanView       = permission.CanView,
                    fk_ModuleId   = permission.fk_ModuleId,
                    fk_FormId     = permission.fk_FormId,
                    fk_EmployeeId = permission.fk_EmployeeId
                };
                _dbContext.TBL_User_CustomPermissions.Add(newPermission);
                _dbContext.SaveChanges();
                newID = newPermission.pk_CustomPermissionID;
            }
            catch (Exception ex)
            {
                string errMessage = ex.Message;
                if (ex.InnerException != null)
                {
                    errMessage += string.Format("\n{0}", ex.InnerException.Message);
                }
                MessageBox.Show(errMessage, "ServiceUsers::AddNewCustomPermission", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            return(newID);
        }
Пример #2
0
        public bool RemoveCustomPermission(int permissionID)
        {
            bool result = false;

            try
            {
                TBL_User_CustomPermissions model = _dbContext.TBL_User_CustomPermissions.Where(x => x.pk_CustomPermissionID == permissionID).FirstOrDefault();
                if (model != null)
                {
                    _dbContext.TBL_User_CustomPermissions.Remove(model);
                    _dbContext.SaveChanges();
                    result = true;
                }
            }
            catch (Exception ex)
            {
                string errMessage = ex.Message;
                if (ex.InnerException != null)
                {
                    errMessage += string.Format("\n{0}", ex.InnerException.Message);
                }
                MessageBox.Show(errMessage, "ServiceUsers::RemoveCustomPermission", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            return(result);
        }
Пример #3
0
        public void UpdateControlAccessListForRole(int roleID, int employeeID)
        {
            try
            {
                foreach (WhosWhoModel model in this.ListControlAccess)
                {
                    TBL_MP_Master_RoleForm roleForm = (new ServiceRoles()).GetRoleFormDBRecordByRoleIDnFormID(roleID, (int)model.FormID);
                    if (roleForm != null)
                    {
                        model.CanAddNew    = roleForm.CanAddNew;
                        model.CanApprove   = roleForm.CanApprove;
                        model.CanAuthorize = roleForm.CanAuthorize;
                        model.CanCheck     = roleForm.CanCheck;
                        model.CanDelete    = roleForm.CanDelete;
                        model.CanModify    = roleForm.CanModify;
                        model.CanPrepare   = roleForm.CanPrepare;
                        model.CanPrint     = roleForm.CanPrint;
                        model.CanView      = roleForm.CanView;
                    }
                    else
                    {
                        model.CanAddNew = model.CanApprove = model.CanAuthorize = model.CanCheck = model.CanDelete = model.CanModify = model.CanPrepare = model.CanPrint = model.CanView = false;
                    }
                }

                //if custom privleges are set for particular employee
                foreach (WhosWhoModel model in this.ListControlAccess)
                {
                    TBL_User_CustomPermissions EmproleForm = (new ServiceRoles()).GetEmpRoleFormDBRecordByRoleIDnFormID(employeeID, (int)model.FormID);
                    if (EmproleForm != null)
                    {
                        model.CanAddNew    = EmproleForm.CanAddNew;
                        model.CanApprove   = EmproleForm.CanApprove;
                        model.CanAuthorize = EmproleForm.CanAuthorize;
                        model.CanCheck     = EmproleForm.CanCheck;
                        model.CanDelete    = EmproleForm.CanDelete;
                        model.CanModify    = EmproleForm.CanModify;
                        model.CanPrepare   = EmproleForm.CanPrepare;
                        model.CanPrint     = EmproleForm.CanPrint;
                        model.CanView      = EmproleForm.CanView;
                    }
                    //else
                    //    model.CanAddNew = model.CanApprove = model.CanAuthorize = model.CanCheck = model.CanDelete = model.CanModify = model.CanPrepare = model.CanPrint = model.CanView = false;
                }
            }
            catch (Exception ex)
            {
                string errMessage = ex.Message;
                if (ex.InnerException != null)
                {
                    errMessage += string.Format("\n{0}", ex.InnerException.Message);
                }
                MessageBox.Show(errMessage, "ServiceWhoseWho::UpdateControlAccessListForRole", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void frmAddEditCustomPermission_Load(object sender, EventArgs e)
        {
            this.Cursor = Cursors.WaitCursor;
            try
            {
                SetPermissionButtonsTag();
                PopulateModulesDropdown();
                PopulateModuleFormsDropdown();

                if (this.CustomPermissionID != 0)
                {
                    TBL_User_CustomPermissions model = (new ServiceUsers()).GetCustomPermissionByPermissionID(this.CustomPermissionID);
                    if (model != null)
                    {
                        this.SelectedModuleID   = (int)model.fk_ModuleId;
                        cboModules.SelectedItem = ((List <SelectListItem>)cboModules.DataSource).Where(x => x.ID == SelectedModuleID).FirstOrDefault();

                        this.SelectedFormID   = (int)model.fk_FormId;
                        cboForms.SelectedItem = ((List <SelectListItem>)cboForms.DataSource).Where(x => x.ID == SelectedFormID).FirstOrDefault();

                        btnCanAddNewRecord.Checked = model.CanAddNew;
                        PermissionsButton_Click(btnCanAddNewRecord, null);
                        btnCanApproveRecord.Checked = model.CanApprove;
                        PermissionsButton_Click(btnCanApproveRecord, null);
                        btnCanAuthorizeRecord.Checked = model.CanAuthorize;
                        PermissionsButton_Click(btnCanAuthorizeRecord, null);
                        btnCanCheckRecord.Checked = model.CanCheck;
                        PermissionsButton_Click(btnCanCheckRecord, null);
                        btnCanDeleteRecord.Checked = model.CanDelete;
                        PermissionsButton_Click(btnCanDeleteRecord, null);
                        btnCanModifyRecord.Checked = model.CanModify;
                        PermissionsButton_Click(btnCanModifyRecord, null);
                        btnCanPrintRecord.Checked = model.CanPrint;
                        PermissionsButton_Click(btnCanPrintRecord, null);
                        btnCanViewRecord.Checked = model.CanView;
                        PermissionsButton_Click(btnCanViewRecord, null);
                    }
                }
            }
            catch (Exception ex)
            {
                string errMessage = ex.Message;
                if (ex.InnerException != null)
                {
                    errMessage += string.Format("\n{0}", ex.InnerException.Message);
                }
                MessageBox.Show(errMessage, "frmAddEditCustomPermission::frmAddEditCustomPermission_Load", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            this.Cursor = Cursors.Default;
        }
Пример #5
0
        public TBL_User_CustomPermissions GetEmpRoleFormDBRecordByRoleIDnFormID(int EmpID, int formID)
        {
            TBL_User_CustomPermissions EmproleForm = null;

            try
            {
                EmproleForm = (from xx in _dbContext.TBL_User_CustomPermissions where xx.fk_EmployeeId == EmpID && xx.fk_FormId == formID select xx).FirstOrDefault();
            }
            catch (Exception ex)
            {
                string errMessage = string.Format("{0}\n{1}", ex.Message, ex.InnerException.Message);
                MessageBox.Show(errMessage, "ServiceRoles::GetRoleFormDBRecordByRoleIDnFormID", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            return(EmproleForm);
        }
Пример #6
0
        public TBL_User_CustomPermissions GetCustomPermissionByPermissionID(int permissionID)
        {
            TBL_User_CustomPermissions model = null;

            try
            {
                model = _dbContext.TBL_User_CustomPermissions.Where(x => x.pk_CustomPermissionID == permissionID).FirstOrDefault();
            }
            catch (Exception ex)
            {
                string errMessage = ex.Message;
                if (ex.InnerException != null)
                {
                    errMessage += string.Format("\n{0}", ex.InnerException.Message);
                }
                MessageBox.Show(errMessage, "ServiceUsers::GetCustomPermissionByPermissionID", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            return(model);
        }
Пример #7
0
        public bool UpdateCustomPermission(int permissionID, TBL_User_CustomPermissions updatePermission)
        {
            bool result = false;

            try
            {
                TBL_User_CustomPermissions model = _dbContext.TBL_User_CustomPermissions.Where(x => x.pk_CustomPermissionID == permissionID).FirstOrDefault();
                if (model != null)
                {
                    model.CanAddNew     = updatePermission.CanAddNew;
                    model.CanApprove    = updatePermission.CanApprove;
                    model.CanAuthorize  = updatePermission.CanAuthorize;
                    model.CanCheck      = updatePermission.CanCheck;
                    model.CanDelete     = updatePermission.CanDelete;
                    model.CanModify     = updatePermission.CanModify;
                    model.CanPrint      = updatePermission.CanPrint;
                    model.CanView       = updatePermission.CanView;
                    model.fk_ModuleId   = updatePermission.fk_ModuleId;
                    model.fk_FormId     = updatePermission.fk_FormId;
                    model.fk_EmployeeId = updatePermission.fk_EmployeeId;
                    _dbContext.SaveChanges();
                    result = true;
                }
                ;
            }
            catch (Exception ex)
            {
                string errMessage = ex.Message;
                if (ex.InnerException != null)
                {
                    errMessage += string.Format("\n{0}", ex.InnerException.Message);
                }
                MessageBox.Show(errMessage, "ServiceUsers::AddNewCustomPermission", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            return(result);
        }
        private void btnSave_Click(object sender, EventArgs e)
        {
            this.Cursor = Cursors.WaitCursor;
            try
            {
                TBL_User_CustomPermissions model = null;
                errorProvider1.Clear();
                if (this.ValidateChildren())
                {
                    if (this.CustomPermissionID != 0)
                    {
                        model              = (new ServiceUsers()).GetCustomPermissionByPermissionID(this.CustomPermissionID);
                        model.CanAddNew    = btnCanAddNewRecord.Checked;
                        model.CanApprove   = btnCanApproveRecord.Checked;
                        model.CanAuthorize = btnCanAuthorizeRecord.Checked;
                        model.CanCheck     = btnCanCheckRecord.Checked;
                        model.CanDelete    = btnCanDeleteRecord.Checked;
                        model.CanModify    = btnCanModifyRecord.Checked;
                        model.CanPrint     = btnCanPrintRecord.Checked;
                        model.CanView      = btnCanViewRecord.Checked;

                        model.fk_ModuleId   = this.SelectedModuleID;
                        model.fk_FormId     = this.SelectedFormID;
                        model.fk_EmployeeId = this.SelectedEmployeeID;
                        if ((new ServiceUsers()).UpdateCustomPermission(this.CustomPermissionID, model))
                        {
                            this.DialogResult = DialogResult.OK;
                        }
                    }
                    else
                    {
                        model = new TBL_User_CustomPermissions()
                        {
                            CanAddNew     = btnCanAddNewRecord.Checked,
                            CanApprove    = btnCanApproveRecord.Checked,
                            CanAuthorize  = btnCanAuthorizeRecord.Checked,
                            CanCheck      = btnCanCheckRecord.Checked,
                            CanDelete     = btnCanDeleteRecord.Checked,
                            CanModify     = btnCanModifyRecord.Checked,
                            CanPrint      = btnCanPrintRecord.Checked,
                            CanView       = btnCanViewRecord.Checked,
                            fk_ModuleId   = this.SelectedModuleID,
                            fk_FormId     = this.SelectedFormID,
                            fk_EmployeeId = this.SelectedEmployeeID
                        };
                        int newID = (new ServiceUsers()).AddNewCustomPermission(model);
                        if (newID > 0)
                        {
                            this.DialogResult = DialogResult.OK;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                string errMessage = ex.Message;
                if (ex.InnerException != null)
                {
                    errMessage += string.Format("\n{0}", ex.InnerException.Message);
                }
                MessageBox.Show(errMessage, "frmAddEditCustomPermission::btnSave_Click", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            this.Cursor = Cursors.Default;
        }