C# Acess数据库的 新增查询删除

 

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.Data.OleDb;
using System.Data.SqlClient;
using System.Collections;

using System.Windows.Forms.DataVisualization.Charting;

namespace 立体仓库管理系统
{
    public partial class kuchenzangtai : Form
    {



        OleDbConnection conn = null;
        OleDbDataAdapter da = null;
        OleDbCommand ocomd = null;
        DataSet ds = null;
        DataTable dt = null;
        public static int hj1ifon = 0;
        public static int hj2ifon = 0;
        public static int hj3ifon = 0;
        public static int hj4ifon = 0;
        int hj1row = 0;
        int hj2row = 0;
        int hj3row = 0;
        int hj4row = 0;

       string conn1="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\\users\\lenovo\\documents\\visual studio 2013\\Projects\\立体仓库管理系统\\立体仓库管理系统\\huojia1.mdb";
       string conn2="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\\users\\lenovo\\documents\\visual studio 2013\\Projects\\立体仓库管理系统\\立体仓库管理系统\\huojia2.mdb";
       string conn3="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\\users\\lenovo\\documents\\visual studio 2013\\Projects\\立体仓库管理系统\\立体仓库管理系统\\huojia3.mdb";
       string conn4="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\\users\\lenovo\\documents\\visual studio 2013\\Projects\\立体仓库管理系统\\立体仓库管理系统\\huojia4.mdb";
        
        public kuchenzangtai()
        {
            InitializeComponent();

            



        }
        private void DataDisplay1()
        {
            conn = new OleDbConnection(conn1);
            string sql = "select * from hjia1";
            da = new OleDbDataAdapter(sql, conn);
            ds = new DataSet();
            da.Fill(ds, "hjia1");
            dt = ds.Tables["hjia1"];
            dataGridView4.DataSource = dt;
            conn.Close();

        }
        private void DataWrite1()
        {
          
            string txt2 =
            "Insert Into hjia1(ID,条码1,条码2) Values('";
            txt2 += textBox1.Text + "' , '";
            txt2 += textBox2.Text + "' , '";
            txt2 += textBox3.Text + "')";
            conn = new OleDbConnection(conn1);
            conn.Open();
            ocomd = new OleDbCommand();
            ocomd.CommandText = txt2;
            ocomd.Connection = conn;
            ocomd.ExecuteNonQuery();
            textBox1.Text = "";
            textBox2.Text = "";
            textBox3.Text = "";
            conn.Close();
            DataDisplay1();


        }
        private void DataDisplay2()
        {
            conn = new OleDbConnection(conn2);
            string sql = "select * from hjia2";
            da = new OleDbDataAdapter(sql, conn);
            ds = new DataSet();
            da.Fill(ds, "hjia2");
            dt = ds.Tables["hjia2"];
            dataGridView3.DataSource = dt;
            conn.Close();

        }
        private void DataWrite2()
        {

            string txt2 =
            "Insert Into hjia2(ID,条码1,条码2) Values('";
            txt2 += textBox1.Text + "' , '";
            txt2 += textBox2.Text + "' , '";
            txt2 += textBox3.Text + "')";
            conn = new OleDbConnection(conn2);
            conn.Open();
            ocomd = new OleDbCommand();
            ocomd.CommandText = txt2;
            ocomd.Connection = conn;
            ocomd.ExecuteNonQuery();
            textBox1.Text = "";
            textBox2.Text = "";
            textBox3.Text = "";
            conn.Close();
            DataDisplay2();


        }
   
