Ejemplo n.º 1
0
        /// <summary>
        /// 删除用户
        /// </summary>
        /// <param name="yh">用户</param>
        public void DeleteYH(Yh yh)
        {
            var userRoles = USERROLEDao.QueryForListByUserId(yh.Xh);

            if (userRoles != null)
            {
                foreach (var userRole in userRoles)
                {
                    USERROLEDao.Delete(userRole.ID);
                }
            }
            USERDao.Delete(yh.Xh);
            mYhList.Remove(yh);
            mYhList.Sort(yhComparer);
            gcMain.RefreshDataSource();
        }
Ejemplo n.º 2
0
        private void BindingGrid()
        {
            mYhList.Clear();
            var users = USERDao.QueryForList();

            if (users != null)
            {
                foreach (var user in users)
                {
                    Yh yh = new Yh
                    {
                        Xh       = user.ID,
                        Xm       = user.REAL_NAME,
                        Dlm      = user.NAME,
                        Xb       = user.GENDER,
                        Bm       = user.DEPT,
                        Lxdh     = user.TEL,
                        Email    = user.EMAIL,
                        Password = user.PASSWORD
                    };
                    var userRoles = USERROLEDao.QueryForListByUserId(user.ID);
                    if (userRoles != null && userRoles.Count > 0)
                    {
                        ROLE role = ROLEDao.Get(userRoles[0].ROLE_ID);
                        if (role != null)
                        {
                            yh.Qx = role.DESCRIPTION;
                        }
                    }
                    mYhList.Add(yh);
                }
            }
            mYhList.Sort(yhComparer);
            gcMain.DataSource = mYhList;
            gcMain.RefreshDataSource();
        }
Ejemplo n.º 3
0
        private void btnOk_Click(object sender, EventArgs e)
        {
            if (txtPwd.Text != txtPwd2.Text)
            {
                MessageBox.Show("两次输入的密码不一致,请重新输入!");
                txtPwd.Focus();
                return;
            }

            if (lblTitle.Text == "新增用户")
            {
                IList <USER> users = USERDao.QueryForList(null).Where(p => p.NAME == txtDlm.Text.Trim()).ToList();
                if (users != null && users.Count > 0)
                {
                    MessageBox.Show("该登录名已使用,请重新输入登录名!");
                    txtDlm.Focus();
                    return;
                }
            }

            USER user = new USER();

            user.ID        = int.Parse(lblXh.Text);
            user.NAME      = txtDlm.Text;
            user.REAL_NAME = txtXm.Text;
            if (rdbMale.Checked == true)
            {
                user.GENDER = "男";
            }
            else
            {
                user.GENDER = "女";
            }
            user.DEPT     = cmbBm.Text;
            user.TEL      = txtLxdh.Text;
            user.EMAIL    = txtEmail.Text;
            user.STATE    = 0;
            user.PASSWORD = txtPwd.Text;
            if (USERDao.Get(user.ID) != null)
            {
                USERDao.Update(user);
            }
            else
            {
                USERDao.Insert(user);
            }

            var userRoles = USERROLEDao.QueryForListByUserId(user.ID);

            if (userRoles != null && userRoles.Count > 0)
            {
                USERROLE userRole = new USERROLE {
                    ID = userRoles[0].ID, USER_ID = user.ID, ROLE_ID = (int)cmbQx.SelectedValue, PROJ_ID = 1
                };
                USERROLEDao.Update(userRole);
            }
            else
            {
                USERROLE userRole = new USERROLE {
                    ID = USERROLEDao.GetNewId(), USER_ID = user.ID, ROLE_ID = (int)cmbQx.SelectedValue, PROJ_ID = 1
                };
                USERROLEDao.Insert(userRole);
            }

            if (lblTitle.Text == "新增用户")
            {
                MainForm.UpdateYHList(null, true);
            }
            else
            {
                MainForm.UpdateYHList(null, false);
            }

            MainForm.HidenFlyout();
        }
Ejemplo n.º 4
0
        private void UserLogin(object sender, EventArgs e)
        {
            Action Login = () =>
            {
                if (string.IsNullOrEmpty(txtUserName.Text.Trim()))
                {
                    Error("用户名不能为空");
                    return;
                }
                else if (string.IsNullOrEmpty(txtPassword.Text.Trim()))
                {
                    Error("密码不能为空");
                    return;
                }
                btnLogin.Text    = "正在登录...";
                btnLogin.Enabled = false;

                IList <USER> users = USERDao.QueryForList(null).Where(
                    p => p.NAME == txtUserName.Text.Trim() && p.PASSWORD == txtPassword.Text.Trim()).ToList();

                if (users != null && users.Count > 0)
                {
                    this.DialogResult = DialogResult.OK;
                    IList <USERROLE>  userRoles  = USERROLEDao.QueryForListByUserId(users[0].ID);
                    IList <ROLERIGHT> roleRights = ROLERIGHTDao.QueryForList(null).Where(p => p.ROLE_ID == userRoles[0].ROLE_ID).ToList();
                    IList <RIGHT>     rights     = new List <RIGHT>();
                    foreach (var roleRight in roleRights)
                    {
                        foreach (var right in RIGHTDao.QueryForList(null).Where(p => p.ID == roleRight.RIGHT_ID))
                        {
                            rights.Add(right);
                        }
                    }

                    AutoLoginUtil autoLogin = new AutoLoginUtil();
                    AutoLoginUser loginUser = new AutoLoginUser();
                    loginUser.UserName = UserName;
                    loginUser.PassWord = PassWord;
                    loginUser.rights   = rights;
                    if (ckRemeberPwd.Checked)
                    {
                        loginUser.RememberPwd = true;
                        autoLogin.SaveAutoLoginInfo(loginUser);
                    }
                    else
                    {
                        autoLogin.SaveAutoLoginInfo(new AutoLoginUser());
                    }
                    LoginUser = loginUser;
                }
                else
                {
                    btnLogin.Text    = "登录";
                    btnLogin.Enabled = true;
                    string errorMessage = "用户名或密码错误";
                    Error(errorMessage);
                }
            };

            this.BeginInvoke(Login);
        }