private void txtBarcode_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e) { if (e.KeyCode == Keys.Enter) { string boardNo = txtBarcode.Text; dateCheck = Ultils.GetNetworkDateTime().ToString("yyMMddHHmmss"); if (boardNo.Contains("=")) { boardNo = boardNo.Replace("=", "_"); } string set_station_no = gridLookUpEditProcessID.EditValue.ToString(); if (!CheckTextBoxNullValue.ValidationTextEditNullValue(txtBarcode)) { MessageHelpers.SetErrorStatus(true, "NG", "Please input a barcode!", lblStatus, lblMessage); return; } else if (txtBarcode.Text.Length <= 5) { MessageHelpers.SetErrorStatus(true, "NG", "Board No invaild. Please try again!", lblStatus, lblMessage); CheckTextBoxNullValue.SetColorErrorTextControl(txtBarcode); return; } else { MessageHelpers.SetDefaultStatus(true, "N/A", "N/A", lblStatus, lblMessage); CheckTextBoxNullValue.SetColorDefaultTextControl(txtBarcode); var boards = _scanningLogsService.Get_SCANNING_LOGS(boardNo).FirstOrDefault(); if (boards != null) { var process_No = _inspectionProcessesService.GET_INSPECTION_PROCESSES_BY_PRODUCT_ID(boards.PRODUCT_ID); if (process_No != null) { // //trạng thái bản mạch hiện tại var curentStationNo = _workOrderItemService.Get_WORK_ORDER_ITEMS_By_BoardNo(boardNo); if (curentStationNo != 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 (curentStationNo.IS_FINISHED == true) { messageError = $"Board '{boardNo}' is finished!"; MessageHelpers.SetErrorStatus(true, "NG", messageError, lblStatus, lblMessage); CheckTextBoxNullValue.SetColorErrorTextControl(txtBarcode); var errorForm = new FormError(messageError); errorForm.ShowDialog(); txtBarcode.Focus(); return; } // 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 (curentStationNo.STATION_NO != set_station_no && curentStationNo.BOARD_STATE == 2) { messageError = $"Board '{boardNo}' bị 'NG' tại trạm '{set_station_no}'!"; MessageHelpers.SetErrorStatus(true, "NG", messageError, lblStatus, lblMessage); CheckTextBoxNullValue.SetColorErrorTextControl(txtBarcode); var errorForm = new FormError(messageError); errorForm.ShowDialog(); txtBarcode.Focus(); return; } // 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 (curentStationNo.STATION_NO == set_station_no && curentStationNo.BOARD_STATE == 1) { messageError = $"Board '{boardNo}' is pass '{set_station_no}'!"; MessageHelpers.SetErrorStatus(true, "NG", messageError, lblStatus, lblMessage); CheckTextBoxNullValue.SetColorErrorTextControl(txtBarcode); var errorForm = new FormError(messageError); errorForm.ShowDialog(); txtBarcode.Focus(); return; } else { var process_Designer = _inspectionProcessesDesignersService.GET_INSPECTION_PROCEDURE_DESIGNERS_BY_PROCESS_NO(process_No.PROCESS_NO); // Set station no var process_by_station_no = process_Designer.FirstOrDefault(item => item.STATION_NO == set_station_no); // 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 (process_by_station_no == null) { messageError = $"Board '{boardNo}' station '{set_station_no}' not invaild!"; MessageHelpers.SetErrorStatus(true, "NG", messageError, lblStatus, lblMessage); CheckTextBoxNullValue.SetColorErrorTextControl(txtBarcode); var errorForm = new FormError(messageError); errorForm.ShowDialog(); txtBarcode.Focus(); return; } // nếu hợp lệ thực hiện tiếp else { // Khi hai giá trị bằng nhau => ICT_FUJ if (curentStationNo.PROCEDURE_INDEX < (process_by_station_no.INDEX - 1)) { messageError = $"Board '{boardNo}' skip stations!"; MessageHelpers.SetErrorStatus(true, "NG", messageError, lblStatus, lblMessage); CheckTextBoxNullValue.SetColorErrorTextControl(txtBarcode); var errorForm = new FormError(messageError); errorForm.ShowDialog(); txtBarcode.Focus(); return; } //// Nếu Index Board > Set Index else if (curentStationNo.PROCEDURE_INDEX > process_by_station_no.INDEX) { // transferred to the next station. messageError = $"Board '{boardNo}' transferred to the next station!"; MessageHelpers.SetErrorStatus(true, "NG", messageError, lblStatus, lblMessage); CheckTextBoxNullValue.SetColorErrorTextControl(txtBarcode); var errorForm = new FormError(messageError); errorForm.ShowDialog(); txtBarcode.Focus(); return; } else if (curentStationNo.PROCEDURE_INDEX == (process_by_station_no.INDEX - 1)) { //Ultils.SuspendOrResumeCurentProcess(cboWindows.Text, false); this.TopMost = false; txtBarcode.ResetText(); txtBarcode.Focus(); productionId = boardNo; modelId = boards.PRODUCT_ID; MessageHelpers.SetSuccessStatus(true, "OK", $"Board '{boardNo}' OK!", lblStatus, lblMessage); // Thực hiện gửi dữ liệu đi int iHandle = NativeWin32.FindWindow(null, cboWindows.Text); NativeWin32.SetForegroundWindow(iHandle); SendKeys.Send(boardNo); SendKeys.Send("{ENTER}"); if (checkEditSerialPort.Checked == true) { // Start machine FCT Check Thread.Sleep(200); com.WriteData("S"); } } else if (curentStationNo.BOARD_STATE == 2) { this.TopMost = false; txtBarcode.ResetText(); txtBarcode.Focus(); productionId = boardNo; modelId = boards.PRODUCT_ID; MessageHelpers.SetSuccessStatus(true, "OK", $"Board '{boardNo}' OK!", lblStatus, lblMessage); // Thực hiện gửi dữ liệu đi int iHandle = NativeWin32.FindWindow(null, cboWindows.Text); NativeWin32.SetForegroundWindow(iHandle); SendKeys.Send(boardNo); SendKeys.Send("{ENTER}"); if (checkEditSerialPort.Checked == true) { // Start machine FCT Check Thread.Sleep(200); com.WriteData("S"); } } } } } else { messageError = $"Station No '{curentStationNo.STATION_NO}' not found!"; MessageHelpers.SetErrorStatus(true, "NG", messageError, lblStatus, lblMessage); CheckTextBoxNullValue.SetColorErrorTextControl(txtBarcode); var errorForm = new FormError(messageError); errorForm.ShowDialog(); txtBarcode.Focus(); return; } } else { messageError = $"Station No '{set_station_no}' invaild!"; MessageHelpers.SetErrorStatus(true, "NG", messageError, lblStatus, lblMessage); CheckTextBoxNullValue.SetColorErrorTextControl(txtBarcode); var errorForm = new FormError(messageError); errorForm.ShowDialog(); txtBarcode.Focus(); return; } } else { messageError = $"Board '{boardNo}' not initialized!"; MessageHelpers.SetErrorStatus(true, "NG", messageError, lblStatus, lblMessage); CheckTextBoxNullValue.SetColorErrorTextControl(txtBarcode); var errorForm = new FormError(messageError); errorForm.ShowDialog(); return; } } } }
private void txtBarcode_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e) { if (e.KeyCode == Keys.Enter) { string boardNo = txtBarcode.Text; dateCheck = Ultils.GetNetworkDateTime().ToString("yyMMddHHmmss"); if (boardNo.Contains("=")) { boardNo = boardNo.Replace("=", "_"); } string set_station_no = gridLookUpEditProcessID.EditValue.ToString(); if (!CheckTextBoxNullValue.ValidationTextEditNullValue(txtBarcode)) { MessageHelpers.SetErrorStatus(true, "NG", "Please input a barcode!", lblStatus, lblMessage); return; } else if (txtBarcode.Text.Length <= 5) { MessageHelpers.SetErrorStatus(true, "NG", "Board No invaild. Please try again!", lblStatus, lblMessage); CheckTextBoxNullValue.SetColorErrorTextControl(txtBarcode); return; } else { MessageHelpers.SetDefaultStatus(true, "N/A", "N/A", lblStatus, lblMessage); CheckTextBoxNullValue.SetColorDefaultTextControl(txtBarcode); var boards = _scanningLogsService.Get_SCANNING_LOGS(boardNo).FirstOrDefault(); if (boards != null) { var process_No = _inspectionProcessesService.GET_INSPECTION_PROCESSES_BY_PRODUCT_ID(boards.PRODUCT_ID); if (process_No != null) { // //trạng thái bản mạch hiện tại var curentStationNo = _workOrderItemService.Get_WORK_ORDER_ITEMS_By_BoardNo(boardNo); if (curentStationNo != 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 (curentStationNo.IS_FINISHED == true) { messageError = $"Board '{boardNo}' is finished!"; MessageHelpers.SetErrorStatus(true, "NG", messageError, lblStatus, lblMessage); CheckTextBoxNullValue.SetColorErrorTextControl(txtBarcode); var errorForm = new FormError(messageError); errorForm.ShowDialog(); txtBarcode.Focus(); return; } // 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 (curentStationNo.STATION_NO != set_station_no && curentStationNo.BOARD_STATE == 2) { messageError = $"Board '{boardNo}' bị 'NG' tại trạm '{set_station_no}'!"; MessageHelpers.SetErrorStatus(true, "NG", messageError, lblStatus, lblMessage); CheckTextBoxNullValue.SetColorErrorTextControl(txtBarcode); var errorForm = new FormError(messageError); errorForm.ShowDialog(); txtBarcode.Focus(); return; } // 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 (curentStationNo.STATION_NO == set_station_no && curentStationNo.BOARD_STATE == 1) { messageError = $"Board '{boardNo}' is pass '{set_station_no}'!"; MessageHelpers.SetErrorStatus(true, "NG", messageError, lblStatus, lblMessage); CheckTextBoxNullValue.SetColorErrorTextControl(txtBarcode); var errorForm = new FormError(messageError); errorForm.ShowDialog(); txtBarcode.Focus(); return; } else { var process_Designer = _inspectionProcessesDesignersService.GET_INSPECTION_PROCEDURE_DESIGNERS_BY_PROCESS_NO(process_No.PROCESS_NO); // Set station no var process_by_station_no = process_Designer.FirstOrDefault(item => item.STATION_NO == set_station_no); // 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 (process_by_station_no == null) { messageError = $"Board '{boardNo}' station '{set_station_no}' not invaild!"; MessageHelpers.SetErrorStatus(true, "NG", messageError, lblStatus, lblMessage); CheckTextBoxNullValue.SetColorErrorTextControl(txtBarcode); var errorForm = new FormError(messageError); errorForm.ShowDialog(); txtBarcode.Focus(); return; } // nếu hợp lệ thực hiện tiếp else { // Khi hai giá trị bằng nhau => ICT_FUJ if (curentStationNo.PROCEDURE_INDEX < (process_by_station_no.INDEX - 1)) { messageError = $"Board '{boardNo}' skip stations!"; MessageHelpers.SetErrorStatus(true, "NG", messageError, lblStatus, lblMessage); CheckTextBoxNullValue.SetColorErrorTextControl(txtBarcode); var errorForm = new FormError(messageError); errorForm.ShowDialog(); txtBarcode.Focus(); return; } //// Nếu Index Board > Set Index else if (curentStationNo.PROCEDURE_INDEX > process_by_station_no.INDEX) { // transferred to the next station. messageError = $"Board '{boardNo}' transferred to the next station!"; MessageHelpers.SetErrorStatus(true, "NG", messageError, lblStatus, lblMessage); CheckTextBoxNullValue.SetColorErrorTextControl(txtBarcode); var errorForm = new FormError(messageError); errorForm.ShowDialog(); txtBarcode.Focus(); return; } else if (curentStationNo.PROCEDURE_INDEX == (process_by_station_no.INDEX - 1)) { //Ultils.SuspendOrResumeCurentProcess(cboWindows.Text, false); this.TopMost = false; txtBarcode.ResetText(); txtBarcode.Focus(); productionId = boardNo; modelId = boards.PRODUCT_ID; MessageHelpers.SetSuccessStatus(true, "OK", $"Board '{boardNo}' OK!", lblStatus, lblMessage); // Thực hiện gửi dữ liệu đi int iHandle = NativeWin32.FindWindow(null, cboWindows.Text); NativeWin32.SetForegroundWindow(iHandle); SendKeys.Send(boardNo); SendKeys.Send("{ENTER}"); if (checkEditSerialPort.Checked == true) { // Start machine FCT Check Thread.Sleep(200); com.WriteData("S"); } } else if(curentStationNo.BOARD_STATE == 2) { this.TopMost = false; txtBarcode.ResetText(); txtBarcode.Focus(); productionId = boardNo; modelId = boards.PRODUCT_ID; MessageHelpers.SetSuccessStatus(true, "OK", $"Board '{boardNo}' OK!", lblStatus, lblMessage); // Thực hiện gửi dữ liệu đi int iHandle = NativeWin32.FindWindow(null, cboWindows.Text); NativeWin32.SetForegroundWindow(iHandle); SendKeys.Send(boardNo); SendKeys.Send("{ENTER}"); if (checkEditSerialPort.Checked == true) { // Start machine FCT Check Thread.Sleep(200); com.WriteData("S"); } } } } } else { messageError = $"Station No '{curentStationNo.STATION_NO}' not found!"; MessageHelpers.SetErrorStatus(true, "NG", messageError, lblStatus, lblMessage); CheckTextBoxNullValue.SetColorErrorTextControl(txtBarcode); var errorForm = new FormError(messageError); errorForm.ShowDialog(); txtBarcode.Focus(); return; } } else { messageError = $"Station No '{set_station_no}' invaild!"; MessageHelpers.SetErrorStatus(true, "NG", messageError, lblStatus, lblMessage); CheckTextBoxNullValue.SetColorErrorTextControl(txtBarcode); var errorForm = new FormError(messageError); errorForm.ShowDialog(); txtBarcode.Focus(); return; } } else { messageError = $"Board '{boardNo}' not initialized!"; MessageHelpers.SetErrorStatus(true, "NG", messageError, lblStatus, lblMessage); CheckTextBoxNullValue.SetColorErrorTextControl(txtBarcode); var errorForm = new FormError(messageError); errorForm.ShowDialog(); return; } } } }