public int GetDefault(WebContentType6 model)
 {
     try
     {
         return _wctdao.GetDefault(model);
     }
     catch (Exception ex)
     {
         throw new Exception("WebContentType6Mgr.GetDefault-->" + ex.Message, ex);
     }
 }
    /// <summary>
    /// 獲取已啟用的個數
    /// </summary>
    /// <returns></returns>
    public int GetDefault(WebContentType6 model)
    {
        StringBuilder sql = new StringBuilder("");
        try
        {
              sql.AppendFormat(@" select count(*) as countSta from web_content_type6 where content_status=1 and  pag_id='{0}';", model.page_id);
        return Convert.ToInt32(_access.getDataTable(sql.ToString()).Rows[0]["countSta"].ToString());
  
        }
        catch (Exception ex)
        {
            throw new Exception("WebContentType6Dao.GetDefault-->" + ex.Message + sql.ToString(), ex); 
        }
      
 }
        /// <summary>
        /// 更改活動使用狀態
        /// </summary>
        /// <returns>數據庫操作結果</returns>
        public JsonResult UpdateActive()
        {
            string storeType = Request.Params["storeType"].ToString();
            switch (storeType)
            {
                case "type1":
                    WebContentType1 model1 = new WebContentType1();
                    model1.content_id = Convert.ToInt32(Request.Params["id"]);
                    model1 = _wctMgr1.GetModel(model1);
                    model1.content_status = Convert.ToInt32(Request.Params["active"]);
                    model1.content_default = 1;
                    if (_wctMgr1.Update(model1) > 0)
                    {
                        return Json(new { success = "true", msg = "" });
                    }
                    else
                    {
                        return Json(new { success = "false", msg = "" });
                    }

                case "type2":
                    WebContentType2 model2 = new WebContentType2();
                    model2.content_id = Convert.ToInt32(Request.Params["id"]);
                    model2 = _wctMgr2.GetModel(model2);
                    model2.content_status = Convert.ToInt32(Request.Params["active"]);
                    model2.content_default = 1;
                    if (_wctMgr2.Update(model2) > 0)
                    {
                        return Json(new { success = "true", msg = "" });
                    }
                    else
                    {
                        return Json(new { success = "false", msg = "" });
                    }

                case "type3":
                    WebContentType3 model3 = new WebContentType3();
                    model3.content_id = Convert.ToInt32(Request.Params["id"]);
                    model3 = _wctMgr3.GetModel(model3);
                    model3.content_status = Convert.ToInt32(Request.Params["active"]);
                    model3.content_default = 1;
                    if (_wctMgr3.Update(model3) > 0)
                    {
                        return Json(new { success = "true", msg = "" });
                    }
                    else
                    {
                        return Json(new { success = "false", msg = "" });
                    }

                case "type4":
                    WebContentType4 model4 = new WebContentType4();
                    model4.content_id = Convert.ToInt32(Request.Params["id"]);
                    model4 = _wctMgr4.GetModel(model4);
                    model4.content_status = Convert.ToInt32(Request.Params["active"]);
                    model4.content_default = 1;
                    if (_wctMgr4.Update(model4) > 0)
                    {
                        return Json(new { success = "true", msg = "" });
                    }
                    else
                    {
                        return Json(new { success = "false", msg = "" });
                    }

                case "type5":
                    WebContentType5 model5 = new WebContentType5();
                    model5.content_id = Convert.ToInt32(Request.Params["id"]);
                    model5 = _wctMgr5.GetModel(model5);
                    model5.content_status = Convert.ToInt32(Request.Params["active"]);
                    model5.content_default = 1;
                    if (_wctMgr5.Update(model5) > 0)
                    {
                        return Json(new { success = "true", msg = "" });
                    }
                    else
                    {
                        return Json(new { success = "false", msg = "" });
                    }

                case "type6":
                    WebContentType6 model6 = new WebContentType6();
                    model6.content_id = Convert.ToInt32(Request.Params["id"]);
                    model6 = _wctMgr6.GetModel(model6);
                    model6.content_status = Convert.ToInt32(Request.Params["active"]);
                    model6.content_default = 1;
                    if (_wctMgr6.Update(model6) > 0)
                    {
                        return Json(new { success = "true", msg = "" });
                    }
                    else
                    {
                        return Json(new { success = "false", msg = "" });
                    }

                case "type7":
                    WebContentType7 model7 = new WebContentType7();
                    model7.content_id = Convert.ToInt32(Request.Params["id"]);
                    model7 = _wctMgr7.GetModel(model7);
                    model7.content_status = Convert.ToInt32(Request.Params["active"]);
                    model7.content_default = 1;
                    if (_wctMgr7.Update(model7) > 0)
                    {
                        return Json(new { success = "true", msg = "" });
                    }
                    else
                    {
                        return Json(new { success = "false", msg = "" });
                    }

                case "type8":
                    WebContentType8 model8 = new WebContentType8();
                    model8.content_id = Convert.ToInt32(Request.Params["id"]);
                    model8 = _wctMgr8.GetModel(model8);
                    model8.content_status = Convert.ToInt32(Request.Params["active"]);
                    model8.content_default = 1;
                    if (_wctMgr8.Update(model8) > 0)
                    {
                        return Json(new { success = "true", msg = "" });
                    }
                    else
                    {
                        return Json(new { success = "false", msg = "" });
                    }
                default:
                    return Json(new { success = "false", msg = "" });

            }
        }
        /// <summary>
        /// 獲取參數表中設置的限制值
        /// </summary>
        /// <returns>數據庫操作結果</returns>
        public JsonResult GetDefaultLimit()
        {
            int statusListNum = 0; int limitNumStatus = 0;
            WebContentTypeSetup model = new WebContentTypeSetup();
            model.web_content_type = Request.Params["storeType"].ToString();
            model.site_id = Convert.ToInt32(Request.Params["site"].ToString());
            model.page_id = Convert.ToInt32(Request.Params["page"]);
            model.area_id = Convert.ToInt32(Request.Params["area"]);
            limitNumStatus = _wctsuMgr.Query(model)[0].content_status_num;

            if (limitNumStatus != 0 && !string.IsNullOrEmpty(limitNumStatus.ToString()))
            {

                switch (model.web_content_type)
                {
                    case "web_content_type1":
                        WebContentType1 model1 = new WebContentType1();
                        model1.page_id = model.page_id;
                        statusListNum = _wctMgr1.GetDefault(model1);//獲取列表中已啟用的數量
                        break;
                    case "web_content_type2":
                        WebContentType2 model2 = new WebContentType2();
                        model2.page_id = model.page_id;
                        statusListNum = _wctMgr2.GetDefault(model2);
                        break;
                    case "web_content_type3":
                        WebContentType3 model3 = new WebContentType3();
                        model3.page_id = model.page_id;
                        statusListNum = _wctMgr3.GetDefault(model3);
                        break;
                    case "web_content_type4":
                        WebContentType4 model4 = new WebContentType4();
                        model4.page_id = model.page_id;
                        statusListNum = _wctMgr4.GetDefault(model4);
                        break;
                    case "web_content_type5":
                        WebContentType5 model5 = new WebContentType5();
                        model5.page_id = model.page_id;
                        statusListNum = _wctMgr5.GetDefault(model5);
                        break;
                    case "web_content_type6":
                        WebContentType6 model6 = new WebContentType6();
                        model6.page_id = model.page_id;
                        statusListNum = _wctMgr6.GetDefault(model6);
                        break;
                    case "web_content_type7":
                        WebContentType7 model7 = new WebContentType7();
                        model7.page_id = model.page_id;
                        statusListNum = _wctMgr7.GetDefault(model7);
                        break;
                    case "web_content_type8":
                        WebContentType8 model8 = new WebContentType8();
                        model8.page_id = model.page_id;
                        statusListNum = _wctMgr8.GetDefault(model8);
                        break;
                    default:
                        break;

                }
            }
            return Json(new { success = "true", listNum = statusListNum, limitNum = limitNumStatus });
        }
        protected HttpResponseBase updateWebContentType6(WebContentType6 model)
        {
            string json = string.Empty;
            try
            {
                if (!model.link_url.Contains('?'))
                {
                    model.link_url = model.link_url + "?content_id=" + model.content_id;
                }
                _wctMgr6.Update(model);

                json = "{success:true}";//返回json數據
            }
            catch (Exception ex)
            {
                Log4NetCustom.LogMessage logMessage = new Log4NetCustom.LogMessage();
                logMessage.Content = string.Format("TargetSite:{0},Source:{1},Message:{2}", ex.TargetSite.Name, ex.Source, ex.Message);
                logMessage.MethodName = System.Reflection.MethodBase.GetCurrentMethod().Name;
                log.Error(logMessage);
                json = "{success:false}";
            }
            this.Response.Clear();
            this.Response.Write(json);
            this.Response.End();
            return this.Response;
        }
        public HttpResponseBase SaveWebContentType6()
        {
            WebContentType6 model = new WebContentType6();
            WebContentType6 oldModel = new WebContentType6();
            if (!String.IsNullOrEmpty(Request.Params["rowid"]))//如果不存在該id說明是添加頁面
            {
                model.content_id = Convert.ToInt32(Request.Params["rowid"].ToString());
                oldModel = _wctMgr6.GetModel(model);
            }
            #region 獲取數據
            model.site_id = 7;
            try
            {
                model.page_id = Convert.ToInt32(Request.Params["page_id"].ToString());
            }
            catch
            {
                model.page_id = oldModel.page_id;
            }
            try
            {
                model.area_id = Convert.ToInt32(Request.Params["area_id"].ToString());
            }
            catch
            {
                model.area_id = oldModel.area_id;
            }
            #region 圖片上傳
            try
            {
                ImagePathConfig();
                for (int iFile = 0; iFile < Request.Files.Count; iFile++)
                {
                    HttpPostedFileBase file = Request.Files[iFile];
                    string fileName = string.Empty;//當前文件名
                    string fileExtention = string.Empty;//當前文件的擴展名
                    //獲取圖片名稱

                    fileName = fileLoad.NewFileName(file.FileName);
                    if (fileName != "")
                    {
                        fileName = fileName.Substring(0, fileName.LastIndexOf("."));
                        fileExtention = file.FileName.Substring(file.FileName.LastIndexOf('.')).ToLower().ToString();

                        string NewFileName = string.Empty;
                        BLL.gigade.Common.HashEncrypt hash = new BLL.gigade.Common.HashEncrypt();
                        NewFileName = hash.Md5Encrypt(fileName, "32");
                        string ServerPath = string.Empty;
                        //判斷目錄是否存在,不存在則創建
                        FTP f_cf = new FTP();
                        f_cf.MakeMultiDirectory(localHealthPath.Substring(0, localHealthPath.Length - healthPath.Length + 1), healthPath.Substring(1, healthPath.Length - 2).Split('/'), ftpuser, ftppwd);
                        // CreateFolder(localPromoPath.Substring(0, localPromoPath.Length - healthPath.Length + 1), healthPath.Substring(1, healthPath.Length - 2).Split('/'));
                        //  returnName += promoPath + NewFileName;
                        fileName = NewFileName + fileExtention;
                        NewFileName = localHealthPath + NewFileName + fileExtention;//絕對路徑
                        ServerPath = Server.MapPath(imgLocalServerPath + healthPath);
                        string ErrorMsg = string.Empty;
                        //上傳之前刪除已有的圖片
                        if (model.content_id != 0)
                        {
                            string oldFileName = oldModel.home_image;
                            CommonFunction.DeletePicFile(ServerPath + oldFileName);//刪除本地圖片
                            FTP ftp = new FTP(localHealthPath, ftpuser, ftppwd);
                            List<string> tem = ftp.GetFileList();
                            if (tem.Contains(oldFileName))
                            {
                                FTP ftps = new FTP(localHealthPath + oldFileName, ftpuser, ftppwd);
                                ftps.DeleteFile(localHealthPath + oldFileName);//刪除ftp:71.159上的舊圖片
                            }
                        }
                        try
                        {//上傳     
                            Resource.CoreMessage = new CoreResource("Product");//尋找product.resx中的資源文件
                            bool result = fileLoad.UpLoadFile(file, ServerPath, NewFileName, extention, int.Parse(maxValue), int.Parse(minValue), ref ErrorMsg, ftpuser, ftppwd);
                            if (result)//上傳成功
                            {
                                model.home_image = fileName;
                            }
                        }
                        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);
                            model.home_image = oldModel.home_image;
                        }
                        if (!string.IsNullOrEmpty(ErrorMsg))
                        {
                            string json = string.Empty;
                            json = "{success:true,msg:\"" + ErrorMsg + "\"}";
                            this.Response.Clear();
                            this.Response.Write(json);
                            this.Response.End();
                            return this.Response;
                        }
                    }
                    else
                    {
                        model.home_image = oldModel.home_image;
                    }
                }
            }
            catch (Exception)
            {

                model.home_image = oldModel.home_image;
            }
            #endregion
            model.home_title = Request.Params["home_title"].ToString();
            model.content_title = Request.Params["content_title"].ToString();
            model.content_html = Request.Params["content_html"].ToString();
            //model.content_default = Convert.ToInt32(Request.Params["content_default"]);
            model.content_status = Convert.ToInt32(Request.Params["content_status"]);
            model.link_url = Request.Params["link_url"].ToString();
            model.link_mode = Convert.ToInt32(Request.Params["link_mode"]);
            model.keywords = Request.Params["keywords"].ToString();
            string[] teshu = { "<", ">", "~", "!", "@", "#", "$", "%", "^", "&", "*", "(", ")", "_", "-", "+", "=", "?", ":", ";", "'", "`", "{", "}", "[", "]" };
            foreach (string item in teshu)
            {
                model.keywords = model.keywords.Replace(item, "").ToString();
            }
            model.keywords = model.keywords.Replace(",", ",").ToString();
            #endregion
            //判斷是否能夠獲取到rowid
            if (String.IsNullOrEmpty(Request.Params["rowid"]))//如果不存在該id說明是添加頁面
            {
                model.created_on = DateTime.Now;
                model.update_on = model.created_on;
                //這裡加上各種參數
                return InsertWebContentType6(model);//如果獲取不到則進行新增
            }
            else
            {
                model.update_on = DateTime.Now;
                //這裡加上各種參數
                return updateWebContentType6(model);//如果可以獲取到rowid則進行修改
            }
        }