private string DowntimeActualVsGoal()
        {
            bool isHome = !string.IsNullOrEmpty(Request.Form["isHome"]);
            DateTime? startDate = null;
            DateTime? endDate = null;
            DateTime d;
            if (DateTime.TryParse(Request.Form["startdate"], out d))
            {
                startDate = d;
            }
            if (DateTime.TryParse(Request.Form["enddate"], out d))
            {
                endDate = d;
            }
            int goal = 10;
            if (!int.TryParse(Request.Form["goal"], out goal)) goal = 0;

            int width = 500;
            int height = 300;
            int.TryParse(Request.Form["width"], out width);
            int.TryParse(Request.Form["height"], out height);
            string level1 = Request.Form["level1"];
            string type = Request.Form["type"];
            if (string.IsNullOrEmpty(type)) type = "day";
            bool isEvents = false;
            if (!bool.TryParse(Request.Form["isEvents"], out isEvents)) isEvents = true;


            GoalReportRow grr = new GoalReportRow();

            if (DetailId.HasValue)
            {
                grr = DBHelper.GetGoals(startDate, endDate, DetailId.Value, level1, 0, Line);

            }
            else
            {
                grr = DCSDashboardDemoHelper.GetGoals(startDate, endDate, level1, 0, Line);
            }

            List<SpecialReportRow> rows = null;
            switch (type.ToLower())
            {
                case "hours":
                    if(DetailId.HasValue)
                        rows = DBHelper.HoursReport(startDate, endDate, DetailId.Value, level1, Line);
                    else
                        rows = DCSDashboardDemoHelper.HoursReport(startDate, endDate, level1, Line);

                    goal = (isEvents ? Convert.ToInt32(grr.Downtimes.Hour) : grr.Occurences.Hour);
                    break;
                case "day":
                    if(DetailId.HasValue)
                        rows = DBHelper.DayReport(startDate, endDate, DetailId.Value, level1, Line);
                    else
                        rows = DCSDashboardDemoHelper.DayReport(startDate, endDate, level1, Line);

                    goal = (isEvents ? Convert.ToInt32(grr.Downtimes.Day) : grr.Occurences.Day);
                    break;
                case "week":
                    if(DetailId.HasValue)
                        rows = DBHelper.WeekReport(startDate, endDate, DetailId.Value, level1, Line);
                    else
                        rows = DCSDashboardDemoHelper.WeekReport(startDate, endDate, level1, Line);

                    goal = (isEvents ? Convert.ToInt32(grr.Downtimes.Week) : grr.Occurences.Week);
                    break;
                case "month":
                    if(DetailId.HasValue)
                        rows = DBHelper.MonthReport(startDate, endDate, DetailId.Value, level1, Line);
                    else
                        rows = DCSDashboardDemoHelper.MonthReport(startDate, endDate, level1, Line);

                    goal = (isEvents ? Convert.ToInt32(grr.Downtimes.Month) : grr.Occurences.Month);
                    break;
                case "year":
                    if(DetailId.HasValue)
                        rows = DBHelper.YearReport(startDate, endDate, DetailId.Value, level1, Line);
                    else
                        rows = DCSDashboardDemoHelper.YearReport(startDate, endDate, level1, Line);

                    goal = (isEvents ? Convert.ToInt32(grr.Downtimes.Year) : grr.Occurences.Year);
                    break;
                default:
                    if(DetailId.HasValue)
                        rows = DBHelper.DayReport(startDate, endDate, DetailId.Value, level1, Line);
                    else
                        rows = DCSDashboardDemoHelper.DayReport(startDate, endDate, level1, Line);

                    goal = (isEvents ? Convert.ToInt32(grr.Downtimes.Day) : grr.Occurences.Day);
                    break;

            }

            StringBuilder sb = new StringBuilder();
            sb.AppendLine("<vc:Chart xmlns:vc=\"clr-namespace:Visifire.Charts;assembly=SLVisifire.Charts\" Width=\"" + width.ToString() + "\" Height=\"" + height.ToString() + "\"  Theme=\"Theme1\" AnimatedUpdate=\"true\" AnimationEnabled=\"true\" View3D=\"True\"  ShadowEnabled=\"true\" CornerRadius=\"12\" DataPointWidth=\"15\" BorderThickness=\"0.5\" BorderBrush=\"Gray\" Padding=\"5,5,10,5\">");
            sb.AppendLine("<vc:Chart.Titles>");
            //sb.AppendLine("<vc:Title Text=\"" + (isEvents ? "Downtime Actual vs. Goal" : "Occurences Actual vs. Goal") + " > " + level1 + "\" FontSize=\"14\"/>");
            sb.AppendLine("<vc:Title " + (isHome ? "Cursor=\"Hand\" Padding=\"5\" FontColor=\"Blue\" TextDecorations=\"Underline\"" : "") + " Text=\"" + (isEvents ? "Downtime Actual vs. Goal" : "Occurences Actual vs. Goal") + "\" FontSize=\"14\"/>");
            sb.AppendLine("</vc:Chart.Titles>");

            sb.AppendLine("<vc:Chart.TrendLines>");
            sb.AppendLine("     <vc:TrendLine LineColor=\"Red\" LineThickness=\"2\" Value=\"" + goal.ToString() + "\" LabelText=\"\"/>");
            sb.AppendLine("</vc:Chart.TrendLines>");

            sb.AppendLine("<vc:Chart.Legends>");
            sb.AppendLine("     <vc:Legend Enabled=\"False\" VerticalAlignment=\"Center\" HorizontalAlignment=\"Right\" />");
            sb.AppendLine("</vc:Chart.Legends>");

            sb.AppendLine("<vc:Chart.AxesY>");
            if (rows.Max(o => (isEvents ? o.Minutes : o.Occurences)) < goal)
            {
                sb.AppendLine(" <vc:Axis AxisMaximum=\"" + (goal + Convert.ToInt32(goal * 0.3)).ToString() + "\">");
            }
            else
            {
                sb.AppendLine(" <vc:Axis >");
            }
            sb.AppendLine("     <vc:Axis.Grids>");
            sb.AppendLine("         <vc:ChartGrid InterlacedColor=\"White\" />");
            sb.AppendLine("     </vc:Axis.Grids>");
            sb.AppendLine(" </vc:Axis>");
            sb.AppendLine("</vc:Chart.AxesY>");

            sb.AppendLine("<vc:Chart.AxesX>");
            sb.AppendLine(" <vc:Axis LineThickness=\"0\">");
            sb.AppendLine("     <vc:Axis.Grids>");
            sb.AppendLine("         <vc:ChartGrid Interval=\"1\" />");
            sb.AppendLine("     </vc:Axis.Grids>");
            sb.AppendLine(" </vc:Axis>");
            sb.AppendLine("</vc:Chart.AxesX>");

            sb.AppendLine("<vc:Chart.PlotArea>");
            sb.AppendLine(" <vc:PlotArea ShadowEnabled=\"true\" CornerRadius=\"0,7,5,0\" BorderThickness=\"0.2,0.2,2,0.2\" >");
            sb.AppendLine("     <vc:PlotArea.Background>");
            sb.AppendLine("         <LinearGradientBrush EndPoint=\"1,0.5\" StartPoint=\"0,0.5\">");
            sb.AppendLine("             <GradientStop Color=\"#FFD8D8D8\"/>");
            sb.AppendLine("             <GradientStop Color=\"#9FFEFCFC\" Offset=\"1\"/>");
            sb.AppendLine("         </LinearGradientBrush>");
            sb.AppendLine("     </vc:PlotArea.Background>");
            sb.AppendLine(" </vc:PlotArea>");
            sb.AppendLine("</vc:Chart.PlotArea>");

            sb.AppendLine("<vc:Chart.Series>");
            sb.AppendLine("<vc:DataSeries RenderAs=\"Line\" Color=\"Blue\" LabelEnabled=\"True\" LegendText=\"" + (isEvents ? "Downtime" : "Occurences") + "\">");
            sb.AppendLine("<vc:DataSeries.DataPoints>");
            foreach (var item in rows)
            {
                sb.AppendFormat("<vc:DataPoint BorderColor=\"Blue\" AxisXLabel=\"{0}\" YValue=\"{1}\"/>", item.Title, (isEvents ? item.Minutes : item.Occurences));
            }
            sb.AppendLine("</vc:DataSeries.DataPoints>");
            sb.AppendLine("</vc:DataSeries>");

            //就为了加个legend到右边,这个蛋痛的
            sb.AppendLine("<vc:DataSeries RenderAs=\"Line\" Color=\"Red\"  LineThickness=\"0\" LabelEnabled=\"False\" LegendText=\"Goal\">");
            sb.AppendLine("<vc:DataSeries.DataPoints>");
            foreach (var item in rows)
            {
                sb.AppendFormat("<vc:DataPoint BorderColor=\"Red\" AxisXLabel=\"{0}\" YValue=\"{1}\"/>", "", goal);
            }
            sb.AppendLine("</vc:DataSeries.DataPoints>");
            sb.AppendLine("</vc:DataSeries>");

            sb.AppendLine("</vc:Chart.Series>");
            sb.AppendLine("</vc:Chart>");

            return sb.ToString();

        }
