예제 #1
0
        public int SaveSystemKeyWord(SphinxKeywordQuery query)
        {
            ///返回的状态
            int state = 0;
            try
            {
                dao = new SystemKeyWordDao(connectionstring);
                //新增
                if (query.operateType == 1)
                {
                    query.kuser = query.user_name;
                    query.moduser = query.user_name;
                    query.kdate = DateTime.Now;
                    query.mddate = DateTime.Now;
                    state = dao.AddSystemKeyWord(query);
                }
                //編輯
                if (query.operateType == 2)
                {
                    query.moduser = query.user_name;
                    query.mddate = DateTime.Now;
                    state = dao.UpdateSystemKeyWord(query);
                }
                return state;
            }
            catch (Exception ex)
            {

                throw new Exception("SystemKeyWordMgr->SaveSystemKeyWord():" + ex.Message);
            }

        } 
예제 #2
0
        public int AddSystemKeyWord(SphinxKeywordQuery query)
        {
            StringBuilder sql = new StringBuilder();
            StringBuilder sqlCondi = new StringBuilder();
            StringBuilder sqlCondiValue = new StringBuilder();
            int state = 0;
            try
            {
                sql.Append(@"INSERT INTO ");
                sqlCondi.Append(@" sphinx_keyword ( ");
                sqlCondiValue.AppendFormat(@" VALUES( ");
                if (!string.IsNullOrEmpty(query.key_word))
                {
                    sqlCondi.Append("key_word ,");
                    sqlCondiValue.AppendFormat(@"'{0}',", query.key_word);
                }
                if (!string.IsNullOrEmpty(query.flag))
                {
                    sqlCondi.Append("flag ,");
                    sqlCondiValue.AppendFormat(@"'{0}',", query.flag);
                }
                if (!string.IsNullOrEmpty(query.kuser))
                {
                    sqlCondi.Append("kuser ,");
                    sqlCondiValue.AppendFormat(@"'{0}',", query.kuser);
                }
                if (query.kdate > DateTime.MinValue)
                {
                    sqlCondi.Append("kdate ,");
                    sqlCondiValue.AppendFormat(@"'{0}',", CommonFunction.DateTimeToString(query.kdate));
                }
                if (!string.IsNullOrEmpty(query.moduser))
                {
                    sqlCondi.Append("moduser ,");
                    sqlCondiValue.AppendFormat(@"'{0}',", query.moduser);
                }
                if (query.mddate > DateTime.MinValue)
                {
                    sqlCondi.Append("mddate ,");
                    sqlCondiValue.AppendFormat(@"'{0}',", CommonFunction.DateTimeToString(query.mddate));
                }
                sqlCondiValue.Append(")");
                sqlCondi.Append(")");
                string strSqlCondi = sqlCondi.ToString().Remove(sqlCondi.ToString().LastIndexOf(","), 1);
                string strSqlCondiValue = sqlCondiValue.ToString().Remove(sqlCondiValue.ToString().LastIndexOf(","), 1);
                strSqlCondi += strSqlCondiValue;
                sql.Append(strSqlCondi);
                ///新增失敗返回0
                state = _accessMySql.execCommand(sql.ToString());
                return state;
            }
            catch (Exception ex)
            {

                throw new Exception("SystemKeyWordDao-->AddSystemKeyWord-->" + ex.Message + sql.ToString(), ex);
            }
        }
예제 #3
0
        public List<SphinxKeywordQuery> GetSystemKeyWord(SphinxKeywordQuery query, out int totalCount)
        {
            try
            {
                dao = new SystemKeyWordDao(connectionstring);
                return dao.GetSystemKeyWord(query, out totalCount);
            }
            catch (Exception ex)
            {

                throw new Exception("SystemKeyWordMgr->GetSystemKeyWord():" + ex.Message);
            }

        }
