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

ASP.NET
使用函数传递参数来执行相应的数据库操作
如何实现在窗体和窗体之间进行传递数据
ASP.NET中文显示之两种解决方法
ASP.NET、JSP及PHP之间的抉择
ASP.NET 2.0发送电子邮件中存在的问题
谈谈HtmlControl与WebControl的区别与用途
从ASP.NET 1.1升级到ASP.NET 2.0要考虑的Cookie问题
通过系统配置来提高ASP.NET应用程序的稳定性
妙用ASP2.0中的URL映射改变网址
AJAX实现web页面中级联菜单的设计
ASP.NET跨页面传值技巧总结
再议ASP.NET DataGrid控件中的“添加新行”功能
Geometry 对象浅析
重构CollapsibleSplitter
如何利用.NET Framework使用RSS feed
ASP.NET获取IP与MAC地址的方法
在ASP.NET 2.0中使用样式、主题和皮肤
ASP.NET中为GridView添加删除提示框
ASP.NET 2.0,无刷新页面新境界
看看一个.net版对话框控件

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


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-03   浏览: 30 ::
收藏到网摘: 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) ;

//写字