Esempio n. 1
0
        private void button2_Click(object sender, EventArgs e)
        {
            serialPort1.Close();
            serialPort1.PortName = cbPort.Text;
            serialPort1.BaudRate = 115200;
            serialPort1.Parity   = Parity.None;
            serialPort1.DataBits = 8;
            serialPort1.StopBits = StopBits.One;
            //serialPort1.Handshake = Handshake.RequestToSend;
            //serialPort1.DtrEnable = true;
            //serialPort1.RtsEnable = true;
            //serialPort1.NewLine = System.Environment.NewLine;
            serialPort1.Open();
            int    test2;
            string tbMAC = "00:04:F3:1A:9B:B0";

            if (serialPort1.IsOpen)
            {
                MessageBox.Show("SerialPort is Open!!");
                SQLiteManager test1 = new SQLiteManager(Properties.Settings.Default.DatabasePath);
                test2 = test1.countRow(test1.CreateConnection(), "SELECT count(id) FROM MACadress WHERE data_read LIKE '%" + tbMAC + "%';");
                MessageBox.Show(test2.ToString());
            }
            else
            {
                MessageBox.Show("SerialPort NOT Open!!");
            }
        }
Esempio n. 2
0
        private void button3_Click(object sender, EventArgs e)
        {
            //XmlManager xmlmanager = new XmlManager();
            //xmlmanager.test2();
            SQLiteManager sql = new SQLiteManager(Properties.Settings.Default.DatabasePath);

            sql.InsertData(sql.CreateConnection(), "INSERT INTO MACadress (partnumber,wo,label_scan,data_read,status) VALUES('123456','11111','123123','12345','PASS');");


            //sql.ReadData(sql.CreateConnection(),"SELECT * FROM Test");
        }