        private void DataDisplay3()
        {
            conn = new OleDbConnection(conn3);
            string sql = "select * from hjia3";
            da = new OleDbDataAdapter(sql, conn);
            ds = new DataSet();
            da.Fill(ds, "hjia3");
            dt = ds.Tables["hjia3"];
            dataGridView2.DataSource = dt;
            conn.Close();


        }
        private void DataWrite3()
        {

            string txt2 =
            "Insert Into hjia3(ID,条码1,条码2) Values('";
            txt2 += textBox1.Text + "' , '";
            txt2 += textBox2.Text + "' , '";
            txt2 += textBox3.Text + "')";
            conn = new OleDbConnection(conn3);
            conn.Open();
            ocomd = new OleDbCommand();
            ocomd.CommandText = txt2;
            ocomd.Connection = conn;
            ocomd.ExecuteNonQuery();
            textBox1.Text = "";
            textBox2.Text = "";
            textBox3.Text = "";
            conn.Close();
            DataDisplay3();


        }
        private void DataDisplay4()
        {
            conn = new OleDbConnection(conn4);
            string sql = "select * from hjia4";
            da = new OleDbDataAdapter(sql, conn);
            ds = new DataSet();
            da.Fill(ds, "hjia4");
            dt = ds.Tables["hjia4"];
            dataGridView1.DataSource = dt;
            conn.Close();

        }

        private void DataWrite4()
        {

            string txt2 =
            "Insert Into hjia4(ID,条码1,条码2) Values('";
            txt2 += textBox1.Text + "' , '";
            txt2 += textBox2.Text + "' , '";
            txt2 += textBox3.Text + "')";
            conn = new OleDbConnection(conn4);
            conn.Open();
            ocomd = new OleDbCommand();
            ocomd.CommandText = txt2;
            ocomd.Connection = conn;
            ocomd.ExecuteNonQuery();
            textBox1.Text = "";
            textBox2.Text = "";
            textBox3.Text = "";
            conn.Close();
            DataDisplay4();


        }


        private void kuchenzangtai_Load(object sender, EventArgs e)
        {
            //Provider=Microsoft.Jet.OLEDB.4.0;Data Source="E:\users\lenovo\documents\visual studio 2013\Projects\立体仓库管理系统\立体仓库管理系统\huojia1.mdb"
            //Provider=Microsoft.Jet.OLEDB.4.0;Data Source="E:\users\lenovo\documents\visual studio 2013\Projects\立体仓库管理系统\立体仓库管理系统\huojia2.mdb"
            //Provider=Microsoft.Jet.OLEDB.4.0;Data Source="E:\users\lenovo\documents\visual studio 2013\Projects\立体仓库管理系统\立体仓库管理系统\huojia3.mdb"
            //Provider=Microsoft.Jet.OLEDB.4.0;Data Source="E:\users\lenovo\documents\visual studio 2013\Projects\立体仓库管理系统\立体仓库管理系统\huojia4.mdb"
            // TODO:  这行代码将数据加载到表“huojia3DataSet1.hjia3”中。您可以根据需要移动或删除它。
            DataDisplay1();
            DataDisplay2();
            DataDisplay3();
            DataDisplay4();

            HJ1();
         
        }

        private void groupBox1_Paint(object sender, PaintEventArgs e)
        {
        
            e.Graphics.Clear(groupBox1.BackColor);
            e.Graphics.DrawString(groupBox1.Text, groupBox1.Font, Brushes.Blue, 10, 1);
            e.Graphics.DrawLine(Pens.Blue, 1, 7, 8, 7);
            e.Graphics.DrawLine(Pens.Blue, e.Graphics.MeasureString(groupBox1.Text, groupBox1.Font).Width + 8, 7, groupBox1.Width - 2, 7);
            e.Graphics.DrawLine(Pens.Blue, 1, 7, 1, groupBox1.Height - 2);
            e.Graphics.DrawLine(Pens.Blue, 1, groupBox1.Height - 2, groupBox1.Width - 2, groupBox1.Height - 2);
            e.Graphics.DrawLine(Pens.Blue, groupBox1.Width - 2, 7, groupBox1.Width - 2, groupBox1.Height - 2); 
        
        }

