Beispiel #1
0
        //删除教师员工
        public bool DeleteTeacher(TeacherModel objTeacherModel)
        {
            string SqlString = "delete FROM Teacher WHERE TeaNum='" + objTeacherModel.TeaNum + "' ";
            DataBaseOperaClass objDataBase = new DataBaseOperaClass();

            return (objDataBase.GetExecute(SqlString));
        }
        public TeacherModel getTeacherByTid(int tid)
        {
            MySqlConnection conn = GetConn.getConn();
            TeacherModel teacherModel = new TeacherModel();
            try
            {
                conn.Open();

                MySqlCommand cmd = new MySqlCommand("select * from `tb_teacher` where `tid`=@tid", conn);
                cmd.Parameters.AddWithValue("@tid", tid);
                MySqlDataReader reader = cmd.ExecuteReader();
                if (reader.Read())
                {
                    teacherModel.Tid = int.Parse(reader["tid"].ToString());
                    teacherModel.Uid = int.Parse(reader["uid"].ToString());
                    teacherModel.Tname = reader["tname"].ToString();
                    teacherModel.Gender = int.Parse(reader["gender"].ToString());
                    teacherModel.Birthday = reader["birthday"].ToString();
                    teacherModel.Phone = reader["phone"].ToString();
                }
                conn.Close();
                return teacherModel;
            }
            catch (Exception)
            {
                conn.Close();
                return null;
            }
        }
        private void button1_Click(object sender, EventArgs e)
        {
            if (this.tb_phone.Text != "" && this.tb_tname.Text != "" && (this.radioButton1.Checked || this.radioButton2.Checked))
            {
                tname = this.tb_tname.Text;
                phone = this.tb_phone.Text;
                if (this.radioButton1.Checked)
                    gender = 1;
                else
                    gender = 0;
                birthday = this.dateTimePicker1.Text;

                TeacherModel teacherModel = new TeacherModel(0, 0, tname, gender, birthday, phone);

                int tid = 0 ;
                TeacherBusiness teacherBusiness = new TeacherBusiness();
                tid = teacherBusiness.addteacher(teacherModel);
                if (tid != 0)
                {
                    MessageBox.Show("成功!");
                }
                else
                {
                    MessageBox.Show("失败,请重试!");
                }
                this.Dispose();
            }
            else
            {
                MessageBox.Show("请填写所有信息!");
            }
        }
        public CourseInfo(CourseModel cModel, TeacherModel tModel, PlaceModel pModel, String precName)
        {
            this.cModel = cModel;
            this.tModel = tModel;
            this.pModel = pModel;
            this.precourseName = precName;

            updateCourseInfo();
        }
Beispiel #5
0
        //返回查找结果:
        public DataTable SearchTea(TeacherModel objTeacherModel)
        {
            string SqlString = "Select TeaNum AS 工号,TeaName AS 姓名,TeaSex AS 性别, TeaAdress AS 联系地址,TeaPhone AS 联系电话,TeaTitle AS 职称,TeaProField AS 专业方向 From dbo.Teacher Where TeaNum='"+objTeacherModel.TeaNum+"'";

            DataBaseOperaClass objDataBaseOperaClass=new DataBaseOperaClass();
            DataTable objDataTable = objDataBaseOperaClass.GetDataSet(SqlString).Tables[0];

            return (objDataTable);
        }
Beispiel #6
0
        //查找教师员工
        public bool SearchTeacher(TeacherModel objTeacherModel)
        {
            string SqlString = "SELECT *FROM Teacher  where TeaName='" + objTeacherModel.TeaName + "'";
            DataBaseOperaClass objDataBase = new DataBaseOperaClass();

               if  (objDataBase.GetDataSet(SqlString ).Tables[0].Rows.Count >0)
               return (true);
               else
               return (false);
        }
Beispiel #7
0
        public bool UpdateTea(TeacherModel objTeacherModel)
        {
            string SQLString;
            SQLString = "UPDATE Teacher SET TeaName='" + objTeacherModel.TeaName + "',TeaSex='" + objTeacherModel.TeaSex + "'";
            SQLString += ",TeaPhone='" + objTeacherModel.TeaPhone + "',TeaAdress='" + objTeacherModel.TeaAdress + "'";
            SQLString += ",TeaTitle='" + objTeacherModel.TeaTitle + "',TeaNum='" + objTeacherModel.TeaNum + "' where TeaNum='" + objTeacherModel.TeaNum + "'";
            DataBaseOperaClass objDataBase = new DataBaseOperaClass();

            if (objDataBase.GetExecute(SQLString))
                return (true);
            else
                return (false);
        }
 public int addteacher(TeacherModel teacherModel)
 {
     UserService userService = new UserService();
     int uid, tid = 0;
     uid = userService.insert(teacherModel.Tname, "123456", 2);
     if (uid != 0)
     {
         teacherModel.Uid = uid;
         TeacherService teacherService = new TeacherService();
         tid = teacherService.insert(teacherModel);
         //这里将来要模拟实现事务,如果tid为0,则删除user表里的记录
     }
     return tid;
 }
