示例#1
0
        void ListStudent_Load(object sender, EventArgs e)
        {
            OOPCSEntities  db   = new OOPCSEntities();
            List <Student> item = db.Students.ToList();

            this.grdStudents.DataSource = item;
        }
        public PM20553 GetStudent(int id)
        {
            var db     = new OOPCSEntities();
            var result = db.PM20553.Find(id);

            db.Dispose();
            return(result);
        }
        public PM20553[] GetStudents()
        {
            var db     = new OOPCSEntities();
            var result = db.PM20553.ToArray();

            db.Dispose();
            return(result);
        }
        public void DeleteStudent(int id)
        {
            var     db      = new OOPCSEntities();
            PM20553 student = db.PM20553.Find(id);

            db.PM20553.Remove(student);
            db.SaveChanges();
            db.Dispose();
        }
        public void UpdateStudent(int id, string code, string name, bool gender, string hometown)
        {
            var     db      = new OOPCSEntities();
            PM20553 student = db.PM20553.Find(id);

            student.Code            = code;
            student.Name            = name;
            student.Gender          = gender;
            student.Hometown        = hometown;
            db.Entry(student).State = System.Data.Entity.EntityState.Modified;
            db.SaveChanges();
            db.Dispose();
        }
        public void CreateStudent(string name, string code, bool gender, string hometown)
        {
            var     db      = new OOPCSEntities();
            PM20553 student = new PM20553();

            student.Code     = code;
            student.Name     = name;
            student.Gender   = gender;
            student.Hometown = hometown;

            db.PM20553.Add(student);
            db.SaveChanges();
            db.Dispose();
        }
示例#7
0
        private void BtnSave_Click(object sender, EventArgs e)
        {
            Student student = new Student();

            student.code     = txtCode.Text;
            student.name     = txtName.Text;
            student.birthday = dtpBirthDay.Value;
            student.hometown = txtHomeTown.Text;

            OOPCSEntities db = new OOPCSEntities();

            db.Students.Add(student);
            db.SaveChanges();
            this.Close();
        }
示例#8
0
 private void BtnDelete_Click(object sender, EventArgs e)
 {
     if (this.grdStudents.SelectedRows.Count == 1)
     {
         DataGridViewRow row  = grdStudents.SelectedRows[0];
         Student         item = (Student)row.DataBoundItem;
         try
         {
             OOPCSEntities db      = new OOPCSEntities();
             Student       student = db.Students.Find(item.id);
             db.Students.Remove(student);
             db.SaveChanges();
             this.ListStudent_Load(null, null);
         }
         catch (Exception error)
         {
             MessageBox.Show(error.Message);
         }
     }
 }