private void button2_Click(object sender, EventArgs e)
        {
            try
            {
                MessageBox.Show("Insert key to read");

                ReadKeyCommand readCommand = new ReadKeyCommand(settings.ComPort);
                readCommand.Execute();

                FuelTrakKeyData inputData = FuelTrakKeyData.Parse(readCommand.DataRead);

                MessageBox.Show("Data read successful. Insert key to write.");

                string dataToWrite = inputData.ToKeyDataString();

                LogDebugMessage("Writing data: " + dataToWrite);

                WriteKeyCommand writeKeyCommand = new WriteKeyCommand(settings.ComPort, dataToWrite);
                writeKeyCommand.Execute();

                if (writeKeyCommand.ExecutionStatus)
                {
                    LogDebugMessage("Data written to key successfully");
                }
                else
                {
                    LogDebugMessage("Data NOT written to key successfully");
                }
            }
            catch (Exception ex)
            {
                LogDebugMessage("ERROR: " + ex.Message);
                LogDebugMessage("ERROR: " + ex.StackTrace);
            }
        }
Exemple #2
0
        private void WriteRequestCallback(IAsyncResult result)
        {
            try
            {
                AsyncResult r = (AsyncResult)result;
                Action      originalAction = (Action)r.AsyncDelegate;
                originalAction.EndInvoke(result);

                WriteKeyCommand command = (WriteKeyCommand)result.AsyncState;

                if (command.ExecutionStatus)
                {
                    DisplayStatusMessage("Successful Key Encode", false);
                }
                else
                {
                    DisplayStatusMessage("Key Encode Failed", false);
                }
            }
            catch (Exception ex)
            {
                Log(ex.Message);
                Log(ex.StackTrace);

                DisplayStatusMessage("Error attempting to encode key", false);
            }
        }
Exemple #3
0
        private void OnEncodeKeyRequest(object sender, EventArgs e)
        {
            try
            {
                //if (currentDisplayedData == null) return;
                //string dataToWrite = currentDisplayedData.ToKeyDataString();
                //string dataToWriteMileage = currentDisplayedData.ToKeyMileageString();
                //string dataToWriteMileageWindow = currentDisplayedData.ToKeyMileageWindowString();

                //DisplayStatusMessage("Writing data", true);

                //WriteKeyCommand writeKeyCommand = new WriteKeyCommand(settings.ComPort, dataToWrite,
                //    dataToWriteMileage, dataToWriteMileageWindow);
                //Action writeAction = new Action(writeKeyCommand.Execute);
                //writeAction.BeginInvoke(WriteRequestCallback, writeKeyCommand);

                //Added By Varun Moota, since we need to differentiate both Vehicles and Personnel Key write's.03/05/2012
                if (currentDisplayedData.KeyType.ToString() == "Personnel")
                {
                    if (currentDisplayedData == null)
                    {
                        return;
                    }
                    string dataToWrite              = currentDisplayedData.ToKeyDataString();
                    string dataToWriteMileage       = Convert.ToString(null);
                    string dataToWriteMileageWindow = Convert.ToString(null);
                    string dataToCheckKeyType       = currentDisplayedData.KeyType.ToString();
                    DisplayStatusMessage("Writing data", true);

                    WriteKeyCommand writeKeyCommand = new WriteKeyCommand(settings.ComPort, dataToWrite,
                                                                          dataToWriteMileage, dataToWriteMileageWindow, dataToCheckKeyType);
                    Action writeAction = new Action(writeKeyCommand.Execute);
                    writeAction.BeginInvoke(WriteRequestCallback, writeKeyCommand);
                }
                else
                {
                    if (currentDisplayedData == null)
                    {
                        return;
                    }
                    string dataToWrite              = currentDisplayedData.ToKeyDataString();
                    string dataToWriteMileage       = currentDisplayedData.ToKeyMileageString();
                    string dataToWriteMileageWindow = currentDisplayedData.ToKeyMileageWindowString();
                    string dataToCheckKeyType       = currentDisplayedData.KeyType.ToString();

                    DisplayStatusMessage("Writing data", true);

                    WriteKeyCommand writeKeyCommand = new WriteKeyCommand(settings.ComPort, dataToWrite,
                                                                          dataToWriteMileage, dataToWriteMileageWindow, dataToCheckKeyType);
                    Action writeAction = new Action(writeKeyCommand.Execute);
                    writeAction.BeginInvoke(WriteRequestCallback, writeKeyCommand);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Probelm Encoding Key:" + ex.InnerException.ToString(), "ERROR", MessageBoxButtons.OK);
            }
        }