Beispiel #9
0
        public bool AddTeacher(TeacherModel objTeacherModel)
        {
            string Sqlstring = "INSERT INTO Teacher(TeaNum,TeaName,TeaSex,TeaAdress,TeaPhone,TeaTitle)VALUES ('" + objTeacherModel.TeaNum + "','" + objTeacherModel.TeaName
              + "','" + objTeacherModel.TeaSex + "','" + objTeacherModel.TeaAdress + "','" + objTeacherModel.TeaPhone + "','" + objTeacherModel.TeaTitle + "')";

            DataBaseOperaClass objDataBase = new DataBaseOperaClass();

            try
            {
                if (objDataBase.GetExecute(Sqlstring))
                    return (true);
                else
                    return (false);
            }
            catch (Exception e1)
            {
                MessageBox.Show("教师工号不能重复\n请检查输入内容!" + e1);
                return (false);
            }
        }
        public List<CourseInfo> getTimetable(int sid)
        {
            int startyear = int.Parse(new StudentBusiness().getStuBySid(sid).Startyear.ToString());
            int year = DateTime.Now.Year;
            int month = DateTime.Now.Month;
            int semester = (month >= 1 && month <= 6) ? 2 * (year - startyear) : 2 * (year - startyear) + 1;

            courseModelList = new CourseService().getAllCourseBySid(sid, semester);
            if (courseModelList != null)
            {
                foreach (CourseModel cModel in courseModelList)
                {
                    tModel = new TeacherService().getTeacherByTid(cModel.Tid);
                    pModel = new PlaceService().getPlacebyPid(cModel.Pid);
                    precName = (new CourseService().getCoursebyCid(cModel.Precourse)).Cname;
                    courseInfo = new CourseInfo(cModel, tModel, pModel, precName);
                    courseInfoList.Add(courseInfo);
                }
            }

            return courseInfoList;
        }
 public int insert(TeacherModel teacherModel)
 {
     MySqlConnection conn = GetConn.getConn();
     try
     {
         conn.Open();
         MySqlCommand cmd = new MySqlCommand("insert into `tb_teacher` (uid,tname,gender,birthday,phone) values (@uid,@tname,@gender,@birthday,@phone)", conn);
         cmd.Parameters.AddWithValue("@uid", teacherModel.Uid);
         cmd.Parameters.AddWithValue("@tname", teacherModel.Tname);
         cmd.Parameters.AddWithValue("@gender", teacherModel.Gender);
         cmd.Parameters.AddWithValue("@birthday", teacherModel.Birthday);
         cmd.Parameters.AddWithValue("@phone", teacherModel.Phone);
         cmd.ExecuteNonQuery();
         cmd.Dispose();
         //返回主键值tid
         return this.getTidByUid(teacherModel.Uid);
     }
     catch (Exception)
     {
         conn.Close();
         return 0;
     }
 }
