Example #1
0
        private void DataGridViewAircraft_CellValueChanged(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex >= 0)
            {
                DataGridViewRow row = dataGridViewAircraft.Rows[e.RowIndex];
                if (String.IsNullOrWhiteSpace((string)row.Cells[0].FormattedValue) && String.IsNullOrWhiteSpace((string)row.Cells[1].FormattedValue) && String.IsNullOrWhiteSpace((string)row.Cells[2].FormattedValue) && String.IsNullOrWhiteSpace((string)row.Cells[3].FormattedValue) && String.IsNullOrWhiteSpace((string)row.Cells[4].FormattedValue))
                {
                    dataGridViewAircraft.Rows.Remove(row);
                }
                else
                {
                    row.DefaultCellStyle.ForeColor = Color.Red;

                    bool found = false;
                    foreach (Aircraft_Type at in userOverrides.aircraft_types)
                    {
                        if (String.Equals(at.type, row.Cells[0].Value))
                        {
                            at.tags.manufacturer = (string)row.Cells[1].Value;
                            //at.tags.size = row.Cells[2] != null && row.Cells[2].Value != null ? (Int32)row.Cells[2].Value : 0;
                            if (int.TryParse((string)row.Cells[2].FormattedValue, out int size))
                            {
                                at.tags.size = size;
                            }
                            else
                            {
                                row.Cells[2].Value = at.tags.size;
                            }
                            at.tags.engine = (string)row.Cells[3].Value;
                            at.regex       = (string)row.Cells[4].Value;
                            found          = true;
                        }
                    }
                    if (!found)
                    {
                        Aircraft_Type at = new Aircraft_Type();
                        at.type = (string)row.Cells[0].Value;
                        at.tags = new Tags();
                        at.tags.manufacturer = (string)row.Cells[1].Value;
                        //at.tags.size = row.Cells[2] != null && row.Cells[2].Value != null ? (Int32)row.Cells[2].Value : 0;
                        if (int.TryParse((string)row.Cells[2].FormattedValue, out int size))
                        {
                            at.tags.size = size;
                        }
                        else
                        {
                            row.Cells[2].Value = at.tags.size = 10;
                        }
                        at.tags.engine = (string)row.Cells[3].Value;
                        at.regex       = (string)row.Cells[4].Value;
                        userOverrides.aircraft_types.Add(at);
                    }
                }

                SaveUserOverrides();
            }
        }
Example #2
0
 private void CheckSimilarAircraft(Aircraft_Type aircraftType, SortedDictionary <string, List <string> > typeMappings, bool testManufacturer, bool testSize, bool testEngine, List <string> matchingModels)
 {
     if (matchingModels.Count == 0)
     {
         foreach (Aircraft_Type matchingAircraftType in mmm.aircraft_types)
         {
             if (aircraftType.type != matchingAircraftType.type &&
                 (String.Equals(aircraftType.tags.manufacturer, matchingAircraftType.tags.manufacturer) == testManufacturer) &&
                 (String.Equals(aircraftType.tags.size, matchingAircraftType.tags.size) == testSize) &&
                 (String.Equals(aircraftType.tags.engine, matchingAircraftType.tags.engine) == testEngine))
             {
                 if (typeMappings.TryGetValue(matchingAircraftType.type, out List <string> models))
                 {
                     matchingModels.AddRange(models);
                 }
             }
         }
     }
 }
Example #3
0
        private void WriteMatchRules(string airline, SortedDictionary <string, List <string> > typeMappings, XmlWriter writer)
        {
            foreach (KeyValuePair <string, List <string> > typeMapping in typeMappings)
            {
                WriteMatchRule(airline, typeMapping.Key, typeMapping.Value, writer);
            }

            foreach (DataGridViewRow row in dataGridViewAircraft.Rows)
            {
                Aircraft_Type at = new Aircraft_Type();
                at.type = (string)row.Cells[0].Value;
                at.tags = new Tags();
                at.tags.manufacturer = (string)row.Cells[1].Value;
                //at.tags.size = row.Cells[2] != null && row.Cells[2].Value != null ? (Int32)row.Cells[2].Value : 0;
                if (int.TryParse((string)row.Cells[2].FormattedValue, out int size))
                {
                    at.tags.size = size;
                }
                else
                {
                    at.tags.size = 10;
                }
                at.tags.engine = (string)row.Cells[3].Value;

                if (!String.IsNullOrWhiteSpace(at.type) && !typeMappings.ContainsKey(at.type))
                {
                    List <string> matchingModels = new List <string>();

                    CheckSimilarAircraft(at, typeMappings, true, true, true, matchingModels);
                    CheckSimilarAircraft(at, typeMappings, false, true, true, matchingModels);
                    CheckSimilarAircraft(at, typeMappings, true, false, true, matchingModels);
                    CheckSimilarAircraft(at, typeMappings, false, false, true, matchingModels);

                    if (matchingModels.Count > 0)
                    {
                        WriteMatchRule(airline, at.type, matchingModels, writer);
                    }
                }
            }
        }