Professional Documents
Culture Documents
Using Using Using Using Using Using Using Using Using Using Namespace Public Partial Class
Using Using Using Using Using Using Using Using Using Using Namespace Public Partial Class
Using Using Using Using Using Using Using Using Using Using Namespace Public Partial Class
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using MySql.Data.MySqlClient;
namespace DBCon4
{
public partial class Form1 : Form
{
//for connection
MySqlConnection CN = new MySqlConnection("server=localhost;uid=root;
password=''; database=dbCon4");
MySqlCommand Com = new MySqlCommand();
MySqlDataReader reader;
int numberofitemsperpage = 0;
int itemsshowed = 0,i=0;
public Form1()
{
InitializeComponent();
Com.Connection = CN;
}
loadgrid();
txtName.Clear();
txtAge.Clear();
dt1.Text = "";
}
void loadgrid()
{
dataGridView1.Rows.Clear();
dataGridView1.ColumnCount = 4;
dataGridView1.Columns[0].Name = "ID";
dataGridView1.Columns[1].Name = "Student Name";
dataGridView1.Columns[2].Name = "Date of Birth";
dataGridView1.Columns[3].Name = "Age";
CN.Open();
Com.CommandText = "select * from student order by sname";
reader = Com.ExecuteReader();
while (reader.Read())
{
dataGridView1.Rows.Add(reader["sid"].ToString(),
reader["sname"].ToString(), reader["dob"].ToString(),
reader["age"].ToString());
}
reader.Close();
CN.Close();
}
void loadgrid2()
{
dataGridView1.Rows.Clear();
dataGridView1.ColumnCount = 4;
dataGridView1.Columns[0].Name = "ID";
dataGridView1.Columns[1].Name = "Student Name";
dataGridView1.Columns[2].Name = "Date of Birth";
dataGridView1.Columns[3].Name = "Age";
CN.Open();
Com.CommandText = "select * from student where dob between '" +
dtStart.Value.ToString("yyyy-MM-dd") + "' AND '" + dtEnd.Value.ToString("yyyy-
MM-dd") + "' order by sname";
reader = Com.ExecuteReader();
while (reader.Read())
{
dataGridView1.Rows.Add(reader["sid"].ToString(),
reader["sname"].ToString(), reader["dob"].ToString(),
reader["age"].ToString());
}
reader.Close();
CN.Close();
}
//dataGridView1_CellMouseClick
txtID.Text = dataGridView1.CurrentRow.Cells[0].Value.ToString();
txtName.Text = dataGridView1.CurrentRow.Cells[1].Value.ToString();
dt1.Text = dataGridView1.CurrentRow.Cells[2].Value.ToString();
txtAge.Text = dataGridView1.CurrentRow.Cells[3].Value.ToString();
}
e.Graphics.DrawImage(Properties.Resources._398_3984434_c_language_circle, 800,
100, 200, 100);
int x = 30, y = 170;
// e.Graphics.DrawString("Sample Printing", new Font("Arial", 11,
FontStyle.Bold), Brushes.Black, new Point(30, 50));
//CN.Open();
//Com.CommandText = "select * from sampTbl";
//reader = Com.ExecuteReader();
e.Graphics.DrawString("ID", new Font("Arial", 11, FontStyle.Bold),
Brushes.Black, new Point(30, 150));
e.Graphics.DrawString("STUDENT NAME", new Font("Arial", 11,
FontStyle.Bold), Brushes.Black, new Point(230, 150));
e.Graphics.DrawString("DATE of BIRTH", new Font("Arial", 11,
FontStyle.Bold), Brushes.Black, new Point(430, 150));
e.Graphics.DrawString("AGE", new Font("Arial", 11, FontStyle.Bold),
Brushes.Black, new Point(630, 150));
//while (reader.Read())
//{
if (numberofitemsperpage <= 3)
{
itemsshowed++;
e.Graphics.DrawString(dataGridView1.Rows[i].Cells[1].Value.ToString(), new
Font("Arial", 11, FontStyle.Bold), Brushes.Black, new Point(x + 200, y));
e.Graphics.DrawString(dataGridView1.Rows[i].Cells[2].Value.ToString(), new
Font("Arial", 11, FontStyle.Bold), Brushes.Black, new Point(x + 400, y));
e.Graphics.DrawString(dataGridView1.Rows[i].Cells[3].Value.ToString(), new
Font("Arial", 11, FontStyle.Bold), Brushes.Black, new Point(x + 600, y));
y = y + 20;
}
else
{
e.HasMorePages = false;
}
}
else
{
numberofitemsperpage = 0;
e.HasMorePages = true;
return;
}
// reader.Close();
// CN.Close();
}
}
namespace DBCon4
{
public partial class FormGraph : Form
{
//for connection
MySqlConnection CN = new MySqlConnection("server=localhost;uid=root;
password=''; database=dbCon4");
MySqlCommand Com = new MySqlCommand();
MySqlDataReader reader;
public FormGraph()
{
InitializeComponent();
Com.Connection = CN; ;
}
ShowGraph();
}
void ShowGraph() {
//chart1.Series["Age"].Points.AddXY("Aaron", 20);
//chart1.Series["Age"].Points.AddXY("Kim", 10);
//chart1.Series["Age"].Points.AddXY("Cora", 50);
//chart1.Series["Age"].Points.AddXY("Benjie", 60);
//chart1.Series["Age"].Points.AddXY("Shane", 30);
CN.Open();
Com.CommandText = "select * from student where dob between '" +
dtStart.Value.ToString("yyyy-MM-dd") + "' AND '" + dtEnd.Value.ToString("yyyy-
MM-dd") + "' order by sname";
reader = Com.ExecuteReader();
while (reader.Read())
{
chart1.Series["Age"].Points.AddXY(reader["sname"],
reader["age"]);
}
reader.Close();
CN.Close();