        private void groupBox2_Paint(object sender, PaintEventArgs e)
        {
            e.Graphics.Clear(groupBox2.BackColor);
            e.Graphics.DrawString(groupBox2.Text, groupBox2.Font, Brushes.Black, 10, 1);
            e.Graphics.DrawLine(Pens.Black, 1, 7, 8, 7);
            e.Graphics.DrawLine(Pens.Black, e.Graphics.MeasureString(groupBox2.Text, groupBox2.Font).Width + 8, 7, groupBox2.Width - 2, 7);
            e.Graphics.DrawLine(Pens.Black, 1, 7, 1, groupBox2.Height - 2);
            e.Graphics.DrawLine(Pens.Black, 1, groupBox2.Height - 2, groupBox2.Width - 2, groupBox2.Height - 2);
            e.Graphics.DrawLine(Pens.Black, groupBox2.Width - 2, 7, groupBox2.Width - 2, groupBox2.Height - 2); 
        }

        private void groupBox3_Paint(object sender, PaintEventArgs e)
        {
            e.Graphics.Clear(groupBox3.BackColor);
            e.Graphics.DrawString(groupBox3.Text, groupBox3.Font, Brushes.Black, 10, 1);
            e.Graphics.DrawLine(Pens.Black, 1, 7, 8, 7);
            e.Graphics.DrawLine(Pens.Black, e.Graphics.MeasureString(groupBox3.Text, groupBox3.Font).Width + 8, 7, groupBox3.Width - 2, 7);
            e.Graphics.DrawLine(Pens.Black, 1, 7, 1, groupBox1.Height - 2);
            e.Graphics.DrawLine(Pens.Black, 1, groupBox3.Height - 2, groupBox3.Width - 2, groupBox3.Height - 2);
            e.Graphics.DrawLine(Pens.Black, groupBox3.Width - 2, 7, groupBox3.Width - 2, groupBox3.Height - 2); 
        }

   
        

     


        private void button1_Click(object sender, EventArgs e)
        {
            if (radioButton1.Checked)
            {
                DataWrite1();
            }
            else if (radioButton2.Checked)
            {
                 DataWrite2();
            }
            else if (radioButton3.Checked)
            {
                DataWrite3();
            }
            else if (radioButton4.Checked)
            {
                DataWrite4();
            }
            
        }

     

        private void timer1_Tick(object sender, EventArgs e)
        {
            label2.Text = Form1.Revdate;
            label4.Text = Form1.senddate;

            HJ1();
            HJ2();
            HJ3();
            HJ4();

          
        }


        private void HJ1()
        {

            OleDbDataAdapter oleDapAdapter; //检索与填充数据,一般填充SQL语句  
            ds = new DataSet();
            oleDapAdapter = new OleDbDataAdapter("select * from hjia1", conn1);
            oleDapAdapter.Fill(ds);
            int a1 = ds.Tables[0].Rows.Count;
            hj1ifon = a1;
            hj1row = 60 - a1;
            double[] yValues = { hj1ifon,hj1row};
            string[] xValues = { "已用", "剩余" };
            chart1.Series[0].Points.DataBindXY(xValues, yValues);
          
        }
        private void HJ2()
        {

            OleDbDataAdapter oleDapAdapter; //检索与填充数据,一般填充SQL语句  
            ds = new DataSet();
            oleDapAdapter = new OleDbDataAdapter("select * from hjia2", conn2);
            oleDapAdapter.Fill(ds);
            int a1 = ds.Tables[0].Rows.Count;
            hj1ifon = a1;
            hj1row = 60 - a1;
            double[] yValues = { hj1ifon, hj1row };
            string[] xValues = { "已用", "剩余" };
            chart2.Series[0].Points.DataBindXY(xValues, yValues);
        }
        private void HJ3()
        {

            OleDbDataAdapter oleDapAdapter; //检索与填充数据,一般填充SQL语句  
            ds = new DataSet();
            oleDapAdapter = new OleDbDataAdapter("select * from hjia3", conn3);
            oleDapAdapter.Fill(ds);
            int a1 = ds.Tables[0].Rows.Count;
            hj1ifon = a1;
            hj1row = 60 - a1;
            double[] yValues = { hj1ifon, hj1row };
            string[] xValues = { "已用", "剩余" };
            chart3.Series[0].Points.DataBindXY(xValues, yValues);

        }
        private void HJ4()
        {

            OleDbDataAdapter oleDapAdapter; //检索与填充数据,一般填充SQL语句  
            ds = new DataSet();
            oleDapAdapter = new OleDbDataAdapter("select * from hjia4", conn4);
            oleDapAdapter.Fill(ds);
            int a1 = ds.Tables[0].Rows.Count;
            hj1ifon = a1;
            hj1row = 60 - a1;
            double[] yValues = { hj1ifon, hj1row };
            string[] xValues = { "已用", "剩余" };
            chart4.Series[0].Points.DataBindXY(xValues, yValues);
        }



        
       
