示例#1
0
        //添加老师信息
        public static bool add_teacher(model.Teacher teacher)
        {
            MySqlConnection conn = Util.getConn();
            MySqlCommand    command;

            try
            {
                command             = conn.CreateCommand();
                command.CommandText = "INSERT INTO teacher(teacher_num,teacher_name,teacher_academy,password,sex,profession,id_number) VALUES('"
                                      + teacher.Teacher_num + "','" + teacher.Teacher_name + "','" +
                                      teacher.Teacher_academy + "','" +
                                      teacher.Password + "','" + teacher.Sex + "','" +
                                      teacher.Profession + "','" + teacher.Id_number + "')";
                Console.WriteLine("sql:" + command.CommandText);
                command.ExecuteNonQuery();
            }
            catch (Exception)
            {
                return(false);
            }
            finally
            {
                if (conn.State == ConnectionState.Open)
                {
                    conn.Close();
                }
            }
            return(true);
        }
示例#2
0
        public static void update(model.Teacher s)//修改学生信息
        {
            MySqlConnection conn    = Util.getConn();
            MySqlCommand    command = null;

            try
            {
                command = conn.CreateCommand();
                string sql = "update teacher set teacher_name='" + s.Teacher_name + "',teacher_academy='" +
                             s.Teacher_academy + "',password='******',profession='" +
                             s.Profession + "',id_number='" + s.Id_number + "' where teacher_num='" +
                             s.Teacher_num + "'";


                Console.Write("sql:" + sql);
                command.CommandText = sql;

                command.ExecuteNonQuery();
                Console.WriteLine();
            }
            catch (Exception)
            {
            }
            finally
            {
                if (conn.State == ConnectionState.Open)
                {
                    conn.Close();
                }
            }
        }
示例#3
0
        public static List <model.Teacher> find_teachers()//查询所有老师
        {
            MySqlConnection conn       = Util.getConn();
            MySqlDataReader dataReader = null;
            MySqlCommand    command    = null;

            List <model.Teacher> tea = new List <model.Teacher>();

            string num = null;

            try
            {
                command             = conn.CreateCommand();
                command.CommandText = "SELECT * FROM teacher";
                dataReader          = command.ExecuteReader();
                Console.WriteLine("sql:" + command.CommandText);
                while (dataReader.Read())
                {
                    model.Teacher teacher = new model.Teacher();
                    teacher.Teacher_num     = dataReader.GetString("teacher_num");
                    teacher.Teacher_name    = dataReader.GetString("teacher_name");
                    teacher.Teacher_academy = dataReader.GetString("teacher_academy");
                    teacher.Profession      = dataReader.GetString("profession");
                    teacher.Id_number       = dataReader.GetString("id_number");
                    teacher.Password        = dataReader.GetString("password");
                    teacher.Sex             = dataReader.GetString("sex");
                    tea.Add(teacher);
                }
            }
            catch (Exception)
            {
            }
            finally
            {
                if (!dataReader.IsClosed)
                {
                    dataReader.Close();
                }
                if (conn.State == ConnectionState.Open)
                {
                    conn.Close();
                }
            }
            return(tea);
        }
示例#4
0
        //姚雅丽
        public model.Teacher selectNum(string number)
        {
            MySqlConnection conn       = util.Util.getConn();
            MySqlDataReader dataReader = null;
            MySqlCommand    command    = null;

            model.Teacher r = new model.Teacher();
            try
            {
                command             = conn.CreateCommand();
                command.CommandText = "SELECT * FROM teacher where teacher_num ='" + number + "'";
                dataReader          = command.ExecuteReader();
                Console.WriteLine(command.CommandText);
                while (dataReader.Read())
                {
                    r.Teacher_num     = dataReader.GetString(0);
                    r.Teacher_name    = dataReader.GetString(1);
                    r.Teacher_academy = dataReader.GetString(2);
                    //r.Question = dataReader.GetString(3);
                    //r.Answer = dataReader.GetString(4);
                    r.Password   = dataReader.GetString(3);
                    r.Sex        = dataReader.GetString(4);
                    r.Profession = dataReader.GetString(5);
                    r.Id_number  = dataReader.GetString(6);
                    return(r);
                }
            }
            catch (Exception)
            {
            }
            finally
            {
                if (!dataReader.IsClosed)
                {
                    dataReader.Close();
                }
                if (conn.State == ConnectionState.Open)
                {
                    conn.Close();
                }
            }
            return(null);
        }
