Beispiel #1
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);
            }
        }