Esempio n. 1
0
        private void tbxBarcode_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == terminator)
            {
                var barcoderReceivedEventArgs = new BarcodeReaderReceivedEventArgs();

                barcoderReceivedEventArgs.Barcode = tbxBarcode.Text.TrimEnd(terminator);

                try
                {
                    if (regex != null && !regex.IsMatch(barcoderReceivedEventArgs.Barcode))
                    {
                        barcoderReceivedEventArgs.Barcode = BarcodeConst.ErrorBarcode;
                    }
                }
                catch
                {
                    barcoderReceivedEventArgs.Barcode = BarcodeConst.ErrorBarcode;
                }

                OnBarcoderReceived(this, barcoderReceivedEventArgs);

                if (barcoderReceivedEventArgs.ConfirmResult == ConfirmResult.OK)
                {
                    barcodes.Add(barcoderReceivedEventArgs.Barcode);
                }

                if (barcoderReceivedEventArgs.ConfirmResult == ConfirmResult.NG)
                {
                    MessageBoxWrapper.ShowDialog(this, $"条码校验出错,错误信息:“{barcoderReceivedEventArgs.ConfirmMessage  }”,请确认!", MessageCaption.Information, MessageBoxButtons.OK);
                }

                tbxBarcode.Text = string.Empty;
            }
        }
Esempio n. 2
0
        public MainForm(PlcManualSimulator plc) : this()
        {
            plc.Readindg += Plc_Reading;
            plc.Writing  += Plc_Writing;

            dgvRead.CellClick += (s, e) =>
            {
                try
                {
                    if (e.RowIndex >= 0 && e.ColumnIndex >= 0)
                    {
                        var row = dgvRead.Rows[e.RowIndex];
                        var readindgEventArgs = row.Tag as ReadindgEventArgs;

                        if (dgvRead[e.ColumnIndex, e.RowIndex].Value.Equals("发送"))
                        {
                            var values = row.Cells[2].Value.ToString().Split(new char[] { ',', ',' }, StringSplitOptions.RemoveEmptyEntries);

                            readindgEventArgs.Result.Clear();

                            foreach (var value in values)
                            {
                                switch (readindgEventArgs.Address.Type)
                                {
                                case DataAddressType.Boolean:
                                {
                                    readindgEventArgs.Result.Add(value == "1");
                                }
                                break;

                                case DataAddressType.Short:
                                {
                                    readindgEventArgs.Result.Add(short.Parse(value));
                                }
                                break;

                                case DataAddressType.Ushort:
                                {
                                    readindgEventArgs.Result.Add(ushort.Parse(value));
                                }
                                break;

                                case DataAddressType.Int:
                                {
                                    readindgEventArgs.Result.Add(int.Parse(value));
                                }
                                break;

                                case DataAddressType.Float:
                                {
                                    readindgEventArgs.Result.Add(float.Parse(value));
                                }
                                break;

                                case DataAddressType.String:
                                {
                                    readindgEventArgs.Result.Add(value);
                                }
                                break;

                                default: throw new NotImplementedException();
                                }
                            }

                            if (readindgEventArgs.Address.Type == DataAddressType.Boolean)
                            {
                                if (readindgEventArgs.Result.Count != 1)
                                {
                                    throw new ApplicationException("请重新输入,输入元素数须唯一");
                                }
                            }
                            else if (readindgEventArgs.Address.Type == DataAddressType.String)
                            {
                                if (readindgEventArgs.Result.Count != 1)
                                {
                                    throw new ApplicationException("请重新输入,输入元素数须唯一");
                                }
                            }
                            else
                            {
                                if (readindgEventArgs.Result.Count != readindgEventArgs.Address.Offset + 1)
                                {
                                    throw new ApplicationException($"请重新输入,输入元素数有误,当前元素数为:{readindgEventArgs.Result.Count}");
                                }
                            }

                            dgvRead.Rows.Remove(row);

                            readindgEventArgs.ManualResetEvent.Set();
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBoxWrapper.ShowDialog(this, ex.Message, MessageCaption.Information, MessageBoxButtons.OK);
                }
            };
        }