Esempio n. 1
0
 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();
             }
         }
     }
 }