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