我找的代码组合一起的,大家帮忙怎么把这数据组合,一个函数里的数据源在令个函数里怎么调起来,新手看,看书也不明白,还望大家指教下:
代码就是编译的时候怎么让上面那函数里的数据DS调用到下面的函数,里面有些句子是我自己 加的,我不知道对不,帮帮忙,谢谢:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;namespace MyFirstXy
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} private void Form1_Load(object sender, EventArgs e)
{
// Create connection string variable. Modify the "Data Source"
// parameter as appropriate for your environment.
String sConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" +
"Data Source=E:\\c#自编\\MyFirstXy\\data.xls ;" +
"Extended Properties=Excel 8.0;"; // Create connection object by using the preceding connection string.
OleDbConnection objConn = new OleDbConnection(sConnectionString); // Open connection with the database.
objConn.Open(); // The code to follow uses a SQL SELECT command to display the data from the worksheet. // Create new OleDbCommand to return data from worksheet.
OleDbCommand objCmdSelect = new OleDbCommand("SELECT * FROM myRange1", objConn); // Create new OleDbDataAdapter that is used to build a DataSet
// based on the preceding SQL SELECT statement.
OleDbDataAdapter objAdapter1 = new OleDbDataAdapter(); // Pass the Select command to the adapter.
objAdapter1.SelectCommand = objCmdSelect; // Create new DataSet to hold information from the worksheet.
DataSet ds = new DataSet(); // Fill the DataSet with the information from the worksheet.
objAdapter1.Fill(ds, "myRange1");//????????????????第二个参数何意?用什么都不影响程序!
dataGridView1.DataSource = ds.Tables[0].DefaultView;//?????????????????????
pictureBox1.Paint += new System.Windows.Forms.PaintEventHandler(this.pictureBox1_Paint); // Clean up objects.
objConn.Close();
} private void pictureBox1_Paint(object sender, EventArgs e)
{
//取得记录数量
int count = ds.Tables[0].Rows.Count;
//记算图表宽度
int wide = 80 + 20 * (count - 1);
//设置最小宽度为400
if (wide < 400) wide = 400;
//生成Bitmap对像
Bitmap img = new Bitmap(wide, 280);
//生成绘图对像
Graphics g = Graphics.FromImage(img);
Pen Bp = new Pen(Color.Black);
//定义红色画笔
Pen Rp = new Pen(Color.Red);
//定义银灰色画笔
Pen Sp = new Pen(Color.Silver);
//定义大标题字体
Font Bfont = new Font("Arial", 12, FontStyle.Bold);
//定义一般字体
Font font = new Font("Arial", 6);
//定义大点的字体
Font Tfont = new Font("Arial", 9);
//绘制底色
g.DrawRectangle(new Pen(Color.White, 400), 0, 0, img.Width, img.Height);
//定义黑色过渡型笔刷
LinearGradientBrush brush = new LinearGradientBrush(new Rectangle(0, 0, img.Width, img.Height), Color.Black, Color.Black, 1.2F, true);
//定义蓝色过渡型笔刷
LinearGradientBrush Bluebrush = new LinearGradientBrush(new Rectangle(0, 0, img.Width, img.Height), Color.Blue, Color.Blue, 1.2F, true);
//绘制图片边框
g.DrawRectangle(Bp, 0, 0, img.Width - 1, img.Height - 1);
//绘制竖坐标线
for (int i = 0; i < count; i++)
{
g.DrawLine(Sp, 40 + 20 * i, 60, 40 + 20 * i, 360);
}
//绘制横轴坐标标签
for (int i = 0; i < count; i += 2)
{
string st = Convert.ToDateTime(ds.Tables[0].Rows[i]["数据1"]).ToString();
g.DrawString(st, font, brush, 30 + 20 * i, 370);
}
//绘制横坐标线
for (int i = 0; i < 10; i++)
{
g.DrawLine(Sp, 40, 60 + 30 * i, 40 + 20 * (count - 1), 60 + 30 * i);
int s = 2500 - 50 * i * 5;
//绘制发送量轴坐标标签
g.DrawString(s.ToString(), font, brush, 10, 60 + 30 * i);
} //绘制竖坐标轴
g.DrawLine(Bp, 40, 55, 40, 360);
//绘制横坐标轴
g.DrawLine(Bp, 40, 360, 45 + 20 * (count - 1), 360); //定义曲线转折点
Point[] p = new Point[count];
for (int i = 0; i < count; i++)
{
p[i].X = 40 + 20 * i;
p[i].Y = 360 - Convert.ToInt32(ds.Tables[0].Rows[i]["数据2"]) / 5 * 3 / 5;
}
//绘制发送曲线
g.DrawLines(Rp, p); for (int i = 0; i < count; i++)
{
//绘制发送记录点的发送量
g.DrawString(ds.Tables[0].Rows[i]["sendnum"].ToString(), font, Bluebrush, p[i].X, p[i].Y - 10);
//绘制发送记录点
g.DrawRectangle(Rp, p[i].X - 1, p[i].Y - 1, 2, 2);
}
//绘制竖坐标标题
g.DrawString("数据2", Tfont, brush, 5, 40);
//绘制横坐标标题
g.DrawString("数据1", Tfont, brush, 40, 385);
}
}
}
代码就是编译的时候怎么让上面那函数里的数据DS调用到下面的函数,里面有些句子是我自己 加的,我不知道对不,帮帮忙,谢谢:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;namespace MyFirstXy
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} private void Form1_Load(object sender, EventArgs e)
{
// Create connection string variable. Modify the "Data Source"
// parameter as appropriate for your environment.
String sConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" +
"Data Source=E:\\c#自编\\MyFirstXy\\data.xls ;" +
"Extended Properties=Excel 8.0;"; // Create connection object by using the preceding connection string.
OleDbConnection objConn = new OleDbConnection(sConnectionString); // Open connection with the database.
objConn.Open(); // The code to follow uses a SQL SELECT command to display the data from the worksheet. // Create new OleDbCommand to return data from worksheet.
OleDbCommand objCmdSelect = new OleDbCommand("SELECT * FROM myRange1", objConn); // Create new OleDbDataAdapter that is used to build a DataSet
// based on the preceding SQL SELECT statement.
OleDbDataAdapter objAdapter1 = new OleDbDataAdapter(); // Pass the Select command to the adapter.
objAdapter1.SelectCommand = objCmdSelect; // Create new DataSet to hold information from the worksheet.
DataSet ds = new DataSet(); // Fill the DataSet with the information from the worksheet.
objAdapter1.Fill(ds, "myRange1");//????????????????第二个参数何意?用什么都不影响程序!
dataGridView1.DataSource = ds.Tables[0].DefaultView;//?????????????????????
pictureBox1.Paint += new System.Windows.Forms.PaintEventHandler(this.pictureBox1_Paint); // Clean up objects.
objConn.Close();
} private void pictureBox1_Paint(object sender, EventArgs e)
{
//取得记录数量
int count = ds.Tables[0].Rows.Count;
//记算图表宽度
int wide = 80 + 20 * (count - 1);
//设置最小宽度为400
if (wide < 400) wide = 400;
//生成Bitmap对像
Bitmap img = new Bitmap(wide, 280);
//生成绘图对像
Graphics g = Graphics.FromImage(img);
Pen Bp = new Pen(Color.Black);
//定义红色画笔
Pen Rp = new Pen(Color.Red);
//定义银灰色画笔
Pen Sp = new Pen(Color.Silver);
//定义大标题字体
Font Bfont = new Font("Arial", 12, FontStyle.Bold);
//定义一般字体
Font font = new Font("Arial", 6);
//定义大点的字体
Font Tfont = new Font("Arial", 9);
//绘制底色
g.DrawRectangle(new Pen(Color.White, 400), 0, 0, img.Width, img.Height);
//定义黑色过渡型笔刷
LinearGradientBrush brush = new LinearGradientBrush(new Rectangle(0, 0, img.Width, img.Height), Color.Black, Color.Black, 1.2F, true);
//定义蓝色过渡型笔刷
LinearGradientBrush Bluebrush = new LinearGradientBrush(new Rectangle(0, 0, img.Width, img.Height), Color.Blue, Color.Blue, 1.2F, true);
//绘制图片边框
g.DrawRectangle(Bp, 0, 0, img.Width - 1, img.Height - 1);
//绘制竖坐标线
for (int i = 0; i < count; i++)
{
g.DrawLine(Sp, 40 + 20 * i, 60, 40 + 20 * i, 360);
}
//绘制横轴坐标标签
for (int i = 0; i < count; i += 2)
{
string st = Convert.ToDateTime(ds.Tables[0].Rows[i]["数据1"]).ToString();
g.DrawString(st, font, brush, 30 + 20 * i, 370);
}
//绘制横坐标线
for (int i = 0; i < 10; i++)
{
g.DrawLine(Sp, 40, 60 + 30 * i, 40 + 20 * (count - 1), 60 + 30 * i);
int s = 2500 - 50 * i * 5;
//绘制发送量轴坐标标签
g.DrawString(s.ToString(), font, brush, 10, 60 + 30 * i);
} //绘制竖坐标轴
g.DrawLine(Bp, 40, 55, 40, 360);
//绘制横坐标轴
g.DrawLine(Bp, 40, 360, 45 + 20 * (count - 1), 360); //定义曲线转折点
Point[] p = new Point[count];
for (int i = 0; i < count; i++)
{
p[i].X = 40 + 20 * i;
p[i].Y = 360 - Convert.ToInt32(ds.Tables[0].Rows[i]["数据2"]) / 5 * 3 / 5;
}
//绘制发送曲线
g.DrawLines(Rp, p); for (int i = 0; i < count; i++)
{
//绘制发送记录点的发送量
g.DrawString(ds.Tables[0].Rows[i]["sendnum"].ToString(), font, Bluebrush, p[i].X, p[i].Y - 10);
//绘制发送记录点
g.DrawRectangle(Rp, p[i].X - 1, p[i].Y - 1, 2, 2);
}
//绘制竖坐标标题
g.DrawString("数据2", Tfont, brush, 5, 40);
//绘制横坐标标题
g.DrawString("数据1", Tfont, brush, 40, 385);
}
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货