コード例 #1
0
        public static object[] GetChartData(string sDate, string eDate, string fleet, string phase, string task, string vendor)
        {
            fleet = fleet ?? "";
            phase = phase ?? "";
            vendor = vendor ?? "";
            task = task ?? "";

            var startDate = DateTime.MinValue;
            var endDate = DateTime.MinValue;

            var fleets = fleet.Replace("null", "").Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
            var phases = phase.Replace("null", "").Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
            var vendors = vendor.Replace("null", "").Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
            var tasks = task.Replace("null", "").Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);

            List<ChartData> tempData;

            if ((string.IsNullOrWhiteSpace(sDate) || string.IsNullOrWhiteSpace(eDate))
                && fleets.Length == 0 && phases.Length == 0 && tasks.Length == 0 && vendors.Length == 0)
                tempData = _chartData;
            else
            {
                tempData = _chartData;
                if (!string.IsNullOrWhiteSpace(sDate) && !string.IsNullOrWhiteSpace(eDate))
                {
                    startDate = DateTime.ParseExact(sDate, "MM/dd/yyyy", CultureInfo.InvariantCulture);
                    endDate = DateTime.ParseExact(eDate, "MM/dd/yyyy", CultureInfo.InvariantCulture);

                    tempData = tempData.Where(x => x.EndDate >= startDate && x.StartDate <= endDate).ToList();
                }

                if (fleets.Length > 0)
                    tempData = tempData.Where(x => fleets.Contains(x.Project)).ToList();

                if (phases.Length > 0)
                    tempData = tempData.Where(x => phases.Contains(x.Phase)).ToList();

                if (vendors.Length > 0)
                    tempData = tempData.Where(x => vendors.Contains(x.Vendor)).ToList();

                if (tasks.Length > 0)
                    tempData = tempData.Where(x => !tasks.Contains(x.Task)).ToList();
            }

            
            var date = tempData.OrderBy(x => x.StartDate).Select(x => x.StartDate).Distinct().FirstOrDefault();

            if (date < startDate)
                date = startDate;

            var newdata = new List<ChartData>();

            var maxLength = tempData.Select(x => x.Phase).Distinct().ToList().Select(x => x.Length).Concat(new[] { 0 }).Max();
            var sb = new StringBuilder();
            for (var i = 0; i < maxLength; i++)
                sb.Append("..");


            var temp = tempData.Select(x => x.Project).Distinct().ToList();

            foreach (var project in temp)
            {
                var projectData = tempData.Where(x => x.Project == project).ToList();
                if (projectData.Count <= 0)
                    continue;

                newdata.Add(new ChartData()
                {
                    StartDate = date.AddDays(-1),
                    EndDate = date.AddDays(-1).AddHours(4),
                    Phase = project + sb + "....",
                    Project = project,
                    Task = "",
                    Fleet = "",
                    Color = "#aaaaaa",
                    Vendor = ""
                });
                newdata.AddRange(projectData);
            }

            var chartData = new List<object>();
            chartData.Add(new object[]{
                "Project",    
                "Phase",
                "Task",
                "StartDate",
                "EndDate",
                "Fleet",
                "Color",
                "Vendor",
                "Tooltip"
                });

            var chartKeyValues = new List<ChartKeyValue>();
            foreach (var data in newdata)
            {
                if (data.StartDate.Date != data.EndDate.Date || data.EndDate.Subtract(data.StartDate).Hours > 4)
                {
                    var sDateValue = data.StartDate.ToString("yyyyMMdd");
                    var eDateValue = data.EndDate.ToString("yyyyMMdd");
                    var phaseValue = data.Phase;
                    var projectValue = data.Project;
                    var key = projectValue + phaseValue + sDateValue + eDateValue;
                    var chartKeyValue = new ChartKeyValue()
                    {
                        ChartData = data,
                        Key = key
                    };
                    chartKeyValues.Add(chartKeyValue);
                }
            }

            var dictChartKeyValues = chartKeyValues.GroupBy(x =>  x.Key).ToDictionary(x=>x.Key, x=>x.ToList());
            var toolTipdict = new Dictionary<string, string>();

            foreach (var key in dictChartKeyValues.Keys)
            {
                var charts = dictChartKeyValues[key];
                if (charts.Count==1)
                {
                    var data = charts[0].ChartData;
                        var colorCode = data.Color;
                        var duration = data.EndDate - data.StartDate;
                        var tooltip = string.Format("<span style='width:300px; white-space: nowrap;'><br/>&nbsp;<font style='background-color:" + colorCode + ";'>&nbsp;&nbsp;</font>&nbsp;&nbsp;<b>{0}</b><br/><hr style=' border: 1px solid " + colorCode + ";' />&nbsp;&nbsp;<b>Date Range : </b>{1}&nbsp; to &nbsp;{2}&nbsp;&nbsp;<br/>&nbsp;&nbsp;<b>Duration : </b>{3}&nbsp;&nbsp;<br /><br/></span>",
                            data.Task, data.StartDate.ToString("MM/dd/yy"), data.EndDate.ToString("MM/dd/yy"), duration.ToString("dd") + " days");
                        toolTipdict.Add(key, tooltip);
                }
                else
                {
                    var n = 0;
                    var tempChartKeyValues = dictChartKeyValues[key];
                    var toolTips = "";
                    foreach (var tempChartKeyValue in tempChartKeyValues)
                    {
                        var color = n == 0 ? "green" : "blue";
                        var data = tempChartKeyValue.ChartData;
                        var colorCode = data.Color;
                        var duration = data.EndDate - data.StartDate;
                        var tooltip = string.Format("<span style='width:300px; white-space: nowrap;'><br/>&nbsp;<span style='background-color:" + colorCode + ";'>&nbsp;&nbsp;</span>&nbsp;&nbsp;<b>{0}</b><br/><hr  style='border: 1px solid " + colorCode + ";' />&nbsp;&nbsp;<b>Date Range : </b>{1}&nbsp; to &nbsp;{2}&nbsp;&nbsp;<br/>&nbsp;&nbsp;<b>Duration : </b>{3}&nbsp;&nbsp;<br /><br/></span>",
                            data.Task, data.StartDate.ToString("MM/dd/yy"), data.EndDate.ToString("MM/dd/yy"), duration.ToString("dd") + " days");
                        toolTips = toolTips + tooltip;
                        n = 1;
                    }
                    toolTipdict.Add(key, toolTips);
                }
            }

            var dictIsTaskAdded = new Dictionary<string, bool>();

            var k = 1;
            foreach (var data in newdata)
            {
                var stDate = data.StartDate;
                var enDate = data.EndDate;
                var duration = data.EndDate - data.StartDate;
                var tooltip = "";
                if (stDate.Date != enDate.Date || enDate.Subtract(stDate).Hours > 4)
                {
                    if (startDate != DateTime.MinValue && stDate < startDate)
                        stDate = startDate;

                    if (endDate != DateTime.MinValue && enDate > endDate)
                        enDate = endDate;

//                    tooltip = string.Format("<div ><span style='width:300px; white-space: nowrap;'><br/>&nbsp;&nbsp;<b>{0}</b><br/><br/><hr  />&nbsp;&nbsp;<b>Date Range : </b>{1}&nbsp; to &nbsp;{2}&nbsp;&nbsp;<br/>&nbsp;&nbsp;<b>Duration : </b>{3}&nbsp;&nbsp;<br /><br/></span>",
//                            data.Task, data.StartDate.ToString("MM/dd/yy"), data.EndDate.ToString("MM/dd/yy"), duration.ToString("dd") + " days");

                    var sDateValue = data.StartDate.ToString("yyyyMMdd");
                    var eDateValue = data.EndDate.ToString("yyyyMMdd");
                    var phaseValue = data.Phase;
                    var projectValue = data.Project;
                    var colorCode = data.Color;
                    var key = projectValue + phaseValue + sDateValue + eDateValue;

                    if (dictIsTaskAdded.ContainsKey(key))
                        continue;

                    dictIsTaskAdded.Add(key, true);

                    if (toolTipdict.ContainsKey(key))
                        tooltip = toolTipdict[key];
                    else
                        tooltip = string.Format("<span style='width:300px; white-space: nowrap;'><br/>&nbsp;<span style='background-color:" + colorCode + ";'>&nbsp;&nbsp;</span>&nbsp;&nbsp;<b>{0}</b><br/><br/><hr style=' border-top: 1px solid #ccc;' />&nbsp;&nbsp;<b>Date Range : </b>{1}&nbsp; to &nbsp;{2}&nbsp;&nbsp;<br/>&nbsp;&nbsp;<b>Duration : </b>{3}&nbsp;&nbsp;<br /><br/></span>",
                                    data.Task, data.StartDate.ToString("MM/dd/yy"), data.EndDate.ToString("MM/dd/yy"), duration.ToString("dd") + " days");
                }

                
                chartData.Add(new object[] { data.Project, data.Phase, data.Task + " " + k.ToString("D2"), stDate, enDate, data.Fleet, data.Color, data.Vendor, tooltip });
                k++;
            }
            return chartData.ToArray();
        }
