c#+Sql server 綁碼程式 原始碼
c# 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.Windows.Forms; using System.IO; using System.Data.SqlClient;
namespace Tie_yards { public partial class Form1 : Form { public String[] Config = { "OrderNumber_Len", "OrderNumber_Str_prefix","CartonBarcode_Len","CartonBarcode_Str_prefix","ClenitSn_Len", "SERVER", "DATABASE", "UID", "PWD", "StoredProcedure" }; public String[] InputKeyValues ={"NULL","NULL","NULL","NULL","NULL","NULL","NULL","NULL", "NULL","NULL","NULL","NULL","NULL","NULL","NULL","NULL", "NULL","NULL","NULL","NULL","NULL","NULL"};
public String[] Character ={"0","1","2","3","4","5","6","7","8","9", "B","C","D","F","G","H","J","K","L","M", "N","P","Q","R","S","T","V","W","X","Y","Z"}; public int TieYards = 20; public List<TextBox> kk = new List<TextBox>();//填入控制元件陣列 public Form1() { InitializeComponent(); }
private void Form1_Load(object sender, EventArgs e) { ReadCfg("config.ini"); textBox1.Focus();//設定控制元件1焦點 kk.Add(this.textBox1); kk.Add(this.textBox2); kk.Add(this.textBox3); kk.Add(this.textBox4); kk.Add(this.textBox5); kk.Add(this.textBox6); kk.Add(this.textBox7); kk.Add(this.textBox8); kk.Add(this.textBox9); kk.Add(this.textBox10); kk.Add(this.textBox11); kk.Add(this.textBox12); kk.Add(this.textBox13); kk.Add(this.textBox14); kk.Add(this.textBox15); kk.Add(this.textBox16); kk.Add(this.textBox17); kk.Add(this.textBox18); kk.Add(this.textBox19); kk.Add(this.textBox20); kk.Add(this.textBox21); kk.Add(this.textBox22); comboBox1.SelectedIndex = 18;//設定綁碼預設值 } public void ReadCfg(String FileName) { try { FileStream fs = new FileStream(FileName,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 i in Config) { if (i ==Array[0].Trim()) { Config[n] = Array[1].Trim(); break; } n++; } } sr.Close(); fs.Close(); } catch (Exception e) { MessageBox.Show("未讀取到配置檔案錯誤資訊如下:\n"+e.ToString()); System.Environment.Exit(1);//退出主程式返回1 } }
private void textBox1_TextChanged(object sender, EventArgs e)////讀取訂單資訊 { label18.Text = ""; if (textBox1.Text.Length == Convert.ToInt32(Config[0])) { if ((ReadOrderInfo(textBox23, textBox24, textBox1)) == true) { if (QueryCartonBarcode(textBox2) == true) { this.SetConsole(textBox1, textBox3, 0, 1); button1.Enabled = true; } else { label18.Left = Convert.ToInt32(groupBox3.Width * 0.3); label18.Top = Convert.ToInt32(groupBox3.Height * 0.5); label18.ForeColor = Color.Red; label18.Text = "連線GPUSER資料中E_CompleteMachine資料表失敗或者外箱編碼超過上限!!"; textBox1.SelectAll();//選中文字框內容 textBox1.Focus();//設定文字框為焦點 } } } else if (textBox1.Text.Length > Convert.ToInt32(Config[0])) { label18.Left = Convert.ToInt32(groupBox3.Width * 0.3); label18.Top = Convert.ToInt32(groupBox3.Height * 0.5); label18.ForeColor = Color.Red; label18.Text = "錄入的工單號區間錯誤,請重新錄入!!"; textBox1.SelectAll();//選中文字框內容 textBox1.Focus();//設定文字框為焦點 } }
private void textBox2_TextChanged(object sender, EventArgs e)//判斷外箱條碼字首符合條件 { if (textBox2.Text.Length == Convert.ToInt32(Config[2])) { if (textBox2.Text.Contains(Config[3])) { this.SetConsole(textBox2, textBox3, 1,1); } else { label18.Left = Convert.ToInt32(groupBox3.Width * 0.3); label18.Top = Convert.ToInt32(groupBox3.Height * 0.5); label18.ForeColor = Color.Red; label18.Text = "錄入的外箱條碼區間錯誤,請重新錄入!!"; textBox2.SelectAll();//選中文字框內容 textBox2.Focus();//設定文字框為焦點 } } }
private void button1_Click(object sender, EventArgs e) { foreach (TextBox ss in kk) { ss.Enabled = false; ss.Text = ""; button1.Enabled = false; } textBox23.Text = ""; textBox24.Text = ""; comboBox1.Enabled = true; textBox1.Enabled = true; textBox1.Focus();//設定控制元件2焦點 }
public void SetConsole(TextBox C1,TextBox C2, int n,int Item)//設定及讀取控制元件內容 { if (Item == 1) { C1.Enabled = false; C2.Enabled = true; C2.Focus();//設定控制元件焦點 InputKeyValues[n] = C1.Text.Trim(); } else if (Item == 2) { C2.Focus();//設定控制元件焦點 InputKeyValues[n] = C1.Text.Trim(); } else if (Item == 3) { C1.Enabled = false; comboBox1.Enabled = true; comboBox1.Focus();//設定控制元件焦 InputKeyValues[n] = C1.Text.Trim(); } else if (Item == 4) { C1.Enabled = false; comboBox1.Enabled = false; C2.Enabled = true; C2.Focus();//設定控制元件焦點 InputKeyValues[n] = C1.Text.Trim(); if (comboBox1.Text.Trim() != "") TieYards = Convert.ToInt32(comboBox1.Text.Trim()); } }
private void textBox3_TextChanged(object sender, EventArgs e) { if ((ReadOrderInfo(textBox23, textBox24, textBox1)) == true)//讀取訂單資訊 { if (QueryCartonBarcode(textBox2) == true) { TextBoxControlArrayImplementation(textBox3, textBox4, Convert.ToInt32(Config[4]), 2, 4); } else { label18.Left = Convert.ToInt32(groupBox3.Width * 0.3); label18.Top = Convert.ToInt32(groupBox3.Height * 0.5); label18.ForeColor = Color.Red; label18.Text = "連線GPUSER資料中E_CompleteMachine資料表失敗或者外箱編碼超過上限!!"; textBox1.SelectAll();//選中文字框內容 textBox1.Focus();//設定文字框為焦點 } } }
private void textBox4_TextChanged(object sender, EventArgs e) { if (this.TieYards == 2) { if((TextBoxControlArrayImplementation(textBox4, textBox5, Convert.ToInt32(Config[4]), 3, 2))==true) ProcessEventuallyTieYards(); } else TextBoxControlArrayImplementation(textBox4, textBox5, Convert.ToInt32(Config[4]), 3, 1); }
private void textBox5_TextChanged(object sender, EventArgs e) { if (this.TieYards == 3) { if((TextBoxControlArrayImplementation(textBox5, textBox6, Convert.ToInt32(Config[4]), 4, 2))==true) ProcessEventuallyTieYards(); } else TextBoxControlArrayImplementation(textBox5, textBox6, Convert.ToInt32(Config[4]), 4, 1); }
private void textBox6_TextChanged(object sender, EventArgs e) { if (this.TieYards == 4) { if((TextBoxControlArrayImplementation(textBox6, textBox7, Convert.ToInt32(Config[4]), 5, 2))==true) ProcessEventuallyTieYards(); } else TextBoxControlArrayImplementation(textBox6, textBox7, Convert.ToInt32(Config[4]), 5, 1); }
private void textBox7_TextChanged(object sender, EventArgs e) { if (this.TieYards == 5) { if((TextBoxControlArrayImplementation(textBox7, textBox8, Convert.ToInt32(Config[4]), 6, 2))==true) ProcessEventuallyTieYards(); } else TextBoxControlArrayImplementation(textBox7, textBox8, Convert.ToInt32(Config[4]), 6, 1); }
private void textBox8_TextChanged(object sender, EventArgs e) { if (this.TieYards == 6) { if((TextBoxControlArrayImplementation(textBox8, textBox9, Convert.ToInt32(Config[4]), 7, 2))==true) ProcessEventuallyTieYards(); } else TextBoxControlArrayImplementation(textBox8, textBox9, Convert.ToInt32(Config[4]), 7, 1); }
private void textBox9_TextChanged(object sender, EventArgs e) { if (this.TieYards == 7) { if((TextBoxControlArrayImplementation(textBox9, textBox10, Convert.ToInt32(Config[4]), 8, 2))==true) ProcessEventuallyTieYards(); } else TextBoxControlArrayImplementation(textBox9, textBox10, Convert.ToInt32(Config[4]), 8, 1); }
private void textBox10_TextChanged(object sender, EventArgs e) { if (this.TieYards == 8) { if((TextBoxControlArrayImplementation(textBox10, textBox11, Convert.ToInt32(Config[4]), 9, 2))==true) ProcessEventuallyTieYards(); } else TextBoxControlArrayImplementation(textBox10, textBox11, Convert.ToInt32(Config[4]), 9, 1); }
private void textBox11_TextChanged(object sender, EventArgs e) { if (this.TieYards == 9) { if ((TextBoxControlArrayImplementation(textBox11, textBox12, Convert.ToInt32(Config[4]), 10, 2)) == true) ProcessEventuallyTieYards(); } else TextBoxControlArrayImplementation(textBox11, textBox12, Convert.ToInt32(Config[4]), 10, 1); }
private void textBox12_TextChanged(object sender, EventArgs e) { if (this.TieYards == 10) { if((TextBoxControlArrayImplementation(textBox12, textBox13, Convert.ToInt32(Config[4]), 11, 2))==true) ProcessEventuallyTieYards(); } else TextBoxControlArrayImplementation(textBox12, textBox13, Convert.ToInt32(Config[4]), 11, 1); }
private void textBox13_TextChanged(object sender, EventArgs e) { if (this.TieYards == 11) { if((TextBoxControlArrayImplementation(textBox13, textBox14, Convert.ToInt32(Config[4]), 12, 2))==true) ProcessEventuallyTieYards(); } else TextBoxControlArrayImplementation(textBox13, textBox14, Convert.ToInt32(Config[4]), 12, 1); }
private void textBox14_TextChanged(object sender, EventArgs e) { if (this.TieYards == 12) { if((TextBoxControlArrayImplementation(textBox14, textBox15, Convert.ToInt32(Config[4]), 13, 2))==true) ProcessEventuallyTieYards(); } else TextBoxControlArrayImplementation(textBox14, textBox15, Convert.ToInt32(Config[4]), 13, 1); }
private void textBox15_TextChanged(object sender, EventArgs e) { if (this.TieYards == 13) { if((TextBoxControlArrayImplementation(textBox15, textBox16, Convert.ToInt32(Config[4]), 14, 2))==true) ProcessEventuallyTieYards(); } else TextBoxControlArrayImplementation(textBox15, textBox16, Convert.ToInt32(Config[4]), 14, 1); }
private void textBox16_TextChanged(object sender, EventArgs e) { if (this.TieYards == 14) { if((TextBoxControlArrayImplementation(textBox16, textBox17, Convert.ToInt32(Config[4]), 15, 2))==true) ProcessEventuallyTieYards(); } else TextBoxControlArrayImplementation(textBox16, textBox17, Convert.ToInt32(Config[4]), 15, 1); }
private void textBox17_TextChanged(object sender, EventArgs e) { if (this.TieYards == 15) { if((TextBoxControlArrayImplementation(textBox17, textBox18, Convert.ToInt32(Config[4]), 16, 2))==true) ProcessEventuallyTieYards(); } else TextBoxControlArrayImplementation(textBox17, textBox18, Convert.ToInt32(Config[4]), 16, 1); }
private void textBox18_TextChanged(object sender, EventArgs e) { if (this.TieYards == 16) { if((TextBoxControlArrayImplementation(textBox18, textBox19, Convert.ToInt32(Config[4]), 17, 2))==true) ProcessEventuallyTieYards(); } else TextBoxControlArrayImplementation(textBox18, textBox19, Convert.ToInt32(Config[4]), 17, 1); }
private void textBox19_TextChanged(object sender, EventArgs e) { if (this.TieYards == 17) { if((TextBoxControlArrayImplementation(textBox19, textBox20, Convert.ToInt32(Config[4]), 18, 2))==true) ProcessEventuallyTieYards(); } else TextBoxControlArrayImplementation(textBox19, textBox20, Convert.ToInt32(Config[4]), 18, 1); }
private void textBox20_TextChanged(object sender, EventArgs e) { if (this.TieYards == 18) { if((TextBoxControlArrayImplementation(textBox20, textBox21, Convert.ToInt32(Config[4]), 19, 2))==true) ProcessEventuallyTieYards(); } else TextBoxControlArrayImplementation(textBox20, textBox21, Convert.ToInt32(Config[4]), 19, 1); }
private void textBox21_TextChanged(object sender, EventArgs e) { if (this.TieYards == 19) { if ((TextBoxControlArrayImplementation(textBox21, textBox22, Convert.ToInt32(Config[4]), 20, 2))==true) ProcessEventuallyTieYards(); } else TextBoxControlArrayImplementation(textBox21, textBox22, Convert.ToInt32(Config[4]), 20, 1); }
private void textBox22_TextChanged(object sender, EventArgs e) { if ((TextBoxControlArrayImplementation(textBox22, textBox22, Convert.ToInt32(Config[4]), 21, 2))==true) ProcessEventuallyTieYards(); }
private Boolean ReadOrderInfo(TextBox Set_OrderTotal,TextBox Set_CompleteTheOrderNumber,TextBox ProcessTextBox)//讀取訂單資訊 { Boolean Flag = false; QueryOrderInfo MyQueryOrderNumber = new QueryOrderInfo("GPUSERVER", "E_CompleteMachine", "sa", "adminsystem", "usp_Found_OrderNumber"); if (MyQueryOrderNumber.Found_OrderNumber(textBox1.Text.Trim()) == true) { Set_OrderTotal.Text = MyQueryOrderNumber.OrderTotal.ToString(); Set_CompleteTheOrderNumber.Text = MyQueryOrderNumber.CompleteTheOrderNumber.ToString(); Flag = true; } else { label18.Left = Convert.ToInt32(groupBox3.Width * 0.1); label18.Top = Convert.ToInt32(groupBox3.Height * 0.5); label18.ForeColor = Color.Red; label18.Text = "連線GPUSERVER資料庫失敗或提示訂單編碼錯誤!!"; ProcessTextBox.SelectAll();//選中文字框內容 ProcessTextBox.Focus();//設定文字框為焦點 Flag = false; } return Flag; }
private Boolean UpdateOrderInfo() //更新訂單資訊 { Boolean Flag=false; QueryOrderInfo MyUpdateOrderInfo = new QueryOrderInfo("GPUSERVER", "E_CompleteMachine", "sa", "adminsystem", "usp_Update_OrderNumber"); if (MyUpdateOrderInfo.UpdateOrderNumberInfo(textBox1.Text.Trim(), Convert.ToInt32(comboBox1.Text.Trim())) == true) Flag = true; else { label18.ForeColor = Color.Red;
int Len = ("訂單資訊更新失敗(原因如下):").Length; String KeyEmpty = String.Empty; for (int n = 0; n < Len; n++) KeyEmpty += " ";
label18.Top = Convert.ToInt32(groupBox3.Height * 0.25); label18.Left = Convert.ToInt32(groupBox3.Width * 0.01); label18.Text = "訂單資訊更新失敗(原因如下):\n" + KeyEmpty + "1.無法連線資料庫;2.輸入訂單數超出上限"; textBox2.SelectAll();//選中文字框內容 textBox2.Focus();//設定文字框為焦點 Flag = false; } return Flag; } private Boolean ProcessModule(String Query_SN,TextBox T1,TextBox T2,int Items,int State)//執行模組 { Boolean Flag = false; QueryTheWholeMachineBindingCode MyTx3Query = new QueryTheWholeMachineBindingCode("GPUSERVER", "E_CompleteMachine", "sa", "adminsystem", "usp_FundTieYards_Data", Query_SN); if (State == 1||State==4) { if (MyTx3Query.QueryRecord() == true) { //textBox3.ForeColor = Color.Green; this.SetConsole(T1, T2, Items,State); Flag = true; } else { String Temp = T1.Text.Trim(); label18.ForeColor = Color.Red;
//定義空白符長度 int Len = (Temp + "條碼資料庫讀取失敗(產生原因如下):").Length; String KeyEmpty=String.Empty; for(int n=0;n<Len;n++) KeyEmpty+=" ";
label18.Top = Convert.ToInt32(groupBox3.Height*0.25); label18.Left = Convert.ToInt32(groupBox3.Width*0.01); label18.Text =Temp + "條碼資料庫讀取失敗(產生原因如下):\n"+KeyEmpty+"1.漏整機測試;2.錄入條碼錯誤"; T1.SelectAll();//選中文字框內容 T1.Focus();//設定文字框為焦點 Flag = false; } } else if (State == 2) { if (MyTx3Query.QueryRecord() == true) { if ((UpdateOrderInfo()) == true)//更新訂單資訊 { this.SetConsole(T1, T2, Items, State); Flag = true; } } else { String Temp = T1.Text.Trim(); label18.ForeColor = Color.Red;
//定義空白符長度 int Len = (Temp + "條碼檢查失敗(原因如下):").Length; String KeyEmpty = String.Empty; for (int n = 0; n < Len; n++) KeyEmpty += " ";
label18.Top = Convert.ToInt32(groupBox3.Height * 0.25); label18.Left = Convert.ToInt32(groupBox3.Width * 0.01); label18.Text = Temp + "條碼檢查失敗(產生原因如下):\n" + KeyEmpty + "1.漏整機測試;2.錄入條碼錯誤";
T1.SelectAll();//選中文字框內容 T1.Focus();//設定文字框為焦點 Flag = false; } } return Flag; }
public Boolean Fund_InnerCarton_SN(String SN,TextBox T1)//通過資料庫查詢,判斷內箱SN是否存在綁碼情況 { label18.Text = ""; Boolean Flag = false; QueryTheWholeMachineBindingCode InnerCarton_SN_Query = new QueryTheWholeMachineBindingCode("GPUSERVER", "E_CompleteMachine", "sa", "adminsystem", "usp_Fund_InnerCartonbarcode", SN); if ((InnerCarton_SN_Query.QueryRecord()) == true) { Flag = true; } else {
String Temp = T1.Text.Trim();
label18.Left = Convert.ToInt32(groupBox3.Width * 0.1); label18.Top = Convert.ToInt32(groupBox3.Height * 0.5); label18.ForeColor = Color.Red; label18.Text = Temp + "條碼已與其它外箱捆綁,請將該板保留,切勿混裝!!"; T1.SelectAll();//選中文字框內容 T1.Focus();//設定文字框為焦點 Flag = false; } return Flag; }
public Boolean DetermineWhetherToRetype(String InputQuerySn,int Len,TextBox T1) { Boolean Flag = true; for (int n = 0; n <Len; n++) { if (InputKeyValues[n].Equals(InputQuerySn)) { label18.Left = Convert.ToInt32(groupBox3.Width * 0.2); label18.Top = Convert.ToInt32(groupBox3.Height * 0.5); label18.ForeColor = Color.Red; String ErrItem=String.Empty; if (n == 0) ErrItem = "訂單號欄條碼錄入"; else if (n == 1) ErrItem = "外箱條碼欄錄入"; else ErrItem = "SN_" + (n - 1).ToString() + "條碼欄錄入"; label18.Text = "錄入"+InputQuerySn + "條碼與"+ErrItem+"重複!!"; T1.SelectAll();//選中文字框內容 T1.Focus();//設定文字框為焦點 Flag = false; } } return Flag; }
public Boolean TextBoxControlArrayImplementation(TextBox T1, TextBox T2, int Len, int NO_1, int NO_2)//條碼錄入欄執行過程 { Boolean Flag = false; if (T1.Text.Trim().Length == Len)//滿足配置錄入長度開始判斷 { if (Fund_InnerCarton_SN(T1.Text.Trim(), T1) == true)//判斷條碼是否已捆綁 { if (DetermineWhetherToRetype(T1.Text.Trim(), NO_1, T1))//判斷條碼是否重複錄入 { if ((ProcessModule(T1.Text.Trim(), T1, T2, NO_1, NO_2)) == true) Flag = true; } } } else if (T1.Text.Trim().Length > Len) { label18.Left = Convert.ToInt32(groupBox3.Width * 0.3); label18.Top = Convert.ToInt32(groupBox3.Height * 0.5); label18.ForeColor = Color.Red; label18.Text = "輸入SN長度超出上限"; T1.SelectAll();//選中文字框內容 T1.Focus();//設定文字框為焦點 Flag = false; } return Flag; }
public Boolean ProcessEventuallyTieYards()//執行最終綁碼 { Boolean Flag = false; InsertDataBase MyData = new InsertDataBase(InputKeyValues[0], InputKeyValues[1], InputKeyValues[2], InputKeyValues[3], InputKeyValues[4], InputKeyValues[5], InputKeyValues[6], InputKeyValues[7], InputKeyValues[8], InputKeyValues[9], InputKeyValues[10], InputKeyValues[11], InputKeyValues[12], InputKeyValues[13], InputKeyValues[14], InputKeyValues[15], InputKeyValues[16], InputKeyValues[17], InputKeyValues[18], InputKeyValues[19], InputKeyValues[20], InputKeyValues[21], Config[5], Config[6], Config[7], Config[8], Config[9]); int Ret = MyData.Insert_TieYards(); label18.Left = Convert.ToInt32(groupBox3.Width * 0.3); label18.Top = Convert.ToInt32(groupBox3.Height * 0.5); if (Ret == 0) { int n = 0; foreach (TextBox ss in kk) { if (n > 1) { ss.Enabled = false; ss.Text = ""; ss.ForeColor = Color.Black; } n++; } textBox3.Enabled = true; textBox3.Focus(); InputKeyValues[21] = textBox22.Text.Trim(); label18.ForeColor = Color.Green; label18.Text = "外箱" + InputKeyValues[1] + "條碼捆綁成功!!"; Flag = true; } else { label18.Top = Convert.ToInt32(groupBox3.Height * 0.25); label18.Left = Convert.ToInt32(groupBox3.Width * 0.01); textBox22.SelectAll();//選中文字框內容 textBox22.Focus();//設定文字框為焦點 label18.ForeColor = Color.Red; if (Ret == 3) label18.Text = "連線 " + Config[5] + "伺服器 " + Config[6] + " 資料庫失敗!!"; else if (Ret == 2) label18.Text = InputKeyValues[2] + " 外箱資料捆綁失敗或條碼重複!!"; else if (Ret == 1) label18.Text = "連線 " + Config[5] + "伺服器 " + Config[6] + " 資料庫失敗或錄入條碼重複!!"; Flag = false; } return Flag; } private Boolean QueryCartonBarcode(TextBox T1) { Boolean Flag=false; for (int n1 = 0; n1 < Character.Length; n1++) { for (int n2 = 0; n2 < Character.Length; n2++) { for (int n3 = 0; n3 < Character.Length; n3++) { String Temp_SN = string.Empty; Temp_SN = "C8M" + DateTime.Now.ToString("yyyyMMdd");//外箱編號字首定義 Temp_SN+=Character[n1]+Character[n2]+Character[n3]; QueryTheWholeMachineBindingCode My_QueryCartonBarcode=new QueryTheWholeMachineBindingCode("GPUSERVER","E_CompleteMachine","sa","adminsystem","usp_Fund_CartonBarcode",Temp_SN); if ((My_QueryCartonBarcode.QueryRecord()) == true) { T1.Text = Temp_SN; InputKeyValues[1] = T1.Text.Trim(); Flag = true; return Flag; } } } } return Flag; } }
public class QueryOrderInfo : Form1 //查詢訂單資訊類 { private String SERVER; private String DATABASE; private String UID; private String PWD; private String StoredProcedure; private String OrderNumber; public int OrderTotal; public int CompleteTheOrderNumber; public int InputTileYardsNumber;
public QueryOrderInfo(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; this.OrderTotal = 1; this.CompleteTheOrderNumber = 1; this.InputTileYardsNumber = 1; this.OrderNumber = ""; }
public bool Found_OrderNumber(String OrderNumber)//查詢,並反回數值 { Boolean Flag = false; try { SqlConnection conn = new SqlConnection("server=" + this.SERVER + ";database=" + this.DATABASE + ";uid=" + this.UID + ";pwd=" + this.PWD); conn.Open(); if (conn.State != ConnectionState.Open) { ErrLog("Connection Data Base Err!!"); Flag = false; return Flag; } SqlCommand cmd = new SqlCommand(this.StoredProcedure, conn);//設定儲存過程啟動 cmd.CommandType = CommandType.StoredProcedure;//啟動資料庫儲存過程 cmd.Parameters.Add("@OrderNumber", OrderNumber); cmd.Parameters.Add("@OrderTotal", this.OrderTotal); cmd.Parameters["@OrderTotal"].Direction = ParameterDirection.Output;//設定輸出引數的方法 cmd.Parameters.Add("@CompleteTheOrderNumber",this.CompleteTheOrderNumber); cmd.Parameters["@CompleteTheOrderNumber"].Direction = ParameterDirection.Output;//設定輸出引數的方法 cmd.Parameters.Add("@rest", 1);//設定返回引數 cmd.Parameters["@rest"].Direction = ParameterDirection.Output;//啟動輸出返回 cmd.ExecuteNonQuery();
this.OrderTotal =(int)cmd.Parameters["@OrderTotal"].Value;//新增訂單總數 this.CompleteTheOrderNumber = (int)cmd.Parameters["@CompleteTheOrderNumber"].Value;//新增匯入訂單總數 if ((int)cmd.Parameters["@rest"].Value == 0) { conn.Close(); Flag = true; } else { conn.Close(); ErrLog("Connection" + this.SERVER + "Data Base Err!!"); Flag = false; return Flag; } } catch (Exception ex) { ErrLog(ex.ToString()); Flag = false; } return Flag; }
public Boolean UpdateOrderNumberInfo(String OrderNumber, int InputTileYardsNumber)//更新資料庫訂單資訊 { Boolean Flag = false; try { SqlConnection conn = new SqlConnection("server=" + this.SERVER + ";database=" + this.DATABASE + ";uid=" + this.UID + ";pwd=" + this.PWD); conn.Open(); if (conn.State != ConnectionState.Open) { ErrLog("Connection"+this.SERVER+"Data Base Err!!"); Flag = false; return Flag; } SqlCommand cmd = new SqlCommand(this.StoredProcedure, conn);//設定儲存過程啟動 cmd.CommandType = CommandType.StoredProcedure;//啟動資料庫儲存過程 cmd.Parameters.Add("@OrderNumber", OrderNumber); cmd.Parameters.Add("@InputTileYardsNumber", InputTileYardsNumber); 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(); ErrLog("Connection" + this.SERVER + "Data Base Err!!"); Flag = false; return Flag; } } catch (Exception ex) { ErrLog(ex.ToString()); Flag = false; } return Flag; }
public void ErrLog(String Text) { try { FileStream fs = new FileStream("Error.log", FileMode.Create, FileAccess.Write); StreamWriter sw = new StreamWriter(fs); sw.WriteLine(Text); sw.Close(); fs.Close(); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } } } public class QueryTheWholeMachineBindingCode : Form1//查詢綁碼結果或條碼使用情況 { private String SERVER; private String DATABASE; private String UID; private String PWD; private String StoredProcedure; private String SN;
public QueryTheWholeMachineBindingCode(String SERVER, String DATABASE, String UID, String PWD, String StoredProcedure, String SN) { this.SERVER = SERVER; this.DATABASE = DATABASE; this.UID = UID; this.PWD = PWD; this.StoredProcedure = StoredProcedure; this.SN = SN; }
public Boolean QueryRecord() { Boolean Flag = false; try { SqlConnection conn = new SqlConnection("server=" + this.SERVER + ";database=" + this.DATABASE + ";uid=" + this.UID + ";pwd=" + this.PWD); conn.Open(); if (conn.State != ConnectionState.Open) { ErrLog("Connection Data Base Err!!"); Flag = false; return Flag; } SqlCommand cmd = new SqlCommand(this.StoredProcedure, conn);//設定儲存過程啟動 cmd.CommandType = CommandType.StoredProcedure;//啟動資料庫儲存過程 cmd.Parameters.Add("@CompleteMachine_SN", this.SN); cmd.Parameters.Add("@rest", 1);//設定返回引數 cmd.Parameters["@rest"].Direction = ParameterDirection.Output;//啟動輸出返回 cmd.ExecuteScalar(); if ((int)cmd.Parameters["@rest"].Value == 0) { conn.Close(); Flag = true; } else { conn.Close(); ErrLog("Data Insert " + this.DATABASE + " DataBase Err!!"); Flag = false; return Flag; } } catch (Exception ex) { ErrLog(ex.ToString()); Flag = false; } return Flag; } public void ErrLog(String Text) { try { FileStream fs = new FileStream("Error.log", FileMode.Create, FileAccess.Write); StreamWriter sw = new StreamWriter(fs); sw.WriteLine(Text); sw.Close(); fs.Close(); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } } } public class InsertDataBase : Form1//插入綁碼記錄 { private String Order_Number; private String Carton_Barcode; private String Client_SN_1; private String Client_SN_2; private String Client_SN_3; private String Client_SN_4; private String Client_SN_5; private String Client_SN_6; private String Client_SN_7; private String Client_SN_8; private String Client_SN_9; private String Client_SN_10; private String Client_SN_11; private String Client_SN_12; private String Client_SN_13; private String Client_SN_14; private String Client_SN_15; private String Client_SN_16; private String Client_SN_17; private String Client_SN_18; private String Client_SN_19; private String Client_SN_20; private String SERVER; private String DATABASE; private String UID; private String PWD; private String StoredProcedure; public InsertDataBase(String Order_Number, String Carton_Barcode, String Client_SN_1, String Client_SN_2, String Client_SN_3, String Client_SN_4, String Client_SN_5, String Client_SN_6, String Client_SN_7, String Client_SN_8, String Client_SN_9, String Client_SN_10, String Client_SN_11, String Client_SN_12, String Client_SN_13, String Client_SN_14, String Client_SN_15, String Client_SN_16, String Client_SN_17, String Client_SN_18, String Client_SN_19, String Client_SN_20,String SERVER,String DATABASE,String UID, String PWD, String StoredProcedure) { this.Order_Number = Order_Number; this.Carton_Barcode = Carton_Barcode; this.Client_SN_1 = Client_SN_1; this.Client_SN_2 = Client_SN_2; this.Client_SN_3 = Client_SN_3; this.Client_SN_4 = Client_SN_4; this.Client_SN_5 = Client_SN_5; this.Client_SN_6 = Client_SN_6; this.Client_SN_7 = Client_SN_7; this.Client_SN_8 = Client_SN_8; this.Client_SN_9 = Client_SN_9; this.Client_SN_10 = Client_SN_10; this.Client_SN_11 = Client_SN_11; this.Client_SN_12 = Client_SN_12; this.Client_SN_13 = Client_SN_13; this.Client_SN_14 = Client_SN_14; this.Client_SN_15 = Client_SN_15; this.Client_SN_16 = Client_SN_16; this.Client_SN_17 = Client_SN_17; this.Client_SN_18 = Client_SN_18; this.Client_SN_19 = Client_SN_19; this.Client_SN_20 = Client_SN_20; this.SERVER = SERVER; this.DATABASE = DATABASE; this.UID = UID; this.PWD = PWD; this.StoredProcedure = StoredProcedure; }
public int Insert_TieYards()//插入資料入資料庫 { try { SqlConnection conn = new SqlConnection("server=" + this.SERVER + ";database=" + this.DATABASE + ";uid=" + this.UID + ";pwd=" + this.PWD); conn.Open(); if (conn.State!= ConnectionState.Open) { ErrLog("Connection Data Base Err!!"); return 1; } SqlCommand cmd = new SqlCommand(this.StoredProcedure,conn);//設定儲存過程啟動 cmd.CommandType = CommandType.StoredProcedure;//啟動資料庫儲存過程 cmd.Parameters.Add("@Order_Number",this.Order_Number); cmd.Parameters.Add("@Carton_Barcode",this.Carton_Barcode); cmd.Parameters.Add("@Client_SN_1",this.Client_SN_1); cmd.Parameters.Add("@Client_SN_2", this.Client_SN_2); cmd.Parameters.Add("@Client_SN_3", this.Client_SN_3); cmd.Parameters.Add("@Client_SN_4", this.Client_SN_4); cmd.Parameters.Add("@Client_SN_5", this.Client_SN_5); cmd.Parameters.Add("@Client_SN_6", this.Client_SN_6); cmd.Parameters.Add("@Client_SN_7", this.Client_SN_7); cmd.Parameters.Add("@Client_SN_8", this.Client_SN_8); cmd.Parameters.Add("@Client_SN_9", this.Client_SN_9); cmd.Parameters.Add("@Client_SN_10", this.Client_SN_10); cmd.Parameters.Add("@Client_SN_11", this.Client_SN_11); cmd.Parameters.Add("@Client_SN_12", this.Client_SN_12); cmd.Parameters.Add("@Client_SN_13", this.Client_SN_13); cmd.Parameters.Add("@Client_SN_14", this.Client_SN_14); cmd.Parameters.Add("@Client_SN_15", this.Client_SN_15); cmd.Parameters.Add("@Client_SN_16", this.Client_SN_16); cmd.Parameters.Add("@Client_SN_17", this.Client_SN_17); cmd.Parameters.Add("@Client_SN_18", this.Client_SN_18); cmd.Parameters.Add("@Client_SN_19", this.Client_SN_19); cmd.Parameters.Add("@Client_SN_20", this.Client_SN_20); cmd.Parameters.Add("@rest",1);//設定返回引數 cmd.Parameters["@rest"].Direction = ParameterDirection.Output;//啟動輸出返回 cmd.ExecuteScalar(); if ((int)cmd.Parameters["@rest"].Value == 0) { conn.Close(); } else { conn.Close(); ErrLog("Data Insert "+this.DATABASE+" DataBase Err!!"); return 2; } } catch (Exception ex) { ErrLog(ex.ToString()); return 3; } return 0; }
public void ErrLog(String Text) { try { FileStream fs = new FileStream("Error.log",FileMode.Create,FileAccess.Write); StreamWriter sw = new StreamWriter(fs); sw.WriteLine(Text); sw.Close(); fs.Close(); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } } } }
SQL 資料庫呼叫程式碼清單項:
SQL SOURCE CODE: