public List<EventPromoAdditionalPriceProductQuery> GetList(EventPromoAdditionalPriceProductQuery model)
 {
     try
     {
         return dao.GetList(model);
     }
     catch (Exception ex)
     {
         throw new Exception("EventPromoAdditionalPriceProductMgr-->GetList-->" + ex.Message, ex);
     }
 }
 public List<EventPromoAdditionalPriceProductQuery> GetList(EventPromoAdditionalPriceProductQuery query)
 {
     StringBuilder sql = new StringBuilder();
     try
     {
         sql.AppendFormat("select ep.row_id,ep.group_id,ep.product_id,ep.add_price,eg.group_name,p.product_name  from event_promo_additional_price_product ep left join event_promo_additional_price_group eg on ep.group_id=eg.group_id");
         sql.AppendFormat(" left join product p on ep.product_id=p.product_id");
         sql.AppendFormat(" where ep.group_id={0}",query.group_id);
         return access.getDataTableForObj<EventPromoAdditionalPriceProductQuery>(sql.ToString());
     }
     catch (Exception ex)
     {
         throw new Exception("EventPromoAdditionalPriceProductDao-->GetList-->" + ex.Message + sql.ToString(), ex);
     }
 }
       //保存活動
       public bool SaveEventPromoAdditionalPrice(EventPromoAdditionalPrice model, List<EventPromoAdditionalPriceProduct> models, string condiType)
       {
           ArrayList _list = new ArrayList();
           MySqlCommand mySqlCmd = new MySqlCommand();
           MySqlConnection mySqlConn = new MySqlConnection(conn);
           try
           {
               if (mySqlConn != null && mySqlConn.State == System.Data.ConnectionState.Closed)
               {
                   mySqlConn.Open();
               }
               mySqlCmd.Connection = mySqlConn;
               mySqlCmd.Transaction = mySqlConn.BeginTransaction();
               mySqlCmd.CommandType = System.Data.CommandType.Text;
               if (model.row_id == 0)//新增
               {                          
                   model.event_type = "AD";
                   model.create_user = (System.Web.HttpContext.Current.Session["caller"] as Caller).user_id;
                   model.create_time = DateTime.Now;
                   mySqlCmd.CommandText = dao.AddOrUpdate(model);
                   model.row_id =Convert.ToInt32(mySqlCmd.ExecuteScalar());
                   model.modify_user = model.create_user;
                   model.modify_time = model.create_time;
                   model.event_id = Common.CommonFunction.GetEventId(model.event_type, model.row_id.ToString());
                   _list.Add(dao.AddOrUpdate(model));

                   //處理輔表
                   EventPromoAdditionalPriceProductDao _epgDao = new EventPromoAdditionalPriceProductDao(conn);
                   foreach (EventPromoAdditionalPriceProduct item in models)
                   {
                       item.group_id = model.group_id;
                       item.create_user = model.create_user;
                       item.create_time = model.create_time;
                       item.modify_user = item.create_user;
                       item.modify_time = item.create_time;
                       _list.Add(_epgDao.AddOrUpdate(item));
                   }

                   //處理輔表活動商品設定
                   _list.AddRange(InsertCondiType(model, condiType));
               }
               else//編輯 
               {
                   model.event_type = "AD";
                   model.modify_user = (System.Web.HttpContext.Current.Session["caller"] as Caller).user_id;
                   model.modify_time = DateTime.Now;
                   model.event_id = Common.CommonFunction.GetEventId(model.event_type, model.row_id.ToString());
                   _list.Add(dao.AddOrUpdate(model));

                   EventPromoAdditionalPriceProductDao _epdDao = new EventPromoAdditionalPriceProductDao(conn);
                   string row_ids = "";
                   foreach (EventPromoAdditionalPriceProduct item in models)
                   {
                       item.modify_user = model.modify_user;
                       item.modify_time = model.modify_time;

                       _list.Add(_epdDao.AddOrUpdate(item));
                       if (item.row_id != 0)
                       {
                           row_ids = row_ids + item.row_id + ",";
                       }
                   }

                   row_ids = row_ids.TrimEnd(',');
                   var row_id = row_ids.Split(',');
                   EventPromoAdditionalPriceProductQuery product = new EventPromoAdditionalPriceProductQuery();
                   product.group_id = model.group_id;
                   List<EventPromoAdditionalPriceProductQuery> product_models = _epdDao.GetList(product);
                   string del_row_ids = string.Empty;//存放本次刪除的
                   foreach (EventPromoAdditionalPriceProduct item in product_models)
                   {
                       if (!row_id.Contains(item.row_id.ToString()))
                       {
                           del_row_ids = del_row_ids + item.row_id.ToString() + ",";
                       }
                   }
                   if (!string.IsNullOrEmpty(del_row_ids))
                   {
                       del_row_ids = del_row_ids.TrimEnd(',');
                       _list.Add(_epdDao.Delete(model.group_id.ToString(), del_row_ids));
                   }


                   //處理輔表活動商品設定
                   EventPromoBrandDao _epbDao = new EventPromoBrandDao(conn);
                   _list.Add(_epbDao.Delete(model.event_id));
                   EventPromoCategoryDao _epcateDao = new EventPromoCategoryDao(conn);
                   _list.Add(_epcateDao.Delete(model.event_id));
                   EventPromoClassDao _epclassDao = new EventPromoClassDao(conn);
                   _list.Add(_epclassDao.Delete(model.event_id));
                   EventPromoPaymentDao _eppayDao = new EventPromoPaymentDao(conn);
                   _list.Add(_eppayDao.Delete(model.event_id));
                   EventPromoShoppingcartDao _epcartDao = new EventPromoShoppingcartDao(conn);
                   _list.Add(_epcartDao.Delete(model.event_id));
                   EventPromoProductDao _epproDao = new EventPromoProductDao(conn);
                   _list.Add(_epproDao.Delete(model.event_id));

                   _list.AddRange(InsertCondiType(model, condiType));

               }

               for (int i = 0; i < _list.Count; i++)
               {
                   mySqlCmd.CommandText = _list[i].ToString();
                   mySqlCmd.ExecuteNonQuery();
               }
               mySqlCmd.Transaction.Commit();
               return true;

           }
           catch (Exception ex)
           {
               mySqlCmd.Transaction.Rollback();
               return false;
               throw new Exception("EventPromoAdditionalPriceMgr-->SaveEventPromoAdditionalPrice" + ex.Message, ex);
           }
           finally
           {
               if (mySqlConn != null && mySqlConn.State == System.Data.ConnectionState.Open)
               {
                   mySqlConn.Close();
               }
           }
       }