コード例 #2
0
        public static object[] GetChartData(string sDate, string eDate, string fleet, string phase, string task, string vendor)
        {
            fleet  = fleet ?? "";
            phase  = phase ?? "";
            vendor = vendor ?? "";
            task   = task ?? "";

            var startDate = DateTime.MinValue;
            var endDate   = DateTime.MinValue;

            var fleets  = fleet.Replace("null", "").Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
            var phases  = phase.Replace("null", "").Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
            var vendors = vendor.Replace("null", "").Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
            var tasks   = task.Replace("null", "").Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);

            List <ChartData> tempData;

            if ((string.IsNullOrWhiteSpace(sDate) || string.IsNullOrWhiteSpace(eDate)) &&
                fleets.Length == 0 && phases.Length == 0 && tasks.Length == 0 && vendors.Length == 0)
            {
                tempData = _chartData;
            }
            else
            {
                tempData = _chartData;
                if (!string.IsNullOrWhiteSpace(sDate) && !string.IsNullOrWhiteSpace(eDate))
                {
                    startDate = DateTime.ParseExact(sDate, "MM/dd/yyyy", CultureInfo.InvariantCulture);
                    endDate   = DateTime.ParseExact(eDate, "MM/dd/yyyy", CultureInfo.InvariantCulture);

                    tempData = tempData.Where(x => x.EndDate >= startDate && x.StartDate <= endDate).ToList();
                }

                if (fleets.Length > 0)
                {
                    tempData = tempData.Where(x => fleets.Contains(x.Project)).ToList();
                }

                if (phases.Length > 0)
                {
                    tempData = tempData.Where(x => phases.Contains(x.Phase)).ToList();
                }

                if (vendors.Length > 0)
                {
                    tempData = tempData.Where(x => vendors.Contains(x.Vendor)).ToList();
                }

                if (tasks.Length > 0)
                {
                    tempData = tempData.Where(x => !tasks.Contains(x.Task)).ToList();
                }
            }


            var date = tempData.OrderBy(x => x.StartDate).Select(x => x.StartDate).Distinct().FirstOrDefault();

            if (date < startDate)
            {
                date = startDate;
            }

            var newdata = new List <ChartData>();

            var maxLength = tempData.Select(x => x.Phase).Distinct().ToList().Select(x => x.Length).Concat(new[] { 0 }).Max();
            var sb        = new StringBuilder();

            for (var i = 0; i < maxLength; i++)
            {
                sb.Append("..");
            }


            var temp = tempData.Select(x => x.Project).Distinct().ToList();

            foreach (var project in temp)
            {
                var projectData = tempData.Where(x => x.Project == project).ToList();
                if (projectData.Count <= 0)
                {
                    continue;
                }

                newdata.Add(new ChartData()
                {
                    StartDate = date.AddDays(-1),
                    EndDate   = date.AddDays(-1).AddHours(4),
                    Phase     = project + sb + "....",
                    Project   = project,
                    Task      = "",
                    Fleet     = "",
                    Color     = "#aaaaaa",
                    Vendor    = ""
                });
                newdata.AddRange(projectData);
            }

            var chartData = new List <object>();

            chartData.Add(new object[] {
                "Project",
                "Phase",
                "Task",
                "StartDate",
                "EndDate",
                "Fleet",
                "Color",
                "Vendor",
                "Tooltip"
            });

            var chartKeyValues = new List <ChartKeyValue>();

            foreach (var data in newdata)
            {
                if (data.StartDate.Date != data.EndDate.Date || data.EndDate.Subtract(data.StartDate).Hours > 4)
                {
                    var sDateValue    = data.StartDate.ToString("yyyyMMdd");
                    var eDateValue    = data.EndDate.ToString("yyyyMMdd");
                    var phaseValue    = data.Phase;
                    var projectValue  = data.Project;
                    var key           = projectValue + phaseValue + sDateValue + eDateValue;
                    var chartKeyValue = new ChartKeyValue()
                    {
                        ChartData = data,
                        Key       = key
                    };
                    chartKeyValues.Add(chartKeyValue);
                }
            }

            var dictChartKeyValues = chartKeyValues.GroupBy(x => x.Key).ToDictionary(x => x.Key, x => x.ToList());
            var toolTipdict        = new Dictionary <string, string>();

            foreach (var key in dictChartKeyValues.Keys)
            {
                var charts = dictChartKeyValues[key];
                if (charts.Count == 1)
                {
                    var data      = charts[0].ChartData;
                    var colorCode = data.Color;
                    var duration  = data.EndDate - data.StartDate;
                    var tooltip   = string.Format("<span style='width:300px; white-space: nowrap;'><br/>&nbsp;<font style='background-color:" + colorCode + ";'>&nbsp;&nbsp;</font>&nbsp;&nbsp;<b>{0}</b><br/><hr style=' border: 1px solid " + colorCode + ";' />&nbsp;&nbsp;<b>Date Range : </b>{1}&nbsp; to &nbsp;{2}&nbsp;&nbsp;<br/>&nbsp;&nbsp;<b>Duration : </b>{3}&nbsp;&nbsp;<br /><br/></span>",
                                                  data.Task, data.StartDate.ToString("MM/dd/yy"), data.EndDate.ToString("MM/dd/yy"), duration.ToString("dd") + " days");
                    toolTipdict.Add(key, tooltip);
                }
                else
                {
                    var n = 0;
                    var tempChartKeyValues = dictChartKeyValues[key];
                    var toolTips           = "";
                    foreach (var tempChartKeyValue in tempChartKeyValues)
                    {
                        var color     = n == 0 ? "green" : "blue";
                        var data      = tempChartKeyValue.ChartData;
                        var colorCode = data.Color;
                        var duration  = data.EndDate - data.StartDate;
                        var tooltip   = string.Format("<span style='width:300px; white-space: nowrap;'><br/>&nbsp;<span style='background-color:" + colorCode + ";'>&nbsp;&nbsp;</span>&nbsp;&nbsp;<b>{0}</b><br/><hr  style='border: 1px solid " + colorCode + ";' />&nbsp;&nbsp;<b>Date Range : </b>{1}&nbsp; to &nbsp;{2}&nbsp;&nbsp;<br/>&nbsp;&nbsp;<b>Duration : </b>{3}&nbsp;&nbsp;<br /><br/></span>",
                                                      data.Task, data.StartDate.ToString("MM/dd/yy"), data.EndDate.ToString("MM/dd/yy"), duration.ToString("dd") + " days");
                        toolTips = toolTips + tooltip;
                        n        = 1;
                    }
                    toolTipdict.Add(key, toolTips);
                }
            }

            var dictIsTaskAdded = new Dictionary <string, bool>();

            var k = 1;

            foreach (var data in newdata)
            {
                var stDate   = data.StartDate;
                var enDate   = data.EndDate;
                var duration = data.EndDate - data.StartDate;
                var tooltip  = "";
                if (stDate.Date != enDate.Date || enDate.Subtract(stDate).Hours > 4)
                {
                    if (startDate != DateTime.MinValue && stDate < startDate)
                    {
                        stDate = startDate;
                    }

                    if (endDate != DateTime.MinValue && enDate > endDate)
                    {
                        enDate = endDate;
                    }

//                    tooltip = string.Format("<div ><span style='width:300px; white-space: nowrap;'><br/>&nbsp;&nbsp;<b>{0}</b><br/><br/><hr  />&nbsp;&nbsp;<b>Date Range : </b>{1}&nbsp; to &nbsp;{2}&nbsp;&nbsp;<br/>&nbsp;&nbsp;<b>Duration : </b>{3}&nbsp;&nbsp;<br /><br/></span>",
//                            data.Task, data.StartDate.ToString("MM/dd/yy"), data.EndDate.ToString("MM/dd/yy"), duration.ToString("dd") + " days");

                    var sDateValue   = data.StartDate.ToString("yyyyMMdd");
                    var eDateValue   = data.EndDate.ToString("yyyyMMdd");
                    var phaseValue   = data.Phase;
                    var projectValue = data.Project;
                    var colorCode    = data.Color;
                    var key          = projectValue + phaseValue + sDateValue + eDateValue;

                    if (dictIsTaskAdded.ContainsKey(key))
                    {
                        continue;
                    }

                    dictIsTaskAdded.Add(key, true);

                    if (toolTipdict.ContainsKey(key))
                    {
                        tooltip = toolTipdict[key];
                    }
                    else
                    {
                        tooltip = string.Format("<span style='width:300px; white-space: nowrap;'><br/>&nbsp;<span style='background-color:" + colorCode + ";'>&nbsp;&nbsp;</span>&nbsp;&nbsp;<b>{0}</b><br/><br/><hr style=' border-top: 1px solid #ccc;' />&nbsp;&nbsp;<b>Date Range : </b>{1}&nbsp; to &nbsp;{2}&nbsp;&nbsp;<br/>&nbsp;&nbsp;<b>Duration : </b>{3}&nbsp;&nbsp;<br /><br/></span>",
                                                data.Task, data.StartDate.ToString("MM/dd/yy"), data.EndDate.ToString("MM/dd/yy"), duration.ToString("dd") + " days");
                    }
                }


                chartData.Add(new object[] { data.Project, data.Phase, data.Task + " " + k.ToString("D2"), stDate, enDate, data.Fleet, data.Color, data.Vendor, tooltip });
                k++;
            }
            return(chartData.ToArray());
        }