view_report.aspx
来自「Bug管理系统」· ASPX 代码 · 共 596 行 · 第 1/2 页
ASPX
596 行
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>
<%@ Import Namespace="System.Drawing" %>
<%@ Import Namespace="System.Drawing.Imaging" %>
<!-- #include file = "inc.aspx" -->
<script language="C#" runat="server">
String sql;
DbUtil dbutil;
Security security;
///////////////////////////////////////////////////////////////////////
void Page_Load(Object sender, EventArgs e)
{
Util.do_not_cache(Response);
dbutil = new DbUtil();
security = new Security();
security.check_security(dbutil, Request, Response, Security.ANY_USER_OK);
// title.InnerText = Util.get_setting("AppTitle","BugTracker.NET") + " - "
// + "view report";
string string_id = Util.sanitize_integer(Request["id"]);
string view = Request["view"];
sql = @"select rp_desc, rp_sql, rp_chart_type
from reports
where rp_id = $id";
sql = sql.Replace("$id", string_id);
DataRow dr = dbutil.get_datarow (sql);
string rp_sql = (string) dr["rp_sql"];
// replace the magic pseudo variable
rp_sql = rp_sql.Replace("$ME", Convert.ToString(security.this_usid));
DataSet ds = dbutil.get_dataset (rp_sql);
if (ds.Tables[0].Rows.Count > 0)
{
if (view == "data")
{
create_table((string) dr["rp_desc"], ds);
}
else
{
if ((string) dr["rp_chart_type"] == "pie")
{
create_pie_chart((string) dr["rp_desc"], ds);
}
else if ((string) dr["rp_chart_type"] == "bar")
{
create_bar_chart((string) dr["rp_desc"], ds);
}
else if ((string) dr["rp_chart_type"] == "line")
{
// we need at least two values to draw a line
if (ds.Tables[0].Rows.Count > 1)
{
create_line_chart((string) dr["rp_desc"], ds);
}
}
else {
create_table((string) dr["rp_desc"], ds);
}
}
}
else
{
create_table((string) dr["rp_desc"], ds);
}
}
///////////////////////////////////////////////////////////////////////
void Page_Unload(Object sender, EventArgs e)
{
if (dbutil != null) {dbutil.close();}
}
///////////////////////////////////////////////////////////////////////
void create_line_chart(string title, DataSet ds)
{
int chart_width=640;
int chart_height=300;
int chart_top_margin = 10; // gap between highest bar and border of chart
int x_axis_text_offset = 8; // gap between edge and start of x axis text
int page_top_margin = 40; // gape between chart and top of page
int max_grid_lines = 20;
Font fontTitle = new Font("Verdana", 12, FontStyle.Bold);
Font fontLegend = new Font("Verdana", 8);
int page_bottom_margin = 3 * fontLegend.Height;
int page_left_margin = (4 * fontLegend.Height) + x_axis_text_offset ; // where the y axis text goes
// find the max of the y axis so we know how to scale the data
float max = 0.0F;
float tmp;
int i;
for (i = 0; i < ds.Tables[0].Rows.Count; i++)
{
tmp = Convert.ToSingle(ds.Tables[0].Rows[i][1]);
if (tmp > max) {max = tmp;};
}
float vertical_scale_factor = (chart_height - chart_top_margin)/max;
// determine how the horizontal grid lines should be
int grid_line_interval = 1;
if (max > 1) {
while (max / grid_line_interval > max_grid_lines)
{
grid_line_interval *= 10;
}
}
// Create a Bitmap instance
Bitmap objBitmap = new Bitmap(
page_left_margin + chart_width, // total width
page_top_margin + fontTitle.Height + chart_height + page_bottom_margin); // total height
Graphics objGraphics = Graphics.FromImage(objBitmap);
// white overall background
objGraphics.FillRectangle(
new SolidBrush(Color.White), // yellow
0,0,
page_left_margin + chart_width, // far left
page_top_margin + fontTitle.Height + chart_height + page_bottom_margin); // bottom
// gray chart background
objGraphics.FillRectangle(
new SolidBrush(Color.FromArgb(204,204,204)), // gray
page_left_margin, page_top_margin + fontTitle.Height,
page_left_margin + chart_width,
chart_height);
SolidBrush blackBrush = new SolidBrush(Color.Black);
// draw title
objGraphics.DrawString(
title,
fontTitle,
blackBrush,
x_axis_text_offset,
fontTitle.Height / 2);
int y;
int chart_bottom = page_top_margin + fontTitle.Height + chart_height;
Pen black_pen = new Pen(Color.Black, 1);
for (i = 0; i < max; i+= grid_line_interval)
{
y = (int)(i * vertical_scale_factor);
// y axis label
objGraphics.DrawString(
Convert.ToString(i),
fontLegend,
blackBrush,
x_axis_text_offset, (chart_bottom-y) - (fontLegend.Height/2));
// grid line
objGraphics.DrawLine(
black_pen,
page_left_margin,
chart_bottom-y,
page_left_margin + chart_width,
chart_bottom-y);
}
/*
// draw high water mark
y = (int)(max * vertical_scale_factor);
objGraphics.DrawString(
Convert.ToString(i),
fontLegend,
blackBrush,
x_axis_text_offset, (chart_bottom-y) - (fontLegend.Height/2));
// grid line
objGraphics.DrawLine(
black_pen,
page_left_margin,
chart_bottom-y,
page_left_margin + chart_width,
chart_bottom-y);
*/
// draw lines
int line_length = chart_width / (ds.Tables[0].Rows.Count-1);
int x = page_left_margin;
int x_axis_text_y = chart_bottom + (page_bottom_margin/2) - (fontLegend.Height/2);
Pen blue_pen = new Pen(Color.FromArgb(0,0,204), 2);
SolidBrush blue_brush = new SolidBrush(Color.FromArgb(0,0,204));
for (i = 1; i < ds.Tables[0].Rows.Count; i++)
{
float data1 = Convert.ToSingle((int)ds.Tables[0].Rows[i-1][1]);
float data2 = Convert.ToSingle((int)ds.Tables[0].Rows[i][1]);
int value_y1 = (int)(data1 * vertical_scale_factor);
int value_y2 = (int)(data2 * vertical_scale_factor);
objGraphics.DrawLine(
blue_pen,
x, chart_bottom - value_y1,
x + line_length, chart_bottom - value_y2);
objGraphics.FillEllipse(
blue_brush,
(x + line_length)-3, (chart_bottom - value_y2) - 3,
6, 6);
x += line_length;
}
// Since we are outputting a Jpeg, set the ContentType appropriately
Response.ContentType = "image/jpeg";
// Save the image to a file
objBitmap.Save(Response.OutputStream, ImageFormat.Jpeg);
// clean up...
objGraphics.Dispose();
objBitmap.Dispose();
}
///////////////////////////////////////////////////////////////////////
void create_bar_chart(string title, DataSet ds)
{
int chart_width=640;
int chart_height=300;
int chart_top_margin = 10; // gap between highest bar and border of chart
int x_axis_text_offset = 8; // gap between edge and start of x axis text
int page_top_margin = 40; // gape between chart and top of page
int max_grid_lines = 20;
Font fontTitle = new Font("Verdana", 12, FontStyle.Bold);
Font fontLegend = new Font("Verdana", 8);
int page_bottom_margin = 3 * fontLegend.Height;
int page_left_margin = (4 * fontLegend.Height) + x_axis_text_offset ; // where the y axis text goes
// find the max of the y axis so we know how to scale the data
float max = 0.0F;
float tmp;
int i;
for (i = 0; i < ds.Tables[0].Rows.Count; i++)
{
tmp = Convert.ToSingle(ds.Tables[0].Rows[i][1]);
if (tmp > max) {max = tmp;};
}
float vertical_scale_factor = (chart_height - chart_top_margin)/max;
// determine how the horizontal grid lines should be
int grid_line_interval = 1;
if (max > 1) {
while (max / grid_line_interval > max_grid_lines)
{
grid_line_interval *= 10;
}
}
// Create a Bitmap instance
Bitmap objBitmap = new Bitmap(
page_left_margin + chart_width, // total width
page_top_margin + fontTitle.Height + chart_height + page_bottom_margin); // total height
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?