1. 程式人生 > >C# 30碼合一+BarTender列印+SQL工具

C# 30碼合一+BarTender列印+SQL工具

1.程式UI圖:

2.配置:

3.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 PanelTieYardsTools_V1._00 {     public partial class Form1 : Form     {         public String Directory_Path = String.Empty;         public List<String[]> ss=new List<String[]>();//儲存訂單資訊         public List<TextBox> AllSn = new List<TextBox>();//儲存SN序號         public int Print_Number = 0;//列印數量         public String Print_Preview = "NO";//是否顯示列印選擇         public String[] NowReadSn = {"NULL","NULL","NULL","NULL","NULL","NULL","NULL","NULL","NULL","NULL","NULL","NULL","NULL","NULL","NULL","NULL","NULL","NULL","NULL","NULL",                                     "NULL","NULL","NULL","NULL","NULL","NULL","NULL","NULL","NULL","NULL"};//儲存當前SN資訊         BarTender.Application btapp;//引用方法1         BarTender.Format btformat;//引用方法2         public Form1()         {             InitializeComponent();         }

        private void Form1_Load(object sender, EventArgs e)         {             this.StartPosition = FormStartPosition.CenterParent;//居中彈出窗體             InitFormInfo();             AllSn.Add(textBox5);             AllSn.Add(textBox6);             AllSn.Add(textBox7);             AllSn.Add(textBox8);             AllSn.Add(textBox9);             AllSn.Add(textBox10);             AllSn.Add(textBox11);             AllSn.Add(textBox12);             AllSn.Add(textBox13);             AllSn.Add(textBox14);             AllSn.Add(textBox15);             AllSn.Add(textBox16);             AllSn.Add(textBox17);             AllSn.Add(textBox18);             AllSn.Add(textBox19);             AllSn.Add(textBox20);             AllSn.Add(textBox21);             AllSn.Add(textBox22);             AllSn.Add(textBox23);             AllSn.Add(textBox24);             AllSn.Add(textBox25);             AllSn.Add(textBox26);             AllSn.Add(textBox27);             AllSn.Add(textBox28);             AllSn.Add(textBox29);             AllSn.Add(textBox30);             AllSn.Add(textBox31);             AllSn.Add(textBox32);             AllSn.Add(textBox33);             AllSn.Add(textBox34);         }

        public Boolean InitFormInfo()//初始化訂單資訊         {             Boolean Flag = false;             comboBox4.SelectedIndex = 28;             if (ReadDirectory_All_TemplateName("btw") == true)             {                 comboBox3.SelectedIndex = 0;                 if (OrderInfo_Into("OrderInfo.Config") == true)                 {                     Flag = true;                 }                 else                 {                     ShowFileInfo(textBox1, comboBox1, "讀取OrderInfo.Config訂單配置資訊出錯!!", 0.3f, 0.5f, 3);                     Flag = false;                 }             }             else             {                 ShowFileInfo(textBox1,comboBox3,"讀取當前目錄下*.btw模板資訊出錯!!",0.3f,0.5f,3);                 Flag = false;

            }             return Flag;         }         public bool OrderInfo_Into(String FileName)//讀取訂單資訊         {             Boolean Flag = false;             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[] OrderInfo = { "OrderNumber", "Box_Prefix", "Box_Up", "Box_Lower", "Print_Number", "Print_Preview"};                     if (Temp[0] != '#')                     {                         String[] Array = Temp.Split(new String[] { "," }, StringSplitOptions.RemoveEmptyEntries);                         OrderInfo[0] = Array[0].Trim();                         OrderInfo[1] = Array[1].Trim();                         OrderInfo[2] = Array[2].Trim();                         OrderInfo[3] = Array[3].Trim();                         OrderInfo[4] = Array[4].Trim();                         OrderInfo[5] = Array[5].Trim();                         ss.Add(OrderInfo);                         comboBox1.Items.Insert(comboBox1.Items.Count,OrderInfo[0].Trim());                     }                 }                 sr.Close();                 fs.Close();                 Flag = true;             }             catch (Exception ex)             {                 Flag = false;                 ErrLog(ex.ToString());             }             return Flag;         }

        public void ErrLog(String Text)//生成Log記錄         {             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 bool ReadDirectory_All_TemplateName(String str)//讀取當前目錄下所有模板檔名         {             Boolean Flag = false;             [email protected]"\";//獲取當前路徑             try             {                 DirectoryInfo dinfo = new DirectoryInfo(Directory_Path);//例項化DirectoryInfo物件                 FileSystemInfo[] fsinfos = dinfo.GetFileSystemInfos();//獲取指定目錄的所有子目錄及檔案內容                 List<String> FileName = new List<String>();                 int n = 0;                 foreach (FileSystemInfo fsinfo in fsinfos)                 {                     if (Path.GetExtension(fsinfo.Name) == str || Path.GetExtension(fsinfo.Name) == @".btw")                     {                         if (n > 0)                         {                             Boolean IsNewFileName = true;                             foreach (String ss in FileName)                             {                                 if (ss == fsinfo.Name)                                 {                                     IsNewFileName = false;                                     //Flag = false;                                     break;                                 }                             }                             if (IsNewFileName == true)                                 comboBox3.Items.Insert(comboBox3.Items.Count, fsinfo.Name.Trim());                                                      }                         else                         {                             comboBox3.Items.Insert(comboBox3.Items.Count, fsinfo.Name.Trim());                         }                         FileName.Add(fsinfo.Name);                         n++;                     }                 }                 Flag = true;             }             catch(Exception ex)             {                 ErrLog(ex.ToString());                 Flag = false;             }             return Flag;         }         public void ShowFileInfo(TextBox T1,ComboBox C1,String Str,float Le,float Tp,int Items)//顯示FAIL資訊         {             label39.Left = Convert.ToInt32(groupBox3.Width*Le);             label39.Top = Convert.ToInt32(groupBox3.Height*Tp);             if (Items == 1)             {                 label39.ForeColor = Color.Red;                 label39.Text = Str;                 T1.SelectAll();//選中文字框內容                 T1.Focus();//設定文字框為焦點             }             else if (Items == 2)             {                 label39.ForeColor = Color.Green;                 label39.Text = Str;                 T1.Focus();//設定文字框為焦點             }             else if (Items == 3)             {                 label39.ForeColor = Color.Red;                 label39.Text = Str;                 C1.SelectAll();//選中文字框內容                 C1.Focus();//設定文字框為焦點             }         }

        private void comboBox4_SelectedIndexChanged(object sender, EventArgs e)         {             //if (comboBox4.Text != "") button2.Enabled = true;         }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)         {             if (comboBox3.Text.Trim() != "" && comboBox4.Text.Trim() != "")             {                 for (int n = 0; n < ss.Count; n++)                 {                     if (ss[n][0].Trim() == comboBox1.Text.Trim())                     {                         textBox35.Text = ss[n][1].Trim();                         textBox3.Text = ss[n][2].Trim();                         textBox4.Text = ss[n][3].Trim();                         Print_Number = Convert.ToInt32(ss[n][4].Trim());//定義列印數量                         Print_Preview = ss[n][5].Trim();//列印預覽                         if (ReResetTheCarton_SN() == true)                         {                             comboBox1.Enabled = false;                             comboBox3.Enabled = false;                             comboBox4.Enabled = false;                             textBox5.Enabled = true;                             textBox5.Focus();//設定文字框為焦點                             button2.Enabled = true;                         }                         else                         {                             ShowFileInfo(textBox1, comboBox1, "連線資料庫出錯或當前訂單箱號已使用完!!", 0.3f, 0.5f, 3);                         }                     }                 }             }                      }

        public Boolean ReResetTheCarton_SN()//重置外箱資訊         {             Boolean Flag = false;             for (int x = Convert.ToInt32(textBox4.Text.Trim()); x <= Convert.ToInt32(textBox3.Text.Trim()); x++)             {                 String prefix = string.Empty;                 for (int i = 0; i < (textBox3.Text.Trim().Length) - (x.ToString().Length); i++)                     prefix += "0";                 prefix += x.ToString();                 prefix = textBox35.Text.Trim() + prefix;                 ReadBoxInfo My_OrderInfo = new ReadBoxInfo("NB_SERVER", "E_Panel", "sa", "adminsystem", "usp_Fund_BoxSn");                 if ((My_OrderInfo.GetBoxInfo(prefix)) == true)                 {                     textBox1.Text = prefix;                     Flag = true;                     return Flag;                 }             }             return Flag;         }

        private void button2_Click(object sender, EventArgs e)         {             ResetStart(1);//重置操作         }

        public void ResetStart(int Items)         {             foreach (TextBox ss in AllSn)             {                 ss.Enabled = false;                 ss.Text = "";                 //button2.Enabled = false;             }             if (Items == 1)             {                 comboBox1.Enabled = true;                 comboBox3.Enabled = true;                 comboBox4.Enabled = true;             }             else if (Items == 2)             {                 textBox5.Enabled = true;                 textBox5.Focus();//指定焦清             }         }

        private void textBox5_TextChanged(object sender, EventArgs e)         {             if (ReResetTheCarton_SN() == false)                 ShowFileInfo(textBox1, comboBox1, "連線資料庫出錯或當前訂單箱號已使用完!!", 0.3f, 0.5f, 3);         }

        private void textBox5_KeyPress(object sender, KeyPressEventArgs e)         {             if (e.KeyChar == (char)Keys.Enter)             {                 SnItemCall(textBox5,textBox6,label8,0,1);//讀取與比較SN資訊             }         }

        public Boolean SnItemCall(TextBox T1,TextBox T2,Label L1,int Array_Item,int Item)         {             Boolean Flag = false;             label39.Text = "";             if (Item == 1)             {                 GetSnInfo My_GetSnInfo = new GetSnInfo("NB_SERVER", "E_Panel", "sa", "adminsystem", "usp_GetColorInfo");                 if (My_GetSnInfo.GetColorSnInfo(comboBox1.Text.Trim(), T1.Text.Trim()) == true)                 {                     NowReadSn[Array_Item] = T1.Text.Trim();//儲存當前的SN資訊                     T2.Enabled = true;                     T1.Enabled = false;                     T2.Focus();//指定焦清                     Flag = true;                 }                 else                 {                     ShowFileInfo(T1, comboBox1, L1.Text.ToString() + "項錄入的SN條碼錯誤或對應訂單條碼已使用完!!", 0.3f, 0.5f, 1);                     T1.SelectAll();//選中文字框內容                     T1.Focus();//指定焦清                     Flag = false;                 }             }             else if (Item == 2)             {                 GetSnInfo My_GetSnInfo = new GetSnInfo("NB_SERVER", "E_Panel", "sa", "adminsystem", "usp_GetColorInfo");                 if (My_GetSnInfo.GetColorSnInfo(comboBox1.Text.Trim(), T1.Text.Trim()) == true)                 {                     NowReadSn[Array_Item] = T1.Text.Trim();//儲存當前的SN資訊                     Flag = true;                                      }                 else                 {                     ShowFileInfo(T1, comboBox1, L1.Text.ToString() + "項錄入的SN條碼錯誤或對應訂單條碼已使用完!!", 0.3f, 0.5f, 1);                     T1.SelectAll();//選中文字框內容                     T1.Focus();//指定焦清                     Flag = false;                 }             }             return Flag;         }         private void textBox6_KeyPress(object sender, KeyPressEventArgs e)         {             if (e.KeyChar == (char)Keys.Enter)             {                 if (Convert.ToInt32(comboBox4.Text.Trim()) == 2)                 {                     if (ItemsStart(textBox6, textBox7, label9, 1, 2) == true)//執行與判斷SN資訊                         Upload_PrintScan_SN(textBox6, textBox5, label39, 1);

                }                 else                     ItemsStart(textBox6, textBox7,label9,1,1);//執行與判斷SN資訊             }         }

        private void textBox7_KeyPress(object sender, KeyPressEventArgs e)         {             if (e.KeyChar == (char)Keys.Enter)             {                 if (Convert.ToInt32(comboBox4.Text.Trim()) == 3)                 {                     if(ItemsStart(textBox7, textBox8, label10, 2, 2)==true)                         Upload_PrintScan_SN(textBox7, textBox5, label39, 2);                 }                 else                     ItemsStart(textBox7, textBox8, label10, 2, 1);//執行與判斷SN資訊             }         }         private void textBox8_KeyPress_1(object sender, KeyPressEventArgs e)         {             if (e.KeyChar == (char)Keys.Enter)             {                 if (Convert.ToInt32(comboBox4.Text.Trim()) == 4)                 {                     if(ItemsStart(textBox8, textBox9, label11, 3, 2)==true)                         Upload_PrintScan_SN(textBox8, textBox5, label39, 3);                 }                 else                     ItemsStart(textBox8, textBox9, label11, 3, 1);//執行與判斷SN資訊             }         }

        private void textBox9_KeyPress(object sender, KeyPressEventArgs e)         {             if (e.KeyChar == (char)Keys.Enter)             {                 if (Convert.ToInt32(comboBox4.Text.Trim()) == 5)                 {                     if(ItemsStart(textBox9, textBox10, label12, 4, 2)==true)                         Upload_PrintScan_SN(textBox9, textBox5, label39, 4);                 }                 else                 ItemsStart(textBox9, textBox10, label12, 4, 1);//執行與判斷SN資訊             }         }

        private void textBox10_KeyPress(object sender, KeyPressEventArgs e)         {             if (e.KeyChar == (char)Keys.Enter)             {                 if (Convert.ToInt32(comboBox4.Text.Trim()) == 6)                 {                      if(ItemsStart(textBox10, textBox11, label13, 5, 2)==true)                         Upload_PrintScan_SN(textBox10, textBox5, label39, 5);                 }                 else                     ItemsStart(textBox10, textBox11, label13, 5, 1);//執行與判斷SN資訊             }         }

        private void textBox11_KeyPress(object sender, KeyPressEventArgs e)         {             if (e.KeyChar == (char)Keys.Enter)             {                 if (Convert.ToInt32(comboBox4.Text.Trim()) == 7)                 {                      if(ItemsStart(textBox11, textBox12, label14, 6, 2)==true)                         Upload_PrintScan_SN(textBox11, textBox5, label39, 6);                 }                 else                     ItemsStart(textBox11, textBox12, label14, 6, 1);//執行與判斷SN資訊             }         }

        private void textBox12_KeyPress(object sender, KeyPressEventArgs e)         {             if (e.KeyChar == (char)Keys.Enter)             {                 if (Convert.ToInt32(comboBox4.Text.Trim()) == 8)                 {                     if(ItemsStart(textBox12, textBox13, label15, 7, 2)==true)                         Upload_PrintScan_SN(textBox12, textBox5, label39, 7);                 }                 else                     ItemsStart(textBox12, textBox13, label15, 7, 1);//執行與判斷SN資訊             }         }

        private void textBox13_KeyPress(object sender, KeyPressEventArgs e)         {             if (e.KeyChar == (char)Keys.Enter)             {                 if (Convert.ToInt32(comboBox4.Text.Trim()) == 9)                 {                      if(ItemsStart(textBox13, textBox14, label16, 8, 2)==true)                         Upload_PrintScan_SN(textBox13, textBox5, label39, 8);                 }                 else                     ItemsStart(textBox13, textBox14, label16, 8, 1);//執行與判斷SN資訊             }         }

        private void textBox14_KeyPress(object sender, KeyPressEventArgs e)         {             if (e.KeyChar == (char)Keys.Enter)             {                 if (Convert.ToInt32(comboBox4.Text.Trim()) == 10)                 {                     if(ItemsStart(textBox14, textBox15, label17, 9, 2)==true)                         Upload_PrintScan_SN(textBox14, textBox5, label39, 9);                 }                 else                     ItemsStart(textBox14, textBox15, label17, 9, 1);//執行與判斷SN資訊             }         }

        private void textBox15_KeyPress(object sender, KeyPressEventArgs e)         {             if (e.KeyChar == (char)Keys.Enter)             {                 if (Convert.ToInt32(comboBox4.Text.Trim()) == 11)                 {                      if(ItemsStart(textBox15, textBox16, label18, 10, 2)==true)                         Upload_PrintScan_SN(textBox15, textBox5, label39, 10);                 }                 else                     ItemsStart(textBox15, textBox16, label18, 10, 1);//執行與判斷SN資訊             }         }

        private void textBox16_KeyPress(object sender, KeyPressEventArgs e)         {             if (e.KeyChar == (char)Keys.Enter)             {                 if (Convert.ToInt32(comboBox4.Text.Trim()) == 12)                 {                      if(ItemsStart(textBox16, textBox17, label19, 11, 2)==true)                         Upload_PrintScan_SN(textBox16, textBox5, label39, 11);                 }                 else                     ItemsStart(textBox16, textBox17, label19, 11, 1);//執行與判斷SN資訊             }         }

        private void textBox17_KeyPress(object sender, KeyPressEventArgs e)         {             if (e.KeyChar == (char)Keys.Enter)             {                 if (Convert.ToInt32(comboBox4.Text.Trim()) == 13)                 {                     if(ItemsStart(textBox17, textBox18, label20, 12, 2)==true)                         Upload_PrintScan_SN(textBox17, textBox5, label39, 12);                 }                 else                     ItemsStart(textBox17, textBox18, label20, 12, 1);//執行與判斷SN資訊             }         }

        private void textBox18_KeyPress(object sender, KeyPressEventArgs e)         {             if (e.KeyChar == (char)Keys.Enter)             {                 if (Convert.ToInt32(comboBox4.Text.Trim()) == 14)                 {                     if(ItemsStart(textBox18, textBox19, label21, 13, 2)==true)                         Upload_PrintScan_SN(textBox18, textBox5, label39, 13);                 }                 else                     ItemsStart(textBox18, textBox19, label21, 13, 1);//執行與判斷SN資訊             }         }

        private void textBox19_KeyPress(object sender, KeyPressEventArgs e)         {             if (e.KeyChar == (char)Keys.Enter)             {                 if (Convert.ToInt32(comboBox4.Text.Trim()) == 15)                 {                      if(ItemsStart(textBox19, textBox20, label22, 14, 2)==true)                         Upload_PrintScan_SN(textBox19, textBox5, label39, 14);                 }                 else                     ItemsStart(textBox19, textBox20, label22, 14, 1);//執行與判斷SN資訊             }         }

        private void textBox20_KeyPress(object sender, KeyPressEventArgs e)         {             if (e.KeyChar == (char)Keys.Enter)             {                 if (Convert.ToInt32(comboBox4.Text.Trim()) == 16)                 {                      if(ItemsStart(textBox20, textBox21, label23, 15, 2)==true)                         Upload_PrintScan_SN(textBox20, textBox5, label39, 15);                 }                 else                     ItemsStart(textBox20, textBox21, label23, 15, 1);//執行與判斷SN資訊             }         }

        private void textBox21_KeyPress(object sender, KeyPressEventArgs e)         {             if (e.KeyChar == (char)Keys.Enter)             {                 if (Convert.ToInt32(comboBox4.Text.Trim()) == 17)                 {                      if(ItemsStart(textBox21, textBox22, label24, 16, 2)==true)                         Upload_PrintScan_SN(textBox21, textBox5, label39, 16);                 }                 else                     ItemsStart(textBox21, textBox22, label24, 16, 1);//執行與判斷SN資訊             }         }

        private void textBox22_KeyPress(object sender, KeyPressEventArgs e)         {             if (e.KeyChar == (char)Keys.Enter)             {                 if (Convert.ToInt32(comboBox4.Text.Trim()) == 18)                 {                      if(ItemsStart(textBox22, textBox23, label25, 17, 2)==true)                         Upload_PrintScan_SN(textBox22, textBox5, label39, 17);                 }                 else                     ItemsStart(textBox22, textBox23, label25, 17, 1);//執行與判斷SN資訊             }         }

        private void textBox23_KeyPress(object sender, KeyPressEventArgs e)         {             if (e.KeyChar == (char)Keys.Enter)             {                 if (Convert.ToInt32(comboBox4.Text.Trim()) == 19)                 {                      if(ItemsStart(textBox23, textBox24, label26, 18, 2)==true)                         Upload_PrintScan_SN(textBox23, textBox5, label39, 18);                 }                 else                     ItemsStart(textBox23, textBox24, label26, 18, 1);//執行與判斷SN資訊             }         }

        private void textBox24_KeyPress(object sender, KeyPressEventArgs e)         {             if (e.KeyChar == (char)Keys.Enter)             {                 if (Convert.ToInt32(comboBox4.Text.Trim()) == 20)                 {                     if(ItemsStart(textBox24, textBox25, label27, 19, 2)==true)                         Upload_PrintScan_SN(textBox24, textBox5, label39, 19);                 }                 else                     ItemsStart(textBox24, textBox25, label27, 19, 1);//執行與判斷SN資訊             }         }

        private void textBox25_KeyPress(object sender, KeyPressEventArgs e)         {             if (e.KeyChar == (char)Keys.Enter)             {                 if (Convert.ToInt32(comboBox4.Text.Trim()) == 21)                 {                     if(ItemsStart(textBox25, textBox26, label28, 20, 2)==true)                         Upload_PrintScan_SN(textBox25, textBox5, label39, 20);                 }                 else                     ItemsStart(textBox25, textBox26, label28, 20, 1);//執行與判斷SN資訊             }         }

        private void textBox26_KeyPress(object sender, KeyPressEventArgs e)         {             if (e.KeyChar == (char)Keys.Enter)             {                 if (Convert.ToInt32(comboBox4.Text.Trim()) == 22)                 {                      if(ItemsStart(textBox26, textBox27, label29, 21, 2)==true)                         Upload_PrintScan_SN(textBox26, textBox5, label39, 21);                 }                 else                     ItemsStart(textBox26, textBox27, label29, 21, 1);//執行與判斷SN資訊             }         }

        private void textBox27_KeyPress(object sender, KeyPressEventArgs e)         {             if (e.KeyChar == (char)Keys.Enter)             {                 if (Convert.ToInt32(comboBox4.Text.Trim()) == 23)                 {                      if(ItemsStart(textBox27, textBox28, label30, 22, 2)==true)                         Upload_PrintScan_SN(textBox27, textBox5, label39, 22);                 }                 else                     ItemsStart(textBox27, textBox28, label30, 22, 1);//執行與判斷SN資訊             }         }

        private void textBox28_KeyPress(object sender, KeyPressEventArgs e)         {             if (e.KeyChar == (char)Keys.Enter)             {                 if (Convert.ToInt32(comboBox4.Text.Trim()) == 24)                 {                      if(ItemsStart(textBox28, textBox29, label31, 23, 2)==true)                         Upload_PrintScan_SN(textBox28, textBox5, label39, 23);                 }                 else                     ItemsStart(textBox28, textBox29, label31, 23, 1);//執行與判斷SN資訊             }         }

        private void textBox29_KeyPress(object sender, KeyPressEventArgs e)         {             if (e.KeyChar == (char)Keys.Enter)             {                 if (Convert.ToInt32(comboBox4.Text.Trim()) == 25)                 {                      if(ItemsStart(textBox29, textBox30, label32, 24, 2)==true)                         Upload_PrintScan_SN(textBox29, textBox5, label39, 24);                 }                 else                     ItemsStart(textBox29, textBox30, label32, 24, 1);//執行與判斷SN資訊             }         }

        private void textBox30_KeyPress(object sender, KeyPressEventArgs e)         {             if (e.KeyChar == (char)Keys.Enter)             {                 if (Convert.ToInt32(comboBox4.Text.Trim()) == 26)                 {                      if(ItemsStart(textBox30, textBox31, label33, 25, 2)==true)                         Upload_PrintScan_SN(textBox30, textBox5, label39, 25);                 }                 else                     ItemsStart(textBox30, textBox31, label33, 25, 1);//執行與判斷SN資訊             }         }

        private void textBox31_KeyPress(object sender, KeyPressEventArgs e)         {             if (e.KeyChar == (char)Keys.Enter)             {                 if (Convert.ToInt32(comboBox4.Text.Trim()) == 27)                 {                      if(ItemsStart(textBox31, textBox32, label34, 26, 2)==true)                         Upload_PrintScan_SN(textBox31, textBox5, label39, 26);                 }                 else                     ItemsStart(textBox31, textBox32, label34, 26, 1);//執行與判斷SN資訊             }         }

        private void textBox32_KeyPress(object sender, KeyPressEventArgs e)         {             if (e.KeyChar == (char)Keys.Enter)             {                 if (Convert.ToInt32(comboBox4.Text.Trim()) == 28)                 {                      if(ItemsStart(textBox32, textBox33, label35, 27, 2)==true)                         Upload_PrintScan_SN(textBox32, textBox5, label39, 27);                 }                 else                     ItemsStart(textBox32, textBox33, label35, 27, 1);//執行與判斷SN資訊             }         }

        private void textBox33_KeyPress(object sender, KeyPressEventArgs e)         {             if (e.KeyChar == (char)Keys.Enter)             {                 if (Convert.ToInt32(comboBox4.Text.Trim()) == 29)                 {                      if(ItemsStart(textBox33, textBox34, label36, 28, 2)==true)                         Upload_PrintScan_SN(textBox33, textBox5, label39, 28);                 }                 else                     ItemsStart(textBox33, textBox34, label36, 28, 1);//執行與判斷SN資訊             }         }

        private void textBox34_KeyPress(object sender, KeyPressEventArgs e)         {             if (e.KeyChar == (char)Keys.Enter)             {                 if(ItemsStart(textBox34, textBox34, label37, 29, 2)==true)//執行與判斷SN資訊                     Upload_PrintScan_SN(textBox34,textBox5,label39,29);//資料插入及列印             }         }

        public Boolean Upload_PrintScan_SN(TextBox T1,TextBox T2,Label L1,int Len)         {             Boolean Flag = false;             if (Print_BarTender(Len) == true)             {                 InsertBarTender My_InsertScanSn = new InsertBarTender("NB_SERVER", "E_Panel", "sa", "adminsystem", "usp_Insert_TieYards_30");                 if (My_InsertScanSn.InsertBarTenderData(NowReadSn, comboBox1.Text.Trim(), textBox1.Text.Trim()))                 {                     if (TieSn(29) == true)//更新SN記錄                     {                         for (int n = 0; n < NowReadSn.Length; n++)                             NowReadSn[n] = "NULL";                         ResetStart(2);//重置TextBox控制元件                         L1.ForeColor = Color.Green;//設定字型顏色                         L1.Text = "資料插入及條碼列印完成!!";                         Flag = true;                     }                     else                     {                         ShowFileInfo(T1, comboBox1, L1.Text.ToString() + "無法將資料插入資料庫,網路異常或插入資料錯誤!!", 0.3f, 0.5f, 1);                         T1.SelectAll();//選中文字框內容                         T1.Focus();//指定焦清                         this.ErrLog("Filling SN Data To Database Error!!");                         Flag = false;                     }                                      }             }             else             {                 ShowFileInfo(T1, comboBox1, "列印條碼出錯!!", 0.3f, 0.5f, 1);                 T1.SelectAll();//選中文字框內容                 T1.Focus();//指定焦清                 this.ErrLog("條碼打印出錯!!");                 Flag = false;             }

            /*if (TieSn(29) == true)//更新SN記錄             {                 if (Print_BarTender(Len) == true)                 {                     InsertBarTender My_InsertScanSn = new InsertBarTender("NB_SERVER", "E_Panel", "sa", "adminsystem", "usp_Insert_TieYards_30");                     if (My_InsertScanSn.InsertBarTenderData(NowReadSn, comboBox1.Text.Trim(), textBox1.Text.Trim()))                     {                         for (int n = 0; n < NowReadSn.Length; n++)                             NowReadSn[n] = "NULL";                         ResetStart(2);//重置TextBox控制元件                         L1.ForeColor = Color.Green;//設定字型顏色                         L1.Text = "資料插入及條碼列印完成!!";                         Flag = true;                     }                 }                 else                 {                     ShowFileInfo(T1, comboBox1,"列印條碼出錯!!", 0.3f, 0.5f, 1);                     T1.SelectAll();//選中文字框內容                     T1.Focus();//指定焦清                     this.ErrLog("條碼打印出錯!!");                     Flag = false;                 }             }                  else             {                 ShowFileInfo(T1, comboBox1, L1.Text.ToString() + "無法將資料插入資料庫,網路異常或插入資料錯誤!!", 0.3f, 0.5f, 1);                 T1.SelectAll();//選中文字框內容                 T1.Focus();//指定焦清                 this.ErrLog("Filling SN Data To Database Error!!");                 Flag = false;             }*/             return Flag;         }

        public Boolean TieSn(int Len)         {             Boolean Flag=true;             for(int n=0;n<Len;n++)             {                 UpdateColorSnInfo My_UpdateInfo = new UpdateColorSnInfo("NB_SERVER", "E_Panel", "sa", "adminsystem", "usp_UpdateColorSN_Info");                 if (My_UpdateInfo.UpdateSnInfo(comboBox1.Text.Trim(), NowReadSn[n])==false)                 {                     label39.Left = Convert.ToInt32(groupBox3.Width * 0.3f);                     label39.Top = Convert.ToInt32(groupBox3.Height * 0.5f);                     label39.ForeColor = Color.Red;                     label39.Text = "SN:"+comboBox1.Text.Trim()+"更新資料出錯!!";                     Flag = false;                     return Flag;                 }             }             return Flag;         }         public Boolean JudgmentEntrySN(String []EntrySN,String Str,int len)//判斷SN錄入是否成功         {             Boolean Flag = true;             for (int n = 0; n < len; n++)             {                 if (EntrySN[n].Trim() == Str)                 {                     Flag = false;                     return Flag;                 }             }             return Flag;         }

        public Boolean ItemsStart(TextBox T1, TextBox T2, Label L1, int Index_1, int Items)         {             Boolean Flag = false;             if (JudgmentEntrySN(NowReadSn, T1.Text.Trim(), Index_1) == true)//判斷錄入的SN是否與各控制元件重複             {                 if (SnItemCall(T1, T2, L1, Index_1, Items) == true)//讀取與比較SN資訊                     Flag = true;                 else                      Flag = false;             }             else             {                 ShowFileInfo(T1, comboBox1, L1.Text + "項錄入的SN重複", 0.3f, 0.5f, 1);//顯示FAIL資訊                 Flag = false;             }             return Flag;         }

        public Boolean Print_BarTender(int Len)         {             Boolean Flag = false;             try             {                 String[] BarTempStr = { "crate","sn1","sn2","sn3","sn4","sn5","sn6","sn7","sn8",                                       "sn9","sn10","sn11","sn12","sn13","sn14","sn15","sn16","sn17",                                       "sn18","sn19","sn20","sn21","sn22","sn23","sn24","sn25","sn26",                                       "sn27","sn28","sn29","sn30"};                 btapp = new BarTender.Application();                 String BarTender_Filepath = System.Environment.CurrentDirectory + @"\" + comboBox3.Text.Trim();//獲取模板檔案路徑                 btformat = btapp.Formats.Open(BarTender_Filepath,false,"");//設定模板檔案                 btformat.PrintSetup.NumberSerializedLabels = Print_Number;//設定列印份數                 btformat.SetNamedSubStringValue(BarTempStr[0].Trim(), textBox1.Text.Trim());                 for (int n = 1; n <= (Len+1); n++)                 {                     btformat.SetNamedSubStringValue(BarTempStr[n].Trim(), NowReadSn[n-1]);                 }                 if (Print_Preview == "YES") btformat.PrintOut(true, true);//第二個引數設定是否跳出列印屬性                 else btformat.PrintOut(true,false);//第二個引數設定是否跳出列印屬性                 Flag = true;                              }             catch (Exception ex)             {                 this.ErrLog(ex.ToString());                 Flag = true;             }             btapp.Quit(BarTender.BtSaveOptions.btSaveChanges);//退出時同退退出BarTender程序             return Flag;         }     }

    public class Base_DataSqlServer : Form1//基類資料庫定義     {         public  String SERVER;         public  String DATABASE;         public  String UID;         public  String PWD;         public  String StoredProcedure;

    }

    public class UpdateColorSnInfo : Base_DataSqlServer//更新SN資訊     {         public UpdateColorSnInfo(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 Boolean UpdateSnInfo(String OrderNumber, String SN)         {             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)                 {                     this.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("@SN",SN);                 cmd.Parameters.Add("@rs", 1);//設定返回引數                 cmd.Parameters["@rs"].Direction = ParameterDirection.Output;//啟動輸出返回                 cmd.ExecuteScalar();                 if ((int)cmd.Parameters["@rs"].Value == 0)                 {                     conn.Close();                     Flag = true;                 }                 else                 {                     conn.Close();                     this.ErrLog("Data Insert " + this.DATABASE + " DataBase Err");                     Flag = false;                     return Flag;                 }             }             catch (Exception ex)             {                 Flag = false;                 this.ErrLog(ex.ToString());             }             return Flag;         }     }

    public class InsertBarTender : Base_DataSqlServer//插入掃描資料     {         public InsertBarTender(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 Boolean InsertBarTenderData(String[] Str, String OrderNumber, String BoxNumber)         {             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)                 {                     this.ErrLog("Connection Data Base Err!!");                     Flag = false;                     return Flag;                 }                 String []Args_SN={"@SN_1","@SN_2","@SN_3","@SN_4","@SN_5","@SN_6","@SN_7","@SN_8","@SN_9","@SN_10","@SN_11","@SN_12","@SN_13","@SN_14",                                  "@SN_15","@SN_16","@SN_17","@SN_18","@SN_19","@SN_20","@SN_21","@SN_22","@SN_23","@SN_24","@SN_25","@SN_26","@SN_27","@SN_28","@SN_29","@SN_30"};                 SqlCommand cmd = new SqlCommand(this.StoredProcedure, conn);//設定儲存過程啟動                 cmd.CommandType = CommandType.StoredProcedure;//啟動資料庫儲存過程                 cmd.Parameters.Add("@OrderNumber", OrderNumber);                 cmd.Parameters.Add("@BoxNumber",BoxNumber);                 for (int n = 0; n < Args_SN.Length;n++)                     cmd.Parameters.Add(Args_SN[n], Str[n].Trim());                 cmd.Parameters.Add("@DATE_Time",DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));                 cmd.Parameters.Add("@rs", 1);//設定返回引數                 cmd.Parameters["@rs"].Direction = ParameterDirection.Output;//啟動輸出返回                 cmd.ExecuteScalar();                 if ((int)cmd.Parameters["@rs"].Value == 0)                 {                     conn.Close();                     Flag = true;                 }                 else                 {                     conn.Close();                     this.ErrLog("Data Insert " + this.DATABASE + " DataBase Err");                     Flag = false;                     return Flag;                 }                              }             catch (Exception ex)             {                 Flag = false;                 this.ErrLog(ex.ToString());             }             return Flag;         }

    }     public class GetSnInfo : Base_DataSqlServer//獲取SN資訊     {         public GetSnInfo(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 Boolean GetColorSnInfo(String OrderNumber, String SN)         {             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)                 {                     this.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("@SN", SN);                 cmd.Parameters.Add("@rs", 1);//設定返回引數                 cmd.Parameters["@rs"].Direction = ParameterDirection.Output;//啟動輸出返回                 cmd.ExecuteScalar();                 if ((int)cmd.Parameters["@rs"].Value == 0)                 {                     conn.Close();                     Flag = true;                 }                 else                 {                     conn.Close();                     this.ErrLog("Data Insert " + this.DATABASE + " DataBase Err");                     Flag = false;                     return Flag;                 }             }             catch (Exception ex)             {                 Flag = false;                 this.ErrLog(ex.ToString());             }             return Flag;         }     }     public class ReadBoxInfo : Base_DataSqlServer//獲取訂單資訊     {         public ReadBoxInfo(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 Boolean GetBoxInfo(String BoxNumber)//獲取盒子資訊         {             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)                 {                     this.ErrLog("Connection Data Base Err!!");                     Flag = false;                     return Flag;                 }                 SqlCommand cmd = new SqlCommand(this.StoredProcedure,conn);//設定儲存過程啟動                 cmd.CommandType = CommandType.StoredProcedure;//啟動資料庫儲存過程                 cmd.Parameters.Add("@BoxNumber",BoxNumber);                 cmd.Parameters.Add("@rs",1);//設定返回引數                 cmd.Parameters["@rs"].Direction = ParameterDirection.Output;//啟動輸出返回                 cmd.ExecuteScalar();                 if ((int)cmd.Parameters["@rs"].Value == 0)                 {                     conn.Close();                     Flag = true;                 }                 else                 {                     conn.Close();                     this.ErrLog("Data Insert "+this.DATABASE+" DataBase Err");                     Flag = false;                     return Flag;                 }             }             catch (Exception ex)             {                 Flag = false;                 this.ErrLog(ex.ToString());             }             return Flag;         }     } }4.Sql Source code:

USE E_Panel GO IF EXISTS(SELECT * FROM SYSOBJECTS WHERE NAME='TieYards_30') DROP TABLE TieYards_30 GO

CREATE TABLE TieYards_30 (     NO int IDENTITY(1,1) NOT NULL,     OrderNumber VARCHAR(50) NOT NULL,     BoxNumber VARCHAR(50) NOT NULL,     SN_1 VARCHAR(50) NOT NULL,     SN_2 VARCHAR(50) NOT NULL,     SN_3 VARCHAR(50) NOT NULL,     SN_4 VARCHAR(50) NOT NULL,     SN_5 VARCHAR(50) NOT NULL,     SN_6 VARCHAR(50) NOT NULL,     SN_7 VARCHAR(50) NOT NULL,     SN_8 VARCHAR(50) NOT NULL,     SN_9 VARCHAR(50) NOT NULL,     SN_10 VARCHAR(50) NOT NULL,     SN_11 VARCHAR(50) NOT NULL,     SN_12 VARCHAR(50) NOT NULL,     SN_13 VARCHAR(50) NOT NULL,     SN_14 VARCHAR(50) NOT NULL,     SN_15 VARCHAR(50) NOT NULL,     SN_16 VARCHAR(50) NOT NULL,     SN_17 VARCHAR(50) NOT NULL,     SN_18 VARCHAR(50) NOT NULL,     SN_19 VARCHAR(50) NOT NULL,     SN_20 VARCHAR(50) NOT NULL,     SN_21 VARCHAR(50) NOT NULL,     SN_22 VARCHAR(50) NOT NULL,     SN_23 VARCHAR(50) NOT NULL,     SN_24 VARCHAR(50) NOT NULL,     SN_25 VARCHAR(50) NOT NULL,     SN_26 VARCHAR(50) NOT NULL,     SN_27 VARCHAR(50) NOT NULL,     SN_28 VARCHAR(50) NOT NULL,     SN_29 VARCHAR(50) NOT NULL,     SN_30 VARCHAR(50) NOT NULL,     DATE_Time VARCHAR(20) NOT NULL ) GO

USE E_Panel GO IF EXISTS (SELECT * FROM SYS.OBJECTS WHERE NAME='usp_GetColorInfo') DROP PROC usp_GetColorInfo GO

CREATE PROC usp_GetColorInfo (     @OrderNumber VARCHAR(50),     @SN VARCHAR(50),     @rs int output ) AS

    SELECT @rs=count(*) FROM Color_SN_Info WHERE @OrderNumber=OrderNumber AND @SN=SN     IF @rs>0     BEGIN         SELECT @rs=count(*) FROM Color_SN_Info WHERE @SN=SN AND State=0         IF @rs>0         BEGIN             SET @rs=0             RETURN @rs         END     END     ELSE     BEGIN         SET @rs=1     END     RETURN @rs GO

USE E_Panel GO IF EXISTS(SELECT * FROM SYS.OBJECTS WHERE NAME='usp_Insert_ColorSN') DROP PROC usp_Insert_ColorSN GO

CREATE PROC usp_Insert_ColorSN (     @OrderNumber VARCHAR(50),     @SN VARCHAR(50),     @State int,     @rs int output ) AS     SELECT @rs=count(*) FROM Color_SN_Info WHERE @SN=SN     IF @rs>0     BEGIN         SET @rs=0         RETURN @rs     END     INSERT INTO Color_SN_Info values(@OrderNumber,@SN,@State)     IF @@ERROR>0     BEGIN         SET @rs=1     END     ELSE     BEGIN         SET @rs=0     END     return @rs GO  

USE E_Panel GO IF EXISTS (SELECT * FROM SYS.OBJECTS WHERE NAME='usp_Insert_TieYards_30') DROP PROC usp_Insert_TieYards_30 GO

CREATE PROC usp_Insert_TieYards_30 (     @OrderNumber VARCHAR(50),     @BoxNumber VARCHAR(50),     @SN_1 VARCHAR(50),     @SN_2 VARCHAR(50),     @SN_3 VARCHAR(50),     @SN_4 VARCHAR(50),     @SN_5 VARCHAR(50),     @SN_6 VARCHAR(50),     @SN_7 VARCHAR(50),     @SN_8 VARCHAR(50),     @SN_9 VARCHAR(50),     @SN_10 VARCHAR(50),     @SN_11 VARCHAR(50),     @SN_12 VARCHAR(50),     @SN_13 VARCHAR(50),     @SN_14 VARCHAR(50),     @SN_15 VARCHAR(50),     @SN_16 VARCHAR(50),     @SN_17 VARCHAR(50),     @SN_18 VARCHAR(50),     @SN_19 VARCHAR(50),     @SN_20 VARCHAR(50),     @SN_21 VARCHAR(50),     @SN_22 VARCHAR(50),     @SN_23 VARCHAR(50),     @SN_24 VARCHAR(50),     @SN_25 VARCHAR(50),     @SN_26 VARCHAR(50),     @SN_27 VARCHAR(50),     @SN_28 VARCHAR(50),     @SN_29 VARCHAR(50),     @SN_30 VARCHAR(50),     @DATE_Time VARCHAR(20),     @rs int output ) AS     SELECT @rs=count(*) FROM  TieYards_30 WHERE @BoxNumber=BoxNumber     IF @rs>0     BEGIN         SET @rs=0         RETURN @rs     END     INSERT INTO TieYards_30 VALUES(@OrderNumber,@BoxNumber,@SN_1,@SN_2,@SN_3,@SN_4,@SN_5,@SN_6,@SN_7,@SN_8,                                     @SN_9,@SN_10,@SN_11,@SN_12,@SN_13,@SN_14,@SN_15,@SN_16,@SN_17,@SN_18,@SN_19,                                     @SN_20,@SN_21,@SN_22,@SN_23,@SN_24,@SN_25,@SN_26,@SN_27,@SN_28,@SN_29,@SN_30,@DATE_Time)     IF @@ERROR>0     BEGIN         SET @rs=1     END     ELSE     BEGIN         SET @rs=0     END     RETURN @rs GO