Пример #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            DateTime beforDT = System.DateTime.Now;
            int      Rows;

            //DataTable dt = new DataTable();

            System.Windows.Forms.OpenFileDialog fd = new OpenFileDialog();

            if (fd.ShowDialog() == DialogResult.OK)
            {
                string fileName = fd.FileName;
                Rows = 0;
                DataTable p      = new DataTable();
                DataTable dt     = ExcelToDS(fileName);
                int       number = dt.Rows.Count;
                //dataGridView1.DataSource = dt;
                //this.dataGridView1.DataSource = dt;
                if (number > 0)
                {
                    //DataRow dr = null;
                    bool Comparison = false;
                    for (int i = 1; i < number; i++)
                    {
                        //dr = dt.Rows[i];
                        string SN       = dt.Rows[i][6].ToString();
                        string CATTONNO = dt.Rows[i][12].ToString();
                        string DATE     = dt.Rows[i][14].ToString();

                        if (SN == "")
                        {
                            continue;
                        }
                        bool result = ORACLEDLL.Comparison(SN, CATTONNO, DATE);
                        if (result)
                        {
                            /*
                             * bool res = ORACLEDLL.InsterApicalComparison(SN, CATTONNO, DATE);
                             * if (!res)
                             * {
                             *  //MessageBox.Show("录入失败!");
                             *  textBox2.Text += "SN:" + dt.Rows[i][6].ToString() + "    " + "箱号:" + dt.Rows[i][12].ToString() + "    " + " 录入失败\r\n";
                             *  Application.DoEvents();
                             * }
                             * textBox1.Text += "SN:" + dt.Rows[i][6].ToString() + "    " + "箱号:" + dt.Rows[i][12].ToString() + "    " + " 录入成功\r\n";
                             * Application.DoEvents();
                             * */

                            //continue;
                        }
                        else
                        {
                            Comparison     = true;
                            textBox1.Text += "SN:" + dt.Rows[i][6].ToString() + "    " + "箱号:" + dt.Rows[i][12].ToString() + "    " + " 重复\r\n";
                            //Application.DoEvents();
                        }

                        label4.ForeColor = Color.Red;
                        label4.Text      = "正在检测数据,请稍后......";
                        Application.DoEvents();
                        //System.Threading.Thread.Sleep(100);
                    }

                    if (Comparison)
                    {
                        MessageBox.Show("有重复数据,请检查!");
                    }
                    else
                    {
                        label4.ForeColor = Color.Red;
                        label4.Text      = "正在录入数据......";
                        for (int i = 1; i < number; i++)
                        {
                            string SN       = dt.Rows[i][6].ToString();
                            string CATTONNO = dt.Rows[i][12].ToString();
                            string DATE     = dt.Rows[i][14].ToString();

                            if (SN == "")
                            {
                                continue;
                            }

                            bool res = ORACLEDLL.InsterApicalComparison(SN, CATTONNO, DATE);
                            if (!res)
                            {
                                textBox1.Text += "SN:" + dt.Rows[i][6].ToString() + "    " + "箱号:" + dt.Rows[i][12].ToString() + "    " + " 录入失败\r\n";
                                MessageBox.Show("录入失败!");
                                Application.DoEvents();
                            }
                            textBox1.Text += "SN:" + dt.Rows[i][6].ToString() + "    " + "箱号:" + dt.Rows[i][12].ToString() + "    " + " 录入成功\r\n";
                            Rows++;
                            Application.DoEvents();
                        }
                    }

                    string exepath  = System.IO.Directory.GetCurrentDirectory();
                    string filepath = exepath + "\\repeat.txt";

                    //FileStream fs = new FileStream("repeat.txt", FileMode.OpenOrCreate, FileAccess.ReadWrite);
                    FileStream   fs = new FileStream(filepath, FileMode.Append, FileAccess.Write);
                    StreamWriter sw = new StreamWriter(fs);
                    DateTime.Now.ToString();        //获取当前系统时间 完整的日期和时间
                    sw.WriteLine(DateTime.Now.ToString());
                    sw.WriteLine(textBox1.Text);
                    //sw.WriteLine(textBox2.Text);
                    sw.Flush(); //文件流
                    sw.Close(); //最后要关闭写入状态
                    if (!Comparison)
                    {
                        label2.Text = "本次操作共录入 " + Rows + "行";
                        MessageBox.Show("导入成功!");
                    }
                }
                else
                {
                    MessageBox.Show("没有数据!");
                }
                label4.ForeColor = Color.Green;
                label4.Text      = "操作完成!";

                label2.ForeColor = Color.Red;
            }

            DateTime afterDT = System.DateTime.Now;
            TimeSpan ts      = afterDT.Subtract(beforDT);
        }
