Example #1
0
        /// <summary>
        /// 查询部门名称为departmentName的所有员工信息
        /// </summary>
        /// <param name="departmendId"></param>
        /// <returns></returns>
        public static List<Employee> QueryEmployee(String departmentName)
        {
            MySqlConnection con = DBTools.GetMySqlConnection();
            MySqlCommand cmd;

            List<Employee> employees = new List<Employee>();

            try
            {
                con.Open();

                cmd = con.CreateCommand();

                cmd.CommandText = QUERY_DEPARTMENT_EMPLOYEE_NAME_STR;
                cmd.Parameters.AddWithValue("@DepartmentName", departmentName);

                MySqlDataReader sqlRead = cmd.ExecuteReader();
                cmd.Dispose();

                while (sqlRead.Read())
                {
                    Employee employee = new Employee();

                    employee.Id = int.Parse(sqlRead["id"].ToString());
                    employee.Name = sqlRead["name"].ToString();
                    employee.Position = sqlRead["position"].ToString();

                    employee.CanSubmit = int.Parse(sqlRead["cansubmit"].ToString());
                    employee.CanSign = int.Parse(sqlRead["cansign"].ToString());
                    employee.IsAdmin = int.Parse(sqlRead["isadmin"].ToString());

                    Department depart = new Department();
                    depart.Id = int.Parse(sqlRead["departid"].ToString());
                    depart.Name = sqlRead["departname"].ToString();
                    employee.Department = depart;

                    User user = new User();
                    user.Username = sqlRead["username"].ToString();
                    user.Password = sqlRead["password"].ToString();
                    employee.User = user;

                    employees.Add(employee);        // 将查询出来的员工信息插入链表中
                }

                con.Close();
                con.Dispose();

            }
            catch (Exception)
            {
                throw;
            }
            finally
            {

                if (con.State == ConnectionState.Open)
                {
                    con.Close();
                }
            }
            return employees;
        }
Example #2
0
        public static bool ModifyEmployeePassword(User user)
        {
            MySqlConnection con = DBTools.GetMySqlConnection();
            MySqlCommand cmd;
            int count = -1;
            try
            {
                con.Open();

                cmd = con.CreateCommand();

                cmd.CommandText = MODIFY_EMPLOYEE_PASSWORD_USERENAME_STR;
                cmd.Parameters.AddWithValue("@Password", user.Password);
                cmd.Parameters.AddWithValue("@Username", user.Username);                        // 员工姓名

                count = cmd.ExecuteNonQuery();
                cmd.Dispose();

                con.Close();
                con.Dispose();
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {

                if (con.State == ConnectionState.Open)
                {
                    con.Close();
                }
            }
            if (count == 1)
            {
                Console.WriteLine("修改密码" + user.ToString() + "成功");

                return true;
            }
            else
            {
                Console.WriteLine("修改密码" + user.ToString() + "失败");

                return false;
            }
        }
Example #3
0
        public static bool IsEmployeePasswordRight(User user)
        {
            MySqlConnection con = DBTools.GetMySqlConnection();
            MySqlCommand cmd;

            int count = -1;

            try
            {
                con.Open();

                cmd = con.CreateCommand();

                cmd.CommandText = IS_EMP_PWD_RIGHT_STR;
                cmd.Parameters.AddWithValue("@username", user.Username);
                cmd.Parameters.AddWithValue("@Password", user.Password);

                MySqlDataReader sqlRead = cmd.ExecuteReader();
                cmd.Dispose();

                while (sqlRead.Read())
                {
                    count = int.Parse(sqlRead["count"].ToString());
                }

                con.Close();
                con.Dispose();

            }
            catch (Exception)
            {
                throw;
            }
            finally
            {

                if (con.State == ConnectionState.Open)
                {
                    con.Close();
                }
            }
            if (count == 1)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
Example #4
0
        public static Employee LoginEmployee(User user)
        {
            MySqlConnection con = DBTools.GetMySqlConnection();
            MySqlCommand cmd;
            Employee employee = new Employee();
            try
            {
                con.Open();

                cmd = con.CreateCommand();

                cmd.CommandText = LOGIN_EMPLOYEE_COM_STR;
                cmd.Parameters.AddWithValue("@Username", user.Username);                         // 员工登录用户名
                cmd.Parameters.AddWithValue("@Password", user.Password);                         // 员工登录密码
                MySqlDataReader sqlRead = cmd.ExecuteReader();

                cmd.Dispose();

                /*while (sqlRead.Read( ))
                {}*/
                if (sqlRead.Read())
                {
                    // 基本信息
                    employee.Id = int.Parse(sqlRead["id"].ToString());
                    employee.Name = sqlRead["name"].ToString();
                    employee.Position = sqlRead["position"].ToString();
                    employee.CanSubmit = int.Parse(sqlRead["cansubmit"].ToString());
                    employee.CanSign = int.Parse(sqlRead["cansign"].ToString());
                    employee.IsAdmin = int.Parse(sqlRead["isadmin"].ToString());

                    // 职位信息
                    Department depart = new Department();
                    depart.Id = int.Parse(sqlRead["departid"].ToString());
                    depart.Name = sqlRead["departname"].ToString();
                    employee.Department = depart;

                    // 用户登录信息
                    employee.User = user;

                }
                else
                {
                    employee.Id = -1;
                }
                con.Close();
                con.Dispose();

            }
            catch (Exception)
            {
                throw;
            }
            finally
            {

                if (con.State == ConnectionState.Open)
                {
                    con.Close();
                }
            }
            return employee;
        }
Example #5
0
        public static Employee GetEmployee(String employeeUsername)
        {
            MySqlConnection con = DBTools.GetMySqlConnection();
            MySqlCommand cmd;
            Employee employee = null;          //  待返回的员工信息

            try
            {
                con.Open();

                cmd = con.CreateCommand();

                cmd.CommandText = GET_EMPLOYEE_USERNAME_STR;
                cmd.Parameters.AddWithValue("@Username", employeeUsername);                         // 员工编号

                MySqlDataReader sqlRead = cmd.ExecuteReader();

                cmd.Dispose();

                if (sqlRead.Read())
                {
                    employee = new Employee();
                    employee.Id = int.Parse(sqlRead["id"].ToString());
                    employee.Name = sqlRead["name"].ToString();
                    employee.Position = sqlRead["position"].ToString();

                    employee.CanSubmit = int.Parse(sqlRead["cansubmit"].ToString());
                    employee.CanSign = int.Parse(sqlRead["cansign"].ToString());
                    employee.IsAdmin = int.Parse(sqlRead["isadmin"].ToString());

                    Department depart = new Department();
                    depart.Id = int.Parse(sqlRead["departid"].ToString());
                    depart.Name = sqlRead["departname"].ToString();
                    employee.Department = depart;

                    User user = new User();
                    user.Username = sqlRead["username"].ToString();
                    user.Password = sqlRead["password"].ToString();
                    employee.User = user;
                    Console.WriteLine(employee);
                }

                con.Close();
                con.Dispose();

            }
            catch (Exception)
            {
                throw;
            }
            finally
            {

                if (con.State == ConnectionState.Open)
                {
                    con.Close();
                }
            }
            return employee;
        }