Exemplo n.º 1
0
        private void ResetForm(bool IsNew, bool lstEnabled, bool txtClear, bool btnNewUserEnabled, bool btnDeleteEnabled, bool focusList)
        {
            lst_users.Enabled = lstEnabled;
            if (txtClear)
            {
                txt_name.ClearAndFocus();
                txt_login_name.Clear();
                txt_name.Clear();
                txt_nic.Clear();
                txt_password.Clear();
                txt_retype_pwd.Clear();
            }
            SelectedID         = 0;
            btn_create.Enabled = btnNewUserEnabled;
            btn_delete.Enabled = btnDeleteEnabled;
            IsNewRecord        = IsNew;
            if (focusList)
            {
                lst_users_SelectedIndexChanged(this, new EventArgs());
            }

            UserWithPasswordValidation.Reset(this);
            UserValidation.Reset(this);
        }
Exemplo n.º 2
0
        private void btn_save_Click(object sender, EventArgs e)
        {
            try
            {
                if (!IsNewRecord && !hasAccessUpdate)
                {
                    ApplicationUtilities.ShowMessage(UniversalEnum.MessageTypes.Error, "You have no save rights.", "Access Denied");
                    return;
                }
                using (DataTable Table = new BL_User().selectUsage(new ML_User {
                    Key = (SelectedID == 0 ? null : (int?)SelectedID), LoginId = txt_login_name.Text
                }))
                {
                    if (IsNewRecord)
                    {
                        //New record - insert
                        if (UserWithPasswordValidation.Validate() && UserValidation.Validate())
                        {
                            if (Table.Rows.Count < 1)
                            {
                                new BL_User().insert(new ML_User()
                                {
                                    LoginId = txt_login_name.Text.Trim(), Name = txt_name.Text.Trim(), NIC = txt_nic.Text.Trim(), Password = (txt_password.IsEmpty() ? null : txt_password.Text), UserAccessTypeKey = (int)cbo_user_access_type.EditValue, UserKey = UniversalVariables.UserKey, UpdatedDate = DateTime.Now.GetFormattedDateString(UniversalVariables.MySQLDateFormat)
                                });

                                LastUser = txt_name.Text;

                                BindUser();
                                ResetForm(false, true, true, hasAccessInsert, hasAccessDelete, true);
                                SetPrevious();
                            }
                            else
                            {
                                ApplicationUtilities.ShowMessage(UniversalEnum.MessageTypes.Error, "The entered user login name is already in the database. Please re-check!", "Error");
                            }
                        }
                        else
                        {
                            ApplicationUtilities.ShowMessage(UniversalEnum.MessageTypes.Exclamation, "None of the values can be null / invalid. Please re-check!", "Error!");
                        }
                    }
                    else
                    {
                        //Update
                        if (UserValidation.Validate() && SelectedID > 0)
                        {
                            if (Table.Rows.Count <= 1)
                            {
                                bool IsPasswordReset;

                                if (txt_password.IsNotEmpty())
                                {
                                    IsPasswordReset = UserWithPasswordValidation.Validate();
                                    if (!IsPasswordReset)
                                    {
                                        return;
                                    }
                                }
                                else
                                {
                                    IsPasswordReset = false;
                                }

                                new BL_User().update(new ML_User {
                                    LoginId = txt_login_name.Text.Trim(), Name = txt_name.Text.Trim(), NIC = txt_nic.Text.Trim(), UserAccessTypeKey = Convert.ToInt32(cbo_user_access_type.EditValue), UserKey = UniversalVariables.UserKey, Key = SelectedID, Password = IsPasswordReset ? (txt_password.IsEmpty() ? null : txt_password.Text) : null, UpdatedDate = DateTime.Now.GetFormattedDateString(UniversalVariables.MySQLDateFormat)
                                });

                                LastUser = txt_name.Text.Trim();
                                BindUser();
                                ResetForm(false, true, true, hasAccessInsert, hasAccessDelete, true);
                                SetPrevious();
                            }
                            else
                            {
                                ApplicationUtilities.ShowMessage(UniversalEnum.MessageTypes.Error, "The entered user login name is already in the database. Please re-check!", "Error");
                            }
                        }
                        else
                        {
                            ApplicationUtilities.ShowMessage(UniversalEnum.MessageTypes.Error, "None of the values can be null / invalid. Please re-check!", "Error");
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                AuditFactory.AuditLog(ex);
                ApplicationUtilities.ShowMessage(UniversalEnum.MessageTypes.Error, ex.Message);
            }
        }
Exemplo n.º 3
0
 private void ManageUsers_Load(object sender, EventArgs e)
 {
     UserWithPasswordValidation.SetValidationRule(txt_password, new CustomPasswordValidationRule());
     FormDirty = false;
 }