Esempio n. 1
0
        private void ActionUpdate1_PressUpdate(object sender, EventArgs e)
        {
            //throw new NotImplementedException();


            TabPermissionBLL mTabPermissionBLL = new TabPermissionBLL(mAccount);
            int t = 0;

            foreach (stanfTabPermission obj in lst)
            {
                mTabPermissionBLL.UpdateElement(obj);
                t++;
            }
            if (t == lst.Count)
            {
                MessageBox.Show("Cập nhật quyền thành công!");
            }
        }
Esempio n. 2
0
        void actionUpdateStanUser_PressUpdate(object sender, EventArgs e)
        {
            msgMessage.Clear();

            if (string.IsNullOrEmpty("" + txtHoTen.Text))
            {
                msgMessage.SetError(txtHoTen, "Bạn cần nhập họ tên trước khi thực hiện");
                txtHoTen.Focus();
                return;
            }
            if (string.IsNullOrEmpty("" + txtEmail.Text))
            {
                msgMessage.SetError(txtEmail, "Bạn cần nhập email trước khi thực hiện");
                txtEmail.Focus();
                return;
            }
            if (!string.IsNullOrEmpty("" + txtEmail.Text))
            {
                if (Common.validateEmail(txtEmail.Text) < 1)
                {
                    msgMessage.SetError(txtEmail, "Bạn cần nhập email đúng định dạng");
                    txtEmail.Focus();
                    return;
                }
            }

            if (string.IsNullOrEmpty("" + txtUserName.Text))
            {
                msgMessage.SetError(txtUserName, "Bạn cần nhập tên tài khoản trước khi thực hiện");
                txtUserName.Focus();
                return;
            }
            if (txtPassword.Enabled == true)
            {
                if (string.IsNullOrEmpty("" + txtPassword.Text))
                {
                    msgMessage.SetError(txtPassword, "Bạn cần nhập mật khẩu trước khi thực hiện");
                    txtPassword.Focus();
                    return;
                }
            }
            if (txtPasswordAfter.Enabled == true)
            {
                if (string.IsNullOrEmpty("" + txtPasswordAfter.Text))
                {
                    msgMessage.SetError(txtPasswordAfter, "Bạn cần nhập mật khẩu nhập lại trước khi thực hiện");
                    txtPasswordAfter.Focus();
                    return;
                }
            }
            if (!string.IsNullOrEmpty("" + txtPassword.Text) && !string.IsNullOrEmpty("" + txtPasswordAfter.Text) && !txtPassword.Text.Equals(txtPasswordAfter.Text))
            {
                msgMessage.SetError(txtPasswordAfter, "Mật khẩu nhập lại không chính xác");
                txtPasswordAfter.Focus();
                return;
            }
            int temp     = 1;
            int mIsAdmin = 1;

            if (cboUserType.Text == "User")
            {
                mIsAdmin = 0;
            }
            if (cboSex.Text == "Nam")
            {
                temp = 0;
            }
            Account objAcc = new Account()
            {
                DisplayName = txtHoTen.Text,
                Email       = txtEmail.Text,
                isOnline    = false,
                isSuccess   = false,
                IsSuperUser = false,
                isAdmin     = mIsAdmin,
                Password    = Common.EncodePassword(txtPassword.Text),
                Phone       = txtMobile.Text,
                Sex         = temp,
                UserName    = txtUserName.Text
            };

            if (UpdateAcc == null) //Insert
            {
                if (mAccountBiLL.InsertElement(objAcc))
                {
                    MessageBox.Show("Thêm mới tài khoản thành công!");
                    List <stanfRole> lstRoles = new List <stanfRole>();
                    lstRoles = new RolesBLL(mAccount).getElements();
                    TabPermissionBLL mTabPermissionBLL = new TabPermissionBLL(mAccount);
                    List <Account>   lstAcc            = new List <Account>();
                    lstAcc = mAccountBiLL.getElements();
                    Account tempAcc = new Account();
                    tempAcc = lstAcc.LastOrDefault();

                    foreach (stanfRole o in lstRoles)
                    {
                        stanfTabPermission mStanfTabPermission = new stanfTabPermission
                        {
                            RoleId = o.RoleId,
                            UserId = tempAcc.UserId
                        };
                        mTabPermissionBLL.InsertElement(mStanfTabPermission);
                    }
                }
                else
                {
                    MessageBox.Show("Thêm mới tài khoản thất bại!");
                }
            }
            else //Update
            {
                objAcc.UserId = UpdateAcc.UserId;
                if (mAccountBiLL.UpdateElement(objAcc))
                {
                    MessageBox.Show("Cập nhật tài khoản thành công!");
                }
                else
                {
                    MessageBox.Show("Cập nhật tài khoản thất bại!");
                }
            }
            this.Close();
        }