1.程式执行果面:
2.Program SOURCE CODE:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Windows;
using System.Data.SqlClient;
using System.Threading;
using System.Web;
using System.Collections;
using System.Diagnostics;
namespace BareBoard_Querying.SN
{
public class Program
{
static public String Sn_Str = String.Empty;
static public String CompleteMachine_SN = String.Empty;
static public String BareBoard_SN = String.Empty;
static public String Mac_Address = String.Empty;
static int Main(string[] args)
{
if (args.Length == 2)
{
DataBase_Inquire MyDb_In = new DataBase_Inquire("GPUSERVER", "E_CompleteMachine","sa","adminsystem");
if (args[0] == @"/B_SN")
{
if (ReadText(args[1],1) == true)
{
if (MyDb_In.Qerying_SN(Sn_Str, "usp_Querying_BareBoard_SN", 1) == true)
{
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("Querying "+Sn_Str+" BareBoard_SN OK!!");
return 0;
}
else
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("Querying " + Sn_Str + " BareBoard_SN NG!!");
return 1;
}
}
else
{
WriteLog("Read " + args[1] + " File Content Err!!");
return 1;
}
}
else if (args[0] == @"/C_SN")
{
if (ReadText(args[1],1) == true)
{
if (MyDb_In.Qerying_SN(Sn_Str, "usp_Querying_CompleteMachine_SN", 2) == true)
{
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("Querying " + Sn_Str + " CompleteMachine_SN OK!!");
return 0;
}
else
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("Querying " + Sn_Str + " CompleteMachine_SN NG!!");
return 1;
}
}
else
{
WriteLog("Read "+args[1]+" File Content Err!!");
return 1;
}
}
else
Help();
}
else if ((args.Length ==3)&&(args[0] ==@"/TY2_Qu"))
{
DataBase_Inquire MyDb_In_2 = new DataBase_Inquire("GPUSERVER", "E_CompleteMachine", "sa", "adminsystem");
if (ReadText(args[1],3) && ReadText(args[2],4))
{
if (MyDb_In_2.Qerying_RAM_TieYards_2(BareBoard_SN, Mac_Address, "usp_RAM_TieYards_2_Querying"))
{
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("Querying " + CompleteMachine_SN + "," + BareBoard_SN + "," + Mac_Address + " TieYards_3 OK!!");
return 0;
}
else
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("Querying " + CompleteMachine_SN + "," + BareBoard_SN + "," + Mac_Address + " TieYards_3 NG!!");
return 1;
}
}
else
{
WriteLog("Read " + args[1] +","+args[2]+","+args[3]+","+" File Content Err!!");
return 1;
}
}
else if ((args.Length == 4)&&(args[0] ==@"/TY3_Qu"))
{
DataBase_Inquire MyDb_In_3 = new DataBase_Inquire("GPUSERVER", "E_CompleteMachine", "sa", "adminsystem");
if (ReadText(args[1],2) && ReadText(args[2],3) &&
ReadText(args[3],4))
{
if (MyDb_In_3.Qerying_RAM_TieYards_3(CompleteMachine_SN,BareBoard_SN, Mac_Address, "usp_RAM_TieYards_3_Querying"))
{
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine(BareBoard_SN + "," + Mac_Address + " TieYards_3 OK!!");
return 0;
}
else
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(BareBoard_SN + "," + Mac_Address + " TieYards_3 NG!!");
return 1;
}
}
else
{
WriteLog("Read " + args[1] + "," + args[2] + "," + " File Content Err!!");
return 1;
}
}
else
Help();
return 1;
}
static public Boolean ReadText(String TextFileName,int Items)
{
Boolean Flag = false;
try
{
FileStream fs = new FileStream(TextFileName, FileMode.Open, FileAccess.Read);
StreamReader sr = new StreamReader(fs,Encoding.Default);
if (Items == 1) Sn_Str = sr.ReadLine();
else if (Items == 2) CompleteMachine_SN = sr.ReadLine();
else if (Items == 3) BareBoard_SN = sr.ReadLine();
else if (Items == 4) Mac_Address = sr.ReadLine();
sr.Close();
fs.Close();
Flag = true;
}
catch (Exception ex)
{
Flag = false;
WriteLog(ex.ToString());
}
return Flag;
}
static public void WriteLog(String Str)
{
FileStream fs = new FileStream("Log.txt", FileMode.Append, FileAccess.Write);
StreamWriter sw = new StreamWriter(fs);
sw.WriteLine(Str);
sw.Close();
}
static void Help()//帮助信息
{
Console.Clear();//清屏
Console.WriteLine("Program Version.1.00");
Console.WriteLine("Property in Copyright Ferex ShenBo.");
Console.WriteLine("============================================================================================");
Console.WriteLine(@"/B_SN Bare plate SN check!!");
Console.WriteLine(@"/C_SN SN inspection of the whole machine!!");
Console.WriteLine(@"/TY3_Qu 3 Yards In One Data Query");
Console.WriteLine(@"/TY2_Qu 2 Yards In One Data Query");
Console.WriteLine(@"Example_1: *.exe /B_SN B_SN.TXT");
Console.WriteLine(@"Example_2: *.exe /TY3_Qu CompleteMachine_SN.TXT BareBoard_SN.TXT Mac_Address.TXT");
Console.WriteLine(@"Example_3: *.exe /TY2_Qu BareBoard_SN.TXT Mac_Address.TXT");
}
}
}
3.DataBase_Inquire SOURCE CODE:
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.IO;
using System.Data.SqlClient;
using System.Threading;
using System.Diagnostics;
using System.Collections;
using System.Web;
namespace BareBoard_Querying.SN
{
public class DataBase_Inquire : Program
{
public String server;
public String database;
public String uid;
public String pwd;
//public String Stored_Procedure;
public DataBase_Inquire(String SERVER, String DATABASE, String UID, String PWD)
{
this.server = SERVER;
this.database = DATABASE;
this.uid = UID;
this.pwd = PWD;
}
public Boolean Qerying_RAM_TieYards_2(String BareBoard_SN, String Mac_Address, String Procedure_Str)//查询二码合一数据是否存在
{
Boolean Flag = false;
String SqlConnectionStr = "server=" + server + ";database=" + database + ";uid=" + uid + ";pwd=" + pwd;
SqlConnection conn = new SqlConnection(SqlConnectionStr);
try
{
conn.Open();
SqlCommand cmd = new SqlCommand(Procedure_Str, conn);
cmd.CommandType = CommandType.StoredProcedure;//启动数据库存储过程
cmd.Parameters.Add("@BareBoard_SN", BareBoard_SN);
cmd.Parameters.Add("@Mac_Address", Mac_Address);
cmd.Parameters.Add("@rest", 1);//设置返回参数
cmd.Parameters["@rest"].Direction = ParameterDirection.Output;//启动输出返回
cmd.ExecuteNonQuery();
if ((int)cmd.Parameters["@rest"].Value == 0)
{
conn.Close();
Flag = true;
}
else
{
conn.Close();
WriteLog(BareBoard_SN + "," + Mac_Address + " Cannot Be Found In The Database!!");
}
}
catch (Exception ex)
{
conn.Close();
Flag = false;
WriteLog(ex.ToString());
}
return Flag;
}
public Boolean Qerying_RAM_TieYards_3(String CompleteMachine_SN, String BareBoard_SN, String Mac_Address, String Procedure_Str)//查询三码合一数据是否存在
{
Boolean Flag = false;
String SqlConnectionStr = "server=" + server + ";database=" + database + ";uid=" + uid + ";pwd=" + pwd;
SqlConnection conn = new SqlConnection(SqlConnectionStr);
try
{
conn.Open();
SqlCommand cmd = new SqlCommand(Procedure_Str, conn);
cmd.CommandType = CommandType.StoredProcedure;//启动数据库存储过程
cmd.Parameters.Add("@CompleteMachine_SN", CompleteMachine_SN);
cmd.Parameters.Add("@BareBoard_SN", BareBoard_SN);
cmd.Parameters.Add("@Mac_Address", Mac_Address);
cmd.Parameters.Add("@rest", 1);//设置返回参数
cmd.Parameters["@rest"].Direction = ParameterDirection.Output;//启动输出返回
cmd.ExecuteNonQuery();
if ((int)cmd.Parameters["@rest"].Value == 0)
{
conn.Close();
Flag = true;
}
else
{
conn.Close();
WriteLog(CompleteMachine_SN + "," + BareBoard_SN + "," + Mac_Address + " Cannot Be Found In The Database!!");
}
}
catch (Exception ex)
{
conn.Close();
Flag = false;
WriteLog(ex.ToString());
}
return Flag;
}
public Boolean Qerying_SN(String SN, String Procedure_Str,int Items)//查询RAM_SN在数据库中是否存在
{
Boolean Flag = false;
String SqlConnectionStr = "server=" + server + ";database=" + database + ";uid=" + uid + ";pwd=" + pwd;
SqlConnection conn = new SqlConnection(SqlConnectionStr);
try
{
conn.Open();
SqlCommand cmd = new SqlCommand(Procedure_Str, conn);
cmd.CommandType = CommandType.StoredProcedure;//启动数据库存储过程
if (Items == 1) cmd.Parameters.Add("@BareBoard_SN", SN);
else cmd.Parameters.Add("@CompleteMachine_SN", SN);
cmd.Parameters.Add("@rest", 1);//设置返回参数
cmd.Parameters["@rest"].Direction = ParameterDirection.Output;//启动输出返回
cmd.ExecuteNonQuery();
if ((int)cmd.Parameters["@rest"].Value == 0)
{
conn.Close();
Flag = true;
}
else
{
conn.Close();
WriteLog(SN + " Cannot Be Found In The Database!!");
}
}
catch (Exception ex)
{
conn.Close();
WriteLog("Connection" + this.server + "Data Base Err \nOr " + ex.ToString() + "!!");
Flag = false;
}
return Flag;
}
public Boolean Delete_Items(String Stored_Procedure,String Str)
{
Boolean Flag = false;
String SqlConnectionStr = "server=" + server + ";database=" + database + ";uid=" + uid + ";pwd=" + pwd;
SqlConnection conn = new SqlConnection(SqlConnectionStr);
try
{
conn.Open();
SqlCommand cmd = new SqlCommand(Stored_Procedure,conn);
cmd.CommandType = CommandType.StoredProcedure;//启动数据库存过程
cmd.Parameters.Add("@Str", Str);
cmd.Parameters.Add("@rs",1);//设置返回参数
cmd.Parameters["@rs"].Direction = ParameterDirection.Output;//启动输出返回
cmd.ExecuteNonQuery();
if ((int)cmd.Parameters["@rs"].Value == 0)
{
conn.Close();
Flag = true;
}
else
{
conn.Close();
WriteLog("Connection" + this.server + "Data Base Err!!");
Flag = false;
}
}
catch (Exception ex)
{
Flag = false;
WriteLog(ex.ToString());
}
return Flag;
}
public void WriteLog(String Str)
{
FileStream fs = new FileStream("Log.txt",FileMode.Append,FileAccess.Write);
StreamWriter sw = new StreamWriter(fs);
sw.WriteLine(Str);
sw.Close();
}
public Boolean RAM_TieYards_3(String StoredProcedure_str, String ProductName_Str, String CompleteMachine_SN,
String BareBoard_SN, String Mac_Address, String NowDate)//插入RAM板3码合一数据
{
Boolean Flag = false;
SqlConnection conn = new SqlConnection("server="+this.server+";database="+this.database+";uid="+this.uid+";pwd="+this.pwd);
conn.Open();
try
{
SqlCommand cmd = new SqlCommand(StoredProcedure_str,conn);//启动存储过程参数
cmd.CommandType = CommandType.StoredProcedure;//启动储存过程参数
cmd.Parameters.Add("@ProductName", ProductName_Str);//设置参数1
cmd.Parameters.Add("@CompleteMachine_SN",CompleteMachine_SN);
cmd.Parameters.Add("@BareBoard_SN", BareBoard_SN);
cmd.Parameters.Add("@Mac_Address", Mac_Address);
cmd.Parameters.Add("@Date_Time", NowDate);
cmd.Parameters.Add("@rest", 1);//设置返回值
cmd.Parameters["@rest"].Direction = ParameterDirection.Output;//启动输出返回
cmd.ExecuteScalar();
if ((int)cmd.Parameters["@rest"].Value == 0)
{
Flag = true;
}
else
{
Flag = false;
}
}
catch (Exception ex)
{
Flag = false;
this.WriteLog(ex.ToString());
}
return Flag;
}
public Boolean QueryingData_Return(List
{
Boolean Flag = false;
String Conn_Str = "server="+this.server+";database="+this.database+";uid="+this.uid+";pwd="+this.pwd;
SqlConnection conn = new SqlConnection(Conn_Str);
conn.Open();
try
{
SqlCommand cmd = new SqlCommand(StoredProcedure,conn);
SqlDataReader reader = cmd.ExecuteReader();//读取执行过程
//List
FileStream fs = new FileStream("BOM.log",FileMode.Create,FileAccess.Write);
StreamWriter sw = new StreamWriter(fs);
while (reader.Read())
{
String aa = String.Empty;
aa = reader[1].ToString() + "," + reader[2].ToString() + "," + reader[3].ToString() + "," + reader[4].ToString();
sw.WriteLine(aa);
ss.Add(reader[1].ToString());
//Temp.Add(aa);
}
//ss = Temp;
sw.Close();
fs.Close();
reader.Close();
conn.Close();
Flag = true;
}
catch (Exception ex)
{
Flag = false;
this.WriteLog(ex.ToString());
//MessageBox.Show("连接" + this.server + "数据库获取BOM编码信息出错!!", "系统提醒", MessageBoxButtons.OK, MessageBoxIcon.Error);
System.Environment.Exit(1);
}
return Flag;
}
}
}