private void MainForm_Load(object sender, EventArgs e) { string path = Environment.CurrentDirectory + "\\Data.db"; DbHelper.LoadDb(path); DataValidation.IsProtocol = true; DataValidation.ProtocolHead = 2; DataValidation.ProtocolEnd = 3; DataValidation.IsValidation = true; _mPort = new PortHelper { PortIsOpenChange = PortOpenOrCloseChange, PortDataReceived = PortDataReceived }; _myMutex = new Mutex(); _comPort = new ComPortHelper(); _comPort.CountChange += ComPortChange; _comPort.Start(); _rect = new Rectangle(p_ComPort.Width / 2 - 20, p_ComPort.Height - 14, 40, 14); _mNumber = DbHelper.Db.FirstDefault <ModuleNumber>() ?? new ModuleNumber() { Number = 1 }; tb_ID.Text = _mNumber.Number.ToString(); }
private void MainForm_Shown(object sender, EventArgs e) { _m_Port = new PortHelper(); _m_Port.PortDataReceived = OnPortDataReceived; _m_Port.PortIsOpenChange = OnPortOpenAndCloseChange; _m_ComPort = new ComPortHelper(); _m_ComPort.CountChange += _m_ComPort_CountChange; _m_ComPort.Start(); dgv_CustomerList.Focus(); }
public frmWBReturnDetIn(BaseEntities db, int?PosId, WaybillList wb, int?wid, DateTime start_date) { InitializeComponent(); _db = db; _PosId = PosId; _wb = wb; _def_wid = wid; _start_date = start_date; WHComboBox.Properties.DataSource = DBHelper.WhList; com_port = new ComPortHelper(Settings.Default.com_port_name, Convert.ToInt32(Settings.Default.com_port_speed)); }
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e) { MessageBoxResult result = MessageBox.Show("Đóng Chương Trình?", "Storing - System", MessageBoxButton.YesNo, MessageBoxImage.Question); if (result == MessageBoxResult.Yes) { serialPortReceive.Close(); ComPortHelper.WriteToPort(portWrite, "DIO[0]:VALUE=0\r\n"); ComPortHelper.WriteToPort(portWrite, "DIO[3]:VALUE=0\r\n"); } else { e.Cancel = true; } }
public frmWeightEdit(String MatName, int weigher_index = 1) { InitializeComponent(); AmountEdit.EditValue = 0; PriceEdit.EditValue = 0; if (weigher_index == 1) { com_port = new ComPortHelper(Settings.Default.com_port_name, Convert.ToInt32(Settings.Default.com_port_speed)); } else if (weigher_index == 2) { com_port = new ComPortHelper(Settings.Default.com_port_name_2, Convert.ToInt32(Settings.Default.com_port_speed_2)); } Text = MatName; }
private void btnBarcodeComplete_Click(object sender, RoutedEventArgs e) { ClearValue(); barcode = txtBarCodeComplete.Text.Trim(); storingPerBarcode = storingList.Where(w => w.Barcode == barcode).FirstOrDefault(); if (storingPerBarcode == null) { MessageBox.Show("Thùng chưa được cân ở INPUT !", "Infor", MessageBoxButton.OK, MessageBoxImage.Information); HighLightTextblock(txtBarCodeComplete, btnBarcodeComplete); return; } outputingPerBarcode = outputingCurrentList.Where(w => w.Outputing.Barcode == barcode && w.Outputing.IsPass == true).Select(s => s.Outputing).FirstOrDefault(); if (outputingPerBarcode != null) { MessageBox.Show("Thùng đã được cân !", "Infor", MessageBoxButton.OK, MessageBoxImage.Information); HighLightTextblock(txtBarCodeComplete, btnBarcodeComplete); return; } NoneHighLightTextblock(txtBarCodeComplete); tblProductNo.Text = storingPerBarcode.ProductNo; tblSizeItemQuantityCartonNo.Text = string.Format("Size: {0}\nCartonNo: {1}", storingPerBarcode.SizeNo, storingPerBarcode.CartonNo); serialPortReceive.Close(); ComPortHelper.WriteToPort(portWrite, "DIO[0]:VALUE=0\r\n"); ComPortHelper.WriteToPort(portWrite, "DIO[3]:VALUE=0\r\n"); if (double.TryParse(txtMinActualWeight.Text, out minActualWeight) == false) { txtMinActualWeight.BorderBrush = Brushes.Red; } else { txtMinActualWeight.ClearValue(TextBox.BorderBrushProperty); } if (double.TryParse(txtMaxActualWeight.Text, out maxActualWeight) == false) { txtMaxActualWeight.BorderBrush = Brushes.Red; } else { txtMaxActualWeight.ClearValue(TextBox.BorderBrushProperty); } serialPortReceive.Open(); }
private void Refresh() { Task.Factory.StartNew(() => { Thread.Sleep(300); // small delay for progress bar to be displayed Application.Current.Dispatcher.Invoke(() => IsRefreshing = true); var ports = ComPortHelper.GetCOMPortsInfo(); //Thread.Sleep(3000); Application.Current.Dispatcher.Invoke(() => { ComPorts = ports; IsRefreshing = false; OnPropertyChanged("ComPorts"); }); }); }
private void BarcodeProcess() { serialPortReceive.Close(); firstCarton_Size_PO = new StoringModel(); ComPortHelper.WriteToPort(portWrite, "DIO[0]:VALUE=0\r\n"); ComPortHelper.WriteToPort(portWrite, "DIO[3]:VALUE=0\r\n"); if (double.TryParse(txtMinActualWeight.Text, out minActualWeight) == false) { txtMinActualWeight.BorderBrush = Brushes.Red; } else { txtMinActualWeight.ClearValue(TextBox.BorderBrushProperty); } if (double.TryParse(txtMaxActualWeight.Text, out maxActualWeight) == false) { txtMaxActualWeight.BorderBrush = Brushes.Red; } else { txtMaxActualWeight.ClearValue(TextBox.BorderBrushProperty); } tblProductNo.Text = productNo; tblSizeItemQuantityCartonNo.Text = String.Format("Size: {0}\nCartonNo: {1} of {2}", sizeNo, cartonNo, GetMaxCarton(productNo)); // check first carton of size of productno if (completeCarton == true) { var storingCurrent_POList = storingCurrentList.Where(w => w.StoringModel.ProductNo == productNo).Select(s => s.StoringModel).ToList(); firstCarton_Size_PO = storingCurrent_POList.Where(w => w.SizeNo == sizeNo && w.IsPass == true && w.IsComplete == true).FirstOrDefault(); var firstCartonProblem = new StoringModel() { ProductNo = productNo, Barcode = barcode, SizeNo = sizeNo, CartonNo = cartonNo, WorkerId = account.UserName, ActualWeight = 0, GrossWeight = 0, DifferencePercent = 0, IsComplete = true }; if (firstCarton_Size_PO == null) { MessageBoxResult result = MessageBox.Show(string.Format("Đây Là Thùng Đầu Tiên Của Size: {0} ; PO#: {1}\n\nMở Thùng Và Kiểm Tra\n- SỐ LƯỢNG GIÀY\n- SIZE.\n\nClick OK để CÂN và tiếp tục, Nếu có vấn đề Click Cancel! ", sizeNo, productNo), "Kiểm tra thùng đầu tiên của Size", MessageBoxButton.OKCancel, MessageBoxImage.Warning); if (result == MessageBoxResult.OK) { serialPortReceive.Open(); insertFirstCarton_Size_PO = true; } if (result == MessageBoxResult.Cancel) { Dispatcher.Invoke(new Action(() => { CheckIssuesWindow window = new CheckIssuesWindow(null, firstCartonProblem, IssuesType.Issues.IssuesFirstCartonOfSizeOfPO, factory); window.ShowDialog(); StoringModel storingRecieve = window.storingCurrent; StoringCurrent storingCurrent = new StoringCurrent(); storingCurrent.StoringModel = storingRecieve; storingCurrentList.Add(storingCurrent); })); } } else { serialPortReceive.Open(); compareCartonSameSize = true; } } else { serialPortReceive.Open(); insertIncompleteCarton = true; } popInputSubPO.IsOpen = false; btnBarcodeComplete.IsEnabled = false; btnCartonNo.IsEnabled = false; }
private ResponseExecCommand GetResponse(string buffer, IEnumerable <ResponseCode> responses) { if (buffer.Contains("\r\n>\r\n") || buffer.Contains("\r\n> ")) { if (responses.Any(r => r == ResponseCode.SMS_TEXT)) { return(new ResponseExecCommand(ResponseCode.SMS_TEXT, buffer)); } } else if (buffer.Contains("\r\nRING\r\n")) { if (responses.Any(r => r == ResponseCode.RING)) { return(new ResponseExecCommand(ResponseCode.RING, buffer)); } } else if (buffer.Contains("\r\nCONNECT\r\n")) { if (responses.Any(r => r == ResponseCode.CONNECT)) { return(new ResponseExecCommand(ResponseCode.CONNECT, buffer)); } } else if (buffer.Contains("\r\nNO CARRIER\r\n")) { if (responses.Any(r => r == ResponseCode.NO_CARRIER)) { return(new ResponseExecCommand(ResponseCode.NO_CARRIER, buffer)); } } else if (buffer.Contains("\r\nBUSY\r\n")) { if (responses.Any(r => r == ResponseCode.BUSY)) { return(new ResponseExecCommand(ResponseCode.BUSY, buffer)); } } else if (buffer.Contains("\r\nNO ANSWER\r\n")) { if (responses.Any(r => r == ResponseCode.NO_ANSWER)) { return(new ResponseExecCommand(ResponseCode.NO_ANSWER, buffer)); } } else if (buffer.Contains("\r\nBLACKLISTED\r\n")) { if (responses.Any(r => r == ResponseCode.BLACKLISTED)) { return(new ResponseExecCommand(ResponseCode.BLACKLISTED, buffer)); } } else if (_regexSms.Match(buffer).Success) { if (responses.Any(r => r == ResponseCode.SMS)) { return(new ResponseExecCommand(ResponseCode.SMS, buffer)); } } else if (_regexCend.Match(buffer).Success) { var match = _regexCend.Match(buffer); Logger.Write(String.Format(ResourceManagerProvider.GetLocalizedString("MSG_COMMAND_RESPONSE_CODE_CEND", Application.CurrentCulture), match.Groups["Cause"].Value)); var res = ComPortHelper.ConvertCENDResponseCode(Int32.Parse(match.Groups["Cause"].Value)); if (responses.Any(r => r == res)) { return(new ResponseExecCommand(res, buffer)); } } else if (_regexCpas.Match(buffer).Success) { var match = _regexCpas.Match(buffer); Logger.Write(String.Format(ResourceManagerProvider.GetLocalizedString("MSG_COMMAND_RESPONSE_CODE_CPAS", Application.CurrentCulture), match.Groups["Stat"].Value)); var res = ComPortHelper.ConvertCPASToResponseCode(Int32.Parse(match.Groups["Stat"].Value)); if (responses.Any(r => r == res)) { return(new ResponseExecCommand(res, buffer)); } } else if (_regexClcc.Match(buffer).Success) { var match = _regexClcc.Match(buffer); Logger.Write(String.Format(ResourceManagerProvider.GetLocalizedString("MSG_COMMAND_RESPONSE_CODE_CLCC", Application.CurrentCulture), match.Groups["Dir"].Value + ";" + match.Groups["Stat"].Value)); var res = ComPortHelper.ConvertCLCCToResponseCode(Int32.Parse(match.Groups["Dir"].Value), Int32.Parse(match.Groups["Stat"].Value), match.Groups["Cause"].Value.ToNullableInt()); if (responses.Any(r => r == res)) { return(new ResponseExecCommand(res, buffer)); } } else if (buffer.Contains("\r\nERROR\r\n") || buffer.Contains("+CMS ERROR:") || buffer.Contains("+CME ERROR:")) //+CME ERROR: 513 { if (responses.Any(r => r == ResponseCode.ERROR)) { return(new ResponseExecCommand(ResponseCode.ERROR, buffer)); } } else if (buffer.Contains("\r\nOK\r\n")) // Should be at last { if (responses.Any(r => r == ResponseCode.OK)) { return(new ResponseExecCommand(ResponseCode.OK, buffer)); } } return(null); }