        /// <summary>
        /// 接收到PLC发来的数据 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void label2_TextChanged(object sender, EventArgs e)
        {
            inputorc();
        }
        /// <summary>
        /// 解析数据 第1位货架号 第2位入库及出库 第3-11编码1 第12-21编码2
        /// </summary>
        private void inputorc()
        {
            string str = label2.Text;
            try
            {
                if (str != "")
                {
                    string str3 = str.Substring(0, 1);
                    string str1 = str.Substring(1, 9);
                    string str2 = str.Substring(10, 9);
                    textBox2.Text = str1;
                    textBox3.Text = str2;
                   // Console.WriteLine(str3);
                    if (str3 == "1")
                    {

                        FindID1();
                        sendPLCdate();
                        DataWrite1();
                    }
                    if (str3 == "2")
                    {
                        FindID2();
                        sendPLCdate();
                        DataWrite2();
                    }
                    if (str3 == "3")
                    {
                        FindID3();
                        sendPLCdate();
                        DataWrite3();
                    }
                    if (str3 == "4")
                    {
                        FindID4();
                        sendPLCdate();
                        DataWrite4();
                    }
                }
 

            }
            catch {}
            
         
          
           


        } 
        private void button3_Click(object sender, EventArgs e)
        {
            if (radioButton1.Checked)
            {
                deledatID1();
            }
            if (radioButton2.Checked)
            {
                deledatID2();
            }
            if (radioButton3.Checked)
            {
                deledatID3();
            }
            if (radioButton4.Checked)
            {
                deledatID4();
            }

          
            
            
        }

       
        private void button2_Click(object sender, EventArgs e)
        {
            if (radioButton1.Checked)
            {
                FindID1();
            }
            if (radioButton2.Checked)
            {
                FindID2();
            }
            if (radioButton3.Checked)
            {
                FindID3();
            }
            if (radioButton4.Checked)
            {
                FindID4();
            }

           
        }
        /// <summary>
        /// 入库找空位
        /// </summary>
        private void FindID1()
        {
            ArrayList a1 = new ArrayList();


            OleDbDataAdapter oleDapAdapter; //检索与填充数据,一般填充SQL语句  
            ds = new DataSet();
            oleDapAdapter = new OleDbDataAdapter("select * from hjia1", conn1);
            oleDapAdapter.Fill(ds);
            int a2 = ds.Tables[0].Rows.Count;
            hj1row = a2;
            int inserta3 = 0;
            int[] arry1 = new int[a2];
            for (int j = 0; j < ds.Tables[0].Rows.Count; j++)
            {
                string ids = (ds.Tables[0].Rows[j]["ID"].ToString());//需要转成String类型  
                int idi = Convert.ToInt32(ids);
                arry1[j] = idi;
               
                // Console.Write(idi);

                // (i != Convert.ToInt32(ids))                  
                //   Console.WriteLine(ids); 
            }
            ds.Reset();
            Console.WriteLine();
            //for (int i = 0; i < arry1.Length; i++)
            //{
            //    Console.Write(arry1[i]); 
            //}
            //Console.WriteLine();
            Array.Sort(arry1);
            //for (int i = 0; i < arry1.Length; i++)
            //{
            //    Console.Write(arry1[i]);
            //}
            Console.WriteLine();

            //12345789101112131520

            int x = 1;//标识初值
            for (int i = 0; i < arry1.Length; i++)
            {

                if (arry1[i] != x)
                {
                    // Console.WriteLine(arry1[i]);
                    //inserta3 = arry1[i]-1 ;
                    //if (i >= 1)
                    //{
                    //    textBox1.Text = Convert.ToString(arry1[i - 1] + 1);
                    //    break;
                    //}
                    //else
                    //{
                    //    textBox1.Text = Convert.ToString(arry1[i] - 1);
                    //    break;
                    //}

                    textBox1.Text = Convert.ToString(arry1[i] - 1);
                    break;
                }
                else if (x == a2)
                {
                    textBox1.Text = Convert.ToString(a2 +1);
                    break; 
                }
                x++;//增量
            }
            Console.WriteLine(inserta3);
        }
        /// <summary>
        /// 清空已出库库位信息
        /// </summary>
        private void deledatID1()
        {
            if (textBox1.Text == "")
            {
                MessageBox.Show("ID号项必须填写! ", "提示");
                return;
            }


            string txt2 = "Delete From hjia1 Where ID = " + textBox1.Text;

            conn = new OleDbConnection(conn1);
            conn.Open();
            ocomd = new OleDbCommand();
            ocomd.CommandText = txt2;
            ocomd.Connection = conn;
          // ocomd.ExecuteNonQuery();
            int a3 = ocomd.ExecuteNonQuery();
            if (a3==1)
            {
                MessageBox.Show("删除成功", "提示");
            }
            else
            {
                MessageBox.Show("删除成功,未找到删除的ID", "提示");
            }


         //   Console.WriteLine(a3);
            textBox1.Text = "";
            textBox2.Text = "";
            textBox3.Text = "";
            conn.Close();
            DataDisplay1(); 


        }
        /// <summary>
        /// 2号库
        /// </summary>
        private void FindID2()
        {
            ArrayList a1 = new ArrayList();


            OleDbDataAdapter oleDapAdapter; //检索与填充数据,一般填充SQL语句  
            ds = new DataSet();
            oleDapAdapter = new OleDbDataAdapter("select * from hjia2", conn2);
            oleDapAdapter.Fill(ds);
            int a2 = ds.Tables[0].Rows.Count;
            hj2row = a2;
            int inserta3 = 0;
            int[] arry1 = new int[a2];
            for (int j = 0; j < ds.Tables[0].Rows.Count; j++)
            {
                string ids = (ds.Tables[0].Rows[j]["ID"].ToString());//需要转成String类型  
                int idi = Convert.ToInt32(ids);
                arry1[j] = idi;
                // Console.Write(idi);

                // (i != Convert.ToInt32(ids))                  
                //   Console.WriteLine(ids); 
            }
            ds.Reset();
            Console.WriteLine();
            //for (int i = 0; i < arry1.Length; i++)
            //{
            //    Console.Write(arry1[i]); 
            //}
            //Console.WriteLine();
            Array.Sort(arry1);
            //for (int i = 0; i < arry1.Length; i++)
            //{
            //    Console.Write(arry1[i]);
            //}
            Console.WriteLine();

            //12345789101112131520

            int x = 1;//标识初值
            for (int i = 0; i < arry1.Length; i++)
            {

                if (arry1[i] != x)
                {
                    // Console.WriteLine(arry1[i]);
                    //inserta3 = arry1[i]-1 ;
                    //if (i >= 1)
                    //{
                    //    textBox1.Text = Convert.ToString(arry1[i - 1] + 1);
                    //    break;
                    //}
                    //else
                    //{
                    //    textBox1.Text = Convert.ToString(arry1[i] - 1);
                    //    break;
                    //}

                    textBox1.Text = Convert.ToString(arry1[i] - 1);
                    break;
                }
                else if (x == a2)
                {
                    textBox1.Text = Convert.ToString(a2 + 1);
                    break;
                }
                x++;//增量
            }
            Console.WriteLine(inserta3);
        }
        private void deledatID2()
        {
            if (textBox1.Text == "")
            {
                MessageBox.Show("ID号项必须填写! ", "提示");
                return;
            }


            string txt2 = "Delete From hjia2 Where ID = " + textBox1.Text;

            conn = new OleDbConnection(conn2);
            conn.Open();
            ocomd = new OleDbCommand();
            ocomd.CommandText = txt2;
            ocomd.Connection = conn;
           // ocomd.ExecuteNonQuery();
            int a3 = ocomd.ExecuteNonQuery();
            if (a3 == 1)
            {
                MessageBox.Show("删除成功", "提示");
            }
            else
            {
                MessageBox.Show("删除成功,未找到删除的ID", "提示");
            }

            textBox1.Text = "";
            textBox2.Text = "";
            textBox3.Text = "";
            conn.Close();
            DataDisplay2();


        }
        private void FindID3()
        {
            ArrayList a1 = new ArrayList();


            OleDbDataAdapter oleDapAdapter; //检索与填充数据,一般填充SQL语句  
            ds = new DataSet();
            oleDapAdapter = new OleDbDataAdapter("select * from hjia3", conn3);
            oleDapAdapter.Fill(ds);
            int a2 = ds.Tables[0].Rows.Count;
            hj3row = a2;
            int inserta3 = 0;
            int[] arry1 = new int[a2];
            for (int j = 0; j < ds.Tables[0].Rows.Count; j++)
            {
                string ids = (ds.Tables[0].Rows[j]["ID"].ToString());//需要转成String类型  
                int idi = Convert.ToInt32(ids);
                arry1[j] = idi;
                // Console.Write(idi);

                // (i != Convert.ToInt32(ids))                  
                //   Console.WriteLine(ids); 
            }
            ds.Reset();
            Console.WriteLine();
            //for (int i = 0; i < arry1.Length; i++)
            //{
            //    Console.Write(arry1[i]); 
            //}
            //Console.WriteLine();
            Array.Sort(arry1);
            //for (int i = 0; i < arry1.Length; i++)
            //{
            //    Console.Write(arry1[i]);
            //}
            Console.WriteLine();

            //12345789101112131520

            int x = 1;//标识初值
            for (int i = 0; i < arry1.Length; i++)
            {

                if (arry1[i] != x)
                {
                    // Console.WriteLine(arry1[i]);
                    //inserta3 = arry1[i]-1 ;
                    //if (i >= 1)
                    //{
                    //    textBox1.Text = Convert.ToString(arry1[i - 1] + 1);
                    //    break;
                    //}
                    //else
                    //{
                    //    textBox1.Text = Convert.ToString(arry1[i] - 1);
                    //    break;
                    //}

                    textBox1.Text = Convert.ToString(arry1[i] - 1);
                    break;
                }
                else if (x == a2)
                {
                    textBox1.Text = Convert.ToString(a2 + 1);
                    break;
                }
                x++;//增量
            }
            Console.WriteLine(inserta3);
        }
        private void deledatID3()
        {
            if (textBox1.Text == "")
            {
                MessageBox.Show("ID号项必须填写! ", "提示");
                return;
            }


            string txt2 = "Delete From hjia3 Where ID = " + textBox1.Text;

            conn = new OleDbConnection(conn3);
            conn.Open();
            ocomd = new OleDbCommand();
            ocomd.CommandText = txt2;
            ocomd.Connection = conn;
            //ocomd.ExecuteNonQuery();
            int a3 = ocomd.ExecuteNonQuery();
            if (a3 == 1)
            {
                MessageBox.Show("删除成功", "提示");
            }
            else
            {
                MessageBox.Show("删除成功,未找到删除的ID", "提示");
            }

            textBox1.Text = "";
            textBox2.Text = "";
            textBox3.Text = "";
            conn.Close();
            DataDisplay3();


        }
        private void FindID4()
        {
            ArrayList a1 = new ArrayList();


            OleDbDataAdapter oleDapAdapter; //检索与填充数据,一般填充SQL语句  
            ds = new DataSet();
            oleDapAdapter = new OleDbDataAdapter("select * from hjia4", conn4);
            oleDapAdapter.Fill(ds);
            int a2 = ds.Tables[0].Rows.Count;
            hj4row = a2;
            int inserta3 = 0;
            int[] arry1 = new int[a2];
            for (int j = 0; j < ds.Tables[0].Rows.Count; j++)
            {
                string ids = (ds.Tables[0].Rows[j]["ID"].ToString());//需要转成String类型  
                int idi = Convert.ToInt32(ids);
                arry1[j] = idi;
                // Console.Write(idi);

                // (i != Convert.ToInt32(ids))                  
                //   Console.WriteLine(ids); 
            }
            ds.Reset();
            Console.WriteLine();
            //for (int i = 0; i < arry1.Length; i++)
            //{
            //    Console.Write(arry1[i]); 
            //}
            //Console.WriteLine();
            Array.Sort(arry1);
            //for (int i = 0; i < arry1.Length; i++)
            //{
            //    Console.Write(arry1[i]);
            //}
            Console.WriteLine();

            //12345789101112131520

            int x = 1;//标识初值
            for (int i = 0; i < arry1.Length; i++)
            {

                if (arry1[i] != x)
                {
                    // Console.WriteLine(arry1[i]);
                    //inserta3 = arry1[i]-1 ;
                    //if (i >= 1)
                    //{
                    //    textBox1.Text = Convert.ToString(arry1[i - 1] + 1);
                    //    break;
                    //}
                    //else
                    //{
                    //    textBox1.Text = Convert.ToString(arry1[i] - 1);
                    //    break;
                    //}

                    textBox1.Text = Convert.ToString(arry1[i] - 1);
                    break;
                }
                else if (x == a2)
                {
                    textBox1.Text = Convert.ToString(a2 + 1);
                    break;
                }
                x++;//增量
            }
            Console.WriteLine(inserta3);
        }
        private void deledatID4()
        {
            if (textBox1.Text == "")
            {
                MessageBox.Show("ID号项必须填写! ", "提示");
                return;
            }


            string txt2 = "Delete From hjia4 Where ID = " + textBox1.Text;

            conn = new OleDbConnection(conn4);
            conn.Open();
            ocomd = new OleDbCommand();
            ocomd.CommandText = txt2;
            ocomd.Connection = conn;
            //ocomd.ExecuteNonQuery();
            int a3 = ocomd.ExecuteNonQuery();
            if (a3 == 1)
            {
                MessageBox.Show("删除成功", "提示");
            }
            else
            {
                MessageBox.Show("删除成功,未找到删除的ID", "提示");
            }

            textBox1.Text = "";
            textBox2.Text = "";
            textBox3.Text = "";
            conn.Close();
            DataDisplay4();


        }

