Beispiel #1
0
 /// <summary>
 /// 根據UserCondition對象的id獲取整個model對象
 /// </summary>
 /// <param name="uc"></param>
 /// <returns></returns>
 public UserCondition GetModelById(UserCondition uc)
 {
     StringBuilder sql = new StringBuilder();
     try
     {
         sql.Append("select *  from  user_condition");
         sql.AppendFormat("  where 1=1 and status=1 and condition_id={0};", uc.condition_id);
         return _access.getSinggleObj<UserCondition>(sql.ToString());
     }
     catch (Exception ex)
     {
         throw new Exception("UserConditionMgr-->GetModelById-->" + ex.Message + sql.ToString(), ex);
     }
 }
        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 PromoPairEdit()
        {
            string jsonStr = String.Empty;
            _promopairMgr = new PromoPairMgr(mySqlConnectionString);
            PromoPair model = new PromoPair();
            PromoPair oldermodel = new PromoPair();
            PromoPairQuery PPQuery = new PromoPairQuery();
            ProductCategory olderpcmodel = new ProductCategory();
            PromoPairQuery oldPPQuery = new PromoPairQuery();
            if (!String.IsNullOrEmpty(Request.Params["rowid"]))
            {
                try
                {
                    model.id = Convert.ToInt32(Request.Params["rowid"].ToString());
                    model.category_id = Convert.ToInt32(Request.Params["categoryid"].ToString());
                    oldermodel = _promopairMgr.GetModelById(model.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;
                    model.vendor_coverage = int.Parse(Request.Params["vendor_coverage"]);
                    #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;
                        }

                        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刪除出錯!'}";
                                this.Response.Clear();
                                this.Response.Write(jsonStr.ToString());
                                this.Response.End();
                                return this.Response;
                            }
                        }
                        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 = 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();
                    if (!string.IsNullOrEmpty(Request.Params["side"].ToString()))//修改時傳的值為siteName
                    {
                        Regex reg = new Regex("^([0-9]+,)*[0-9]+$");
                        if (reg.IsMatch(Request.Params["side"].ToString()))
                        {
                            model.website = Request.Params["side"].ToString();// 將站台改為多選 edit by shuangshuang0420j 20140925 10:08
                        }
                        else
                        {
                            model.website = oldermodel.website;
                        }
                    }
                    #region 紅+綠
                    if (Request.Params["price"].ToString() != "")
                    {
                        try//price
                        {
                            model.price = Convert.ToInt32(Request.Params["price"].ToString());
                        }
                        catch (Exception)
                        {
                            model.price = oldermodel.group_id;
                        }
                        model.discount = 0;
                    }
                    else if (Request.Params["discount"].ToString() != "")
                    {
                        try//discount
                        {
                            model.discount = Convert.ToInt32(Request.Params["discount"].ToString());
                        }
                        catch (Exception)
                        {
                            model.discount = oldermodel.condition_id;
                        }
                        model.price = 0;
                    }
                    #endregion
                    model.starts = Convert.ToDateTime(Request.Params["starts"].ToString());
                    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;
                    PPQuery.event_id = CommonFunction.GetEventId(model.event_type, model.id.ToString());
                    #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

                    #region  注釋上傳圖片
                    ////string nowtime = DateTime.Now.ToString("hhmm");
                    //Random rand = new Random();
                    //int nowtime = rand.Next(1000, 9999);
                    //try
                    //{
                    //    string saveFoler = Server.MapPath("~/aimg.gigade100.com/active/");
                    //    string savePath, fileName, oldsavePath;
                    //    for (int iFile = 0; iFile < Request.Files.Count; iFile++)
                    //    {
                    //        HttpPostedFileBase postedFile = Request.Files[iFile];
                    //        fileName = Path.GetFileName(postedFile.FileName);
                    //        if (fileName != "")
                    //        {
                    //            string fileType = fileName.Substring(fileName.LastIndexOf("."));
                    //            string newName = GetEventId(oldermodel.event_type, model.id.ToString()) + nowtime + fileType;
                    //            oldsavePath = olderpcmodel.banner_image;
                    //            oldsavePath = saveFoler + oldsavePath;
                    //            savePath = saveFoler + newName;                                 
                    //            if (System.IO.File.Exists(oldsavePath))
                    //            {//检查是否在服务器上已经存在用户上传的同名文件
                    //                System.IO.File.Delete(oldsavePath);
                    //            }
                    //            if (fileType.ToLower() == ".jpg" || fileType.ToLower() == ".png" || fileType.ToLower() == ".gif" || fileType.ToLower() == ".jpeg")
                    //            {
                    //                if (postedFile.ContentLength <= 300 * 1024)
                    //                {
                    //                    postedFile.SaveAs(savePath);
                    //                    PPQuery.banner_image = newName;
                    //                }
                    //                else
                    //                {
                    //                    jsonStr = "{success:false,msg:1}";
                    //                    this.Response.Clear();
                    //                    this.Response.Write(jsonStr.ToString());
                    //                    this.Response.End();
                    //                    return this.Response;
                    //                }
                    //            }
                    //            else
                    //            {
                    //                jsonStr = "{success:false,msg:2}";
                    //                this.Response.Clear();
                    //                this.Response.Write(jsonStr.ToString());
                    //                this.Response.End();
                    //                return this.Response;
                    //            }
                    //        }
                    //        else
                    //        {
                    //            PPQuery.banner_image = olderpcmodel.banner_image;
                    //        }
                    //    }
                    //}
                    //catch (Exception)
                    //{
                    //    PPQuery.banner_image = olderpcmodel.banner_image;
                    //}
                    #endregion
                    try//存連接地址 id是否也添加時間
                    {
                        PPQuery.category_link_url = phpwebhost + "/pair/red_green_match.php?event_id=" + PPQuery.event_id;
                    }
                    catch (Exception)
                    {
                        PPQuery.category_link_url = oldPPQuery.category_link_url;
                    }
                    //foreach (string rid in Request.Params["rowid"].ToString().Split('|'))
                    //{
                    //    if (!string.IsNullOrEmpty(rid))
                    //    {
                    //        query.id = Convert.ToInt32(rid);
                    //        _promopairMgr.Update(query);
                    //    }
                    //}                    
                    if (_promopairMgr.CategoryID(model).ToString() == "true")
                    {
                        _promopairMgr.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;
        }
        /// <summary>
        ///獲取數據  會員條件設定新增或編輯
        /// </summary>
        /// <returns>跳轉到執行方法</returns>
        public HttpResponseBase SavePromotionsUser()
        {
            NameValueCollection param = Request.Params;
            UserCondition uc = new UserCondition();
            uc.condition_name = param["condition_name"];
            if (param["condition_id"] == "0" || param["condition_id"] == "")
            {
                if (!string.IsNullOrEmpty(Request.Params["reg_start"]))
                {
                    uc.reg_start = Convert.ToInt32(CommonFunction.GetPHPTime(param["reg_start"].ToString()));
                }
                else
                {
                    uc.reg_start = Convert.ToInt32(CommonFunction.GetPHPTime(DateTime.Now.ToString()));
                }
                if (!string.IsNullOrEmpty(Request.Params["reg_end"]))
                {
                    uc.reg_end = Convert.ToInt32(CommonFunction.GetPHPTime(param["reg_end"].ToString()));
                }
                else
                {
                    uc.reg_end = Convert.ToInt32(CommonFunction.GetPHPTime(DateTime.Now.ToString()));
                }
                if (!string.IsNullOrEmpty(Request.Params["reg_interval"]))
                {
                    uc.reg_interval = Convert.ToInt32(param["reg_interval"]);
                }
                else
                {
                    uc.reg_interval = 0;
                }
                if (!string.IsNullOrEmpty(Request.Params["buy_times_min"]))
                {
                    uc.buy_times_min = Convert.ToInt32(param["buy_times_min"]);
                }
                else
                {
                    uc.buy_times_min = 0;
                }
                if (!string.IsNullOrEmpty(Request.Params["buy_times_max"]))
                {
                    uc.buy_times_max = Convert.ToInt32(param["buy_times_max"]);
                }
                else
                {
                    uc.buy_times_max = 0;
                }
                if (!string.IsNullOrEmpty(Request.Params["buy_amount_min"]))
                {
                    uc.buy_amount_min = Convert.ToInt32(param["buy_amount_min"]);
                }
                else
                {
                    uc.buy_amount_min = 0;
                }
                if (!string.IsNullOrEmpty(Request.Params["buy_amount_max"]))
                {
                    uc.buy_amount_max = Convert.ToInt32(param["buy_amount_max"]);
                }
                else
                {
                    uc.buy_amount_max = 0;
                }
                if (!string.IsNullOrEmpty(Request.Params["last_time_start"]))
                {
                    uc.last_time_start = Convert.ToInt32(CommonFunction.GetPHPTime(param["last_time_start"].ToString()));
                }
                else
                {
                    uc.last_time_start = Convert.ToInt32(CommonFunction.GetPHPTime(DateTime.Now.ToString()));
                }
                if (!string.IsNullOrEmpty(Request.Params["last_time_end"]))
                {
                    uc.last_time_end = Convert.ToInt32(CommonFunction.GetPHPTime(param["last_time_end"].ToString()));
                }
                else
                {
                    uc.last_time_end = Convert.ToInt32(CommonFunction.GetPHPTime(DateTime.Now.ToString()));
                }
                if (!string.IsNullOrEmpty(Request.Params["last_time_interval"]))
                {
                    uc.last_time_interval = Convert.ToInt32(param["last_time_interval"]);
                }
                else
                {
                    uc.last_time_interval = 0;
                }
                if (!string.IsNullOrEmpty(Request.Params["join_channel"]))
                {
                    uc.join_channel = Convert.ToInt32(param["join_channel"]);
                }
                else
                {
                    uc.join_channel = 0;
                }
                uc.status = 1;
                return AddPromotionsUser(uc);
            }
            else
            {
                uc.condition_id = Convert.ToInt32(param["condition_id"].ToString());
                UserCondition OldUc = _ucMgr.Select(uc);
                if (!string.IsNullOrEmpty(Request.Params["reg_start"]))
                {
                    uc.reg_start = Convert.ToInt32(CommonFunction.GetPHPTime(param["reg_start"].ToString()));
                }
                else
                {
                    uc.reg_start = OldUc.reg_start;
                }
                if (!string.IsNullOrEmpty(Request.Params["reg_end"]))
                {
                    uc.reg_end = Convert.ToInt32(CommonFunction.GetPHPTime(param["reg_end"].ToString()));
                }
                else
                {
                    uc.reg_end = OldUc.reg_end;
                }
                if (!string.IsNullOrEmpty(Request.Params["reg_interval"]))
                {
                    uc.reg_interval = Convert.ToInt32(param["reg_interval"]);
                }
                else
                {
                    uc.reg_interval = OldUc.reg_interval;
                }
                if (!string.IsNullOrEmpty(Request.Params["buy_times_min"]))
                {
                    uc.buy_times_min = Convert.ToInt32(param["buy_times_min"]);
                }
                else
                {
                    uc.buy_times_min = OldUc.buy_times_min;
                }
                if (!string.IsNullOrEmpty(Request.Params["buy_times_max"]))
                {
                    uc.buy_times_max = Convert.ToInt32(param["buy_times_max"]);
                }
                else
                {
                    uc.buy_times_max = OldUc.buy_times_max;
                }
                if (!string.IsNullOrEmpty(Request.Params["buy_amount_min"]))
                {
                    uc.buy_amount_min = Convert.ToInt32(param["buy_amount_min"]);
                }
                else
                {
                    uc.buy_amount_min = OldUc.buy_amount_min;
                }
                if (!string.IsNullOrEmpty(Request.Params["buy_amount_max"]))
                {
                    uc.buy_amount_max = Convert.ToInt32(param["buy_amount_max"]);
                }
                else
                {
                    uc.buy_amount_max = OldUc.buy_amount_max;
                }
                if (!string.IsNullOrEmpty(Request.Params["last_time_start"]))
                {
                    uc.last_time_start = Convert.ToInt32(CommonFunction.GetPHPTime(param["last_time_start"].ToString()));
                }
                else
                {
                    uc.last_time_start = OldUc.last_time_start;
                }
                if (!string.IsNullOrEmpty(Request.Params["last_time_end"]))
                {
                    uc.last_time_end = Convert.ToInt32(CommonFunction.GetPHPTime(param["last_time_end"].ToString()));
                }
                else
                {
                    uc.last_time_end = OldUc.last_time_end;
                }
                if (!string.IsNullOrEmpty(Request.Params["last_time_interval"]))
                {
                    uc.last_time_interval = Convert.ToInt32(param["last_time_interval"]);
                }
                else
                {
                    uc.last_time_interval = OldUc.last_time_interval;
                }
                if (!string.IsNullOrEmpty(Request.Params["join_channel"].ToString()))
                {
                    int channelId = 0;
                    if (int.TryParse(Request.Params["join_channel"].ToString(), out channelId))
                    {
                        uc.join_channel = Convert.ToInt32(param["join_channel"]);
                    }
                    else
                    {
                        uc.join_channel = OldUc.join_channel;
                    }
                }
                else
                {
                    uc.join_channel = OldUc.join_channel;
                }
                uc.status = 1;
                return UpdatePromotionsUser(uc);
            }

        }
        public HttpResponseBase UserConInfo()
        {
            UserCondition uc = new UserCondition();
            string json = string.Empty;

            if (Request.Params["condition_id"] != "" && Request.Params["condition_id"] != "0")
            {
                if (!string.IsNullOrEmpty(Request.Params["condition_id"]))
                {
                    uc.condition_id = Convert.ToInt32(Request.Params["condition_id"]);
                }
                else
                {
                    uc.condition_id = 0;
                }
                UserCondition ucResult = new UserCondition();
                ucResult = _ucMgr.GetModelById(uc);

                ucResult.reg_startDateTime = CommonFunction.GetNetTime(ucResult.reg_start);
                ucResult.reg_endDateTime = CommonFunction.GetNetTime(ucResult.reg_end);
                ucResult.last_time_startDateTime = CommonFunction.GetNetTime(ucResult.last_time_start);
                ucResult.last_time_endDateTime = CommonFunction.GetNetTime(ucResult.last_time_end);
                IsoDateTimeConverter timeConverter = new IsoDateTimeConverter();
                //这里使用自定义日期格式,如果不使用的话,默认是ISO8601格式     
                timeConverter.DateTimeFormat = "yyyy-MM-dd HH:mm:ss";

                //listUser是准备转换的对象
                //json = "{success:true,totalCount:" + totalCount + ",data:" + JsonConvert.SerializeObject(stores, Formatting.Indented, timeConverter) + "}";//返回json數據
                try
                {

                    if (ucResult != null)
                    {

                        json = "{success:true,data:[" + JsonConvert.SerializeObject(ucResult, Formatting.Indented, timeConverter) + "]}";
                    }
                    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:true,totalCount:0,data:[]}";
                }
                this.Response.Clear();
                this.Response.Write(json);
                this.Response.End();
                return this.Response;
            }
            this.Response.Clear();
            this.Response.Write(json);
            this.Response.End();
            return this.Response;
        }
 /// <summary>
 /// 會員條件設定編輯
 /// </summary>
 /// <param name="uc">UserCondition uc對象</param>
 /// <returns>執行結果</returns>
 public HttpResponseBase UpdatePromotionsUser(UserCondition uc)
 {
     string json = string.Empty;
     try
     {
         if (_ucMgr.Update(uc) > 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;
 }
 /// <summary>
 /// 會員條件設定新增
 /// </summary>
 /// <param name="uc">UserCondition uc對象</param>
 /// <returns>執行結果 json數組獲取condition_id</returns>
 public HttpResponseBase AddPromotionsUser(UserCondition uc)
 {
     string json = string.Empty;
     try
     {
         System.Data.DataTable query = _ucMgr.Add(uc);
         if (query != null)
         {
             json = "{success:true,id:" + query.Rows[0]["condition_id"] + ",data:" + JsonConvert.SerializeObject(query) + "}";
         }
         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 HttpResponseBase SecondSaveGift()
        {
            string jsonStr = String.Empty;
            try
            {
                string rowID = Request.Params["rowid"].ToString();
                string isEdit = Request.Params["isEdit"].ToString();
                _promoAmountGiftMgr = new PromotionsAmountGiftMgr(mySqlConnectionString);
                PromotionsAmountGiftQuery model = new PromotionsAmountGiftQuery();
                PromotionsAmountGiftQuery OldModel = _promoAmountGiftMgr.Select(Convert.ToInt32(rowID));
                OldModel.event_id = CommonFunction.GetEventId(OldModel.event_type, OldModel.id.ToString());

                #region 獲取數據
                if (!string.IsNullOrEmpty(Request.Params["rowid"]))
                {
                    model.id = Convert.ToInt32(Request.Params["rowid"]);
                }
                else
                {
                    model.id = OldModel.id;
                }
                model.category_id = OldModel.category_id;
                if (!string.IsNullOrEmpty(Request.Params["event_name"]))
                {
                    model.name = Request.Params["event_name"].ToString();
                }
                else
                {
                    model.name = OldModel.name;
                }
                if (!string.IsNullOrEmpty(Request.Params["event_desc"]))
                {
                    model.event_desc = Request.Params["event_desc"].ToString();
                }
                else
                {
                    model.event_desc = OldModel.event_desc;
                }
                if (!string.IsNullOrEmpty(Request.Params["vendor_coverage"]))
                {
                    model.vendor_coverage = Convert.ToInt32(Request.Params["vendor_coverage"].ToString());
                }
                else
                {
                    model.vendor_coverage = 0;
                }
                if (!string.IsNullOrEmpty(Request.Params["event_type"]))
                {
                    model.event_type = Request.Params["event_type"].ToString();
                }
                else
                {
                    model.event_type = OldModel.event_type;
                }
                if (Request.Params["amount"].ToString() != "" && Request.Params["amount"].ToString() != "0")
                {
                    if (!string.IsNullOrEmpty(Request.Params["amount"]))
                    {

                        model.amount = Convert.ToInt32(Request.Params["amount"].ToString());
                        model.quantity = 0;
                    }
                    else
                    {
                        model.amount = OldModel.amount;
                        model.quantity = 0;
                    }
                }
                else
                {
                    if (!string.IsNullOrEmpty(Request.Params["quantity"]))
                    {
                        model.quantity = Convert.ToInt32(Request.Params["quantity"].ToString());
                        model.amount = 0;
                    }
                    else
                    {
                        model.quantity = OldModel.quantity;
                        model.amount = 0;
                    }
                }

                if (model.id != 0)
                {
                    model.event_id = CommonFunction.GetEventId(model.event_type, model.id.ToString());
                }
                else
                {
                    model.event_id = CommonFunction.GetEventId(OldModel.event_type, OldModel.id.ToString());
                }
                #endregion

                #region 講圖片和鏈接保存至product_category中
                ////講圖片和鏈接保存至product_category中
                if (!string.IsNullOrEmpty(Request.Params["url_by"]))
                {
                    model.url_by = Convert.ToInt32(Request.Params["url_by"].ToString());
                    if (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 = model.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 = OldModel.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)//上傳成功
                                    {
                                        model.banner_image = fileName;
                                    }
                                }
                                catch (Exception)
                                {
                                    model.banner_image = OldModel.banner_image;
                                }
                            }
                        }
                        catch (Exception)
                        {
                            model.banner_image = OldModel.banner_image;
                        }

                        #endregion
                        if (!string.IsNullOrEmpty(Request.Params["banner_url"]))
                        {
                            model.category_link_url = Request.Params["banner_url"].ToString();
                        }
                        else
                        {
                            model.category_link_url = OldModel.category_link_url;
                        }

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


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

                            }
                            else
                            {
                                model.class_id = OldModel.class_id;
                            }
                        }
                        else
                        {
                            model.class_id = 0;
                        }

                        if (!string.IsNullOrEmpty(Request.Params["allClass"]))
                        {
                            if (Request.Params["allClass"] == "1")
                            {
                                model.quanguan = 1;
                                model.class_id = 0;
                                model.brand_id = 0;
                                model.product_id = 999999;
                            }
                            else
                            {
                                model.quanguan = 0;
                            }
                        }
                    }
                    else//非專區
                    {
                        model.category_link_url = "";
                        model.banner_image = "";

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


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

                            }
                            else
                            {
                                model.class_id = OldModel.class_id;
                            }
                        }
                        else
                        {
                            model.class_id = OldModel.class_id;
                        }

                        if (!string.IsNullOrEmpty(Request.Params["product_id"]))
                        {
                            model.product_id = Convert.ToInt32(Request.Params["product_id"].ToString());
                        }
                        else
                        {
                            model.product_id = OldModel.product_id;
                        }

                        if (!string.IsNullOrEmpty(Request.Params["noallClass"]))
                        {
                            if (Request.Params["noallClass"] == "1" || Request.Params["noallClass"] == "true")
                            {
                                model.quanguan = 1;
                                model.class_id = 0;
                                model.brand_id = 0;
                                model.product_id = 999999;
                            }
                            else
                            {
                                model.quanguan = 0;
                            }
                        }
                    }
                }
                else
                {
                    model.url_by = OldModel.url_by;
                }
                #endregion

                #region 獲取數據
                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))
                    {
                        model.group_id = Convert.ToInt32(Request.Params["group_id"].ToString());
                    }
                    else
                    {
                        model.group_id = OldModel.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")
                {
                    if (!string.IsNullOrEmpty(Request.Params["condition_id"]))//condition_id
                    {
                        model.condition_id = Convert.ToInt32(Request.Params["condition_id"].ToString());
                    }
                    else
                    {
                        model.condition_id = OldModel.condition_id;
                    }
                    model.group_id = 0;
                }


                if (!string.IsNullOrEmpty(Request.Params["count_by"]))
                {
                    model.count_by = Convert.ToInt32(Request.Params["count_by"].ToString());
                }
                else
                {
                    model.count_by = OldModel.count_by;
                }
                if (!string.IsNullOrEmpty(Request.Params["numLimit"]))
                {
                    model.num_limit = Convert.ToInt32(Request.Params["numLimit"].ToString());
                }
                else
                {
                    model.num_limit = OldModel.num_limit;
                }
                if (!string.IsNullOrEmpty(Request.Params["IsRepeat"]))
                {
                    model.repeat = Convert.ToInt32(Request.Params["IsRepeat"].ToString()) == 1 ? true : false;
                }
                else
                {
                    model.repeat = OldModel.repeat;
                }
                if (!string.IsNullOrEmpty(Request.Params["frieghttype"].ToString()))
                {
                    int typeId = 0;
                    if (int.TryParse(Request.Params["frieghttype"].ToString(), out typeId))
                    {
                        model.type = Convert.ToInt32(Request.Params["frieghttype"].ToString());
                    }
                    else
                    {
                        model.type = OldModel.type;
                    }
                }
                else
                {
                    model.type = OldModel.type;
                }
                if (!string.IsNullOrEmpty(Request.Params["devicename"]))
                {
                    model.device = Convert.ToInt32(Request.Params["devicename"].ToString());
                }
                else
                {
                    model.device = OldModel.device;
                }
                if (!string.IsNullOrEmpty(Request.Params["payment"].ToString()))
                {
                    Regex reg = new Regex("^([0-9]+,)*[0-9]+$");
                    if (reg.IsMatch(Request.Params["payment"].ToString()))
                    {
                        model.payment_code = Request.Params["payment"].ToString();
                    }
                    else
                    {
                        model.payment_code = OldModel.payment_code;
                    }
                }

                if (!string.IsNullOrEmpty(Request.Params["start_time"]))
                {
                    model.startdate = Convert.ToDateTime(Request.Params["start_time"].ToString());
                }
                else
                {
                    model.startdate = OldModel.startdate;
                }
                if (!string.IsNullOrEmpty(Request.Params["end_time"]))
                {
                    model.enddate = Convert.ToDateTime(Request.Params["end_time"].ToString());
                }
                else
                {
                    model.enddate = OldModel.enddate;
                }
                //int siteTranId = 0;
                //if (!string.IsNullOrEmpty(Request.Params["site"].ToString()) && int.TryParse(Request.Params["site"].ToString(), out siteTranId))//site
                //{
                //    model.site = Convert.ToInt32(Request.Params["site"].ToString());
                //}
                //else
                //{
                //    model.site = OldModel.site;
                //}
                if (!string.IsNullOrEmpty(Request.Params["site"].ToString()))//修改時傳的值為siteName
                {

                    Regex reg = new Regex("^([0-9]+,)*[0-9]+$");
                    if (reg.IsMatch(Request.Params["site"].ToString()))
                    {
                        model.site = Request.Params["site"].ToString();// 將站台改為多選 edit by shuangshuang0420j 20140925 10:08
                    }
                    else
                    {
                        model.site = OldModel.site;
                    }
                }
                #endregion

                #region 贈品處理
                if (!string.IsNullOrEmpty(Request.Params["gift_type"]))//gift_type when 1 then '商品' WHEN 2 then '機會' when 3  then '購物金' when 4 then '抵用券' 
                {
                    model.gift_type = Convert.ToInt32(Request.Params["gift_type"].ToString());
                    if (OldModel.gift_type == 2)
                    {
                        if (model.gift_type == 2)
                        {
                            if (OldModel.ticket_id != 0)
                            {
                                model.ticket_id = OldModel.ticket_id;
                            }
                            else
                            {
                                model.ticket_id = 0;
                            }
                            model.ticket_name = model.name;
                        }
                        else
                        {
                            if (_ptMgr.Delete(OldModel.ticket_id) > 0)
                            {
                                jsonStr = "{success:success}";
                                model.ticket_id = 0;
                                model.ticket_name = "";
                            }
                            else
                            {
                                jsonStr = "{success:false,msg:'promo_ticket刪除出錯!'}";
                                this.Response.Clear();
                                this.Response.Write(jsonStr.ToString());
                                this.Response.End();
                                return this.Response;
                            }
                        }
                    }
                    if (model.gift_type == 1)
                    {
                        model.gift_id = Convert.ToInt32(Request.Params["gift_id"].ToString());
                        model.gift_product_number = Convert.ToInt32(Request.Params["gift_product_number"].ToString());
                    }
                    else if (model.gift_type == 3)
                    {
                        model.bonus_type = 1;
                    }
                    else if (model.gift_type == 4)
                    {
                        model.bonus_type = 2;
                    }



                    if (!string.IsNullOrEmpty(Request.Params["activeNow"]))
                    {
                        model.active_now = Convert.ToInt32(Request.Params["activeNow"].ToString());
                    }
                    else
                    {
                        model.active_now = OldModel.active_now;
                    }
                    if (!string.IsNullOrEmpty(Request.Params["startdate"]))
                    {
                        model.use_start = Convert.ToDateTime(Request.Params["startdate"].ToString());
                    }
                    else
                    {

                        model.use_start = OldModel.use_start;
                    }
                    if (!string.IsNullOrEmpty(Request.Params["enddate"]))
                    {
                        model.use_end = Convert.ToDateTime(Request.Params["enddate"].ToString());
                    }
                    else
                    {

                        model.use_end = OldModel.use_end;
                    }
                    try
                    {
                        TimeSpan ts1 = new TimeSpan(model.use_end.Ticks);
                        TimeSpan ts2 = new TimeSpan(model.use_start.Ticks);
                        TimeSpan ts3 = ts1.Subtract(ts2).Duration();
                        int isAddDay = ts3.Hours > 0 ? 1 : 0;
                        model.valid_interval = ts3.Days + isAddDay;
                    }
                    catch
                    {
                        model.valid_interval = OldModel.valid_interval;
                    }
                    if (!string.IsNullOrEmpty(Request.Params["bonusAmount"]))
                    {
                        model.deduct_welfare = Convert.ToUInt32(Request.Params["bonusAmount"].ToString());
                    }
                    else
                    {
                        model.deduct_welfare = OldModel.deduct_welfare;
                    }
                }
                else
                {
                    model.gift_type = OldModel.gift_type;
                    model.ticket_id = OldModel.ticket_id;
                    model.ticket_name = OldModel.ticket_name;
                }
                #endregion

                model.status = 1;


                _promoAmountGiftMgr = new PromotionsAmountGiftMgr(mySqlConnectionString);
                if (string.IsNullOrEmpty(isEdit))
                {
                    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;
                    if (_promoAmountGiftMgr.Update(model, OldModel.event_id) > 0)
                    {
                        jsonStr = "{success:true,msg:0}";//返回json數據
                    }
                    else
                    {
                        jsonStr = "{success:false,msg:0}";//返回json數據
                    }
                }
                else
                {
                    model.kuser = OldModel.kuser;
                    model.created = OldModel.created;
                    model.muser = (System.Web.HttpContext.Current.Session["caller"] as Caller).user_id.ToString();
                    model.modified = DateTime.Now;

                    if (_promoAmountGiftMgr.Update(model, OldModel.event_id) > 0)
                    {

                        jsonStr = "{success:true,msg:0}";//返回json數據
                    }
                    else
                    {
                        jsonStr = "{success:false,msg:0}";//返回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,msg:0}";
            }
            this.Response.Clear();
            this.Response.Write(jsonStr.ToString());
            this.Response.End();
            return this.Response;
        }
Beispiel #9
0
 /// <summary>
 /// 查詢數據
 /// </summary>
 /// <param name="uc"></param>
 /// <returns></returns>
 public UserCondition Select(UserCondition uc)
 {
     StringBuilder sql = new StringBuilder();
     try
     {
         sql.AppendFormat("select * from user_condition where status = '1';");
         return _access.getSinggleObj<UserCondition>(sql.ToString());
     }
     catch (Exception ex)
     {
         throw new Exception("UserConditionMgr-->Select-->" + ex.Message + sql.ToString(), ex);
     }
 }
        /// <summary>
        /// 新增或修改數據
        /// </summary>
        /// <returns>數據庫操作結果</returns>
        public HttpResponseBase SavePromotionsAccumulateBonus()
        {
            string json = string.Empty;
            Caller caller = Session["caller"] as Caller;
            string rowid = Request.Form["rowid"];
            string name = Request.Form["name"];
            string group_id = Request.Form["group_id"];
            string startTime = Request.Form["startTime"];
            string end = Request.Form["end"];
            string bonus_rate = Request.Form["bonus_rate"];
            string extra_point = Request.Form["extra_point"];
            string bonus_expire_day = Request.Form["bonus_expire_day"];
            string new_user = Request.Form["new_user"];
            string repeat = Request.Form["repeatPresent"];
            string present_time = Request.Form["present_time"];
            string active = Request.Form["active"];
            string event_desc = Request.Form["event_desc"];
            string event_type = Request.Form["event_type"];
            string condition_id = Request.Form["condition_id"];
            string device = Request.Form["device"];
            string payment_code = Request.Form["payment_code"];
            int kuser = caller.user_id;

            string new_user_date = Request.Form["new_user_date"];

            PromotionsAccumulateBonus model=new PromotionsAccumulateBonus();
            int result = 0; //操作數據庫結果

            if (string.IsNullOrEmpty(rowid))    //新增
            {
                model.name = name;
                model.event_desc = event_desc;
                if (!string.IsNullOrEmpty(group_id) )
                {
                    model.group_id = Convert.ToInt32(group_id);
                    //判斷condition_id是否存在如果存在刪除原有數據
                    if (!string.IsNullOrEmpty(condition_id) && condition_id != "0")
                    {
                        UserCondition uc = new UserCondition();
                        uc.condition_id = Convert.ToInt32(condition_id);
                        _ucMgr.Delete(uc);
                    }
                    model.condition_id = 0;
                }
                else if (!string.IsNullOrEmpty(condition_id))
                {
                    model.condition_id = Convert.ToInt32(condition_id);
                    model.group_id = 0;
                }
                if (!string.IsNullOrEmpty(bonus_rate))
                {
                    model.bonus_rate = Convert.ToUInt32(bonus_rate);
                    model.extra_point = 0;
                }
                else if (!string.IsNullOrEmpty(extra_point))
                {
                    model.extra_point = Convert.ToInt32(extra_point);
                    model.bonus_rate = 0;
                }
                model.bonus_expire_day = Convert.ToInt32(bonus_expire_day);
                if (Convert.ToInt32(repeat) == 0)
                {
                    model.repeat = 0;
                    model.present_time = Convert.ToInt32(present_time);
                }
                else if (Convert.ToInt32(repeat) == 1)
                {
                    model.repeat = 1;
                    model.present_time = 0; //贈送次數清0
                }
                else if (Convert.ToInt32(repeat) == 2)
                {
                    model.repeat = 2;
                    model.present_time = 0; //贈送次數清0
                }
                if (!string.IsNullOrEmpty(Request.Params["payment"]))
                {
                    model.payment_code = Request.Params["payment"].ToString();
                }
                model.startTime = Convert.ToDateTime(startTime);
                model.end = Convert.ToDateTime(end);
                model.created = DateTime.Now;
                model.modified = DateTime.Now;
               
                model.muser = kuser;
                model.kuser = kuser;
                model.active = active == null ? false : true;
               

                try
                {
                    result = _promAccBnus.Save(model);
                    if (result == 1)
                    {
                        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,msg:'" + Resources.Promotion.ADD_FAIL + "'}";
                }
            }
            else    //修改
            {
                model = _promAccBnus.GetModel(Convert.ToInt32(rowid));
                model.name = name;
                model.event_desc = event_desc;
                if (!string.IsNullOrEmpty(group_id))
                {
                    try
                    {
                        model.group_id = Convert.ToInt32(group_id);
                        //判斷condition_id是否存在如果存在刪除原有數據
                        if (!string.IsNullOrEmpty(condition_id) && condition_id != "0")
                        {
                            UserCondition uc = new UserCondition();
                            uc.condition_id = Convert.ToInt32(condition_id);
                            _ucMgr.Delete(uc);
                        }
                        model.condition_id = 0; //將會員條件清0
                    }
                    catch
                    {
                    }
                }
                else if (!string.IsNullOrEmpty(condition_id))
                {
                    model.condition_id = Convert.ToInt32(condition_id);
                    model.group_id = 0; //將會員群組清0
                }
                if (!string.IsNullOrEmpty(bonus_rate))
                {
                    model.bonus_rate = Convert.ToUInt32(bonus_rate);
                    model.extra_point = 0;
                }
                else if (!string.IsNullOrEmpty(extra_point))
                {
                    model.extra_point = Convert.ToInt32(extra_point);
                    model.bonus_rate = 0;
                }
                model.bonus_expire_day = Convert.ToInt32(bonus_expire_day);
                if (!string.IsNullOrEmpty(new_user))
                {
                    model.new_user = false;
                }
                if (Convert.ToInt32(repeat)==0)
                {
                    model.repeat = 0;
                    model.present_time = 0;

                }
                else if (Convert.ToInt32(repeat)==1)
                {
                    model.repeat = 1;
                    //model.present_time = 0; //贈送次數清0
                    model.present_time = Convert.ToInt32(present_time);
                }
                else if (Convert.ToInt32(repeat)==2)
                {
                    model.repeat = 2;
                    //model.present_time = 0; //贈送次數清0
                    model.present_time = Convert.ToInt32(present_time);
                }
                if (!string.IsNullOrEmpty(Request.Params["payment"]))
                {
                    model.payment_code = Request.Params["payment"].ToString();
                }
                model.startTime = Convert.ToDateTime(startTime);
                model.end = Convert.ToDateTime(end);
                model.active = active == null ? false : true;
                model.modified = DateTime.Now;
                model.muser = kuser;
                try
                {
                    result = _promAccBnus.Update(model);
                    if (result == 1)
                    {
                        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,msg:'" + Resources.Promotion.SAVE_FAIL + "'}";
                }
            }

            this.Response.Clear();
            this.Response.Write(json);
            this.Response.End();
            return this.Response;
        } 
        //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則進行修改
            }
        }
        public HttpResponseBase UpdateTrial()
        {
            string jsonStr = String.Empty;
            int isTranInt = 0;
            try
            {
                string trial_id = Request.Params["trial_id"].ToString();
                string isEdit = Request.Params["isEdit"].ToString();
                _promotionsAmountTrialMgr = new PromotionsAmountTrialMgr(mySqlConnectionString);
                _ucMgr = new UserConditionMgr(mySqlConnectionString);
                PromotionsAmountTrialQuery model = new PromotionsAmountTrialQuery();
                PromotionsAmountTrialQuery OldModel = new PromotionsAmountTrialQuery();


                #region 第一面板數據
                if (!string.IsNullOrEmpty(Request.Params["trial_id"]))
                {
                    model.id = Convert.ToInt32(Request.Params["trial_id"]);
                    OldModel = _promotionsAmountTrialMgr.Select(model.id);
                }
                if (!string.IsNullOrEmpty(Request.Params["name"]))
                {//活動名稱
                    model.name = Request.Params["name"].ToString();
                }


                int event_type = 0;
                if (!string.IsNullOrEmpty(Request.Params["event_type"]))
                {
                    if (int.TryParse(Request.Params["event_type"], out event_type))
                    {
                        if (event_type == 1)
                        {
                            model.event_type = "T1";
                        }
                        else if (event_type == 2)
                        {
                            model.event_type = "T2";
                        }
                    }
                }
                model.event_id = CommonFunction.GetEventId(model.event_type, model.id.ToString());

                int paper_id = 0;
                if (int.TryParse(Request.Params["paper_id"].ToString(), out paper_id))
                {
                    model.paper_id = paper_id;
                }
                if (!string.IsNullOrEmpty(Request.Params["event_url"].ToString()))
                {
                    model.url = Request.Params["event_url"];
                }
                if (!string.IsNullOrEmpty(Request.Params["start_date"]))
                {
                    model.start_date = Convert.ToDateTime(Request.Params["start_date"].ToString());
                }

                if (!string.IsNullOrEmpty(Request.Params["end_date"]))
                {
                    model.end_date = Convert.ToDateTime(Request.Params["end_date"].ToString());
                }
                //活動描述
                if (!string.IsNullOrEmpty(Request.Params["event_desc"]))
                {
                    model.event_desc = Request.Params["event_desc"].ToString();
                }

                #endregion
                #region 第二面板數據
                if (!string.IsNullOrEmpty(Request.Params["group_id"].ToString()))
                {
                    if (int.TryParse(Request.Params["group_id"].ToString(), out isTranInt))
                    {
                        model.group_id = Convert.ToInt32(Request.Params["group_id"].ToString());
                    }
                    else
                    {
                        model.group_id = OldModel.group_id;
                    }
                    //當編輯活動時將會員條件改為會員群組則刪除原有的會員條件
                    if (OldModel.condition_id != 0)
                    {
                        UserCondition uc = new UserCondition();
                        uc.condition_id = OldModel.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;
                        }
                    }
                    //當活動設置完會員條件又改為會員群組時刪除設置的會員條件
                    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")
                {
                    model.condition_id = Convert.ToInt32(Request.Params["condition_id"].ToString());
                    model.group_id = 0;
                }
                if (!string.IsNullOrEmpty(Request.Params["count_by"]))
                {
                    model.count_by = Convert.ToInt32(Request.Params["count_by"].ToString());
                }
                if (!string.IsNullOrEmpty(Request.Params["numLimit"]))
                {
                    model.num_limit = Convert.ToInt32(Request.Params["numLimit"].ToString());
                }
                if (!string.IsNullOrEmpty(Request.Params["gift_mundane"]))
                {
                    model.gift_mundane = Convert.ToInt32(Request.Params["gift_mundane"].ToString());
                }

                if (!string.IsNullOrEmpty(Request.Params["IsRepeat"]))
                {
                    model.repeat = Convert.ToInt32(Request.Params["IsRepeat"].ToString()) == 1 ? true : false;
                }

                if (!string.IsNullOrEmpty(Request.Params["freight_type"].ToString()))
                {
                    if (int.TryParse(Request.Params["freight_type"].ToString(), out isTranInt))
                    {
                        model.freight_type = Convert.ToInt32(Request.Params["freight_type"].ToString());
                    }
                    else
                    {
                        model.freight_type = OldModel.freight_type;
                    }
                }

                if (!string.IsNullOrEmpty(Request.Params["device_name"]))
                {
                    model.device = Convert.ToInt32(Request.Params["device_name"].ToString());
                }

                if (!string.IsNullOrEmpty(Request.Params["site"].ToString()))//修改時傳的值為siteName
                {

                    Regex reg = new Regex("^([0-9]+,)*([0-9]+)$");
                    if (reg.IsMatch(Request.Params["site"].ToString()))
                    {
                        model.site = Request.Params["site"].ToString();// 將站台改為多選 edit by shuangshuang0420j 20140925 10:08
                    }
                    else
                    {
                        model.site = OldModel.site;
                    }
                }

                #endregion

                #region 第三面板數據

                if (!string.IsNullOrEmpty(Request.Params["product_id"]))
                {
                    model.product_id = Convert.ToInt32(Request.Params["product_id"].ToString());
                }
                if (!string.IsNullOrEmpty(Request.Params["product_name"]))
                {
                    model.product_name = Request.Params["product_name"].ToString();
                }
                if (!string.IsNullOrEmpty(Request.Params["sale_product_id"]))
                {
                    model.sale_productid = Convert.ToInt32(Request.Params["sale_product_id"].ToString());
                }
                model.category_id = Convert.ToUInt32(Request.Params["category_id"].ToString());
                model.brand_id = Convert.ToInt32(Request.Params["brand_id"].ToString());
                model.market_price = Convert.ToInt32(Request.Params["market_price"].ToString());
                model.show_number = Convert.ToInt32(Request.Params["show_number"].ToString());
                model.apply_limit = Convert.ToInt32(Request.Params["apply_limit"].ToString());
                model.apply_sum = Convert.ToInt32(Request.Params["apply_sum"].ToString());

                #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;//圖片存儲地址


                    string fileName = string.Empty;//當前文件名
                    string fileExtention = string.Empty;//當前文件的擴展名
                    bool result = false;
                    string NewFileName = string.Empty;//編譯后的文件名
                    string oldFile = "";
                    string ServerPath = string.Empty;
                    string ErrorMsg = string.Empty;


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

                    FileManagement fileLoad = new FileManagement();

                    for (int iFile = 0; iFile < Request.Files.Count; iFile++)
                    {
                        if (iFile == 0 && !string.IsNullOrEmpty(Request.Params["prod_file"]))
                        {
                            model.product_img = Request.Params["prod_file"].ToString().Substring(Request.Params["prod_file"].ToString().LastIndexOf("/") + 1);
                        }
                        else
                        {

                            HttpPostedFileBase file = Request.Files[iFile];

                            Random rand = new Random();
                            int newRand = rand.Next(1000, 9999);

                            fileName = Path.GetFileName(file.FileName);
                            if (fileName != "")
                            {

                                switch (iFile)
                                {
                                    case 1:
                                        oldFile = OldModel.event_img_small;
                                        break;
                                    case 2:
                                        oldFile = OldModel.event_img;
                                        break;
                                    case 0:
                                        oldFile = OldModel.product_img;
                                        break;
                                }

                                FTP ftp = new FTP(localPromoPath, ftpuser, ftppwd);
                                List<string> tem = ftp.GetFileList();
                                if (tem.Contains(oldFile))
                                {
                                    FTP ftps = new FTP(localPromoPath + oldFile, ftpuser, ftppwd);
                                    ftps.DeleteFile(localPromoPath + oldFile);//刪除ftp:71.159上的舊圖片
                                    DeletePicFile(ServerPath + oldFile);//刪除本地圖片
                                }

                                fileExtention = fileName.Substring(fileName.LastIndexOf(".")).ToLower();
                                NewFileName = model.event_id + newRand + fileExtention;

                                fileName = NewFileName;
                                NewFileName = localPromoPath + NewFileName;//絕對路徑
                                ServerPath = Server.MapPath(imgLocalServerPath + promoPath);
                                try
                                {
                                    //上傳
                                    result = fileLoad.UpLoadFile(file, ServerPath, NewFileName, extention, int.Parse(maxValue), int.Parse(minValue), ref ErrorMsg, ftpuser, ftppwd);
                                    if (result)//上傳成功
                                    {
                                        switch (iFile)
                                        {
                                            case 1:
                                                model.event_img_small = fileName;
                                                break;
                                            case 2:
                                                model.event_img = fileName;
                                                break;
                                            case 0:
                                                model.product_img = fileName;
                                                break;
                                        }

                                    }

                                }
                                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);
                                }
                            }
                            else
                            {
                                switch (iFile)
                                {
                                    case 1:
                                        model.event_img_small = OldModel.event_img_small;
                                        break;
                                    case 2:
                                        model.event_img = OldModel.event_img;
                                        break;
                                    case 0:
                                        model.product_img = OldModel.product_img;
                                        break;
                                }

                            }
                        }
                    }
                }
                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);
                }

                #endregion

                #endregion


                #region     更新表結構
                if (string.IsNullOrEmpty(isEdit))//新增數據
                {
                    model.active = 0;//默認不啟用
                    model.status = 1;//第二步保存為有效數據
                    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;
                    if (_promotionsAmountTrialMgr.Update(model) > 0)
                    {

                        jsonStr = "{success:true,msg:0}";//返回json數據
                    }
                    else
                    {
                        jsonStr = "{success:false,msg:0}";//返回json數據
                    }
                }
                else//編輯數據
                {
                    model.active = OldModel.active;
                    model.status = OldModel.status;
                    model.kuser = OldModel.kuser;
                    model.created = OldModel.created;
                    model.muser = (System.Web.HttpContext.Current.Session["caller"] as Caller).user_id.ToString();
                    model.modified = DateTime.Now;
                    if (_promotionsAmountTrialMgr.Update(model) > 0)
                    {

                        jsonStr = "{success:true,msg:0}";//返回json數據
                    }
                    else
                    {
                        jsonStr = "{success:false,msg:0}";//返回json數據
                    }
                }
                #endregion
            }
            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:0}";
            }
            this.Response.Clear();
            this.Response.Write(jsonStr.ToString());
            this.Response.End();
            return this.Response;
        }
        public HttpResponseBase SecondSaveFare()
        {
            string jsonStr = String.Empty;
            int stringTranInt = 0;//使用tryParse使string轉換為int時保存轉換的值
            try
            {
                string rowID = Request.Params["rowid"].ToString() ?? "0";
                string isEdit = Request.Params["isEdit"].ToString() ?? "";
                _promoAmountFareMgr = new PromotionsAmountFareMgr(mySqlConnectionString);
                PromotionsAmountFareQuery model = new PromotionsAmountFareQuery();

                PromotionsAmountFareQuery OldModel = _promoAmountFareMgr.Select(Convert.ToInt32(rowID));

                #region 獲取數據
                if (!string.IsNullOrEmpty(Request.Params["rowid"]))
                {
                    model.id = Convert.ToInt32(Request.Params["rowid"]);
                }
                else
                {
                    model.id = 0;
                }
                model.category_id = OldModel.category_id;
                if (!string.IsNullOrEmpty(Request.Params["name"]))
                {
                    model.name = Request.Params["name"].ToString();
                }
                else
                {
                    model.name = OldModel.name;
                }
                if (!string.IsNullOrEmpty(Request.Params["desc"]))
                {
                    model.event_desc = Request.Params["desc"].ToString();
                }

                else
                {
                    model.event_desc = OldModel.event_desc;
                }
                if (!string.IsNullOrEmpty(Request.Params["vendor_coverage"]))
                {
                    model.vendor_coverage = Convert.ToInt32(Request.Params["vendor_coverage"].ToString());
                }
                else
                {
                    model.vendor_coverage = 0;
                }
                if (!string.IsNullOrEmpty(Request.Params["sclass_id"]))
                {
                    if (int.TryParse(Request.Params["sclass_id"].ToString(), out stringTranInt))
                    {
                        model.class_id = Convert.ToInt32(Request.Params["sclass_id"].ToString() == "" ? "0" : Request.Params["sclass_id"].ToString());
                    }
                    else
                    {
                        model.class_id = OldModel.class_id;
                    }
                }
                else
                {
                    model.class_id = 0;
                }
                if (!string.IsNullOrEmpty(Request.Params["sbrand_id"]))
                {
                    if (int.TryParse(Request.Params["sbrand_id"].ToString(), out stringTranInt))
                    {
                        model.brand_id = Convert.ToInt32(Request.Params["sbrand_id"].ToString() == "" ? "0" : Request.Params["sbrand_id"].ToString());

                    }
                    else
                    {
                        model.brand_id = OldModel.brand_id;
                    }
                }
                else
                {
                    model.brand_id = 0;
                }
                if (!string.IsNullOrEmpty(Request.Params["allClass"]))
                {
                    model.allClass = Convert.ToInt32(Request.Params["allClass"].ToString() == "1" ? "1" : "0");
                    if (1 == model.allClass)
                    {
                        model.product_id = 999999;
                    }

                }
                else
                {
                    model.allClass = 0;
                }

                if (!string.IsNullOrEmpty(Request.Params["event_type"]))
                {
                    //獲取event_type和category_father_id
                    _parasrcMgr = new ParameterMgr(mySqlConnectionString);
                    List<Parametersrc> fatherIdResult = _parasrcMgr.QueryUsed(new Parametersrc { ParameterType = "event_type", parameterName = Request.Params["event_type"].ToString(), Used = 1 });
                    if (fatherIdResult.Count == 1)
                    {
                        model.event_type = fatherIdResult[0].ParameterCode;
                        model.category_father_id = Convert.ToUInt32(fatherIdResult[0].ParameterProperty);
                    }
                }

                if (!string.IsNullOrEmpty(Request.Params["amount"]))
                {
                    model.amount = Convert.ToInt32(Request.Params["amount"].ToString());
                }
                else
                {
                    model.amount = OldModel.amount;
                }
                if (!string.IsNullOrEmpty(Request.Params["quantity"]))
                {
                    model.quantity = Convert.ToInt32(Request.Params["quantity"].ToString());
                }
                else
                {
                    model.quantity = OldModel.quantity;
                }
                if (!string.IsNullOrEmpty(Request.Params["fare_percent"]))
                {
                    model.fare_percent = Convert.ToInt32(Request.Params["fare_percent"].ToString());
                }
                else
                {
                    model.fare_percent = OldModel.fare_percent;
                }
                if (!string.IsNullOrEmpty(Request.Params["off_times"]))
                {
                    model.off_times = Convert.ToInt32(Request.Params["off_times"].ToString());
                }
                else
                {
                    model.off_times = OldModel.off_times;
                }
                if (model.id != 0)
                {
                    model.event_id = BLL.gigade.Common.CommonFunction.GetEventId(model.event_type, model.id.ToString());
                }

                if (Request.Params["group_id"].ToString() != "")
                {//會員群組不為空時,要清空已存在的會員條件
                    if (!string.IsNullOrEmpty(Request.Params["group_id"].ToString()) && int.TryParse(Request.Params["group_id"].ToString(), out stringTranInt))//group_id
                    {
                        model.group_id = Convert.ToInt32(Request.Params["group_id"].ToString());
                    }
                    else
                    {
                        model.group_id = OldModel.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"]);
                        _ucMgr = new UserConditionMgr(mySqlConnectionString);
                        if (_ucMgr.Delete(uc) > 0)
                        {
                            jsonStr = "{success:true}";
                            model.condition_id = 0;
                        }
                        else
                        {
                            jsonStr = "{success:false,msg:3}";
                            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 = OldModel.condition_id;
                    }
                    model.group_id = 0;
                }
                if (!string.IsNullOrEmpty(Request.Params["type"]) && int.TryParse(Request.Params["type"].ToString(), out stringTranInt))
                {
                    model.type = Convert.ToInt32(Request.Params["type"].ToString());
                }
                else
                {
                    model.type = OldModel.type;
                }
                if (!string.IsNullOrEmpty(Request.Params["deliver"].ToString()) && int.TryParse(Request.Params["deliver"].ToString(), out stringTranInt))
                {
                    model.delivery_store = Convert.ToInt32(Request.Params["deliver"].ToString());
                }
                else
                {
                    model.delivery_store = OldModel.delivery_store;
                }
                if (!string.IsNullOrEmpty(Request.Params["devicename"].ToString()))
                {
                    model.device = Convert.ToInt32(Request.Params["devicename"].ToString());
                }
                else
                {
                    model.device = OldModel.device;
                }
                if (!string.IsNullOrEmpty(Request.Params["payment"].ToString()))
                {
                    Regex reg = new Regex("^([0-9]+,)*[0-9]+$");
                    if (reg.IsMatch(Request.Params["payment"].ToString()))
                    {
                        model.payment_code = Request.Params["payment"].ToString();
                    }
                    else
                    {
                        model.payment_code = OldModel.payment_code;
                    }
                }
                if (!string.IsNullOrEmpty(Request.Params["start_time"].ToString()))
                {
                    model.start = Convert.ToDateTime(Request.Params["start_time"].ToString());
                }
                else
                {
                    model.start = OldModel.start_time;
                }
                if (!string.IsNullOrEmpty(Request.Params["end_time"].ToString()))
                {
                    model.end = Convert.ToDateTime(Request.Params["end_time"].ToString());
                }
                else
                {
                    model.end = OldModel.end_time;
                }
                if (!string.IsNullOrEmpty(Request.Params["site"].ToString()))
                {
                    Regex reg = new Regex("^([0-9]+,)*[0-9]+$");
                    if (reg.IsMatch(Request.Params["site"].ToString()))
                    {
                        model.site = Request.Params["site"].ToString();
                    }
                    else
                    {
                        model.site = OldModel.site;
                    }
                }

                model.status = 1;
                if (!string.IsNullOrEmpty(Request.Params["url_by"].ToString()))
                {
                    model.url_by = Convert.ToInt32(Request.Params["url_by"].ToString());
                }
                else
                {
                    model.url_by = OldModel.url_by;
                }

                #endregion
                ////講圖片和鏈接保存至product_category中

                if (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);//獲取隨機數重命名圖片


                        if (Request.Files.Count > 0)
                        {

                            HttpPostedFileBase file = Request.Files[0];
                            string fileName = string.Empty;//當前文件名

                            string fileExtention = string.Empty;//當前文件的擴展名

                            fileName = Path.GetFileName(file.FileName);
                            if (fileName != "")
                            {
                                // string returnName = imgServerPath;
                                bool result = false;
                                string NewFileName = string.Empty;

                                fileExtention = fileName.Substring(fileName.LastIndexOf(".")).ToLower();
                                NewFileName = model.event_id + newRand + fileExtention;

                                string ServerPath = string.Empty;
                                //判斷目錄是否存在,不存在則創建
                                CreateFolder(localPromoPath.Substring(0, localPromoPath.Length - promoPath.Length + 1), promoPath.Substring(1, promoPath.Length - 2).Split('/'));
                                fileName = NewFileName;
                                NewFileName = localPromoPath + NewFileName;//絕對路徑
                                ServerPath = Server.MapPath(imgLocalServerPath + promoPath);
                                string ErrorMsg = string.Empty;
                                //上傳之前刪除已有的圖片
                                string oldFileName = OldModel.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);//刪除本地圖片
                                }
                                FileManagement fileLoad = new FileManagement();
                                //上傳
                                result = fileLoad.UpLoadFile(file, ServerPath, NewFileName, extention, int.Parse(maxValue), int.Parse(minValue), ref ErrorMsg, ftpuser, ftppwd);
                                if (result)//上傳成功
                                {
                                    model.banner_image = fileName;
                                }

                            }
                            else
                            {
                                model.banner_image = OldModel.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:0}";
                        model.banner_image = OldModel.banner_image;
                    }

                    #endregion
                    if (!string.IsNullOrEmpty(Request.Params["banner_url"].ToString()))
                    {
                        model.category_link_url = Request.Params["banner_url"].ToString();
                    }
                    else
                    {
                        model.category_link_url = OldModel.category_link_url;
                    }

                }
                else//url_by=0
                {
                    //刪除上傳的圖片
                    string oldFileName = OldModel.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);//刪除本地圖片
                    }
                    model.category_link_url = "";
                    model.banner_image = "";
                }

                _promoAmountFareMgr = new PromotionsAmountFareMgr(mySqlConnectionString);
                if (string.IsNullOrEmpty(isEdit))
                {
                    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;
                    if (_promoAmountFareMgr.ReSave(model) > 0)
                    {
                        jsonStr = "{success:true,msg:0}";//返回json數據
                    }
                    else
                    {
                        jsonStr = "{success:false,msg:0}";//返回json數據
                    }
                }
                else
                {
                    model.kuser = OldModel.kuser;
                    model.created = OldModel.created;
                    model.muser = (System.Web.HttpContext.Current.Session["caller"] as Caller).user_id.ToString();
                    model.modified = DateTime.Now;
                    if (_promoAmountFareMgr.Update(model, OldModel.event_id) > 0)
                    {
                        jsonStr = "{success:true,msg:0}";//返回json數據
                    }
                    else
                    {
                        jsonStr = "{success:false,msg:0}";//返回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,msg:0}";
            }
            this.Response.Clear();
            this.Response.Write(jsonStr.ToString());
            this.Response.End();
            return this.Response;
        }