public DataTable Query(ProdPromo query) { StringBuilder sql = new StringBuilder(); sql.AppendFormat("select product_id, event_id,event_type,event_desc,start,end,page_url,user_specified,kuser,kdate,muser,mdate,status from prod_promo "); sql.AppendFormat("where status = 1 and event_id='{0}' and product_id='{1}';", query.event_id, query.product_id); return _access.getDataTable(sql.ToString()); }
public List<ProdPromo> Select(ProdPromo query, out int totalCount) { StringBuilder sql = new StringBuilder(); sql.AppendFormat("select product_id, event_id,event_type,event_desc,start,end,page_url,user_specified,kuser,kdate,muser,mdate,status from prod_promo "); sql.AppendFormat("where status = 1 and 1=1;"); totalCount = 0; return _access.getDataTableForObj<ProdPromo>(sql.ToString()); }
/// <summary> /// 新增促銷活動時使用 /// </summary> /// <param name="model"></param> /// <returns></returns> public string SaveProdProm(ProdPromo model) { model.Replace4MySQL(); StringBuilder sbSql = new StringBuilder(); sbSql.Append(@" insert into prod_promo ("); sbSql.Append(" product_id, event_id,event_type,event_desc,start,end,page_url,user_specified,kuser,kdate,muser,mdate,status) "); sbSql.AppendFormat(" values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}');", model.product_id, model.event_id, model.event_type, model.event_desc, CommonFunction.DateTimeToString(model.start), Common.CommonFunction.DateTimeToString(model.end), model.page_url, model.user_specified, model.kuser, Common.CommonFunction.DateTimeToString(model.kdate), model.muser, Common.CommonFunction.DateTimeToString(model.mdate), model.status); return sbSql.ToString(); }
public int Update(ProdPromo model) { model.Replace4MySQL(); StringBuilder sbSql = new StringBuilder(); sbSql.Append("set sql_safe_updates = 0; "); sbSql.Append("update prod_promo set "); sbSql.AppendFormat(" product_id='{0}', event_type='{1}',event_desc='{2}',start='{3}',end='{4}', ", model.product_id, model.event_type, model.event_desc, CommonFunction.DateTimeToString(model.start), Common.CommonFunction.DateTimeToString(model.end)); sbSql.AppendFormat(" page_url='{0}',user_specified='{1}',muser='******',mdate='{3}',status='{4}'", model.page_url, model.user_specified, model.muser, Common.CommonFunction.DateTimeToString(model.mdate), model.status); sbSql.AppendFormat(" where event_id='{0}';", model.event_id); sbSql.Append("set sql_safe_updates = 1;"); return _access.execCommand(sbSql.ToString()); }
public int UpdateUrl(ProdPromo store) { try { return _cateDao.UpdateUrl(store); } catch (Exception ex) { throw new Exception("ProductCategoryMgr-->UpdateUrl->" + ex.Message, ex); } }
public List<ProdPromoQuery> GetList(ProdPromo store, out int totalCount) { try { return _cateDao.GetList(store,out totalCount); } catch (Exception ex) { throw new Exception("ProductCategoryMgr-->GetList->" + ex.Message, ex); } }
/// <summary> /// 移除幾件幾元或幾件幾折 /// </summary> /// <returns></returns> public HttpResponseBase Deletezhe() { string jsonStr = String.Empty; PromotionsAmountDiscount query = new PromotionsAmountDiscount(); ProductCategory pmodel = new ProductCategory(); ProductCategorySet pmsmodel = new ProductCategorySet(); ProductCategorySet querypcs = new ProductCategorySet(); PromoDiscount querypd = new PromoDiscount(); PromoAll pamodel = new PromoAll(); ProdPromo ppmodel = new ProdPromo(); querypcs.Category_Id = pmodel.category_id; List<ProductCategorySet> smodel = _produCateSetMgr.Query(querypcs); if (!String.IsNullOrEmpty(Request.Params["rowid"])) { try { foreach (string rid in Request.Params["rowid"].ToString().Split('|'))//批次移除 { if (!string.IsNullOrEmpty(rid)) { //刪除peomotion_amount_discount //根據id 獲取整個model query = _promoAmountDiscountMgr.GetModelById(Convert.ToInt32(rid)); var eventid = CommonFunction.GetEventId(query.event_type, query.id.ToString()); if (_promoAmountDiscountMgr.Delete(query, eventid) > 0) { jsonStr = "{success:true}"; } else { jsonStr = "{success:false}"; } } } } 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); jsonStr = "{success:false}"; } } this.Response.Clear(); this.Response.Write(jsonStr); this.Response.End(); return this.Response; }
public string DeleteProdPromByPID(ProdPromo model) { StringBuilder sb = new StringBuilder(); sb.AppendFormat("set sql_safe_updates = 0;delete from prod_promo where event_id='{0}' and status=1 and product_id='{1}' ;set sql_safe_updates = 1;", model.event_id, model.product_id); return sb.ToString(); }
public HttpResponseBase UpdateUrl() { string json = string.Empty; ProdPromo query = new ProdPromo(); _procateMgr = new ProductCategoryMgr(connectionString); if (!string.IsNullOrEmpty(Request.Params["rowID"])) { try { if (!string.IsNullOrEmpty(Request.Params["pageUrl"])) { query.page_url = Request.Params["pageUrl"]; } foreach (string rid in Request.Params["rowID"].ToString().Split('|')) { if (!string.IsNullOrEmpty(rid)) { query.rid = Convert.ToInt32(rid); if (_procateMgr.UpdateUrl(query) >= 0) { json = "{success:true}"; } } } } 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); json = "{success:false}"; } } this.Response.Clear(); this.Response.Write(json); this.Response.End(); return this.Response; }
/// <summary> /// 修改狀態 /// </summary> /// <param name="model"></param> /// <returns></returns> public int UpdateActive(PromotionsAmountFareQuery model) { int i = 0; MySqlCommand mySqlCmd = new MySqlCommand(); MySqlConnection mySqlConn = new MySqlConnection(connStr); StringBuilder sql = new StringBuilder(); 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; sql.Append(_prodPromoDao.DeleteProdProm(model.event_id));//先刪除在新增當active=0時照樣刪除只有active=1時才新增 if (model.active) { ProductCategorySet querySet = new ProductCategorySet(); querySet.Category_Id = Convert.ToUInt32(model.category_id); ProductCategorySetDao _setDao = new ProductCategorySetDao(connStr); List<ProductCategorySet> lmodelSet = _setDao.Query(querySet); foreach (ProductCategorySet item in lmodelSet) { ProdPromo ppmodel = new ProdPromo(); ppmodel.product_id = Convert.ToInt32(item.Product_Id); ppmodel.event_id = model.event_id; ppmodel.event_type = model.event_type; ppmodel.event_desc = model.event_desc; ppmodel.start = model.start; ppmodel.end = model.end; ppmodel.page_url = model.category_link_url; if (model.group_id == 0 && model.condition_id == 0) { ppmodel.user_specified = 0; } else { ppmodel.user_specified = 1; } ppmodel.kuser = model.muser; ppmodel.kdate = model.modified; ppmodel.muser = model.muser; ppmodel.mdate = model.modified; ppmodel.status = model.status; sql.Append(_prodPromoDao.SaveProdProm(ppmodel)); } } if (model.id != 0) { sql.Append(UpdatePromoFare(model)); PromotionsAmountReduce parModel = new PromotionsAmountReduce(); parModel.id = model.id; parModel.name = model.name; parModel.delivery_store = model.delivery_store; parModel.group_id = model.group_id; parModel.type = model.type; parModel.amount = model.amount; parModel.quantity = model.quantity; parModel.start = model.start; parModel.end = model.end; parModel.created = model.created; parModel.updatetime = model.modified; parModel.active = model.active ? 1 : 0; parModel.status = model.status; sql.Append(_promAmountReduceDao.Update(parModel)); } mySqlCmd.CommandText = sql.ToString(); i += mySqlCmd.ExecuteNonQuery(); mySqlCmd.Transaction.Commit(); } catch (Exception ex) { mySqlCmd.Transaction.Rollback(); throw new Exception("PromotionsAmountFareDao-->UpdateActive-->" + ex.Message + sql.ToString(), ex); } finally { if (mySqlConn != null && mySqlConn.State == System.Data.ConnectionState.Open) { mySqlConn.Close(); } } return i; }
public HttpResponseBase GetList() { string json = string.Empty; List<ProdPromoQuery> store = new List<ProdPromoQuery>(); ProdPromo query = new ProdPromo(); int totalCount = 0; try { query.Start = Convert.ToInt32(Request.Params["start"] ?? "0"); query.Limit = Convert.ToInt32(Request.Params["limit"] ?? "25"); if (!string.IsNullOrEmpty(Request.Params["searchcontent"])) { query.SearchContent = Request.Params["searchcontent"].ToString(); } _procateMgr = new ProductCategoryMgr(connectionString); store = _procateMgr.GetList(query, out totalCount); IsoDateTimeConverter timeConverter = new IsoDateTimeConverter(); timeConverter.DateTimeFormat = "yyyy-MM-dd HH:mm:ss"; json = "{success:true,totalCount:" + totalCount + ",data:" + JsonConvert.SerializeObject(store, Formatting.Indented, timeConverter) + "}"; } 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); json = "{success:false,totalCount:0,data:[]}"; } this.Response.Clear(); this.Response.Write(json); this.Response.End(); return this.Response; }
public int UpdateActive(PromoPairQuery store) {//是否啟用 int id = 0; StringBuilder sb = new StringBuilder(); MySqlCommand mySqlCmd = new MySqlCommand(); MySqlConnection mySqlConn = new MySqlConnection(connStr); 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; sb.Append(_prodPromoDao.DeleteProdProm(store.event_id)); if (store.active) { //查詢出商品信息后插入prod_promo表 DataTable dt = _access.getDataTable("SELECT cate_red,cate_green FROM promo_pair WHERE id=" + store.id + ""); DataTable dt_red = _access.getDataTable("SELECT product_id FROM product_category_set WHERE category_id=" + dt.Rows[0]["cate_red"] + " ;"); DataTable dt_green = _access.getDataTable("SELECT product_id FROM product_category_set WHERE category_id=" + dt.Rows[0]["cate_green"] + " ;"); if (dt_red.Rows.Count > 0) { for (int i = 0; i < dt_red.Rows.Count; i++) { ProdPromo ppmodel = new ProdPromo(); ppmodel.product_id = Convert.ToInt32(dt_red.Rows[i][0].ToString()); ppmodel.event_id = store.event_id; ppmodel.event_type = store.event_type; ppmodel.event_desc = store.event_desc; ppmodel.start = store.starts; ppmodel.end = store.end; ppmodel.page_url = store.category_link_url; if (store.group_id == 0 && store.condition_id == 0) ppmodel.user_specified = 0; else ppmodel.user_specified = 1; ppmodel.kuser = store.muser; ppmodel.kdate = store.modified; ppmodel.muser = store.muser; ppmodel.mdate = store.modified; ppmodel.status = store.status; sb.Append(_prodPromoDao.SaveProdProm(ppmodel)); } } if (dt_green.Rows.Count > 0) { for (int i = 0; i < dt_green.Rows.Count; i++) { ProdPromo ppmodel = new ProdPromo(); ppmodel.product_id = Convert.ToInt32(dt_green.Rows[i][0].ToString()); ppmodel.event_id = store.event_id; ppmodel.event_type = store.event_type; ppmodel.event_desc = store.event_desc; ppmodel.start = store.starts; ppmodel.end = store.end; ppmodel.page_url = store.category_link_url; if (store.group_id == 0 && store.condition_id == 0) ppmodel.user_specified = 0; else ppmodel.user_specified = 1; ppmodel.kuser = store.muser; ppmodel.kdate = store.modified; ppmodel.muser = store.muser; ppmodel.mdate = store.modified; ppmodel.status = store.status; sb.Append(_prodPromoDao.SaveProdProm(ppmodel)); } } } sb.AppendFormat("update promo_pair set active ={0},modified='{1}',muser='******' where id={3}", store.active,CommonFunction.DateTimeToString( store.modified),store.muser,store.id); mySqlCmd.CommandText = sb.ToString(); id = Convert.ToInt32(mySqlCmd.ExecuteNonQuery()); mySqlCmd.Transaction.Commit(); } catch (Exception ex) { mySqlCmd.Transaction.Rollback(); throw new Exception("PromoPairDao-->UpdateActive-->" + ex.Message+sb.ToString(), ex); } finally { mySqlConn.Close(); } return id; }
public bool UpdateActive(PromotionsAmountDiscountCustom query) { ArrayList _list = new ArrayList(); try { _list.Add(_prodpromoDao.DeleteProdProm(query.event_id)); if (query.active)//true 為啟用,false為棄用 { List<ProductCategorySet> lmodelSet = _prodCategSet.Query(new ProductCategorySet { Category_Id = query.category_id }); foreach (ProductCategorySet item in lmodelSet) { ProdPromo ppmodel = new ProdPromo(); ppmodel.product_id = Convert.ToInt32(item.Product_Id); ppmodel.event_id = query.event_id; ppmodel.event_type = query.event_type; ppmodel.event_desc = query.event_desc; ppmodel.start = query.start; ppmodel.end = query.end; ppmodel.page_url = query.category_link_url; if (query.group_id != 0 || query.condition_id != 0) { ppmodel.user_specified = 1; } else ppmodel.user_specified = 0; ppmodel.kuser = query.muser; ppmodel.kdate = query.modified; ppmodel.muser = query.muser; ppmodel.mdate = query.modified; ppmodel.status = query.status; _list.Add(_prodpromoDao.SaveProdProm(ppmodel)); } } _list.Add(_padDao.UpdatePromoAmountDisActive(query)); return _mysqlDao.ExcuteSqls(_list); } catch (Exception ex) { throw new Exception("PromotionsAmountDiscountMgr-->UpdateActive-->" + ex.Message, ex); } }
public int UpdateUrl(ProdPromo store) { StringBuilder sql = new StringBuilder(); sql.AppendFormat("update prod_promo set page_url='{0}' where rid={1};", store.page_url, store.rid); try { return _access.execCommand(sql.ToString()); } catch (Exception ex) { throw new Exception("ProductCategoryDao-->UpdateUrl-->" + sql.ToString() + ex.Message, ex); } }
public List<ProdPromoQuery> GetList(ProdPromo store, out int totalCount) { StringBuilder sql = new StringBuilder(); StringBuilder sqlCount = new StringBuilder(); StringBuilder sqlWhere = new StringBuilder(); totalCount = 0; sqlCount.AppendFormat("select count(*) as totalCount from prod_promo pp "); sql.AppendFormat("select pp.rid,pp.product_id,pp.event_id,pp.event_type,pp.event_desc,pp.`start`,pp.`end`,pp.page_url,pp.kdate,pp.`status`,pp.muser,mu.user_username from prod_promo pp LEFT JOIN manage_user mu on pp.muser=mu.user_id "); sqlWhere.AppendFormat(" where 1=1 "); if (!string.IsNullOrEmpty(store.SearchContent)) { sqlWhere.AppendFormat(" and (pp.event_id like '%{0}%' or pp.product_id like '%{1}%' ) ", store.SearchContent, store.SearchContent); } if (store.IsPage) { DataTable _dt = _access.getDataTable(sqlCount.ToString() + sqlWhere.ToString()); if (_dt != null && _dt.Rows.Count > 0) { totalCount = Convert.ToInt32(_dt.Rows[0]["totalCount"]); } } sqlWhere.AppendFormat(" order by rid desc limit {0},{1} ;", store.Start, store.Limit); try { return _access.getDataTableForObj<ProdPromoQuery>(sql.ToString() + sqlWhere.ToString()); } catch (Exception ex) { throw new Exception("ProductCategoryDao-->GetList-->" + sql.ToString() + sqlWhere.ToString() + ex.Message, ex); } }
public int ChangeActive(Model.Query.PromoAdditionalPriceQuery m) {//是否啟用 int r = 0; StringBuilder sb = new StringBuilder(); MySqlCommand mySqlCmd = new MySqlCommand(); MySqlConnection mySqlConn = new MySqlConnection(connStr); 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; sb.Append(_prodPromoDao.DeleteProdProm(m.event_id)); if (m.active) { if (m.event_type != "A1") { // 保存左類別下面的商品 DataTable dt_L = _access.getDataTable("SELECT product_id FROM product_category_set WHERE category_id=" + m.left_category_id + ""); if (dt_L.Rows.Count > 0) { ProdPromo ppmodel = new ProdPromo(); for (int i = 0; i < dt_L.Rows.Count; i++) { ppmodel.product_id = Convert.ToInt32(dt_L.Rows[i]["product_id"].ToString()); ppmodel.event_id = m.event_id; if (m.event_type == "A2") { ppmodel.event_type = "A4"; } else if (m.event_type == "A3") { ppmodel.event_type = "A6"; } ppmodel.event_desc = m.event_desc; ppmodel.start = m.starts; ppmodel.end = m.end; ppmodel.page_url = m.category_link_url; if (m.group_id == 0 && m.condition_id == 0) ppmodel.user_specified = 0; else ppmodel.user_specified = 1; ppmodel.kuser = m.muser; ppmodel.kdate = m.modified; ppmodel.muser = m.muser; ppmodel.mdate = m.modified; ppmodel.status = m.status; sb.Append(_prodPromoDao.SaveProdProm(ppmodel)); } } //保存右類別下面的商品 DataTable dt_R = _access.getDataTable("SELECT product_id FROM product_category_set WHERE category_id=" + m.right_category_id + ""); if (dt_R.Rows.Count > 0) { ProdPromo ppmodel = new ProdPromo(); for (int i = 0; i < dt_R.Rows.Count; i++) { ppmodel.product_id = Convert.ToInt32(dt_R.Rows[i]["product_id"].ToString()); ppmodel.event_id = m.event_id; if (m.event_type == "A2") { ppmodel.event_type = "A5"; } else if (m.event_type == "A3") { ppmodel.event_type = "A7"; } ppmodel.event_desc = m.event_desc; ppmodel.start = m.starts; ppmodel.end = m.end; ppmodel.page_url = m.category_link_url; if (m.group_id == 0 && m.condition_id == 0) ppmodel.user_specified = 0; else ppmodel.user_specified = 1; ppmodel.kuser = m.muser; ppmodel.kdate = m.modified; ppmodel.muser = m.muser; ppmodel.mdate = m.modified; ppmodel.status = m.status; sb.Append(_prodPromoDao.SaveProdProm(ppmodel)); } } } else { DataTable _dt = _access.getDataTable("SELECT product_id FROM product_category_set WHERE category_id=" + m.category_id + ""); if (_dt.Rows.Count > 0) { ProdPromo ppmodel = new ProdPromo(); for (int i = 0; i < _dt.Rows.Count; i++) { ppmodel.product_id = Convert.ToInt32(_dt.Rows[i]["product_id"].ToString()); ppmodel.event_id = m.event_id; ppmodel.event_type = m.event_type; ppmodel.event_desc = m.event_desc; ppmodel.start = m.starts; ppmodel.end = m.end; ppmodel.page_url = m.category_link_url; if (m.group_id == 0 && m.condition_id == 0) ppmodel.user_specified = 0; else ppmodel.user_specified = 1; ppmodel.kuser = m.muser; ppmodel.kdate = m.modified; ppmodel.muser = m.muser; ppmodel.mdate = m.modified; ppmodel.status = m.status; sb.Append(_prodPromoDao.SaveProdProm(ppmodel)); } } } } sb.AppendFormat(@"UPDATE promo_additional_price SET condition_id='{1}',group_id='{2}',`start`='{3}',`end`='{4}',modified='{5}',deliver_type='{6}',device='{7}',muser='******',website='{9}',event_name='{10}',event_desc='{11}',fixed_price='{12}',buy_limit='{13}',url_by='{14}',active={15} where id={0} ; ", m.id, m.condition_id, m.group_id, CommonFunction.DateTimeToString(m.starts), CommonFunction.DateTimeToString(m.end), CommonFunction.DateTimeToString(m.modified), m.deliver_type, m.device, m.muser, m.website, m.event_name, m.event_desc, m.fixed_price, m.buy_limit, m.url_by, m.active); mySqlCmd.CommandText = sb.ToString(); r += mySqlCmd.ExecuteNonQuery(); mySqlCmd.Transaction.Commit(); } catch (Exception ex) { mySqlCmd.Transaction.Rollback(); throw new Exception("PromoAdditionalPriceDao-->ChangeActive-->" + ex.Message + sb.ToString(), ex); } finally { mySqlConn.Close(); } return r; }