Beispiel #12
0
        //Add:
        private void btnAdd_Click(object sender, EventArgs e)
        {
            #region sql语句进行添加,已注释
            //TeacherBLL objTeacherBLL = new TeacherBLL();
            //TeacherModel Teacher = new TeacherModel();
            //Teacher.TeaNum = txtNum.Text  ;
            //Teacher.TeaName = txtName.Text;
            //Teacher.TeaSex = cmbSex.Text;
            //Teacher.TeaAdress = txtAdress.Text;
            //Teacher.TeaPhone = txtPhone.Text;
            //Teacher.TeaTitle = txtTitle.Text;

            //if(objTeacherBLL.AddTeacher(Teacher)==true)
            //    MessageBox.Show("数据添加成功");
            //else
            //    MessageBox.Show("数据添加失败");
            //dgvTeacherInfo.DataSource = objTeacherBLL.ShowTeacher();
            #endregion

            #region  //存储过程 已注释
            ////SqlConnection objConn = new SqlConnection("Data Source=.\\SQLExpress;Initial Catalog=StuManageSystem_2008;Integrated Security=True");
            ////objConn.Open();
            ////SqlCommand objSqlCommand = new SqlCommand();
            //objSqlCommand.Connection = objConn;
            //objSqlCommand.CommandType = CommandType.StoredProcedure;
            //objSqlCommand.CommandText = "Teachers";
            //objSqlCommand.Parameters.Add("@TeaName", SqlDbType.NChar, 10);
            //objSqlCommand.Parameters["@TeaName"].Value = txtName.Text;
            //objSqlCommand.Parameters.Add("@Sex", SqlDbType.NChar, 10);
            //objSqlCommand.Parameters["@TeaSex"].Value = txtSex.Text;
            //objSqlCommand.Parameters.Add("@TeaAdress", SqlDbType.NChar, 10);
            //objSqlCommand.Parameters["@TeaAdress"].Value = txtAdress.Text;
            //objSqlCommand.Parameters.Add("@TeaPhone", SqlDbType.NChar, 10);
            //objSqlCommand.Parameters["@TeaPhone"].Value = txtPhone.Text;
            //objSqlCommand.Parameters.Add("@TeaTitle", SqlDbType.NChar, 10);
            //objSqlCommand.Parameters["@TeaTitle"].Value = txtTitle.Text;
            //if (objSqlCommand.EndExecuteNonQuery() > 0)
            //    MessageBox.Show("添加成功");
            //else MessageBox.Show("添加失败");
            //objConn.Close();

            //调用类的后半段
            //string SqlString = "select*from dbo.Teacher";

            // dgvTeacherInfo.DataSource = objDataBase.GetDataSet(SqlString).Tables[0];

            //SqlCommand objSqlCommand = new SqlCommand();
            //objSqlCommand.CommandType = CommandType.StoredProcedure;
            //objSqlCommand.CommandText = "studentInsert";

            //objSqlCommand.Parameters.AddWithValue("@TeaNum", txtNum.Text);
            //objSqlCommand.Parameters.AddWithValue("@TeaName", txtName.Text);
            //objSqlCommand.Parameters.AddWithValue("@TeaSex", cmbSex.Text);
            //objSqlCommand.Parameters.AddWithValue("@TeaAdress ", txtAdress.Text);
            //objSqlCommand.Parameters.AddWithValue("@TeaPhone", txtPhone.Text);
            //objSqlCommand.Parameters.AddWithValue("@TeaTitle", txtTitle.Text);

            //SQLClass1 objdatabase = new SQLClass1();

            //if (objdatabase.GetExecute1(objSqlCommand))
            //    MessageBox.Show("添加成功");
            //else
            //    MessageBox.Show("添加失败");

            //showDGV();

            #endregion

            if (txtTeaNum.Text=="" || txtTeaName.Text == "")
            {
                MessageBox.Show("工号和姓名都不能为空!\n 请重新输入!");

            }
            else
            {
                TeacherBLL objTeacherBLL = new TeacherBLL();
                TeacherModel objTeacherModel = new TeacherModel();

                objTeacherModel.TeaAdress = txtTeaAddress.Text;
                objTeacherModel.TeaName = txtTeaName.Text;
                objTeacherModel.TeaNum = txtTeaNum.Text;
                objTeacherModel.TeaPhone = txtTeaPhone.Text;
                objTeacherModel.TeaTitle = txtTeaTitle.Text;
                objTeacherModel.TeaSex = cbxTeaSex.Text;
                objTeacherModel.TeaTitle = txtTeaTitle.Text;

                if (objTeacherBLL.AddTeacher(objTeacherModel) == true)
                {
                    MessageBox.Show("增加成功!");
                }
                else
                    MessageBox.Show("增加失败!");
                ShowTable();
            }
        }
Beispiel #13
0
        //Search:
        private void btnSearch_Click(object sender, EventArgs e)
        {
            dgvTeacherInfo.DataSource=0;

            if (txtTeaNum.Text == "")
            {
                MessageBox.Show("请先输入工号\n!");

            }
            else
            {
                TeacherModel objTeacherModel = new TeacherModel();
                objTeacherModel.TeaNum = txtTeaNum.Text;

                TeacherBLL objTeacherBLL = new TeacherBLL();

                dgvTeacherInfo.DataSource = objTeacherBLL.SearchTea(objTeacherModel);

            }
        }
