コード例 #1
0
        private void barButtonItem3_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (DataGrid.SelectedRowsCount == 0)
            {
                XtraMessageBox.Show("请选择要编辑的学生!");
                return;
            }
            var addForm = new StudentAdd((Student)DataGrid.GetRow(DataGrid.GetSelectedRows()[0]))
            {
                StartPosition = FormStartPosition.CenterParent
            };

            if (addForm.ShowDialog() == DialogResult.OK)
            {
                using (DataProvider dp = new DataProvider())
                {
                    Student entity = dp.Student.FirstOrDefault(m => m.Id == addForm.student.Id);
                    entity.StuNo = addForm.student.StuNo;
                    entity.Name  = addForm.student.Name;
                    dp.SaveChanges();
                }
                addForm.Dispose();
                GridLoadData();
            }
        }
コード例 #2
0
        private void barButtonItem1_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            var addForm = new StudentAdd
            {
                StartPosition = FormStartPosition.CenterParent
            };

            if (addForm.ShowDialog() == DialogResult.OK)
            {
                var stu = addForm.student;
                stu.Id = Guid.NewGuid().ToString();
                using (DataProvider dp = new DataProvider())
                {
                    dp.Student.Add(addForm.student);
                    dp.SaveChanges();
                }
            }
            addForm.Dispose();
            GridLoadData();
        }