Beispiel #1
0
 private void btnSave_Click(object sender, EventArgs e)
 {
     using (var db = new XLYJEntities())
     {
         if (txtCode.Tag != null)
         {
             int id  = int.Parse(txtCode.Tag.ToString());
             var stu = db.X_Student.FirstOrDefault(p => p.ID == id);
             SetStuInfoEntity(stu);
             stu.ModifyPerson = "admin";
             stu.ModifyTime   = DateTime.Now;
             db.SaveChanges();
         }
         else
         {
             X_Student stu = new X_Student();
             SetStuInfoEntity(stu);
             stu.CreatePerson = "admin";
             stu.CreateTime   = DateTime.Now;
             db.X_Student.Add(stu);
             db.SaveChanges();
         }
         this.DialogResult = DialogResult.Yes;
     }
 }
Beispiel #2
0
 private void btnDel_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
 {
     if (this.gridView.RowCount > 0)
     {
         DialogResult dialogResult = XtraMessageBox.Show("确定删除吗?", "系统提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
         if (dialogResult == DialogResult.Yes)
         {
             int _id = ((X_Student)this.gridView.GetRow(this.gridView.FocusedRowHandle)).ID;
             using (var dataContext = new XLYJEntities())
             {
                 X_Student stu = dataContext.X_Student.SingleOrDefault((X_Student p) => p.ID == _id);
                 if (null != stu)
                 {
                     dataContext.X_Student.Remove(stu);
                 }
                 dataContext.SaveChanges();
                 this.BindStuInfoes();
             }
         }
     }
 }