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; } }
private void btnInfo_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { if (this.gridView.RowCount > 0) { X_Student stu = this.gridView.GetFocusedRow() as X_Student; using (FrmSingleStuInformation frm = new FrmSingleStuInformation(stu.ID)) { frm.ShowDialog(); } } }
public void SetStuInfoEntity(X_Student StuInfo) { StuInfo.Code = txtCode.Text.Trim(); StuInfo.Name = txtName.Text.Trim(); StuInfo.Sex = rdoSex.SelectedIndex == 0 ? "男" : "女"; StuInfo.Birthday = dtBirthday.DateTime.Date; StuInfo.Age = txtAge.Text.Trim() == "" ? 0 : int.Parse(txtAge.Text.Trim()); StuInfo.Phone = txtPhone.Text.Trim(); StuInfo.QQ = txtQQ.Text.Trim(); StuInfo.Address = txtAddress.Text; StuInfo.WeChat = txtWeChat.Text; StuInfo.Career = txtCareer.Text; StuInfo.Remark = txtRemark.Text; }
public void GetStuInfoEntity(X_Student StuInfo) { txtCode.Tag = StuInfo.ID; txtCode.Text = StuInfo.Code; txtName.Text = StuInfo.Name; rdoSex.SelectedIndex = StuInfo.Sex == "男" ? 0 : 1; dtBirthday.DateTime = (DateTime)StuInfo.Birthday; txtPhone.Text = StuInfo.Phone; txtAge.Text = StuInfo.Age.ToString(); txtQQ.Text = StuInfo.QQ; txtAddress.Text = StuInfo.Address; txtWeChat.Text = StuInfo.WeChat; txtCareer.Text = StuInfo.Career; txtRemark.Text = StuInfo.Remark; }
private void btnUpdate_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { if (this.gridView.RowCount > 0) { X_Student stu = this.gridView.GetFocusedRow() as X_Student; using (FrmSingleStuInfo frmSingleProduct = new FrmSingleStuInfo(stu)) { DialogResult dialogResult = frmSingleProduct.ShowDialog(); if (dialogResult == DialogResult.Yes) { this.BindStuInfoes(); } } } }
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(); } } } }
public FrmSingleStuInfo(X_Student StuInfo) : this() { _StuInfo = StuInfo; }