Example #1
0
        private void btnDelete_Click(object sender, EventArgs e)
        {
            var db = new Note1Entities();

            for (int i = 0; i < this.listView.SelectedRows.Count; i++)
            {
                var row  = this.listView.SelectedRows[i];
                var item = (Note)row.DataBoundItem;
                try
                {
                    DialogResult = MessageBox.Show("Bạn có muốn xoá?", "Thông báo", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
                    if (DialogResult == DialogResult.OK)
                    {
                        var @note = db.Note.Find(item.id);
                        db.Note.Remove(@note);
                        db.SaveChanges(); // Do-It
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
            this.ShowNoteList();
        }
Example #2
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            var  db      = new Note1Entities();
            Note newNote = db.Note.Find(this.note.id);

            try
            {
                newNote.title           = this.txtTitle.Text;
                newNote.content         = this.txtContext.Text;
                db.Entry(newNote).State = System.Data.Entity.EntityState.Modified;
                db.SaveChanges(); // Do-It
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            this.Close();
        }
Example #3
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            Note @note = new Note();

            note.title   = txtTitle.Text;
            note.content = txtContext.Text;
            try
            {
                var db = new Note1Entities();
                db.Note.Add(@note);
                db.SaveChanges(); // Do-It
                this.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }