Ejemplo n.º 1
0
 public bool AddTeacher(Teacher teacher)
 {
     entities.Teachers.AddObject(teacher);
     if (entities.SaveChanges() > 0)
         return true;
     return false;
 }
Ejemplo n.º 2
0
        public bool AddUser(User user,Student student,Teacher teacher)
        {
            if(student!=null)
            entities.Students.AddObject(student);

            if(teacher !=null)
                entities.Teachers.AddObject(teacher);

            entities.Users.AddObject(user);
            if (entities.SaveChanges() > 0)
                return true;
            return false;
        }
        private void btnLogin_Click(object sender, RoutedEventArgs e)
        {
            UserBLL bll = new UserBLL();
            try
            {
                User itemUser = new User();
                Student itemStudent = null;
                Teacher itemTeacher = null;

                if (radStudent.IsChecked.Value)
                {
                    itemStudent = new Student();
                    itemStudent.SClassID = Convert.ToInt32(this.cboData.SelectedValue);
                    itemUser.UserRole = (int)ClassRoom.Enum.UserRoleTypeEnum.Student;
                    itemUser.Student = itemStudent;
                }

                if (radTeacher.IsChecked.Value)
                {
                    itemTeacher = new Teacher();
                    itemTeacher.CourseID = Convert.ToInt32(this.cboData.SelectedValue);
                    itemUser.UserRole = (int)ClassRoom.Enum.UserRoleTypeEnum.Teacher;
                    itemUser.Teacher = itemTeacher;
                    //TeacherBLL.AddTeacher(itemTeacher);
                }

                itemUser.Sex = this.radioButton1.IsChecked;
                itemUser.Realname = this.tbRealName.Text;
                itemUser.Email = this.tbEmail.Text;
                itemUser.Password = this.tbPassword.Text;

                bool result = bll.AddUser(itemUser, itemStudent, itemTeacher);

                if (result)
                {
                    MessageBox.Show("保存成功!");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.InnerException.ToString());
            }
        }
 /// <summary>
 /// 用于向 Teachers EntitySet 添加新对象的方法,已弃用。请考虑改用关联的 ObjectSet&lt;T&gt; 属性的 .Add 方法。
 /// </summary>
 public void AddToTeachers(Teacher teacher)
 {
     base.AddObject("Teachers", teacher);
 }
 /// <summary>
 /// 创建新的 Teacher 对象。
 /// </summary>
 /// <param name="teacherID">TeacherID 属性的初始值。</param>
 /// <param name="courseID">CourseID 属性的初始值。</param>
 public static Teacher CreateTeacher(global::System.Int32 teacherID, global::System.Int32 courseID)
 {
     Teacher teacher = new Teacher();
     teacher.TeacherID = teacherID;
     teacher.CourseID = courseID;
     return teacher;
 }