Ejemplo n.º 4
0
        public HttpResponseBase GetEventPromoAdditionalPriceProduct()
        {
            string jsonStr = "{success:false}";
            try
            {
                EventPromoAdditionalPriceProductQuery query = new EventPromoAdditionalPriceProductQuery();
                query.Start = Convert.ToInt32(Request.Params["start"] ?? "0");
                query.Limit = Convert.ToInt32(Request.Params["limit"] ?? "25");

                if (!string.IsNullOrEmpty(Request.Params["group_id"]))
                {
                    query.group_id = int.Parse(Request.Params["group_id"]);
                }
                int totalCount = 0;
                epappMgr = new EventPromoAdditionalPriceProductMgr(mySqlConnectionString);
                List<EventPromoAdditionalPriceProductQuery> _list = epappMgr.GetList(query);

                IsoDateTimeConverter timeConverter = new IsoDateTimeConverter();
                //这里使用自定义日期格式,如果不使用的话,默认是ISO8601格式     
                timeConverter.DateTimeFormat = "yyyy-MM-dd HH:mm:ss";
                jsonStr = "{success:true,totalCount:" + totalCount + ",item:" + JsonConvert.SerializeObject(_list, Formatting.Indented, timeConverter) + "}";//返回json數據
            }
            catch (Exception ex)
            {
                Log4NetCustom.LogMessage logMessage = new Log4NetCustom.LogMessage();
                logMessage.Content = string.Format("TargetSite:{0},Source:{1},Message:{2}", ex.TargetSite.Name, ex.Source, ex.Message);
                logMessage.MethodName = System.Reflection.MethodBase.GetCurrentMethod().Name;
                log.Error(logMessage);
            }
            this.Response.Clear();
            this.Response.Write(jsonStr.ToString());
            this.Response.End();
            return this.Response;
        }