public HttpResponseBase SaveOne()
 {
     string jsonStr = String.Empty;
     try
     {
         PromoAdditionalPrice model = new PromoAdditionalPrice();
         _promoadditionproceMgr = new PromoAdditionalPriceMgr(mySqlConnectionString);
         if (!String.IsNullOrEmpty(Request.Params["rowid"]))
         {
         }
         else
         {
             model.event_name = Request.Params["name"].ToString();
             model.event_desc = Request.Params["desc"].ToString();
             model.event_type = Request.Params["event"].ToString();
             model.kuser = (System.Web.HttpContext.Current.Session["caller"] as Caller).user_id.ToString();
             model.created = DateTime.Now;
             model.muser = model.kuser;
             model.modified = model.created;
             model.id = _promoadditionproceMgr.InsertFirst(model); // _promopairMgr.Save(model);
             model = _promoadditionproceMgr.GetModel(model.id);  //_promopairMgr.Select(query);
             string event_id = GetEventId(model.event_type, model.id.ToString());
             if (model.id > 0)
             {
                 jsonStr = "{success:true,\"id\":\"" + model.id + "\",\"cateID\":\"" + model.category_id + "\",\"event_id\":\"" + event_id + "\",\"cateOne\":\"" + model.left_category_id + "\",\"cateTwo\":\"" + model.right_category_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;
 }
        public HttpResponseBase PromoAdditionalPriceEdit()
        {
            string jsonStr = String.Empty;
            _promoadditionproceMgr = new PromoAdditionalPriceMgr(mySqlConnectionString);
            PromoAdditionalPrice model = new PromoAdditionalPrice();
            PromoAdditionalPrice oldermodel = new PromoAdditionalPrice();
            PromoAdditionalPriceQuery PPQuery = new PromoAdditionalPriceQuery();
            ProductCategory olderpcmodel = new ProductCategory();
            PromoAdditionalPriceQuery oldPPQuery = new PromoAdditionalPriceQuery();
            if (!String.IsNullOrEmpty(Request.Params["rowid"]))
            {
                try
                {
                    model.id = Convert.ToInt32(Request.Params["rowid"].ToString());
                    oldermodel = _promoadditionproceMgr.GetModel(model.id);
                    model.category_id = oldermodel.category_id;
                    olderpcmodel = _produCateMgr.GetModelById(Convert.ToUInt32(model.category_id));
                    model.event_name = Request.Params["event_name"].ToString();
                    model.event_desc = Request.Params["event_desc"].ToString();
                    model.event_type = oldermodel.event_type;
                    if (!string.IsNullOrEmpty(Request.Params["url_by"]))
                    {
                        model.url_by =Convert.ToInt32(Request.Params["url_by"]);
                    }
                    #region 會員群組 會員條件
                    if (Request.Params["group_id"].ToString() != "")
                    {
                        try//group_id
                        {
                            model.group_id = Convert.ToInt32(Request.Params["group_id"].ToString());
                        }
                        catch (Exception)
                        {
                            model.group_id = oldermodel.group_id;
                        }
                        model.condition_id = 0;
                    }
                    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 = oldermodel.condition_id;
                        }
                        model.group_id = 0;
                    }
                    #endregion
                    model.deliver_type = Convert.ToInt32(Request.Params["deliver_id"].ToString());
                    model.device = Request.Params["device_id"].ToString();
                    model.website = Request.Params["side"].ToString();
                    PPQuery.event_id = GetEventId(model.event_type, model.id.ToString());
                    try
                    {
                        model.fixed_price = Convert.ToInt32(Request.Params["fixed_price"].ToString());
                    }
                    catch (Exception)
                    {
                        model.fixed_price = oldermodel.fixed_price;
                    }
                    try
                    {
                        model.buy_limit = Convert.ToInt32(Request.Params["buy_limit"].ToString());
                    }
                    catch (Exception)
                    {
                        model.fixed_price = oldermodel.fixed_price;
                    }
                    model.starts = Convert.ToDateTime(Request.Params["starts"].ToString());
                    //string s = Request.Params["starts"];
                    //model.starts = DateTime.Parse(Request.Params["starts"]);
                    model.end = Convert.ToDateTime(Request.Params["end"].ToString());
                    model.muser = (System.Web.HttpContext.Current.Session["caller"] as Caller).user_id.ToString();
                    model.modified = DateTime.Now;
                    //20140925 add 折扣
                    if (model.event_type == "A3")
                    {
                        model.discount = Int32.Parse(Request.Params["discount"].ToString());
                    }
                    else
                    {
                        model.discount = 0;
                    }
                    PPQuery.category_ipfrom = Request.UserHostAddress;
                    PPQuery.event_id = GetEventId(model.event_type, model.id.ToString());
                    try//存連接地址
                    {
                        PPQuery.category_link_url = Request.Params["banner_url"].ToString();
                        if (PPQuery.category_link_url == "" || PPQuery.category_link_url == null)
                        {
                            model.url_by = 0;
                            //刪除上傳的圖片
                            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);//刪除本地圖片
                            }
                            PPQuery.category_link_url = "";
                            PPQuery.banner_image = "";
                        }
                        else
                        {
                            model.url_by = 1;
                            #region 上傳圖片
                            try
                            {
                                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);
                                FileManagement fileLoad = new FileManagement();
                                for (int iFile = 0; iFile < Request.Files.Count; iFile++)
                                {
                                    HttpPostedFileBase file = Request.Files[iFile];
                                    string fileName = string.Empty;//當前文件名
                                    string fileExtention = string.Empty;//當前文件的擴展名
                                    fileName = Path.GetFileName(file.FileName);
                                    // string returnName = imgServerPath;
                                    bool result = false;
                                    string NewFileName = string.Empty;
                                    fileExtention = fileName.Substring(fileName.LastIndexOf(".")).ToLower();
                                    NewFileName = PPQuery.event_id + newRand + fileExtention;
                                    string ServerPath = string.Empty;
                                    //判斷目錄是否存在,不存在則創建
                                    //string[] mapPath = new string[1];
                                    //mapPath[0] = promoPath.Substring(1, promoPath.Length - 2);
                                    //string s = localPromoPath.Substring(0, localPromoPath.Length - promoPath.Length + 1);
                                    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
                                    {
                                        //上傳
                                        result = fileLoad.UpLoadFile(file, ServerPath, NewFileName, extention, int.Parse(maxValue), int.Parse(minValue), ref ErrorMsg, ftpuser, ftppwd);
                                        if (result)//上傳成功
                                        {
                                            PPQuery.banner_image = fileName;
                                        }
                                    }
                                    catch (Exception)
                                    {
                                        PPQuery.banner_image = olderpcmodel.banner_image;
                                    }
                                }
                            }
                            catch (Exception)
                            {
                                PPQuery.banner_image = olderpcmodel.banner_image;
                            }
                            #endregion
                        }
                    }
                    catch (Exception)
                    {
                        PPQuery.category_link_url = oldPPQuery.category_link_url;
                    }
                    model.active = false;
                    if (_promoadditionproceMgr.CategoryID(model).ToString() == "true")
                    {

                        _promoadditionproceMgr.Update(model, PPQuery);
                        jsonStr = "{success:true}";
                    }
                    else
                    {
                        jsonStr = "{success:false,msg:3}";
                    }
                }
                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 HttpResponseBase PromoAdditionalPriceList()
        //{
        //    PromoAdditionalPriceQuery query = new PromoAdditionalPriceQuery();
        //    List<PromoAdditionalPriceQuery> store = new List<PromoAdditionalPriceQuery>();
        //    string json = string.Empty;
        //    try
        //    {
        //        query.Start = Convert.ToInt32(Request.Params["start"] ?? "0");
        //        if (!string.IsNullOrEmpty(Request.Params["limit"]))
        //        {
        //            query.Limit = Convert.ToInt32(Request.Params["limit"]);
        //        }
        //        if (!string.IsNullOrEmpty(Request.Params["ddlSel"]))
        //        {
        //            query.expired = Convert.ToInt32(Request.Params["ddlSel"]);
        //        }

        //        query.event_type = Request.Params["event_type"];
        //        _promoadditionproceMgr = new PromoAdditionalPriceMgr(mySqlConnectionString);
        //        int totalCount = 0;
        //        store = _promoadditionproceMgr.Query(query, out totalCount);
        //        IsoDateTimeConverter timeConverter = new IsoDateTimeConverter();
        //        //这里使用自定义日期格式,如果不使用的话,默认是ISO8601格式     
        //        timeConverter.DateTimeFormat = "yyyy-MM-dd HH:mm:ss";

        //        foreach (var item in store)
        //        {
        //            if (item.banner_image != "")
        //            {
        //                item.banner_image = imgServerPath + promoPath + item.banner_image;
        //            }
        //            else
        //            {
        //                item.banner_image = defaultImg;
        //            }
        //        }
        //        json = "{success:true,totalCount:" + totalCount + ",data:" + JsonConvert.SerializeObject(store, Formatting.Indented, timeConverter) + "}";//返回json數據
        //    }
        //    catch (Exception ex)
        //    {
        //        Log4NetCustom.LogMessage logMessage = new Log4NetCustom.LogMessage();
        //        logMessage.Content = string.Format("TargetSite:{0},Source:{1},Message:{2}", ex.TargetSite.Name, ex.Source, ex.Message);
        //        logMessage.MethodName = System.Reflection.MethodBase.GetCurrentMethod().Name;
        //        log.Error(logMessage);
        //        json = "{success:false,totalCount:0,data:[]}";
        //    }
        //    this.Response.Clear();
        //    this.Response.Write(json);
        //    this.Response.End();
        //    return this.Response;
        //}
        #endregion

        #region 不同商品固定價 同品加固定價 不同品加不同價格  刪除+HttpResponseBase PromoAdditionalPriceDelete()
        public HttpResponseBase PromoAdditionalPriceDelete()
        {
            PromoAdditionalPrice pap = new PromoAdditionalPrice();
            string jsonStr = String.Empty;
            _promoadditionproceMgr = new PromoAdditionalPriceMgr(mySqlConnectionString);
            if (!String.IsNullOrEmpty(Request.Params["rowID"]))
            {
                try
                {
                    foreach (string rid in Request.Params["rowID"].ToString().Split('|'))
                    {
                        if (rid != null)
                        {
                            int id = 0;

                            try
                            {
                                id = Convert.ToInt32(rid);
                            }
                            catch (Exception)
                            {

                            }

                            pap = _promoadditionproceMgr.GetModel(id);
                            var eventid = CommonFunction.GetEventId(pap.event_type, pap.id.ToString());

                            if (!string.IsNullOrEmpty(rid))
                            {
                                if (_promoadditionproceMgr.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;
        }