public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; context.Response.Cache.SetNoStore(); int id = Convert.ToInt32(context.Request.QueryString["id"]); SM.YuQing.BLL.MonitorWebs bll = new SM.YuQing.BLL.MonitorWebs(); SM.YuQing.Model.MonitorWebs web = bll.GetModel(id); context.Response.Write(JsonConvert.SerializeObject(web)); }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(SM.YuQing.Model.MonitorWebs model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update MonitorWebs set "); strSql.Append("RegionID=@RegionID,"); strSql.Append("Name=@Name,"); strSql.Append("Url=@Url,"); strSql.Append("Status=@Status,"); strSql.Append("CreateTime=@CreateTime,"); strSql.Append("CreatePerson=@CreatePerson,"); strSql.Append("UpdateTime=@UpdateTime,"); strSql.Append("UpdatePerson=@UpdatePerson"); strSql.Append(" where ID=@ID "); SqlParameter[] parameters = { new SqlParameter("@ID", SqlDbType.Int, 4), new SqlParameter("@RegionID", SqlDbType.Int, 4), new SqlParameter("@Name", SqlDbType.NVarChar, 50), new SqlParameter("@Url", SqlDbType.NVarChar, 500), new SqlParameter("@Status", SqlDbType.NVarChar, 50), new SqlParameter("@CreateTime", SqlDbType.DateTime), new SqlParameter("@CreatePerson", SqlDbType.NVarChar, 50), new SqlParameter("@UpdateTime", SqlDbType.DateTime), new SqlParameter("@UpdatePerson", SqlDbType.NVarChar, 50) }; parameters[0].Value = model.ID; parameters[1].Value = model.RegionID; parameters[2].Value = model.Name; parameters[3].Value = model.Url; parameters[4].Value = model.Status; parameters[5].Value = model.CreateTime; parameters[6].Value = model.CreatePerson; parameters[7].Value = model.UpdateTime; parameters[8].Value = model.UpdatePerson; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 得到一个对象实体 /// </summary> public SM.YuQing.Model.MonitorWebs DataRowToModel(DataRow row) { SM.YuQing.Model.MonitorWebs model = new SM.YuQing.Model.MonitorWebs(); if (row != null) { if (row["ID"] != null && row["ID"].ToString() != "") { model.ID = int.Parse(row["ID"].ToString()); } if (row["RegionID"] != null && row["RegionID"].ToString() != "") { model.RegionID = int.Parse(row["RegionID"].ToString()); } if (row["Name"] != null) { model.Name = row["Name"].ToString(); } if (row["Url"] != null) { model.Url = row["Url"].ToString(); } if (row["Status"] != null) { model.Status = row["Status"].ToString(); } if (row["CreateTime"] != null && row["CreateTime"].ToString() != "") { model.CreateTime = DateTime.Parse(row["CreateTime"].ToString()); } if (row["CreatePerson"] != null) { model.CreatePerson = row["CreatePerson"].ToString(); } if (row["UpdateTime"] != null && row["UpdateTime"].ToString() != "") { model.UpdateTime = DateTime.Parse(row["UpdateTime"].ToString()); } if (row["UpdatePerson"] != null) { model.UpdatePerson = row["UpdatePerson"].ToString(); } } return(model); }
/// <summary> /// 增加一条数据 /// </summary> public bool Add(SM.YuQing.Model.MonitorWebs model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into MonitorWebs("); strSql.Append("RegionID,Name,Url,Status,CreateTime,CreatePerson,UpdateTime,UpdatePerson)"); strSql.Append(" values ("); strSql.Append("@RegionID,@Name,@Url,@Status,@CreateTime,@CreatePerson,@UpdateTime,@UpdatePerson)"); SqlParameter[] parameters = { new SqlParameter("@RegionID", SqlDbType.Int, 4), new SqlParameter("@Name", SqlDbType.NVarChar, 50), new SqlParameter("@Url", SqlDbType.NVarChar, 500), new SqlParameter("@Status", SqlDbType.NVarChar, 50), new SqlParameter("@CreateTime", SqlDbType.DateTime), new SqlParameter("@CreatePerson", SqlDbType.NVarChar, 50), new SqlParameter("@UpdateTime", SqlDbType.DateTime), new SqlParameter("@UpdatePerson", SqlDbType.NVarChar, 50) }; parameters[0].Value = model.RegionID; parameters[1].Value = model.Name; parameters[2].Value = model.Url; parameters[3].Value = model.Status; parameters[4].Value = model.CreateTime; parameters[5].Value = model.CreatePerson; parameters[6].Value = model.UpdateTime; parameters[7].Value = model.UpdatePerson; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
public void ProcessRequest(HttpContext context) { string id = context.Request.Form["id"]; context.Response.ContentType = "text/plain"; context.Response.Cache.SetNoStore(); SM.YuQing.Accounts.SiteIdentity identity = (SM.YuQing.Accounts.SiteIdentity)(new SM.YuQing.Accounts.AccountsPrincipal(context.User.Identity.Name)).Identity; int personid = identity.FID; SM.YuQing.BLL.MonitorWebs bll = new SM.YuQing.BLL.MonitorWebs(); SM.YuQing.Model.MonitorWebs web = bll.GetModel(Convert.ToInt32(id)); string url = web.Url, name = web.Name; bool success = bll.Delete(Convert.ToInt32(id)); Hashtable ht = new Hashtable(); if (success) { SM.YuQing.Model.Log log = new SM.YuQing.Model.Log(); log.LogType = "操作"; log.Message = context.User.Identity.Name + " 删除了网站 " + url + "(" + name + ")";; log.IP = context.Request.UserHostAddress; log.MenuID = 0; log.PersonID = personid; log.CreateTime = DateTime.Now; SM.YuQing.BLL.Log logBll = new SM.YuQing.BLL.Log(); logBll.Add(log); ht.Add("success", true); } else { ht.Add("errorMsg", "Some errors occured."); } context.Response.Write(JsonConvert.SerializeObject(ht)); }
/// <summary> /// 得到一个对象实体 /// </summary> public SM.YuQing.Model.MonitorWebs GetModel(int ID) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 ID,RegionID,Name,Url,Status,CreateTime,CreatePerson,UpdateTime,UpdatePerson from MonitorWebs "); strSql.Append(" where ID=@ID "); SqlParameter[] parameters = { new SqlParameter("@ID", SqlDbType.Int, 4) }; parameters[0].Value = ID; SM.YuQing.Model.MonitorWebs model = new SM.YuQing.Model.MonitorWebs(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }
public DataTable GetDataRows(DataTable dt, string website, string keyword, SM.YuQing.Model.Regions region, SM.YuQing.Model.MonitorWebs web) { try { string html = GetHtmlString(website, "utf-8"); if (html.IndexOf("charset") < 0) { html = GetHtmlString(website, "gb2312"); if (html.IndexOf("charset") < 0) { html = GetHtmlString(website, "gbk"); } } //string html = GetHtmlString(website, "UTF-8"); //string str = html.Substring(0, html.IndexOf("charset=") + 64); //报错点??? //if (str.ToLower().Contains("gb2312")) //{ // html = GetHtmlString(website, "GB2312"); //} //else if (str.ToLower().Contains("gbk")) //{ // html = GetHtmlString(website, "GBK"); //} ////将获取的内容写入文本 //using (StreamWriter sw = new StreamWriter("c:\\html.html")) //{ // sw.Write(html); //} //string regex = @">.*" + keyword + @".*<"; //string regex = @">((.*|\s*))?" + keyword + @"((.*|\s*)<)?"; if (html.IndexOf("charset=") >= 0) { string regex = @">[^<>]*" + keyword + @"[^<>]*<"; if (keyword.ToLower() == "sm") { regex = @">[^<>]*" + keyword + @"[^a-zA-Z][^<>]*<"; } Regex re = new Regex(regex, RegexOptions.IgnoreCase); MatchCollection matches = re.Matches(html); if (matches != null) { IEnumerator enu = matches.GetEnumerator(); while (enu.MoveNext() && enu.Current != null) { Match match = (Match)(enu.Current); if (html.LastIndexOf(match.Value) > html.Length) { continue; } string url = GetUrlFromHtml(html.Substring(0, html.LastIndexOf(match.Value))); SM.YuQing.BLL.MonitorInfos bll = new MonitorInfos(); //if (bll.Exists(url, region == null ? 0 : region.ID)) //存在此Url+RegionID // continue; string tmpHtml = GetHtmlString(url, "UTF-8"); if (tmpHtml.IndexOf("charset=") < 0) { tmpHtml = GetHtmlString(url, "GB2312"); if (tmpHtml.IndexOf("charset=") < 0) { tmpHtml = GetHtmlString(url, "GBK"); } } string title = match.Value.Replace(">", "").Replace("<", "").Trim(); //去掉头尾的“>”和“<” if (Regex.IsMatch(match.Value, @"[\u4e00-\u9fa5]") && !Regex.IsMatch(match.Value, @";|function") && url != "" && !url.ToLower().Contains("error")) //包含中文,去除js代码、空url && tmpHtml.Contains(title) && Regex.IsMatch(title, @"\p{ASCII}") { DataRow dr = dt.NewRow(); //dr["Title"] = match.Value.Substring(1, match.Value.Length - 2).Trim(); //去掉头尾的“>”和“<” //if (isLastLevel) // dr["Title"] = GetHtmlTitle(html); //else dr["Title"] = title.Length > 100 ? (title.Substring(0, 97) + "...") : title; dr["PublishDate"] = ""; dr["ViewsCounts"] = ""; dr["Region"] = region == null ? "" : region.Mall; dr["RegionID"] = region == null ? "" : region.ID.ToString(); dr["MonitorUrl"] = web == null ? website : web.Url; dr["Keyword"] = keyword; dr["Url"] = url; dt.Rows.Add(dr); } } } } } catch (Exception ex) { throw ex; //DataRow dr = dt.NewRow(); //dr["Title"] = "Error in GetDataRows():" + ex.Message; //dr["PublishDate"] = ""; //dr["ViewsCounts"] = ""; //dr["Region"] = ""; //dr["RegionID"] = ""; //dr["MonitorUrl"] = ""; //dr["Keyword"] = ""; //dr["Url"] = ""; //dt.Rows.Add(dr); } return(dt); }
public DataTable GetData(DataTable dt, string website, string keyword, SM.YuQing.Model.Regions region, SM.YuQing.Model.MonitorWebs web) { //DataTable dt = new DataTable(); //dt.Columns.Add("Title"); //dt.Columns.Add("PublishDate"); //dt.Columns.Add("ViewsCounts"); //dt.Columns.Add("Region"); //dt.Columns.Add("RegionID"); //dt.Columns.Add("MonitorUrl"); //dt.Columns.Add("Keyword"); //dt.Columns.Add("Url"); DataTable dtUrl = new DataTable(); dtUrl.Columns.Add("Title"); dtUrl.Columns.Add("PublishDate"); dtUrl.Columns.Add("ViewsCounts"); dtUrl.Columns.Add("Region"); dtUrl.Columns.Add("RegionID"); dtUrl.Columns.Add("MonitorUrl"); dtUrl.Columns.Add("Keyword"); dtUrl.Columns.Add("Url"); //int searchLevel = 1; try { //get all urls dtUrl = RemoveCommonUrl(GetUrls(website)); //一级页面 dt = GetDataRows(dt, website, keyword, null, null); //二级页面 int count = dtUrl.Rows.Count; for (int i = 0; i < count; i++) { string site = dtUrl.Rows[i]["Url"].ToString(); dt = GetDataRows(dt, site, keyword, null, null); } } catch (Exception ex) { throw ex; } return(dt); }
public void ProcessRequest(HttpContext context) { string id = context.Request.QueryString["id"]; string Url = context.Request.Form["Url"]; string Name = context.Request.Form["Name"]; string RegionID = context.Request.Form["RegionID"]; string Status = context.Request.Form["Status"]; string errMsg = ""; bool success; context.Response.ContentType = "text/plain"; context.Response.Cache.SetNoStore(); SM.YuQing.Accounts.SiteIdentity identity = (SM.YuQing.Accounts.SiteIdentity)(new SM.YuQing.Accounts.AccountsPrincipal(context.User.Identity.Name)).Identity; int personid = identity.FID; if (id == null) //新增 { SM.YuQing.BLL.MonitorWebs bll = new SM.YuQing.BLL.MonitorWebs(); if (!bll.ExistWeb(Convert.ToInt32(RegionID), Url, Status)) { SM.YuQing.Model.MonitorWebs web = new SM.YuQing.Model.MonitorWebs(); web.Url = Url; web.Name = Name; web.RegionID = Convert.ToInt32(RegionID); web.Status = Status; web.CreatePerson = context.User.Identity.Name; web.CreateTime = DateTime.Now; web.UpdatePerson = context.User.Identity.Name; web.UpdateTime = DateTime.Now; success = bll.Add(web); if (success) { SM.YuQing.Model.Log log = new SM.YuQing.Model.Log(); log.LogType = "操作"; log.Message = context.User.Identity.Name + " 新增了网站 " + Url + "(" + Name + ")"; log.IP = context.Request.UserHostAddress; log.MenuID = 0; log.PersonID = personid; log.CreateTime = DateTime.Now; SM.YuQing.BLL.Log logBll = new SM.YuQing.BLL.Log(); logBll.Add(log); } else { success = false; errMsg = "some error occured."; } } else { success = false; errMsg = "该网址已存在于此区域中!"; } } else //修改 { SM.YuQing.BLL.MonitorWebs bll = new SM.YuQing.BLL.MonitorWebs(); SM.YuQing.Model.MonitorWebs web = bll.GetModel(Convert.ToInt32(id)); string oldUrl = web.Url, oldName = web.Name, oldRegionID = web.RegionID.ToString(), oldStatus = web.Status; web.Url = Url; web.Name = Name; web.RegionID = Convert.ToInt32(RegionID); web.Status = Status; web.UpdatePerson = context.User.Identity.Name; web.UpdateTime = DateTime.Now; if (oldUrl == Url && oldName == Name && oldRegionID == RegionID && oldStatus == Status) { success = false; errMsg = "您未修改任何信息"; } else if (oldUrl == Url && oldName != Name && oldRegionID == RegionID && oldStatus == Status) { success = bll.Update(web); } else if (!bll.ExistWeb(Convert.ToInt32(RegionID), Url, Status)) { success = bll.Update(web); } else { success = false; errMsg = "该网址已存在于此区域中!"; } if (success) { SM.YuQing.Model.Log log = new SM.YuQing.Model.Log(); log.LogType = "操作"; log.Message = context.User.Identity.Name + " 修改了ID=" + id + "的网站信息" + " | " + (oldUrl == Url ? "" : (oldUrl + " -> " + Url + " | ")) + (oldName == Name ? "" : (oldName + " -> " + Name + " | ")) + (oldRegionID == RegionID ? "" : ("RegionID: " + oldRegionID + " -> " + RegionID + " | ")) + (oldStatus == Status ? "" : (oldStatus + " -> " + Status + " | ")); log.IP = context.Request.UserHostAddress; log.MenuID = 0; log.PersonID = personid; log.CreateTime = DateTime.Now; SM.YuQing.BLL.Log logBll = new SM.YuQing.BLL.Log(); logBll.Add(log); } else if (!success && errMsg == "") { errMsg = "some error occured."; } } Hashtable ht = new Hashtable(); if (success) { ht.Add("success", true); } else { ht.Add("errorMsg", errMsg); } context.Response.Write(JsonConvert.SerializeObject(ht)); }