Exemplo n.º 1
0
 private void button3_Click(object sender, EventArgs e)
 {
     AdHTML = htmlEditorControl1.InnerHtml;
     //using (EditHtmlForm dialog = new EditHtmlForm())
     //{
     //    dialog.HTML = this.DocumentHtml;
     //    dialog.ReadOnly = true;
     //    dialog.SetCaption(HTML_TITLE_VIEW);
     //    DefineDialogProperties(dialog);
     //    dialog.ShowDialog(this.ParentForm);
     //}
     //寫進資料庫
     using (SmartShoppingEntities db = new SmartShoppingEntities())
     {
         //新增
         if (NewAd)
         {
             Promotions promotion = new Promotions();
             promotion.AdHtml          = AdHTML;
             promotion.PromotionName   = this.textBoxTitle.Text;
             db.Entry(promotion).State = EntityState.Added;
         }
         else
         {
             //修改
             Promotions promotion = db.Promotions.Find(AdID);
             promotion.AdHtml          = AdHTML;
             promotion.PromotionName   = this.textBoxTitle.Text;
             db.Entry(promotion).State = EntityState.Modified;
         }
         try
         {
             db.SaveChanges();
         }
         catch (Exception ex)
         {
             Console.WriteLine(ex.ToString());
         }
     }
     LoadAdLabel();
     MessageBox.Show("儲存成功");
 }
Exemplo n.º 2
0
        private void FromOrderToSmart()
        {
            using (SmartShoppingEntities db = new SmartShoppingEntities())
            {
                db.Database.ExecuteSqlCommand("TRUNCATE TABLE [RoleSmart]");

                var q = from r in db.View_RoleXProduct
                        select r;//只從新增的開始讀?上次讀到幾要存起來
                foreach (var item in q.ToList())
                {
                    //檢查RoleSmart資料表是否有此Role X Product的紀錄
                    var qry = (from P in db.RoleSmart
                               where P.RoleID == item.Roles_ID && P.ProductID == item.Product_ID
                               select P).FirstOrDefault();
                    if (qry == null)
                    {
                        //新增程式代碼記錄
                        var NewRS = new RoleSmart();
                        NewRS.RoleID         = item.Roles_ID;
                        NewRS.ProductID      = item.Product_ID;
                        NewRS.TimesPurchased = 1;
                        NewRS.OrderBilling   = item.Amount;


                        //加入程式代碼
                        db.Entry(NewRS).State = EntityState.Added;
                        db.SaveChanges();
                    }
                    else
                    {
                        RoleSmart rs = db.RoleSmart.Find(item.Roles_ID, item.Product_ID);
                        rs.TimesPurchased += 1;
                        rs.OrderBilling   += item.Amount;
                        db.Entry(rs).State = EntityState.Modified;
                        db.SaveChanges();
                    }
                }
            }
        }