public int UpdateActive(PromotionsAccumulateRate store)
 {
     StringBuilder sb = new StringBuilder();
     store.Replace4MySQL();
     try
     {
         sb.AppendFormat("update promotions_accumulate_rate set active ={0},modified='{1}',muser={2} where id={3}", store.active, CommonFunction.DateTimeToString(store.modified),store.muser, store.id);
         return _access.execCommand(sb.ToString());
     }
     catch (Exception ex)
     {
         throw new Exception("PromotionsAccumulateRateDao-->UpdateActive-->" + ex.Message + sb.ToString(), ex);
     }
 }
 /// <summary>
 /// 更改活動使用狀態
 /// </summary>
 /// <returns>數據庫操作結果</returns>
 public JsonResult UpdateActive()
 {
     string currentUser = (System.Web.HttpContext.Current.Session["caller"] as Caller).user_id.ToString();
     string muser = Request.Params["muser"];
     int activeValue = Convert.ToInt32(Request.Params["active"]);
     if (currentUser == muser && activeValue == 1)
     {
         return Json(new { success = "stop" });
     }
     _padAccRateMgr = new PromotionsAccumulateRateMgr(mySqlConnectionString);
     int id = Convert.ToInt32(Request.Params["id"]);
     PromotionsAccumulateRate model = new PromotionsAccumulateRate();
     model.active = Convert.ToBoolean(activeValue);
     model.modified = DateTime.Now;
     model.muser = int.Parse(currentUser);
     model.id = id;
     if (_padAccRateMgr.UpdateActive(model) > 0)
     {
         return Json(new { success = "true", msg = "" });
     }
     else
     {
         return Json(new { success = "false", msg = "" });
     }
 }
        //public HttpResponseBase getfkfs()
        //{
        //    List<PaymentType> fklx = new List<PaymentType>();
        //    List<PaymentType> nfklx = new List<PaymentType>();
        //    string resultStr = "";
        //    try
        //    {
        //        _paytyMgr = new PaymentTypeMgr(mySqlConnectionString);
        //        fklx = _paytyMgr.Myfkfs();
        //        PaymentType pt1 = new PaymentType();
        //        pt1.payment_name = "不分";
        //        pt1.payment_code = "0";
        //        nfklx.Add(pt1);

        //        for (int i = 0; i < fklx.Count; i++)
        //        {
        //            PaymentType pt = new PaymentType();
        //            pt.payment_name = fklx[i].payment_name;
        //            pt.payment_code = fklx[i].payment_code;
        //            nfklx.Add(pt);
        //        }

        //        resultStr = JsonConvert.SerializeObject(nfklx);

        //    }
        //    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(resultStr);
        //this.Response.End();
        //return this.Response;
        //}
        #endregion

        #region 點數累積 判斷保存或者編輯 +HttpResponseBase Save()
        public HttpResponseBase Save()
        {
            PromotionsAccumulateRate model = new PromotionsAccumulateRate();
            model.muser=(System.Web.HttpContext.Current.Session["caller"] as Caller).user_id;
            model.modified = DateTime.Now;
            string jsonStr = String.Empty;
            //判斷是否能夠獲取到rowid
            if (String.IsNullOrEmpty(Request.Params["rowid"]))
            {
                //todo:對model進行賦值  
                model.kuser = model.muser;
                model.created = model.modified;
                #region try catch 應用
                try
                {
                    model.amount = Convert.ToInt32(Request.Params["amount"]);
                }
                catch (Exception)
                {
                    model.amount = 0;
                }
                try
                {
                    if (Convert.ToInt32(Request.Params["bonus_type"]) == 1)
                    {
                        model.bonus_type = 1;
                    }
                    else
                    {
                        model.bonus_type = 0;
                    }
                }
                catch
                {
                    model.bonus_type = 0;
                }
                try
                {
                    model.end = Convert.ToDateTime(Request.Params["end"]);
                }
                catch (Exception)
                {
                    model.end = DateTime.Now;
                }

                if (Request.Params["group_id"].ToString() != "")
                {
                    try//group_id
                    {
                        model.group_id = Convert.ToInt32(Request.Params["group_id"].ToString());
                    }
                    catch (Exception)
                    {
                        model.group_id = 0;
                    }
                    model.condition_id = 0;
                }
                else if (Request.Params["condition_id"].ToString() != "" && Request.Params["condition_id"].ToString() != "0")
                {
                    try//condition_id
                    {
                        model.condition_id = Convert.ToInt32(Request.Params["condition_id"].ToString());
                    }
                    catch (Exception)
                    {
                        model.condition_id = 0;
                    }
                    model.group_id = 0;
                }
                try
                {
                    model.start = Convert.ToDateTime(Request.Params["newstart"]);
                }
                catch (Exception)
                {
                    model.start = DateTime.Now;
                }
                try
                {
                    model.name = Request.Params["name"];
                }
                catch (Exception)
                {
                    model.name = "";
                }
                try
                {
                    model.dollar = Convert.ToInt32(Request.Params["dollar"]);
                }
                catch (Exception)
                {
                    model.dollar = 0;
                }
                try
                {
                    model.point = Convert.ToInt32(Request.Params["points"]);
                }
                catch (Exception)
                {
                    model.point = 0;
                }
                try
                {
                    model.payment_type_rid = Request.Params["payment_id"];
                }
                catch (Exception)
                {
                    model.payment_type_rid = "";
                }
                #endregion
                return InsertPromotionsAccumulateRate(model);//如果獲取不到則進行新增

            }
            else
            {
                _padAccRateMgr = new PromotionsAccumulateRateMgr(mySqlConnectionString);
                model.id = Convert.ToInt32(Request.Params["rowid"].ToString());
                PromotionsAccumulateRate PAR = _padAccRateMgr.GetModel(model.id);
                #region try catch應用
                try
                {
                    model.amount = Convert.ToInt32(Request.Params["amount"]);
                }
                catch (Exception)
                {
                    model.amount = PAR.amount;
                }

                try
                {
                    model.bonus_type = Convert.ToInt32(Request.Params["bonus_type"]);
                }
                catch (Exception)
                {
                    model.bonus_type = PAR.bonus_type;
                }

                try
                {
                    model.end = Convert.ToDateTime(Request.Params["end"]);
                }
                catch (Exception)
                {
                    model.end = PAR.end;
                }


                try
                {
                    model.start = Convert.ToDateTime(Request.Params["newstart"]);
                }
                catch (Exception)
                {
                    model.start = PAR.start;
                }
                try
                {
                    model.name = Request.Params["name"];
                }
                catch (Exception)
                {
                    model.name = PAR.name;
                }
                try
                {
                    model.dollar = Convert.ToInt32(Request.Params["dollar"]);
                }
                catch (Exception)
                {
                    model.dollar = 0;
                }
                try
                {
                    model.point = Convert.ToInt32(Request.Params["points"]);
                }
                catch (Exception)
                {
                    model.point = PAR.point;
                }
                try
                {
                    model.payment_type_rid = Request.Params["payment_id"];
                }
                catch (Exception)
                {
                    model.payment_type_rid = PAR.payment_type_rid;
                }

                //try
                //{

                //    model.group_id = Convert.ToInt32(Request.Params["group_id"]);

                //}
                //catch (Exception)
                //{
                //    model.group_id = PAR.group_id;
                //}

                //try
                //{
                //    if (Convert.ToInt32(Request.Params["condition_id"]) != 0)
                //    {
                //        model.condition_id = Convert.ToInt32(Request.Params["condition_id"]);
                //        //model.group_id = 0;
                //    }
                //    else
                //    {
                //        model.condition_id = 0;
                //    }
                //}
                //catch (Exception)
                //{
                //    model.condition_id = PAR.condition_id;
                //}
                if (Request.Params["group_id"].ToString() != "")
                {
                    try//group_id
                    {
                        model.group_id = Convert.ToInt32(Request.Params["group_id"].ToString());
                    }
                    catch (Exception)
                    {
                        model.group_id = PAR.group_id;
                    }

                    if (Request.Params["condition_id"].ToString() != "" && Request.Params["condition_id"].ToString() != "0")
                    {
                        UserCondition uc = new UserCondition();
                        uc.condition_id = Convert.ToInt32(Request.Params["condition_id"]);
                        if (_ucMgr.Delete(uc) > 0)
                        {
                            jsonStr = "{success:true}";
                            model.condition_id = 0;
                        }
                        else
                        {
                            jsonStr = "{success:false,msg:'user_condition刪除出錯!'}";
                            this.Response.Clear();
                            this.Response.Write(jsonStr.ToString());
                            this.Response.End();
                            return this.Response;
                        }
                    }
                }
                else if (Request.Params["condition_id"].ToString() != "" && Request.Params["condition_id"].ToString() != "0")
                {
                    try//condition_id
                    {
                        model.condition_id = Convert.ToInt32(Request.Params["condition_id"].ToString());
                    }
                    catch (Exception)
                    {
                        model.condition_id = PAR.condition_id;
                    }
                    model.group_id = 0;
                }
                #endregion
                model.active = false;
                //todo:對model進行賦值
                return UpdatePromotionsAccumulateRate(model);//如果可以獲取到rowid則進行修改
            }
        }
 /// <summary>
 /// 修改功能 PromotionsAmountFare
 /// </summary>
 /// <param name="model"></param>
 /// <returns></returns>
 protected HttpResponseBase UpdatePromotionsAccumulateRate(PromotionsAccumulateRate model)
 {
     string json = string.Empty;
     try
     {
         _padAccRateMgr.Update(model);
         json = "{success:true}";//返回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);
         json = "{success:false}";
     }
     this.Response.Clear();
     this.Response.Write(json);
     this.Response.End();
     return this.Response;
 }
        public HttpResponseBase Delete()
        {
            string jsonStr = String.Empty;
            _padAccRateMgr = new PromotionsAccumulateRateMgr(mySqlConnectionString);
            PromotionsAccumulateRate query = new PromotionsAccumulateRate();
            if (!String.IsNullOrEmpty(Request.Params["rowid"]))
            {
                try
                {
                    foreach (string rid in Request.Params["rowid"].ToString().Split('|'))
                    {
                        if (!string.IsNullOrEmpty(rid))
                        {
                            query.id = Convert.ToInt32(rid);
                            query.muser =(System.Web.HttpContext.Current.Session["caller"] as Caller).user_id;
                            query.modified = DateTime.Now;
                            _padAccRateMgr.Delete(query);
                        }
                    }
                    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;
        }