/// <summary>
        /// 更改活動使用狀態
        /// </summary>
        /// <returns>數據庫操作結果</returns>
        public JsonResult UpdateActive()
        {
            string jsonStr = string.Empty;
            try
            {
                string currentUser = (System.Web.HttpContext.Current.Session["caller"] as Caller).user_id.ToString();
                string muser = string.Empty;
                int activeValue = Convert.ToInt32(Request.Params["active"]);
                if (!string.IsNullOrEmpty(Request.Params["muser"]))
                {
                    muser = (Request.Params["muser"]);
                }
                if (currentUser == muser && activeValue == 1)
                {
                    return Json(new { success = "stop" });
                }
                _promotionsAmountTrialMgr = new PromotionsAmountTrialMgr(mySqlConnectionString);
                int id = Convert.ToInt32(Request.Params["id"]);
                PromotionsAmountTrialQuery model = _promotionsAmountTrialMgr.Select(id);

                model.active = activeValue;
                model.id = id;
                model.muser = currentUser;
                model.modified = DateTime.Now;

                if (_promotionsAmountTrialMgr.UpdateActive(model) > 0)
                {
                    return Json(new { success = "true" });
                }
                else
                {
                    return Json(new { 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);
                return Json(new { success = "false" });
            }

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