private bool WriteLotId(string tagId, string lotId)
        {
            lotId = lotId.Trim().ToUpper();

            if ((tagId.Length == 10) && (tagId.StartsWith("30")) && (_myRegexUid.IsMatch(tagId)))
            {
                MessageBox.Show(ResStrings.str_Tag_not_compatible_for_writing, ResStrings.strInfo, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return(false);
            }

            if (!SDK_SC_RfidReader.DeviceBase.SerialRFID.isStringValidToWrite(lotId))
            {
                MessageBox.Show(ResStrings.str_Tag_Invalid_Tag_ID, ResStrings.strInfo, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return(false);
            }

            WriteCode codeResult = WriteCode.WC_Error;

            if (_currentEthernetDevice == null) // (USB) local reader
            {
                if ((_device.ConnectionStatus == ConnectionStatus.CS_Connected) && (_device.DeviceStatus == DeviceStatus.DS_Ready))
                {
                    codeResult = _device.WriteNewUID(tagId, lotId);
                }

                else
                {
                    MessageBox.Show(ResStrings.str_device_not_ready, ResStrings.strInfo, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }

            else
            {
                TcpIpClient tcpClient = new TcpIpClient();
                tcpClient.RequestWriteBlock(_currentEthernetDevice.IP_Server, _currentEthernetDevice.Port_Server, tagId, lotId, out codeResult);
            }


            switch (codeResult)
            {
            case WriteCode.WC_Error:
                MessageBox.Show(ResStrings.strWriteStatusUnexpectedError);
                break;

            case WriteCode.WC_TagNotDetected:
                MessageBox.Show(ResStrings.strWriteStatusOperation_failed);
                break;

            case WriteCode.WC_TagNotConfirmed:
                MessageBox.Show(ResStrings.strWriteStatus_Tag_not_confirmed);
                break;

            case WriteCode.WC_TagBlockedOrNotSupplied:
                MessageBox.Show(ResStrings.strWriteStatus_Tag_blocked_or_not_well_supplied);
                break;

            case WriteCode.WC_TagBlocked:
                MessageBox.Show(ResStrings.strWriteStatus_Tag_blocked);
                break;

            case WriteCode.WC_TagNotSupplied:
                MessageBox.Show(ResStrings.strWriteStatus_Tag_not_well_supplied);
                break;

            case WriteCode.WC_ConfirmationFailed:
                MessageBox.Show(ResStrings.strWriteStatus_Updated_tag_confirmation_has_failed);
                return(true);

            case WriteCode.WC_Success:
            {
                string initialUid = _db.GetInitialUID(tagId);
                _db.AddUidHistory(string.IsNullOrEmpty(initialUid) ? tagId : initialUid, lotId);
            }
                return(true);
            }

            return(false);
        }
Пример #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            WriteCode codeResult = WriteCode.WC_Error;
            string    newUid     = textBoxNewUID.Text.Trim();

            string initialUid = _db.GetInitialUID(newUid);

            if (!string.IsNullOrEmpty(initialUid))
            {
                List <UidWriteHistory> tmpList = _db.GetUidHistory(initialUid);

                if (tmpList != null)
                {
                    if (tmpList[0]._writtenUid == newUid)
                    {
                        MessageBox.Show(ResStrings.str_UID_already_in_use_Please_Change_UID);
                        return;
                    }
                }
            }


            if (comboBoxSelWrite.SelectedIndex == 0)
            {
                if ((!SDK_SC_RfidReader.DeviceBase.SerialRFID.isStringValidToWrite(textBoxNewUID.Text.Trim()) || (textBoxNewUID.Text.Length > 17)))
                {
                    MessageBox.Show(ResStrings.str_Invalid_Tag_ID, ResStrings.strInfo, MessageBoxButtons.OK,
                                    MessageBoxIcon.Error);
                    return;
                }
            }
            else if (comboBoxSelWrite.SelectedIndex == 1)
            {
                System.Text.RegularExpressions.Regex myRegex = new Regex(@"^[0-9]+$");
                if ((!myRegex.IsMatch(textBoxNewUID.Text)) || (textBoxNewUID.Text.Length > 12))
                {
                    MessageBox.Show(ResStrings.str_Invalid_Tag_ID, ResStrings.strInfo, MessageBoxButtons.OK,
                                    MessageBoxIcon.Error);
                    return;
                }
            }

            if (!_isEthernetDevice) // (USB) local reader
            {
                if ((_currentDevice.ConnectionStatus == ConnectionStatus.CS_Connected) &&
                    (_currentDevice.DeviceStatus == DeviceStatus.DS_Ready))
                {
                    if (comboBoxSelWrite.SelectedIndex == 0)  //SPCE2 With family
                    {
                        codeResult = _currentDevice.WriteNewUidWithFamily(_previousUid, newUid);
                    }
                    else if (comboBoxSelWrite.SelectedIndex == 1)  // SPCE2 Decimal
                    {
                        codeResult = _currentDevice.WriteNewUidDecimal(_previousUid, newUid);
                    }
                    else
                    {
                        MessageBox.Show(ResStrings.str_RFID_device_not_ready);
                        return;
                    }
                }
            }

            else // (Ethernet) Remote reader
            {
                TcpIP_class.TcpIpClient tcpClient = new TcpIP_class.TcpIpClient();
                tcpClient.RequestWriteBlock(_currentDeviceClass.infoDev.IP_Server, _currentDeviceClass.infoDev.Port_Server, _previousUid, newUid, out codeResult, comboBoxSelWrite.SelectedIndex);
            }


            switch (codeResult)
            {
            case WriteCode.WC_Error:
                MessageBox.Show(ResStrings.strWriteStatusUnexpectedError);
                break;

            case WriteCode.WC_TagNotDetected:
                MessageBox.Show(ResStrings.strWriteStatusOperation_failed);
                break;

            case WriteCode.WC_TagNotConfirmed:
                MessageBox.Show(ResStrings.strWriteStatus_Tag_not_confirmed);
                break;

            case WriteCode.WC_TagBlockedOrNotSupplied:
                MessageBox.Show(ResStrings.str_Tag_blocked_or_not_well_supplied__Operation_failed);
                break;

            case WriteCode.WC_TagBlocked:
                MessageBox.Show(ResStrings.str_Tag_blocked__Operation_failed);
                break;

            case WriteCode.WC_TagNotSupplied:
                MessageBox.Show(ResStrings.str_Tag_not_well_supplied__Operation_failed);
                break;

            case WriteCode.WC_ConfirmationFailed:
                MessageBox.Show(ResStrings.str_Updated_tag_confirmation_has_failed);
                break;

            case WriteCode.WC_Success:

                _db.AddUidHistory(string.IsNullOrEmpty(_initialUid) ? _previousUid : _initialUid, newUid);
                if (_initialUid != null)
                {
                    UpdateHistoryTable(_initialUid);
                }
                Application.DoEvents();
                Thread.Sleep(200);
                MessageBox.Show(ResStrings.str_Tag_UID_succesfully_updated_);

                break;
            }
            Close();
        }