做了个关于多线程连接存储数据库的程序,但是总感觉在数据库的open()上感觉有点乱乱的!希望各位看官给点意见啊!
using System;
using System.Drawing;
using System.Collections;//Arrylist
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Runtime.InteropServices;
using System.Threading;
using System.Data.SqlClient;
namespace ground
{
/**////
/// Form1 的摘要说明。
///
public class Form1 : System.Windows.Forms.Form
{
data define#region data define
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.Button button3;
private System.Windows.Forms.Button button4;
private System.Windows.Forms.Button button5;
private System.Windows.Forms.ProgressBar progressBar1;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Button button6;
private System.ComponentModel.IContainer components;
//设定系统时间
System.DateTime currentTime=new System.DateTime();
System.DateTime currentTime1=new System.DateTime();
System.DateTime currentTime0=new System.DateTime();
//定义插入语句
string insert_mq="INSERT INTO MQ_DATA (MQ_DATA,OFFSET,TIME,ID) VALUES(ch[i][0],ch[i][1],ch[i][2])";
string insert_zlj="INSERT INTO ZLJ_DATA (ZLJ_DATA,OFFSET,TIME) VALUES(ch[i][0],ch[i][1],ch[i][2])";
string insert_return="INSERT INTO RETURN_MQ_DATA (RETURN_MQ_DATA,OFFSET,TIME) VALUES(ch[i][0],ch[i][1],ch[i][2])";
string insert_rc="INSERT INTO RC_DATA (RC_DATA,OFFSET,TIME) VALUES(ch[i][0],ch[i][1],ch[i][2])";
string insert_b="INSERT INTO B_DATA (B_DATA,OFFSET,TIME) VALUES(ch[i][0],ch[i][1],ch[i][2])";
string insert_locom="INSERT INTO LOCOM_DATA (LOCOM_DATA,OFFSET,TIME) VALUES(ch[i][0],ch[i][1],ch[i][2])";
string insert_s="INSERT INTO S_DATA (S_DATA,OFFSET,TIME) VALUES(ch[i][0],ch[i][1],ch[i][2])";
string insert_l="INSERT INTO L_DATA (L_DATA,OFFSET,TIME) VALUES(ch[i][0],ch[i][1],ch[i][2])";
string insert_error="INSERT INTO ERROR_DATA (ERROR_DATA,OFFSET,TIME) VALUES(ch[i][0],ch[i][1],ch[i][2])";
//定义输入数据
private int[]data_mq= new int[1000];
private int[]data_zlj= new int[1000];
private int[]data_return= new int[1000];
private int[]data_rc= new int[1000];
private int[]data_b= new int[1000];
private int[]data_locom= new int[1000];
private int[]data_s= new int[1000];
private int[]data_l= new int[1000];
private int[]data_error= new int[1000];
//定义样本数据(定期更新)
private int[]check_mq= new int[1000];
private int[]check_zlj= new int[1000];
private int[]check_return= new int[1000];
private int[]check_rc= new int[1000];
private int[]check_b= new int[1000];
private int[]check_locom= new int[1000];
private int[]check_s= new int[1000];
private int[]check_l= new int[1000];
private int[]check_error= new int[1000];
//进程说明
private Thread mq;
private Thread zlj;
private Thread return_mq;
private Thread rc;
private Thread b;
private Thread locom;
private Thread s;
private Thread error;
private Thread l;
private Thread t;
private int x;//数组长度
#endregion
//数据库连接
SqlConnection mySqlConnection=new SqlConnection("server=(local);database=GroundDB;uid=sa;pwd=sa");
public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
currentTime1=System.DateTime.Now;
InitializeComponent();
button2.Enabled=false;
button3.Enabled=false;
//开辟进程
mq=new Thread(new ThreadStart(MQ));
zlj=new Thread(new ThreadStart(ZLJ));
return_mq=new Thread(new ThreadStart(RETURN));
rc=new Thread(new ThreadStart(RC_DATA));
b=new Thread(new ThreadStart(B_DATA));
locom=new Thread (new ThreadStart(LOCOM_DATA));
s=new Thread(new ThreadStart(S_DATA));
l=new Thread (new ThreadStart(L_DATA));
error=new Thread (new ThreadStart(ERROR_DATA));
t=new Thread(new ThreadStart(ProgBar));
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
/**////
/// 清理所有正在使用的资源。
///
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
Windows 窗体设计器生成的代码#region Windows 窗体设计器生成的代码
/**////
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
///
private void InitializeComponent()
{
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1));
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.button3 = new System.Windows.Forms.Button();
this.button4 = new System.Windows.Forms.Button();
this.button5 = new System.Windows.Forms.Button();
this.progressBar1 = new System.Windows.Forms.ProgressBar();
this.label1 = new System.Windows.Forms.Label();
this.button6 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(56, 112);
this.button1.Name = "button1";
this.button1.TabIndex = 0;
this.button1.Text = "接收数据";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// button2
//
this.button2.Location = new System.Drawing.Point(184, 112);
this.button2.Name = "button2";
this.button2.TabIndex = 1;
this.button2.Text = "挂起";
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// button3
//
this.button3.Location = new System.Drawing.Point(312, 112);
this.button3.Name = "button3";
this.button3.TabIndex = 2;
this.button3.Text = "恢复";
this.button3.Click += new System.EventHandler(this.button3_Click);
//
// button4
//
this.button4.Location = new System.Drawing.Point(432, 112);
this.button4.Name = "button4";
this.button4.TabIndex = 3;
this.button4.Text = "停止";
this.button4.Click += new System.EventHandler(this.button4_Click);
//
// button5
//
this.button5.Location = new System.Drawing.Point(312, 184);
this.button5.Name = "button5";
this.button5.Size = new System.Drawing.Size(96, 23);
this.button5.TabIndex = 4;
this.button5.Text = "退出";
this.button5.Click += new System.EventHandler(this.button5_Click);
//
// progressBar1
//
this.progressBar1.Location = new System.Drawing.Point(160, 40);
this.progressBar1.Name = "progressBar1";
this.progressBar1.Size = new System.Drawing.Size(352, 32);
this.progressBar1.TabIndex = 5;
//
// label1
//
this.label1.Location = new System.Drawing.Point(56, 40);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(80, 32);
this.label1.TabIndex = 7;
this.label1.Text = "当前状态:";
this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// button6
//
this.button6.Location = new System.Drawing.Point(160, 184);
this.button6.Name = "button6";
this.button6.Size = new System.Drawing.Size(96, 23);
this.button6.TabIndex = 8;
this.button6.Text = "查看";
this.button6.Click += new System.EventHandler(this.button6_Click);
//
// Form1
//
this.AutoScale = false;
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.AutoScroll = true;
this.ClientSize = new System.Drawing.Size(560, 266);
this.Controls.Add(this.button6);
this.Controls.Add(this.label1);
this.Controls.Add(this.progressBar1);
this.Controls.Add(this.button5);
this.Controls.Add(this.button4);
this.Controls.Add(this.button3);
this.Controls.Add(this.button2);
this.Controls.Add(this.button1);
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.Name = "Form1";
this.Text = "数据接收";
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false);
}
#endregion
/**////
/// 应用程序的主入口点。
///
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void SavePoint(string save)
{
SqlCommand mySqlCommand=mySqlConnection.CreateCommand();
mySqlConnection.Open();
SqlTransaction mySqlTransaction=mySqlConnection.BeginTransaction();
mySqlCommand.Transaction=mySqlTransaction;
//保存记录
mySqlTransaction.Save("Save_mq");
//记录回滚
//mySqlTransaction.Rollback(Savepoint);
}
private void timer()
{
// long a1=DateTime.Now.Ticks;//millsecond 单位
// //System.DateTime b=System.DateTime.Now;
//
// int []In=new int [1000];//接收数据
/**/////
// do
// {
// check=In;
// }
// while ((a2-a1)/(10*60*1000))==0);
}
threading !!!???#region threading !!!???
//进程函数定义
private void ProgBar()
{
do
{
Thread.Sleep(500);
if (progressBar1.Value >= 100 )
{
progressBar1.Value = 0;
}
progressBar1.Value += 5;
}while (true);
SavePoint("save");
}
private void MQ()
{
int[,] check=new int[x,3];
int i=0;
int j=0;
currentTime=System.DateTime.Now;
int Mills=currentTime.Millisecond;
for(i=0;i<=x;)
{
if((data_mq[i]!=check_mq[i])&&(j<x))
{
check[j,2]=Mills;
check[j,1]=data_mq[i];
check[j,0]=i;
j++;
i++;
}
}
DataConn(check,insert_mq);
}
private void ZLJ()
{
int[,] check=new int[x,3];
int i=0;
int j=0;
currentTime=System.DateTime.Now;
int Mills=currentTime.Millisecond;
for(i=0;i<=x;)
{
if((data_mq[i]!=check_zlj[i])&&(j<x))
{
check[j,2]=Mills;
check[j,1]=data_zlj[i];
check[j,0]=i;
j++;
i++;
}
}
DataConn(check,insert_zlj);
}
private void RETURN()
{
int[,] check=new int[x,3];
int i=0;
int j=0;
currentTime=System.DateTime.Now;
int Mills=currentTime.Millisecond;
for(i=0;i<=x;)
{
if((data_mq[i]!=check_return[i])&&(j<x))
{
check[j,2]=Mills;
check[j,1]=data_return[i];
check[j,0]=i;
j++;
i++;
}
}
DataConn(check,insert_return);
}
private void RC_DATA()
{
int[,] check=new int[x,3];
int i=0;
int j=0;
currentTime=System.DateTime.Now;
int Mills=currentTime.Millisecond;
for(i=0;i<=x;)
{
if((data_mq[i]!=check_rc[i])&&(j<x))
{
check[j,2]=Mills;
check[j,1]=data_rc[i];
check[j,0]=i;
j++;
i++;
}
}
DataConn(check,insert_rc);
}
private void B_DATA()
{
int[,] check=new int[x,3];
int i=0;
int j=0;
currentTime=System.DateTime.Now;
int Mills=currentTime.Millisecond;
for(i=0;i<=x;)
{
if((data_mq[i]!=check_b[i])&&(j<x))
{
check[j,2]=Mills;
check[j,1]=data_b[i];
check[j,0]=i;
j++;
i++;
}
}
DataConn(check,insert_b);
}
private void LOCOM_DATA()
{
int[,] check=new int[x,3];
int i=0;
int j=0;
currentTime=System.DateTime.Now;
int Mills=currentTime.Millisecond;
for(i=0;i<=x;)
{
if((data_mq[i]!=check_locom[i])&&(j<x))
{
check[j,2]=Mills;
check[j,1]=data_locom[i];
check[j,0]=i;
j++;
i++;
}
}
DataConn(check,insert_locom);
}
private void S_DATA()
{
int[,] check=new int[x,3];
int i=0;
int j=0;
currentTime=System.DateTime.Now;
int Mills=currentTime.Millisecond;
for(i=0;i<=x;)
{
if((data_mq[i]!=check_s[i])&&(j<x))
{
check[j,2]=Mills;
check[j,1]=data_s[i];
check[j,0]=i;
j++;
i++;
}
}
DataConn(check,insert_s);
}
private void L_DATA()
{
int[,] check=new int[x,3];
int i=0;
int j=0;
currentTime=System.DateTime.Now;
int Mills=currentTime.Millisecond;
for(i=0;i<=x;)
{
if((data_mq[i]!=check_l[i])&&(j<x))
{
check[j,2]=Mills;
check[j,1]=data_l[i];
check[j,0]=i;
j++;
i++;
}
}
DataConn(check,insert_l);
}
private void ERROR_DATA()
{
int[,] check=new int[x,3];
int i=0;
int j=0;
currentTime=System.DateTime.Now;
int Mills=currentTime.Millisecond;
for(i=0;i<=x;)
{
if((data_mq[i]!=check_error[i])&&(j<x))
{
check[j,2]=Mills;
check[j,1]=data_error[i];
check[j,0]=i;
DataConn(check,insert_error);
j++;
i++;
}
}
}
#endregion
Conn#region Conn
private void DataConn(int[,] a,string insert)//check 数组 ,the name of database ,insert
{//数据存储
int[,] ch=new int [x,3];
ch=a;
SqlCommand mySqlCommand=mySqlConnection.CreateCommand();
SqlDataAdapter mySqlDataAdapter=new SqlDataAdapter();
for(int i=0;i<x;i++)
{
mySqlCommand.CommandText=insert;
//计算所插入的数组数量
//int nomberOfRows=mySqlCommand.ExecuteNonQuery();
}
mySqlCommand.Connection.Close();
}
#endregion
winform#region winform
private void button1_Click(object sender, System.EventArgs e)
{
currentTime0=System.DateTime.Now;//取时间样本
//进程开始
t.Start();
zlj.Start();
return_mq.Start();
rc.Start();
b.Start();
locom.Start();
s.Start();
l.Start();
error.Start();
mq.Start();
button1.Enabled=false;
button2.Enabled=true;
button3.Enabled=false;
}
private void button2_Click(object sender, System.EventArgs e)
{
//进程挂起
mq.Suspend();
t.Suspend();
zlj.Suspend();
return_mq.Suspend();
rc.Suspend();
b.Suspend();
locom.Suspend();
s.Suspend();
l.Suspend();
error.Suspend();
button2.Enabled=false;
button3.Enabled=true;
button4.Enabled=false;
}
private void button3_Click(object sender, System.EventArgs e)
{
//进程恢复
mq.Resume();
t.Resume();
zlj.Resume();
return_mq.Resume();
rc.Resume();
b.Resume();
locom.Resume();
s.Resume();
l.Resume();
error.Resume();
button2.Enabled=true;
button3.Enabled=false;
button4.Enabled=true;
}
private void button4_Click(object sender, System.EventArgs e)
{
//进程退出
t.Abort();
mq.Abort();
zlj.Abort();
return_mq.Abort();
rc.Abort();
b.Abort();
locom.Abort();
s.Abort();
l.Abort();
error.Abort();
button2.Enabled=false;
button3.Enabled=false;
}
private void button6_Click(object sender, System.EventArgs e)
{
//打开form2
Form2 form2=new Form2();
form2.ShowDialog();
}
private void button5_Click(object sender, System.EventArgs e)
{
//关闭form
this.Close();
}
private void timer1_Tick(object sender, System.EventArgs e)
{
}
private void Form1_Load(object sender, System.EventArgs e)
{
}
#endregion
}
}
using System.Drawing;
using System.Collections;//Arrylist
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Runtime.InteropServices;
using System.Threading;
using System.Data.SqlClient;
namespace ground
{
/**////
/// Form1 的摘要说明。
///
public class Form1 : System.Windows.Forms.Form
{
data define#region data define
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.Button button3;
private System.Windows.Forms.Button button4;
private System.Windows.Forms.Button button5;
private System.Windows.Forms.ProgressBar progressBar1;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Button button6;
private System.ComponentModel.IContainer components;
//设定系统时间
System.DateTime currentTime=new System.DateTime();
System.DateTime currentTime1=new System.DateTime();
System.DateTime currentTime0=new System.DateTime();
//定义插入语句
string insert_mq="INSERT INTO MQ_DATA (MQ_DATA,OFFSET,TIME,ID) VALUES(ch[i][0],ch[i][1],ch[i][2])";
string insert_zlj="INSERT INTO ZLJ_DATA (ZLJ_DATA,OFFSET,TIME) VALUES(ch[i][0],ch[i][1],ch[i][2])";
string insert_return="INSERT INTO RETURN_MQ_DATA (RETURN_MQ_DATA,OFFSET,TIME) VALUES(ch[i][0],ch[i][1],ch[i][2])";
string insert_rc="INSERT INTO RC_DATA (RC_DATA,OFFSET,TIME) VALUES(ch[i][0],ch[i][1],ch[i][2])";
string insert_b="INSERT INTO B_DATA (B_DATA,OFFSET,TIME) VALUES(ch[i][0],ch[i][1],ch[i][2])";
string insert_locom="INSERT INTO LOCOM_DATA (LOCOM_DATA,OFFSET,TIME) VALUES(ch[i][0],ch[i][1],ch[i][2])";
string insert_s="INSERT INTO S_DATA (S_DATA,OFFSET,TIME) VALUES(ch[i][0],ch[i][1],ch[i][2])";
string insert_l="INSERT INTO L_DATA (L_DATA,OFFSET,TIME) VALUES(ch[i][0],ch[i][1],ch[i][2])";
string insert_error="INSERT INTO ERROR_DATA (ERROR_DATA,OFFSET,TIME) VALUES(ch[i][0],ch[i][1],ch[i][2])";
//定义输入数据
private int[]data_mq= new int[1000];
private int[]data_zlj= new int[1000];
private int[]data_return= new int[1000];
private int[]data_rc= new int[1000];
private int[]data_b= new int[1000];
private int[]data_locom= new int[1000];
private int[]data_s= new int[1000];
private int[]data_l= new int[1000];
private int[]data_error= new int[1000];
//定义样本数据(定期更新)
private int[]check_mq= new int[1000];
private int[]check_zlj= new int[1000];
private int[]check_return= new int[1000];
private int[]check_rc= new int[1000];
private int[]check_b= new int[1000];
private int[]check_locom= new int[1000];
private int[]check_s= new int[1000];
private int[]check_l= new int[1000];
private int[]check_error= new int[1000];
//进程说明
private Thread mq;
private Thread zlj;
private Thread return_mq;
private Thread rc;
private Thread b;
private Thread locom;
private Thread s;
private Thread error;
private Thread l;
private Thread t;
private int x;//数组长度
#endregion
//数据库连接
SqlConnection mySqlConnection=new SqlConnection("server=(local);database=GroundDB;uid=sa;pwd=sa");
public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
currentTime1=System.DateTime.Now;
InitializeComponent();
button2.Enabled=false;
button3.Enabled=false;
//开辟进程
mq=new Thread(new ThreadStart(MQ));
zlj=new Thread(new ThreadStart(ZLJ));
return_mq=new Thread(new ThreadStart(RETURN));
rc=new Thread(new ThreadStart(RC_DATA));
b=new Thread(new ThreadStart(B_DATA));
locom=new Thread (new ThreadStart(LOCOM_DATA));
s=new Thread(new ThreadStart(S_DATA));
l=new Thread (new ThreadStart(L_DATA));
error=new Thread (new ThreadStart(ERROR_DATA));
t=new Thread(new ThreadStart(ProgBar));
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
/**////
/// 清理所有正在使用的资源。
///
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
Windows 窗体设计器生成的代码#region Windows 窗体设计器生成的代码
/**////
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
///
private void InitializeComponent()
{
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1));
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.button3 = new System.Windows.Forms.Button();
this.button4 = new System.Windows.Forms.Button();
this.button5 = new System.Windows.Forms.Button();
this.progressBar1 = new System.Windows.Forms.ProgressBar();
this.label1 = new System.Windows.Forms.Label();
this.button6 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(56, 112);
this.button1.Name = "button1";
this.button1.TabIndex = 0;
this.button1.Text = "接收数据";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// button2
//
this.button2.Location = new System.Drawing.Point(184, 112);
this.button2.Name = "button2";
this.button2.TabIndex = 1;
this.button2.Text = "挂起";
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// button3
//
this.button3.Location = new System.Drawing.Point(312, 112);
this.button3.Name = "button3";
this.button3.TabIndex = 2;
this.button3.Text = "恢复";
this.button3.Click += new System.EventHandler(this.button3_Click);
//
// button4
//
this.button4.Location = new System.Drawing.Point(432, 112);
this.button4.Name = "button4";
this.button4.TabIndex = 3;
this.button4.Text = "停止";
this.button4.Click += new System.EventHandler(this.button4_Click);
//
// button5
//
this.button5.Location = new System.Drawing.Point(312, 184);
this.button5.Name = "button5";
this.button5.Size = new System.Drawing.Size(96, 23);
this.button5.TabIndex = 4;
this.button5.Text = "退出";
this.button5.Click += new System.EventHandler(this.button5_Click);
//
// progressBar1
//
this.progressBar1.Location = new System.Drawing.Point(160, 40);
this.progressBar1.Name = "progressBar1";
this.progressBar1.Size = new System.Drawing.Size(352, 32);
this.progressBar1.TabIndex = 5;
//
// label1
//
this.label1.Location = new System.Drawing.Point(56, 40);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(80, 32);
this.label1.TabIndex = 7;
this.label1.Text = "当前状态:";
this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// button6
//
this.button6.Location = new System.Drawing.Point(160, 184);
this.button6.Name = "button6";
this.button6.Size = new System.Drawing.Size(96, 23);
this.button6.TabIndex = 8;
this.button6.Text = "查看";
this.button6.Click += new System.EventHandler(this.button6_Click);
//
// Form1
//
this.AutoScale = false;
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.AutoScroll = true;
this.ClientSize = new System.Drawing.Size(560, 266);
this.Controls.Add(this.button6);
this.Controls.Add(this.label1);
this.Controls.Add(this.progressBar1);
this.Controls.Add(this.button5);
this.Controls.Add(this.button4);
this.Controls.Add(this.button3);
this.Controls.Add(this.button2);
this.Controls.Add(this.button1);
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.Name = "Form1";
this.Text = "数据接收";
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false);
}
#endregion
/**////
/// 应用程序的主入口点。
///
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void SavePoint(string save)
{
SqlCommand mySqlCommand=mySqlConnection.CreateCommand();
mySqlConnection.Open();
SqlTransaction mySqlTransaction=mySqlConnection.BeginTransaction();
mySqlCommand.Transaction=mySqlTransaction;
//保存记录
mySqlTransaction.Save("Save_mq");
//记录回滚
//mySqlTransaction.Rollback(Savepoint);
}
private void timer()
{
// long a1=DateTime.Now.Ticks;//millsecond 单位
// //System.DateTime b=System.DateTime.Now;
//
// int []In=new int [1000];//接收数据
/**/////
// do
// {
// check=In;
// }
// while ((a2-a1)/(10*60*1000))==0);
}
threading !!!???#region threading !!!???
//进程函数定义
private void ProgBar()
{
do
{
Thread.Sleep(500);
if (progressBar1.Value >= 100 )
{
progressBar1.Value = 0;
}
progressBar1.Value += 5;
}while (true);
SavePoint("save");
}
private void MQ()
{
int[,] check=new int[x,3];
int i=0;
int j=0;
currentTime=System.DateTime.Now;
int Mills=currentTime.Millisecond;
for(i=0;i<=x;)
{
if((data_mq[i]!=check_mq[i])&&(j<x))
{
check[j,2]=Mills;
check[j,1]=data_mq[i];
check[j,0]=i;
j++;
i++;
}
}
DataConn(check,insert_mq);
}
private void ZLJ()
{
int[,] check=new int[x,3];
int i=0;
int j=0;
currentTime=System.DateTime.Now;
int Mills=currentTime.Millisecond;
for(i=0;i<=x;)
{
if((data_mq[i]!=check_zlj[i])&&(j<x))
{
check[j,2]=Mills;
check[j,1]=data_zlj[i];
check[j,0]=i;
j++;
i++;
}
}
DataConn(check,insert_zlj);
}
private void RETURN()
{
int[,] check=new int[x,3];
int i=0;
int j=0;
currentTime=System.DateTime.Now;
int Mills=currentTime.Millisecond;
for(i=0;i<=x;)
{
if((data_mq[i]!=check_return[i])&&(j<x))
{
check[j,2]=Mills;
check[j,1]=data_return[i];
check[j,0]=i;
j++;
i++;
}
}
DataConn(check,insert_return);
}
private void RC_DATA()
{
int[,] check=new int[x,3];
int i=0;
int j=0;
currentTime=System.DateTime.Now;
int Mills=currentTime.Millisecond;
for(i=0;i<=x;)
{
if((data_mq[i]!=check_rc[i])&&(j<x))
{
check[j,2]=Mills;
check[j,1]=data_rc[i];
check[j,0]=i;
j++;
i++;
}
}
DataConn(check,insert_rc);
}
private void B_DATA()
{
int[,] check=new int[x,3];
int i=0;
int j=0;
currentTime=System.DateTime.Now;
int Mills=currentTime.Millisecond;
for(i=0;i<=x;)
{
if((data_mq[i]!=check_b[i])&&(j<x))
{
check[j,2]=Mills;
check[j,1]=data_b[i];
check[j,0]=i;
j++;
i++;
}
}
DataConn(check,insert_b);
}
private void LOCOM_DATA()
{
int[,] check=new int[x,3];
int i=0;
int j=0;
currentTime=System.DateTime.Now;
int Mills=currentTime.Millisecond;
for(i=0;i<=x;)
{
if((data_mq[i]!=check_locom[i])&&(j<x))
{
check[j,2]=Mills;
check[j,1]=data_locom[i];
check[j,0]=i;
j++;
i++;
}
}
DataConn(check,insert_locom);
}
private void S_DATA()
{
int[,] check=new int[x,3];
int i=0;
int j=0;
currentTime=System.DateTime.Now;
int Mills=currentTime.Millisecond;
for(i=0;i<=x;)
{
if((data_mq[i]!=check_s[i])&&(j<x))
{
check[j,2]=Mills;
check[j,1]=data_s[i];
check[j,0]=i;
j++;
i++;
}
}
DataConn(check,insert_s);
}
private void L_DATA()
{
int[,] check=new int[x,3];
int i=0;
int j=0;
currentTime=System.DateTime.Now;
int Mills=currentTime.Millisecond;
for(i=0;i<=x;)
{
if((data_mq[i]!=check_l[i])&&(j<x))
{
check[j,2]=Mills;
check[j,1]=data_l[i];
check[j,0]=i;
j++;
i++;
}
}
DataConn(check,insert_l);
}
private void ERROR_DATA()
{
int[,] check=new int[x,3];
int i=0;
int j=0;
currentTime=System.DateTime.Now;
int Mills=currentTime.Millisecond;
for(i=0;i<=x;)
{
if((data_mq[i]!=check_error[i])&&(j<x))
{
check[j,2]=Mills;
check[j,1]=data_error[i];
check[j,0]=i;
DataConn(check,insert_error);
j++;
i++;
}
}
}
#endregion
Conn#region Conn
private void DataConn(int[,] a,string insert)//check 数组 ,the name of database ,insert
{//数据存储
int[,] ch=new int [x,3];
ch=a;
SqlCommand mySqlCommand=mySqlConnection.CreateCommand();
SqlDataAdapter mySqlDataAdapter=new SqlDataAdapter();
for(int i=0;i<x;i++)
{
mySqlCommand.CommandText=insert;
//计算所插入的数组数量
//int nomberOfRows=mySqlCommand.ExecuteNonQuery();
}
mySqlCommand.Connection.Close();
}
#endregion
winform#region winform
private void button1_Click(object sender, System.EventArgs e)
{
currentTime0=System.DateTime.Now;//取时间样本
//进程开始
t.Start();
zlj.Start();
return_mq.Start();
rc.Start();
b.Start();
locom.Start();
s.Start();
l.Start();
error.Start();
mq.Start();
button1.Enabled=false;
button2.Enabled=true;
button3.Enabled=false;
}
private void button2_Click(object sender, System.EventArgs e)
{
//进程挂起
mq.Suspend();
t.Suspend();
zlj.Suspend();
return_mq.Suspend();
rc.Suspend();
b.Suspend();
locom.Suspend();
s.Suspend();
l.Suspend();
error.Suspend();
button2.Enabled=false;
button3.Enabled=true;
button4.Enabled=false;
}
private void button3_Click(object sender, System.EventArgs e)
{
//进程恢复
mq.Resume();
t.Resume();
zlj.Resume();
return_mq.Resume();
rc.Resume();
b.Resume();
locom.Resume();
s.Resume();
l.Resume();
error.Resume();
button2.Enabled=true;
button3.Enabled=false;
button4.Enabled=true;
}
private void button4_Click(object sender, System.EventArgs e)
{
//进程退出
t.Abort();
mq.Abort();
zlj.Abort();
return_mq.Abort();
rc.Abort();
b.Abort();
locom.Abort();
s.Abort();
l.Abort();
error.Abort();
button2.Enabled=false;
button3.Enabled=false;
}
private void button6_Click(object sender, System.EventArgs e)
{
//打开form2
Form2 form2=new Form2();
form2.ShowDialog();
}
private void button5_Click(object sender, System.EventArgs e)
{
//关闭form
this.Close();
}
private void timer1_Tick(object sender, System.EventArgs e)
{
}
private void Form1_Load(object sender, System.EventArgs e)
{
}
#endregion
}
}