Esempio n. 3
0
        private void button1_Click_1(object sender, EventArgs e)
        {
            string tbText;
            string tbMAC;

            string[] tbTextArray;

            int sqlRow_count, sqlRow_countMAC;

            al.Clear();
            this.lbStatus.Text      = "Status";
            this.lbStatus.BackColor = Color.White;
            this.txtSN.Text         = "";
            skip_openPort           = false;

            if (hash_config["ReadSerialport"].ToString() == "True")
            {
                this.btOpen_Click(sender, e);
                skip_openPort = false;
            }
            else
            {
                skip_openPort = true;
                //this.groupBox2.Enabled = false;
            }

            //Thread.Sleep(3000);

            if (serialPort1.IsOpen || skip_openPort == true)
            {
                this.btnSend_Click(sender, e);
                this.lbStatus.Text         = "Running";
                this.lbStatus.BackColor    = Color.Yellow;
                this.pictureBox1.BackColor = Color.Yellow;

                if (SN != null && macAddress != null || skip_openPort == true)
                {
                    for (int i = 1; i <= iLabel; i++)
                    {
                        // MessageBox.Show(i.ToString());
                        textBox1.AppendText("====== Scan Label" + i + "======" + Environment.NewLine);
                        Scanlabel scan = new Scanlabel(i.ToString(), this);
                        scan.ShowDialog();
                        tbText = scan.gettbText();



                        if (skip_openPort.ToString() == "True")
                        {
                            char specialChar = ',';

                            if (i == 1)
                            {
                                specialChar = ',';
                            }
                            else
                            {
                                specialChar = ';';
                            }

                            tbTextArray = tbText.Split(',');

                            tbText = tbTextArray[0];
                        }


                        SQLiteManager sql_sn = new SQLiteManager(Properties.Settings.Default.DatabasePath);
                        sqlRow_count = sql_sn.countRow(sql_sn.CreateConnection(), "SELECT * FROM MACadress WHERE data_read LIKE '%" + tbText + "%' AND status = 'PASS';");

                        if (sqlRow_count == 0)
                        {
                            if (skip_openPort == false)
                            {
                                textBox1.AppendText(DateTime.Now.ToString("HH:mm:ss") + " => Skip serial port : False" + Environment.NewLine);

                                if (tbText != SN)
                                {
                                    this.lbStatus.Text         = "FAIL";
                                    this.lbStatus.BackColor    = Color.Red;
                                    this.pictureBox1.BackColor = Color.Red;
                                    break;
                                }
                                else
                                {
                                    if (i == iLabel)
                                    {
                                        textBox1.AppendText("====== Scan MAC Address ======" + Environment.NewLine);
                                        ScanMAC scanMac = new ScanMAC(this);

                                        scanMac.ShowDialog();
                                        tbMAC = scanMac.gettbText();

                                        SQLiteManager sql_mac = new SQLiteManager(Properties.Settings.Default.DatabasePath);
                                        sqlRow_countMAC = sql_mac.countRow(sql_mac.CreateConnection(), "SELECT * FROM MACadress WHERE data_read LIKE '%" + tbMAC + "%' AND status = 'PASS';");

                                        if (sqlRow_countMAC == 0)
                                        {
                                            if (tbMAC == macAddress)
                                            {
                                                this.lbStatus.Text         = "PASS";
                                                this.lbStatus.BackColor    = Color.GreenYellow;
                                                this.pictureBox1.BackColor = Color.GreenYellow;
                                            }
                                            else
                                            {
                                                this.lbStatus.Text         = "FAIL";
                                                this.lbStatus.BackColor    = Color.Red;
                                                this.pictureBox1.BackColor = Color.Red;
                                            }
                                        }
                                        else
                                        {
                                            textBox1.AppendText(DateTime.Now.ToString("HH:mm:ss") + " => Found dulplicate MACadddress" + Environment.NewLine);
                                            MessageBox.Show("MACaddress ซ้ำ");
                                            this.lbStatus.Text         = "ERROR";
                                            this.lbStatus.BackColor    = Color.Red;
                                            this.pictureBox1.BackColor = Color.Red;

                                            goto End;
                                        }
                                    }
                                }
                            }
                            else
                            {
                                textBox1.AppendText(DateTime.Now.ToString("HH:mm:ss") + " => Skip serial port : False" + Environment.NewLine);


                                //MessageBox.Show(sSn[i - 1]);
                                //MessageBox.Show(sImei[i - 1]);

                                if (i > 1)
                                {
                                    if (sImei[0] == sImei[i - 1])
                                    {
                                        textBox1.AppendText(DateTime.Now.ToString("HH:mm:ss") + "Imei comparison" + Environment.NewLine);
                                        //MessageBox.Show(sImei[0].ToString() + "==" + sImei[i - 1].ToString());
                                        this.lbStatus.Text         = "PASS";
                                        this.lbStatus.BackColor    = Color.GreenYellow;
                                        this.pictureBox1.BackColor = Color.GreenYellow;
                                    }
                                    else
                                    {
                                        textBox1.AppendText(DateTime.Now.ToString("HH:mm:ss") + "IMEI Label 1 กับ Label2 ไม่เหมือนกัน" + Environment.NewLine);
                                        MessageBox.Show("IMEI Label 1 กับ Label2 ไม่เหมือนกัน");
                                        this.lbStatus.Text         = "FAIL";
                                        this.lbStatus.BackColor    = Color.Red;
                                        this.pictureBox1.BackColor = Color.Red;
                                    }
                                }
                                labelText.Append(tbText + ',');
                            }
                        }
                        else
                        {
                            textBox1.AppendText(DateTime.Now.ToString("HH:mm:ss") + " => Found dulplicate serial number" + Environment.NewLine);
                            MessageBox.Show("Serial Number ซ้ำ");
                            this.lbStatus.Text         = "ERROR";
                            this.lbStatus.BackColor    = Color.Red;
                            this.pictureBox1.BackColor = Color.Red;

                            goto End;
                        }
                    }
                }
                else
                {
                    MessageBox.Show("Cannot connect to UUT. กรุญาเลือก port อื่น");
                    this.lbStatus.Text         = "ERROR";
                    this.lbStatus.BackColor    = Color.Red;
                    this.pictureBox1.BackColor = Color.Red;

                    goto End;
                }
            }
            else
            {
                this.lbStatus.Text         = "ERROR";
                this.lbStatus.BackColor    = Color.Red;
                this.pictureBox1.BackColor = Color.Red;
            }


            //Write values to text file
            //foreach(var item in al)
            //{
            //    MessageBox.Show(item.ToString());
            //}
            StringBuilder sb_label_scan = new StringBuilder();

            textBox1.AppendText("====== RESULT FILE ======" + Environment.NewLine);
            textBox1.AppendText(DateTime.Now.ToString("HH:mm:ss") + " => Writing to a result file" + Environment.NewLine);
            using (StreamWriter sw = File.AppendText(DateTime.Now.ToString("dd-MM-yyyy") + " Result.txt"))
            {
                sw.Write(DateTime.Now.ToString("HH:mm:ss"));
                sw.Write(",");
                sw.Write(Partnumber);
                sw.Write(",");
                sw.Write(Wo);
                sw.Write(",");
                sw.Write(iLabel);
                sw.Write(",");
                sw.Write(txtSN.Text);
                sw.Write(",");

                if (skip_openPort.ToString() == "False")
                {
                    foreach (string s in al)
                    {
                        sw.Write(s);
                        sw.Write(",");
                        sb_label_scan.Append(s + ",");
                    }
                }
                else
                {
                    sw.Write("IMEI:");
                    sb_label_scan.Append("IMEI:");

                    foreach (string imei in sImei)
                    {
                        sw.Write(imei);
                        sw.Write(",");
                        sb_label_scan.Append(imei + ",");
                    }

                    sw.Write("SN:");
                    sb_label_scan.Append("SN:");

                    //Fixed "," issue of database inserting 26-7-19
                    for (var i = 0; i < sSn.Count; i++)
                    {
                        sw.Write(sSn[i]);


                        sw.Write(",");

                        if (i == sSn.Count - 1)
                        {
                            sb_label_scan.Append(sSn[i]);
                        }
                        else
                        {
                            sb_label_scan.Append(sSn[i] + ",");
                        }
                    }



                    //foreach (string sn in sSn)
                    //{
                    //    sw.Write(sn);


                    //    sw.Write(",");
                    //    sb_label_scan.Append(sn + ",");
                    //}

                    txtSN.Text = labelText.ToString();
                }

                sw.Write(this.lbStatus.Text);
                sw.WriteLine();
            }
            //MessageBox.Show(sb_label_scan.ToString());

            textBox1.AppendText(DateTime.Now.ToString("HH:mm:ss") + " => Finished Write" + Environment.NewLine);

            //Database write
            textBox1.AppendText("====== DATABASE ======" + Environment.NewLine);
            textBox1.AppendText(DateTime.Now.ToString("HH:mm:ss") + " => Database Insert" + Environment.NewLine);
            SQLiteManager sql = new SQLiteManager(Properties.Settings.Default.DatabasePath);

            sql.InsertData(sql.CreateConnection(), "INSERT INTO MACadress (partnumber,wo,data_read,label_scan,status,timestamp) VALUES('" + Partnumber + "','" + Wo + "','" + txtSN.Text + "','" + sb_label_scan.ToString() + "','" + this.lbStatus.Text + "','" + DateTime.Now.ToString("dd-MM-yyyy HH:mm:ss") + "');");
            textBox1.AppendText(DateTime.Now.ToString("HH: mm:ss") + " => Insert Completed" + Environment.NewLine);

            btClose_Click(sender, e);



End:
            SN         = null;
            macAddress = null;
            serialPort1.Close();
            clearPorts();
            loadPorts();
            sSn.Clear();
            sImei.Clear();
        }