コード例 #1
0
ファイル: VehicleForm.cs プロジェクト: qqj1228/SH_OBD
        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("确保在数字输入框内仅输入了数字,并且确保没有遗漏输入数据", "出错", 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("必须给当前车辆配置命名", "出错", MessageBoxButtons.OK, MessageBoxIcon.Hand);
            }
        }
コード例 #2
0
        public void SaveActiveProfile(VehicleProfile profile)
        {
            Settings settings = CommSettings;

            settings.ActiveProfileIndex = VehicleProfiles.IndexOf(profile);
            SaveCommSettings(settings);
        }
コード例 #3
0
ファイル: VehicleForm.cs プロジェクト: qqj1228/SH_OBD
        private void btnNewVehicle_Click(object sender, EventArgs e)
        {
            VehicleProfile vehicleProfile = new VehicleProfile();

            listVehicles.Items.Add(vehicleProfile);
            m_VehicleList.Add(vehicleProfile);
            listVehicles.SetSelected(listVehicles.Items.Count - 1, true);
        }
コード例 #4
0
ファイル: Settings.cs プロジェクト: qqj1228/SH_OBD
 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)
         );
 }
コード例 #5
0
ファイル: VehicleForm.cs プロジェクト: qqj1228/SH_OBD
        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);
        }
コード例 #6
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) {
                // file读完以后会抛出SerializationException异常,什么都不做继续执行finally块
            } catch (Exception e) {
                // 发生其余异常的话就写log
                m_log.TraceError("Failed to load vehicle profile. Reason: " + e.Message);
            } finally {
                if (file != null)
                {
                    file.Close();
                }
            }
            return(profiles);
        }