Esempio n. 1
0
 private void btn_lkaddtocoln_Click(object sender, EventArgs e)
 {
     if (this.dgv_like.CurrentRow != null)
     {
         try
         {
             RecipeID = (int)this.dgv_like.CurrentRow.Cells["食譜編號"].Value;
             Collection_Table table = new Collection_Table()
             {
                 CollectionFolderID = dbcontext.CollectionFolder_Table.Where(c => c.CollectionFolder == "我的最愛" && c.MemberID == memberData.MemberID).Select(s => s.CollectionFolderID).ToList()[0],
                 ReicipeID          = RecipeID,
                 Datetime           = DateTime.Now
             };
             dbcontext.Collection_Table.Add(table);
             dbcontext.SaveChanges();
             MessageBox.Show("收藏成功");
             btn_lkaddtocoln.Enabled = false;
             LoadRecipe();
         }
         catch (Exception)
         {
             MessageBox.Show("收藏失敗");
         }
     }
     else
     {
         return;
     }
 }
Esempio n. 2
0
        private void Cb_FolderCurrentChanged(object sender, EventArgs e)
        {
            CheckBox cb = sender as CheckBox;

            if (!cb.Checked)
            {
                //刪除
                Collection_Table table = dbcontext.Collection_Table.AsEnumerable().First(c => c.ReicipeID == Recipeid && c.CollectionFolder_Table.CollectionFolder == cb.Name && c.CollectionFolder_Table.MemberID == memberData.MemberID);
                dbcontext.Collection_Table.Remove(table);
                try
                {
                    dbcontext.SaveChanges();
                }
                catch (Exception)
                {
                    MessageBox.Show("發生錯誤");
                }
            }
            else
            {
                //新增
                var table = new Collection_Table()
                {
                    CollectionFolderID = dbcontext.CollectionFolder_Table.FirstOrDefault(c => c.CollectionFolder == cb.Name && c.MemberID == memberData.MemberID).CollectionFolderID,
                    ReicipeID          = Recipeid,
                    Datetime           = DateTime.Now
                };
                dbcontext.Collection_Table.Add(table);
                try
                {
                    dbcontext.SaveChanges();
                }
                catch (Exception)
                {
                    MessageBox.Show("修改失敗");
                }
            }
            LoadRecipe();
        }