Пример #1
0
        /// <summary>
        /// Retrieve the first ApplicationDataModel from the list of discovered data models at the source location.
        /// Set the DataModel property with this value. If successful, build the GrowerTree collection from the
        /// information in the DataModel.
        /// </summary>
        /// <returns></returns>
        private static ApplicationDataModel LoadAdaptDataModel()
        {
            var models = AdmPlugin.Import(SourcePath);

            if (models.Count > 0)
            {
                DataModel  = models[0];
                GrowerTree = new GrowerTree(DataModel);
                GrowerTree.BuildFromCropZones();
            }
            else
            {
                throw new Exception($"There were no ADAPT Application Data Models found at {SourcePath}.");
            }

            return(DataModel);
        }
Пример #2
0
        /// <summary>
        /// Displays a list of Growers and Farms within the DataModel.
        /// For each Grower and Farm a list of Fields, Crops, Seasons and Area within the field is also listed.
        /// </summary>
        private static void ListActiveCropZones()
        {
            var list = GrowerTree.Select(g => g);

            if (UseGrowerId != 0)
            {
                list = list.Where(g => g.GrowerId == UseGrowerId);
            }
            if (UseFarmId != 0)
            {
                list = list.Where(g => g.FarmId == UseFarmId);
            }
            if (UseFieldId != 0)
            {
                list = list.Where(g => g.FieldId == UseFieldId);
            }
            if (UseCropId != 0)
            {
                list = list.Where(g => g.CropId == UseCropId);
            }
            if (!string.IsNullOrEmpty(UseCropSeason))
            {
                list = list.Where(g => g.CropSeason.Description == UseCropSeason);
            }

            var group = list.OrderBy(g => g.GrowerName)
                        .ThenBy(g => g.FarmName)
                        .ThenBy(g => g.FieldName)
                        .ThenBy(g => g.CropName)
                        .GroupBy(g => new { g.GrowerName, g.FarmName });

            foreach (var g in group)
            {
                Console.WriteLine($"GROWER: {g.Key.GrowerName}\tFARM: {g.Key.FarmName}");
                foreach (var n in g)
                {
                    Console.WriteLine($"\tFIELD: {n.FieldName}\tCROP: {n.CropName}\tSEASON: {n.CropSeason?.Description}\tAREA: {Math.Round(n.ZoneArea,2)}");
                }
                Console.WriteLine();
            }
            Console.ReadKey();
        }
Пример #3
0
        /// <summary>
        /// Ask if the user is interested in limiting the output to this item and if so, display
        /// the distinct possibilities and ask him to choose.
        /// </summary>
        /// <param name="item"></param>
        /// <returns></returns>
        private static string ChooseLimitingId(string item)
        {
            string result = (item == "CropSeason")? string.Empty: "0";
            var    list   = new List <Tuple <int, int?, string> >();
            int    count  = 0;

            Console.WriteLine($"Would you like to limit the output by a specific {item}? (Y/N)");
            var keyChar = Console.ReadKey().KeyChar;

            Console.WriteLine();
            Console.WriteLine();
            if (keyChar != 'Y' && keyChar != 'y')
            {
                return(result);
            }

            switch (item)
            {
            case "Grower":
                GrowerTree.Select(g => new { Id = g.GrowerId, Name = g.GrowerName })
                .Distinct()
                .ToList()
                .ForEach(d => { list.Add(new Tuple <int, int?, string>(++count, d.Id, d.Name)); });
                break;

            case "Farm":
                GrowerTree.Select(g => new { Id = g.FarmId, Name = g.FarmName })
                .Distinct()
                .ToList()
                .ForEach(d => { list.Add(new Tuple <int, int?, string>(++count, d.Id, d.Name)); });
                break;

            case "Field":
                GrowerTree.Select(g => new { Id = g.FieldId, Name = g.FieldName })
                .Distinct()
                .ToList()
                .ForEach(d => { list.Add(new Tuple <int, int?, string>(++count, d.Id, d.Name)); });
                break;

            case "Crop":
                GrowerTree.Select(g => new { Id = g.CropId, Name = g.CropName })
                .Distinct()
                .ToList()
                .ForEach(d => { list.Add(new Tuple <int, int?, string>(++count, d.Id, d.Name)); });
                break;

            case "CropSeason":
                GrowerTree.Select(g => new { Id = 0, Name = g.CropSeason.Description })
                .Distinct()
                .ToList()
                .ForEach(d => { list.Add(new Tuple <int, int?, string>(++count, d.Id, d.Name)); });
                break;
            }
            foreach (var l in list)
            {
                Console.WriteLine($"{l.Item1}.\t{l.Item3}");
            }
            Console.WriteLine($"Select the number of the {item} to limit the output.");
            int line = Convert.ToInt32(Console.ReadLine());

            Console.WriteLine();
            Console.WriteLine();

            if (item != "CropSeason")
            {
                result = list.Where(l => l.Item1 == line)
                         .Select(l => l.Item2)
                         .DefaultIfEmpty(0)
                         .FirstOrDefault()
                         .ToString();
            }
            else
            {
                result = list.Where(l => l.Item1 == line)
                         .Select(l => l.Item3)
                         .DefaultIfEmpty(string.Empty)
                         .FirstOrDefault()
                         .ToString();
            }
            return(result);
        }