コード例 #1
0
        private void Load_Event()
        {
            TimeKeeperEntities db = new TimeKeeperEntities();             // create connection to your database

            this.dataList.DataSource            = db.List_Event.ToList(); // get the list of students from database, then assign to DataSource of data grid view
            this.dataList.Columns["id"].Visible = false;                  // hide the id column
        }
コード例 #2
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");
        }
コード例 #3
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");
     }
 }
コード例 #4
0
 public FormEdit(int id)
 {
     InitializeComponent();
     db = new TimeKeeperEntities();
     le = db.List_Event.Single(ls => ls.Id == id);
 }