示例#5
0
        public static model.Teacher find_teacher(string teacher_num)//根据学号查询学生信息
        {
            MySqlConnection conn       = Util.getConn();
            MySqlDataReader dataReader = null;
            MySqlCommand    command    = null;

            model.Teacher teacher = new model.Teacher();

            try
            {
                command             = conn.CreateCommand();
                command.CommandText = "SELECT * FROM teacher where teacher_num='" + teacher_num + "'";
                dataReader          = command.ExecuteReader();
                Console.WriteLine();
                while (dataReader.Read())
                {
                    teacher.Teacher_num     = dataReader.GetString("teacher_num");
                    teacher.Teacher_name    = dataReader.GetString("teacher_name");
                    teacher.Teacher_academy = dataReader.GetString("teacher_academy");

                    teacher.Profession = dataReader.GetString("profession");
                    teacher.Id_number  = dataReader.GetString("id_number");
                    teacher.Password   = dataReader.GetString("password");
                    teacher.Sex        = dataReader.GetString("sex");
                }
            }
            catch (Exception)
            {
            }
            finally
            {
                if (!dataReader.IsClosed)
                {
                    dataReader.Close();
                }
                if (conn.State == ConnectionState.Open)
                {
                    conn.Close();
                }
            }
            return(teacher);
        }
示例#6
0
        public static List <model.Teacher> find_teachers2(model.Teacher s)//根据条件老师
        {
            MySqlConnection conn       = Util.getConn();
            MySqlDataReader dataReader = null;
            MySqlCommand    command    = null;

            List <model.Teacher> studs = new List <model.Teacher>();

            string num = null;

            try
            {
                command = conn.CreateCommand();
                string sql   = "SELECT * FROM teacher where";
                bool   shuru = false;//sql语句中是否已添加条件
                if (s.Teacher_num != "")
                {
                    sql   = sql + "  teacher_num='" + s.Teacher_num + "' ";
                    shuru = true;
                }
                if (s.Teacher_name != "")
                {
                    if (shuru == true)
                    {
                        sql = sql + "  and  ";
                    }
                    sql = sql + "  teacher_name='" + s.Teacher_name + "' ";
                }
                if (s.Teacher_academy != "")
                {
                    if (shuru == true)
                    {
                        sql = sql + "  and  ";
                    }
                    sql = sql + "  teacher_academy like '%" + s.Teacher_academy + "%' ";
                }
                if (s.Profession != "")
                {
                    if (shuru == true)
                    {
                        sql = sql + "  and  ";
                    }
                    sql = sql + "  profession='" + s.Profession + "' ";
                }
                Console.Write("sql:" + sql);
                command.CommandText = sql;
                dataReader          = command.ExecuteReader();
                Console.WriteLine();
                while (dataReader.Read())
                {
                    model.Teacher teacher = new model.Teacher();
                    teacher.Teacher_num     = dataReader.GetString("teacher_num");
                    teacher.Teacher_name    = dataReader.GetString("teacher_name");
                    teacher.Teacher_academy = dataReader.GetString("teacher_academy");
                    teacher.Profession      = dataReader.GetString("profession");
                    teacher.Id_number       = dataReader.GetString("id_number");
                    teacher.Password        = dataReader.GetString("password");
                    teacher.Sex             = dataReader.GetString("sex");
                    studs.Add(teacher);
                }
            }
            catch (Exception)
            {
            }
            finally
            {
                if (!dataReader.IsClosed)
                {
                    dataReader.Close();
                }
                if (conn.State == ConnectionState.Open)
                {
                    conn.Close();
                }
            }
            return(studs);
        }