当前位置: 首页 > 图文教程 > 网络编程 > ASP.NET > 从一个舆论调查的制作谈面向对象的编程思路(四)

ASP.NET
FreeTextBox(版本3.1.6)在ASP.Net 2.0中使用方法
.NET 常用功能和代码小结
在 .NET Framework 2.0 中未处理的异常导致基于 ASP.NET 的应用程序意外退出
asp.net IList查询数据后格式化数据再绑定控件
asp.net sql存储过程
asp.net 简单实现禁用或启用页面中的某一类型的控件
asp.net(c#)获取内容第一张图片地址的函数
The remote procedure call failed and did not execute的解决办法
ASP.NET 在线文件管理
asp.net 读取并修改config文件实现代码
ASP.NET Cookie 操作实现
asp.net Silverlight中的模式窗体
Silverlight中动态获取Web Service地址
asp.net Silverlight应用程序中获取载体aspx页面参数
asp.net 水晶报表隔行换色实现方法
asp.net 获取Gridview隐藏列的值
手动把asp.net的类生成dll文件的方法
asp.net 使用ObjectDataSource控件在ASP.NET中实现Ajax真分页
动态指定任意类型的ObjectDataSource对象的查询参数
asp.net Md5的用法小结

ASP.NET 中的 从一个舆论调查的制作谈面向对象的编程思路(四)


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-03   浏览: 42 ::
收藏到网摘: n/a

public MyChart()
{
//
// TODO: Add Constructor Logic here
//
m_arrItems = new ArrayList() ;
m_strTitle = "" ;
m_objBackColor = Color.White ;
m_intWidth = 200 ;
m_intHeight = 200 ;
m_intChartType = ChartType.Pie ;
m_strUnit = "" ;
}

/// <summary>
/// 重载构造函数
/// </summary>
/// <param name="a_strTitle"> </param>
/// <param name="a_objBackColor"> </param>
/// <param name="a_intWidth"> </param>
/// <param name="a_intHeight"> </param>
/// <param name="a_intChartType"> </param>
/// <param name="a_strUnit"> </param>
public MyChart(string a_strTitle , System.Drawing.Color a_objBackColor ,
int a_intWidth , int a_intHeight , ChartType a_intChartType , string a_strUnit)
{
m_arrItems = new ArrayList() ;
m_strTitle = a_strTitle ;
m_objBackColor = a_objBackColor ;
m_intWidth = a_intWidth ;
m_intHeight = a_intHeight ;
m_intChartType = a_intChartType ;
m_intTotalCount = 0 ;
m_strUnit = a_strUnit ;
}

/// <summary>
/// 添加一个新的统计图项目
/// </summary>
/// <param name="a_objItem"> </param>
public void AddItem(object a_objItem)
{
if(a_objItem is MyClass.Util.ChartItem)
{
m_arrItems.Add(a_objItem) ;
m_intTotalCount += ((ChartItem)a_objItem).Count ;
}
else
{
throw(new Exception("对象类型错误,要加入的必须是ChartItem对象")) ;
}
}

/// <summary>
/// 产生统计图图片
/// </summary>
/// <param name="a_strFileName">要保存的文件名 </param>
/// <remarks>
/// a_strFileName必须是绝对物理路径
/// </remarks>
public void Create(string a_strFileName)
{
//如果没有定义统计图项,则抛出异常
if (m_arrItems.Count == 0)
{
throw(new Exception("没有定义统计图项")) ;
}


//根据不同统计图类型选择函数
switch(m_intChartType)
{
case ChartType.Bar:
DrawBar(a_strFileName) ;
break;

case ChartType.Pie:
DrawPie(a_strFileName) ;
break ;

case ChartType.Curve:
DrawCurve(a_strFileName) ;
break ;

default:
DrawPie(a_strFileName) ;
break ;
}

}

/// <summary>
/// 画条形图
/// </summary>
/// <param name="a_strFileName">要保存的图片名称</param>
protected void DrawBar(string a_strFileName)
{
//绘图准备,新建一个image对象,一个graphics对象
System.Drawing.Image myBmp = new Bitmap(m_intWidth , m_intHeight ) ;
System.Drawing.Graphics g = Graphics.FromImage(myBmp) ;

//填充背景
g.FillRectangle(new System.Drawing.SolidBrush(m_objBackColor) , 0 , 0 , m_intWidth , m_intHeight) ;

//如果没有任何回答,则显示没有结果
if (this.m_intTotalCount == 0)
{
g.DrawString("没有统计数字!" , new Font("宋体" , m_intWidth / 14) ,
new SolidBrush(Color.Red) , (m_intWidth - m_intWidth / 8 * 6) / 2 ,
m_intHeight / 2 - m_intWidth / 8) ;
}
else
{

//写题目

//g.DrawString(m_strTitle , new System.Drawing.Font("黑体" , m_intWidth / 30) ,
// new System.Drawing.SolidBrush(Color.Black) , (m_intWidth - m_strTitle.Length * (m_intWidth / 30))/2 , 10 ,
// System.Drawing.StringFormat.GenericDefault) ;


//画统计图项目的矩形
//计算每个矩形的宽度
int intWidth = m_intWidth / (m_arrItems.Count * 2 - 1) ;

//定义一个一个像素宽的黑色的笔
System.Drawing.Pen pen = new System.Drawing.Pen(new System.Drawing.SolidBrush(Color.Black) , 1) ;

for (int i = 0 ; i < m_arrItems.Count ; i ++)
{
ChartItem item = (ChartItem)m_arrItems[i] ;

//计算所占百分比
float intPercent = (float)Decimal.Divide(item.Count * 100 , m_intTotalCount) ;

//计算矩形高度
int intHeight = (int)(m_intHeight/ 3 * 2 * intPercent / 100 - 10) ;

//计算矩形坐标
int ix = intWidth * i * 3 / 2 + intWidth ;
int iy = m_intHeight / 3 * 2 - intHeight ;


//画矩形
g.FillRectangle(new System.Drawing.SolidBrush(item.Color) ,
ix , iy , intWidth , intHeight + 10) ;

//写字