?? browsestudent.cs
字號:
this.button3.Click += new System.EventHandler(this.button3_Click);
//
// BrowseStudent
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(709, 342);
this.Controls.Add(this.button3);
this.Controls.Add(this.button2);
this.Controls.Add(this.button1);
this.Controls.Add(this.label3);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Controls.Add(this.textBox1);
this.Controls.Add(this.dataGrid1);
this.Controls.Add(this.comboBox2);
this.Controls.Add(this.comboBox1);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
this.Name = "BrowseStudent";
this.Text = "學生信息瀏覽";
this.Load += new System.EventHandler(this.BrowseStudent_Load);
this.Closed += new System.EventHandler(this.xsll_Closed);
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
this.ResumeLayout(false);
}
#endregion
private void BrowseStudent_Load(object sender, System.EventArgs e)
{
oleDbConnection1.Open();
string sql="select specialtyid,specialtyname from specialtyinfo";
OleDbDataAdapter adp=new OleDbDataAdapter(sql,oleDbConnection1);
DataSet ds=new DataSet();
adp.Fill(ds,"specialty");
comboBox1.DataSource=ds.Tables["specialty"].DefaultView;
comboBox1.DisplayMember="specialtyname";
comboBox1.ValueMember="specialtyid";
textBox1.Text=System.DateTime.Now.Year.ToString().Trim();
}
private void textBox1_TextChanged(object sender, System.EventArgs e)
{
if (textBox1.Text.Trim()!="" && textBox1.Text.Trim().Length==4 && strisyear(textBox1.Text.Trim()))
{
string sql="select classid,classname from classinfo where specialtyname='"+comboBox1.Text.ToString()+"' and year(enrolmenttime)="+textBox1.Text.ToString();
OleDbDataAdapter adp=new OleDbDataAdapter(sql,oleDbConnection1);
DataSet ds=new DataSet();
ds.Clear();
adp.Fill(ds,"class");
comboBox2.DisplayMember="classname";
comboBox2.ValueMember="classid";
comboBox2.DataSource=ds.Tables[0].DefaultView;
// comboBox2.Items.Clear();
// OleDbDataReader dr;
// OleDbCommand cmd=new OleDbCommand(sql,oleDbConnection1);
//dr=cmd.ExecuteReader();
//while (dr.Read())
//{
// comboBox2.Items.Add(dr.GetString(1).ToString());
// }
}
else
comboBox2.DataSource=null;
}
DataSet ds;
private void comboBox2_SelectedIndexChanged(object sender, System.EventArgs e)
{
OleDbConnection cn=new OleDbConnection("Data Source=xsxxdb.mdb;Jet OLEDB:Engine Type=5;Provider=Microsoft.Jet.OLEDB.4.0");
cn.Open();
string sql="select StudentInfo.StudentId as 自動編號,studentinfo.studentnumber as 學號,studentinfo.name as 姓名,studentinfo.sex as 性別,studentinfo.race as 族別,studentinfo.address as 家庭住址,studentinfo.telephone as 聯系方式,studentinfo.role as 政治面貌,studentinfo.postalcode as 郵政編碼,classinfo.classname as 班級名稱,studentinfo.remark as 備注 from studentinfo inner join classinfo on studentinfo.classid = classinfo.classid where classinfo.classname='"+comboBox2.Text.ToString()+"' order by studentnumber";
OleDbDataAdapter adp=new OleDbDataAdapter(sql,oleDbConnection1);
ds=new DataSet();
ds.Clear();
adp.Fill(ds,"student");
if (ds.Tables["student"].Rows.Count!=0)
dataGrid1.DataSource=ds.Tables[0].DefaultView;
else
dataGrid1.DataSource=null;
dataGrid1.CaptionText="該班級目前有"+ds.Tables["student"].Rows.Count+"名學生";
cn.Close();
}
private void comboBox2_TextChanged(object sender, System.EventArgs e)
{
}
private void comboBox1_SelectedIndexChanged(object sender, System.EventArgs e)
{
textBox1.Clear();
comboBox2.DataSource=null;
}
private void xsll_Closed(object sender, System.EventArgs e)
{
oleDbConnection1.Close();
}
public bool strisyear(string s)
{
if (s.Trim().Length!=4)
return (false);
else
{
int n=1;
for (int i=0;i<=s.Length-1;i++)
{
if (!System.Char.IsNumber(s[i]))
{
n=-1;
break;
}
}
if (n==1)
return (true);
else
return (false);
}
}
private void textBox1_Leave(object sender, System.EventArgs e)
{
if (!strisyear(textBox1.Text.Trim()))
{
MessageBox.Show("請輸入合法的入學年份","錯誤提示");
textBox1.Text=System.DateTime.Now.Year.ToString().Trim();
comboBox2.DataSource=null;
}
}
ModifyStudent modifystudent;
private void button1_Click(object sender, System.EventArgs e)
{
if (dataGrid1.DataSource!=null && dataGrid1[dataGrid1.CurrentCell]!=null)
{
modifystudent=new ModifyStudent();
modifystudent.Tag=ds.Tables[0].Rows[dataGrid1.CurrentCell.RowNumber][0].ToString().Trim();
modifystudent.textBox1.Text=ds.Tables[0].Rows[dataGrid1.CurrentCell.RowNumber][1].ToString().Trim();
modifystudent.textBox2.Text=ds.Tables[0].Rows[dataGrid1.CurrentCell.RowNumber][2].ToString().Trim();
modifystudent.comboBox1.Text=ds.Tables[0].Rows[dataGrid1.CurrentCell.RowNumber][3].ToString().Trim();
modifystudent.textBox4.Text=ds.Tables[0].Rows[dataGrid1.CurrentCell.RowNumber][4].ToString().Trim();
modifystudent.textBox5.Text=ds.Tables[0].Rows[dataGrid1.CurrentCell.RowNumber][5].ToString().Trim();
modifystudent.textBox6.Text=ds.Tables[0].Rows[dataGrid1.CurrentCell.RowNumber][6].ToString().Trim();
modifystudent.comboBox2.Text=ds.Tables[0].Rows[dataGrid1.CurrentCell.RowNumber][7].ToString().Trim();
modifystudent.textBox8.Text=ds.Tables[0].Rows[dataGrid1.CurrentCell.RowNumber][8].ToString().Trim();
modifystudent.label13.Text=comboBox1.Text.Trim();
modifystudent.label14.Text=ds.Tables[0].Rows[dataGrid1.CurrentCell.RowNumber][9].ToString().Trim();
modifystudent.textBox10.Text=ds.Tables[0].Rows[dataGrid1.CurrentCell.RowNumber][10].ToString().Trim();
modifystudent.ShowDialog();
}
else
MessageBox.Show("沒有指定的學生信息","提示");
}
private void button3_Click(object sender, System.EventArgs e)
{
if (dataGrid1.CurrentRowIndex>=0 && dataGrid1.DataSource!=null && dataGrid1[dataGrid1.CurrentCell]!=null)
{
string sql="select * from scoreinfo where studentnumber='"+ds.Tables["student"].Rows[dataGrid1.CurrentCell.RowNumber][1].ToString().Trim()+"'";
OleDbCommand cmd=new OleDbCommand(sql,oleDbConnection1);
OleDbDataReader dr;
dr=cmd.ExecuteReader();
if (dr.Read())
{
MessageBox.Show("刪除學生'"+ds.Tables["student"].Rows[dataGrid1.CurrentCell.RowNumber][1].ToString().Trim()+"'失敗,請先刪除該學生的成績信息","提示");
dr.Close();
}
else
{
dr.Close();
sql="delete * from studentinfo where studentnumber='"+ds.Tables["student"].Rows[dataGrid1.CurrentCell.RowNumber][1].ToString().Trim()+"'";
cmd.CommandText=sql;
cmd.ExecuteNonQuery();
MessageBox.Show("刪除學生'"+ds.Tables["student"].Rows[dataGrid1.CurrentCell.RowNumber][2].ToString().Trim()+"'成功","提示");
}
}
else
MessageBox.Show("沒有指定的學生信息","提示");
}
private void button2_Click(object sender, System.EventArgs e)
{
this.Close();
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -