public HttpResponseBase GetList()
        {
            string json = string.Empty;
            int totalCount=0;
            try
            {
                PromotionsAmountDiscountCustom query = new PromotionsAmountDiscountCustom();
                List<PromotionsAmountDiscountCustom> store = new List<PromotionsAmountDiscountCustom>();
               query.Start = Convert.ToInt32(Request.Params["start"] ?? "0");
               query.Limit = Convert.ToInt32(Request.Params["limit"] ?? "25");

               _promotionsAmountDiscount = new PromotionsAmountDiscountMgr(mySqlConnectionString);
               if (!string.IsNullOrEmpty(Request.Params["searchStore"]))
               {
                   query.searchStore = Convert.ToInt32(Request.Params["searchStore"]);
               }
               store=_promotionsAmountDiscount.GetList(query,out totalCount);
               //foreach (var item in store)
               //{
               //    if (item.group_name == "")
               //    {
               //        item.group_name = "不分";
               //    }
               //}
               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:true,totalCount:0,data:[]}";
            }
            this.Response.Clear();
            this.Response.Write(json);
            this.Response.End();
            return this.Response;
        }
        public HttpResponseBase UpdatePromotionsAmountDiscount(PromotionsAmountDiscountCustom model, string oldEventId)
        {
            string jsonStr = String.Empty;
            try
            {

                if (_promoAmountDiscountMgr.ReUpdateDiscount(model, oldEventId))
                {
                    jsonStr = "{success:true}";//返回json數據
                }
                else
                {
                    jsonStr = "{success:false}";//返回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);
                jsonStr = "{success:false}";
            }

            this.Response.Clear();
            this.Response.Write(jsonStr.ToString());
            this.Response.End();
            return this.Response;
        }
        public HttpResponseBase SavePromotionsAmountDiscountTwo()
        {
            try
            {
                string jsonStr = string.Empty;
                PromotionsAmountDiscount model = new PromotionsAmountDiscount();
                ProductCategory pmodel = new ProductCategory();
                int isTryInt = 0;
                #region 獲取新增時promotionamountdiscount和productcategory model值
                if (!string.IsNullOrEmpty(Request.Params["pid"].ToString()))
                {
                    model.id = Convert.ToInt32(Request.Params["pid"].ToString());
                }

                PromotionsAmountDiscountCustom oldermodel = _promoAmountDiscountMgr.GetModelById(model.id);
                model.category_id = oldermodel.category_id;
                pmodel.category_id = Convert.ToUInt32(oldermodel.category_id);

                ProductCategory olderpcmodel = _produCateMgr.GetModelById(pmodel.category_id);

                PromotionsAmountDiscountCustom pacdModel = new PromotionsAmountDiscountCustom();
                pacdModel.id = model.id;
                pacdModel.category_id = model.category_id;

                if (!string.IsNullOrEmpty(Request.Params["name"].ToString()))
                {
                    pacdModel.name = Request.Params["name"].ToString();
                }
                if (!string.IsNullOrEmpty(Request.Params["desc"].ToString()))
                {
                    pacdModel.event_desc = Request.Params["desc"].ToString();
                }
                if (!string.IsNullOrEmpty(Request.Params["e_type"].ToString()))
                {
                    pacdModel.event_type = Request.Params["e_type"].ToString();
                }
                pacdModel.event_id = CommonFunction.GetEventId(pacdModel.event_type.ToString(), pacdModel.id.ToString());
                if (!string.IsNullOrEmpty(Request.Params["url_by"].ToString()))
                {
                    pacdModel.url_by = Convert.ToInt32(Request.Params["url_by"].ToString());
                }
                else
                {
                    pacdModel.url_by = oldermodel.url_by;
                }
                if (pacdModel.url_by == 1)
                {

                    #region 上傳圖片

                    try
                    {
                        if (Request.Files.Count != 0)
                        {
                            string path = Server.MapPath(xmlPath);
                            SiteConfigMgr _siteConfigMgr = new SiteConfigMgr(path);
                            SiteConfig extention_config = _siteConfigMgr.GetConfigByName("PIC_Extention_Format");
                            SiteConfig minValue_config = _siteConfigMgr.GetConfigByName("PIC_Length_MinValue");
                            SiteConfig maxValue_config = _siteConfigMgr.GetConfigByName("PIC_Length_MaxValue");
                            SiteConfig admin_userName = _siteConfigMgr.GetConfigByName("ADMIN_USERNAME");
                            SiteConfig admin_passwd = _siteConfigMgr.GetConfigByName("ADMIN_PASSWD");

                            //擴展名、最小值、最大值
                            string extention = extention_config.Value == "" ? extention_config.DefaultValue : extention_config.Value;
                            string minValue = minValue_config.Value == "" ? minValue_config.DefaultValue : minValue_config.Value;
                            string maxValue = maxValue_config.Value == "" ? maxValue_config.DefaultValue : maxValue_config.Value;

                            string localPromoPath = imgLocalPath + promoPath;//圖片存儲地址
                            //生成隨機數,用於圖片的重命名
                            Random rand = new Random();
                            int newRand = rand.Next(1000, 9999);



                            //獲取上傳的圖片
                            HttpPostedFileBase file = Request.Files[0];
                            string fileName = string.Empty;//當前文件名
                            string fileExtention = string.Empty;//當前文件的擴展名

                            fileName = Path.GetFileName(file.FileName);
                            if (!string.IsNullOrEmpty(fileName))
                            {
                                bool result = false;
                                string NewFileName = string.Empty;

                                fileExtention = fileName.Substring(fileName.LastIndexOf(".")).ToLower();
                                NewFileName = pacdModel.event_id + newRand + fileExtention;//圖片重命名為event_id+4位隨機數+擴展名

                                string ServerPath = string.Empty;
                                //判斷目錄是否存在,不存在則創建
                                CreateFolder(localPromoPath.Substring(0, localPromoPath.Length - promoPath.Length + 1), promoPath.Substring(1, promoPath.Length - 2).Split('/'));

                                //  returnName += promoPath + NewFileName;
                                fileName = NewFileName;
                                NewFileName = localPromoPath + NewFileName;//絕對路徑
                                ServerPath = Server.MapPath(imgLocalServerPath + promoPath);
                                string ErrorMsg = string.Empty;

                                //上傳之前刪除已有的圖片
                                string oldFileName = olderpcmodel.banner_image;
                                FTP ftp = new FTP(localPromoPath, ftpuser, ftppwd);
                                List<string> tem = ftp.GetFileList();
                                if (tem.Contains(oldFileName))
                                {
                                    //FTP ftps = new FTP(localPromoPath + oldFileName, ftpuser, ftppwd);
                                    //ftps.DeleteFile(localPromoPath + oldFileName);//刪除ftp:71.159上的舊圖片
                                    //DeletePicFile(ServerPath + oldFileName);//刪除本地圖片
                                }
                                try
                                {
                                    //上傳
                                    FileManagement fileLoad = new FileManagement();
                                    result = fileLoad.UpLoadFile(file, ServerPath, NewFileName, extention, int.Parse(maxValue), int.Parse(minValue), ref ErrorMsg, ftpuser, ftppwd);
                                    if (result)//上傳成功
                                    {
                                        pacdModel.banner_image = fileName;
                                    }

                                }
                                catch (Exception ex)
                                {
                                    Log4NetCustom.LogMessage logMessage = new Log4NetCustom.LogMessage();
                                    logMessage.Content = string.Format("TargetSite:{0},Source:{1},Message:{2}", ex.TargetSite.Name + "->fileLoad.UpLoadFile()", ex.Source, ex.Message);
                                    logMessage.MethodName = System.Reflection.MethodBase.GetCurrentMethod().Name;
                                    log.Error(logMessage);
                                    jsonStr = "{success:false,msg:'圖片上傳失敗'}";

                                    pacdModel.banner_image = olderpcmodel.banner_image;
                                }
                            }
                            else
                            {
                                pacdModel.banner_image = olderpcmodel.banner_image;
                            }
                        }

                    }
                    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,msg:'圖片上傳失敗'}";

                        pacdModel.banner_image = olderpcmodel.banner_image;
                    }


                    #endregion

                    if (!string.IsNullOrEmpty(Request.Params["banner_url"].ToString()))//存連接地址
                    {
                        pacdModel.category_link_url = Request.Params["banner_url"].ToString();
                    }
                    else
                    {
                        pacdModel.category_link_url = olderpcmodel.category_link_url;
                    }

                    if (!string.IsNullOrEmpty(Request.Params["sbrand_id"].ToString()))
                    {
                        int brandTranId = 0;
                        if (int.TryParse(Request.Params["sbrand_id"].ToString(), out brandTranId))
                        {
                            pacdModel.brand_id = Convert.ToInt32(Request.Params["sbrand_id"].ToString());
                        }
                        else
                        {
                            pacdModel.brand_id = oldermodel.brand_id;
                        }
                    }
                    else
                    {
                        pacdModel.brand_id = 0;
                    }


                    if (!string.IsNullOrEmpty(Request.Params["sclass_id"].ToString()))
                    {
                        int classTranId = 0;
                        if (int.TryParse(Request.Params["sclass_id"].ToString(), out classTranId))
                        {
                            pacdModel.class_id = Convert.ToInt32(Request.Params["sclass_id"].ToString());

                        }
                        else
                        {
                            pacdModel.class_id = oldermodel.class_id;
                        }
                    }
                    else
                    {
                        pacdModel.class_id = 0;
                    }
                    if (Request.Params["allClass"].ToString() == "1")//是否全館
                    {
                        string allClass = Request.Params["allClass"];
                        pacdModel.brand_id = 0;
                        pacdModel.class_id = 0;
                        pacdModel.product_id = 999999;


                    }
                }
                else
                {
                    //刪除上傳的圖片
                    //string oldFileName = olderpcmodel.banner_image;
                    //FTP ftp = new FTP(imgLocalPath + promoPath, ftpuser, ftppwd);
                    //List<string> tem = ftp.GetFileList();
                    //if (tem.Contains(oldFileName))
                    //{
                    //FTP ftps = new FTP(imgLocalPath + promoPath + oldFileName, ftpuser, ftppwd);
                    //ftps.DeleteFile(imgLocalPath + promoPath + oldFileName);//刪除ftp:71.159上的舊圖片
                    // DeletePicFile(Server.MapPath(imgLocalServerPath + promoPath) + oldFileName);//刪除本地圖片
                    // }

                    pacdModel.banner_image = "";
                    pacdModel.category_link_url = "";
                    if (!string.IsNullOrEmpty(Request.Params["noclass_id"]) && int.TryParse(Request.Params["noclass_id"].ToString(), out isTryInt))
                    {
                        pacdModel.class_id = Convert.ToInt32(Request.Params["noclass_id"]);
                    }
                    else
                    {
                        pacdModel.class_id = 0;
                    }
                    if (!string.IsNullOrEmpty(Request.Params["nobrand_id"]) && int.TryParse(Request.Params["nobrand_id"].ToString(), out isTryInt))
                    {
                        pacdModel.brand_id = Convert.ToInt32(Request.Params["nobrand_id"]);
                    }
                    else
                    {
                        pacdModel.brand_id =0;
                    }
                    if (!string.IsNullOrEmpty(Request.Params["product_id"]))
                    {
                        pacdModel.product_id = Convert.ToInt32(Request.Params["product_id"]);
                    }
                    else
                    {
                        pacdModel.product_id = 0;
                    }
                    if (!string.IsNullOrEmpty(Request.Params["no_allClass"]))
                    {
                        if (Request.Params["no_allClass"].ToString() == "1")//是否全館
                        {
                            string allClass = Request.Params["no_allClass"];
                            pacdModel.brand_id = 0;
                            pacdModel.class_id = 0;
                            pacdModel.product_id = 999999;


                        }
                    }
                    if (!string.IsNullOrEmpty(Request.Params["no_amount"]))
                    {
                        pacdModel.amount = Convert.ToInt32(Request.Params["no_amount"]);
                    }
                    else
                    {
                        pacdModel.amount = 0;
                    }
                    if (!string.IsNullOrEmpty(Request.Params["no_discount"]))
                    {
                        pacdModel.discount = Convert.ToInt32(Request.Params["no_discount"]);
                    }
                    else
                    {
                        pacdModel.discount = 0;
                    }
                    if (!string.IsNullOrEmpty(Request.Params["no_quantity"]))
                    {
                        pacdModel.quantity = Convert.ToInt32(Request.Params["no_quantity"]);
                    }
                    else
                    {
                        pacdModel.quantity = 0;
                    }
                }
                if (Request.Params["group_id"].ToString() != "")
                {
                    int groupTryId = 0;
                    if (!string.IsNullOrEmpty(Request.Params["group_id"].ToString()) && int.TryParse(Request.Params["group_id"].ToString(), out groupTryId))
                    {
                        pacdModel.group_id = Convert.ToInt32(Request.Params["group_id"].ToString());

                    }
                    else
                    {
                        pacdModel.group_id = oldermodel.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}";
                        }
                        else
                        {
                            jsonStr = "{success:false,msg:'user_condition delete failure!'}";
                            this.Response.Clear();
                            this.Response.Write(jsonStr.ToString());
                            this.Response.End();
                            return this.Response;
                        }
                    }
                    pacdModel.condition_id = 0;
                }
                else
                {
                    if (Request.Params["condition_id"].ToString() != "" && Request.Params["condition_id"].ToString() != "0")
                    {
                        if (!string.IsNullOrEmpty(Request.Params["condition_id"].ToString()))//condition_id
                        {
                            pacdModel.condition_id = Convert.ToInt32(Request.Params["condition_id"].ToString());
                        }
                        else
                        {
                            pacdModel.condition_id = oldermodel.condition_id;
                        }
                        pacdModel.group_id = 0;
                    }
                }


                if (!string.IsNullOrEmpty(Request.Params["devicename"].ToString()))//device
                {
                    pacdModel.device = Convert.ToInt32(Request.Params["devicename"].ToString());
                }
                else
                {
                    pacdModel.device = oldermodel.device;
                }
                if (!string.IsNullOrEmpty(Request.Params["start_date"].ToString()))//start
                {
                    pacdModel.start = Convert.ToDateTime(Request.Params["start_date"].ToString());
                }
                else
                {
                    pacdModel.start = oldermodel.date_state;
                }
                if (!string.IsNullOrEmpty(Request.Params["end_date"].ToString()))//end
                {
                    pacdModel.end = Convert.ToDateTime(Request.Params["end_date"].ToString());
                }
                else
                {
                    pacdModel.end = oldermodel.date_end;
                }

                if (!string.IsNullOrEmpty(Request.Params["site"].ToString()))//修改時傳的值為siteName
                {
                    string site = Request.Params["site"].ToString();
                    Regex reg = new Regex("^([0-9]+,)*[0-9]+$");
                    if (reg.IsMatch(site))
                    {
                        pacdModel.site = site;// 將站台改為多選 edit by shuangshuang0420j 20140925 10:08
                    }
                    else
                    {
                        if (site.LastIndexOf(',') == site.Length - 1)//最後一個字符為,時
                        {
                            pacdModel.site = site.Substring(0, site.Length - 1);

                        }

                    }
                }

                if (!string.IsNullOrEmpty(Request.Params["vendor_coverage"].ToString()))//vendor_coverage
                {
                    pacdModel.vendor_coverage = Convert.ToInt32(Request.Params["vendor_coverage"].ToString());
                }
                else
                {
                    pacdModel.vendor_coverage = oldermodel.vendor_coverage;
                }
                //獲取pacdModel.category_father_id
                List<Parametersrc> fatherIdResult = _parasrcMgr.QueryUsed(new Parametersrc { ParameterType = "event_type", Used = 1, ParameterCode = pacdModel.event_type });
                if (fatherIdResult.Count > 0)
                {
                    pacdModel.category_father_id = Convert.ToUInt32(fatherIdResult[0].ParameterProperty);
                }
                pacdModel.active = false;
                pacdModel.category_updatedate = (uint)BLL.gigade.Common.CommonFunction.GetPHPTime();
                pacdModel.status = 1;
                pacdModel.category_ipfrom = Request.UserHostAddress;
                #endregion
                if (Request.Params["type"].ToString() == "Add")
                {
                    pacdModel.kuser = (System.Web.HttpContext.Current.Session["caller"] as Caller).user_id.ToString();
                    pacdModel.created = DateTime.Now;
                    pacdModel.muser = pacdModel.kuser;
                    pacdModel.modified = pacdModel.created;
                    return AddPromotionsAmountDiscount(pacdModel);
                }
                else
                {

                    pacdModel.kuser = oldermodel.kuser;
                    pacdModel.created = oldermodel.created;
                    pacdModel.muser = (System.Web.HttpContext.Current.Session["caller"] as Caller).user_id.ToString();
                    pacdModel.modified = DateTime.Now;
                    return UpdatePromotionsAmountDiscount(pacdModel, CommonFunction.GetEventId(oldermodel.event_type.ToString(), oldermodel.id.ToString()));
                }
            }
            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("{success:false,msg:0}");
                this.Response.End();
                return this.Response;
            }

        }
        public HttpResponseBase Save()
        {
            string json = string.Empty;
            try
            {
                PromotionsAmountDiscountCustom query = new PromotionsAmountDiscountCustom();
                _promotionsAmountDiscount = new PromotionsAmountDiscountMgr(mySqlConnectionString);
                if (!string.IsNullOrEmpty(Request.Params["name"]))
                {
                    query.name = Request.Params["name"];
                }
                if (!string.IsNullOrEmpty(Request.Params["group_id"]))
                {
                    query.group_id =Convert.ToInt32( Request.Params["group_id"]);
                }
                if (!string.IsNullOrEmpty(Request.Params["discount"]))
                {
                    query.discount = Convert.ToInt32(Request.Params["discount"]);
                }
                if (!string.IsNullOrEmpty(Request.Params["amount"]))
                {
                    query.amount = Convert.ToInt32(Request.Params["amount"]);
                }
                if (!string.IsNullOrEmpty(Request.Params["quantity"]))
                {
                    query.quantity = Convert.ToInt32(Request.Params["quantity"]);
                }
                if (!string.IsNullOrEmpty(Request.Params["site"]))
                {
                    query.site = (Request.Params["site"]);
                }
                if (!string.IsNullOrEmpty(Request.Params["start"]))
                {
                    query.start =Convert.ToDateTime(Request.Params["start"]);
                }
                if (!string.IsNullOrEmpty(Request.Params["end"]))
                {
                    query.end =Convert.ToDateTime( Request.Params["end"]);
                }
                if (string.IsNullOrEmpty(Request.Params["id"]))
                {
                    query.status = 0;
                    query.created = DateTime.Now;
                    query.modified = query.created;
                    query.kuser = (Session["caller"] as Caller).user_id.ToString();
                    query.muser = query.kuser;
                    //新增
                    if (_promotionsAmountDiscount.Save(query) > 0)
                    {

                        json = "{success:'true'}";
                    }
                    else
                    {
                        json = "{success:'false'}";
                    }
                }
                else
                {
                    //編輯
                    query.id = Convert.ToInt32(Request.Params["id"]);
                    query.modified = DateTime.Now;
                    query.muser = (Session["caller"] as Caller).user_id.ToString();
                    if (_promotionsAmountDiscount.Save(query) > 0)
                    {
                        json = "{success:'true'}";
                    }
                    else
                    {
                        json = "{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);
                json = "{success:'false'}";
            }

            this.Response.Clear();
            this.Response.Write(json);
            this.Response.End();
            return this.Response;
        }
        public JsonResult UpPADActive()
        {
            string json = string.Empty;
            try
            {
                PromotionsAmountDiscountCustom query = new PromotionsAmountDiscountCustom();
                string currentUser = (Session["caller"] as Caller).user_id.ToString();
                if (!string.IsNullOrEmpty(Request.Params["muser"]))
                {
                    query.muser = (Request.Params["muser"]);
                }
                if (!string.IsNullOrEmpty(Request.Params["active"]))
                {
                    if (Convert.ToInt32(Request.Params["active"]) == 1)
                    {
                        query.active = true;
                    }
                    else
                    {
                        query.active = false;
                    }
                }
                if (currentUser != query.muser || query.active!=true)
                {
                    if (!string.IsNullOrEmpty(Request.Params["id"]))
                    {
                        query.id = Convert.ToInt32(Request.Params["id"]);
                    }
                    query.modified = DateTime.Now;
                    query.muser = currentUser;
                    _promotionsAmountDiscount = new PromotionsAmountDiscountMgr(mySqlConnectionString);
                    if (_promotionsAmountDiscount.UpdatePromoAmountDisActive(query))
                    {
                        return Json(new { success = "true" });
                    }
                    else
                    {
                        return Json(new { success = "false" });
                    }
                }
                else
                {
                    return Json(new { success="msg"});
                }
          

            }
            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);
                return Json(new { success = "false" });
            }
        }
        public bool UpdatePromoAmountDisActive(PromotionsAmountDiscountCustom model)
        {
            try
            {

                ArrayList arrList = new ArrayList();
                arrList.Add(_padDao.UpdatePromoAmountDisActive(model));
                if (_mysqlDao.ExcuteSqls(arrList))
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
            catch (Exception ex)
            {
                throw new Exception("PromotionsAmountDiscountMgr-->UpdatePromoAmountDisActive-->" + ex.Message, ex);
            }
        }
 public HttpResponseBase Delete()
 {
     string json = string.Empty;
     PromotionsAmountDiscountCustom query = null;
     _promotionsAmountDiscount = new PromotionsAmountDiscountMgr(mySqlConnectionString);
     List<PromotionsAmountDiscountCustom> list = new List<PromotionsAmountDiscountCustom>();
     try
     {
         if (!string.IsNullOrEmpty(Request.Form["rowID"]))
         {
             string rowIDs = Request.Form["rowID"];
             if (rowIDs.IndexOf("|") != -1)
             {
                 foreach (string id in rowIDs.Split('|'))
                 {
                     if (!string.IsNullOrEmpty(id))
                     {
                         query = new PromotionsAmountDiscountCustom();
                         query.id = Convert.ToInt32(id);
                         list.Add(query);
                     }
                 }
             }
             if (_promotionsAmountDiscount.Delete(list))
             {
                 json = "{success:true}";
             }
             else
             {
                 json = "{failure: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 = "{failure:true}";
     }
     this.Response.Clear();
     this.Response.Write(json);
     this.Response.End();
     return this.Response;
 }
        public List<PromotionsAmountDiscountCustom> GetList(PromotionsAmountDiscountCustom query, out int totalCount)
        {
            try
            {
                List<PromotionsAmountDiscountCustom>store=_padDao.GetList(query, out totalCount);
                     SiteDao _sDao = new SiteDao(connStr);
                foreach (var item in store)
                {

                    string[] araySite = item.site.Split(',');
                    foreach (string site in araySite)
                    {
                        if (item.group_name == "")
                        {
                            item.group_name = "不分";
                        }
                        if (site != "" && site != "0")
                        {
                            item.site_name += _sDao.Query(new Site { Site_Id = Convert.ToUInt32(site) }).FirstOrDefault().Site_Name + ",";
                        }
                    }
                    item.site_name = item.site_name.TrimEnd(',');
                }
                return store;
            }
            catch (Exception ex)
            {
                throw new Exception("PromotionsAmountDiscountMgr-->GetList-->" + ex.Message, ex);
            }
        }
 public int Save(PromotionsAmountDiscountCustom query)
 {
     try
     {
         return _padDao.Save(query);
     }
     catch (Exception ex)
     {
         throw new Exception("PromotionsAmountDiscountMgr-->Save-->" + ex.Message, ex);
     }
 }
        public bool ReSaveDiscount(PromotionsAmountDiscountCustom model)
        {

            ArrayList arryList = new ArrayList();
            try
            {
                if (model.product_id == 999999)
                {
                    ProductCategorySet pcsModel = new ProductCategorySet();
                    pcsModel.Brand_Id = 0;
                    pcsModel.Category_Id = model.category_id;
                    pcsModel.Product_Id = 999999;
                    arryList.Add(_prodCategSet.SaveProdCategorySet(pcsModel));

                }
                else
                {
                    //刪除全館商品
                    ProductCategorySet qgSet = new ProductCategorySet();
                    qgSet.Category_Id = model.category_id;
                    qgSet.Product_Id = 999999;//全館商品刪除 id=999999
                    //根據category_id刪除product_category_set表數據

                    if (model.url_by == 1)
                    {
                        if (model.brand_id != 0)//專區時當品牌不為空時講該品牌下的所有商品加入set表
                        {
                            arryList.Add(_prodCategSet.DelProdCateSetByCPID(qgSet));
                            QueryVerifyCondition query = new QueryVerifyCondition();
                            query.brand_id = Convert.ToUInt32(model.brand_id);
                            query.site_ids = model.site;
                            query.combination = 1;
                            query.IsPage = false;
                            int totalCount = 0;
                            List<QueryandVerifyCustom> qvcList = _promoMainDao.GetProList(query, out totalCount);
                            foreach (QueryandVerifyCustom qvcItem in qvcList)
                            {
                                ProductCategorySet pcsModel = new ProductCategorySet();
                                pcsModel.Product_Id = qvcItem.product_id;
                                pcsModel.Brand_Id = Convert.ToUInt32(model.brand_id);
                                pcsModel.Category_Id = model.category_id;
                                arryList.Add(_prodCategSet.SaveProdCategorySet(pcsModel));
                            }
                        }
                    }
                    else//非專區時
                    {
                        if (model.event_type == "M1")
                        {
                            arryList.Add(_prodCategSet.DelProdCateSetByCPID(qgSet));
                        }
                        if (model.product_id != 0)
                        {
                            arryList.Add(_prodCategSet.DelProdCateSetByCPID(qgSet));
                            ProductCategorySet pcsModel = new ProductCategorySet();
                            pcsModel.Product_Id = Convert.ToUInt32(model.product_id);
                            pcsModel.Brand_Id = _prodDao.Query(new Product { Product_Id = pcsModel.Product_Id }).FirstOrDefault().Brand_Id;
                            pcsModel.Category_Id = model.category_id;
                            arryList.Add(_prodCategSet.SaveProdCategorySet(pcsModel));
                        }
                        else if (model.brand_id != 0)
                        {
                            arryList.Add(_prodCategSet.DelProdCateSetByCPID(qgSet));
                            QueryVerifyCondition query = new QueryVerifyCondition();
                            query.brand_id = Convert.ToUInt32(model.brand_id);
                            query.site_ids = model.site;
                            query.combination = 1;
                            query.IsPage = false;
                            int totalCount = 0;//篩選出該品牌下符合條件的商品
                            List<QueryandVerifyCustom> qvcList = _promoMainDao.GetProList(query, out totalCount);
                            foreach (QueryandVerifyCustom qvcItem in qvcList)
                            {
                                ProductCategorySet pcsModel = new ProductCategorySet();
                                pcsModel.Product_Id = qvcItem.product_id;
                                pcsModel.Brand_Id = Convert.ToUInt32(model.brand_id);
                                pcsModel.Category_Id = model.category_id;
                                arryList.Add(_prodCategSet.SaveProdCategorySet(pcsModel));
                            }
                        }
                        else if (model.class_id != 0)
                        {
                            arryList.Add(_prodCategSet.DelProdCateSetByCPID(qgSet));
                            VendorBrandSetDao _vbsDao = new VendorBrandSetDao(connStr);
                            List<VendorBrandSet> brandIDs = _vbsDao.Query(new VendorBrandSet { class_id = (uint)model.class_id });

                            if (brandIDs.Count > 0)
                            {
                                QueryVerifyCondition query = new QueryVerifyCondition();
                                foreach (VendorBrandSet item in brandIDs)
                                {
                                    query.brand_ids += item.brand_id + ",";
                                }
                                query.brand_ids = query.brand_ids.TrimEnd(',');
                                query.site_ids = model.site;
                                query.combination = 1;
                                query.IsPage = false;
                                int totalCount = 0;
                                List<QueryandVerifyCustom> qvcList = _promoMainDao.GetProList(query, out totalCount);
                                foreach (QueryandVerifyCustom qvcItem in qvcList)
                                {
                                    ProductCategorySet pcsModel = new ProductCategorySet();
                                    pcsModel.Product_Id = qvcItem.product_id;
                                    pcsModel.Brand_Id = Convert.ToUInt32(model.brand_id);
                                    pcsModel.Category_Id = model.category_id;
                                    arryList.Add(_prodCategSet.SaveProdCategorySet(pcsModel));
                                }
                            }
                        }
                    }
                }

                PromoAll pamodel = new PromoAll();
                pamodel.event_id = model.event_id;
                pamodel.event_type = model.event_type;
                pamodel.brand_id = model.brand_id;
                pamodel.class_id = model.class_id;
                pamodel.category_id = Convert.ToInt32(model.category_id);
                pamodel.startTime = model.start;
                pamodel.end = model.end;
                pamodel.status = model.status;
                pamodel.kuser = model.kuser;
                pamodel.kdate = model.created;
                pamodel.muser = model.kuser;
                pamodel.mdate = model.created;
                pamodel.product_id = model.product_id;
                pamodel.class_id = model.class_id;
                pamodel.brand_id = model.brand_id;
                arryList.Add(_proAllDao.SavePromAll(pamodel));
                ProductCategory pcmodel = _proCateDao.GetModelById(Convert.ToUInt32(model.category_id));
                pcmodel.category_id = Convert.ToUInt32(model.category_id);
                pcmodel.banner_image = model.banner_image;
                pcmodel.category_link_url = model.category_link_url;
                pcmodel.category_display = Convert.ToUInt32(model.status);
                pcmodel.category_name = model.name;
                pcmodel.category_father_id = model.category_father_id;
                arryList.Add(_proCateDao.UpdateProdCate(pcmodel));
                arryList.Add(_padDao.UpdatePromoAmountDis(model));
                return _mysqlDao.ExcuteSqls(arryList);
            }
            catch (Exception ex)
            {

                throw new Exception("PromotionsAmountDiscountMgr-->ReSaveDiscount-->" + ex.Message, ex);
            }


        }
        public bool ReUpdateDiscount(PromotionsAmountDiscountCustom model, string oldEventId)
        {
            ArrayList arryList = new ArrayList();
            try
            {

                arryList.Add(_prodpromoDao.DeleteProdProm(oldEventId));//修改時先刪除原有的prodprom
                if (model.product_id == 999999)
                {
                    ProductCategorySet pcsModel = new ProductCategorySet();

                    pcsModel.Brand_Id = 0;
                    pcsModel.Category_Id = model.category_id;
                    pcsModel.Product_Id = 999999;
                    arryList.Add(_prodCategSet.DeleteProdCateSet(pcsModel.Category_Id));
                    arryList.Add(_prodCategSet.SaveProdCategorySet(pcsModel));

                }
                else
                {
                    if (model.url_by == 1)
                    {
                        if (model.brand_id != 0)//當品牌不為空時講該品牌下的所有商品加入set表
                        {
                            arryList.Add(_prodCategSet.DeleteProdCateSet(model.category_id));//brand_id不為0時先刪除set表中數據,在新增

                            QueryVerifyCondition query = new QueryVerifyCondition();
                            query.brand_id = Convert.ToUInt32(model.brand_id);
                            query.site_ids = model.site;
                            query.combination = 1;
                            query.IsPage = false;
                            int totalCount = 0;
                            List<QueryandVerifyCustom> qvcList = _promoMainDao.GetProList(query, out totalCount);
                            foreach (QueryandVerifyCustom qvcItem in qvcList)
                            {
                                ProductCategorySet pcsModel = new ProductCategorySet();
                                pcsModel.Product_Id = qvcItem.product_id;
                                pcsModel.Brand_Id = Convert.ToUInt32(model.brand_id);
                                pcsModel.Category_Id = model.category_id;
                                //刪除已有的 新增異動的
                                arryList.Add(_prodCategSet.SaveProdCategorySet(pcsModel));
                            }
                        }
                    }
                    else//非專區
                    {
                        if (model.event_type == "M1")
                        {
                            arryList.Add(_prodCategSet.DeleteProdCateSet(model.category_id));//幾件幾折的非專區時先刪除set表中數據,在新增
                        }

                        if (model.product_id != 0)
                        {
                            arryList.Add(_prodCategSet.DeleteProdCateSet(model.category_id));//非專區時先刪除set表中數據,在新增
                            ProductCategorySet pcsModel = new ProductCategorySet();
                            pcsModel.Product_Id = Convert.ToUInt32(model.product_id);
                            pcsModel.Brand_Id = _prodDao.Query(new Product { Product_Id = pcsModel.Product_Id }).FirstOrDefault().Brand_Id;
                            pcsModel.Category_Id = model.category_id;
                            arryList.Add(_prodCategSet.SaveProdCategorySet(pcsModel));
                        }
                        else if (model.brand_id != 0)
                        {
                            arryList.Add(_prodCategSet.DeleteProdCateSet(model.category_id));//非專區時先刪除set表中數據,在新增
                            QueryVerifyCondition query = new QueryVerifyCondition();
                            query.brand_id = Convert.ToUInt32(model.brand_id);
                            query.site_ids = model.site;
                            query.combination = 1;
                            int totalCount = 0;
                            query.IsPage = false;
                            List<QueryandVerifyCustom> qvcList = _promoMainDao.GetProList(query, out totalCount);
                            foreach (QueryandVerifyCustom qvcItem in qvcList)
                            {
                                ProductCategorySet pcsModel = new ProductCategorySet();
                                pcsModel.Product_Id = qvcItem.product_id;
                                pcsModel.Brand_Id = Convert.ToUInt32(model.brand_id);
                                pcsModel.Category_Id = model.category_id;
                                arryList.Add(_prodCategSet.SaveProdCategorySet(pcsModel));
                            }
                        }
                        else if (model.class_id != 0)
                        {
                            arryList.Add(_prodCategSet.DeleteProdCateSet(model.category_id));//非專區時先刪除set表中數據,在新增
                            VendorBrandSetDao _vbsDao = new VendorBrandSetDao(connStr);
                            List<VendorBrandSet> brandIDs = _vbsDao.Query(new VendorBrandSet { class_id = (uint)model.class_id });

                            if (brandIDs.Count > 0)
                            {
                                QueryVerifyCondition query = new QueryVerifyCondition();
                                foreach (VendorBrandSet item in brandIDs)
                                {
                                    query.brand_ids += item.brand_id + ",";
                                }
                                query.brand_ids = query.brand_ids.TrimEnd(',');
                                query.site_ids = model.site;
                                query.combination = 1;
                                query.IsPage = false;
                                int totalCount = 0;
                                List<QueryandVerifyCustom> qvcList = _promoMainDao.GetProList(query, out totalCount);
                                foreach (QueryandVerifyCustom qvcItem in qvcList)
                                {
                                    ProductCategorySet pcsModel = new ProductCategorySet();
                                    pcsModel.Product_Id = qvcItem.product_id;
                                    pcsModel.Brand_Id = Convert.ToUInt32(model.brand_id);
                                    pcsModel.Category_Id = model.category_id;
                                    arryList.Add(_prodCategSet.SaveProdCategorySet(pcsModel));
                                }
                            }
                        }
                    }
                }
                if (model.event_id != "")
                {
                    arryList.Add(_proAllDao.DelPromAll(oldEventId));
                }
                PromoAll pamodel = new PromoAll();
                pamodel.event_id = model.event_id;
                pamodel.event_type = model.event_type;
                pamodel.brand_id = model.brand_id;
                pamodel.class_id = model.class_id;
                pamodel.category_id = Convert.ToInt32(model.category_id);
                pamodel.startTime = model.start;
                pamodel.end = model.end;
                pamodel.status = model.status;
                pamodel.kuser = model.kuser;
                pamodel.kdate = model.created;
                pamodel.muser = model.muser;
                pamodel.mdate = model.modified;
                pamodel.status = model.status;
                pamodel.product_id = model.product_id;
                pamodel.class_id = model.class_id;
                pamodel.brand_id = model.brand_id;
                arryList.Add(_proAllDao.SavePromAll(pamodel));
                ProductCategory pcmodel = _proCateDao.GetModelById(Convert.ToUInt32(model.category_id));
                pcmodel.category_id = Convert.ToUInt32(model.category_id);
                pcmodel.banner_image = model.banner_image;
                pcmodel.category_link_url = model.category_link_url;
                pcmodel.category_display = Convert.ToUInt32(model.status);
                pcmodel.category_name = model.name;
                pcmodel.category_updatedate = (uint)BLL.gigade.Common.CommonFunction.GetPHPTime(model.modified.ToString());
                pcmodel.category_father_id = model.category_father_id;
                arryList.Add(_proCateDao.UpdateProdCate(pcmodel));
                arryList.Add(_padDao.UpdatePromoAmountDis(model));
                return _mysqlDao.ExcuteSqls(arryList);
            }
            catch (Exception ex)
            {
                throw new Exception("PromotionsAmountDiscountDao-->ReUpdate-->" + ex.Message, ex);
            }

        }
        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 Save(PromotionsAmountDiscountCustom query)
        {
            StringBuilder sql = new StringBuilder();
            query.Replace4MySQL();
            try
            {

                if (query.id == 0)//新增
                {
                    sql.AppendFormat("insert into  promotions_amount_discount (");
                    sql.AppendFormat("name,group_id,class_id,brand_id,category_id,product_id,type,amount,quantity,discount,vendor_coverage,start,end,");
                    sql.AppendFormat("event_desc,event_type,condition_id,device,payment_code,kuser,created,muser,modified,site,active,status,url_by) values ");
                    sql.AppendFormat("('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}','{15}','{16}','{17}','{18}','{19}','{20}','{21}','{22}',{23},'{24}','{25}');", query.name, query.group_id, query.class_id, query.brand_id, query.category_id, query.product_id, query.type, query.amount, query.quantity, query.discount, query.vendor_coverage, CommonFunction.DateTimeToString(query.start), CommonFunction.DateTimeToString(query.end), query.event_desc, query.event_type, query.condition_id, query.device, query.payment_code, query.kuser, CommonFunction.DateTimeToString(query.created), query.muser, CommonFunction.DateTimeToString(query.modified), query.site, query.active, query.status, query.url_by);
                }
                else//編輯
                {
                    sql.AppendFormat("update promotions_amount_discount set name='{0}',group_id='{1}', discount='{2}',start='{3}',end='{4}',modified='{5}', muser='******' ,amount='{7}',quantity='{8}',site='{9}' where id='{10}';", query.name, query.group_id, query.discount, CommonFunction.DateTimeToString(query.start), CommonFunction.DateTimeToString(query.end), CommonFunction.DateTimeToString(query.modified), query.muser, query.amount,query.quantity,query.site,query.id);
                }
                return _access.execCommand(sql.ToString());
            }
            catch (Exception ex)
            {
                throw new Exception("PromotionAmountDiscountsDao-->Save-->+" + sql.ToString() + ex.Message, ex);
            }
        }
 public List<PromotionsAmountDiscountCustom> GetList(PromotionsAmountDiscountCustom query, out int totalCount)
 {
     StringBuilder sql = new StringBuilder();
     StringBuilder sqlFrom = new StringBuilder();
     StringBuilder sqlWhere = new StringBuilder();
     totalCount = 0;
     try
     {
         sql.Append(" select  pad.id,pad.`name`,pad.group_id,vug.group_name, pad.discount,pad.amount,pad.quantity,pad.site,pad.start,pad.end,pad.kuser,mu1.user_username 'create_user', pad.muser,mu2.user_username 'update_user',pad.active  ");
         sqlFrom.Append(" from promotions_amount_discount pad  ");
         sqlFrom.Append(" LEFT JOIN vip_user_group vug on vug.group_id=pad.group_id LEFT JOIN manage_user mu1 on mu1.user_id=pad.kuser LEFT JOIN manage_user mu2 on mu2.user_id=pad.muser  ");
         sqlWhere.Append(" where 1=1   ");
         if (query.searchStore == 1)
         {
             sqlWhere.AppendFormat(" and pad.end>'{0}' ", CommonFunction.DateTimeToString(DateTime.Now));
         }
         else
         {
             sqlWhere.AppendFormat(" and pad.end<'{0}' ", CommonFunction.DateTimeToString(DateTime.Now));
         }
         if (query.IsPage)
         {
             DataTable _dt = _access.getDataTable(" select  count(pad.id)  as totalCount " + sqlFrom.ToString() + sqlWhere.ToString());
             if (_dt.Rows.Count > 0)
             {
                 totalCount = Convert.ToInt32(_dt.Rows[0]["totalCount"]);
             }
             sqlWhere.AppendFormat(" order by pad.id desc limit {0},{1};", query.Start, query.Limit);
         }
         sql.Append(sqlFrom.ToString() + sqlWhere.ToString());
         return _access.getDataTableForObj<PromotionsAmountDiscountCustom>(sql.ToString());
     }
     catch (Exception ex)
     {
         throw new Exception("PromotionAmountDiscountsDao-->GetList-->+" + sql.ToString() + ex.Message, ex);
     }
 }
        /// <summary>
        /// 更新Active的時候進行更新的數據
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public string UpdatePromoAmountDisActive(PromotionsAmountDiscountCustom model)
        {
            model.Replace4MySQL();
            StringBuilder sql = new StringBuilder();
            try
            {
                sql.AppendFormat("update  promotions_amount_discount  set active={0},modified='{1}',muser='******'", model.active, CommonFunction.DateTimeToString(model.modified), model.muser);

                sql.AppendFormat("  where id={0};", model.id);
                return sql.ToString();
            }
            catch (Exception ex)
            {
                throw new Exception("PromotionsAmountDiscountDao-->UpdatePromoAmountDisActive-->" + ex.Message + sql.ToString(), ex);
            }
        }
 /// <summary>
 /// 更新PromoAmountDis數據 
 /// </summary>
 /// <param name="model">參數模型</param>
 /// <returns>返回sql語句</returns>
 public string UpdatePromoAmountDis(PromotionsAmountDiscountCustom model)
 {
     model.Replace4MySQL();
     StringBuilder sql = new StringBuilder();
     try
     {
         sql.AppendFormat("update  promotions_amount_discount  set ");
         sql.AppendFormat("name='{0}',group_id={1},class_id={2},brand_id={3},category_id={4}", model.name, model.group_id, model.class_id, model.brand_id, model.category_id);
         sql.AppendFormat(",product_id={0},type={1},amount={2},quantity={3},discount={4},vendor_coverage={5}", model.product_id, model.type, model.amount, model.quantity, model.discount, model.vendor_coverage);
         sql.AppendFormat(",start='{0}',end='{1}',modified='{2}',active={3}", CommonFunction.DateTimeToString(model.start), CommonFunction.DateTimeToString(model.end), CommonFunction.DateTimeToString(model.modified), model.active);
         sql.AppendFormat(",event_desc='{0}',event_type='{1}',condition_id={2},device={3},payment_code={4}", model.event_desc, model.event_type, model.condition_id, model.device, model.payment_code);
         sql.AppendFormat(",muser='******',site='{1}',status='{2}',url_by='{3}'", model.muser, model.site, model.status, model.url_by);
         sql.AppendFormat("  where id={0};", model.id);
         return sql.ToString();
     }
     catch (Exception ex)
     {
         throw new Exception("PromotionsAmountDiscountDao-->UpdatePromoAmountDis-->" + ex.Message + sql.ToString(), ex);
     }
 }