コード例 #1
0
        public SeriesEditForm(EngineSeries series = null)
        {
            InitializeComponent();
            headerPanel.BackColor = Color.FromArgb(51, 53, 53);
            shadowLabel1.Text     = (series == null) ? "New Engine Series" : "Modify Engine Series";
            Series    = series;
            NewSeries = series == null;

            // Add engine icons
            var images = Directory.GetFiles(MatPath, "*.dds");

            foreach (string image in images)
            {
                string fn = Path.GetFileNameWithoutExtension(image);
                iconBox.Items.Add(fn);
                if (series != null && fn.Equals(series.EngineIcon, StringComparison.OrdinalIgnoreCase))
                {
                    iconBox.SelectedIndex = iconBox.Items.Count - 1;
                }
            }

            // Add each sound to the lists
            using (AppDatabase db = new AppDatabase())
            {
                foreach (EngineSoundPackage sound in db.EngineSoundPackages)
                {
                    soundBox.Items.Add(sound);
                    if (Series != null && sound.Id == series.SoundPackageId)
                    {
                        soundBox.SelectedIndex = soundBox.Items.Count - 1;
                    }
                }
            }

            // Select default icon index
            if (iconBox.SelectedIndex == -1 && iconBox.Items.Count > 0)
            {
                iconBox.SelectedIndex = 0;
            }

            // Select default sound package index
            if (soundBox.SelectedIndex == -1 && soundBox.Items.Count > 0)
            {
                soundBox.SelectedIndex = 0;
            }

            // Set texts
            if (series != null)
            {
                manuNameBox.Text      = series.Manufacturer;
                seriesNameBox.Text    = series.Name;
                displacementBox.Value = series.Displacement;
                iconBox.Focus();
            }
        }
コード例 #2
0
        /// <summary>
        /// Gets an <see cref="EngineSeries"/> with the specified key from the cache. If the
        /// <see cref="EngineSeries"/> is not found in the cache, then it is fetched from the
        /// database and stored in the cache.
        /// </summary>
        private static EngineSeries GetEngineSeries(int seriesId, AppDatabase db, Dictionary <int, EngineSeries> cache)
        {
            EngineSeries series = null;

            if (!cache.TryGetValue(seriesId, out series))
            {
                series = db.Query <EngineSeries>("SELECT * FROM `EngineSeries` WHERE `Id`=@P0", seriesId).FirstOrDefault();
                cache.Add(seriesId, series);
            }

            return(series);
        }
コード例 #3
0
ファイル: EngineForm.cs プロジェクト: wilson212/ATSEngineTool
        private void engineModelBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            // Unlock all other controls
            if (!engineNameBox.Enabled)
            {
                unitNameBox.Enabled   = true;
                engineNameBox.Enabled = true;
                unlockBox.Enabled     = true;
                priceBox.Enabled      = true;
                torqueBox.Enabled     = true;
                horsepowerBox.Enabled = true;
                //peakRPMBox.Enabled = true;
                rpmLimitBox.Enabled         = true;
                idleRpmBox.Enabled          = true;
                brakePositionsBox.Enabled   = true;
                brakeStrengthBox.Enabled    = true;
                automaticDSCheckBox.Enabled = true;
                rpmRangeBox1.Enabled        = true;
                rpmRangeBox2.Enabled        = true;
                rpmRangeBox3.Enabled        = true;
                rpmRangeBox4.Enabled        = true;
                rpmRangeBox5.Enabled        = true;
                rpmRangeBox6.Enabled        = true;
                neutralRpmBox.Enabled       = true;
                filenameTextBox.Enabled     = true;
                adBlueConsumption.Enabled   = true;
                adBlueNoPowerLimit.Enabled  = true;
                engineBrakeHigh.Enabled     = true;
                engineBrakeLow.Enabled      = true;
                resistanceBox.Enabled       = true;
                consumptionBox.Enabled      = true;
            }

            EngineSeries series = (EngineSeries)engineModelBox.SelectedItem;
            string       path   = Path.Combine(MatPath, series.EngineIcon);

            if (!path.EndsWith(".dds"))
            {
                path += ".dds";
            }

            // Set data's for engine series
            displacementBox.Value = series.Displacement;
            soundTextBox.Text     = series.SoundPackage.Name;

            // Perform cleanup
            if (engineIcon.Image != null)
            {
                engineIcon.Image.Dispose();
                engineIcon.Image = null;
            }

            // Ensure icon exists before proceeding
            if (!File.Exists(path))
            {
                return;
            }

            // Attempt to load image as a DDS file... or png if its a mod sometimes
            FREE_IMAGE_FORMAT Format   = FREE_IMAGE_FORMAT.FIF_UNKNOWN;
            Bitmap            MapImage = FreeImage.LoadBitmap(path, FREE_IMAGE_LOAD_FLAGS.DEFAULT, ref Format);

            if (MapImage != null)
            {
                engineIcon.Image = new Bitmap(MapImage, 64, 64);
            }
        }
コード例 #4
0
        private void confirmButton_Click(object sender, EventArgs e)
        {
            // Check for a valid identifier string
            if (!Regex.Match(manuNameBox.Text, @"^[a-z0-9_.,\-\s\t()]+$", RegexOptions.IgnoreCase).Success)
            {
                // Tell the user this isnt allowed
                MessageBox.Show("Invalid Manufacturer Name. Please use alpha-numeric, period, comma, underscores, dashes or spaces only",
                                "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning
                                );

                return;
            }

            // Check engine name
            if (!Regex.Match(seriesNameBox.Text, @"^[a-z0-9_.,\-\s\t()]+$", RegexOptions.IgnoreCase).Success)
            {
                // Tell the user this isnt allowed
                MessageBox.Show(
                    "Invalid Series Name string. Please use alpha-numeric, period, underscores, dashes or spaces only",
                    "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning
                    );
            }


            // Save or update the engine series
            try
            {
                // Add or update the truck in the database
                using (AppDatabase db = new AppDatabase())
                {
                    if (NewSeries)
                    {
                        Series = new EngineSeries()
                        {
                            Name         = seriesNameBox.Text.Trim(),
                            Manufacturer = manuNameBox.Text.Trim(),
                            Displacement = displacementBox.Value,
                            EngineIcon   = iconBox.SelectedItem.ToString(),
                            SoundPackage = ((EngineSoundPackage)soundBox.SelectedItem)
                        };
                        db.EngineSeries.Add(Series);
                    }
                    else
                    {
                        Series.Name         = seriesNameBox.Text.Trim();
                        Series.Manufacturer = manuNameBox.Text.Trim();
                        Series.Displacement = displacementBox.Value;
                        Series.EngineIcon   = iconBox.SelectedItem.ToString();
                        Series.SoundPackage = ((EngineSoundPackage)soundBox.SelectedItem);
                        db.EngineSeries.Update(Series);
                    }
                }
            }
            catch (Exception ex)
            {
                // Tell the user about the failed validation error
                MessageBox.Show(ex.Message, "Database Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            this.DialogResult = DialogResult.OK;
        }