Exemplo n.º 1
0
        private void SaveCarsWorker_ProgressChanged(object sender, ProgressChangedEventArgs e)
        {
            if (e.ProgressPercentage > 0)
            {
                this.pbProgress.Value = e.ProgressPercentage;
            }

            if (e.UserState != null)
            {
                Dictionary <NR2003Car, bool> carSaveResult = e.UserState as Dictionary <NR2003Car, bool>;

                foreach (KeyValuePair <NR2003Car, bool> kvp in carSaveResult) //NORMALLY WILL CONTAIN ONLY ONE ITEM
                {
                    NR2003Car c       = kvp.Key;
                    bool      success = kvp.Value;

                    int carIndex = this.colCars.IndexOf(c);
                    this.bsCars.Position = carIndex;

                    if (success)
                    {
                        this.dgCars.Rows[carIndex].DefaultCellStyle.BackColor = Color.LightGreen;
                        this.lbLog.WriteToLog(String.Format("Save successful: {0}", c.ToString()), false);
                    }
                    else
                    {
                        this.dgCars.Rows[carIndex].DefaultCellStyle.BackColor = Color.LightPink;
                        this.lbLog.WriteToLog(String.Format("Save NOT successful: {0}", c.ToString()), false);
                    }
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Searches cars in targetCars but not in processedCars matching number and/or name (according to grouping options), and updates it with the same ratings.
        /// Then adds modified cars to processedCars (which is updated by reference)
        /// </summary>
        /// <param name="sourceCar"></param>
        /// <param name="processedCars"></param>
        private void GroupRatings(NR2003Car sourceCar, List <NR2003Car> processedCars)
        {
            if (this.mGroupByNumber || this.mGroupByName)
            {
                //SELECT ALL UNPROCESSED CARS FROM COMPLETE CARLIST, DIFFERENT FROM SOURCECAR
                var q = from NR2003Car c in this.mCarCollection
                        where !processedCars.Contains(c) && c != sourceCar
                        select c;

                List <NR2003Car> similarCars = q.ToList();

                if (this.mGroupByNumber)
                {
                    similarCars = similarCars.Where(c => c.Number.Equals(sourceCar.Number)).ToList();
                }

                if (this.mGroupByName)
                {
                    similarCars = similarCars.Where(c => c.DriverFirstName.Equals(sourceCar.DriverFirstName) && c.DriverLastName.Equals(sourceCar.DriverLastName)).ToList();
                }


                foreach (NR2003Car c in similarCars)
                {
                    c.Ratings = (Ratings)sourceCar.Ratings.Clone();
                    processedCars.Add(c);
                }
            }
        }
Exemplo n.º 3
0
        private void CarIsDirtyChanged(object sender, EventArgs <bool> e)
        {
            this.SetSelectModifiedButtonText();

            try
            {
                int       carIndex = -1;
                NR2003Car car      = (NR2003Car)sender;

                CarCollection colCars = (CarCollection)this.bsCars.DataSource;
                carIndex = colCars.IndexOf(car);

                if (carIndex != -1)
                {
                    if (e.ArgObject == true)
                    {
                        this.dgCars.Rows[carIndex].DefaultCellStyle.BackColor = Color.LightBlue;
                    }
                    else
                    {
                        this.dgCars.Rows[carIndex].DefaultCellStyle.BackColor = Color.White;
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }
Exemplo n.º 4
0
        public frmModifyRatings(CarCollection carCol, NR2003Car currentCar)
        {
            InitializeComponent();
            this.mRMod = new RatingsModifier();
            this.mRMod.CarCollection = carCol;
            this.mRMod.CurrentCar    = currentCar;

            this.mIsDirty      = false;
            this.mTrackIsDirty = false;
        }
Exemplo n.º 5
0
        private void copyRatingsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (this.colCars != null)
            {
                NR2003Car c = this.bsCars.Current as NR2003Car;

                if (c != null)
                {
                    this.CopiedRatings = (Ratings)c.Ratings.Clone();
                }
            }
        }
Exemplo n.º 6
0
        private void revertCompletelyToolStripMenuItem_Click(object sender, EventArgs e)
        {
            NR2003Car c = this.bsCars.Current as NR2003Car;

            if (c != null)
            {
                c.RevertToOriginal(NR2003Car.RevertType.Completely);

                //this.grpRatings.TrackChanges(false);
                this.grpRatings.Ratings = c.Ratings;
                //this.grpRatings.TrackChanges(true);
            }
        }
Exemplo n.º 7
0
        private void dgCars_CurrentCellDirtyStateChanged(object sender, EventArgs e)
        {
            if (this.dgCars.CurrentCell.OwningColumn.Name == "mappedToRealDriverDataGridViewComboBoxColumn")
            {
                this.dgCars.EndEdit();

                NR2003Car c = this.bsCars.Current as NR2003Car;

                if (c != null)
                {
                    this.grpRatings.Ratings = c.Ratings;
                }
            }
        }
Exemplo n.º 8
0
        private void pasteRatingsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (this.colCars != null)
            {
                NR2003Car c = this.bsCars.Current as NR2003Car;

                if (c != null && this.CopiedRatings != null)
                {
                    c.Ratings            = (Ratings)this.CopiedRatings.Clone();
                    c.MappedToRealDriver = null;

                    //this.grpRatings.TrackChanges(false);
                    this.grpRatings.Ratings = c.Ratings;
                    //this.grpRatings.TrackChanges(true);
                }
            }
        }
Exemplo n.º 9
0
        private void butModifyRatings_Click(object sender, EventArgs e)
        {
            bool showModifyDialog = true;
            int  currentRow       = 0;

            if (this.colCars.IsDirty == true)
            {
                DialogResult sure = MessageBox.Show("You have unsaved changes in your carlist. If you bulk modify the ratings, you may possibly overwrite these changes. Are you sure you want to continue ?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);

                if (sure == DialogResult.No)
                {
                    showModifyDialog = false;
                }
            }

            if (showModifyDialog)
            {
                DataGridViewSelectedRowCollection dgvRows = this.dgCars.SelectedRows;

                NR2003Car currentCar = null;
                if (dgvRows != null && dgvRows.Count > 0)
                {
                    currentCar = (NR2003Car)dgvRows[0].DataBoundItem;
                    currentRow = dgvRows[0].Index;
                }

                frmModifyRatings fModifyRatings = new frmModifyRatings(this.colCars, currentCar);
                fModifyRatings.ShowDialog();


                this.dgCars.Focus();
                this.dgCars.Refresh();

                if (this.dgCars.Rows.Count > 0)
                {
                    this.dgCars.Rows[currentRow].Selected = true;
                    this.dgCars_SelectionChanged(null, null);
                }

                if (this.colCars.IsDirty)
                {
                    this.EnableControlsIfDirtyCarCollection(true);
                }
            }
        }
Exemplo n.º 10
0
        private void dgCars_SelectionChanged(object sender, EventArgs e)
        {
            //this.grpRatings.TrackChanges(false);

            if (this.bsCars != null && this.bsCars.Count > 0)
            {
                NR2003Car c = (NR2003Car)this.bsCars.Current;
                this.grpRatings.Ratings = c.Ratings;
                //this.grpRatings.TrackChanges(true);
                this.grpRatings.EnableControls(true);

                Console.WriteLine("Current car: " + c.ToString());
            }
            else
            {
                this.grpRatings.EnableControls(false);
            }
        }
Exemplo n.º 11
0
        private void dgCars_MouseDown(object sender, MouseEventArgs e)
        {
            //On right mouseclick, make sure the car at the cursor is selected, to allow correct functioning of contextmenustrip

            DataGridView.HitTestInfo Hti;

            if (e.Button == MouseButtons.Right)
            {
                Hti = this.dgCars.HitTest(e.X, e.Y);

                this.bsCars.Position = Hti.RowIndex;

                NR2003Car c = this.bsCars.Current as NR2003Car;

                if (c != null)
                {
                    if (c.IsDirty == false)
                    {
                        this.ctxMenuStripCars.Items["revertToolStripMenuItem"].Enabled = false;
                    }
                    else
                    {
                        this.ctxMenuStripCars.Items["revertToolStripMenuItem"].Enabled = true;
                    }

                    if (this.CopiedRatings == null)
                    {
                        this.ctxMenuStripCars.Items["pasteRatingsToolStripMenuItem"].Enabled = false;
                    }
                    else
                    {
                        this.ctxMenuStripCars.Items["pasteRatingsToolStripMenuItem"].Enabled = true;
                    }
                }
            }
        }
Exemplo n.º 12
0
        private void carListWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            bool   errorsOnRead = false;
            double progress     = 0.0;

            if (this.selectedMod.Path != null)
            {
                String carPath = this.selectedMod.Path + @"\cars";

                if (Directory.Exists(carPath))
                {
                    string rosterContents = null;
                    if (this.selectedRoster != null && this.selectedRoster.FullPath != null)
                    {
                        try
                        {
                            rosterContents = this.selectedRoster.GetRosterContents();
                        }
                        catch (Exception ex)
                        {
                            carListWorker.ReportProgress(-1, "Error reading roster " + this.selectedRoster.Name + ": " + ex.ToString());
                            errorsOnRead = true;
                        }
                    }



                    String[] carFiles    = Directory.GetFiles(carPath, "*.car");
                    int      numCarFiles = carFiles.Length;
                    int      counter     = 0;

                    this.colCars = new CarCollection();
                    foreach (String carFile in carFiles)
                    {
                        counter++;

                        string carFileName = carFile.Substring(carFile.LastIndexOf(@"\") + 1);

                        NR2003Car c = new NR2003Car(carPath, carFileName);

                        try
                        {
                            c.ReadCarInfo();

                            c.IsDirtyChanged += new EventHandler <EventArgs <bool> >(CarIsDirtyChanged);

                            if (rosterContents != null)
                            {
                                if (rosterContents.Contains(@"+" + c.FileName))
                                {
                                    this.colCars.Add(c);
                                }
                            }
                            else
                            {
                                this.colCars.Add(c);
                            }
                        }
                        catch (UnauthorizedAccessException)
                        {
                            carListWorker.ReportProgress(-1, "Not allowed to access carfile " + c.FileName + ". Make sure the file is not set to readonly !");
                            errorsOnRead = true;
                        }
                        catch (Exception ex)
                        {
                            errorsOnRead = true;
                            carListWorker.ReportProgress(-1, "There was an error reading carfile " + c.FileName + ": " + ex.Message);
                        }

                        progress = ((double)(counter) / (double)(numCarFiles)) * 100.0;
                        carListWorker.ReportProgress((int)(Math.Round(progress, 0)));
                    }

                    this.colCars.IsDirtyChanged += new EventHandler <EventArgs <bool> >(colCars_IsDirtyChanged);


                    if (errorsOnRead == true)
                    {
                        frmNR2003Ratings.ShowError("There were errors while reading the carfiles. Check the logbox at the bottom of the screen !");
                    }
                }
                else
                {
                    frmNR2003Ratings.ShowError(@"Cannot load cars: series does not contain a \cars subfolder !");
                    this.colCars = null;
                }
            }
            else
            {
                this.colCars = null;
            }
        }