/// <summary> /// Validate the VIN. /// </summary> private bool IsLegal() { bool isLegal = true; if (this.vinBox.Text.Length == 17) { this.prompt.Text = "The VIN is 17 characters long. Good!"; } else { this.prompt.Text = $"The VIN must be 17 characters long. This is {this.vinBox.Text.Length}."; isLegal = false; } if (VinForm.IsAlphaNumeric(this.vinBox.Text)) { this.prompt2.Text = "The VIN contains only letters and numbers. Good!"; } else { this.prompt2.Text = "The VIN must contain only letters and numbers."; isLegal = false; } return(isLegal); }
/// <summary> /// Update the VIN. /// </summary> private async void modifyVinButton_Click(object sender, EventArgs e) { try { Response <uint> osidResponse = await this.Vehicle.QueryOperatingSystemId(CancellationToken.None); if (osidResponse.Status != ResponseStatus.Success) { this.AddUserMessage("Operating system query failed: " + osidResponse.Status); return; } PcmInfo info = new PcmInfo(osidResponse.Value); var vinResponse = await this.Vehicle.QueryVin(); if (vinResponse.Status != ResponseStatus.Success) { this.AddUserMessage("VIN query failed: " + vinResponse.Status.ToString()); return; } DialogBoxes.VinForm vinForm = new DialogBoxes.VinForm(); vinForm.Vin = vinResponse.Value; DialogResult dialogResult = vinForm.ShowDialog(); if (dialogResult == DialogResult.OK) { bool unlocked = await this.Vehicle.UnlockEcu(info.KeyAlgorithm); if (!unlocked) { this.AddUserMessage("Unable to unlock PCM."); return; } Response <bool> vinmodified = await this.Vehicle.UpdateVin(vinForm.Vin.Trim()); if (vinmodified.Value) { this.AddUserMessage("VIN successfully updated to " + vinForm.Vin); MessageBox.Show("VIN updated to " + vinForm.Vin + " successfully.", "Good news.", MessageBoxButtons.OK); } else { MessageBox.Show("Unable to change the VIN to " + vinForm.Vin + ". Error: " + vinmodified.Status, "Bad news.", MessageBoxButtons.OK); } } } catch (Exception exception) { this.AddUserMessage("VIN change failed: " + exception.ToString()); } }
/// <summary> /// Validate the VIN. /// </summary> private bool IsLegal() { if (this.vinBox.Text.Length != 17) { this.prompt.Text = $"The VIN must be 17 characters long! This is {this.vinBox.Text.Length}."; return(false); } if (!VinForm.IsAlphaNumeric(this.vinBox.Text)) { this.prompt.Text = "The VIN must contain only letters and numbers."; return(false); } this.vinBox.Text = this.vinBox.Text.ToUpper(); if (IsVinChecksumOK(this.vinBox.Text)) { this.prompt.Text = "The VIN is valid. Good!"; return(true); } return(false); }