62,073
社区成员
发帖
与我相关
我的任务
分享
public static bool GetPubMsg(string usrname, DateTime downtime, string onltime, string upload, string download ,string usrcookies)
{
lk.Model.PubMsg p = new PubMsg();
p.usrname = usrname;
p.onltime = onltime;
p.downtime = downtime;
string pattern = @"([0-9]*)\s[\u4e00-\u9fa5]*\s([0-9]*)\s[\u4e00-\u9fa5]*\s([0-9]*)\s[\u4e00-\u9fa5]*\s([0-9]*)\s[\u4e00-\u9fa5]*";
string d="";
string h="";
string m="";
string s="";
Regex regex = new Regex(pattern, RegexOptions.Compiled);
Match mh = regex.Match(onltime);
if (mh.Success)
{
d = mh.Groups[1].Value;
h = mh.Groups[2].Value;
m = mh.Groups[3].Value;
s = mh.Groups[4].Value;
}
DateTime uptime = downtime.AddDays(0 - Convert.ToInt32(d));
uptime = uptime.AddHours(0 - Convert.ToDouble(h));
uptime = uptime.AddMinutes(0 - Convert.ToDouble(m));
uptime = uptime.AddSeconds(0 - Convert.ToDouble(s));
p.uptime = uptime;
p.lkadmin = usrcookies;
double up = 0;
double down = 0;
double sum = 0;
string patterng = @"([0-9.]*)[G]";
string patternk = @"([0-9.]*)[K]";
string patternb = @"([0-9.]*)[B]";
string patternm = @"([0-9.]*)[M]";
Regex rg = new Regex(patterng, RegexOptions.Compiled);
Match mg = rg.Match(upload);
Regex rk = new Regex(patternk, RegexOptions.Compiled);
Match mk = rk.Match(upload);
Regex rb = new Regex(patternb, RegexOptions.Compiled);
Match mb = rb.Match(upload);
Regex rm = new Regex(patternm, RegexOptions.Compiled);
Match mm = rm.Match(upload);
if (mg.Success)
{
up = Double.Parse(mg.Groups[1].Value) * 1048576;
}
else if (mk.Success)
{
up =Double.Parse(mk.Groups[1].Value);
}
else if (mb.Success)
{
up = Double.Parse(mb.Groups[1].Value)/1024;
}
else if (mm.Success)
{
up = Double.Parse(mm.Groups[1].Value) * 1024;
}
Match mdg = rg.Match(download);
Match mdk = rk.Match(download);
Match mdb = rb.Match(download);
Match mdm = rm.Match(download);
if (mdg.Success)
{
down = Double.Parse(mdg.Groups[1].Value) * 1048576;
}
else if (mdk.Success)
{
down = Double.Parse(mdk.Groups[1].Value);
}
else if (mdb.Success)
{
down = Double.Parse(mdb.Groups[1].Value)/1024;
}
else if (mdm.Success)
{
down = Double.Parse(mdm.Groups[1].Value) * 1024;
}
sum = up + down;
p.sumload = sum.ToString();
DateTime dtnow = DateTime.Now;
dtnow = dtnow.AddHours(0-6);
p.createtime = dtnow;
p.download = down.ToString();
p.upload = up.ToString();
bool b=lk.PubSql.PubSql.CheckMsg(usrname, downtime);
if (b==true)
{
lk.PubSql.PubSql.PubMsgllIn(p);
//实例化用户信息字段
lk.Model.UsrInfo UsrInfo = new lk.Model.UsrInfo();
//通过用户名读取用户流量字段值
UsrInfo = lk.PubSql.UsrInfo.GetAllUsrInfo(usrname);
//用户已用流量加上用户本次扫描的流量
double lusred = Convert.ToDouble(UsrInfo.llusred) + sum;
//更新数据库
lk.PubSql.UsrInfo.UpdataLLusred(lusred, usrname);
}
else
{
}
return b;
//实际环境中加上以下判断权限
//if (usrcookies != null)
//{
//}
//else
//{
//}
}
}
}
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Text.RegularExpressions;
using System.Xml;
using lk.Model;
using lk.PubSql;
using lk.Config;
namespace lk.Web.manage
{
public partial class ReadInfo : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (Request.Cookies["lkadmin"]==null)
Response.Redirect(DBConfig.zipath+"login.aspx");
if (lk.PubSql.AdminSql.CheckLog(Request.Cookies["lkadmin"].Value) == false)
{
int truevalue = 0;
int faslevalue = 0;
int sumvalue = 0;
if (!IsPostBack)
{
if (Request["code"] == "msginfo")
{
XmlDocument Xmld = new XmlDocument();
Xmld.Load(Request.InputStream);
XmlElement xmlel = (XmlElement)Xmld.DocumentElement.ChildNodes[0];
string PubMsg = xmlel.FirstChild.Value;
//string PubMsg = Session["pubmsg"].ToString();
//string pattern = @"([0-9]{4}\-[0-9]{2}\-[0-9]{2}\s[0-9]{2}\:[0-9]{2}\:[0-9]{2})\s\w{5}\s[\u4e00-\u9fa5]{2}\s(jh[0-9]{3}|sw[0-9]{3})/(\w{3,8})/[0-9\.]{9,14}\s[\u4e00-\u9fa5]{3}\s*\1\s[\u4e00-\u9fa5]{4}:\s([0-9]*\s[\u4e00-\u9fa5]*\s[0-9]*\s[\u4e00-\u9fa5]*\s[0-9]*\s[\u4e00-\u9fa5]*\s[0-9]*\s[\u4e00-\u9fa5]*),\s[\u4e00-\u9fa5]{4}\s{1,}([0-9.]*[MBKG]),\s[\u4e00-\u9fa5]{4}\s{1,}([0-9.]*[MBKG])";
string pattern = @"([0-9]{4}\-[0-9]{2}\-[0-9]{2}\s[0-9]{2}\:[0-9]{2}\:[0-9]{2})\s[\u4e00-\u9fa5]{4}:\s([0-9]*\s[\u4e00-\u9fa5]*\s[0-9]*\s[\u4e00-\u9fa5]*\s[0-9]*\s[\u4e00-\u9fa5]*\s[0-9]*\s[\u4e00-\u9fa5]*),\s[\u4e00-\u9fa5]{4}\s{1,}([0-9.]*[MBKG]),\s[\u4e00-\u9fa5]{4}\s{1,}([0-9.]*[MBKG])\s*\1\s\w{5,10}\s[\u4e00-\u9fa5]{2}\s(jh[0-9]{3}|sw[0-9]{3})/(\w{3,8})/[0-9\.]{9,14}\s[\u4e00-\u9fa5]{3}";
Regex regex = new Regex(pattern, RegexOptions.Compiled);
Match match = regex.Match(PubMsg);
while (match.Success)
{
string tm = match.Value;
//string g1 = match.Groups[1].Value;//断开时间
//string g2 = match.Groups[2].Value;//用户名
//string g4 = match.Groups[4].Value;//在线时间
//string g5 = match.Groups[5].Value;//上传流量
//string g6 = match.Groups[6].Value;//下载流量
string g1 = match.Groups[1].Value;//断开时间
string g2 = match.Groups[5].Value;//用户名
string g4 = match.Groups[2].Value;//在线时间
string g5 = match.Groups[3].Value;//上传流量
string g6 = match.Groups[4].Value;//下载流量
string usrcookies = Request.Cookies["lkadmin"].Value; //实际环境需要开启读取cookie
//string usrcookies = "lkadmin";
if (ReadInfo.GetPubMsg(g2, Convert.ToDateTime(g1), g4, g5, g6, usrcookies) == true)
{
truevalue += 1;
}
else
{
faslevalue += 1;
}
string _tm = "";
PubMsg = PubMsg.Replace(tm, _tm);
//match = regex.Match(PubMsg);
match = match.NextMatch();
sumvalue += 1;
Session["sumvalue"] = sumvalue.ToString();//把所有正确读取的条数赋值给session
}
Response.Write("总扫描数据条数:" + sumvalue + " 写入条数:" + truevalue + " 抛弃数据库已存在数据条数:" + faslevalue);
Response.End();
}
else if (Request["code"] == "usrmsg")
{
XmlDataDocument xmld = new XmlDataDocument();
xmld.Load(Request.InputStream);
XmlElement xmle = (XmlElement)xmld.DocumentElement.ChildNodes[0];
string usrname = xmle.FirstChild.Value;
lk.Model.UsrInfo usrinfo=new lk.Model.UsrInfo();
usrinfo = lk.PubSql.UsrInfo.GetAllUsrInfo(usrname);
string namel = "";
string beizhu = "";
string uip = "";
DateTime loadtime = Convert.ToDateTime("2001-1-1 1:1");
if (usrinfo.name == null)
{
usrinfo.name = namel;
}
if (usrinfo.beizhu == null)
{
usrinfo.beizhu = beizhu;
}
if (usrinfo.uip == null)
{
usrinfo.uip = uip;
}
if (usrinfo.loadtime == Convert.ToDateTime("0001-1-1 0:00:00"))
{
usrinfo.loadtime = loadtime;
}
string str = string.Format("{0},{1},{2},{3},{4},{5},{6},{7},{8},{9},{10}", usrinfo.usrname, usrinfo.usrpsw, usrinfo.name, usrinfo.menu, usrinfo.beizhu, usrinfo.uip, usrinfo.loadtime, usrinfo.loadpaz, usrinfo.llusred, usrinfo.zt, usrinfo.bull);
Response.Write(str);
Response.End();
}
else if (Request["code"] == "usrtj")
{
XmlDocument Xmld = new XmlDocument();
Xmld.Load(Request.InputStream);
XmlElement xmlel = (XmlElement)Xmld.DocumentElement.ChildNodes[0];
string usrmsg = xmlel.FirstChild.Value;
string[] usrarray = new string[11];
char c = Convert.ToChar(",");
usrarray = usrmsg.Split(c);
if (lk.PubSql.PubSql.CheckUsr(usrarray[0]) == false)
{
lk.Model.UsrInfo us = new lk.Model.UsrInfo();
us.usrname = usrarray[0];
us.usrpsw = usrarray[1];
us.menu = int.Parse(usrarray[3]);
us.llusred = int.Parse(usrarray[8]);
us.bull = int.Parse(usrarray[10]);
us.name = usrarray[2];
us.loadtime = Convert.ToDateTime(usrarray[6]);
us.loadpaz = int.Parse(usrarray[7]);
us.uip = usrarray[5];
us.zt = int.Parse(usrarray[9]);
us.beizhu = usrarray[4];
if (lk.PubSql.PubSql.IntoUsrMsg(us) == true)
{
Response.Write("true");
Response.End();
}
else
{
Response.Write("false");
Response.End();
}
}
else
{
Response.Write("usrnot");
Response.End();
}
}
Response.Redirect(DBConfig.zipath + "erro.aspx");
}
}
else
{
Response.Redirect(DBConfig.zipath+"login.aspx");
}
}
下边还有接上边
//定义四个数组
ArrayList number = new ArrayList();
ArrayList ip = new ArrayList();
ArrayList address = new ArrayList();
ArrayList date = new ArrayList();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
string Path = Server.MapPath("info.txt");
getStr(Path);
for (int i = 0; i < number.Count; i++)
{
Response.Write(number[i].ToString()+" | ");
}
Response.Write("<br/>");
for (int j = 0; j< number.Count; j++)
{
Response.Write(ip[j].ToString() + " | ");
}
Response.Write("<br/>");
for (int k = 0; k < number.Count; k++)
{
Response.Write(number[k].ToString() + " | ");
}
Response.Write("<br/>");
for (int l = 0; l < number.Count;l++)
{
Response.Write(number[l].ToString() + " | ");
}
}
}
//读取txt行中的每一个数据
public void getStr(string Path)
{
string strLine = "";
int i = 0;
try
{
StreamReader sr = new StreamReader(Path, Encoding.GetEncoding("GB2312"));
while ((strLine=sr.ReadLine()) != null)
{
string[] val = strLine.Split(' ');
//将数据保存在ArrayList集合中
number.Add(val[0]);
ip.Add(val[1]);
address.Add(val[2]);
date.Add(val[3]);
Response.Write("当前第"+i+"行:<br/>");
foreach (string s in val)
{
Response.Write(s + "<br>");
}
i++;
Response.Write("<hr>");
}
sr.Dispose();
sr.Close();
}
catch
{
}
}
string content = "youstring";
string[] lines = content.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
foreach (string li in lines)
{
string[] line = li.Split(' ');
//line[0]
//取到第一个数字和数据库判断,如果数据库中存在continue继续循环下一个继续判断
}
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
string Path = Server.MapPath("2.txt");//路径
insertStr(Path);
}
}
//读取文件
public void insertStr(string Path)
{
string strLine = "";
int i = 0;
try
{
StreamReader sr = new StreamReader(Path, Encoding.GetEncoding("GB2312"));
strLine = sr.ReadLine();
while (strLine != null)
{
Response.Write(strLine + "<br>");
strLine = sr.ReadLine();
i++;
}
Response.Write(i);
sr.Dispose();
sr.Close();
}
catch
{
}
}
string[] rows = File.ReadAllLines(Server.MapPath("~/ip.txt"));
foreach (string row in rows)
{
string[] datas = row.Split(' ');
foreach (string data in datas)
Response.Write(data + " ");
Response.Write("<br/>");
}
//定义四个数组
ArrayList number = new ArrayList();
ArrayList ip = new ArrayList();
ArrayList address = new ArrayList();
ArrayList date = new ArrayList();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
string Path = Server.MapPath("info.txt");
getStr(Path);
for (int i = 0; i < number.Count; i++)
{
Response.Write(number[i].ToString()+" | ");
}
Response.Write("<br/>");
for (int j = 0; j< number.Count; j++)
{
Response.Write(ip[j].ToString() + " | ");
}
Response.Write("<br/>");
for (int k = 0; k < number.Count; k++)
{
Response.Write(number[k].ToString() + " | ");
}
Response.Write("<br/>");
for (int l = 0; l < number.Count;l++)
{
Response.Write(number[l].ToString() + " | ");
}
}
}
//读取txt行中的每一个数据
public void getStr(string Path)
{
string strLine = "";
int i = 0;
try
{
string url = "http://192.168.0.121/txt/info.txt";
string temp = "";
System.Net.WebRequest wreq = System.Net.WebRequest.Create(url);
System.Net.HttpWebResponse wresp = (System.Net.HttpWebResponse)wreq.GetResponse();
System.IO.Stream s = wresp.GetResponseStream();
System.IO.StreamReader sr = new System.IO.StreamReader(s, System.Text.Encoding.GetEncoding("gb2312"));
while ((strLine=sr.ReadLine()) != null)
{
string[] val = strLine.Split(' ');
//将数据保存在ArrayList集合中
number.Add(val[0]);
ip.Add(val[1]);
address.Add(val[2]);
date.Add(val[3]);
Response.Write("当前第"+i+"行:<br/>");
foreach (string s in val)
{
Response.Write(s + "<br>");
}
i++;
Response.Write("<hr>");
}
sr.Dispose();
sr.Close();
}
catch
{
}
}
string url ="http://192.168.0.121/txt/info.txt";
string temp="";
System.Net.WebRequest wreq=System.Net.WebRequest.Create(url);
System.Net.HttpWebResponse wresp=(System.Net.HttpWebResponse)wreq.GetResponse();
System.IO.Stream s=wresp.GetResponseStream();
System.IO.StreamReader sr=new System.IO.StreamReader(s,System.Text.Encoding.GetEncoding("gb2312"));
temp=sr.ReadToEnd();//temp为你读的内容.
//如果temp为空则没有找到文件
if(temp=="")
{
Response .Write ("文件不存在");
}
else
{
Response.Write("存在");
}