예제 #1
0
        public void ProcessRequest(HttpContext context)
        {
            string yearString = context.Request["year"];
            int    year       = -1;

            if (yearString != null && int.TryParse(yearString, out year))
            {
                int firstYear = year - 4;

                eisEntities ctx   = new eisEntities();
                var         types = from type in ctx.numberofemployees
                                    where type.Year >= firstYear && type.Year <= year
                                    select type;

                var empTypes = from empType in ctx.employeetypes
                               select empType.TypeName;

                List <string> xVal = new List <string>();
                for (int i = firstYear; i <= year; i++)
                {
                    int actualYear = ((i - 2500) % 100);
                    xVal.Add(actualYear.ToString());
                }

                Dictionary <string, decimal> dataTable1 = new Dictionary <string, decimal>();
                Dictionary <string, decimal> dataTable2 = new Dictionary <string, decimal>();
                Dictionary <string, decimal> dataTable3 = new Dictionary <string, decimal>();
                DateTime lastUpdated  = DateTime.MinValue;
                decimal  maximumValue = 0;
                foreach (var type in types)
                {
                    string shortYear = ((type.Year - 2500) % 100).ToString();
                    if (!dataTable1.ContainsKey(shortYear))
                    {
                        dataTable1[shortYear] = 0;
                        dataTable2[shortYear] = 0;
                        dataTable3[shortYear] = 0;
                    }
                    dataTable1[shortYear] += type.GovernmentOfficer;
                    dataTable2[shortYear] += type.PermanentContractor;
                    dataTable3[shortYear] += type.GeneralOfficer;
                    if (type.LastUpdated > lastUpdated)
                    {
                        lastUpdated = type.LastUpdated;
                    }
                    maximumValue = Math.Max(maximumValue, dataTable1[shortYear]);
                    maximumValue = Math.Max(maximumValue, dataTable2[shortYear]);
                    maximumValue = Math.Max(maximumValue, dataTable3[shortYear]);
                }

                //Series1
                List <string>  s1x = new List <string>();
                List <decimal> s1y = new List <decimal>();
                for (int i = 0; i < 5; i++)
                {
                    s1x.Add(xVal[i]);
                    s1y.Add(dataTable1[xVal[i]]);
                }

                //Series2
                List <string>  s2x = new List <string>();
                List <decimal> s2y = new List <decimal>();
                for (int i = 0; i < 5; i++)
                {
                    s2x.Add(xVal[i]);
                    s2y.Add(dataTable2[xVal[i]]);
                }

                //Series3
                List <string>  s3x = new List <string>();
                List <decimal> s3y = new List <decimal>();
                for (int i = 0; i < 5; i++)
                {
                    s3x.Add(xVal[i]);
                    s3y.Add(dataTable3[xVal[i]]);
                }

                ColumnChart chart = new ColumnChart(xVal, 3, 1, 75);
                chart.SetLastUpdated(lastUpdated);
                chart.SetSummary("*ไม่มีข้อมูลพนักงานราชการ", Color.Red);
                chart.AddLeftAnnotation("จำนวนคน  ", 82, 15);
                chart.SetAxisFont(new Font("Circular", 16, FontStyle.Bold));

                chart.AddSeries("0", "0", SeriesChartType.Column, s1x.ToArray(), s1y.ToArray());
                chart.AddSeries("1", "1", SeriesChartType.Column, s2x.ToArray(), s2y.ToArray());
                chart.AddSeries("2", "2", SeriesChartType.Column, s3x.ToArray(), s3y.ToArray());

                chart.GetSeries("0").Color           = ColorPalette.GetColor(0);
                chart.GetSeries("1").Color           = ColorPalette.GetColor(0);
                chart.GetSeries("2").Color           = ColorPalette.GetColor(0);
                chart.GetSeries("0").Points[4].Color = ColorPalette.GetColor(1);
                chart.GetSeries("1").Points[4].Color = ColorPalette.GetColor(1);
                chart.GetSeries("2").Points[4].Color = ColorPalette.GetColor(1);

                for (int i = 0; i < 3; i++)
                {
                    chart.GetSeries("" + i).SmartLabelStyle.Enabled = false;
                    chart.GetSeries("" + i).LabelAngle = -90;
                    chart.GetSeries("" + i).SmartLabelStyle.MaxMovingDistance = 100;
                    chart.GetSeries("" + i).SmartLabelStyle.MovingDirection   = LabelAlignmentStyles.Top;
                    chart.GetSeries("" + i).SetCustomProperty("RenderType", "Cylinder");
                }

                chart.GetChartArea("0").AxisY.LabelStyle.Enabled    = false;
                chart.GetChartArea("0").AxisY.MajorTickMark.Enabled = false;
                chart.GetChartArea("1").AxisY.LabelStyle.Enabled    = false;
                chart.GetChartArea("1").AxisY.MajorTickMark.Enabled = false;
                chart.GetChartArea("2").AxisY.LabelStyle.Enabled    = false;
                chart.GetChartArea("2").AxisY.MajorTickMark.Enabled = false;

                chart.GetChartArea("0").AxisY.Maximum = (double)maximumValue;
                chart.GetChartArea("1").AxisY.Maximum = (double)maximumValue;
                chart.GetChartArea("2").AxisY.Maximum = (double)maximumValue;

                chart.GetChartArea("0").AxisX.CustomLabels.Add(0, 6, "ข้าราชการ", 1, LabelMarkStyle.LineSideMark);
                chart.GetChartArea("1").AxisX.CustomLabels.Add(0, 6, "ลูกจ้างประจำ", 1, LabelMarkStyle.LineSideMark);
                chart.GetChartArea("2").AxisX.CustomLabels.Add(0, 6, "พนักงานราชการ", 1, LabelMarkStyle.LineSideMark);

                chart.GetLegendBox().Enabled = false;

                byte[] dataArray = chart.Render();

                context.Response.ContentType = "image/png";
                context.Response.OutputStream.Write(dataArray, 0, dataArray.Length);
            }
            else
            {
                context.Response.ContentType = "text/plain";
                context.Response.Write("Error: Year was not specified");
            }
        }
