Esempio n. 1
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            this.Cursor = Cursors.WaitCursor;

            if (String.IsNullOrEmpty(this.txtNewPassword1.Text))
            {
                MessageBox.Show("密码不能为空");
                return;
            }
            if (!this.txtNewPassword1.Text.Equals(this.txtNewPassword2.Text))
            {
                MessageBox.Show("二次输入的密码不一致,请重新输入");
                return;
            }

            UserDao userDao = new UserDao();
            User user = new User();
            user.userId = this.txtUserName.Text;
            user.name = this.txtName.Text;
            user.password = this.txtNewPassword1.Text;
            userDao.Update(user);
            this.Cursor = Cursors.Default;
            MessageBox.Show("密码修改完成,下次请用新密码登录.");

        }
Esempio n. 2
0
 public const string mysqlConnection = DBConstant.mysqlConnection;//"User Id=root;Host=115.29.229.134;Database=chinaunion;password=c513324665;charset=utf8";
 /// <summary> 
 /// 添加数据 
 /// </summary> 
 /// <returns></returns> 
 public int Add(User entity)
 {
     string sql = "INSERT INTO tb_user (userId, name, password) VALUE (@userId, @name, @password)";
     using (MySqlConnection mycn = new MySqlConnection(mysqlConnection))
     {
         mycn.Open();
         MySqlCommand command = new MySqlCommand(sql, mycn);
         command.Parameters.AddWithValue("@userId", entity.userId);
         command.Parameters.AddWithValue("@name", entity.name);
         command.Parameters.AddWithValue("@password", entity.password);
         int i = command.ExecuteNonQuery();
         mycn.Close();
         return i;
     }
 }
Esempio n. 3
0
        /// <summary> 
        /// 修改数据 
        /// </summary> 
        /// <param name="entity"></param> 
        /// <returns></returns> 
        public int Update(User entity)
        {
            string sql = "UPDATE  tb_user SET userId=@userId ,name=@name,password=@password where userId=@userId ";

            //string sql = "UPDATE cimuser SET userNickName=@userNickName WHERE userid=@userid";
            using (MySqlConnection mycn = new MySqlConnection(mysqlConnection))
            {
                mycn.Open();
                MySqlCommand command = new MySqlCommand(sql, mycn);
                command.Parameters.AddWithValue("@userId", entity.userId);
                command.Parameters.AddWithValue("@name", entity.name);
                command.Parameters.AddWithValue("@password", entity.password);
                int i = command.ExecuteNonQuery();
                mycn.Close();
                return i;
            }
        }
Esempio n. 4
0
        private void btnLogin_Click(object sender, EventArgs e)
        {
            if (String.IsNullOrEmpty(this.txtUserName.Text))
            {
                MessageBox.Show("请输入用户名");
                txtUserName.Focus();
                return;
            }
            if (String.IsNullOrEmpty(this.txtPassword.Text))
            {
                MessageBox.Show("请输入密码");
                txtPassword.Focus();
                return;
            }
            this.Cursor = Cursors.WaitCursor;
            UserDao userDao = new UserDao();
            this.loginUser = userDao.Get(this.txtUserName.Text);
            if (loginUser == null || (loginUser != null && !loginUser.password.Equals(this.txtPassword.Text)))
            {
                MessageBox.Show("用户名或者密码不正确,请重新输入.");
                txtUserName.Focus();
                this.Cursor = Cursors.Default;
                return;
            }
            this.DialogResult = DialogResult.OK;
            this.Hide();
            //异步执行开始
            worker.RunWorkerAsync();
            frmProgress frm = new frmProgress(this.worker);
          //  frm.Height = 100;
            frm.StartPosition = FormStartPosition.CenterScreen;
            frm.ShowDialog(this);
            frm.Close();
            this.Cursor = Cursors.Default;

            this.Close();
           
        }
Esempio n. 5
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (String.IsNullOrEmpty(this.txtNewUserId.Text.Trim()))
            {
                MessageBox.Show("请输入用户名!");
                this.txtNewUserId.Focus();
                return;
            }
            if (String.IsNullOrEmpty(this.txtName.Text.Trim()))
            {
                MessageBox.Show("请输入姓名!");
                this.txtName.Focus();
                return;
            }
            if (String.IsNullOrEmpty(this.txtPassword.Text.Trim()))
            {
                MessageBox.Show("请输入密码!");
                this.txtPassword.Focus();
                return;
            }
            this.Cursor = Cursors.WaitCursor;
            User user = new User();
            user.userId = this.txtNewUserId.Text.Trim();
            user.name = this.txtName.Text.Trim();
            user.password = this.txtPassword.Text.Trim();
            userRightDao.DeleteByUserId(user.userId);
            userDao.Delete(user.userId);
            userDao.Add(user);

            foreach (TreeNode node in this.tvMenu.Nodes)
            {

                if (node.Checked)
                {
                    UserRight userRight = new UserRight();
                    userRight.userId = user.userId;
                    userRight.menuId = node.Tag.ToString();
                    userRightDao.Add(userRight);
                }
                bool hasInsert = false;
                foreach (TreeNode childNode in node.Nodes)
                {
                   
                    if (childNode.Checked)
                    {
                        UserRight userRight = new UserRight();
                        userRight.userId = user.userId;
                        userRight.menuId = childNode.Tag.ToString();
                        userRightDao.Add(userRight);
                        if (!childNode.Parent.Checked && !hasInsert)
                        {
                            UserRight parentUserRight = new UserRight();
                            parentUserRight.userId = user.userId;
                            parentUserRight.menuId = childNode.Parent.Tag.ToString();
                            userRightDao.Add(parentUserRight);
                            hasInsert = true;
                        }
                    }

                }
            }
            /*

            foreach (DataGridViewRow row in this.dgAssignRight.Rows)
            {
                UserRight userRight = new UserRight();
                userRight.userId = user.userId;
                userRight.menuId = row.Cells[0].Value.ToString();
                userRightDao.Add(userRight);
            }*/
            this.prepareGrid("");
            MessageBox.Show("操作完成");

            this.Cursor = Cursors.Default;
        }
