public bool AddStudent(Student student)
 {
     entities.Students.AddObject(student);
     if (entities.SaveChanges() > 0)
         return true;
     return false;
 }
Esempio 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>
 /// 复制
 /// </summary>
 public void Clone(Student entity)
 {
     this.StudentID = entity.StudentID;
         this.SClassID = entity.SClassID;
         this.Grade = entity.Grade;
 }
 /// <summary>
 /// 用于向 Students EntitySet 添加新对象的方法,已弃用。请考虑改用关联的 ObjectSet&lt;T&gt; 属性的 .Add 方法。
 /// </summary>
 public void AddToStudents(Student student)
 {
     base.AddObject("Students", student);
 }
 /// <summary>
 /// 创建新的 Student 对象。
 /// </summary>
 /// <param name="studentID">StudentID 属性的初始值。</param>
 /// <param name="sClassID">SClassID 属性的初始值。</param>
 public static Student CreateStudent(global::System.Int32 studentID, global::System.Int32 sClassID)
 {
     Student student = new Student();
     student.StudentID = studentID;
     student.SClassID = sClassID;
     return student;
 }