示例#1
0
 public bool Equals(VehicleProfile p)
 {
     return(
         Name.Equals(p.Name) &&
         AutoTransmission == p.AutoTransmission &&
         Weight == p.Weight &&
         DynoDriveRatio == p.DynoDriveRatio &&
         DragCoefficient == p.DragCoefficient &&
         Wheel.Width == p.Wheel.Width &&
         Wheel.AspectRatio == p.Wheel.AspectRatio &&
         Wheel.RimDiameter == p.Wheel.RimDiameter &&
         ElmTimeout == p.ElmTimeout && Notes.Equals(p.Notes)
         );
 }
示例#2
0
        private void EditProfile(VehicleProfile profile)
        {
            txtName.Text     = profile.Name;
            numTimeout.Value = new decimal(profile.ElmTimeout);
            if (profile.AutoTransmission)
            {
                radioAutomatic.Checked = true;
            }
            else
            {
                radioManual.Checked = true;
            }

            txtSpeedoFactor.Text = profile.SpeedCalibrationFactor.ToString("0.000");
            txtWeight.Text       = profile.Weight.ToString();
            txtDragCoeff.Text    = profile.DragCoefficient.ToString("0.000");
            txtTireWidth.Text    = profile.Wheel.Width.ToString();
            txtAspectRatio.Text  = profile.Wheel.AspectRatio.ToString();
            txtRimDiameter.Text  = profile.Wheel.RimDiameter.ToString();
            txtNotes.Text        = profile.Notes;
            MarkProfileDirty(false);
        }
示例#3
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (txtName.Text.Length > 0)
            {
                VehicleProfile vehicle = new VehicleProfile();
                vehicle.Name             = txtName.Text;
                vehicle.ElmTimeout       = Convert.ToInt32(numTimeout.Value, CultureInfo.InvariantCulture);
                vehicle.AutoTransmission = radioAutomatic.Checked;

                try
                {
                    vehicle.SpeedCalibrationFactor = Convert.ToSingle(txtSpeedoFactor.Text, CultureInfo.InvariantCulture);
                    vehicle.Weight            = Convert.ToSingle(txtWeight.Text, CultureInfo.InvariantCulture);
                    vehicle.DragCoefficient   = Convert.ToSingle(txtDragCoeff.Text, CultureInfo.InvariantCulture);
                    vehicle.Wheel.Width       = Convert.ToInt32(txtTireWidth.Text, CultureInfo.InvariantCulture);
                    vehicle.Wheel.AspectRatio = Convert.ToInt32(txtAspectRatio.Text, CultureInfo.InvariantCulture);
                    vehicle.Wheel.RimDiameter = Convert.ToInt32(txtRimDiameter.Text, CultureInfo.InvariantCulture);
                    vehicle.Notes             = txtNotes.Text;
                }
                catch (FormatException)
                {
                    MessageBox.Show("Make sure that numeric fields contain only numeric data, and make sure that you are not forgetting a required field.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                    return;
                }

                m_VehicleList[listVehicles.SelectedIndex] = vehicle;
                MarkProfileDirty(false);

                int selectedIndex = listVehicles.SelectedIndex;
                UpdateProfileList(m_VehicleList);
                listVehicles.SetSelected(selectedIndex, true);
            }
            else
            {
                MessageBox.Show("You must enter a name for your profile.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
            }
        }
示例#4
0
        public List <VehicleProfile> LoadVehicleProfiles()
        {
            FileStream            file            = null;
            BinaryFormatter       binaryFormatter = new BinaryFormatter();
            List <VehicleProfile> profiles        = new List <VehicleProfile>();

            try
            {
                if (File.Exists(m_vehicles_db))
                {
                    file = new FileStream(m_vehicles_db, FileMode.Open, FileAccess.Read);
                }
                else
                {
                    VehicleProfile profile = new VehicleProfile();
                    file = new FileStream(m_vehicles_db, FileMode.Create, FileAccess.ReadWrite);
                    binaryFormatter.Serialize(file, profile);
                }
                file.Position = 0L;
                while (true)
                {
                    VehicleProfile vehicleProfile = binaryFormatter.Deserialize(file) as VehicleProfile;
                    profiles.Add(vehicleProfile);
                }
            }
            catch (SerializationException) { }
            catch (Exception) { }
            finally
            {
                if (file != null)
                {
                    file.Close();
                }
            }
            return(profiles);
        }