public DataTable SelectDt(PromotionsAmountGift model) { try { return _pagDao.SelectDt(model); } catch (Exception ex) { throw new Exception("PromotionsAmountGiftMgr-->SelectDt-->" + ex.Message, ex); } }
public HttpResponseBase TryEatAndDiscountFirstSaveGift() { string jsonStr = String.Empty; try { PromotionsAmountGiftQuery model = new PromotionsAmountGiftQuery(); #region 獲取第一步保存model的數據 if (!string.IsNullOrEmpty(Request.Params["name"])) { model.name = Request.Params["name"].ToString(); } else { model.name = string.Empty; } if (!string.IsNullOrEmpty(Request.Params["desc"])) { model.event_desc = Request.Params["desc"].ToString(); } else { model.event_desc = string.Empty; } if (!string.IsNullOrEmpty(Request.Params["vendor_coverage"])) { model.vendor_coverage = Convert.ToInt32(Request.Params["vendor_coverage"].ToString()); } else { model.vendor_coverage = 0; } if (!string.IsNullOrEmpty(Request.Params["bonus_state"]))//0:一般 1:試吃 2:紅利折抵 { switch (Request.Params["bonus_state"].ToString()) { case "0": model.bonus_state = 0; model.dividend = 0; break; case "1": model.bonus_state = 1; model.dividend = 0; if (!string.IsNullOrEmpty(Request.Params["freight_price"])) { model.freight_price = Convert.ToInt32(Request.Params["freight_price"].ToString()); } else { model.freight_price = 0; } break; case "2": model.bonus_state = 2; if (!string.IsNullOrEmpty(Request.Params["Points"])) { model.dividend = Convert.ToInt32(Request.Params["Points"]); if (model.dividend == 4) { if (!string.IsNullOrEmpty(Request.Params["point"]))//此處要做出修改 { model.point = Convert.ToInt32(Request.Params["point"].ToString()); } else { model.point = 0; } if (!string.IsNullOrEmpty(Request.Params["dollar"]))//此處要做出修改 { model.dollar = Convert.ToInt32(Request.Params["dollar"].ToString()); } else { model.dollar = 0; } } else if (model.dividend == 5) { model.point = 0; if (!string.IsNullOrEmpty(Request.Params["dollar"]))//此處要做出修改 { model.dollar = Convert.ToInt32(Request.Params["dollar"].ToString()); } else { model.dollar = 0; } } else { model.point = 0; model.dollar = 0; } } break; } } model.kuser = (System.Web.HttpContext.Current.Session["caller"] as Caller).user_id.ToString(); model.created = DateTime.Now; model.status = 0; if (!string.IsNullOrEmpty(Request.Params["event_type_name"])) { //獲取event_type和category_father_id _parasrcMgr = new ParameterMgr(mySqlConnectionString); List<Parametersrc> fatherIdResult = _parasrcMgr.QueryUsed(new Parametersrc { ParameterType = "event_type", parameterName = Request.Params["event_type_name"].ToString(), Used = 1 }); if (fatherIdResult.Count == 1) { model.event_type = fatherIdResult[0].ParameterCode; model.category_father_id = Convert.ToUInt32(fatherIdResult[0].ParameterProperty); } } else { model.event_type = string.Empty; model.category_father_id = 0; } model.category_ipfrom = Request.UserHostAddress; #endregion _promoAmountGiftMgr = new PromotionsAmountGiftMgr(mySqlConnectionString); PromotionsAmountGift query = new PromotionsAmountGift(); int id = _promoAmountGiftMgr.TryEatAndDiscountSave(model); //DataTable dt = _promoAmountGiftMgr.SelectDt(query); PromotionsAmountGift pag = _promoAmountGiftMgr.GetModel(id); string event_id = CommonFunction.GetEventId(pag.event_type, pag.id.ToString()); if (pag != null) { jsonStr = "{success:true,\"id\":\"" + pag.id + "\",\"cateID\":\"" + pag.category_id + "\",\"event_type\":\"" + pag.event_type + "\",\"event_id\":\"" + event_id + "\"}"; } 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.ToString()); this.Response.End(); return this.Response; }
/// <summary> /// 刪除列表頁數據 /// </summary> /// <returns></returns> public HttpResponseBase DeletePromoAmountGift() { PromotionsAmountGift pag = new PromotionsAmountGift(); string jsonStr = String.Empty; _promoAmountGiftMgr = new PromotionsAmountGiftMgr(mySqlConnectionString); if (!String.IsNullOrEmpty(Request.Params["rowID"])) { try { foreach (string rid in Request.Params["rowID"].ToString().Split('|')) { if (rid != null) { pag = _promoAmountGiftMgr.GetModel(Convert.ToInt32(rid)); var eventid = CommonFunction.GetEventId(pag.event_type, pag.id.ToString()); if (!string.IsNullOrEmpty(rid)) { if (_promoAmountGiftMgr.Delete(Convert.ToInt32(rid), eventid) > 0) { jsonStr = "{success:true}"; } else { jsonStr = "{success:false}"; } } } } jsonStr = "{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); jsonStr = "{success:false}"; } } this.Response.Clear(); this.Response.Write(jsonStr); this.Response.End(); return this.Response; }
//新添加 #region 新增數據 第一步試吃/紅利抵用保存 #region 事物新增主表數據和product_category表數據 + int Save(PromotionsAmountGiftQuery query) public int TryEatAndDiscountSave(PromotionsAmountGiftQuery query) { _proCateDao = new ProductCategoryDao(connStr); query.Replace4MySQL(); int id = 0; MySqlCommand mySqlCmd = new MySqlCommand(); MySqlConnection mySqlConn = new MySqlConnection(connStr); StringBuilder sbExSql = 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; //#region 保存第一步到product_category 獲取prodduct_amount_fare的category_id ProductCategory pmodel = new ProductCategory(); pmodel.category_name = query.name; pmodel.category_createdate = (uint)BLL.gigade.Common.CommonFunction.GetPHPTime(); pmodel.category_father_id = query.category_father_id; pmodel.category_ipfrom = query.category_ipfrom; pmodel.category_display = Convert.ToUInt32(query.status); mySqlCmd.CommandText = _proCateDao.SaveCategory(pmodel); sbExSql.Append(mySqlCmd.CommandText); query.category_id = Convert.ToUInt32(mySqlCmd.ExecuteScalar()); //修改表serial Serial serial = new Serial(); serial.Serial_id = 12; serial.Serial_Value = Convert.ToUInt32(query.category_id); mySqlCmd.CommandText = _serialDao.UpdateAutoIncreament(serial); sbExSql.Append(mySqlCmd.CommandText); id = Convert.ToInt32(mySqlCmd.ExecuteScalar()); //#endregion PromotionsAmountGift pgmodel = new PromotionsAmountGift(); pgmodel.name = query.name; pgmodel.event_desc = query.event_desc; pgmodel.vendor_coverage = query.vendor_coverage; pgmodel.event_type = query.event_type; pgmodel.freight_price = query.freight_price; pgmodel.kuser = query.kuser; pgmodel.created = query.created; pgmodel.status = query.status; pgmodel.category_id = query.category_id; pgmodel.dividend = query.dividend; mySqlCmd.CommandText = TryEatAndDiscountSavePromoGift(pgmodel); sbExSql.Append(mySqlCmd.CommandText); id = Convert.ToInt32(mySqlCmd.ExecuteScalar()); mySqlCmd.Transaction.Commit(); } catch (Exception ex) { mySqlCmd.Transaction.Rollback(); throw new Exception("PromotionsAmountGiftDao-->Save-->" + ex.Message + sbExSql.ToString(), ex); } finally { if (mySqlConn != null && mySqlConn.State == System.Data.ConnectionState.Open) { mySqlConn.Close(); } } return id; }
/// <summary> /// 根據model獲取datatable對象 /// </summary> /// <param name="model">PromotionsAmountGift model對象</param> /// <returns>datatable類型數據</returns> public DataTable SelectDt(PromotionsAmountGift model) { model.Replace4MySQL(); StringBuilder sql = new StringBuilder(); try { sql.Append("select pag.id,pag.name,pag.category_id,pag.group_id,pag.class_id,"); sql.Append(" pag.brand_id,pag.product_id,pag.type,pag.amount,pag.quantity,pag.`repeat`,pag.gift_id,pag.ticket_id,"); sql.Append(" pag.ticket_name,pag.deduct_welfare,pag.bonus_type,pag.mailer_id,pag.start 'startdate',pag.end 'enddate',pag.created,"); sql.Append(" pag.modified,pag.active,pag.event_desc,pag.event_type,pag.condition_id,pag.device,pag.payment_code,pag.gift_type,pag.ticket_name,"); sql.Append(" pag.count_by,pag.number,pag.num_limit,pag.valid_interval,pag.active_now,pag.use_start,pag.use_end,pag.kuser,pag.muser,pag.url_by,pag.site,pag.status,pag.vendor_coverage,pag.gift_product_number"); sql.Append(" from promotions_amount_gift pag where 1=1 "); sql.AppendFormat(" and id='{0}';", model.id); return _access.getDataTable(sql.ToString()); } catch (Exception ex) { throw new Exception("PromotionsAmountGiftDao-->SelectDt-->" + ex.Message + sql.ToString(), ex); } }
/// <summary> /// 想promotions_amount_discount添加第一步數據 /// </summary> /// <param name="query">PromotionsAmountGift query對象</param> /// <returns>添加主表數據的sql語句</returns> public string SavePromoGift(PromotionsAmountGift query) { query.Replace4MySQL(); StringBuilder sql = new StringBuilder(); try { sql.AppendFormat("insert into promotions_amount_gift ("); sql.AppendFormat("name,group_id,class_id,brand_id,category_id,product_id,type,amount,quantity,`repeat` ,gift_id,"); sql.AppendFormat("deduct_welfare,bonus_type,mailer_id,start,end,created,modified,active,event_desc,event_type,condition_id,device, "); sql.AppendFormat(" payment_code,gift_type,ticket_id,ticket_name,count_by,number,num_limit,active_now,valid_interval, "); sql.AppendFormat("use_start,use_end ,kuser,muser,url_by,url,banner_file,status,site,vendor_coverage,gift_product_number) values "); sql.AppendFormat("('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}',", query.name, query.group_id, query.class_id, query.brand_id, query.category_id, query.product_id, query.type, query.amount, query.quantity, query.repeat ? '1' : '0', query.gift_id); sql.AppendFormat("'{0}','{1}','{2}','{3}','{4}','{5}','{6}',{7},'{8}','{9}','{10}','{11}',", query.deduct_welfare, query.bonus_type, query.mailer_id, CommonFunction.DateTimeToString(query.start), CommonFunction.DateTimeToString(query.end), CommonFunction.DateTimeToString(query.created), CommonFunction.DateTimeToString(query.modified), query.active, query.event_desc, query.event_type, query.condition_id, query.device); sql.AppendFormat("'{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}',", query.payment_code, query.gift_type, query.ticket_id, query.ticket_name, query.count_by, query.number, query.num_limit, query.active_now, query.valid_interval); sql.AppendFormat("'{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}');select @@identity;", CommonFunction.DateTimeToString(query.use_start), CommonFunction.DateTimeToString(query.use_end), query.kuser, query.muser, query.url_by, query.url, query.banner_file, query.status, query.site, query.vendor_coverage, query.gift_product_number); return sql.ToString(); } catch (Exception ex) { throw new Exception("PromotionsAmountGiftDao-->SavePromoGift-->" + ex.Message + sql.ToString(), ex); } }