c#+Sql server 绑码程式 源码

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u013934107/article/details/82957771

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:

猜你喜欢

转载自blog.csdn.net/u013934107/article/details/82957771
今日推荐