Exemple #1
0
        public List <Crop> predictCropsToGrow(int i_SiteID)
        {
            List <Crop> allAllowedCrops = new List <Crop>();

            using (EntitiesNegev4 context = new EntitiesNegev4())
            {
                CropRepository            cropRepo          = new CropRepository(context);
                List <Crop>               allCrops          = cropRepo.GetNegevEntityCollection() as List <Crop>;
                List <CropYearPair>       cropYearsPairs    = GetCropsBySiteId(i_SiteID);
                CropsConstrainsRepository cropConstrainRepo = new CropsConstrainsRepository(context);

                foreach (Crop crop in allCrops)
                {
                    bool allowGrow = true;

                    foreach (CropYearPair cyp in cropYearsPairs)
                    {
                        int allowedYears = GetYears(crop.ID, cyp._Crop.ID);
                        if (!determineIfCropAllowed(allowedYears, cyp.Year))
                        {
                            allowGrow = false;
                            break;
                        }
                    }

                    if (allowGrow)
                    {
                        allAllowedCrops.Add(crop);
                    }
                }
            }

            return(allAllowedCrops);
        }
Exemple #2
0
        public void mapExcel()
        {
            CropHendler m_CropHendler = new CropHendler(new GenericRepository <Crop>());
            var         filePath      = @"C:\Users\user\Desktop\excel\rawData.csv";
            var         data          = File.ReadLines(filePath).Select(x => x.Split(',')).ToArray();

            addAllMissingCrops(data[0]);
            int currentId;

            int[] ids = convertNamesToIds(data[0]);



            using (EntitiesNegev4 context = new EntitiesNegev4())
            {
                CropsConstrainsRepository cropsContains = new CropsConstrainsRepository(context);

                for (int i = 1; i < data.Length; i++)
                {
                    currentId = getCropIdByName(data[i][0]);

                    for (int j = 1; j < data[i].Length; j++)
                    {
                        CropConstrains cc = new CropConstrains();
                        cc.Crop1_Id   = currentId;
                        cc.Crop2_Id   = ids[j];
                        cc.NumOfYears = int.Parse(data[i][j]);

                        cropsContains.AddRow(cc);
                        cropsContains.Save();
                    }
                }
            }
        }
Exemple #3
0
        private void addCrop(string name)
        {
            using (EntitiesNegev4 context = new EntitiesNegev4())
            {
                CropRepository            crops         = new CropRepository(context);
                List <Crop>               cropsDataBase = crops.GetNegevEntityCollection() as List <Crop>;
                CropsConstrainsRepository ccrs          = new CropsConstrainsRepository(context);

                Crop c = new Crop();

                c.Name        = name;
                c.Quantity    = 0;
                c.SiteByYears = null;
                c.Description = "";
                crops.AddRow(c);
                crops.Save();
            }
        }