private void News_Load(object sender, EventArgs e)
{
this.Size = new Size (712,359);
//加载数据源
string str = string.Format(@"select * from News");
DataTable dt = DBHelperL.ExcuteQuery(str);
this.dataGridView1.DataSource=dt;
}
private void timer1_Tick(object sender, EventArgs e)
{
//显示时间
this.lab_time.Text = DateTime.Now.ToString();
}
private void button5_Click(object sender, EventArgs e)
{
//删除的代码
string id= this.textBox1_id.Text .Trim ();
string str = string.Format(@"delete from News where id='{0}'",id );
object o = DBHelperL.ExcuteBYSQL(str );
int returnno = Convert.ToInt32(o.ToString ());
if (returnno == 1)
{
MessageBox.Show(" Data Is Delete Succeed !!!");
}
else
{
MessageBox.Show("Sorry You Not Succeed !!!");
}
}
private void label4_Click(object sender, EventArgs e)
{
//查询的代码
string name = this.tb_set.Text.Trim();
if (name !="")
{
string str = string.Format(@"select * from News where name='{0}'",name );
DataTable dt = DBHelperL.ExcuteQuery(str);
this.dataGridView1.DataSource = dt;
}
else
{
string str = string.Format(@"select * from News");
DataTable dt = DBHelperL.ExcuteQuery(str);
this.dataGridView1.DataSource = dt;
}
}
private void button2_Click(object sender, EventArgs e)
{
//界面的大小
this.Size = new Size(712,446);
}
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
//显示选中的数据
this.textBox1_id.Text = this.dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString();
this.textBox2_name .Text =this .dataGridView1 .Rows [e.RowIndex ].Cells [1].Value .ToString ();
this.textBox3_sex.Text = this.dataGridView1.Rows[e.RowIndex].Cells[2].Value.ToString();
this.textBox4_age.Text = this.dataGridView1.Rows[e.RowIndex].Cells[3].Value.ToString();
this.textBox5_birth.Text = this.dataGridView1.Rows[e.RowIndex].Cells[4].Value.ToString();
this.textBox6_phone.Text = this.dataGridView1.Rows[e.RowIndex].Cells[5].Value.ToString();
}
private void News_FormClosing(object sender, FormClosingEventArgs e)
{
//退出的代码
System.Environment.Exit(1);
}
private void button6_Click(object sender, EventArgs e)
{
//修改的代码
string id = this.textBox1_id.Text.Trim();
string name = this.textBox2_name.Text.Trim();
string sex = this.textBox3_sex.Text.Trim();
string age = this.textBox4_age.Text.Trim();
string birth = this.textBox5_birth.Text.Trim();
string phone = this.textBox6_phone.Text.Trim();
string str = string.Format(@"UPDATE [News] SET [Name] = '{0}' ,[Sex] = '{1}',[Age] = '{2}',[Birth] = '{3}',[Phone] = '{4}'WHERE id='{5}'",name ,sex ,age ,birth ,phone ,id );
Object o = DBHelperL.ExcuteBYSQL(str);
int returnno = Convert.ToInt32(o.ToString ());
if(returnno ==1)
{
MessageBox.Show(" Data Is Update Succeed !!!");
}
else
{
MessageBox.Show("Sorry You Not Succeed !!!");
}
}
}
}