Ejemplo n.º 1
0
 public virtual void InsertUserPermission(UserPermission userPermission)
 {
     InsertObject(userPermission);
 }
Ejemplo n.º 2
0
        private void BtnSaveClick(object sender, EventArgs e)
        {
            try
            {
                if ((cmbGender.SelectedIndex == -1) || (cmbMaritalStatus.SelectedIndex == -1)
                    || (cmbPosition.SelectedIndex == -1) || (cmbContractType.SelectedIndex == -1)
                    || (String.IsNullOrEmpty(txtUserName.Text)) || (String.IsNullOrEmpty(txtLogInName.Text))
                    || (String.IsNullOrEmpty(txtPassword.Text)))
                {
                    const string briefMsg = "អំពីពត៌មាន";
                    var detailMsg = Resources.MsgInvalidData;
                    using (var frmMessageBox = new FrmExtendedMessageBox())
                    {
                        frmMessageBox.BriefMsgStr = briefMsg;
                        frmMessageBox.DetailMsgStr = detailMsg;
                        frmMessageBox.IsCanceledOnly = true;
                        frmMessageBox.ShowDialog(this);
                        return;
                    }
                }

                var permissionList = new List<UserPermission>();
                var permissionNum = ((IList) clbPermission.DataSource).Count;
                for (var counter = 0; counter < permissionNum; counter++)
                {
                    if (!clbPermission.GetItemChecked(counter))
                        continue;

                    var userPermission = new UserPermission
                                             {
                                                 PermissionId =
                                                     ((Permission) clbPermission.Items[counter]).PermissionId
                                             };
                    permissionList.Add(userPermission);
                }

                if (permissionList.Count == 0)
                {
                    const string briefMsg = "អំពីពត៌មាន";
                    var detailMsg = Resources.MsgInvalidData;
                    using (var frmMessageBox = new FrmExtendedMessageBox())
                    {
                        frmMessageBox.BriefMsgStr = briefMsg;
                        frmMessageBox.DetailMsgStr = detailMsg;
                        frmMessageBox.IsCanceledOnly = true;
                        frmMessageBox.ShowDialog(this);
                        return;
                    }
                }

                if (_user == null)
                    _user = new User();
                _user.UserName = txtUserName.Text;
                _user.GenderId = int.Parse(cmbGender.SelectedValue.ToString());
                _user.GenderStr = cmbGender.Text;
                _user.MaritalStatusId = int.Parse(cmbMaritalStatus.SelectedValue.ToString());
                _user.MaritalStatusStr = cmbMaritalStatus.Text;
                _user.BirthDate = dtpBirthDate.Value;
                _user.PhoneNumber = txtPhoneNumber.Text;
                _user.Address = txtAddress.Text;
                _user.PositionId = int.Parse(cmbPosition.SelectedValue.ToString());
                _user.PositionStr = cmbPosition.Text;
                _user.ContractId = int.Parse(cmbContractType.SelectedValue.ToString());
                _user.ContractStr = cmbContractType.Text;
                _user.StartingDate = dtpStartingDate.Value;
                _user.Salary = float.Parse(txtSalary.Text);
                _user.LogInName = txtLogInName.Text;
                _user.Password = txtPassword.Text;
                _user.PhotoPath = txtPhotoPath.Text.Length == 0 ? _user.PhotoPath : txtPhotoPath.Text;

                if (_userService == null)
                    _userService = ServiceFactory.GenerateServiceInstance().GenerateUserService();

                _userService.UserManagement(_user, permissionList,
                                            _user.UserId != 0
                                                ? Resources.OperationRequestUpdate
                                                : Resources.OperationRequestInsert);

                if (AppContext.User == null)
                    return;

                if (_user.UserId == AppContext.User.UserId)
                    AppContext.UserPermissionList = permissionList;

                DialogResult = DialogResult.OK;
            }
            catch (Exception exception)
            {
                FrmExtendedMessageBox.UnknownErrorMessage(
                    Resources.MsgCaptionUnknownError,
                    exception.Message);
            }
        }