예제 #4
0
        public HttpResponseBase GetSystemKeyWord()
        {
            int totalCount = 0;
            string json = string.Empty;
            List<SphinxKeywordQuery> stores = new List<SphinxKeywordQuery>();
            SphinxKeywordQuery query = new SphinxKeywordQuery();
            swMgr = new SystemKeyWordMgr(SqlConnectionString);
            DateTime time;
            try
            {
                query.Start = Convert.ToInt32(Request.Params["Start"] ?? "0");
                if (!string.IsNullOrEmpty(Request.Params["Limit"]))
                {
                    query.Limit = Convert.ToInt32(Request.Params["Limit"]);
                }
                if (!string.IsNullOrEmpty(Request.Params["searchKey"]))
                {
                    query.searchKey = Request.Params["searchKey"];
                }
                if (DateTime.TryParse(Request.Params["startTime"], out time))
                {
                    query.startTime = time;
                }
                if (DateTime.TryParse(Request.Params["endTime"], out time))
                {
                    query.endTime = time;
                }
                stores = swMgr.GetSystemKeyWord(query, out totalCount);
                IsoDateTimeConverter timeConverter = new IsoDateTimeConverter();
                //这里使用自定义日期格式,如果不使用的话,默认是ISO8601格式     
                timeConverter.DateTimeFormat = "yyyy-MM-dd HH:mm:ss";
                json = "{success:true,totalCount:" + totalCount + ",data:" + JsonConvert.SerializeObject(stores, Formatting.Indented, timeConverter) + "}";//返回json數據
            }
            catch (Exception ex)
            {
                Log4NetCustom.LogMessage logMessage = new Log4NetCustom.LogMessage();
                logMessage.Content = string.Format("TargetSite:{0},Source:{1},Message:{2}", ex.TargetSite.Name, ex.Source, ex.Message);
                logMessage.MethodName = System.Reflection.MethodBase.GetCurrentMethod().Name;
                log.Error(logMessage);
                json = "{success:false}";
            }
            this.Response.Clear();
            this.Response.Write(json);
            this.Response.End();
            return this.Response;

        }
예제 #5
0
        public int DelSystemKeyWord(SphinxKeywordQuery query)
        {

            ///返回的状态
            int state = 0;
            try
            {
                dao = new SystemKeyWordDao(connectionstring);
                state = dao.DelSystemKeyWord(query);
                return state;
            }
            catch (Exception ex)
            {

                throw new Exception("SystemKeyWordMgr->DelSystemKeyWord():" + ex.Message);
            }
        } 
예제 #6
0
        public List<SphinxKeywordQuery> GetSystemKeyWord(SphinxKeywordQuery query, out int totalCount)
        {
            StringBuilder sql = new StringBuilder();
            StringBuilder sqlCount = new StringBuilder();
            StringBuilder sqlCondi = new StringBuilder();
            totalCount = 0;
            try
            {
                sql.Append(@"SELECT sk.row_id,sk.key_word,sk.flag,sk.kdate,sk.kuser,sk.mddate,sk.moduser ");
                sqlCount.Append(@"SELECT count( key_word) as totalCount ");
                sqlCondi.Append(@"from sphinx_keyword sk where 1=1 ");
                if (!string.IsNullOrEmpty(query.searchKey))
                {
                    sqlCondi.AppendFormat("AND sk.key_word  LIKE N'%{0}%'", query.searchKey);
                }
                if (query.startTime > DateTime.MinValue)
                {
                    sqlCondi.AppendFormat("AND sk.kdate BETWEEN '{0}' and '{1}' ", CommonFunction.DateTimeToString(query.startTime), CommonFunction.DateTimeToString(query.endTime));
                }
                if (query.IsPage)
                {
                    sqlCount.Append(sqlCondi.ToString());
                    DataTable _dt = _accessMySql.getDataTable(sqlCount.ToString());
                    if (_dt != null && _dt.Rows.Count > 0)
                    {
                        //得到滿足條件的總行數
                        totalCount = Convert.ToInt32(_dt.Rows[0]["totalCount"]);
                    }
                }
                sqlCondi.AppendFormat("LIMIT {0},{1}", query.Start, query.Limit);
                sql.Append(sqlCondi.ToString());
                return _accessMySql.getDataTableForObj<SphinxKeywordQuery>(sql.ToString());

            }
            catch (Exception ex)
            {

                throw new Exception("SystemKeyWordDao-->GetSystemKeyWord-->" + ex.Message + sql.ToString(), ex);
            }
        }
예제 #7
0
 public List<SphinxKeywordQuery> GetKeyWordExportList(SphinxKeywordQuery query)
 {
     try
     {
         dao = new SystemKeyWordDao(connectionstring);
         return dao.GetKeyWordExportList(query);
     }
     catch (Exception ex)
     {
         throw new Exception("SystemKeyWordMgr->GetKeyWordExportList():" + ex.Message);
     }
 } 
