예제 #1
0
파일: FormMain.cs 프로젝트: imatary/work
        private void txtBarcode_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                // nếu = false thì làm việc như bình thường, test log
                if (skipWaitLogs == false)
                {
                    try
                    {
                        boardNo = txtBarcode.Text.Trim();
                        if (boardNo != null && boardNo.Length >= 10)
                        {
                            productId          = cboModels.Text;
                            dateCheck          = DateTime.Now.ToString("yyMMddHHmmss");
                            txtBarcode.Enabled = false;
                            lblReset.Enabled   = true;
                            //dataGridView1.DataSource = null;
                            byte[] byData = Encoding.ASCII.GetBytes(boardNo);
                            for (int i = 0; i < m_clientCount; i++)
                            {
                                if (m_workerSocket[i] != null)
                                {
                                    if (m_workerSocket[i].Connected)
                                    {
                                        m_workerSocket[i].Send(byData);
                                    }
                                }
                            }

                            if (cboCheckTwoPcs.Checked == false)
                            {
                                ActiveProcess(processName);
                            }
                            else
                            {
                                txtBarcode.Enabled = false;

                                txtBarcode2.ResetText();
                                txtBarcode2.Focus();
                            }
                        }
                        else
                        {
                            ErrorMessage("NG", "Vui lòng bắn vào barcode");
                            txtBarcode.Focus();
                        }
                    }
                    catch (SocketException se)
                    {
                        MessageBox.Show(se.Message);
                    }
                }
                // nếu = true, thì tạo log luôn không cần chờ Log máy nữa
                else
                {
                    if (txtBarcode.Text != null)
                    {
                        Ultils.CreateFileLog(cboModels.Text, txtBarcode.Text, "P", stationNo, DateTime.Now.ToString("yyMMddHHmmss"));
                        txtBarcode.ResetText();
                        txtBarcode.Focus();
                    }
                }
            }
        }
예제 #2
0
파일: FormMain.cs 프로젝트: imatary/work
        private void timer1_Tick(object sender, EventArgs e)
        {
            if (checkLength == true)
            {
                ActiveWindows(this.Text);
                txtBarcode.Enabled = true;
                txtBarcode.ResetText();
                txtBarcode.Focus();
                serial      = "";
                checkLength = false;
            }
            else
            {
                if (RunTaks)
                {
                    if (ModelName(fileLastWriteTime).Substring(0, productId.Length) == productId)
                    {
                        boardState = GetStateBoardOne(fileLastWriteTime);
                        List <Item> items = new List <Item>();

                        Item item = new Item()
                        {
                            BoardNo   = boardNo,
                            ProductId = productId,
                            Date      = DateTime.Now.ToShortDateString(),
                            Time      = DateTime.Now.ToShortTimeString(),
                            State     = boardState,
                        };
                        items.Add(item);

                        if (cboCheckTwoPcs.Checked == true)
                        {
                            string boardState2 = GetStateBoardTwo(fileLastWriteTime);
                            Item   item2       = new Item()
                            {
                                BoardNo   = txtBarcode2.Text,
                                ProductId = productId,
                                Date      = DateTime.Now.ToShortDateString(),
                                Time      = DateTime.Now.ToShortTimeString(),
                                State     = boardState2,
                            };

                            items.Add(item2);
                        }

                        dataGridView1.DataSource = items;

                        string strOK = "", strNG = "";

                        foreach (var itemW in items)
                        {
                            Ultils.CreateFileLog(itemW.ProductId, itemW.BoardNo, itemW.State, stationNo, dateCheck);
                            if (itemW.State == "P")
                            {
                                pass   = pass + 1;
                                strOK += $"Board [{itemW.BoardNo}] OK! \n";

                                txtBarcode.Enabled = true;
                                txtBarcode.ResetText();

                                if (cboCheckTwoPcs.Checked == true)
                                {
                                    txtBarcode2.ResetText();
                                    txtBarcode2.Enabled = true;
                                }
                                txtBarcode.Focus();
                            }
                            if (itemW.State == "F")
                            {
                                ng     = ng + 1;
                                strNG += $"Board [{itemW.BoardNo}] NG! \n";
                            }
                        }

                        if (strOK != "")
                        {
                            SuccessMessage("OK", strOK);
                        }

                        if (strNG != "")
                        {
                            ErrorMessage("NG", strNG);
                        }



                        lblReset.Enabled = true;
                        total            = pass + ng;
                        lblPASS.Text     = pass.ToString();
                        lblNG.Text       = ng.ToString();
                        lblTOTAL.Text    = total.ToString();
                    }
                    else
                    {
                        ErrorMessage("NG", $"Sai Model. Vui lòng chọn lại Model cho chính xác!" +
                                     $"\nModel: {ModelName(fileLastWriteTime)}" +
                                     $"\nBoard No: {boardNo}");

                        txtBarcode.Enabled = true;
                        txtBarcode.ResetText();
                        txtBarcode.Focus();
                        checkLength = false;
                        serial      = "";
                    }

                    // TopMode this form
                    ActiveWindows(Text);
                    RunTaks = false;
                }
            }
        }