/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void backgroundWorker1_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e) { while (backgroundWorker1.CancellationPending == false) { Thread.Sleep(500); var allText = GetValueWindowText.GetAllTextFromWindowByTitle(cboWindows.EditValue.ToString()); //var broad_id_first = allText.Split(new[] {"labelControl1"}, 4, StringSplitOptions.None); //var broad_id_last = broad_id_first[1].Split(new[] {"123456789"}, 4, StringSplitOptions.None); // Lấy giá trị serial var broad_id_first = allText.Split(new[] { "S/N" }, 4, StringSplitOptions.None); var broad_id_last = broad_id_first[1].Split(new[] { "NVM " }, 4, StringSplitOptions.None); _result = $"{broad_id_last[0]}"; if (_result.Length > 10) { _workOrderItems = _workOrderItemService.Get_WORK_ORDER_ITEMS_LIKE_BoardNo(_result); if (_workOrderItems != null) { if (!_workOrderItems.IS_FINISHED) { backgroundWorker1.ReportProgress(0, _workOrderItems.BOARD_NO); } } else { backgroundWorker1.ReportProgress(0, _result); } } if (backgroundWorker1.CancellationPending) { backgroundWorker1.ReportProgress(0, null); } } }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void txtBarcode_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e) { if (e.KeyCode == Keys.Enter) { string boardNo = txtBarcode.Text; _dateCheck = Ultils.GetNetworkDateTime().ToString("yyMMddHHmmss") != "" ? Ultils.GetNetworkDateTime().ToString("yyMMddHHmmss") : DateTime.Now.ToString("yyMMddHHmmss"); _timeCheck = Ultils.GetNetworkDateTime().ToShortTimeString() != "" ? Ultils.GetNetworkDateTime().ToShortTimeString() : DateTime.Now.ToShortTimeString(); if (boardNo.Contains("=")) { boardNo = boardNo.Replace("=", "_"); } string setStationNo = gridLookUpEditProcessID.EditValue.ToString(); if (txtBarcode.Text.Length <= 10) { ActiveFormByWindowsTitle(cboWindows.EditValue.ToString()); } else { _scanningLogs = _scanningLogsService.Get_SCANNING_LOGS(boardNo).FirstOrDefault(); if (_scanningLogs != null) { _inspectionProcesses = _inspectionProcessesService.GET_INSPECTION_PROCESSES_BY_PRODUCT_ID(_scanningLogs.PRODUCT_ID); if (_inspectionProcesses != null) { _inspectionProcedureDesigners = _inspectionProcessesDesignersService.GET_INSPECTION_PROCEDURE_DESIGNERS_BY_PROCESS_NO(_inspectionProcesses.PROCESS_NO); //trạng thái bản mạch hiện tại _workOrderItems = _workOrderItemService.Get_WORK_ORDER_ITEMS_By_BoardNo(boardNo); if (_workOrderItems != null) { // nếu đã đã chạy qua các bước, với trạng thái là Finished // thì thông báo cho người dùng biết if (_workOrderItems.IS_FINISHED) { //CancelAsyncBackgroundWorker(); _messageError = $"Board '{boardNo}' is finished!"; MessageHelpers.SetErrorStatus(true, "NG", _messageError, lblStatus, lblMessage); CheckTextBoxNullValue.SetColorErrorTextControl(txtBarcode); Reset(_messageError); } // Kiểm tra nếu trạng thái bản mạch hiện tại bị NG // mà khác với với trạm được cài đặt "FCT" thì thông báo lỗi else if (_workOrderItems.STATION_NO != setStationNo && _workOrderItems.BOARD_STATE == 2) { //CancelAsyncBackgroundWorker(); var stationName = _inspectionProcedureDesigners.FirstOrDefault(item => item.INDEX == _workOrderItems.PROCEDURE_INDEX); if (stationName != null) _messageError = $"Board '{boardNo}' bị 'NG' tại trạm trước {stationName.STATION_NO}!"; MessageHelpers.SetErrorStatus(true, "NG", _messageError, lblStatus, lblMessage); CheckTextBoxNullValue.SetColorErrorTextControl(txtBarcode); Reset(_messageError); } // Nếu tên giống nhau, thì thông báo đã chạy qua công đoạn này rồi else if (_workOrderItems.STATION_NO == setStationNo && _workOrderItems.BOARD_STATE == 1) { Excute(boardNo, _scanningLogs.PRODUCT_ID); } else { // Set station no var processByStationNo = _inspectionProcedureDesigners.FirstOrDefault(item => item.STATION_NO == setStationNo); // Nếu trong process_Designer không có STATION_NO giống với // station_no curent thì thông báo cho người dùng biết if (processByStationNo == null) { //CancelAsyncBackgroundWorker(); _messageError = $"Board '{boardNo}' station '{setStationNo}' not invaild!"; MessageHelpers.SetErrorStatus(true, "NG", _messageError, lblStatus, lblMessage); CheckTextBoxNullValue.SetColorErrorTextControl(txtBarcode); Reset(_messageError); } // nếu hợp lệ thực hiện tiếp else { // Khi hai giá trị bằng nhau => ICT_FUJ if (_workOrderItems.PROCEDURE_INDEX < (processByStationNo.INDEX - 1)) { //CancelAsyncBackgroundWorker(); var stationName = _inspectionProcedureDesigners.FirstOrDefault(item => item.INDEX == _workOrderItems.PROCEDURE_INDEX); if (stationName != null) _messageError = $"Board '{boardNo}' bỏ qua công đoạn '{stationName.STATION_NO}'!"; MessageHelpers.SetErrorStatus(true, "NG", _messageError, lblStatus, lblMessage); CheckTextBoxNullValue.SetColorErrorTextControl(txtBarcode); Reset(_messageError); //Excute(boardNo, _scanningLogs.PRODUCT_ID); } //// Nếu Index Board > Set Index else if (_workOrderItems.PROCEDURE_INDEX > processByStationNo.INDEX) { //CancelAsyncBackgroundWorker(); // transferred to the next station. var stationName = _inspectionProcedureDesigners.FirstOrDefault(item => item.INDEX == _workOrderItems.PROCEDURE_INDEX); if (stationName != null) _messageError = $"Board '{boardNo}' chuyển đến trạm '{stationName.STATION_NO}' để chạy tiếp!"; MessageHelpers.SetErrorStatus(true, "NG", _messageError, lblStatus, lblMessage); CheckTextBoxNullValue.SetColorErrorTextControl(txtBarcode); Reset(_messageError); } else if (_workOrderItems.PROCEDURE_INDEX == (processByStationNo.INDEX - 1)) { Excute(boardNo, _scanningLogs.PRODUCT_ID); } else if (_workOrderItems.BOARD_STATE == 2) { Excute(boardNo, _scanningLogs.PRODUCT_ID); } } } } else { //CancelAsyncBackgroundWorker(); _messageError = $"Không tìm thấy trạm với tên {setStationNo}!"; MessageHelpers.SetErrorStatus(true, "NG", _messageError, lblStatus, lblMessage); CheckTextBoxNullValue.SetColorErrorTextControl(txtBarcode); Reset(_messageError); } } else { //CancelAsyncBackgroundWorker(); _messageError = $"Station No '{setStationNo}' không hợp lệ!"; MessageHelpers.SetErrorStatus(true, "NG", _messageError, lblStatus, lblMessage); CheckTextBoxNullValue.SetColorErrorTextControl(txtBarcode); Reset(_messageError); } } else { //CancelAsyncBackgroundWorker(); _messageError = $"Board '{boardNo}' chưa được khởi tạo. Vui lòng kiểm tra lại!"; MessageHelpers.SetErrorStatus(true, "NG", _messageError, lblStatus, lblMessage); CheckTextBoxNullValue.SetColorErrorTextControl(txtBarcode); Reset(_messageError); } } } }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void backgroundWorker1_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e) { while (backgroundWorker1.CancellationPending == false) { Thread.Sleep(2000); var allText = GetValueWindowText.GetAllTextFromWindowByTitle(cboWindows.EditValue.ToString()); //string allText = "10.751427478测试完成87.3OK2016/11/2 9:52:39X6AQ0683QYT2_960K 87372 K001DADF 960K87372"; var broad_id_first = allText.Split(new[] { "_" }, 4, StringSplitOptions.None); //var broad_id_first = allText.Split(new[] { "labelControl1" }, 4, StringSplitOptions.None); //var broad_id_last = broad_id_first[1].Split(new[] { "123456789" }, 4, StringSplitOptions.None); // Lấy giá trị serial //var broad_id_first = allText.Split(new[] { "S/N" }, 4, StringSplitOptions.None); //var broad_id_last = broad_id_first[1].Split(new[] { "NVM " }, 4, StringSplitOptions.None); _result = $"{ broad_id_first[0].Substring(broad_id_first[0].Length-12)}_{broad_id_first[1].Substring(0, 14)}"; //_result = broad_id_last[0].ToString(); if (_result.Length > 23) { _workOrderItems = _workOrderItemService.Get_WORK_ORDER_ITEMS_LIKE_BoardNo(_result); if (_workOrderItems != null) { if (!_workOrderItems.IS_FINISHED) { backgroundWorker1.ReportProgress(0, _workOrderItems.BOARD_NO); } else { SetStatusDefault("OK"); SetMessageDefault("Broad is finished."); } } else { backgroundWorker1.ReportProgress(0, _result); } } } }