예제 #8
0
 public HttpResponseBase KeyWordUploadExcel()
 {
     string newName = string.Empty;
     string json = string.Empty;
     List<SphinxKeywordQuery> store = new List<SphinxKeywordQuery>();
     HashEncrypt hashpt = new HashEncrypt();
     try
     {
         DTIlocExcel.Clear();
         DTIlocExcel.Columns.Clear();
         DTIlocExcel.Columns.Add("keyword", typeof(String));
         DTIlocExcel.Columns.Add("foodkeyword(1:是食安關鍵字,0不是食安關鍵字)", typeof(String));
         DTIlocExcel.Columns.Add("failureMessage", typeof(String));
         int result = 0;
         int count = 0;//總匯入數
         //int entercount = 0;//插入失敗個數
         int errorcount = 0;//數據異常個數
         int repeat = 0;//數據已存在個數
         string create_user = (Session["caller"] as Caller).user_username;
         if (Request.Files["ImportExcelFile"] != null && Request.Files["ImportExcelFile"].ContentLength > 0)
         {
             HttpPostedFileBase excelFile = Request.Files["ImportExcelFile"];
             newName = Server.MapPath(excelPath) + excelFile.FileName;
             excelFile.SaveAs(newName);
             DataTable dt = new DataTable();
             NPOI4ExcelHelper helper = new NPOI4ExcelHelper(newName);
             dt = helper.SheetData();
             if (dt.Rows.Count > 0)
             {
                 swMgr = new SystemKeyWordMgr(SqlConnectionString);
                 int i = 0;
                 foreach (DataRow dr in dt.Rows)
                 {
                     StringBuilder strsql = new StringBuilder();
                     SphinxKeywordQuery query = new BLL.gigade.Model.Query.SphinxKeywordQuery();
                     i++;
                     try
                     {
                         if (!string.IsNullOrEmpty(dr[0].ToString()) && !string.IsNullOrEmpty(dr[1].ToString()))
                         {
                             int row_id_exsit = swMgr.CheckKeyWordExsit(dr[0].ToString());//判斷關鍵字是否存在
                             query.user_name = create_user;
                             query.key_word = dr[0].ToString();
                             query.flag = dr[1].ToString();
                             query.operateType = 1;
                             if (row_id_exsit > 0)
                             {
                                 DataRow drtwo = DTIlocExcel.NewRow();
                                 drtwo[0] = dr[0].ToString();
                                 drtwo[1] = dr[1].ToString();
                                 drtwo[2] = "系統關鍵字已存在";
                                 DTIlocExcel.Rows.Add(drtwo);
                                 repeat++;
                                 continue;
                             }
                             else//關鍵字不存在
                             {
                                 if (query.flag == "0" || query.flag == "1")
                                 {
                                     byte[] strBt = Encoding.Unicode.GetBytes(query.key_word);
                                     //關鍵字最多為25個中文字或50個英文字
                                     if (strBt.Length <= 50)
                                     {
                                         result = swMgr.SaveSystemKeyWord(query);
                                         if (result > 0)
                                         {
                                             count++;
                                             continue;
                                         }
                                         else
                                         {
                                             DataRow drtwo = DTIlocExcel.NewRow();
                                             drtwo[0] = dr[0].ToString();
                                             drtwo[1] = dr[1].ToString();
                                             drtwo[2] = "關鍵字插入數據庫時失敗";
                                             DTIlocExcel.Rows.Add(drtwo);
                                             errorcount++;
                                             continue;
                                         }
                                     }
                                     else
                                     {
                                         DataRow drtwo = DTIlocExcel.NewRow();
                                         drtwo[0] = dr[0].ToString();
                                         drtwo[1] = dr[1].ToString();
                                         drtwo[2] = "關鍵字最多為25個中文字或50個英文字";
                                         DTIlocExcel.Rows.Add(drtwo);
                                         errorcount++;
                                         continue;
                                     }
                                 }
                                 else
                                 {
                                     DataRow drtwo = DTIlocExcel.NewRow();
                                     drtwo[0] = dr[0].ToString();
                                     drtwo[1] = dr[1].ToString();
                                     drtwo[2] = "'foodkeyword的值只能為0或1'";
                                     DTIlocExcel.Rows.Add(drtwo);
                                     errorcount++;
                                     continue;
                                 }
                             }
                         }
                         else
                         {
                             DataRow drtwo = DTIlocExcel.NewRow();
                             drtwo[0] = dr[0].ToString();
                             drtwo[1] = dr[1].ToString();
                             drtwo[2] = "keyword或foodkeyword不符合格式";
                             DTIlocExcel.Rows.Add(drtwo);
                             errorcount++;
                             continue;
                         }
                     }
                     catch
                     {
                         DataRow drtwo = DTIlocExcel.NewRow();
                         drtwo[0] = dr[0].ToString();
                         drtwo[1] = dr[1].ToString();
                         drtwo[2] = "數據異常";
                         DTIlocExcel.Rows.Add(drtwo);
                         errorcount++;
                         continue;
                     }
                 }
                 if (count > 0)
                 {
                     json = "{success:true,total:" + count + ",error:" + errorcount + ",repeat:" + repeat+"}";
                 }
                 else
                 {
                     json = "{success:true,total:" + 0 + ",error:" + errorcount + ",repeat:" + repeat+"}";
                 }
             }
             else
             {
                 json = "{success:true,total:" + 0 + ",error:" + 0 + ",repeat" + repeat + "}";
             }
         }
     }
     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,data:" + "" + "}";
     }
     this.Response.Clear();
     this.Response.Write(json);
     this.Response.End();
     return this.Response;
 }