Beispiel #14
0
        //Update:
        private void btnModify_Click(object sender, EventArgs e)
        {
            if (txtTeaNum.Text == "" || txtTeaName.Text == "")
            {
                MessageBox.Show("工号和姓名都不能为空!\n 请重新输入!");

            }
            else
            {

                TeacherBLL objTeacherBLL = new TeacherBLL();
                TeacherModel objTeacherModel = new TeacherModel();

                objTeacherModel.TeaAdress = txtTeaAddress.Text;
                objTeacherModel.TeaName = txtTeaName.Text;
                objTeacherModel.TeaNum = txtTeaNum.Text;
                objTeacherModel.TeaPhone = txtTeaPhone.Text;
                objTeacherModel.TeaTitle = txtTeaTitle.Text;
                objTeacherModel.TeaSex = cbxTeaSex.Text;
                objTeacherModel.TeaTitle = txtTeaTitle.Text;

                if (objTeacherBLL.UpdateTea(objTeacherModel)==true)
                {
                    MessageBox.Show("增加成功!");
                }
                else
                    MessageBox.Show("增加失败!");
            }

            ShowTable();
        }
Beispiel #15
0
        //Del:
        private void btnDel_Click(object sender, EventArgs e)
        {
            TeacherBLL objTeacherBLL = new TeacherBLL();

                TeacherModel objTeacherModel = new TeacherModel();

                objTeacherModel.TeaNum = txtTeaNum.Text;

                if (objTeacherBLL.DeleteTeacher(objTeacherModel)==true)

                { MessageBox.Show("数据删除成功"); }
                else
                { MessageBox.Show("数据删除失败"); }

                ShowTable();
        }
Beispiel #16
0
 public bool DeleteTeacher(TeacherModel objTeacherModel)
 {
     TeacherDAl objTeacherDAl = new TeacherDAl();
          return (objTeacherDAl.DeleteTeacher(objTeacherModel));
 }
        //教师列表编辑后保存
        private void dataGridView2_CellEndEdit(object sender, DataGridViewCellEventArgs e)
        {
            TeacherModel teaModelToBeUpdated = new TeacherModel();
            TeacherBusiness teaBusiness = new TeacherBusiness();

            teaModelToBeUpdated.Tid = int.Parse(this.dataGridView2.CurrentRow.Cells["tid"].Value.ToString());

            teaModelToBeUpdated.Tname = this.dataGridView2.CurrentRow.Cells["tname"].Value.ToString();
            teaModelToBeUpdated.Birthday = this.dataGridView2.CurrentRow.Cells["birthday"].Value.ToString();
            teaModelToBeUpdated.Gender = this.dataGridView2.CurrentRow.Cells["tgender"].Value.ToString()=="男"?1:0;
            teaModelToBeUpdated.Phone = this.dataGridView2.CurrentRow.Cells["phone"].Value.ToString();

            int result = teaBusiness.updateteacher(teaModelToBeUpdated);
            if (result != 0)
            {
                MessageBox.Show("更新成功");
            }
            else
            {
                MessageBox.Show("更新失败");
            }
        }
Beispiel #18
0
        public bool UpdateTea(TeacherModel objTeacherModel)
        {
            TeacherDAl objTeacherDAL = new TeacherDAl();

                return (objTeacherDAL.UpdateTea(objTeacherModel));
        }
Beispiel #19
0
 public DataTable SearchTea(TeacherModel objTeacherModel)
 {
     TeacherDAl objTeacherDAl=new TeacherDAl();
          return(objTeacherDAl.SearchTea(objTeacherModel));
 }
 public int update(TeacherModel teaModel)
 {
     MySqlConnection conn = GetConn.getConn();
     try
     {
         conn.Open();
         MySqlCommand cmd = new MySqlCommand("update `tb_teacher` set `tname`=@tname, `gender`=@gender, `birthday`=@birthday, `phone`=@phone where `tid`=@tid", conn);
         cmd.Parameters.AddWithValue("@tname", teaModel.Tname);
         cmd.Parameters.AddWithValue("@gender", teaModel.Gender);
         cmd.Parameters.AddWithValue("@birthday", teaModel.Birthday);
         cmd.Parameters.AddWithValue("@phone", teaModel.Phone);
         cmd.Parameters.AddWithValue("@tid", teaModel.Tid);
         int result = cmd.ExecuteNonQuery();
         cmd.Dispose();
         return result;
     }
     catch (Exception)
     {
         conn.Close();
         return 0;
     }
 }
 public int updateteacher(TeacherModel teaModel)
 {
     return new TeacherService().update(teaModel);
 }
Beispiel #22
0
        public bool AddTeacher(TeacherModel objTeacherModel)
        {
            TeacherDAl objTeacherDAL = new TeacherDAl();

                return (objTeacherDAL.AddTeacher(objTeacherModel));
        }