public void InitializeData()
        {
            // Initialize

            Fields = new ObservableCollection <Field>(pndatr == FileType.PND ? MainDataModel.ReadPNDDEFConfig() : MainDataModel.ReadATRDEFConfig());
        }
Esempio n. 2
0
        public void InitializeBaseData()
        {
            // Initialize

            Descriptions = new List <string>();
            Headers      = new List <string>();
            Data         = new ObservableCollection <List <object> >();
            Types        = new List <string>();
            ComboValues  = new List <List <string> >();

            // Read Data
            List <Field> fields = new List <Field>(fileType == FileType.PND ? MainDataModel.ReadPNDDEFConfig() : MainDataModel.ReadATRDEFConfig());

            foreach (Field f in fields)
            {
                Headers.Add(f.FieldName);
                Descriptions.Add(f.Description);
                Types.Add(f.Type);
                ComboValues.Add(f.ComboValues);
            }

            List <List <string> > records = fileType == FileType.PND ? MainDataModel.ReadPNDDEF() : MainDataModel.ReadATRDEF();

            foreach (List <string> strData in records)
            {
                if (strData.Count > Headers.Count)
                {
                    for (int i = Headers.Count; i < strData.Count; i++)
                    {
                        Headers.Add($"Unknown{i}");
                        Descriptions.Add($"Unknown{i}");
                        Types.Add("Text");
                    }
                }

                List <object> dataObjs = new List <object>(strData);

                for (int i = 0; i < strData.Count; i++)
                {
                    if (string.Equals(Types[i], "bool", StringComparison.OrdinalIgnoreCase))
                    {
                        dataObjs[i] = string.Equals(strData[i], "1", StringComparison.OrdinalIgnoreCase);
                    }
                }
                Data.Add(dataObjs);
            }

            if (Data.Count == 0)
            {
                List <object> dummyRecord = new List <object>();

                for (int i = 0; i < Headers.Count; i++)
                {
                    dummyRecord.Add(null);
                }

                Data.Add(dummyRecord);
            }

            Data.CollectionChanged += (s, e) => UpdateLocationIDs();

            if (fileType == FileType.PND)
            {
                LocationIDs = new List <int>();
                UpdateLocationIDs();
            }
        }