public JsonResult addNValues(Int16 indicatorID, Int16 fiscalYear)
        {
            var indicatorNValue = db.Indicators.FirstOrDefault(x => x.Indicator_N_Value == true && x.Indicator_N_Value_ID == indicatorID);
            var title = "N-Values: " + db.Indicators.FirstOrDefault(x => x.Indicator_ID == indicatorID).Indicator;
            if (indicatorNValue == null)
            {
                indicatorNValue = new Indicators()
                {
                    Indicator_N_Value = true,
                    Indicator_N_Value_ID = indicatorID,
                    Indicator = title
                };
                db.Indicators.Add(indicatorNValue);
                db.SaveChanges();
                ModelState.Clear();
            }
            var indicatorNValueMap = new Indicator_CoE_Maps(){
                Fiscal_Year = fiscalYear,
                CoE_ID = 0,
            };
            if (!db.Indicator_CoE_Maps.Any(x => x.Indicator.Indicator_N_Value_ID == indicatorID && x.Fiscal_Year == fiscalYear))
            {
                indicatorNValueMap.Indicator_ID = indicatorNValue.Indicator_ID;
                db.Indicator_CoE_Maps.Add(indicatorNValueMap);
                db.SaveChanges();
            }

            return Json(new { indicatorID = indicatorNValue.Indicator_ID, mapID = indicatorNValueMap.Map_ID, coeID = indicatorNValueMap.CoE_ID, areaID = indicatorNValueMap.Indicator.Area_ID }, JsonRequestBehavior.AllowGet);
        }
        public ActionResult Create(Indicators indicators)
        {
            if (ModelState.IsValid)
            {
                db.Indicators.Add(indicators);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            return View(indicators);
        }
 public ActionResult Edit(Indicators indicators)
 {
     if (ModelState.IsValid)
     {
         db.Entry(indicators).State = EntityState.Modified;
         db.SaveChanges();
         return RedirectToAction("Index");
     }
     return View(indicators);
 }
Esempio n. 4
0
        public static string getThreshold(String inTarget, Indicators inIndicator, Int16? Threshold_ID, Int16? Direction_ID, Int16 Fiscal_Year)
        {
            string str;
            float outScore;
            string Target = inTarget;

            if (Target == "-") { return "-"; }

            str = Color.getNum(Target);
            if (str == null) { return "TBD"; }

            var direction = ">";
            if (Target != null){
                if (Target.Length != 0) {
                    var sign = Target.Substring(0,1);
                    direction = sign;
                }
            }

            if (float.TryParse(str, out outScore)) { }
            else if (str != null && str.Length != 0 && str.IndexOf(":") != -1) { outScore = float.Parse(str.Replace(":", "")); }
            float targetScore = outScore;

            if (targetScore == 0) { return "-"; }

            double threshold_high = 1.1;
            double threshold_low = 0.9;
            if (Threshold_ID == 2)
            {
                threshold_high = 1.01;
                threshold_low = 0.99;
            }

            /*
            var direction = ">";
            if (Direction_ID == 2)
            {
                direction = "≥";
            }
            else if (Direction_ID == 3)
            {
                direction = "<";
            }
            else if (Direction_ID == 4)
            {
                direction = "≤";
            }*/

            if (Target != null)
            {
                if (Target.IndexOf("%") != -1) { targetScore = targetScore / 100; }
                if (direction == "≤" || direction == "<")
                {
                    if (inIndicator.Format != null)
                    {
                        if (inIndicator.Format.Format_Code_C == "T")
                        {
                            return TimeSpan.FromHours(targetScore * threshold_high).ToString("h\\:mm");
                        }
                    }
                    return (targetScore * threshold_high).ToString(inIndicator.Format != null ? inIndicator.Format.Format_Code_C : "");
                }
                else if (direction == "≥" || direction == ">")
                {

                    if (inIndicator.Format != null)
                    {
                        if (inIndicator.Format.Format_Code_C == "T")
                        {
                            return TimeSpan.FromHours(targetScore * threshold_low).ToString("h\\:mm");
                        }
                    }
                    return (targetScore * threshold_low).ToString(inIndicator.Format != null ? inIndicator.Format.Format_Code_C : "");
                }
                else
                {
                    return "TBD";
                }
            }
            else
            {
                return "";
            }
        }
Esempio n. 5
0
        public static String getColor(String inStr, String inTarget, String inMonth, String inCustom, Int16 Color_ID, Boolean isYTD, Indicators inIndicator, Int16? Threshold_ID, Int16? Direction_ID, Int16 Fiscal_Year)
        {
            string str;
            float outScore;
            string Target = inTarget;

            double threshold_high = 1.1;
            double threshold_low = 0.9;
            if (Threshold_ID == 2)
            {
                threshold_high = 1.01;
                threshold_low = 0.99;
            }

            if (Color_ID == 3)
            {
                return String.IsNullOrEmpty(inCustom) ? "cssWhite" : inCustom;
            }

            var direction = ">";
            if (Direction_ID == 2)
            {
                direction = "≥";
            }
            else if (Direction_ID == 3)
            {
                direction = "<";
            }
            else if (Direction_ID == 4)
            {
                direction = "≤";
            }

            if (inStr != null) inStr = inStr.Replace("%", "");

            str = Color.getNum(inStr);
            if (str == null) { return "cssWhite"; }
            if (float.TryParse(str, out outScore)) { }
            else if (str != null && str.Length != 0 && str.IndexOf(":") != -1) { outScore = float.Parse(str.Replace(":", "")); }
            float score = outScore;

            str = Color.getNum(Target);
            if (str == null) { return "cssWhite"; }
            if (float.TryParse(str, out outScore)) { }
            else if (str != null && str.Length != 0 && str.IndexOf(":") != -1) { outScore = float.Parse(str.Replace(":", "")); }
            float targetScore = outScore;

            if (Color_ID == 0) { return "cssWhite"; }

            if (Color_ID == 2 || Color_ID == 4)
            {
                if (isYTD == false)
                {
                    switch (inMonth)
                    {
                        case "Apr": score *= 12 / 1; break;
                        case "May": score *= 12 / 2; break;
                        case "Jun": score *= 12 / 3; break;
                        case "Jul": score *= 12 / 1; break;
                        case "Aug": score *= 12 / 2; break;
                        case "Sep": score *= 12 / 3; break;
                        case "Oct": score *= 12 / 1; break;
                        case "Nov": score *= 12 / 2; break;
                        case "Dec": score *= 12 / 3; break;
                        case "Jan": score *= 12 / 1; break;
                        case "Feb": score *= 12 / 2; break;
                        case "Mar": score *= 12 / 3; break;
                        default: score *= 12 / 3; break;
                    }
                }
                else
                {
                    int numMonths = 0;
                    if (Fiscal_Year == 2)
                    {
                        if (Color.getNum(inIndicator.FY_14_15_Q1) != null)
                        {
                            if (float.TryParse(Color.getNum(inIndicator.FY_14_15_Q1), out outScore))
                            {
                                switch (inIndicator.FY_14_15_Q1_Sup)
                                {
                                    case "Apr": numMonths += 1; break;
                                    case "May": numMonths += 2; break;
                                    case "Jun": numMonths += 3; break;
                                    default: numMonths += 3; break;
                                }
                            }
                        }
                        if (Color.getNum(inIndicator.FY_14_15_Q2) != null)
                        {
                            if (float.TryParse(Color.getNum(inIndicator.FY_14_15_Q2), out outScore))
                            {
                                switch (inIndicator.FY_14_15_Q2_Sup)
                                {
                                    case "Jul": numMonths += 1; break;
                                    case "Aug": numMonths += 2; break;
                                    case "Sep": numMonths += 3; break;
                                    default: numMonths += 3; break;
                                }
                            }
                        }
                        if (Color.getNum(inIndicator.FY_14_15_Q3) != null)
                        {
                            if (float.TryParse(Color.getNum(inIndicator.FY_14_15_Q3), out outScore))
                            {
                                switch (inIndicator.FY_14_15_Q3_Sup)
                                {
                                    case "Oct": numMonths += 1; break;
                                    case "Nov": numMonths += 2; break;
                                    case "Dec": numMonths += 3; break;
                                    default: numMonths += 3; break;
                                }
                            }
                        }
                        if (Color.getNum(inIndicator.FY_14_15_Q4) != null)
                        {
                            if (float.TryParse(Color.getNum(inIndicator.FY_14_15_Q4), out outScore))
                            {
                                switch (inIndicator.FY_14_15_Q4_Sup)
                                {
                                    case "Jan": numMonths += 1; break;
                                    case "Feb": numMonths += 2; break;
                                    case "Mar": numMonths += 3; break;
                                    default: numMonths += 3; break;
                                }
                            }
                        }
                    }
                    if (Fiscal_Year == 3)
                    {
                        if (Color.getNum(inIndicator.FY_15_16_Q1) != null)
                        {
                            if (float.TryParse(Color.getNum(inIndicator.FY_15_16_Q1), out outScore))
                            {
                                switch (inIndicator.FY_15_16_Q1_Sup)
                                {
                                    case "Apr": numMonths += 1; break;
                                    case "May": numMonths += 2; break;
                                    case "Jun": numMonths += 3; break;
                                    default: numMonths += 3; break;
                                }
                            }
                        }
                        if (Color.getNum(inIndicator.FY_15_16_Q2) != null)
                        {
                            if (float.TryParse(Color.getNum(inIndicator.FY_15_16_Q3), out outScore))
                            {
                                switch (inIndicator.FY_15_16_Q2_Sup)
                                {
                                    case "Jul": numMonths += 1; break;
                                    case "Aug": numMonths += 2; break;
                                    case "Sep": numMonths += 3; break;
                                    default: numMonths += 3; break;
                                }
                            }
                        }
                        if (Color.getNum(inIndicator.FY_15_16_Q3) != null)
                        {
                            if (float.TryParse(Color.getNum(inIndicator.FY_15_16_Q3), out outScore))
                            {
                                switch (inIndicator.FY_15_16_Q3_Sup)
                                {
                                    case "Oct": numMonths += 1; break;
                                    case "Nov": numMonths += 2; break;
                                    case "Dec": numMonths += 3; break;
                                    default: numMonths += 3; break;
                                }
                            }
                        }
                        if (Color.getNum(inIndicator.FY_15_16_Q4) != null)
                        {
                            if (float.TryParse(Color.getNum(inIndicator.FY_15_16_Q4), out outScore))
                            {
                                switch (inIndicator.FY_15_16_Q4_Sup)
                                {
                                    case "Jan": numMonths += 1; break;
                                    case "Feb": numMonths += 2; break;
                                    case "Mar": numMonths += 3; break;
                                    default: numMonths += 3; break;
                                }
                            }
                        }
                    }
                    if (numMonths == 0) { numMonths = 1; }
                    score /= numMonths;
                    score *= 12;
                }
            }

            if (Color_ID != 4 && Color_ID != 5)
            {
                if (Target != null)
                {
                    if (direction == "≤")
                    {
                        if (score <= targetScore)
                        {
                            return "cssGreen";
                        }
                        else
                        {
                            if (score <= targetScore * threshold_high)
                            {
                                return "cssYellow";
                            }
                            else
                            {
                                return "cssRed";
                            }
                        }
                    }
                    else if (direction == "<")
                    {
                        if (score < targetScore)
                        {
                            return "cssGreen";
                        }
                        else
                        {
                            if (score < targetScore * threshold_high)
                            {
                                return "cssYellow";
                            }
                            else
                            {
                                return "cssRed";
                            }
                        }
                    }
                    else if (direction == ">")
                    {
                        if (score > targetScore)
                        {
                            return "cssGreen";
                        }
                        else
                        {
                            if (score > targetScore * threshold_low)
                            {
                                return "cssYellow";
                            }
                            else
                            {
                                return "cssRed";
                            }
                        }
                    }
                    else
                    {
                        if (score >= targetScore)
                        {
                            return "cssGreen";
                        }
                        else
                        {
                            if (score >= targetScore * threshold_low)
                            {
                                return "cssYellow";
                            }
                            else
                            {
                                return "cssRed";
                            }
                        }
                    }
                }
                else
                {
                    return "cssWhite";
                }
            }
            else
            {
                if (Target != null)
                {
                    if (direction == ">" || direction == "≥")
                    {
                        if (score < targetScore)
                        {
                            return "cssRed";
                        }
                        else if (score > targetScore * (((threshold_high * 100) + 1) / 100))
                        {
                            return "cssRed";
                        }
                        else if (score >= targetScore * threshold_high && score <= targetScore * (((threshold_high * 100) + 1) / 100))
                        {
                            return "cssYellow";
                        }
                        else if (score > targetScore)
                        {
                            return "cssGreen";
                        }
                        else
                        {
                            return "cssRed";
                        }
                    }
                    else
                    {
                        if (score > targetScore)
                        {
                            return "cssRed";
                        }
                        else if (score < targetScore * (((threshold_high * 100) + 1) / 100))
                        {
                            return "cssRed";
                        }
                        else if (score <= targetScore * threshold_low && score >= targetScore * (((threshold_low * 100) - 1) / 100))
                        {
                            return "cssYellow";
                        }
                        else if (score < targetScore)
                        {
                            return "cssGreen";
                        }
                        else
                        {
                            return "cssRed";
                        }
                    }
                }
                else
                {
                    return "cssWhite";
                }
            }
        }
        public JsonResult newIndicatorAtPR(Int16 fiscalYear, Int16 areaID, Int16 coeID, Int16 indicatorID, Int16? newIndicatorID)
        {
            Indicators indicator = new Indicators();

            if (newIndicatorID.HasValue)
            {
                indicator = db.Indicators.FirstOrDefault(x => x.Indicator_ID == newIndicatorID);
            }
            else
            {
                indicator = new Indicators();
                indicator.Area_ID = areaID;
                indicator.Indicator = "";
                db.Indicators.Add(indicator);
                db.SaveChanges();
            }

            var newMap = new Indicator_CoE_Maps();
            newMap.Indicator_ID = indicator.Indicator_ID;

            int number = 0;
            if (indicatorID != 0)
            {
                number = db.Indicator_CoE_Maps.Where(x => x.CoE_ID == coeID && x.Fiscal_Year == x.Fiscal_Year).FirstOrDefault(x => x.Indicator_ID == indicatorID).Number + 1;
            }
            newMap.Number = (Int16)number;

            var allMaps = db.Indicator_CoE_Maps.ToList();
            foreach (var map in allMaps.OrderBy(x => x.Number).Where(x => x.CoE_ID == coeID && x.Fiscal_Year == x.Fiscal_Year && x.Number >= number))
            {
                map.Number++;
                db.Entry(map).State = EntityState.Modified;
                db.SaveChanges();
            }
            newMap.CoE_ID = coeID;
            newMap.Fiscal_Year = fiscalYear;
            db.Indicator_CoE_Maps.Add(newMap);
            db.SaveChanges();

            return Json(new { indicatorID = indicator.Indicator_ID, mapID = newMap.Map_ID, newAreaID = indicator.Area_ID }, JsonRequestBehavior.AllowGet);
        }
        public ActionResult editCoEs(String CoE_ID_Filter)
        {
            var viewModelItems = db.CoEs.ToArray();
            var viewModel = viewModelItems.OrderBy(x => x.CoE_ID).Select(x => new CoEsViewModel
            {
                CoE_ID = x.CoE_ID,
                CoE = x.CoE,
                CoE_Abbr = x.CoE_Abbr,
                CoE_Notes = x.CoE_Notes,
                CoE_Subtitle = x.CoE_Subtitle,
                CoE_Type = x.CoE_Type,
                CoE_Title = x.CoE_Title
            }).ToList();
            if (Request.IsAjaxRequest())
            {
                if (CoE_ID_Filter == "")
                {
                    var newCoE = db.CoEs.Create();
                    newCoE.CoE_Abbr = "";
                    db.CoEs.Add(newCoE);
                    db.SaveChanges();

                    var newIndicator = new Indicators();
                    var newAreaCoEMap = new Area_CoE_Maps();
                    var newIndicatorCoEMap = new Indicator_CoE_Maps();

                    var allFiscalYear = db.Fiscal_Years.ToList();
                    var allAreas = db.Areas.ToList();
                    foreach (var fiscalYear in allFiscalYear)
                    {
                        foreach (var area in allAreas)
                        {
                            for (var i = 1; i <= 5; i++)
                            {
                                newIndicator = db.Indicators.Create();
                                db.Indicators.Add(newIndicator);
                                db.SaveChanges();
                                newIndicator.Area_ID = area.Area_ID;
                                db.Entry(newIndicator).State = EntityState.Modified;
                                db.SaveChanges();

                                newIndicatorCoEMap = new Indicator_CoE_Maps
                                {
                                    CoE_ID = newCoE.CoE_ID,
                                    Fiscal_Year = fiscalYear.Fiscal_Year_Code,
                                    Indicator_ID = newIndicator.Indicator_ID
                                };
                                db.Indicator_CoE_Maps.Add(newIndicatorCoEMap);
                                db.SaveChanges();
                            }
                            newAreaCoEMap = new Area_CoE_Maps{
                                Area_ID = area.Area_ID,
                                CoE_ID = newCoE.CoE_ID,
                                Fiscal_Year = fiscalYear.Fiscal_Year_Code,
                                Objective = ""
                            };
                            db.Area_CoE_Maps.Add(newAreaCoEMap);
                            db.SaveChanges();
                        }
                    }

                    viewModel = new List<CoEsViewModel>();
                    var newViewModelItem = new CoEsViewModel
                    {
                        CoE_ID = newCoE.CoE_ID,
                        CoE = newCoE.CoE,
                        CoE_Abbr = newCoE.CoE_Abbr,
                        CoE_Notes = newCoE.CoE_Notes,
                        CoE_Subtitle = newCoE.CoE_Subtitle,
                        CoE_Type = newCoE.CoE_Type,
                        CoE_Title = newCoE.CoE_Title
                    };
                    viewModel.Add(newViewModelItem);

                    return Json(viewModel, JsonRequestBehavior.AllowGet);
                }
                else
                {
                    return Json(viewModel.Where(x => x.CoE_ID.ToString().Contains(CoE_ID_Filter == null ? "" : CoE_ID_Filter)), JsonRequestBehavior.AllowGet);
                }
            }
            else
            {
                return View(viewModel);
            }
        }
        public JsonResult newIndicatorAtPRdbl(Int16 fiscalYear, Int16 areaID, Int16 coeID, Int16 coeID2)
        {
            Indicators indicator = new Indicators();
            Indicators indicator2 = new Indicators();

            indicator = db.Indicators.Create();
            indicator2 = db.Indicators.Create();
            db.Indicators.Add(indicator);
            db.Indicators.Add(indicator2);
            db.SaveChanges();
            indicator.Area_ID = areaID;
            indicator2.Area_ID = areaID;

            var type = indicator.GetType();
            var property = type.GetProperty(Helpers.FiscalYear.FYStrFull("FY_Color_ID", fiscalYear));
            property.SetValue(indicator, Convert.ChangeType(1, property.PropertyType), null);
            var type2 = indicator2.GetType();
            var property2 = type.GetProperty(Helpers.FiscalYear.FYStrFull("FY_Color_ID", fiscalYear));
            property2.SetValue(indicator2, Convert.ChangeType(1, property2.PropertyType), null);

            indicator.Indicator = "";
            indicator.Indicator_Link = indicator2.Indicator_ID;
            db.Entry(indicator).State = EntityState.Modified;
            db.SaveChanges();
            indicator2.Indicator = "";
            indicator2.Indicator_Link = indicator.Indicator_ID;
            db.Entry(indicator2).State = EntityState.Modified;
            db.SaveChanges();

            var newMap = new Indicator_CoE_Maps();
            newMap.Indicator_ID = indicator.Indicator_ID;
            newMap.CoE_ID = coeID;
            newMap.Fiscal_Year = fiscalYear;
            db.Indicator_CoE_Maps.Add(newMap);
            db.SaveChanges();

            var newMap2 = new Indicator_CoE_Maps();
            newMap2.Indicator_ID = indicator2.Indicator_ID;
            newMap2.CoE_ID = coeID2;
            newMap2.Fiscal_Year = fiscalYear;
            db.Indicator_CoE_Maps.Add(newMap2);
            db.SaveChanges();

            var colorID = (Int16)newMap.Indicator.GetType().GetProperty(FiscalYear.FYStrFull("FY_", fiscalYear) + "Color_ID").GetValue(newMap.Indicator, null);

            return Json(new { indicatorID = indicator.Indicator_ID, mapID = newMap.Map_ID, newAreaID = indicator.Area_ID, colorID = colorID,
                              indicatorID2 = indicator2.Indicator_ID, mapID2 = newMap2.Map_ID, newAreaID2 = indicator2.Area_ID, colorID2 = colorID
                            }, JsonRequestBehavior.AllowGet);
        }
        public JsonResult newIndicatorAtPR(Int16 fiscalYear, Int16 areaID, Int16 coeID, Int16 indicatorID, Int16? newIndicatorID)
        {
            Indicators indicator = new Indicators();

            if (newIndicatorID.HasValue)
            {
                indicator = db.Indicators.FirstOrDefault(x => x.Indicator_ID == newIndicatorID);
            }
            else
            {
                indicator = db.Indicators.Create();//new Indicators();
                db.Indicators.Add(indicator);
                db.SaveChanges();
                indicator.Area_ID = areaID;

                var type = indicator.GetType();
                var property = type.GetProperty(Helpers.FiscalYear.FYStrFull("FY_Color_ID", fiscalYear));
                property.SetValue(indicator, Convert.ChangeType(1, property.PropertyType), null);

                indicator.Indicator = "";
                db.Entry(indicator).State = EntityState.Modified;
                //db.Indicators.Add(indicator);
                db.SaveChanges();
            }

            var newMap = new Indicator_CoE_Maps();
            newMap.Indicator_ID = indicator.Indicator_ID;

            int number = 0;
            if (indicatorID != 0)
            {
                if (db.Indicator_CoE_Maps.Where(x => x.CoE_ID == coeID && x.Fiscal_Year == fiscalYear).FirstOrDefault(x => x.Indicator_ID == indicatorID) != null)
                {
                    number = db.Indicator_CoE_Maps.Where(x => x.CoE_ID == coeID && x.Fiscal_Year == fiscalYear).FirstOrDefault(x => x.Indicator_ID == indicatorID).Number + 1;
                }
                else
                {
                    number = 0;
                }
            }
            newMap.Number = (Int16)number;

            var allMaps = db.Indicator_CoE_Maps.ToList();
            foreach (var map in allMaps.OrderBy(x => x.Number).Where(x => x.CoE_ID == coeID && x.Fiscal_Year == x.Fiscal_Year && x.Number >= number))
            {
                map.Number++;
                db.Entry(map).State = EntityState.Modified;
                db.SaveChanges();
            }
            newMap.CoE_ID = coeID;
            newMap.Fiscal_Year = fiscalYear;
            db.Indicator_CoE_Maps.Add(newMap);
            db.SaveChanges();

            var colorID = (Int16)newMap.Indicator.GetType().GetProperty(FiscalYear.FYStrFull("FY_", fiscalYear) + "Color_ID").GetValue(newMap.Indicator, null);

            return Json(new { indicatorID = indicator.Indicator_ID, mapID = newMap.Map_ID, newAreaID = indicator.Area_ID, colorID = colorID}, JsonRequestBehavior.AllowGet);
        }