Example #2
0
        public static GoalReportRow GetGoals(DateTime startTime, DateTime endTime)
        {
            using (DB db = new DB(DBHelper.GetConnectionString(Filter_Client)))
            {
                var q = from o in db.GoalSet
                        where o.StartTime <= startTime && o.EndTime >= endTime
                        && o.CLIENT == Filter_Client
                        && o.LINE == Filter_Line
                        select o;
                int? totalOcc = null;
                try
                {
                    totalOcc = q.Sum(o => o.Occuring);
                }
                catch (Exception)
                {

                    //throw;
                }

                decimal? totalTime = null;
                try
                {
                    totalTime = q.Sum(o => o.Dowmtime);
                }
                catch (Exception)
                {

                    // throw;
                }

                if (!totalOcc.HasValue) totalOcc = 0;
                if (!totalTime.HasValue) totalTime = 0;

                decimal totalDays = 0;//Math.Abs(Convert.ToDecimal( endTime.Subtract(startTime).TotalDays));

                foreach (var item in q.ToList())
                {
                    totalDays += Convert.ToDecimal(item.EndTime.Subtract(item.StartTime).TotalDays);
                }

                if (totalDays == 0) totalDays = 1m;
                GoalReportRow grr = new GoalReportRow();
                grr.Downtimes.Hour = totalTime.Value / (totalDays * 24);
                grr.Downtimes.Day = totalTime.Value / totalDays;
                grr.Downtimes.Week = totalTime.Value / (totalDays / 7);
                grr.Downtimes.Month = totalTime.Value / (totalDays / 30);
                grr.Downtimes.Year = totalTime.Value / (totalDays / 365);

                grr.Occurences.Hour = Convert.ToInt32(totalOcc.Value / (totalDays * 24));
                grr.Occurences.Day = Convert.ToInt32(totalOcc.Value / totalDays);
                grr.Occurences.Week = Convert.ToInt32(totalOcc.Value / (totalDays / 7));
                grr.Occurences.Month = Convert.ToInt32(totalOcc.Value / (totalDays / 30));
                grr.Occurences.Year = Convert.ToInt32(totalOcc.Value / (totalDays / 365));

                return grr;
            }
        }