111,126
社区成员
发帖
与我相关
我的任务
分享
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form6 : Form
{
public Form6()
{
InitializeComponent();
Db db = new Db();
textBox1.Text = "1";
}
private void Form1_Load(object sender, EventArgs e)
{
//pictureBox1.Paint += new System.Windows.Forms.PaintEventHandler(this.pictureBox1_Paint);
}
private void pictureBox1_Paint(object sender, PaintEventArgs e)
{
Db db = new Db();
Graphics g = e.Graphics;
Pen pen = new Pen(Color.Black, 2);
SolidBrush sb = new SolidBrush(Color.Green);
Point[] xpts = new Point[3]{
new Point(pictureBox1.Width-35,pictureBox1.Height-32),
new Point(pictureBox1.Width-35,pictureBox1.Height-28),
new Point(pictureBox1.Width-30,pictureBox1.Height-30)
};
g.DrawLine(pen, 50, pictureBox1.Height - 30, pictureBox1.Width - 30, pictureBox1.Height - 30);
g.DrawPolygon(pen, xpts);
g.DrawString("时间", new Font("宋体", 9), sb, pictureBox1.Width - 30, pictureBox1.Height - 30);
Point[] ypts = new Point[3]{
new Point(48,55),
new Point(50,50),
new Point(52,55)
};
g.DrawLine(pen, 50, pictureBox1.Height - 30, 50, 50);
g.DrawPolygon(pen, ypts);
g.DrawString("/mmHg", new Font("宋体", 9), sb, 50, 50);
g.DrawString("50", new Font("宋体", 9), sb, 30, pictureBox1.Height - 35);
for (int j = 0; j < 9; j++)
{
g.DrawLine(pen, 50, pictureBox1.Height - 30 - (j + 1) * (pictureBox1.Height - 80) / 10, 55, pictureBox1.Height - 30 - (j + 1) * (pictureBox1.Height - 80) / 10);
g.DrawString(((j + 1) * 13 + 50).ToString(), new Font("宋体", 9), sb, 30, pictureBox1.Height - 35 - (j + 1) * (pictureBox1.Height - 80) / 10);
}
string sql = "select sbp,dbp,time from bp where pnum='" + textBox1.Text + "'";
string[,] a = db.doSelect(sql);
int n = 0;
n = a.GetLength(0);
//取出的数据的行数为n;
int i = 0;
for (i = 0; i < n - 1; i++)
{
g.DrawLine(new Pen(Color.Blue), 50 + (i + 1) * (pictureBox1.Width - 80) / (n + 1), pictureBox1.Height - 30 - (int.Parse(a[i, 0]) - 50) * (pictureBox1.Height - 80) / 130, 50 + (i + 2) * (pictureBox1.Width - 80) / (n + 1), pictureBox1.Height - 30 - (int.Parse(a[i + 1, 0]) - 50) * (pictureBox1.Height - 80) / 130);
g.DrawLine(new Pen(Color.Red), 50 + (i + 1) * (pictureBox1.Width - 80) / (n + 1), pictureBox1.Height - 30 - (int.Parse(a[i, 1]) - 50) * (pictureBox1.Height - 80) / 130, 50 + (i + 2) * (pictureBox1.Width - 80) / (n + 1), pictureBox1.Height - 30 - (int.Parse(a[i + 1, 1]) - 50) * (pictureBox1.Height - 80) / 130);
g.DrawLine(new Pen(Color.Black), 50 + (i + 1) * (pictureBox1.Width - 80) / (n + 1), pictureBox1.Height - 35, 50 + (i + 1) * (pictureBox1.Width - 80) / (n + 1), pictureBox1.Height - 30);
g.DrawString(a[i, 2], new Font("宋体", 9), sb, 20 + (i + 1) * (pictureBox1.Width - 80) / (n + 1), pictureBox1.Height - 28);
}
g.DrawLine(new Pen(Color.Blue), 50 + (i + 1) * (pictureBox1.Width - 80) / (n + 1), pictureBox1.Height - 35, 50 + (i + 1) * (pictureBox1.Width - 80) / (n + 1), pictureBox1.Height - 30);
g.DrawString(a[i, 2], new Font("宋体", 9), sb, 20 + (i + 1) * (pictureBox1.Width - 80) / (n + 1), pictureBox1.Height - 28);
}
}
}
public string[,] doSelect(string sql) {
SqlConnection conn = new SqlConnection();//建立连接
conn.ConnectionString = cnString;
//设置数据库连接的参数,包括登录的服务器名,和数据库文件所在的位置
conn.Open();//打开数据库
SqlCommand cmd = new SqlCommand();//新建一个数据库命令参数
cmd.Connection = conn;//这个参数将作用于conn所连接的数据库
cmd.CommandType = CommandType.Text;
cmd.CommandText = sql;//执行数据库命令,得到数据
DataSet shuju = new DataSet();//新建一个数据库
SqlDataAdapter adt = new SqlDataAdapter();
adt.SelectCommand = cmd;//
adt.Fill(shuju, "shuju");//将取出来到的数据放到userinfo表中
conn.Close();
if (shuju.Tables["shuju"].Rows.Count > 0)
{
string[,] x = new string[shuju.Tables["shuju"].Rows.Count, shuju.Tables["shuju"].Columns.Count];
for (int i = 0; i < shuju.Tables["shuju"].Rows.Count; i++)
{
for (int j = 0; j < shuju.Tables["shuju"].Columns.Count; j++)
{
x[i, j] = shuju.Tables["shuju"].Rows[i][j].ToString();
}
}
return x;
}
else
{
string[,] x = new string[1, 1];
x[0, 0] = "";
return x;
}
}