public int DeleteKeyWords(DisableKeywordsQuery query)
        {
            int result = 0;
            string sql = string.Empty;
            int dk_id=0;
            try
            {
                string[] arrID = query.ids.Split(',');
                foreach (var id in arrID)
                {
                    if (int.TryParse(id, out dk_id))
                    {
                        sql = _dkDao.DeleteKeyWords(id);
                        result = _dbAccess.execCommand(sql);
                        if (result > 0)
                        {
                            continue;
                        }
                    }
                    else
                    {
                        return result;
                    }
                }
                return result;
            }
            catch (Exception ex)
            {

                throw new Exception("DisableKeywordsDao-->DeleteKeyWords-->" + ex.Message, ex);
            }
        }
 public DataTable GetKeyWordsList(DisableKeywordsQuery query,out int totalCount)
 {
     try
     {
         DataTable store = new DataTable();
         store = _dkDao.GetKeyWordsList(query,out totalCount);
         return store;
     }
     catch (Exception ex)
     {
         throw new Exception("DisableKeywordsDao-->GetKeyWordsList-->" + ex.Message, ex);
     }
 }
        public int UpdateKeyWords(DisableKeywordsQuery query)
        {
            int result = 0;
            try
            {
                string sql = _dkDao.UpdateKeyWords(query);
                result = _dbAccess.execCommand(sql);
                return result;
            }
            catch (Exception ex)
            {

                throw new Exception("DisableKeywordsDao-->AddKeyWords-->" + ex.Message, ex);
            }
        }
        public string AddKeyWords(DisableKeywordsQuery query)
        {
            StringBuilder strSql = new StringBuilder();
            query.Replace4MySQL();
            try
            {
                strSql.AppendFormat(@"INSERT INTO disable_keywords(dk_string,user_id,dk_created) VALUES ('{0}','{1}',NOW());", query.dk_string, query.user_id);
                return strSql.ToString();
            }
            catch (Exception ex)
            {

                throw new Exception("DisableKeywordsDao-->AddKeyWords-->" + ex.Message + strSql.ToString(), ex);
            }
        }
        public DataTable GetKeyWordsList(DisableKeywordsQuery query,out int totalCount)
        {
            StringBuilder strSql = new StringBuilder();
            StringBuilder count = new StringBuilder();
            DataTable store = new DataTable();
            totalCount = 0;
            try
            {
                strSql.AppendFormat(@"SELECT dk_id,dk_string,u.user_username as user_name,dk_created,dk_modified,dk_active from disable_keywords dk,manage_user u WHERE u.user_id = dk.user_id");
                count.AppendFormat(@"select count(dk_id) as totalCount from disable_keywords WHERE 1=1");
                if (query.end != DateTime.MinValue && query.start != DateTime.MinValue)
                {
                    strSql.AppendFormat(" AND dk_created BETWEEN '{0}' AND '{1}'", Common.CommonFunction.DateTimeToString(query.start), Common.CommonFunction.DateTimeToString(query.end));
                    count.AppendFormat("  AND dk_created BETWEEN '{0}' AND '{1}'", Common.CommonFunction.DateTimeToString(query.start), Common.CommonFunction.DateTimeToString(query.end));
                }
                if (query.search_text != "")
                {
                    strSql.AppendFormat(" AND dk_string LIKE N'%{0}%'", query.search_text);
                    count.AppendFormat(" AND dk_string LIKE N'%{0}%'", query.search_text);
                }
                if (query.IsPage)
                {
                    DataTable dt = _dbAccess.getDataTable(count.ToString());
                    if (dt != null && dt.Rows.Count > 0)
                    {
                        totalCount = Convert.ToInt32(dt.Rows[0][0]);
                    }
                }
                strSql.AppendFormat(" order by dk_id desc limit {0},{1}", query.Start, query.Limit);
                store = _dbAccess.getDataTable(strSql.ToString());
                return store;
            }
            catch (Exception ex)
            {

                throw new Exception("DisableKeywordsDao-->GetKeyWordsList-->" + ex.Message + strSql.ToString(), ex);
            }
        }
 public string UpdateStatus(DisableKeywordsQuery query)
 {
     string josn;
     string sql="";
     try
     {
         if (query.dk_active == 0)
         {
             query.dk_active = 1;
         }
         else
         {
             query.dk_active = 0;
         }
         sql = _dkDao.UpdateStatus(query);
         if (_dbAccess.execCommand(sql)>0)
         {
             josn = "{success:true}";
         }
         else
         {
             josn = "{success:false}";
         }
         return josn;
     }
     catch (Exception ex)
     {
         throw new Exception("DisableKeywordsDao-->UpdateStatus-->" + ex.Message + sql, ex);
     }
 }
        public string UpdateKeyWords(DisableKeywordsQuery query)
        {
            query.Replace4MySQL();
            StringBuilder strSql = new StringBuilder();
            try
            {
                strSql.AppendFormat(@"UPDATE disable_keywords SET dk_string='{0}' WHERE dk_id='{1}'", query.dk_string, query.dk_id);
                return strSql.ToString();
            }
            catch (Exception ex)
            {

                throw new Exception("DisableKeywordsDao-->UpdateKeyWords-->" + ex.Message + strSql.ToString(), ex);
            }
        }
 public string UpdateStatus(DisableKeywordsQuery query)
 {
     StringBuilder strSql = new StringBuilder();
     try
     {
         strSql.AppendFormat(@"Update disable_keywords set dk_active='{1}' WHERE dk_id={0}", query.dk_id, query.dk_active);
         return strSql.ToString();
     }
     catch (Exception ex)
     {
         throw new Exception("DisableKeywordsDao-->UpdateStatus-->" + ex.Message + strSql.ToString(), ex);
     }
 }
        public HttpResponseBase UpdateStats()
        {
            string json = string.Empty;
            try
            {
                _dkMgr = new DisableKeywordsMgr(mySqlConnectionString);
                DisableKeywordsQuery query = new DisableKeywordsQuery();

                if (!string.IsNullOrEmpty(Request.Params["id"]))
                {
                    query.dk_id = Convert.ToInt32(Request.Params["id"]);
                }
                if (!string.IsNullOrEmpty(Request.Params["active"]))
                {
                    query.dk_active = Convert.ToInt32(Request.Params["active"]);
                }
                json = _dkMgr.UpdateStatus(query);
            }
            catch (Exception ex)
            {
                Log4NetCustom.LogMessage logMessage = new Log4NetCustom.LogMessage();
                logMessage.Content = string.Format("TargetSite:{0},Source:{1},Message:{2}", ex.TargetSite.Name, ex.Source, ex.Message);
                logMessage.MethodName = System.Reflection.MethodBase.GetCurrentMethod().Name;
                log.Error(logMessage);
                json = "{success:false,totalCount:0,data:[]}";
            }
            this.Response.Clear();
            this.Response.Write(json);
            this.Response.End();
            return this.Response;
        }
        public HttpResponseBase DeleteKeyWords()
        {
            string json = string.Empty;
            int result = 0;
            _dkMgr = new DisableKeywordsMgr(mySqlConnectionString);
            try
            {
                DisableKeywordsQuery query = new DisableKeywordsQuery();
                if (!string.IsNullOrEmpty(Request.Params["ids"]))
                {
                    query.ids = Request.Params["ids"].ToString();
                }
                result = _dkMgr.DeleteKeyWords(query);
                if (result > 0)
                {
                    json = "{success:true,msg:\'1\'}";
                }
                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 AddOrEdit()
 {
     string json = string.Empty;
     int result = 0;
     _dkMgr = new DisableKeywordsMgr(mySqlConnectionString);
     try
     {
         DisableKeywordsQuery query = new DisableKeywordsQuery();
         #region 編輯
         if (!string.IsNullOrEmpty(Request.Params["dk_id"]))
         {
             query.dk_string = Request.Params["dk_string"].ToString().Replace("\\", "\\\\");
             query.dk_id = Convert.ToInt32(Request.Params["dk_id"]);
             result = _dkMgr.UpdateKeyWords(query);
             if (result > 0)
             {
                 json = "{success:true,msg:\'1\'}";
             }
             else
             {
                 json = "{success:false}";
             }
         }
         #endregion
         #region 新增
         else
         {
             query.dk_string = Request.Params["dk_string"].ToString().Replace("\\", "\\\\");
             query.user_id = Convert.ToInt32((System.Web.HttpContext.Current.Session["caller"] as Caller).user_id.ToString());
             query.dk_created = DateTime.Now;
             result = _dkMgr.AddKeyWords(query);
             if (result > 0)
             {
                 json = "{success:true,msg:\'0\'}";
             }
             else
             {
                 json = "{success:false}";
             }
         }
         #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);
         json = "{success:false}";
     }
     this.Response.Clear();
     this.Response.Write(json);
     this.Response.End();
     return this.Response;
 } 
 public HttpResponseBase GetKeyWordsList()
 {
     string json = string.Empty;
     int totalCount = 0;
     DisableKeywordsQuery query = new DisableKeywordsQuery();
     query.Start = Convert.ToInt32(Request.Params["start"] ?? "0");//用於分頁的變量
     query.Limit = Convert.ToInt32(Request.Params["limit"] ?? "20");//用於分頁的變量
     try
     {
         if (!string.IsNullOrEmpty(Request.Params["starttime"]) && !string.IsNullOrEmpty(Request.Params["endtime"]))
         {
             query.start = Convert.ToDateTime(Request.Params["starttime"]);
             query.end = Convert.ToDateTime(Request.Params["endtime"]);
         }
         if (!string.IsNullOrEmpty(Request.Params["text"]))
         {
             query.search_text = Request.Params["text"].ToString().Replace("\\", "\\\\");
         }
         _dkMgr = new DisableKeywordsMgr(mySqlConnectionString);
         DataTable store = _dkMgr.GetKeyWordsList(query, out totalCount);
         IsoDateTimeConverter timeConverter = new IsoDateTimeConverter();
         timeConverter.DateTimeFormat = "yyyy-MM-dd HH:mm:ss";
         json = "{success:true,totalCount:" + totalCount + ",data:" + JsonConvert.SerializeObject(store, Formatting.Indented, timeConverter) + "}";
     }
     catch (Exception ex)
     {
         Log4NetCustom.LogMessage logMessage = new Log4NetCustom.LogMessage();
         logMessage.Content = string.Format("TargetSite:{0},Source:{1},Message:{2}", ex.TargetSite.Name, ex.Source, ex.Message);
         logMessage.MethodName = System.Reflection.MethodBase.GetCurrentMethod().Name;
         log.Error(logMessage);
         json = "{success:false,totalCount:0,data:[]}";
     }
     this.Response.Clear();
     this.Response.Write(json);
     this.Response.End();
     return this.Response;
 }