コード例 #1
0
ファイル: EmpMegrForm.cs プロジェクト: ronggangfan/hai
 protected override void Sav()
 {
     base.Sav();
     if (this.IsChecked)
     {
         using (db = new haiEntities())
         {
             if (this.Curd == ECurdOption.U)
             {
                 employees emp = new employees();
                 emp.id      = Guid.Parse(Dgvr.Cells["id"].Value.ToString());
                 emp.name    = this.nameTB.Text;
                 emp.phone   = this.phoneTB.Text;
                 emp.address = this.addressTB.Text;
                 emp.parid   = Guid.Parse(this.parCBB.SelectedValue.ToString());
                 emp.sex     = this.sexCBB.Text;
                 db.employees.Attach(emp);
                 db.Entry(emp).State = System.Data.Entity.EntityState.Modified;
                 db.SaveChanges();
                 this.ParForm.DoRefresh();
                 this.Close();
             }
             else
             {
                 employees emp = new employees();
                 emp.id      = Guid.NewGuid();
                 emp.name    = this.nameTB.Text;
                 emp.phone   = this.phoneTB.Text;
                 emp.address = this.addressTB.Text;
                 emp.parid   = Guid.Parse(this.parCBB.SelectedValue.ToString());
                 emp.sex     = this.sexCBB.Text;
                 db.employees.Add(emp);
                 db.SaveChanges();
                 MessageBox.Show("操作成功");
                 this.ParForm.DoRefresh();
                 FormClear();
             }
         }
     }
 }