        private void button4_Click(object sender, EventArgs e)
        {
            
                sendPLCdate();
                       
        }
        private void sendPLCdate()
        {
            Form1.Sendmsg = textBox1.Text;
            Form1.Sendbtn = "1";
        }



        private void outproduct()
        {
            int a1 = 0;
            if (a1 == 0)
            {
                try
                {
                    OleDbDataAdapter oleDapAdapter; //检索与填充数据,一般填充SQL语句  
                    ds = new DataSet();
                    oleDapAdapter = new OleDbDataAdapter("select * from hjia1", conn1);
                    oleDapAdapter.Fill(ds);

                    for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                    {

                        //   Console.WriteLine(ds.Tables[0].Rows[i]["ID"].ToString());         
                        //  Console.WriteLine(ds.Tables[0].Rows[i]["条码1"].ToString());      
                        //  Console.WriteLine(ds.Tables[0].Rows[i]["条码2"].ToString());
                        string str1 = ds.Tables[0].Rows[i]["ID"].ToString();
                        string str2 = ds.Tables[0].Rows[i]["条码1"].ToString();
                        string str3 = ds.Tables[0].Rows[i]["条码2"].ToString();

                        if ((str2 == textBox2.Text) || (str3 == textBox3.Text))
                        {
                            textBox1.Text = str1;
                            textBox5.Text = str1;
                            textBox4.Text = "1";
                            a1 = 5;
                            textBox2.Text = "";
                            textBox3.Text = "";
                            break;
                        }
                        if (a1==0)
                        {
                            a1 = 1;
                        }

                    }
                }
                catch { }

            }

            if (a1 == 1)
            {
                try
                {
                    OleDbDataAdapter oleDapAdapter; //检索与填充数据,一般填充SQL语句  
                    ds = new DataSet();
                    oleDapAdapter = new OleDbDataAdapter("select * from hjia2", conn2);
                    oleDapAdapter.Fill(ds);

                    for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                    {
                        //   Console.WriteLine(ds.Tables[0].Rows[i]["ID"].ToString());         
                        //  Console.WriteLine(ds.Tables[0].Rows[i]["条码1"].ToString());      
                        //  Console.WriteLine(ds.Tables[0].Rows[i]["条码2"].ToString());
                        string str1 = ds.Tables[0].Rows[i]["ID"].ToString();
                        string str2 = ds.Tables[0].Rows[i]["条码1"].ToString();
                        string str3 = ds.Tables[0].Rows[i]["条码2"].ToString();

                        if ((str2 == textBox2.Text) || (str3 == textBox3.Text))
                        {
                            textBox1.Text = str1;
                            textBox5.Text = str1;
                            textBox4.Text = "2";
                            a1 = 5;
                            textBox2.Text = "";
                            textBox3.Text = "";
                            break;
                        }
                        if (a1 == 1)
                        {
                            a1 = 2;
                        }

                    }
                }
                catch { }

            }


            if (a1 == 2)
            {
                try
                {
                    OleDbDataAdapter oleDapAdapter; //检索与填充数据,一般填充SQL语句  
                    ds = new DataSet();
                    oleDapAdapter = new OleDbDataAdapter("select * from hjia3", conn3);
                    oleDapAdapter.Fill(ds);

                    for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                    {
                        //   Console.WriteLine(ds.Tables[0].Rows[i]["ID"].ToString());         
                        //  Console.WriteLine(ds.Tables[0].Rows[i]["条码1"].ToString());      
                        //  Console.WriteLine(ds.Tables[0].Rows[i]["条码2"].ToString());
                        string str1 = ds.Tables[0].Rows[i]["ID"].ToString();
                        string str2 = ds.Tables[0].Rows[i]["条码1"].ToString();
                        string str3 = ds.Tables[0].Rows[i]["条码2"].ToString();

                        if ((str2 == textBox2.Text) || (str3 == textBox3.Text))
                        {
                            textBox1.Text = str1;
                            textBox5.Text = str1;
                            textBox4.Text = "3";
                            a1 = 5;
                            textBox2.Text = "";
                            textBox3.Text = "";
                            break;
                        }
                        if (a1 == 2)
                        {
                            a1 = 3;
                        }

                    }
                }
                catch { }

            }

            if (a1 == 3)
            {
                try
                {
                    OleDbDataAdapter oleDapAdapter; //检索与填充数据,一般填充SQL语句  
                    ds = new DataSet();
                    oleDapAdapter = new OleDbDataAdapter("select * from hjia4", conn4);
                    oleDapAdapter.Fill(ds);

                    for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                    {
                        //   Console.WriteLine(ds.Tables[0].Rows[i]["ID"].ToString());         
                        //  Console.WriteLine(ds.Tables[0].Rows[i]["条码1"].ToString());      
                        //  Console.WriteLine(ds.Tables[0].Rows[i]["条码2"].ToString());
                        string str1 = ds.Tables[0].Rows[i]["ID"].ToString();
                        string str2 = ds.Tables[0].Rows[i]["条码1"].ToString();
                        string str3 = ds.Tables[0].Rows[i]["条码2"].ToString();

                        if ((str2 == textBox2.Text) || (str3 == textBox3.Text))
                        {
                            textBox1.Text = str1;
                            textBox5.Text = str1;
                            textBox4.Text = "4";
                            a1 = 5;
                            textBox2.Text = "";
                            textBox3.Text = "";
                            break;
                        }
                   
                    }
                }
                catch { }

            }
            
          if (a1!=5)
          {
              MessageBox.Show("未找到所查询的条码 请重新输入", "提示");
          }

        }

        private void button5_Click(object sender, EventArgs e)
        {
            outproduct();
        }

       
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值