Beispiel #1
0
        private void btn_del_Click(object sender, EventArgs e)
        {
            int key = int.Parse(this.txt_id.Text);

            using (CatBaseEntities context = new CatBaseEntities())
            {
                cat mew_cat = context.cats.FirstOrDefault(input => input.catID == key);

                context.cats.Remove(mew_cat);
                context.SaveChanges();
                loadgrid();
            }
        }
Beispiel #2
0
        private void btn_edit_Click(object sender, EventArgs e)
        {
            int key = int.Parse(this.txt_id.Text);

            using (CatBaseEntities context = new CatBaseEntities())
            {
                cat mew_cat = context.cats.FirstOrDefault(input => input.catID == key);

                mew_cat.catName = this.txt_name.Text;
                mew_cat.catAge  = int.Parse(this.txt_id.Text);
                mew_cat.ownerID = 1;

                context.SaveChanges();
                loadgrid();
            }
        }
Beispiel #3
0
 private void btn_create_Click(object sender, EventArgs e)
 {
     using (CatBaseEntities context = new CatBaseEntities())
     {
         int nextID  = context.cats.Last().catID;
         cat mew_cat = new cat
         {
             catID   = nextID,
             catName = this.txt_name.Text,
             catAge  = int.Parse(this.txt_age.Text),
             ownerID = 1
         };
         context.cats.Add(mew_cat);
         context.SaveChanges();
         loadgrid();
     }
 }
Beispiel #4
0
        private void loadgrid()
        {
            CatBaseEntities context = new CatBaseEntities();

            catgrid.DataSource = context.cats.ToList();
        }
Beispiel #5
0
        private void Form1_Load(object sender, EventArgs e)
        {
            CatBaseEntities context = new CatBaseEntities();

            catgrid.DataSource = context.cats.ToList();
        }