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); } }
private bool RetrievePersonnelInformationAndBind(string personnelId) { try { PersonnelInformation info; string personnelKey; using (KeyEncoderService keyEncoderService = new KeyEncoderService()) { keyEncoderService.Url = settings.FuelTrakUrl + (settings.FuelTrakUrl.EndsWith("/") ? "" : "/") + "Services/KeyEncoderService.asmx"; info = keyEncoderService.GetPersonnelInformation(personnelId); if (info == null) { DisplayStatusMessage("No data found for personnel: " + personnelId, false); return(false); } personnelKey = keyEncoderService.GetPersonnelKeyId(personnelId); } FuelTrakKeyData data = FuelTrakKeyData.ParseFromPersonnelInformation(info, personnelKey); BindDataToView(data); return(true); } catch (Exception ex) { Log(ex.Message); Log(ex.StackTrace); DisplayStatusMessage("Exception:" + ex.InnerException.ToString(), false); return(false); } }
private void ReadRequestCallback(IAsyncResult result) { try { AsyncResult r = (AsyncResult)result; Action originalAction = (Action)r.AsyncDelegate; originalAction.EndInvoke(result); ReadKeyCommand command = (ReadKeyCommand)result.AsyncState; if (command.DataRead.StartsWith("+")) { DisplayStatusMessage("Successful Read", false); } else { DisplayStatusMessage("Read Failed", false); } FuelTrakKeyData data = FuelTrakKeyData.Parse(command.DataRead, command.DataReadMileage, command.DataReadMileageWindow); BindDataToView(data); } catch (Exception ex) { Log(ex.Message); Log(ex.StackTrace); DisplayStatusMessage("Error attempting read", false); } }
private bool RetrieveVehicleInformationAndBind(string vehicleId) { try { VehicleInformation info; string vehicleKey; using (KeyEncoderService keyEncoderService = new KeyEncoderService()) { keyEncoderService.Url = settings.FuelTrakUrl + (settings.FuelTrakUrl.EndsWith("/") ? "" : "/") + "Services/KeyEncoderService.asmx"; info = keyEncoderService.GetVehicleInformation(vehicleId); if (info == null) { DisplayStatusMessage("No data found for vehicle: " + vehicleId, false); return(false); } vehicleKey = keyEncoderService.GetVehicleKeyId(vehicleId); } FuelTrakKeyData data = FuelTrakKeyData.ParseFromVehicleInformation(info, vehicleKey); BindDataToView(data); return(true); } catch (Exception ex) { return(false); } }
public static FuelTrakKeyData ParseFromPersonnelInformation(FuelTrak.PersonnelInformation info, string keyId) { FuelTrakKeyData data = new FuelTrakKeyData(); data.KeyType = FuelTrakKeyType.Personnel; data.ItemId = info.Id.ToString(); data.SystemNumber = info.SystemId; data.KeyId = keyId; data.Expiration = "Never"; return(data); }
private void BindDataToView(FuelTrakKeyData data) { txtKeyType.Text = data.KeyType.ToString(); txtKeyNumber.Text = data.KeyId; txtVehicleId.Text = data.ItemId; txtExpiration.Text = data.Expiration; txtSystemNumber.Text = data.SystemNumber; txtFuelLimit.Text = data.FuelLimit; txtMaster.Text = data.IsMasterKey ? "Yes" : "No"; txtMileage.Text = data.Mileage; txtOption.Text = data.Option ? "Yes" : "No"; txtRequiredMileage.Text = data.IsMileageEntryRequired ? "Yes" : "No"; }
private void button1_Click(object sender, EventArgs e) { try { ReadKeyCommand readCommand = new ReadKeyCommand(settings.ComPort); readCommand.Execute(); LogDebugMessage("Recieved data: " + readCommand.DataRead); FuelTrakKeyData data = FuelTrakKeyData.Parse(readCommand.DataRead); BindDataToView(data); } catch (Exception ex) { LogDebugMessage("ERROR: " + ex.Message); LogDebugMessage("ERROR: " + ex.StackTrace); } }
public static FuelTrakKeyData ParseFromVehicleInformation(FuelTrak.VehicleInformation info, string keyId) { FuelTrakKeyData data = new FuelTrakKeyData(); data.KeyType = FuelTrakKeyType.Vehicle; data.ItemId = info.Id.ToString(); data.SystemNumber = info.SystemId; data.KeyId = keyId; data.Expiration = "Never"; data.FuelLimit = info.FuelLimit; data.IsMasterKey = info.IsMaster; data.IsMileageEntryRequired = info.MileageEntryRequired; data.IsSecondKeyReq = info.RequireSecondKey; data.Option = false; data.fuelTypes = info.FuelTypes; // Added by RSmith 9/27/10 data.Mileage = info.Mileage; data.MileageWindow = info.MileageWindow; return(data); }
private void BindDataToView(FuelTrakKeyData data) { try { if (InvokeRequired) { Invoke(new Action <FuelTrakKeyData>(BindDataToView), data); return; } pnlInformationDisplay.Controls.Clear(); currentDisplayedData = data; if (currentDisplayedData == null) { btnEncodeKey.Enabled = false; return; } if (currentDisplayedData.KeyType == FuelTrakKeyType.Personnel) { PersonnelKeyInfo infoControl = new PersonnelKeyInfo(); infoControl.Data = currentDisplayedData; pnlInformationDisplay.Controls.Add(infoControl); infoControl.Dock = DockStyle.Fill; } else { VehicleKeyInfo infoControl = new VehicleKeyInfo(); infoControl.Data = currentDisplayedData; pnlInformationDisplay.Controls.Add(infoControl); infoControl.Dock = DockStyle.Fill; } btnEncodeKey.Enabled = true; } catch (Exception ex) { } }
//public static bool TryParse(string keydata, out FuelTrakKeyData data) //{ // try // { // FuelTrakKeyData parsedData = Parse(keydata); // data = parsedData; // return true; // } // catch // { // data = null; // return false; // } //} public static FuelTrakKeyData Parse(string keydata, string mileageData, string mileageWindowData) { FuelTrakKeyData data = new FuelTrakKeyData(); if (keydata.Substring(0, 1) != "+") { throw new ArgumentException("keydata", "Data was not read successfully from the key."); } switch (keydata.Substring(17, 1)) { case "0": data.keyType = FuelTrakKeyType.Vehicle; break; case "1": data.keyType = FuelTrakKeyType.Personnel; break; default: throw new ArgumentOutOfRangeException("keydata", "Invalid key type"); } data.keyId = keydata.Substring(2, 5); data.itemId = keydata.Substring(7, 10); data.expiration = "Never"; data.systemNumber = keydata.Substring(21, 3); if (data.keyType == FuelTrakKeyType.Vehicle) { // RSmith 9/27/10 note: The original code for finding data.master is // replaced below. //data.master = keydata.Substring(34, 1) == "1"; data.secondKeyReq = keydata.Substring(18, 1) == "1"; data.mileageRequired = keydata.Substring(19, 1) == "1"; data.option = keydata.Substring(20, 1) == "1"; data.fuelLimit = keydata.Substring(24, 3); data.master = keydata.Substring(31, 1) == "1"; // Finished by RSmith 9/27/10 // data.fuelTypes = "".PadRight(15, 'N'); data.fuelTypes = string.Empty; for (int i = 0; i < 15; i++) { data.fuelTypes += keydata.Substring(i + 32, 1) == "1" ? "Y" : "N"; } } // data comes in as (e.g.) "\r\n8765 4321 \r\n\r\n+" // we clean that up to: 87654321 mileageData = mileageData.Replace("\r", "").Replace("\n", "").Replace("+", "").Replace(" ", ""); mileageData = mileageData.Trim(); // then rearrange to 21436587 string strTemp = mileageData.Substring(6, 2) + mileageData.Substring(4, 2) + mileageData.Substring(2, 2) + mileageData.Substring(0, 2); Int32 intTemp = 0; try { intTemp = Int32.Parse(strTemp, System.Globalization.NumberStyles.HexNumber); data.mileage = intTemp.ToString(); } catch { MessageBox.Show("Error converting Hex Mileage", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1); } mileageWindowData = mileageWindowData.Replace("\r", "").Replace("\n", "").Replace("+", ""); mileageWindowData = mileageWindowData.Trim(); strTemp = mileageWindowData.Substring(2, 2) + mileageWindowData.Substring(0, 2); try { intTemp = Int32.Parse(strTemp, System.Globalization.NumberStyles.HexNumber); data.mileageWindow = intTemp.ToString(); } catch { MessageBox.Show("Error converting Hex Mileage Window", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1); } return(data); }