public int RecordToDatabase(DataTable dt, string userName) { int count = 0; //写入数据库 for (int i = 0; i < dt.Rows.Count; i++) { SM.YuQing.BLL.MonitorInfos bll = new SM.YuQing.BLL.MonitorInfos(); SM.YuQing.Model.MonitorInfos monitorInfo = new SM.YuQing.Model.MonitorInfos(); monitorInfo.Title = dt.Rows[i]["Title"].ToString(); monitorInfo.PublishDate = dt.Rows[i]["PublishDate"].ToString() == "" ? DateTime.Now : Convert.ToDateTime(dt.Rows[i]["PublishDate"].ToString()); monitorInfo.ViewsCounts = dt.Rows[i]["ViewsCounts"].ToString() == "" ? 0 : Convert.ToInt32(dt.Rows[i]["ViewsCounts"].ToString()); int regionid = dt.Rows[i]["RegionID"].ToString() == "" ? 0 : Convert.ToInt32(dt.Rows[i]["RegionID"].ToString()); monitorInfo.RegionID = regionid; monitorInfo.MonitorUrl = dt.Rows[i]["MonitorUrl"].ToString(); monitorInfo.Keyword = dt.Rows[i]["Keyword"].ToString(); monitorInfo.Url = dt.Rows[i]["Url"].ToString(); monitorInfo.Property = ""; monitorInfo.CreatePerson = userName; monitorInfo.CreateTime = DateTime.Now; monitorInfo.UpdatePerson = userName; monitorInfo.UpdateTime = DateTime.Now; if (!bll.Exists(dt.Rows[i]["Url"].ToString(), regionid)) //存在此Url+RegionID { bll.Add(monitorInfo); count++; } } return(count); }
private DataTable GetDataRow(DataTable dt, SM.YuQing.Model.Regions region, string reg, string strWhere) { int positive = 0, negative = 0, neutral = 0, empty = 0; try { DataRow dr = dt.NewRow(); dr["Region"] = region == null?reg:region.Mall; SM.YuQing.BLL.MonitorInfos monitorInfoBll = new SM.YuQing.BLL.MonitorInfos(); List <SM.YuQing.Model.MonitorInfos> monitorInfoList = monitorInfoBll.GetModelList(strWhere + " and Keyword like \'SM\'"); foreach (SM.YuQing.Model.MonitorInfos monitorInfo in monitorInfoList) { switch (monitorInfo.Property) { case "正面": positive++; break; case "负面": negative++; break; case "中性": neutral++; break; case "": empty++; break; } } dr["Positive"] = positive.ToString(); dr["Negative"] = negative.ToString(); dr["Neutral"] = neutral.ToString(); dr["Empty"] = empty.ToString(); dr["Total"] = (positive + negative + neutral + empty).ToString(); dt.Rows.Add(dr); } catch (Exception ex) { DataRow dr = dt.NewRow(); dr["Region"] = "Error in GetDataRow():" + ex.Message;; dr["Positive"] = ""; dr["Negative"] = ""; dr["Neutral"] = ""; dr["Empty"] = ""; dr["Total"] = ""; dt.Rows.Add(dr); } return(dt); }
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.Regions bll = new SM.YuQing.BLL.Regions(); SM.YuQing.Model.Regions region = bll.GetModel(Convert.ToInt32(id)); string mall = region.Mall; bool success; SM.YuQing.BLL.MonitorWebs webBll = new SM.YuQing.BLL.MonitorWebs(); SM.YuQing.BLL.MonitorInfos infoBll = new SM.YuQing.BLL.MonitorInfos(); if (!bll.ExistRegion(Convert.ToInt32(id), personid) && !webBll.ExistRegion(Convert.ToInt32(id)) && !infoBll.ExistRegion(Convert.ToInt32(id))) { bll.Delete(Convert.ToInt32(id)); bll.DeletePersonRegion(personid, Convert.ToInt32(id)); success = true; } else { success = false; } Hashtable ht = new Hashtable(); if (success) { SM.YuQing.Model.Log log = new SM.YuQing.Model.Log(); log.LogType = "操作"; log.Message = context.User.Identity.Name + " 删除了区域 " + mall; 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", "该区域已有关联监测数据,不允许删除"); } context.Response.Write(JsonConvert.SerializeObject(ht)); }
public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; context.Response.Cache.SetNoStore(); string id = context.Request.QueryString["id"]; string property = context.Request.Form["property"]; bool success; SM.YuQing.BLL.MonitorInfos bll = new SM.YuQing.BLL.MonitorInfos(); SM.YuQing.Model.MonitorInfos monitorInfo = bll.GetModel(Convert.ToInt32(id)); string oldProperty = monitorInfo.Property; monitorInfo.Property = property; monitorInfo.UpdatePerson = context.User.Identity.Name; monitorInfo.UpdateTime = DateTime.Now; success = bll.Update(monitorInfo); Hashtable ht = new Hashtable(); if (success) { 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.Model.Log log = new SM.YuQing.Model.Log(); log.LogType = "操作"; log.Message = context.User.Identity.Name + " 保存了ID=" + id + "的监测记录的性质为 " + property + " (原性质为 " + (oldProperty == "" ? "空" : oldProperty) + " )"; 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)); }
void Global_ExecuteTask(object sender, System.Timers.ElapsedEventArgs e) { SM.YuQing.BLL.Regions bllRegions = new SM.YuQing.BLL.Regions(); List <SM.YuQing.Model.Regions> regions = bllRegions.GetModelList(""); SM.YuQing.BLL.MonitorInfos bllInfos = new SM.YuQing.BLL.MonitorInfos(); SM.YuQing.BLL.Config bllConfig = new SM.YuQing.BLL.Config(); int searchLevel = bllConfig.GetSearchLevels(); foreach (SM.YuQing.Model.Regions region in regions) { //每天下午16点监测一次 if (DateTime.Now.Hour == 16) { bllInfos.GetMonitorInfos(region, region.Keyword, searchLevel); } //每小时监测一次 bllInfos.GetMonitorInfos(region, "SM", searchLevel); } //foreach (SM.YuQing.Model.MonitorInfos item in infos) //{ // bllInfos.Add(item); //} //SM.YuQing.BLL.MonitorWebs bllwebs = new SM.YuQing.BLL.MonitorWebs(); ////SM.YuQing.Model.MonitorWebs modelwebs = bllwebs.GetModel(7); //List<SM.YuQing.Model.MonitorWebs> webs = bllwebs.GetModelList(""); //SM.YuQing.BLL.MonitorInfos bllinfos = new SM.YuQing.BLL.MonitorInfos(); //List<SM.YuQing.Model.MonitorInfos> infos = bllinfos.GetMonitorInfos(webs, "SM"); //foreach (SM.YuQing.Model.MonitorInfos item in infos) //{ // bllinfos.Add(item); //} }
public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; context.Response.Cache.SetNoStore(); string regionid = context.Request.QueryString["regionid"], reg = ""; string beginDate = context.Request.QueryString["beginDate"]; string endDate = context.Request.QueryString["endDate"]; string property = context.Request.QueryString["property"]; string func = context.Request.QueryString["func"]; if (regionid == "" || regionid.Contains("-1")) { GetRegionIdHelper grih = new GetRegionIdHelper(); regionid = grih.GetRegionID(); } DataTable dt = new DataTable(); dt.Columns.Add("ID"); dt.Columns.Add("Title"); dt.Columns.Add("PublishDate"); dt.Columns.Add("ViewsCounts"); dt.Columns.Add("Region"); dt.Columns.Add("Property"); dt.Columns.Add("Url"); try { string strWhere = ""; ArrayList strWhereList = new ArrayList(); strWhereList.Add(" RegionID in (" + regionid + ")"); strWhereList.Add(" Keyword like \'SM\'"); if (beginDate != "" && endDate != "") { strWhereList.Add(" PublishDate>=\'" + beginDate + "\' and PublishDate<=\'" + endDate + " 23:59:59.999\'"); } if (property != "" && !property.Contains("全部")) { //strWhereList.Add(" Property=N\'" + (property == "空" ? "" : property) + "\'"); //" (Property=N\'" + (p == "空" ? "" : p) + "\' or Property=N\'" + p + "\'") string[] props = property.Split(','); string tmpSql = ""; foreach (string p in props) { tmpSql += " or Property=N\'" + (p == "空" ? "" : p) + "\'"; } tmpSql = tmpSql.Substring(tmpSql.IndexOf("or") + 2, tmpSql.Length - 3); strWhereList.Add(" (" + tmpSql + ") "); } switch (strWhereList.Count) { case 2: strWhere = strWhereList[0].ToString() + " and " + strWhereList[1].ToString(); break; case 3: strWhere = strWhereList[0].ToString() + " and " + strWhereList[1].ToString() + " and " + strWhereList[2].ToString(); break; case 4: strWhere = strWhereList[0].ToString() + " and " + strWhereList[1].ToString() + " and " + strWhereList[2].ToString() + " and " + strWhereList[3].ToString(); break; default: break; } SM.YuQing.BLL.MonitorInfos monitorInfoBll = new SM.YuQing.BLL.MonitorInfos(); List <SM.YuQing.Model.MonitorInfos> monitorInfoList = monitorInfoBll.GetModelList(strWhere); foreach (SM.YuQing.Model.MonitorInfos monitorInfo in monitorInfoList) { DataRow dr = dt.NewRow(); dr["ID"] = monitorInfo.ID; dr["Title"] = monitorInfo.Title; dr["PublishDate"] = monitorInfo.PublishDate.ToString("yyyy-MM-dd"); dr["ViewsCounts"] = monitorInfo.ViewsCounts; if (monitorInfo.RegionID > 0) { SM.YuQing.BLL.Regions regionBll = new SM.YuQing.BLL.Regions(); SM.YuQing.Model.Regions region = regionBll.GetModel(Convert.ToInt32(monitorInfo.RegionID)); reg = region.Mall; } else { reg = ""; } dr["Region"] = reg; dr["Property"] = monitorInfo.Property; dr["Url"] = monitorInfo.Url; dt.Rows.Add(dr); } if (dt.Rows.Count == 0) { DataRow dr = dt.NewRow(); dr["ID"] = ""; dr["Title"] = "未查询到数据"; dr["PublishDate"] = ""; dr["ViewsCounts"] = ""; dr["Region"] = ""; dr["Property"] = ""; dr["Url"] = ""; dt.Rows.Add(dr); } //context.Response.Write("<script>lert(\'ManageInfos.DoSearch\');</script>"); } catch (Exception ex) { throw ex; //DataRow dr = dt.NewRow(); //dr["ID"] = ""; //dr["Title"] = "Error in ProcessRequest():" + ex.Message; //dr["PublishDate"] = ""; //dr["ViewsCounts"] = ""; //dr["Region"] = ""; //dr["Property"] = ""; //dr["Url"] = ""; //dt.Rows.Add(dr); } if (func == "1") //导出excel { ExportToExcelHelper eteh = new ExportToExcelHelper(); eteh.ExportToExcel(dt, "ManageInfoResult.xls", "[监测管理] -> [监测数据管理]"); } else { context.Response.Write(JsonConvert.SerializeObject(dt)); } }
public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; context.Response.Cache.SetNoStore(); string regionid = context.Request.QueryString["regionid"], reg = ""; string beginDate = context.Request.QueryString["beginDate"]; string endDate = context.Request.QueryString["endDate"]; string keyword = context.Request.QueryString["keyword"]; string func = context.Request.QueryString["func"]; if (regionid == "" || regionid.Contains("-1")) { GetRegionIdHelper grih = new GetRegionIdHelper(); regionid = grih.GetRegionID(); } DataTable dt = new DataTable(); dt.Columns.Add("ID"); dt.Columns.Add("Title"); dt.Columns.Add("PublishDate"); dt.Columns.Add("ViewsCounts"); dt.Columns.Add("Keyword"); dt.Columns.Add("Region"); dt.Columns.Add("Url"); try { string strWhere = ""; ArrayList strWhereList = new ArrayList(); if (beginDate != "" && endDate != "") { strWhereList.Add(" PublishDate>=\'" + beginDate + "\' and PublishDate<=\'" + endDate + " 23:59:59.999\'"); } if (regionid != "") { strWhereList.Add(" RegionID in (" + regionid + ")"); } if (keyword != "") { strWhereList.Add(" Keyword like N\'%" + keyword + "%\'"); } switch (strWhereList.Count) { case 1: strWhere = strWhereList[0].ToString(); break; case 2: strWhere = strWhereList[0].ToString() + " and " + strWhereList[1].ToString(); break; case 3: strWhere = strWhereList[0].ToString() + " and " + strWhereList[1].ToString() + " and " + strWhereList[2].ToString(); break; default: break; } SM.YuQing.BLL.MonitorInfos monitorInfoBll = new SM.YuQing.BLL.MonitorInfos(); List <SM.YuQing.Model.MonitorInfos> monitorInfoList = monitorInfoBll.GetModelList(strWhere); foreach (SM.YuQing.Model.MonitorInfos monitorInfo in monitorInfoList) { DataRow dr = dt.NewRow(); dr["ID"] = monitorInfo.ID; dr["Title"] = monitorInfo.Title; dr["PublishDate"] = monitorInfo.PublishDate.ToString("yyyy-MM-dd"); dr["ViewsCounts"] = monitorInfo.ViewsCounts; dr["Keyword"] = monitorInfo.Keyword; if (monitorInfo.RegionID > 0) { SM.YuQing.BLL.Regions regionBll = new SM.YuQing.BLL.Regions(); SM.YuQing.Model.Regions region = regionBll.GetModel(Convert.ToInt32(monitorInfo.RegionID)); reg = region.Mall; } else { reg = ""; } dr["Region"] = reg; dr["Url"] = monitorInfo.Url; dt.Rows.Add(dr); } if (dt.Rows.Count == 0) { DataRow dr = dt.NewRow(); dr["ID"] = ""; dr["Title"] = "未查询到数据"; dr["PublishDate"] = ""; dr["ViewsCounts"] = ""; dr["Keyword"] = ""; dr["Region"] = ""; dr["Url"] = ""; dt.Rows.Add(dr); } } catch (Exception ex) { throw ex; //DataRow dr = dt.NewRow(); //dr["Title"] = "Error in ProcessRequest():" + ex.Message; //dr["PublishDate"] = ""; //dr["ViewsCounts"] = ""; //dr["Keyword"] = ""; //dr["Region"] = ""; //dr["Url"] = ""; //dt.Rows.Add(dr); } if (func == "1") //导出excel { ExportToExcelHelper eteh = new ExportToExcelHelper(); eteh.ExportToExcel(dt, "IndustryResult.xls", "[监测管理] -> [行业监测]"); } else { context.Response.Write(JsonConvert.SerializeObject(dt)); } }