private void EditDream_Load(object sender, EventArgs e) { DreamDBEntities1 db = new DreamDBEntities1(); txtName.Text = DreamList.Name; txtTarget.Text = DreamList.Target; txtSplit.Text = Convert.ToString(DreamList.Splitphase); dTPDateCrt.Value = DreamList.DateCreated.Value; dTPDateEx.Value = DreamList.DateExpired; }
private void btnbtnSave_Click(object sender, EventArgs e) { try { int spt = int.Parse(txtSplit.Text); var db = new DreamDBEntities1(); DreamList editDream = db.DreamLists.Find(DreamList.idDream); editDream.Name = txtName.Text; editDream.Target = txtTarget.Text; editDream.Splitphase = spt; editDream.DateCreated = dTPDateCrt.Value.Date; editDream.DateExpired = dTPDateEx.Value.Date; db.Entry(editDream).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); this.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void btnbtnAdd_Click(object sender, EventArgs e) { int sptphase = int.Parse(txtSplit.Text); DreamList addnew = new DreamList(); addnew.Name = txtName.Text; addnew.Target = txtTarget.Text; addnew.Splitphase = sptphase; addnew.DateCreated = dateTPBegin.Value; addnew.DateExpired = dateTPExpired.Value; try { var db = new DreamDBEntities1(); db.DreamLists.Add(addnew); db.SaveChanges(); } catch (Exception ex) { MessageBox.Show(ex.Message); } this.Close(); }