예제 #9
0
        public void KeyWordExcelList()
        {
            string json = string.Empty;
            SphinxKeywordQuery skQuery = new SphinxKeywordQuery();
            DataTable dtExcel = new DataTable();
            List<SphinxKeywordQuery> store = new List<SphinxKeywordQuery>();
            try
            {
                DateTime time;
                if (!string.IsNullOrEmpty(Request.Params["searchKey"].Trim()))
                {
                    skQuery.searchKey = Request.Params["searchKey"].ToString();
                }
                if (DateTime.TryParse(Request.Params["startTime"].ToString(), out time))
                {
                    skQuery.startTime = time;
                }
                if (DateTime.TryParse(Request.Params["endtime"].ToString(), out time))
                {
                    skQuery.endTime = time;
                }

                swMgr = new SystemKeyWordMgr(SqlConnectionString);
                store = swMgr.GetKeyWordExportList(skQuery);
                dtExcel.Columns.Add("keyword", typeof(String));
                dtExcel.Columns.Add("foodkeyword(1:是食安關鍵字,0不是食安關鍵字)", typeof(String));
                for (int i = 0; i < store.Count; i++)
                {
                    DataRow newRow = dtExcel.NewRow();
                    newRow[0] = store[i].key_word.ToString();
                    newRow[1] = store[i].flag.ToString();
                    dtExcel.Rows.Add(newRow);
                }
                if (dtExcel.Rows.Count > 0)
                {
                    string fileName = "系統關鍵字_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xls";
                    MemoryStream ms = ExcelHelperXhf.ExportDT(dtExcel, "");
                    Response.AddHeader("Content-Disposition", "attachment; filename=" + fileName);
                    Response.BinaryWrite(ms.ToArray());
                }
                else
                {
                    Response.Write("匯出數據不存在");
                }
            }
            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);
            }
        }
