using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.IO;
using System.Threading;
using System.Timers;
using System.Web;
//using System.Timers;
namespace AginTestScanProgram
{
public partial class Form1 : Form
{
public static String[] KeyValue = { "NULL","NULL","NULL","NULL","NULL","NULL"};
public static String[] Smple = { "SNLEN", "SERVER", "DATABASE", "UID", "PWD", "StoredProcedure" };
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
CfgProcess MyCfg = new CfgProcess("config.ini");//读取配置
timer1.Enabled = true;
}
private void groupBox1_Enter(object sender, EventArgs e)
{
}
public class CfgProcess : Form1 {
public CfgProcess(String CfgFileName)
{
try
{
FileStream fs = new FileStream(CfgFileName,FileMode.Open,FileAccess.Read);
StreamReader sr = new StreamReader(fs,Encoding.Default);
String Temp = String.Empty;
while ((Temp = sr.ReadLine()) != null)
{
String[] Array = Temp.Split(new String[] { "=" }, StringSplitOptions.RemoveEmptyEntries);
int n = 0;
foreach (String str in Smple)
{
if (Array[0].Trim() == str)
{
KeyValue[n] = Array[1].Trim();
}
n++;
}
}
}
catch (Exception ex)
{
MessageBox.Show(CfgFileName+" Config Read Error:\n"+ex.ToString());
Environment.Exit(1);
}
}
}
public class SqlServerDataBaseProcess:Form1{
private String SERVER;
private String DATABASE;
private String UID;
private String PWD;
private String StoredProcedure;
public SqlServerDataBaseProcess(String SERVER, String DATABASE, String UID, String PWD, String StoredProcedure)//初始化类私有变量
{
this.SERVER = SERVER;
this.DATABASE = DATABASE;
this.UID = UID;
this.PWD = PWD;
this.StoredProcedure = StoredProcedure;
}
public bool ConnectionSqlServerDataBaseFindTestData(String Client_SN)
{
bool Flag = false;
SqlConnection conn = new SqlConnection("server="+this.SERVER+";database="+this.DATABASE+";uid="+this.UID+";pwd="+this.PWD);
conn.Open();
if (conn.State != ConnectionState.Open)
{
MessageBox.Show(this.SERVER+" Server "+this.DATABASE+" DataBase Connection Failed!!");
Flag = false;
return Flag;
}
SqlCommand cmd = new SqlCommand(this.StoredProcedure,conn);//设置命令行启动
cmd.CommandType = CommandType.StoredProcedure;//启动数据库存储过程
cmd.Parameters.Add("@Client_SN",Client_SN);//参数1
cmd.Parameters.Add("@rs",1);//参数2
cmd.Parameters["@rs"].Direction = ParameterDirection.Output;//启动输出返回
cmd.ExecuteScalar();
if ((int)cmd.Parameters["@rs"].Value == 0)
{
conn.Close();
Flag = true;
}
return Flag;
}
}
private void timer1_Tick(object sender, EventArgs e)
{
if (this.textBox1.Text.ToString().Length == Convert.ToInt32(KeyValue[0]))
{
SqlServerDataBaseProcess MySqlServerDataBaseProcess = new SqlServerDataBaseProcess(KeyValue[1],KeyValue[2],KeyValue[3],KeyValue[4],KeyValue[5]);//连接数据库
if (MySqlServerDataBaseProcess.ConnectionSqlServerDataBaseFindTestData(textBox1.Text.ToString().Trim()) == true)
{
label3.Text = "PASS";
label3.ForeColor = Color.Green;
label2.Text = "已完成老化测试!!";
label2.ForeColor = Color.Green;
}
else
{
label3.Text = "FAIL";
label3.ForeColor = Color.Red;
label2.Text = "未完成老化测试,请返回进行老化测试!!";
label2.ForeColor = Color.Red;
}
textBox1.Text = "";
}
}
private void label1_Click(object sender, EventArgs e)
{
}
}
}
USE E_AgeTestData
GO
IF EXISTS(SELECT *FROM SYS.OBJECTS WHERE name='usp_BurnInTest_Data_SN_Found')
DROP PROC usp_BurnInTest_Data_SN_Found
GO
CREATE PROC usp_BurnInTest_Data_SN_Found
@Client_SN VARCHAR(50),
@rs int output
as
SELECT @rs=count(*) FROM BurnInTest_Data WHERE @Client_SN=Client_SN
IF @@ERROR>0
BEGIN
SET @rs=1
END
ELSE IF @rs>0
BEGIN
SET @rs=0
END
ELSE IF @rs<=0
BEGIN
SET @rs=1
END
RETURN @rs
GO
图2: