/// <summary> /// 添加用户 /// </summary> /// <param name="obj">用户对象</param> /// <returns></returns> public int InsReleaseInfo(ModelReleaseInfo obj) { string sql = @"INSERT INTO ReleaseInfo(Title,Contexts,ReleaseDate,InfoSource,KeyWords,ReleaseName,CollectDate,Snapshot) VALUES(@Title,@Contexts,@RleaseDate,@InfoSource,@KeyWords,@ReleaseName,@CollectDate,@Snapshot) "; List <MySqlParameter> par = new List <MySqlParameter>(); par.Add(new MySqlParameter("@Title", obj.Title)); par.Add(new MySqlParameter("@Contexts", obj.Contexts)); par.Add(new MySqlParameter("@RleaseDate", obj.ReleaseDate)); par.Add(new MySqlParameter("@InfoSource", obj.InfoSource)); par.Add(new MySqlParameter("@KeyWords", obj.KeyWords)); par.Add(new MySqlParameter("@ReleaseName", obj.ReleaseName)); par.Add(new MySqlParameter("@CollectDate", obj.CollectDate)); par.Add(new MySqlParameter("@Snapshot", obj.Snapshot)); try { MySqlCmd dbobj = new MySqlCmd(); return(dbobj.ExecuteNonQueryInt(sql, par)); } catch (Exception ex) { throw new Exception("新建失败,位置:InsReleaseInfo.原因:" + ex.Message); } }
/// <summary> /// 删除用户信息 /// </summary> /// <param name="uid">用户ID</param> /// <returns>返回值,1为成功</returns> public int DelReleaseInfo(int uid) { string sql = @"DELETE FROM ReleaseInfo WHERE uid=@uid"; List <MySqlParameter> par = new List <MySqlParameter>(); par.Add(new MySqlParameter("@uid", uid)); try { DataBaseServer.MySqlCmd dbobj = new MySqlCmd(); return(dbobj.ExecuteNonQueryInt(sql, par)); } catch (Exception ex) { throw new Exception("删除失败,位置:DelReleaseInfo.原因:" + ex.Message); } }
private void parseXml(string xml, bool isPublicTimeline) { try { XmlDocument xmldoc = new XmlDocument(); xmldoc.LoadXml(xml); if (xmldoc != null && xmldoc.ChildNodes.Count > 0) { XmlNode data = xmldoc.SelectSingleNode("//data"); if (isPublicTimeline) { XmlNode t = data.SelectSingleNode("//pos"); if (t == null) { return; } public_timeline_pos = int.Parse(t.InnerText); } XmlNodeList xnl = data.SelectNodes("//info"); StringBuilder sql = new StringBuilder(); ArrayList lst_kw = new ArrayList(); Hashtable ht_evt = new Hashtable(); string text = ""; string origtext = ""; string reposts = ""; string comments = ""; string infosource = ""; string nick = ""; string type = ""; string timestamp = ""; string weibo_id = ""; string name = ""; //foreach (XmlNode xn in xnl) for (int i = 0; i < xnl.Count; i++) { //XmlNode info = xn; XmlNode info = xnl[i]; //内容 text = info.SelectSingleNode("text") == null ? "" : info.SelectSingleNode("text").InnerText; //原始内容 origtext = info.SelectSingleNode("origtext") == null ? "" : info.SelectSingleNode("origtext").InnerText; //转发次数 reposts = info.SelectSingleNode("count") == null ? "" : info.SelectSingleNode("count").InnerText; //点评次数 comments = info.SelectSingleNode("mcount") == null ? "" : info.SelectSingleNode("mcount").InnerText; //来源 infosource = info.SelectSingleNode("from") == null ? "" : info.SelectSingleNode("from").InnerText; //发布人 nick = info.SelectSingleNode("nick") == null ? "" : info.SelectSingleNode("nick").InnerText; //微博类型。1-原创发表,2-转载,3-私信,4-回复,5-空回,6-提及,7-评论 type = info.SelectSingleNode("type") == null ? "" : info.SelectSingleNode("type").InnerText; //发表时间 timestamp = info.SelectSingleNode("timestamp") == null ? "" : info.SelectSingleNode("timestamp").InnerText; //微博id weibo_id = info.SelectSingleNode("id") == null ? "" : info.SelectSingleNode("id").InnerText; //博主name,拼微博链接用 name = info.SelectSingleNode("name") == null ? "" : info.SelectSingleNode("name").InnerText; StringBuilder sb_keys = new StringBuilder(); if (type == "1" || type == "2") { if (!weibo_ids.Equals(weibo_id) && long.Parse(weibo_ids.Equals("") ? "0" : weibo_ids) < long.Parse(weibo_id)) { foreach (string key in keywords) { string[] _words = key.Split(new char[] { ' ' }); if (!lst_kw.Contains(key)) { lst_kw.Add(key); foreach (string w in _words) { if (!origtext.Contains(w)) { lst_kw.Remove(key); break; } } } } ht_evt = evtJudge(dt_event, lst_kw); if (ht_evt.Count > 0) { int part = partJudge(dt_partWord, origtext); //判断正负向 weibo_ids = weibo_id; foreach (DictionaryEntry de in ht_evt) { int urlTherear = UrlThereare(weibo_id); if (urlTherear <= 0) { sql.Append("insert into ReleaseInfoWB (title,contexts,releasedate,infosource,keywords,releasename,collectdate,snapshot,webname,pid,part,reposts,comments,kid) values ('" + weibo_id + "','" + origtext + "','" + Comm.getTime(long.Parse(timestamp)) + "','" + "http://t.qq.com/" + name + "','" + de.Key.ToString() + "','" + nick + "','" + string.Format(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")) + "','','腾讯微博','3','" + part.ToString() + "','" + reposts + "','" + comments + "'," + de.Value.ToString() + ");"); //Console.WriteLine(sql); } } } lst_kw.Clear(); } } } if (sql.Length > 0) { cmd.ExecuteNonQueryInt(sql.ToString()); } } } catch (Exception e) { Console.WriteLine(e.Message); } }
public void timer_Elapsed(object source, System.Timers.ElapsedEventArgs e) { //关键字预警方式表 string timeNow = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); string timeBefore = ""; int aviCount = 1; //int sendAviCountSMS=1; string sql = ""; //string url = "http://www.shangwukaocha.cn/finder/users.php?userID=" + userID + "&m=q"; //取短信余额的网址,用userid先去服务端取可用短信数量aviCount ////每次往服务端提交一次短信使用量,服务端用来记录用户短信可用数量。当到达一定阀值,给用户发短信提示短信不足。 //string[] retVal = new string[3] { "", "","" }; //try //{ // string _r = postSend(url, ""); // if (_r.Contains(',')) // { // retVal = _r.Split(','); // } // aviCount = int.Parse(retVal[0].Equals("") ? "1" : retVal[0]); //可用量 // sendAviCountSMS = int.Parse(retVal[1].Equals("") ? "1" : retVal[1]); //是否已发送短信账户不足提示 //} //catch (FormatException fe) {} //DataTable dt_alert_collection_sms = cmd.GetTabel("select * from warn where WarnWay=1"); //DataTable dt_alert_collection_snd = cmd.GetTabel("select * from warn where WarnWay=2"); string sendText = ""; DateTime hashtableTime; int thisTimeCount = 0; //本次短信使用数量 string tmp_IntervalHours = ""; //每个关键词的预警周期 int tmp_IntervalHoursTotalInfo = 0; //每个关键词的预警数量 string tmp_keyword = ""; //关键词 string tmp_sendContent = ""; //关键词报警短信发送的内容 string tmp_phoneNumber = ""; //发送到手机号 string tmp_hasSmsAlerted = "0"; //同一个关键词短信是否已报过警,报过为1 DataTable dt_alert_collection = cmd.GetTabel("select * from warn"); for (int icount = 0; icount <= dt_alert_collection.Rows.Count - 1; icount++) { //短信预警开始 if (dt_alert_collection.Rows[icount]["WarnWay"].ToString().Equals("1")) { if (aviCount > 0) { tmp_IntervalHours = dt_alert_collection.Rows[icount]["IntervalHours"].ToString(); tmp_IntervalHoursTotalInfo = int.Parse(dt_alert_collection.Rows[icount]["IntervalHoursTotalInfo"].ToString()); timeBefore = DateTime.Now.AddHours(-double.Parse(tmp_IntervalHours)).ToString("yyyy-MM-dd HH:mm:ss"); tmp_keyword = dt_alert_collection.Rows[icount]["keyword"].ToString(); tmp_sendContent = dt_alert_collection.Rows[icount]["WarnContent"].ToString(); tmp_phoneNumber = dt_alert_collection.Rows[icount]["mobile"].ToString(); sql = "select * from sms where keyword = '" + tmp_keyword + "' order by sendtime desc"; DataTable dtsms = cmd.GetTabel(sql); if (dtsms != null && dtsms.Rows.Count > 0) { string lastTime = dtsms.Rows[0]["sendtime"].ToString(); if (string.Compare(timeBefore, lastTime) < 0) { timeBefore = lastTime; } } //2015.3.18 wangcg 修改后,ReleaseInfo数据库的keywords字段存储的是关键字不是事件名称,需要修改sql //sql = "select count(1) cs,keywords from releaseinfo where collectdate between '" // + timeBefore + "' and '" // + timeNow + "' and " // + " keywords = '" + tmp_keyword + "'"; //样例sql: //select count(*) cs, b.name from releaseinfo a //left join keywords b on a.keywords=b.[KeyWord] //where b.[Name]='自然灾害' sql = @"select count(1) cs,b.Name keywords from releaseinfo a left join keywords b on a.keywords=b.KeyWord where a.collectdate between '{0}' and '{1}' and b.Name='{2}'"; sql = string.Format(sql, timeBefore, timeNow, tmp_keyword); DataTable dt_SMS = cmd.GetTabel(sql); if (int.Parse(dt_SMS.Rows[0]["cs"].ToString()) >= tmp_IntervalHoursTotalInfo) { tmp_hasSmsAlerted = "1"; //短时间内刚发过同样短信就不再发的判断 //if (ht.Contains(tmp_keyword)) //{ // hashtableTime = (DateTime)ht[tmp_keyword]; // if ((DateTime.Now - hashtableTime).TotalMinutes > double.Parse(tmp_IntervalHours) * 60) // { sendText = StringReplace(tmp_sendContent, "[事件名称]", insertSign(tmp_keyword)); sendSMS(sendText, tmp_phoneNumber, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); thisTimeCount++; //aviCount--; //ht.Remove(tmp_keyword); //ht.Add(tmp_keyword, DateTime.Now); sendText = ""; //发完短信在数据库中插入刚才发的短信记录 sql = "insert into sms (content,sendtime,mobile,keyword) values ('" + tmp_sendContent + "','" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "','" + tmp_phoneNumber + "','" + tmp_keyword + "')"; cmd.ExecuteNonQueryInt(sql); // } //} //else //{ // ht.Add(tmp_keyword, DateTime.Now); // sendText = StringReplace(tmp_sendContent, "[事件名称]", insertSign(tmp_keyword)); // sendSMS(sendText, tmp_phoneNumber, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); // thisTimeCount++; // //aviCount--; // sendText = ""; // //发完短信在数据库中插入刚才发的短信记录 // sql = "insert into sms (content,sendtime,mobile,keyword) values ('" // + tmp_sendContent + "','" // + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "','" // + tmp_phoneNumber + "','" // + tmp_keyword + "')"; // cmd.ExecuteNonQueryInt(sql); //} } else { tmp_hasSmsAlerted = "0"; } //if (aviCount <= 100 && sendAviCountSMS == 0) //{ // sendSMS("截止目前,您的舆情系统账户短信剩余量已不足100条,请尽快联系客服续费!", // tmp_phoneNumber, // DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); //} //"把本次使用量thisTimeCount,userID作为参数请求url" string url = "http://www.shangwukaocha.cn/finder/users.php?userID=" + userID + "&m=usc&smscount=" + thisTimeCount.ToString(); //2016.4.17 地址已经失效,去掉短信条数的登记服务 //postSend(url, ""); //if (int.Parse(retVal[2].Equals("") ? "0" : retVal[2]) == 0 && aviCount <= 0) //{ // sendSMS("截止目前,您的舆情系统账户短信剩余量已为0,短信功能将停止,请尽快联系客服续费!", // tmp_phoneNumber, // DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); //} } //短信预警结束 } else { //声音预警开始 if (dt_alert_collection.Rows[icount]["keyword"].ToString().Equals(tmp_keyword)) { //该关键字短信已经报警则声音也报警 if (tmp_hasSmsAlerted.Equals("1")) { tmp_sendContent = dt_alert_collection.Rows[icount]["WarnContent"].ToString(); soundAlert(tmp_keyword, tmp_sendContent); } } else { tmp_IntervalHours = dt_alert_collection.Rows[icount]["IntervalHours"].ToString(); tmp_IntervalHoursTotalInfo = int.Parse(dt_alert_collection.Rows[icount]["IntervalHoursTotalInfo"].ToString()); timeBefore = DateTime.Now.AddHours(-double.Parse(tmp_IntervalHours)).ToString("yyyy-MM-dd HH:mm:ss"); tmp_keyword = dt_alert_collection.Rows[icount]["keyword"].ToString(); tmp_sendContent = dt_alert_collection.Rows[icount]["WarnContent"].ToString(); tmp_phoneNumber = dt_alert_collection.Rows[icount]["mobile"].ToString(); //sql = "select count(1) cs,keywords from releaseinfo where collectdate between '" // + timeBefore + "' and '" // + timeNow + "' and " // + " keywords = '" + tmp_keyword + "'"; sql = "select * from soundAlert where keyword = '" + tmp_keyword + "' order by sendtime desc"; DataTable dtsms = cmd.GetTabel(sql); if (dtsms != null && dtsms.Rows.Count > 0) { string lastTime = dtsms.Rows[0]["sendtime"].ToString(); if (string.Compare(timeBefore, lastTime) < 0) { timeBefore = lastTime; } } //样例sql: //select count(*) cs, b.name from releaseinfo a //left join keywords b on a.keywords=b.[KeyWord] //where b.[Name]='自然灾害' sql = @"select count(1) cs,b.Name keywords from releaseinfo a left join keywords b on a.keywords=b.KeyWord where a.collectdate between '{0}' and '{1}' and b.Name='{2}'"; sql = string.Format(sql, timeBefore, timeNow, tmp_keyword); DataTable dt_SND = cmd.GetTabel(sql); if (int.Parse(dt_SND.Rows[0]["cs"].ToString()) >= tmp_IntervalHoursTotalInfo) { //此处还应加短时间内刚发过同样内容的声音预警就不再播放声音的判断 soundAlert(tmp_keyword, tmp_sendContent); } } } //声音预警结束 } }
private void dgv1_CellContentClick(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex != -1 && e.ColumnIndex == 5) //保存 { string sql; string kw; string hours; string hours_info; string content; string mobile; int id = 0; try { kw = dgv1.Rows[e.RowIndex].Cells[0].Value.ToString(); hours = dgv1.Rows[e.RowIndex].Cells[1].Value.ToString(); hours_info = dgv1.Rows[e.RowIndex].Cells[2].Value.ToString(); content = dgv1.Rows[e.RowIndex].Cells[3].Value.ToString(); mobile = dgv1.Rows[e.RowIndex].Cells[4].Value.ToString(); id = int.Parse(dgv1.Rows[e.RowIndex].Cells[5].Tag.ToString()); } catch (Exception ex) { MessageBox.Show("请确认您所有的数据都填写完整!", "提示", MessageBoxButtons.OK); return; } if (!Comm.isInteger(hours)) { MessageBox.Show("输入的时间格式不正确,应为整数!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); dgv1.Rows[e.RowIndex].Cells[1].Value = 0; return; } if (!Comm.isInteger(hours_info)) { MessageBox.Show("输入的次数格式不正确,应为整数!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); dgv1.Rows[e.RowIndex].Cells[2].Value = 0; return; } if (content.Trim().Length > 70) { MessageBox.Show("您输入的短信内容不正确。短信内容需小于70个字!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); dgv1.Rows[e.RowIndex].Cells[3].Value = content.Substring(0, 64); return; } if (!Comm.isMobile(mobile)) { MessageBox.Show("输入的手机格式不正确!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); dgv1.Rows[e.RowIndex].Cells[4].Value = "13988888888"; return; } if (!id.Equals(0)) { sql = "UPDATE Warn SET IntervalHours=@IntervalHours,IntervalHoursTotalInfo=@IntervalHoursTotalInfo," + "keyword=@keyword,WarnWay=@WarnWay,WarnContent=@WarnContent,Mobile=@Mobile WHERE ID=" + id; List <MySqlParameter> pars = new List <MySqlParameter>(); pars.Add(new MySqlParameter("@IntervalHours", hours)); pars.Add(new MySqlParameter("@IntervalHoursTotalInfo", hours_info)); pars.Add(new MySqlParameter("@keyword", kw)); pars.Add(new MySqlParameter("@WarnWay", 1)); pars.Add(new MySqlParameter("@WarnContent", content)); pars.Add(new MySqlParameter("@Mobile", mobile)); try { if (cmd.ExecuteNonQueryInt(sql, pars) > 0) { MessageBox.Show("保存成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); dgv1.CellValueChanged -= new DataGridViewCellEventHandler(dgv1_CellValueChanged); dgv1.Rows.Clear(); IniDgv1Data(); } else { MessageBox.Show("保存失败,请稍后重试或联系软件提供商!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } } catch (Exception ex) { MessageBox.Show("保存失败,请稍后重试或联系软件提供商!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } } else { if (!mobile.Equals("")) { sql = "insert into warn (IntervalHours,IntervalHoursTotalInfo,Keyword,WarnWay,WarnContent,Mobile) " + "values ('" + hours + "','" + hours_info + "','" + kw + "',1,'" + content + "','" + mobile + "')"; try { if (cmd.ExecuteNonQueryInt(sql) > 0) { MessageBox.Show("保存成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); dgv1.CellValueChanged -= new DataGridViewCellEventHandler(dgv1_CellValueChanged); dgv1.Rows.Clear(); IniDgv1Data(); } else { MessageBox.Show("保存失败,请稍后重试或联系软件提供商!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } } catch (Exception ex) { MessageBox.Show("保存失败,请稍后重试或联系软件提供商!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } } } } if (e.RowIndex != -1 && e.ColumnIndex == 6) //删除 { if (!dgv1.Rows[e.RowIndex].Cells[6].Tag.ToString().Equals("0")) { string sql = "delete from warn where id =" + int.Parse(dgv1.Rows[e.RowIndex].Cells[6].Tag.ToString()); try { if (cmd.ExecuteNonQueryInt(sql) > 0) { MessageBox.Show("删除成功!", "提示:", MessageBoxButtons.OK, MessageBoxIcon.Information); dgv1.CellValueChanged -= new DataGridViewCellEventHandler(dgv1_CellValueChanged); dgv1.Rows.Clear(); IniDgv1Data(); } else { MessageBox.Show("删除失败,请稍后重试或联系软件提供商!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } } catch (Exception ex) { MessageBox.Show("删除失败,请稍后重试或联系软件提供商!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } } } }
//由通过认证的新浪客户端,调取当前登录用户及其所关注用户的最新微博接口Friends_Timeline,n最大是一次100条 //获得最新的n条含有用户关键字的公共微博信息并存入数据库 public void getFriends_Timeline_sina(Client sinaClient, int n) { StringBuilder sql = new StringBuilder(); ArrayList lst_kw = new ArrayList(); Hashtable ht_evt = new Hashtable(); try { NetDimension.Weibo.Entities.status.Collection satColl = sinaClient.API.Entity.Statuses.FriendsTimeline("", "", n); foreach (NetDimension.Weibo.Entities.status.Entity entity in satColl.Statuses) { string text = entity.RetweetedStatus == null ? entity.Text : entity.Text + entity.RetweetedStatus.Text; if (!weibo_ids.Equals(entity.ID) || long.Parse(weibo_ids.Equals("") ? "0" : weibo_ids) > long.Parse(entity.ID)) { //把正文里包含的关键词都放入list for (int i = 0; i < dt_kw.Rows.Count; i++) { string[] _words = dt_kw.Rows[i][0].ToString().Split(new char[] { ' ' }); if (!lst_kw.Contains(dt_kw.Rows[i][0].ToString())) { lst_kw.Add(dt_kw.Rows[i][0].ToString()); foreach (string w in _words) { if (!text.Contains(w)) { lst_kw.Remove(dt_kw.Rows[i][0].ToString()); break; } } } } ht_evt = evtJudge(dt_event, lst_kw); if (ht_evt.Count > 0) { int part = partJudge(dt_partWord, text); weibo_ids = entity.ID; //string text = entity.RetweetedStatus == null ? entity.Text : entity.Text + entity.RetweetedStatus.Text; foreach (DictionaryEntry de in ht_evt) { int urlTherear = UrlThereare(entity.ID); if (urlTherear <= 0) { sql = sql.Append("insert into ReleaseInfoWB (title,contexts,releasedate,infosource," + "keywords,releasename,collectdate,snapshot,webname,pid,part,reposts,comments,kid) values ('"+entity.ID+"','" + text + "','" + string.Format(NetDimension.Weibo.Utility.ParseUTCDate(entity.CreatedAt).ToString("yyyy-MM-dd HH:mm:ss")) + "','" + "http://weibo.com/" + entity.User.ID + "','" + de.Key.ToString() + "','" + entity.User.Name + "','" + string.Format(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")) + "','','" + "新浪微博" + "','" + "3" + "','" + part.ToString() + "','" + entity.RepostsCount + "','" + entity.CommentsCount + "'," + de.Value.ToString() + ");"); } } } lst_kw.Clear(); } } } catch (Exception err) { Console.Write(err.Message); } //插入数据库 if (sql.Length > 0) cmd.ExecuteNonQueryInt(sql.ToString()); }