예제 #10
0
 public HttpResponseBase CheckKeyWordExsit()
 {
     string json = string.Empty;
     SphinxKeywordQuery query = new SphinxKeywordQuery();
     swMgr = new SystemKeyWordMgr(SqlConnectionString);
     int msg = 0;
     try
     {
         if (!string.IsNullOrEmpty(Request.Params["key_word"]))
         {
             query.key_word = Request.Params["key_word"].Trim();
         }
         msg = swMgr.CheckKeyWordExsit(query.key_word);
         json = "{success:true,msg:" + msg + "}";//返回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;
 } 
예제 #11
0
        public HttpResponseBase DelSystemKeyWord()
        {
            string json = string.Empty;
            ///返回的状态
            int state = 0;
            List<SphinxKeywordQuery> stores = new List<SphinxKeywordQuery>();
            SphinxKeywordQuery query = new SphinxKeywordQuery();
            swMgr = new SystemKeyWordMgr(SqlConnectionString);
            try
            {
                if (!string.IsNullOrEmpty(Request.Params["row_id"]))
                {
                    string[] strId = Request.Params["row_id"].Split(new string[] { "|" }, StringSplitOptions.RemoveEmptyEntries);
                    query.ArrId = strId;
                }
                query.user_name = (System.Web.HttpContext.Current.Session["caller"] as Caller).user_username;
                state = swMgr.DelSystemKeyWord(query);
                IsoDateTimeConverter timeConverter = new IsoDateTimeConverter();
                //这里使用自定义日期格式,如果不使用的话,默认是ISO8601格式     
                timeConverter.DateTimeFormat = "yyyy-MM-dd HH:mm:ss";
                json = "{success:true,state:" + state + "}";//返回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;

        }
예제 #12
0
        public List<SphinxKeywordQuery> GetKeyWordExportList(SphinxKeywordQuery query)
        {
            StringBuilder sql = new StringBuilder();
            StringBuilder sqlCount = new StringBuilder();
            StringBuilder sqlCondi = new StringBuilder();
            try
            {
                sql.Append(@"SELECT sk.key_word,sk.flag");
                sqlCount.Append(@"SELECT count(row_id) as totalCount ");
                sqlCondi.Append(@" from sphinx_keyword sk where 1=1 ");
                if (!string.IsNullOrEmpty(query.searchKey))
                {
                    sqlCondi.AppendFormat("AND sk.key_word  LIKE N'%{0}%'", query.searchKey);
                }
                if (query.startTime > DateTime.MinValue)
                {
                    sqlCondi.AppendFormat("AND sk.kdate BETWEEN '{0}' and '{1}' ", CommonFunction.DateTimeToString(query.startTime), CommonFunction.DateTimeToString(query.endTime));
                }
                sqlCount.Append(sqlCondi.ToString());
                DataTable _dt = _accessMySql.getDataTable(sqlCount.ToString());
                sql.Append(sqlCondi.ToString());
                return _accessMySql.getDataTableForObj<SphinxKeywordQuery>(sql.ToString());
            }
            catch (Exception ex)
            {

                throw new Exception("SystemKeyWordDao-->DelSystemKeyWord-->" + ex.Message + sql.ToString(), ex);
            }
        } 
예제 #13
0
        public int DelSystemKeyWord(SphinxKeywordQuery query)
        {
            int state = 0;
            StringBuilder sql = new StringBuilder();
            StringBuilder sqlCondi = new StringBuilder();
            try
            {
                sql.Append(@" DELETE from sphinx_keyword WHERE 1=1");
                if (query.ArrId != null)
                {
                    sqlCondi.Append(" and row_id IN (");
                    foreach (var row_id in query.ArrId)
                    {
                        sqlCondi.AppendFormat("{0},", row_id);
                    }
                    sqlCondi.Append(" )");
                }
                sql.Append(sqlCondi.ToString().Remove(sqlCondi.ToString().LastIndexOf(','), 1));
                int line = _accessMySql.execCommand(sql.ToString());
                if (line >= 1)
                {
                    state = 1;
                }
                else
                    state = 0;
                return state;
            }
            catch (Exception ex)
            {

                throw new Exception("SystemKeyWordDao-->DelSystemKeyWord-->" + ex.Message + sql.ToString(), ex);
            }
        }
예제 #14
0
        public int UpdateSystemKeyWord(SphinxKeywordQuery query)
        {
            StringBuilder sql = new StringBuilder();
            StringBuilder sqlCondi = new StringBuilder();
            int state = 0;
            try
            {
                sql.Append(@" set sql_safe_updates = 0;  UPDATE sphinx_keyword");
                sqlCondi.Append(@" SET ");
                if (!string.IsNullOrEmpty(query.key_word))
                {
                    sqlCondi.AppendFormat("key_word='{0}',", query.key_word);
                }
                if (!string.IsNullOrEmpty(query.flag))
                {
                    sqlCondi.AppendFormat("flag='{0}',", query.flag);
                }
                if (!string.IsNullOrEmpty(query.moduser))
                {
                    sqlCondi.AppendFormat("moduser='******',", query.moduser);
                }
                if (query.mddate > DateTime.MinValue)
                {
                    sqlCondi.AppendFormat("mddate='{0}',", CommonFunction.DateTimeToString(query.mddate));
                }
                sqlCondi.AppendFormat("where row_id={0};", query.row_id);
                sql.Append(sqlCondi.ToString().Remove(sqlCondi.ToString().LastIndexOf(','), 1));
                sql.Append("set sql_safe_updates = 1;");
                ///新增失敗返回0
                state = _accessMySql.execCommand(sql.ToString());
                return state;
            }
            catch (Exception ex)
            {

                throw new Exception("SystemKeyWordDao-->UpdateSystemKeyWord-->" + ex.Message + sql.ToString(), ex);
            }
        }