110,571
社区成员
发帖
与我相关
我的任务
分享
public class FlowSize
{
public long up;
public long down;
public long flow;
public long daysum;
public long monthsum;
public FlowSize()
{
this.down = 0;
this.up = 0;
}
public void clear()
{
this.down = 0;
this.up = 0;
}
public bool Isempty()
{
if ((this.down == 0) && (this.up == 0)) return true;
else return false;
}
public static bool WriteDebugLog = true;
public static int TimeWaitCloseMainWindow = 30;
public static int TimeWaitClose = 30;
public static int TimeWaitKillProcess = 30;
}
public static void Refresh_TempData(FlowSize grab_flow)
{
DateTime time = DateTime.Now;
string dbpath = Application.StartupPath + @"\FlowDB.mdb";
OleDbConnection con = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data source=" + dbpath);
long flow = 0;
FlowSize grab, real;
grab = new FlowSize();
real = new FlowSize();
try
{
con.Open();
OleDbCommand cmd = con.CreateCommand();
cmd.CommandText = "select * from FlowPerMonth where cstr(YearMonth) = '" + GetStandardYM(time)+ "'";
OleDbDataReader reader = cmd.ExecuteReader();
if (reader.Read())
{
flow = Convert.ToInt64(reader["User_GB"].ToString()) * num + Convert.ToInt64(reader["User_B"].ToString());
}
reader.Close();
cmd.CommandText = "select * from FlowPerday where cstr(FlowData) ='" + GetStandardYMD(time) + "'";
reader = cmd.ExecuteReader();
while (reader.Read())
{
grab.up += Convert.ToInt64(reader["Grab_up_GB"].ToString()) * num + Convert.ToInt64(reader["Grab_up_B"].ToString());
grab.down += Convert.ToInt64(reader["Grab_down_GB"].ToString()) * num + Convert.ToInt64(reader["Grab_down_B"].ToString());
}
reader.Close();
con.Close();
UpdateWindow.UpdateFlowMonth(flow+grab_flow.up+grab_flow.down);
UpdateWindow.UpdateFlowPerDay(grab.up+grab_flow.up, grab.down+grab_flow.down);
}
catch (Exception ee)
{
Flowfairy.FairyLog.WriteLog(ee.ToString());
}
}
public class FlowSize
{
public long up;//数据库中的数据均为整数,故用long
public long down;
public static long flows;
public static long getflows()
{
return flows;
}
public long daysum;
public long monthsum;
public FlowSize()
{
this.down = 0;
this.up = 0;;
}
public void clear()
{
this.down = 0;
this.up = 0;
}
public bool Isempty()
{
if ((this.down == 0) && (this.up == 0)) return true;
else return false;
}
}
public static void Refresh_TempData(FlowSize grab_flow)//grab_flow是类FlowSize的实例
{
DateTime time = DateTime.Now;//time是当前时间
string dbpath = Application.StartupPath + @"\FlowDB.mdb";//dbpath是数据库的路径,即和应用程序在同一目录下的FlowDB.mdb文件
OleDbConnection con = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data source=" + dbpath);//创建到数据库的链接
long flow = 0;
FlowSize grab, real;//grab, real类FlowSize的实例
grab = new FlowSize();
real = new FlowSize();//初始化grab和real
try
{
con.Open();//尝试打开数据库
OleDbCommand cmd = con.CreateCommand();//cmd为创建数据库命令的对象
cmd.CommandText = "select * from FlowPerMonth where cstr(YearMonth) = '" + GetStandardYM(time)+ "'";
// cmd.CommandText是要执行的SQL语句
OleDbDataReader reader = cmd.ExecuteReader();//reader为执行数据库命令的对象
if (reader.Read())//若要执行的命令读取成功
{
flow = Convert.ToInt64(reader["User_GB"].ToString()) * num + Convert.ToInt64(reader["User_B"].ToString());
//从数据表FlowPerMonth中读取User_GB和User_B字段的值并相加,得到用户目前当月的总流量
}
reader.Close();//关闭命令
cmd.CommandText = "select * from FlowPerday where cstr(FlowData) ='" + GetStandardYMD(time) + "'";
reader = cmd.ExecuteReader();
while (reader.Read())//若读取成功则更新grab.up和grab.down的值
{
grab.up += Convert.ToInt64(reader["Grab_up_GB"].ToString()) * num + Convert.ToInt64(reader["Grab_up_B"].ToString());
//从数据表FlowPerday中读取Grab_up_GB和Grab_up_B字段的值并相加,得到目前当天的上传流量
grab.down += Convert.ToInt64(reader["Grab_down_GB"].ToString()) * num + Convert.ToInt64(reader["Grab_down_B"].ToString());
//从数据表FlowPerday中读取Grab_down_GB和Grab_down_B字段的值并相加,得到目前当天的下载流量
}
reader.Close();
con.Close();//关闭数据库连接
UpdateWindow.UpdateFlowMonth(flow+grab_flow.up+grab_flow.down);
//当月流量为目前当月的总流量与上传流量和下载流量之和,上传流量和下载流量分别是数据库中的数据加上实时改变的流量
UpdateWindow.UpdateFlowPerDay(grab.up+grab_flow.up, grab.down+grab_flow.down);
//当天流量为上传流量和下载流量之和,他们分别是数据库中的数据加上实时改变的流量
FlowSize.flows = grab.up+grab_flow.up+grab.down+grab_flow.down;
FlowSize.getflows();
}
catch (Exception ee)
{
Flowfairy.FairyLog.WriteLog(ee.ToString());
}
}