using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Drawing.Drawing2D;
using System.IO;
using System.Data;
/*********************************************************************************************************************
* Date: 2007- 6 - 13
* Creator: JueJue
* Summary: Ò»¸ö×Ô¶¯Í³¼ÆͼÉú³É¿Ø¼þ£¬¾ßÓи߶ȵĿɶ¨ÖÆÌØÐÔ¡£ÌṩͼƬ±£´æ¹¦ÄÜ¡£
*
* Step: 1> ×¼±¸Êý¾Ý
* 2> ×¼±¸¸÷ÏîÊôÐÔ
* 3> ¿ªÊ¼»æÖÆ
* 4> À¬»ø»ØÊÕ
* *********************************************************************************************************************/
namespace Xc_mzb_DoctorWorks
{
/// <summary>
/// ×Ô¶¨Òåͼ±í
/// </summary>
public class CustomeChart : PictureBox
{
#region Important Fields
/// <summary>µ±Ç°Í³¼ÆͼµÄλͼ</summary>
Bitmap myBitmap = null;
/// <summary>±³¾°ÑÕÉ«</summary>
Color bgc = Color.White;
/// <summary>¾ö¶¨»æÖÆÖÊÁ¿</summary>
System.Drawing.Text.TextRenderingHint trh = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;
/// <summary>´æ·Å½«Òª×÷Ϊͳ¼Æͼ»æÖÆÒÀ¾ÝµÄÊý¾Ý</summary>
ArrayList myValue = new ArrayList();
/// <summary>×¼±¸Í³¼ÆµÄÊý¾Ý</summary>
public DataTable dtValue = new DataTable();
#endregion
#region Brushes and Fonts and Pens of X axis and Y axis
Pen px = Pens.Black; // X×ø±êÖá»±Ê
Pen py = Pens.Black; // Y×ø±êÖá»±Ê
Pen pxStuff = new Pen( Brushes.Black, 2 ); // X×ø±êÖá¶Ì×®»±Ê
Pen pyStuff = Pens.Black; // Y×ø±êÖá¶Ì×®»±Ê
Pen pxArrow = Pens.Black; // X×ø±ê¼ýÍ·»±Ê
Pen pyArrow = Pens.Black; // Y×ø±ê¼ýÍ·»±Ê
Pen pRec = Pens.Blue; // ÍâΧ¾ØÐοòµÄÑÕÉ«
Pen pxEnd = new Pen( Brushes.Red, 2 ); // X×ø±êÖá×îÄ©¶Ì×®µÄ»±Ê
Pen pyStubTot = new Pen( Brushes.Red, 1 ); // ºÏ¼Æ¶Ì×®»±Ê
Brush bStubTot = Brushes.Blue; // ºÏ¼Æ¶Ì×®»Ë¢
Brush bTot = Brushes.RoyalBlue; // ºÏ¼ÆÖùµÄ»Ë¢
Brush bWa = Brushes.Red; // ºòÕïÖùµÄ»Ë¢
Brush bAl = Brushes.Blue; // ÔÚÕïÖùµÄ»Ë¢
Brush bLe= Brushes.Gray; // ÒÑÕïÖùµÄ»Ë¢
Brush bCh = Brushes.Yellow; // תÕïÖùµÄ»Ë¢
Brush normalBrush = Brushes.Black; // Õý³£Çé¿öϵĻˢ
Brush XYBrush = Brushes.Blue; // XYÖá»ãºÏ´¦µÄ»Ë¢
Font captionFont = new Font( "ËÎÌå", 18, FontStyle.Bold ); // Ö÷±êÌâ×ÖÌå
Font normalFont = new Font( "ËÎÌå", 9 ); // Ò»°ã×ÖÌå
Font XYFont = new Font( "ËÎÌå", 9 ); // XYÖá×ÖÌå
Color ct1 = Color.RoyalBlue; // ½¥±äµÚһɫ
Color ct2 = Color.White; // ½¥±äµÚ¶þÉ«
Color ct3 = Color.RoyalBlue; // ½¥±äµÚÈýÉ«
#endregion
#region Length, Height, Width of A axis and Y axis
Point xy; // Á½×ø±êÖá½»½ç´¦µÄ×ø±ê
int times = 1; // YÖá¼ä¸ô´óС
int hx = 0; // X×ø±êÖ᳤¶È
int hy = 0; // Y×ø±êÖá¸ß¶È
int mLeft = 45; // ×ó±ß¾à
int mRight = 20; // Óұ߾à
int mTop = 30; // ¶¥²¿±ß¾à
int mBottom = 31; // µ×²¿±ß¾à
int myMax = 0; // ÖµµÄ×î´óÖµ
int baseSpan = 60; // X×ø±êÖáÒ»¸öÊý¾ÝµÄ¿í¶È£¨¼ÓÉÏ¿Õ°×£©
int baseInterval = 10;
int begX = 10; // X×ø±ê¿ªÊ¼»æÖƵã
double unitY = 0;
int unitX = 0;
int XMargin = 10; // X×ø±êÖáĩ׮ºÍX¼ýÍ·¼ä¾à
int YMargin = 55; // y×ø±êÖáĩ׮ºÍY¼ýÍ·¼ä¾à
#endregion
#region String object
string name = string.Empty; // Ò½ÉúÐÕÃû
string dept = string.Empty; // ¿ÆÊÒÃû³Æ
string tBegin = string.Empty; // ¿ªÊ¼Ê±¼ä
string tEnd = string.Empty; // ½áÊøʱ¼ä
public string title = string.Empty; // ¸±±êÌâ
string caption = "ÃÅÕﲿҽʦ¹¤×÷Á¿Í³¼Æͼ"; // Ö÷±êÌâ
[Category("MyChartOption"), Description("Ö¸¶¨Í³¼ÆͼµÄÖ÷±êÌâ¡£") ]
public string Caption
{
get{ return this.caption; }
set{ this.caption = value; base.Invalidate(); }
}
[Category("MyChartOption"), Description("Ö¸¶¨ºÏ¼Æ¾ØÐοòµÚÒ»½¥±äÉ«¡£") ]
public Color Ct1
{
get{ return this.ct1; }
set{ this.ct1 = value; base.Invalidate(); }
}
[Category("MyChartOption"), Description("Ö¸¶¨ºÏ¼Æ¾ØÐοòµÚ¶þ½¥±äÉ«¡£") ]
public Color Ct2
{
get{ return this.ct2; }
set{ this.ct2 = value; base.Invalidate(); }
}
[Category("MyChartOption"), Description("Ö¸¶¨ºÏ¼Æ¾ØÐοòµÚÈý½¥±äÉ«¡£") ]
public Color Ct3
{
get{ return this.ct3; }
set{ this.ct3 = value; base.Invalidate(); }
}
#endregion
#region System Fields
/// <summary>
/// ±ØÐèµÄÉè¼ÆÆ÷±äÁ¿¡£
/// </summary>
private System.ComponentModel.Container components = null;
private System.Windows.Forms.ContextMenu cmMain;
private System.Windows.Forms.MenuItem menuItem1;
private System.Windows.Forms.MenuItem menuItem2;
private System.Windows.Forms.MenuItem menuItem3;
private System.Windows.Forms.MenuItem menuItem4;
private System.Windows.Forms.MenuItem menuItem5;
private System.Windows.Forms.MenuItem menuItem6;
private System.Windows.Forms.MenuItem menuItem7;
private System.Windows.Forms.MenuItem menuItem8;
private System.Windows.Forms.MenuItem menuItem9;
private System.Windows.Forms.MenuItem menuItem10;
private System.Windows.Forms.MenuItem menuItem11;
private System.Windows.Forms.MenuItem menuItem12;
private System.Windows.Forms.MenuItem menuItem13;
private System.Windows.Forms.MenuItem menuItem14;
private System.Windows.Forms.MenuItem menuItem15;
#endregion
#region Constructor and GC
/// <summary>
/// ¹¹ÔìÆ÷
/// </summary>
public CustomeChart()
{
//
// Windows ´°ÌåÉè¼ÆÆ÷Ö§³ÖËù±ØÐèµÄ
//
InitializeComponent();
// Mine
}
/// <summary>
/// ÇåÀíËùÓÐÕýÔÚʹÓõÄ×ÊÔ´¡£
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#endregion
#region Windows ´°ÌåÉè¼ÆÆ÷Éú³ÉµÄ´úÂë
/// <summary>
/// Éè¼ÆÆ÷Ö§³ÖËùÐèµÄ·½·¨ - ²»ÒªÊ¹ÓôúÂë±à¼Æ÷ÐÞ¸Ä
/// ´Ë·½·¨µÄÄÚÈÝ¡£
/// </summary>
private void InitializeComponent()
{
this.cmMain = new System.Windows.Forms.ContextMenu();
this.menuItem1 = new System.Windows.Forms.MenuItem();
this.menuItem2 = new System.Windows.Forms.MenuItem();
this.menuItem3 = new System.Windows.Forms.MenuItem();
this.menuItem4 = new System.Windows.Forms.MenuItem();
this.menuItem5 = new System.Windows.Forms.MenuItem();
this.menuItem6 = new System.Windows.Forms.MenuItem();
this.menuItem7 = new System.Windows.Forms.MenuItem();
this.menuItem8 = new System.Windows.Forms.MenuItem();
this.menuItem9 = new System.Windows.Forms.MenuItem();
this.menuItem10 = new System.Windows.Forms.MenuItem();
this.menuItem11 = new System.Windows.Forms.MenuItem();
this.menuItem12 = new System.Windows.Forms.MenuItem();
this.menuItem13 = new System.Windows.Forms.MenuItem();
this.menuItem14 = new System.Windows.Forms.MenuItem();
this.menuItem15 = new System.Windows.Forms.MenuItem();
//
// cmMain
//
this.cmMain.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem1,
this.menuItem7,
this.menuItem6,
this.menuItem2});
//
// menuItem1
//
this.menuItem1.Index = 0;
this.menuItem1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem3,
this.menuItem4,
this.menuItem5});
this.menuItem1.Text = "ÏÔʾÖÊÁ¿";
//
// menuItem2
//
this.menuItem2.Index = 3;
this.menuItem2.Text = "Áí´æΪ¡";
this.menuItem2.Click += new System.EventHandler(this.menuItem3_Click);
//
// menuItem3
//
this.menuItem3.Index = 0;
this.menuItem3.Text = "µÍ";
this.menuItem3.Click += new System.EventHandler(this.menuItem3_Click);
//
// menuItem4
//
this.menuItem4.Index = 1;
this.menuItem4.Text = "ÖÐ";
this.menuItem4.Click += new System.EventHandler(this.menuItem3_Click);
//
// menuItem5
//
this.menuItem5.Checked = true;
this.menuItem5.Index = 2;
this.menuItem5.Text = "¸ß£¨Ä¬ÈÏ£©";
this.menuItem5.Click += new System.EventHandler(this.menuItem3_Click);
//
// menuItem6
//
this.menuItem6.Index = 2;
this.menuItem6.Text = "-";
//
// menuItem7
//
this.menuItem7.Index = 1;
this.menuItem7.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem8,
this.menuItem9,
this.menuItem10,
this.menuItem11,
this.menuItem12,
this.menuItem13,
this.menuItem15,
this.menuItem14});
this.menuItem7.Text = "±³¾°ÑÕÉ«";
//
// menuItem8
//
this.menuItem8.Index = 0;
this.menuItem8.Text = "ÑÌ°×";
this.menuItem8.Click += new System.EventHandler(this.menuItem8_Click);
//
// menuItem9
//
this.menuItem9.Index = 1;
this.menuItem9.Text = "»Ê¼ÒÀ¶";
this.menuItem9.Click += new System.EventHandler(this.menuItem8_Click);
//
// menuItem10
//
this.menuItem10.Index = 2;
this.menuItem10.Text = "怅";
this.menuItem10.Click += new System.EventHandler(this.menuItem8_Click);
//
// menuItem11
//
this.menuItem11.Index = 3;
this.menuItem11.Text = "dzÂÌ";
this.menuItem11.Click += new System.EventHandler(this.menuItem8_Click);
//
// menuItem12
//
this.menuItem12.Index = 4;
this.menuItem12.Text = "Âó»Æ";
this.menuItem12.Click += new System.EventHandler(this.menuItem8_Click);
//
// menuItem13
//
this.menuItem13.Checked = true;
this.menuItem13.Index = 5;
this.menuItem13.Text = "´¿°×£¨Ä¬ÈÏ£©";
this.menuItem13.Click += new System.EventHandler(this.menuItem8_Click);
//
// menuItem14
//
this.menuItem14.Index = 7;
this.menuItem14.Text = "×Ô¶¨Òå¡";
this.menuItem14.Click += new System.EventHandler(this.menuItem14_Click);
//
// menuItem15
//
this.menuItem15.Index = 6;
this.menuItem15.Text = "-";
//
// FrmChart
//
this.ContextMenu = this.cmMain;
this.Name = "FrmChart";
this.Text = "FrmChart";
this.Resize += new System.EventHandler(this.FrmChart_Resize);
this.Paint += new System.Windows.Forms.PaintEventHandler(this.FrmChart_Paint);
}
#endregion
#region Common Methods
/// <summary>
/// ðÅÝÅÅÐò
/// </summary>
/// <param name="a">Êý×é</param>
private void Sort( params int[] a )
{
for( int i = 0; i < 3; i ++ )
{
for( int m = 1; m < 4 - i; m ++ )
{
int k = 0;
if( a[ m ] > a[ m - 1 ] )
{
k = a[ m ];
a[ m ] = a[ m - 1 ];
a[ m - 1 ] = k;
}
}
}
}
/// <summary>
/// ʵÀý»¯±êÌâºÍ¸±±êÌâ
/// </summary>
private void InitializeTitle()
{
//title = "²éÕÒ·¶Î§[" + dept + name + "] ʱ¼ä¶Î£º[" + tBegin + " - " + tEnd + "]";
}
/// <summary>
/// ×¼±¸½«Òª»æÖƵÄÊý¾Ý
/// </summary>
private void InitializeMyValue()
{
myValue.Clear();
if( dtValue == null || dtValue.Rows.Count == 0 )
{
Value v1 = new Value( "ÄÏ°¶ÆÕ¶Ù", "È˹¤ÖÇÄÜ¿Æ", 12, 10, 11, 1, 99 );
Value v2 = new Value( "ÁõÐã", "È˹¤ÖÇÄÜ¿Æ", 7, 8, 6, 3, 24 );
Value v3 = new Value( "ºúÒþÃÎ", "È˹¤ÖÇÄÜ¿Æ", 5, 10, 11, 1, 127 );
Value v4 = new Value( "ÁõÐã", "È˹¤ÖÇÄÜ¿Æ", 22, 8, 6, 3, 39 );
Value v5 = new Value( "Bill", "È˹¤ÖÇÄÜ¿Æ", 12, 10, 7, 17, 46 );
Value v6 = new Value( "ÁõÐã", "È˹¤ÖÇÄÜ¿Æ", 2, 8, 6, 3, 19 );
myValue.AddRange( new Value[] { v1, v2,v3, v4, v5, v6 } );
}
else
{
int len = dtValue.Rows.Count;
Value[] v = new Value[ len ];
for( int i = 0; i < len; i ++ )
{
v[ i ] = new Value( dtValue.Rows[ i ][ 0 ].ToString(),
string.Empty,
Convert.ToInt32( dtValue.Rows[ i ][ 1 ] ),
Convert.ToInt32( dtValue.Rows[ i ][ 2 ] ),
Convert.ToInt32( dtValue.Rows[ i ][ 3 ] ),
Convert.ToInt32( dtValue.Rows[ i ][ 4 ] ),
Convert.ToInt32( dtValue.Rows[ i ][ 5 ] )
);
}
myValue.AddRange( v );
}
}
/// <summary>
/// ¼ÆËã×î´óÖµ
/// </summary>
private void CalculateMax( )
{
times = 1;
myMax = 0;
if( myValue == null || myValue.Count == 0 )
{
this.myMax = 0;
return;
}
foreach( object o in myValue )
{
Value v = o as Value;
if( v.Tot > myMax )
{
myMax = v.Tot;
}
}
times = myMax <= 51 ? times : myMax % 50 != 0 ? myMax / 50 + 1 : myMax / 50;
}
/// <summary>
/// ¼ÆËã»ù±¾¼ä¾à
/// </summary>
private void CalculateBaseUnit()
{
if( myMax == 0 )
{
return;
}
int len = myValue.Count;
hx -= XMargin;
hy -= YMargin;
unitY = (double)hy / (double)myMax;
unitX = (int)Math.Ceiling( (hx - begX )/ len );
}
/// <summary>
/// ¼ÆËã±êÌâµÄ´óС£¨ÏñËØΪµ¥Î»£©
/// </summary>
/// <returns>´óС</returns>
private Size MeasureCaption()
{
if( caption == string.Empty )
{
return Size.Empty;
}
SizeF s = this.CreateGraphics().MeasureString( caption, captionFont );
Size cs = new Size( ( this.Width - ( int )s.Width ) / 2, ( int )s.Height );
return cs;
}
/// <summary>
/// »æÖÆ»·ÈÆÔÚͳ¼ÆͼÍâµÄ¾ØÐÎ
/// </summary>
/// <param name="g">»æÃæͼ</param>
/// <param name="width">¿í¶È</param>
/// <param name="height">¸ß¶È</param>
private void DrawRectangle( Graphics g, int width, int height )
{
CalculateMax();
g.Clear( bgc );
g.DrawRectangle( this.pRec, 5, 5, width, height );
}
/// <summary>
/// »æÖÆÖ÷±êÌâ
/// </summary>
/// <param name="g">»æÃæͼ</param>
private void DrawCaption( Graphics g )
{
Size s = this.MeasureCaption();
if( myMax == 0 )
{
g.DrawString( "ûÓÐÊý¾Ý£¬ÑÝʾ£¡", captionFont, normalBrush, s.Width, s.Height );
}
else
{
g.DrawString( caption, captionFont, normalBrush, s.Width, s.Height );
}
SizeF sf = g.MeasureString( title, normalFont );
if( trh == System.Drawing.Text.TextRenderingHint.AntiAlias )
{
Rectangle r = new Rectangle( this.Width - s.Width + 4, s.Height + 16, (int)sf.Width, 15 );
g.DrawRectangle( Pens.Blue, r );
}
else
{
Rectangle r = new Rectangle( this.Width - s.Width + 4, s.Height + 16, (int)sf.Width - 8, 15 );
g.DrawRectangle( Pens.Blue, r );
}
g.DrawString( title, normalFont, normalBrush, this.Width - s.Width + 4, s.Height + 18 );
}
/// <summary>
/// »æÖÆX¡¢Y×ø±ê
/// </summary>
/// <param name="g">»æÃæͼ</param>
/// <param name="x">X×ø±êÖá</param>
/// <param name="y">Y×ø±êÖá</param>
private void DrawFramework( Graphics g, int x, int y )
{
g.DrawLine( px, xy, new Point( x, mTop ) );
g.DrawLine( px, new Point( x, mTop ), new Point( x - 4, mTop + 10 ) );
g.DrawLine( px, new Point( x, mTop ), new Point( x + 4, mTop + 10 ) );
g.DrawLine( py, xy, new Point( this.Width - mRight, y ) );
g.DrawLine( px, new Point( Width - mRight, y ), new Point( Width - mRight - 10, y + 4 ) );
g.DrawLine( px, new Point( Width - mRight, y ), new Point( Width - mRight - 10, y - 4 ) );
g.DrawString( "0", XYFont, XYBrush, x - 1, y + 1 );
}
/// <summary>
/// »æÖƶÌ×®
/// </summary>
private void DrawStub( Graphics g )
{
if( myMax == 0 )
{
return;
}
CalculateBaseUnit();
StringFormat sf = new StringFormat();
sf.Alignment = StringAlignment.Far;
sf.LineAlignment = StringAlignment.Far;
sf.FormatFlags = StringFormatFlags.NoWrap;
int meeting = myMax / times;
string s1 = string.Empty;
for( int i = 1; i <= meeting ; i ++ )
{
Point p1 = new Point( xy.X, xy.Y - (int)( unitY * i * times ) );
Point p2 = new Point( xy.X + 3, (int)(xy.Y - unitY * i * times) );
s1 = Convert.ToString( i * times );
g.DrawLine( pxStuff, p1, p2 );
g.DrawString( s1, normalFont, normalBrush, xy.X, xy.Y - (int)(unitY * i * times) + 8, sf );
}
if( int.Parse( s1 ) < myMax )
{
int l = int.Parse( s1 );
int offset = 1;
if( Math.Ceiling( ( myMax - l ) / times ) > 0.55 )
{
offset += (int)( 0.9 * unitY );
}
else
{
offset += 5;
}
Point p1 = new Point( xy.X, (int)(xy.Y - unitY * meeting * times - offset ) );
Point p2 = new Point( xy.X + 3, (int)(xy.Y - unitY * meeting * times - offset) );
s1 = myMax.ToString();
g.DrawLine( pxEnd, p1, p2 );
g.DrawString( s1, normalFont, normalBrush, xy.X, (int)(xy.Y - unitY * meeting * times + 8 - offset - 3), sf );
}
sf.Alignment = StringAlignment.Near;
sf.LineAlignment = StringAlignment.Near;
sf.FormatFlags = StringFormatFlags.NoFontFallback;
if( hx - 3 < baseSpan * myValue.Count )
{
for( int i = 0; i < myValue.Count; i ++ )
{
Value v = myValue[ i ] as Value;
string s = v.Name;
Point p1 = new Point( xy.X + begX + unitX * ( i - 0 ), xy.Y );
Point p2 = new Point( xy.X + begX + unitX * ( i - 0 ), xy.Y + 3 );
if( i == myValue.Count - 1 )
{
g.DrawLine( pyStubTot, p1, p2 );
g.DrawString( s, XYFont, bStubTot, p1.X, p1.Y + 4, sf );
}
else
{
g.DrawLine( pyStuff, p1, p2 );
g.DrawString( s, normalFont, normalBrush, p1.X, p1.Y + 4, sf );
}
}
}
else
{
for( int i = 0; i < myValue.Count; i ++ )
{
Value v = myValue[ i ] as Value;
string s = v.Name;
Point p1 = new Point( xy.X + begX + baseSpan * ( i - 0 ), xy.Y );
Point p2 = new Point( xy.X + begX + baseSpan * ( i - 0 ), xy.Y + 6 );
if( i == myValue.Count - 1 )
{
g.DrawLine( pyStubTot, p1, p2 );
g.DrawString( s, XYFont, bStubTot, p1.X, p1.Y + 4, sf );
}
else
{
g.DrawLine( pyStuff, p1, p2 );
g.DrawString( s, normalFont, normalBrush, p1.X, p1.Y + 4, sf );
}
}
}
}
/// <summary>
/// »æÖÆ×îºóµÄÊý¾Ý
/// </summary>
/// <param name="g">»æÃæͼ</param>
private void DrawData( Graphics g )
{
Value v = null;
for( int i = 0; i < myValue.Count; i ++ )
{
v = myValue[ i ] as Value;
int wa = v.Wa;
int al = v.Al;
int le = v.Le;
int ch = v.Ch;
int tot = v.Tot;
if( hx - 3 < baseSpan * myValue.Count )
{
int span = (int)Math.Ceiling( ( unitX - baseInterval ) / 4 );
Rectangle rWa = new Rectangle( xy.X + begX + unitX * ( i - 0 ) , (int)(xy.Y - wa * unitY), span, (int)(wa * unitY) );
Rectangle rAl = new Rectangle( xy.X + begX + unitX * ( i - 0 ) + span, (int)(xy.Y - al * unitY), span, (int)(al * unitY) );
Rectangle rLe = new Rectangle( xy.X + begX + unitX * ( i - 0 ) + span * 2, (int)(xy.Y - le * unitY), span, (int)(le * unitY) );
Rectangle rCh = new Rectangle( xy.X + begX + unitX * ( i - 0 ) + span * 3, (int)(xy.Y - ch * unitY), span, (int)(ch * unitY) );
Rectangle rTot = new Rectangle( xy.X + begX + unitX * ( i - 0 ), (int)(xy.Y - tot * unitY), unitX - baseInterval, (int)(v.Tot * unitY) );
//g.FillRectangle( this.bTot, rTot );
Rectangle rTot1 = new Rectangle( xy.X + begX + unitX * ( i - 0 ), (int)(xy.Y - tot * unitY), span * 2 + 4, (int)(v.Tot * unitY) + 1 );
Rectangle rTot2 = new Rectangle( xy.X + begX + unitX * ( i - 0 ) + span * 2 + 4, (int)(xy.Y - tot * unitY), span * 2 - 4, (int)(v.Tot * unitY) + 1 );
Brush bTot1 = new LinearGradientBrush( rTot1, ct1, ct2, LinearGradientMode.Horizontal );
Brush bTot2 = new LinearGradientBrush( rTot2, ct2, ct3, LinearGradientMode.Horizontal );
g.FillRectangle( bTot1, rTot1 );
g.FillRectangle( bTot2, rTot2 ); g.DrawString( "ºÏ¼Æ:" + tot.ToString(), normalFont, normalBrush, rTot1.X - 2, rTot1.Y - 11 );
g.DrawString( "ºÏ¼Æ:" + tot.ToString(), normalFont, normalBrush, rTot.X - 2, rTot.Y - 13);
g.FillRectangle( this.bWa, rWa );
if( wa > times ) g.DrawString( wa.ToString(), normalFont, normalBrush, rWa.X - 2, rWa.Y - 0 );
g.FillRectangle( this.bAl, rAl );
if( al > times ) g.DrawString( al.ToString(), normalFont, normalBrush, rAl.X - 2, rAl.Y - 0 );
g.FillRectangle( this.bLe, rLe );
if( le > times ) g.DrawString( le.ToString(), normalFont, normalBrush, rLe.X - 2, rLe.Y - 0 );
g.FillRectangle( this.bCh, rCh );
if( ch > times ) g.DrawString( ch.ToString(), normalFont, normalBrush, rCh.X - 2, rCh.Y - 0 );
}
else
{
int span = (int)Math.Ceiling( ( baseSpan - baseInterval ) / 4 );
Rectangle rWa = new Rectangle( xy.X + begX + baseSpan * ( i - 0 ) , (int)(xy.Y - wa * unitY), span, (int)(wa * unitY) + 1 );
Rectangle rAl = new Rectangle( xy.X + begX + baseSpan * ( i - 0 ) + span, (int)(xy.Y - al * unitY), span, (int)(al * unitY) + 1 );
Rectangle rLe = new Rectangle( xy.X + begX + baseSpan * ( i - 0 ) + span * 2, (int)(xy.Y - le * unitY), span, (int)(le * unitY) + 1 );
Rectangle rCh = new Rectangle( xy.X + begX + baseSpan * ( i - 0 ) + span * 3, (int)(xy.Y - ch * unitY), span, (int)(ch * unitY) + 1 );
Rectangle rTot1 = new Rectangle( xy.X + begX + baseSpan * ( i - 0 ), (int)(xy.Y - tot * unitY), span * 2 + 4, (int)(v.Tot * unitY) + 1 );
Rectangle rTot2 = new Rectangle( xy.X + begX + baseSpan * ( i - 0 ) + span * 2 + 4, (int)(xy.Y - tot * unitY), span * 2 - 4, (int)(v.Tot * unitY) + 1 );
Brush bTot1 = new LinearGradientBrush( rTot1, ct1, ct2, LinearGradientMode.Horizontal );
Brush bTot2 = new LinearGradientBrush( rTot2, ct2, ct3, LinearGradientMode.Horizontal );
g.FillRectangle( bTot1, rTot1 );
g.FillRectangle( bTot2, rTot2 ); g.DrawString( "ºÏ¼Æ:" + tot.ToString(), normalFont, normalBrush, rTot1.X - 2, rTot1.Y - 11 );
g.FillRectangle( this.bWa, rWa ); if( wa > times ) g.DrawString( wa.ToString(), normalFont, normalBrush, rWa.X - 2, rWa.Y - 0 );
g.FillRectangle( this.bAl, rAl ); if( al > times ) g.DrawString( al.ToString(), normalFont, normalBrush, rAl.X - 2, rAl.Y - 0 );
g.FillRectangle( this.bLe, rLe ); if( le > times ) g.DrawString( le.ToString(), normalFont, normalBrush, rLe.X - 2, rLe.Y - 0 );
g.FillRectangle( this.bCh, rCh ); if( ch > times ) g.DrawString( ch.ToString(), normalFont, normalBrush, rCh.X - 2, rCh.Y - 0 );
}
}
}
/// <summary>
/// »æÖÆÌáʾ
/// </summary>
/// <param name="g">»æÃæͼ</param>
private void DrawHint( Graphics g )
{
Rectangle r1 = new Rectangle( xy.X + 10, mTop, 40, 15 ); Rectangle r1s = new Rectangle( xy.X + 52, mTop + 2, 60, 15 ); // waiting
Rectangle r2 = new Rectangle( xy.X + 10, mTop + 22, 40, 15 );Rectangle r2s = new Rectangle( xy.X + 52, mTop + 24, 60, 15 ); // already
Rectangle r3 = new Rectangle( xy.X + 114, mTop, 40, 15 ); Rectangle r3s = new Rectangle( xy.X + 156, mTop + 2, 60, 15 ); // leave
Rectangle r4 = new Rectangle( xy.X + 114, mTop + 22, 40, 15 );Rectangle r4s = new Rectangle( xy.X + 156, mTop + 24, 60, 15 ); // change
Rectangle r5 = new Rectangle( xy.X + 6, mTop - 4, 202, 44 );// retcangle
Rectangle r6 = new Rectangle( xy.X + 5, mTop - 3, 202, 42 ); // solid rectangle
g.FillRectangle( Brushes.WhiteSmoke, r6 );
g.FillRectangle( bWa, r1 ); g.DrawString( "ºòÕﲡÈË", normalFont, normalBrush, r1s );
g.FillRectangle( bAl, r2 ); g.DrawString( "ÔÚÕﲡÈË", normalFont, normalBrush, r2s );
g.FillRectangle( bLe, r3 ); g.DrawString( "ÒÑÕﲡÈË", normalFont, normalBrush, r3s );
g.FillRectangle( bCh, r4 ); g.DrawString( "תÕﲡÈË", normalFont, normalBrush, r4s );
g.DrawRectangle( Pens.RoyalBlue, r5 );
}
/// <summary>
/// ±£´æλͼ
/// </summary>
void SaveImage()
{
if( myBitmap == null )
{
MessageBox.Show( "¶Ô²»Æð£¬äÖȾ³ö´í¡£ ÇëˢкóÔÙÊÔ£¡", "Ìáʾ", MessageBoxButtons.OK, MessageBoxIcon.Error );
return;
}
SaveFileDialog sfd = new SaveFileDialog();
sfd.Filter = "λͼ|*.bmp";
sfd.Title = caption;
if( sfd.ShowDialog() == DialogResult.OK )
{
string fileName = sfd.FileName;
try
{
myBitmap.Save( fileName );
MessageBox.Show( "±£´æ³É¹¦¡£ /n´æ·Å·¾¶£º" + fileName, "Ìáʾ", MessageBoxButtons.OK, MessageBoxIcon.Information );
}
catch
{
MessageBox.Show( "¶Ô²»Æð£¬äÖȾ³ö´í¡£ ÇëˢкóÔÙÊÔ£¡", "Ìáʾ", MessageBoxButtons.OK, MessageBoxIcon.Error );
}
finally
{
sfd.Dispose();
myBitmap.Dispose();
myBitmap = null;
}
}
}
/// <summary>
/// ÉèÖò˵¥×´Ì¬
/// </summary>
/// <param name="mi">µ±Ê²˵¥</param>
void SetColorMenu( MenuItem mi )
{
foreach( MenuItem m in menuItem7.MenuItems )
{
m.Checked = false;
}
mi.Checked = true;
}
#endregion
#region Events
private void FrmChart_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
InitializeMyValue();
InitializeTitle();
xy = new Point( mLeft, this.Height - mBottom );
hy = xy.Y - mTop;
hx = Width - xy.X - mRight;
Graphics g = e.Graphics;
Bitmap b = new Bitmap( this.Width, this.Height );
Graphics gb = Graphics.FromImage( b );
g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
gb.TextRenderingHint = trh;
DrawRectangle( gb, b.Width - 10, b.Height - 10 ); // »ÍâΧ¾ØÐÎ
DrawHint( gb );
DrawCaption( gb ); // »±êÌ⣨¾ø¶Ô¾ÓÖУ©
DrawFramework( gb, xy.X, xy.Y ); //£¨»¿ò¼Ü£©
DrawStub( gb );
DrawData( gb );
myBitmap = b;
g.DrawImage( b, 0, 0 );
GC.Collect();
}
private void FrmChart_Resize(object sender, System.EventArgs e)
{
Refresh();
}
private void menuItem3_Click(object sender, System.EventArgs e)
{
MenuItem mi = sender as MenuItem;
string name = mi.Text;
switch( name )
{
case "µÍ" : trh = System.Drawing.Text.TextRenderingHint.SingleBitPerPixelGridFit;
mi.Checked = true;
menuItem4.Checked = false;
menuItem5.Checked = false;
Refresh();
break;
case "ÖÐ" : trh = System.Drawing.Text.TextRenderingHint.AntiAlias;
mi.Checked = true;
menuItem3.Checked = false;
menuItem5.Checked = false;
Refresh();
break;
case "¸ß£¨Ä¬ÈÏ£©" : trh = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;
mi.Checked = true;
menuItem4.Checked = false;
menuItem3.Checked = false;
Refresh();
break;
case "Áí´æΪ¡" : Refresh(); SaveImage(); break;
}
}
private void menuItem8_Click(object sender, System.EventArgs e)
{
MenuItem mi = sender as MenuItem;
string name = mi.Text;
switch( name )
{
case "ÑÌ°×" : SetColorMenu( mi ); bgc = Color.WhiteSmoke; break;
case "»Ê¼ÒÀ¶" : SetColorMenu( mi ); bgc = Color.LightSteelBlue; break;
case "怅" : SetColorMenu( mi ); bgc = Color.LightCyan; break;
case "dzÂÌ" : SetColorMenu( mi ); bgc = Color.LightGreen; break;
case "Âó»Æ" : SetColorMenu( mi ); bgc = Color.LightGoldenrodYellow; break;
case "´¿°×£¨Ä¬ÈÏ£©" : SetColorMenu( mi ); bgc = Color.White; break;
}
Refresh();
}
private void menuItem14_Click(object sender, System.EventArgs e)
{
ColorDialog cd = new ColorDialog();
if( cd.ShowDialog() == DialogResult.OK )
{
bgc = cd.Color;
SetColorMenu( menuItem14 );
Refresh();
}
}
#endregion
/******************************************************************************************************************
*
* ÓÃÓÚ¹¹½¨Í¼±íµÄµ¥ÌåÖµÀà
*
* ****************************************************************************************************************/
/// <summary>
/// ÓÃÓÚ¹¹½¨Í¼±íµÄµ¥ÌåÖµÀà
/// </summary>
public class Value
{
#region ¹¹ÔìÆ÷
/// <summary>
/// ʵÀý»¯Í¼±íÖµÀà¶ÔÏó
/// </summary>
/// <param name="name">Ò½ÉúÃû×Ö</param>
/// <param name="dept">¿ÆÊÒÃû×Ö</param>
/// <param name="wa">ºòÕïÈËÊý</param>
/// <param name="al">ÔÚÕïÈËÊý</param>
/// <param name="le">ÒÑÕïÈËÊý</param>
/// <param name="ch">תÕïÈËÊý</param>
/// <param name="tot">×ÜÈËÊý</param>
public Value( string name, string dept, int wa, int al, int le, int ch, int tot )
{
this.name = name == null ? string.Empty : name;
this.dept = dept == null ? string.Empty : dept;
this.wa = wa;
this.al = al;
this.le = le;
this.ch = ch;
this.tot = tot;
}
#endregion
#region ×Ö¶Î
string name = string.Empty;
string dept = string.Empty;
int wa = 0;
int al = 0;
int le = 0;
int ch = 0;
int tot = 0;
#endregion
#region ÊôÐÔ
/// <summary>
/// ÐÕÃû£¨Èç¹ûÓУ©
/// </summary>
public string Name
{
set{ this.name = value;}
get{ return this.name;}
}
/// <summary>
/// ¿ÆÊÒ£¨Èç¹ûÓУ©
/// </summary>
public string Dept
{
set{ this.dept = value;}
get{ return this.dept;}
}
/// <summary>
/// ºòÕïÈËÊý£¨Èç¹ûÓУ©
/// </summary>
public int Wa
{
set{ this.wa = value;}
get{ return this.wa;}
}
/// <summary>
/// ÔÚÕïÈËÊý£¨Èç¹ûÓУ©
/// </summary>
public int Al
{
set{ this.al = value;}
get{ return this.al;}
}
/// <summary>
/// ÒÑÕïÈËÊý£¨Èç¹ûÓУ©
/// </summary>
public int Le
{
set{ this.le = value;}
get{ return this.le;}
}
/// <summary>
/// תÕïÈËÊý£¨Èç¹ûÓУ©
/// </summary>
public int Ch
{
set{ this.ch = value;}
get{ return this.ch;}
}
/// <summary>
/// ×ÜÈËÊý£¨Èç¹ûÓУ©
/// </summary>
public int Tot
{
set{ this.tot = value;}
get{ return this.tot;}
}
#endregion
}
}
}