예제 #2
0
        public void ProcessRequest(HttpContext context)
        {
            string yearString = context.Request["year"];
            int    year       = -1;

            if (yearString != null && int.TryParse(yearString, out year))
            {
                int           firstYear = year - 4;
                List <string> xVal      = new List <string>();
                for (int i = firstYear; i <= year; i++)
                {
                    int actualYear = ((i - 2500) % 100);
                    xVal.Add(actualYear.ToString());
                }

                eisEntities ctx    = new eisEntities();
                var         usages = from type in ctx.estimatedfundmembers
                                     where type.Year >= firstYear && type.Year <= year
                                     select type;
                var usageList = usages.ToList();

                var memberTypes = from type in ctx.fundmembertypes
                                  select type.TypeName;

                Dictionary <string, Dictionary <string, decimal> > dataTable  = new Dictionary <string, Dictionary <string, decimal> >();
                Dictionary <string, Dictionary <string, decimal> > dataTable2 = new Dictionary <string, Dictionary <string, decimal> >();
                DateTime lastUpdated  = DateTime.MinValue;
                decimal  maximumValue = 0;
                foreach (var usage in usageList)
                {
                    string typeName  = usage.fundmembertype.TypeName;
                    string shortYear = ((usage.Year - 2500) % 100).ToString();
                    if (!dataTable.ContainsKey(typeName))
                    {
                        dataTable[typeName]  = new Dictionary <string, decimal>();
                        dataTable2[typeName] = new Dictionary <string, decimal>();
                    }
                    dataTable[typeName][shortYear] = usage.EstimatedValue;
                    maximumValue = Math.Max(maximumValue, usage.EstimatedValue);
                    if (usage.LastUpdated > lastUpdated)
                    {
                        lastUpdated = usage.LastUpdated;
                    }
                }

                ColumnChart chart = new ColumnChart(xVal.ToArray(), memberTypes.Count());
                chart.SetLastUpdated(lastUpdated);
                chart.AddLeftAnnotation("จำนวนคน", 2, 15);
                chart.SetAxisFont(new Font("Circular", 16, FontStyle.Bold));
                chart.GetLegendBox().Enabled = false;

                int runner = 0;
                foreach (var type in memberTypes)
                {
                    List <decimal> s1y = new List <decimal>();
                    Dictionary <string, decimal> dataList = dataTable[type];
                    foreach (string x in xVal)
                    {
                        s1y.Add(dataList[x]);
                    }
                    chart.AddSeries(type, "" + runner, SeriesChartType.StackedColumn, xVal.ToArray(), s1y.ToArray());

                    chart.GetSeries(type).IsValueShownAsLabel = false;
                    chart.GetSeries(type).IsVisibleInLegend   = false;
                    chart.GetSeries(type).Color = ColorPalette.GetColor(0);

                    chart.GetChartArea("" + runner).AxisY.Maximum = (double)maximumValue;
                    chart.GetChartArea("" + runner).AxisY.MajorTickMark.Enabled = false;
                    chart.GetChartArea("" + runner).AxisY.LabelStyle.Enabled    = true;
                    chart.GetChartArea("" + runner).AxisX.CustomLabels.Add(0, 6, type, 1, LabelMarkStyle.LineSideMark);
                    runner++;
                }

                byte[] dataArray = chart.Render();

                context.Response.ContentType = "image/png";
                context.Response.OutputStream.Write(dataArray, 0, dataArray.Length);
            }
            else
            {
                context.Response.ContentType = "text/plain";
                context.Response.Write("Error: Year was not specified");
            }
        }
        public void ProcessRequest(HttpContext context)
        {
            string yearString = context.Request["year"];
            int    year       = -1;

            if (yearString != null && int.TryParse(yearString, out year))
            {
                int firstYear = year - 4;

                eisEntities ctx   = new eisEntities();
                var         types = from type in ctx.numberofemployees
                                    where type.Year == year
                                    select type;

                var empTypes = from empType in ctx.employeetypes
                               select empType.TypeName;

                string[] xVals = empTypes.ToArray <string>();

                List <decimal> y1          = new List <decimal>();
                List <decimal> y2          = new List <decimal>();
                List <decimal> y3          = new List <decimal>();
                DateTime       lastUpdated = DateTime.MinValue;
                foreach (var type in types)
                {
                    y1.Add(type.GovernmentOfficer);
                    y2.Add(type.PermanentContractor);
                    y3.Add(type.GeneralOfficer);
                    if (type.LastUpdated > lastUpdated)
                    {
                        lastUpdated = type.LastUpdated;
                    }
                }

                ColumnChart chart = new ColumnChart(xVals, 1, 1, 75);
                chart.SetLastUpdated(lastUpdated);
                chart.SetSummary("*ไม่มีข้อมูลพนักงานราชการ", Color.Red);
                chart.AddLeftAnnotation("จำนวนคน", 1, 8);
                chart.SetAxisFont(new Font("Circular", 16, FontStyle.Bold));

                chart.AddSeries("ข้าราชการ", y1.ToArray());
                chart.AddSeries("ลูกจ้างประจำ", y2.ToArray());
                chart.AddSeries("พนักงานราชการ", y3.ToArray());

                for (int i = 0; i < 3; i++)
                {
                    chart.GetSeries(i).SmartLabelStyle.Enabled = false;
                    chart.GetSeries(i).LabelAngle = -90;
                }

                //chart.GetLegendBox().Docking = Docking.Bottom;
                chart.GetLegendBox().Position  = new ElementPosition(0, 87, 100, 6);
                chart.GetLegendBox().Alignment = StringAlignment.Center;

                byte[] dataArray = chart.Render();

                context.Response.ContentType = "image/png";
                context.Response.OutputStream.Write(dataArray, 0, dataArray.Length);
            }
            else
            {
                context.Response.ContentType = "text/plain";
                context.Response.Write("Error: Year was not specified");
            }
        }
        public void ProcessRequest(HttpContext context)
        {
            string yearString = context.Request["year"];
            int    year       = -1;

            if (yearString != null && int.TryParse(yearString, out year))
            {
                int           firstYear   = year - 4;
                DateTime      lastUpdated = DateTime.MinValue;
                List <string> yearList    = new List <string>();
                for (int y = year; y >= firstYear; y--)
                {
                    yearList.Add(y.ToString());
                }

                eisEntities ctx   = new eisEntities();
                var         types = from type in ctx.employeerelatedbudgettypes
                                    select type.TypeName;
                var typeList = types.ToList();

                ColumnChart chart = new ColumnChart(yearList.ToArray(), 1, 2, 80);
                foreach (var type in typeList)
                {
                    var usages = from usage in ctx.employeerelatedbudgetusages
                                 where usage.Year >= firstYear && usage.Year <= year
                                 orderby usage.Year descending
                                 select usage;
                    var usageList = usages.ToList();

                    var filteredUsages = from usage in usageList
                                         where usage.employeerelatedbudgettype.TypeName == type
                                         select usage;
                    var filteredUsageList = filteredUsages.ToList();

                    List <decimal> yValues = new List <decimal>();
                    foreach (var usage in filteredUsageList)
                    {
                        yValues.Add(usage.Amount);
                        if (usage.LastUpdated > lastUpdated)
                        {
                            lastUpdated = usage.LastUpdated;
                        }
                    }
                    chart.AddSeries(type, yValues.ToArray());
                    chart.GetSeries(type).ChartType = SeriesChartType.Bar;
                }
                chart.SetLastUpdated(lastUpdated);
                chart.AddLeftAnnotation("เงิน - ล้านบาท)", 4, 13);

                Legend legend = chart.GetLegendBox();
                legend.Position.Auto   = false;
                legend.Position.X      = 0;
                legend.Position.Y      = 5;
                legend.Position.Width  = 100;
                legend.Position.Height = 10;
                legend.Font            = new Font("Circular", 18, FontStyle.Regular);

                byte[] dataArray = chart.Render();

                context.Response.ContentType = "image/png";
                context.Response.OutputStream.Write(dataArray, 0, dataArray.Length);
            }
            else
            {
                context.Response.ContentType = "text/plain";
                context.Response.Write("Error: Year was not specified");
            }
        }
        public void ProcessRequest(HttpContext context)
        {
            string yearString = context.Request["year"];
            int    year       = -1;

            if (yearString != null && int.TryParse(yearString, out year))
            {
                eisEntities ctx   = new eisEntities();
                var         types = from type in ctx.estimatedretirements
                                    where type.Year == year
                                    select type;
                var typeList = types.ToList();

                List <string> yValues = new List <string>();
                List <int>    xValues = new List <int>();

                DateTime lastUpdated = DateTime.MinValue;
                foreach (var type in typeList)
                {
                    yValues.Add(type.retirementtype.TypeName);
                    xValues.Add(type.EstimatedValue);
                    if (type.LastUpdated > lastUpdated)
                    {
                        lastUpdated = type.LastUpdated;
                    }
                }
                ColumnChart chart = new ColumnChart(yValues.ToArray());
                chart.SetLastUpdated(lastUpdated);
                chart.AddSeries("จำนวนคน", xValues.ToArray());
                chart.GetChartArea().Area3DStyle.Enable3D = true;
                chart.GetChartArea().Area3DStyle.PointDepth = 30;
                chart.GetChartArea().Area3DStyle.IsRightAngleAxes = true;
                chart.GetChartArea().Area3DStyle.Rotation = 20;
                chart.GetChartArea().Area3DStyle.Inclination = 20;
                chart.GetSeries("จำนวนคน")["DrawingStyle"] = "Cylinder";

                DateTime now         = DateTime.Now;
                DateTime yearCutOff  = new DateTime(now.Year, 9, 30, 23, 59, 59);
                int      currentYear = now.Year;
                if (now > yearCutOff)
                {
                    currentYear += 1;
                }
                if (currentYear < 2500)
                {
                    currentYear += 543;
                }
                chart.AddLeftAnnotation("(1 ตุลาคม " + currentYear + ")", 67, 10);

                byte[] dataArray = chart.Render();

                string filename = "image.png";
                context.Response.ContentType = "image/png";
                context.Response.AddHeader("Content-Disposition", "attachment; filename=\"" + filename + "\"");
                context.Response.OutputStream.Write(dataArray, 0, dataArray.Length);
            }
            else
            {
                context.Response.ContentType = "text/plain";
                context.Response.Write("Error: Year was not specified");
            }
        }