Example #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;
                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;
                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");
            }
        }
Example #3
0
        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         usages = from type in ctx.budgetusages
                                     where type.Year == year
                                     select type;
                var usageList = usages.ToList();

                List <string>  xValues  = new List <string>();
                List <decimal> yValues  = new List <decimal>();
                List <decimal> yValues2 = new List <decimal>();

                DateTime lastUpdated = DateTime.MinValue;
                foreach (var usage in usageList)
                {
                    xValues.Add(usage.budgettype1.TypeName);
                    yValues.Add(usage.BudgetAmount - usage.Used);
                    yValues2.Add(usage.Used);
                    if (usage.LastUpdated > lastUpdated)
                    {
                        lastUpdated = usage.LastUpdated;
                    }
                }
                ColumnChart chart = new ColumnChart(xValues.ToArray());
                chart.SetLastUpdated(lastUpdated);
                chart.AddSeries("งบประมาณ (ลบ.)", yValues.ToArray());
                chart.AddSeries("เบิกจ่าย (ลบ.)", yValues2.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("งบประมาณ (ลบ.)").ChartType       = SeriesChartType.StackedColumn;
                chart.GetSeries("เบิกจ่าย (ลบ.)").ChartType       = SeriesChartType.StackedColumn;
                chart.GetSeries("งบประมาณ (ลบ.)")["DrawingStyle"] = "Cylinder";
                chart.GetSeries("เบิกจ่าย (ลบ.)")["DrawingStyle"] = "Cylinder";
                chart.GetSeries("งบประมาณ (ลบ.)").Color           = ColorPalette.GetColor(0);
                chart.GetSeries("เบิกจ่าย (ลบ.)").Color           = ColorPalette.GetColor(1);

                Series series = chart.GetSeries("เบิกจ่าย (ลบ.)");
                int    runner = 0;
                foreach (var usage in usageList)
                {
                    decimal percent = (usage.Used / usage.BudgetAmount) * 100m;
                    series.Points[runner].Label = "#VALY{N0}\n(" + percent.ToString("N2") + "%)";
                    runner++;
                }

                series = chart.GetSeries("งบประมาณ (ลบ.)");
                runner = 0;
                foreach (var usage in usageList)
                {
                    series.Points[runner].Label = usage.BudgetAmount.ToString("N0");
                    runner++;
                }

                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");
            }
        }
        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))
            {
                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");
            }
        }