Пример #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            DateTime dt =
                DateTime.ParseExact(this.textBoxDate2.Text, "dd/MM/yyyy hh:mm tt", CultureInfo.InvariantCulture);

            TimeKeeperEntities db = new TimeKeeperEntities();
            List_Event         ls = new List_Event();

            ls.Name = this.textBoxName.Text;
            ls.Time = dt;

            ls.Place       = this.textBoxPlace.Text;
            ls.Description = this.textBoxDes.Text;
            db.List_Event.Add(ls);
            db.SaveChanges();
            this.Close();
            MessageBox.Show("Add successfully");
        }
Пример #2
0
 private void btnDelete_Click(object sender, EventArgs e)
 {
     if (dataList.SelectedRows.Count == 1)
     {
         var row  = dataList.SelectedRows[0];
         var cell = row.Cells["Id"];
         int id   = (int)cell.Value;
         TimeKeeperEntities db = new TimeKeeperEntities();
         List_Event         ls = db.List_Event.Single(le => le.Id == id);
         db.List_Event.Remove(ls);
         db.SaveChanges();
         MessageBox.Show("Delete sucessfully");
         Load_Event();
     }
     else
     {
         MessageBox.Show("You should a row");
     }
 }