showImage .cs
资源名称:MEIMS.rar [点击查看]
上传用户:ah_jiwei
上传日期:2022-07-24
资源大小:54044k
文件大小:4k
源码类别:
数据库编程
开发平台:
Visual C++
- using System;
- using System.Web;
- using System.Web.UI;
- using System.Drawing;
- using System.Collections;
- using System.Drawing.Imaging;
- using System.Drawing.Drawing2D;
- using System.Data;
- using System.Data.SqlClient;
- using System.Web.Configuration;
- public class showImage
- {
- struct department
- {
- public string name;
- public int number;
- }
- public void ProcessRequest ()
- {
- ArrayList departments = new ArrayList();
- department dp;
- SolidBrush sb = new SolidBrush(Color.Aqua);
- Random rd = new Random();
- SqlConnection connection = DB.connect_la();
- int sum = 0;
- int success = 0;
- int startAngle = 0;
- int sweepAngle = 45;
- //connect the database
- try
- {
- connection.Open();
- SqlCommand comm1 = new SqlCommand("select count(sut_id) from stu_tea where state = '已选择'", connection);
- SqlDataReader dr1 = comm1.ExecuteReader();
- if (dr1.Read())
- {
- dp.name = "已确定导师";
- dp.number = Convert.ToInt32(dr1.GetInt32(0));
- success = dr1.GetInt32(0);
- departments.Add(dp);
- }
- dr1.Close();
- SqlCommand comm2 = new SqlCommand("select count(stu_id) from stu_id_num", connection);
- SqlDataReader dr2 = comm2.ExecuteReader();
- if (dr2.Read())
- {
- dp.name = "未确定导师";
- sum = dr2.GetInt32(0);
- dp.number = sum-success;
- departments.Add(dp);
- }
- dr2.Close();
- }
- catch (Exception ex)
- {
- throw new Exception(ex.Message);
- }
- finally
- {
- connection.Close();
- }
- //Draw the pie of the every department
- if (departments.Count > 0)
- {
- using (Bitmap bm = new Bitmap(200,260))
- {
- using (Graphics gp = Graphics.FromImage(bm))
- {
- gp.SmoothingMode = SmoothingMode.AntiAlias;
- gp.Clear(Color.White);
- //Rectangle rect = new Rectangle(0, 0, 200, 200);
- int pointX = 0;
- int pointY = 20;
- gp.DrawLine(Pens.Black, 10, 204, 190, 204);
- bool single = true;
- int y = 210;
- for (int i = 0; i < departments.Count; i++)
- {
- dp = (department)departments[i];
- sb.Color = Color.FromArgb(rd.Next(255), rd.Next(255), rd.Next(255));
- sweepAngle = Convert.ToInt32(360 * Convert.ToSingle(dp.number) / Convert.ToSingle(sum));
- //gp.FillPie(sb, rect, startAngle, sweepAngle);
- if (startAngle < 180)
- {
- for (int height = 0; height < 8; height++)
- {
- gp.FillPie(Brushes.Black, pointX, pointY + height, 200, 100, startAngle, sweepAngle);
- }
- }
- gp.FillPie(sb, pointX, pointY, 200, 100, startAngle, sweepAngle);
- startAngle += sweepAngle;
- if (single)
- {
- gp.FillRectangle(sb, new Rectangle(10, y, 20, 15));
- gp.DrawString(dp.name, new Font("Tahoma", 8, FontStyle.Regular), Brushes.Black, new PointF(30, y));
- single = false;
- }
- else
- {
- gp.FillRectangle(sb, new Rectangle(110, y, 20, 15));
- gp.DrawString(dp.name, new Font("Tahoma", 8, FontStyle.Regular), Brushes.Black, new PointF(130, y));
- single = true;
- y += 20;
- }
- }
- //save the image in the page
- gp.DrawLine(Pens.Black, 10, 258, 190, 258);
- string path = System.AppDomain.CurrentDomain.BaseDirectory+"\image\graph1.gif";
- bm.Save(path);
- }
- }
- }
- }
- }