Пример #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            string Database;

            //Database = comboBox1.Text;
            if (comboBox1.Text == "二楼MES")
            {
                Database = "2FMES";
            }
            else if (comboBox1.Text == "四楼MES")
            {
                Database = "4FMES";
            }
            else if (comboBox1.Text == "TestMES")
            {
                Database = "TestMES";
            }
            else
            {
                MessageBox.Show("请先选择导入数据库!");
                return;
            }

            string exepath  = System.IO.Directory.GetCurrentDirectory();
            string filepath = exepath + "\\BOM.xls";

            string Date = DateTime.Now.ToString("yyyyMMdd");
            //textBox1.Text = Date;

            DataTable p      = new DataTable();
            DataTable dt     = ExcelToDS(filepath);
            int       number = dt.Rows.Count; //获取数据行数

            //textBox1.Text = dt.Rows[0][0].ToString() + "\t";
            //textBox1.Text = dt.Rows.Count.ToString();


            for (int i = 2; i < number; i++)
            {
                bool b = ORACLEDLL.Material_Exists(dt.Rows[i][0].ToString(), Database);
                if (b)
                {
                    bool result = ORACLEDLL.InsterMatertal(dt.Rows[i][0].ToString(), dt.Rows[i][1].ToString(), dt.Rows[i][2].ToString(), "PCS", "itemtype_rawmaterial", "0", "0", "SYSTEM", Date, "10000", "1", "0", Database);
                    if (result)
                    {
                        bool temp = ORACLEDLL.BOM_Exists(dt.Rows[0][0].ToString(), dt.Rows[i][0].ToString(), Database);
                        if (temp)
                        {
                            bool result2 = ORACLEDLL.InsterBom(dt.Rows[0][0].ToString(), dt.Rows[i][0].ToString(), dt.Rows[i][0].ToString(), dt.Rows[i][4].ToString(), Date, "0", "0", "29991231", "0", "EA", "SYSTEM", Date, "10000", "1", "1.1", "1", "0", "0", "S", Database);
                            if (result2)
                            {
                                textBox1.Text += "物料:" + dt.Rows[i][0].ToString() + " 与产品:" + dt.Rows[0][0].ToString() + " 成功绑定\r\n";
                            }
                            else
                            {
                                textBox1.Text += "物料:" + dt.Rows[i][0].ToString() + " 录入成功" + " 但是与产品:" + dt.Rows[0][0].ToString() + "绑定失败,请重试!\r\n";
                            }
                        }
                        else
                        {
                            textBox1.Text += "物料:" + dt.Rows[i][0].ToString() + " 与产品:" + dt.Rows[0][0].ToString() + " 已有绑定关系\r\n";
                        }
                    }
                    else
                    {
                        textBox1.Text += "物料:" + dt.Rows[i][0].ToString() + " 录入失败,请重试!\r\n";
                    }
                }
                else
                {
                    bool temp = ORACLEDLL.BOM_Exists(dt.Rows[0][0].ToString(), dt.Rows[i][0].ToString(), Database);
                    if (temp)
                    {
                        bool result = ORACLEDLL.InsterBom(dt.Rows[0][0].ToString(), dt.Rows[i][0].ToString(), dt.Rows[i][0].ToString(), dt.Rows[i][4].ToString(), Date, "0", "0", "29991231", "0", "EA", "SYSTEM", Date, "10000", "1", "1.1", "1", "0", "0", "S", Database);
                        if (result)
                        {
                            textBox1.Text += "物料:" + dt.Rows[i][0].ToString() + " 与产品:" + dt.Rows[0][0].ToString() + " 成功绑定\r\n";
                        }
                        else
                        {
                            textBox1.Text += "物料:" + dt.Rows[i][0].ToString() + " 与产品:" + dt.Rows[0][0].ToString() + "绑定失败,请重试!\r\n";
                        }
                    }
                    else
                    {
                        textBox1.Text += "物料:" + dt.Rows[i][0].ToString() + " 与产品:" + dt.Rows[0][0].ToString() + " 已有绑定关系\r\n";
                    }
                }
                textBox1.Text += "\r\n";
                //Thread.Sleep(1000);
            }
            //bool B = ORACLEDLL.InsterMatertal("1202008-0003-8", "PCBA", "69830WVRAIT8M", "PCS", "itemtypel", "0", "0", "SYSTEM", "20180508", "10000", "1", "0");
            //bool B = ORACLEDLL.InsterBom("1109008-0161-1", "1601002-0537-1", "1601002-0537-1", "1", "20180508", " ", "0", "29991231", "0", "EA", "SYSTEM", "20180508", "10000", "1", "1.1", "1", "0", "0", "S");
        }