Exemple #1
0
        public static bool DeleteTeacherInfo(TeacherExt teacherExt)
        {
            SqlHelper.GetConn();
            string sqlStr = "delete from teacher where teacher_id = '{0}'";

            sqlStr = string.Format(sqlStr, teacherExt.Teacher_id);
            if (SqlHelper.CreateCommand(sqlStr).ExecuteNonQuery() == 1)
            {
                SqlHelper.CloseConn();
                return(true);
            }
            else
            {
                SqlHelper.CloseConn();
                return(false);
            }
        }
Exemple #2
0
        public static bool UpdateTeacherInfo(TeacherExt teacherExt)
        {
            SqlHelper.GetConn();
            string sqlCheck = "select * from teacher where teacher_id = '{0}'";

            sqlCheck = string.Format(sqlCheck, teacherExt.Teacher_id);
            SqlDataReader reader = SqlHelper.CreateCommand(sqlCheck).ExecuteReader();

            try
            {
                if (reader.HasRows)
                {
                    string sqlStr = "update teacher set teacher_id = '{0}',teacher_name = '{1}',teacher_sex = '{2}',college_id = (select college_id from college where college_name = '{3}'),nation_id = (select nation_id from nation where nation_name = '{4}'),email = '{5}',phone_num = '{6}',house_address = '{7}',ID_card = '{8}',teacher_birthday = '{9}',profession_id = (select profession_id from profession where profession_name = '{10}') where teacher_id = '{11}'";
                    sqlStr = string.Format(sqlStr, teacherExt.Teacher_id, teacherExt.Teacher_name, teacherExt.Teacher_sex, teacherExt.College_name, teacherExt.Nation_name, teacherExt.Email, teacherExt.Phone_num, teacherExt.House_address, teacherExt.ID_card, teacherExt.Teacher_birthday.ToString(), teacherExt.Profession_name, teacherExt.Teacher_id);
                    if (SqlHelper.CreateCommand(sqlStr).ExecuteNonQuery() == 0)
                    {
                        MessageBox.Show("修改失败", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1);
                        return(false);
                    }
                    else
                    {
                        return(true);
                    }
                }
                else
                {
                    if (MessageBox.Show("不存在该工号教师,是否在数据库中添加此教师?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == DialogResult.Yes)
                    {
                        AddTeacherInfo(teacherExt);
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
            }
            catch
            {
                throw new Exception("修改教师信息失败!");
            }
            finally
            {
                SqlHelper.CloseConn();
            }
        }
Exemple #3
0
        public static bool AddTeacherInfo(TeacherExt teacherExt)
        {
            SqlHelper.GetConn();
            string sqlStr = "insert into teacher values('{0}','{1}','{2}',(select college_id from college where college_name = '{3}'),(select nation_id from nation where nation_name = '{4}'),'{5}','{6}','{7}','{8}','{9}',null,(select profession_id from profession where profession_name = '{10}'))";

            sqlStr = string.Format(sqlStr, teacherExt.Teacher_id, teacherExt.Teacher_name, teacherExt.Teacher_sex, teacherExt.College_name, teacherExt.Nation_name, teacherExt.Email, teacherExt.Phone_num, teacherExt.House_address, teacherExt.ID_card, teacherExt.Teacher_birthday.ToString(), teacherExt.Profession_name);
            if (SqlHelper.CreateCommand(sqlStr).ExecuteNonQuery() == 0)
            {
                MessageBox.Show("添加失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                SqlHelper.CloseConn();
                return(false);
            }
            else
            {
                SqlHelper.CloseConn();
                return(true);
            }
        }