Esempio n. 6
0
        /// <summary> 
        /// 根据主键查询 
        /// </summary> 
        /// <param name="primaryKey"></param> 
        /// <returns></returns> 
        public User Get(String userId)
        {
            string sql = "SELECT userId, name, password FROM tb_user where  userId=@userId";
            using (MySqlConnection mycn = new MySqlConnection(mysqlConnection))
            {
                mycn.Open();
                MySqlCommand command = new MySqlCommand(sql, mycn);
                command.Parameters.AddWithValue("@userId", userId);
                MySqlDataReader reader = command.ExecuteReader();

                User user = null;
                UserRightDao userRightDao = new UserRightDao();
                if (reader.Read())
                {
                    user = new User();
                    user.userId = reader["userId"] == DBNull.Value ? null : reader["userId"].ToString();
                    user.name = reader["name"] == DBNull.Value ? null : reader["name"].ToString();
                    user.password = reader["password"] == DBNull.Value ? null : reader["password"].ToString();                   
                }
                reader.Close();

                sql = "SELECT t1.userId,t1.menuId, t2.menu_text FROM tb_user_right t1, tb_menu t2 where  userId=@userId and t1.menuId = t2.ID ";

                command = new MySqlCommand(sql, mycn);
                command.Parameters.AddWithValue("@userId", userId);
                MySqlDataReader userRightReader = command.ExecuteReader();

                IList<UserRight> list = new List<UserRight>();
                UserRight userRight = null;
                while (userRightReader.Read())
                {
                    userRight = new UserRight();
                    userRight.userId = userRightReader["userId"] == DBNull.Value ? null : userRightReader["userId"].ToString();
                    userRight.menuId = userRightReader["menuId"] == DBNull.Value ? null : userRightReader["menuId"].ToString();
                    userRight.menuText = userRightReader["menu_text"] == DBNull.Value ? null : userRightReader["menu_text"].ToString();
                    list.Add(userRight);
                }
                if (user != null)
                {
                    user.userRightList = list;
                }

                mycn.Close();

                return user;
            }

        }
Esempio n. 7
0
        /// <summary> 
        /// 查询集合 
        /// </summary> 
        /// <returns></returns> 
        public IList<User> GetList(String userId)
        {
            string sql = "SELECT userId, name, password FROM tb_user ";
            if (!String.IsNullOrEmpty(userId))
            {
                sql = sql + " where userId like '" + userId + "%'";
            }
            using (MySqlConnection mycn = new MySqlConnection(mysqlConnection))
            {
                mycn.Open();
                MySqlCommand command = new MySqlCommand(sql, mycn);
                MySqlDataReader reader = command.ExecuteReader();
                IList<User> list = new List<User>();
                User user = null;
                // UserRightDao userRightDao = new UserRightDao();
                while (reader.Read())
                {
                    user = new User();

                    user.userId = reader["userId"] == DBNull.Value ? null : reader["userId"].ToString();
                    user.name = reader["name"] == DBNull.Value ? null : reader["name"].ToString();
                    user.password = reader["password"] == DBNull.Value ? null : reader["password"].ToString();
                    //user.userRightList = userRightDao.GetList(user.userId);
                    list.Add(user);
                }
                
                mycn.Close();
                return list;
            }
        }
Esempio n. 8
0
 private void btnModifyPassword_Click(object sender, EventArgs e)
 {
   
     if (String.IsNullOrEmpty(this.txtUserName.Text))
     {
         MessageBox.Show("请输入用户名");
         txtUserName.Focus();
         return;
     }
     if (String.IsNullOrEmpty(this.txtPassword.Text))
     {
         MessageBox.Show("请输入密码");
         txtPassword.Focus();
         return;
     }
     this.Cursor = Cursors.WaitCursor;
     UserDao userDao = new UserDao();
     this.loginUser = userDao.Get(this.txtUserName.Text);
     if (loginUser == null || (loginUser != null && !loginUser.password.Equals(this.txtPassword.Text)))
     {
         MessageBox.Show("用户名或者密码不正确,请重新输入.");
         txtUserName.Focus();
         return;
     }
     this.Cursor = Cursors.Default;
     frmUserModification frmUserModification = new frmUserModification();
     frmUserModification.ShowDialog();
 }