Esempio n. 1
0
        public async Task <ActionResult> DeleteConfirmed(int id)
        {
            CropConditionNDVI cropConditionNDVI = await db.CropConditionNDVIs.FindAsync(id);

            db.CropConditionNDVIs.Remove(cropConditionNDVI);
            await db.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }
Esempio n. 2
0
        public async Task <ActionResult> Edit([Bind(Include = "Id,Date,catoid,CropConditionTypeId")] CropConditionNDVI cropConditionNDVI)
        {
            if (ModelState.IsValid)
            {
                db.Entry(cropConditionNDVI).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            ViewBag.catoid = new SelectList(db.CATOes, "Id", "AB", cropConditionNDVI.catoid);
            ViewBag.CropConditionTypeId = new SelectList(db.CropConditionTypes, "Id", "Name", cropConditionNDVI.CropConditionTypeId);
            return(View(cropConditionNDVI));
        }
Esempio n. 3
0
        public async Task <ActionResult> Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            CropConditionNDVI cropConditionNDVI = await db.CropConditionNDVIs.FindAsync(id);

            if (cropConditionNDVI == null)
            {
                return(HttpNotFound());
            }
            return(View(cropConditionNDVI));
        }
Esempio n. 4
0
        public async Task <ActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            CropConditionNDVI cropConditionNDVI = await db.CropConditionNDVIs.FindAsync(id);

            if (cropConditionNDVI == null)
            {
                return(HttpNotFound());
            }
            ViewBag.catoid = new SelectList(db.CATOes, "Id", "AB", cropConditionNDVI.catoid);
            ViewBag.CropConditionTypeId = new SelectList(db.CropConditionTypes, "Id", "Name", cropConditionNDVI.CropConditionTypeId);
            return(View(cropConditionNDVI));
        }
Esempio n. 5
0
        public ActionResult GetCropsConditionChartImage(int? Year, int? MonthStart, int? DayStart, /*int? MonthFinish, int? DayFinish, */int? CATOId, int? DatePosition)
        {
            if (CATOId == null)
            {
                return null;
            }

            DateTime Start = DateTime.Today;
            int? Month = MonthStart,
                Day = DayStart;
            try
            {
                Start = new DateTime((int)Year, (int)Month, (int)Day);
            }
            catch
            {
                for (int i = 0; i < 4; i++)
                {
                    try
                    {
                        Day--;
                        Start = new DateTime((int)Year, (int)Month, (int)Day);
                        break;
                    }
                    catch
                    {

                    }
                }
            }

            List<decimal> values= new List<decimal>();
            List<string> names = new List<string>();
            
            IList<DateTime> Dates = db.CropConditionNDVIs
                .Where(c => c.Date >= Start && c.Date.Year == Year)
                .Select(c => c.Date)
                .Distinct()
                .ToList();
            Dates = Dates.OrderBy(d => d.Date).ToList();
            DateTime Date = Dates[DatePosition == null ? 0 : (int) DatePosition];

            string title = db.CATOes
                .Where(c => c.Id == CATOId)
                .Select(c => c.Name)
                .ToList()
                .FirstOrDefault();

            foreach (CropConditionType cctype in db.CropConditionTypes.OrderBy(c => c.Max).ToList())
            {
                CropConditionNDVI ccNDVI = db.CropConditionNDVIs
                    .Where(c => c.catoid == CATOId && c.CropConditionTypeId == cctype.Id && c.Date == Date)
                    .Include(c => c.CropConditionType)
                    .FirstOrDefault();
                if(ccNDVI!=null)
                {
                    if(ccNDVI.Value > 0)
                    {
                        values.Add(ccNDVI.Value);
                        names.Add(ccNDVI.CropConditionType.Name);
                    }
                }
                
            }

            title += " (" + Date.ToShortDateString() + ")";

            string theme = "<Chart PaletteCustomColors=\"255,0,0; 255,127,39; 255,200,14; 181,230,29; 0,255,0; 34,177,76; 63,72,204\" BackColor=\"#C9DC87\" BackGradientStyle=\"TopBottom\" BorderColor=\"181, 64, 1\" BorderWidth=\"2\" BorderlineDashStyle=\"Solid\" Palette=\"None\">\r\n  <ChartAreas>\r\n    <ChartArea Name=\"Default\" _Template_=\"All\" BackColor=\"Transparent\" BackSecondaryColor=\"White\" BorderColor=\"64, 64, 64, 64\" BorderDashStyle=\"Solid\" ShadowColor=\"Transparent\">\r\n      <AxisY LineColor=\"64, 64, 64, 64\">\r\n        <MajorGrid Interval=\"Auto\" LineColor=\"64, 64, 64, 64\" />\r\n        <LabelStyle Font=\"Trebuchet MS, 8.25pt, style=Bold\" />\r\n      </AxisY>\r\n      <AxisX LineColor=\"64, 64, 64, 64\">\r\n        <MajorGrid LineColor=\"64, 64, 64, 64\" />\r\n        <LabelStyle Font=\"Trebuchet MS, 8.25pt, style=Bold\" />\r\n      </AxisX>\r\n      <Area3DStyle Inclination=\"15\" IsClustered=\"False\" IsRightAngleAxes=\"False\" Perspective=\"10\" Rotation=\"10\" WallWidth=\"0\" />\r\n    </ChartArea>\r\n  </ChartAreas>\r\n  <Legends>\r\n    <Legend _Template_=\"All\" Alignment=\"Center\" BackColor=\"Transparent\" Docking=\"Right\" Font=\"Trebuchet MS, 8.25pt, style=Bold\" IsTextAutoFit =\"True\" LegendStyle=\"Column\">\r\n    </Legend>\r\n  </Legends>\r\n  <BorderSkin SkinStyle=\"Emboss\" />\r\n</Chart>";
            var chart_CropsCondition = new Chart(width: 450, height: 350, theme: theme)
            .AddTitle(title)
            .AddSeries(
                chartType: "Pie",
                xValue: names,
                yValues: values)
            .AddLegend();

            return File(chart_CropsCondition.ToWebImage().GetBytes(), "image/jpeg");
        }