學(xué)生管理系統(tǒng)所需要的具體控件和主要屬性:
1、登錄窗體
基本控件:
label(標(biāo)簽控件)
主要屬性:Image(在標(biāo)簽上顯示的圖像)
Text(在標(biāo)簽上顯示的文本)
TextBox(文本框控件)
主要屬性:PasswordChar(指示在作為密碼框時(shí),文本框中顯示的字符,而不是實(shí)際輸入的文本)
Button(按鈕控件)
ComboBox(下拉框)屬性:SelectedItem:獲取當(dāng)前選定的項(xiàng)
事件:Click(單擊控件時(shí)發(fā)生)
private void butStyle_Click(object sender, EventArgs e)
{
string str = "Data source=.;Initial catalog=Myschool;uid=sa";
SqlConnection con = new SqlConnection(str);
string sql = "select count(1) from student where studentName='" + txtUserName.Text + "' and LoginPwd='" + txtPwd.Text + "'";
SqlCommand cmd = new SqlCommand(sql, con);
try
{
con.Open();
int count = Convert.ToInt32(cmd.ExecuteScalar());
if (count > 0)
{
MessageBox.Show("登陸成功");
this.Hide();
FormMain frm = new FormMain();
frm.Show();
}
}
catch (Exception)
{
MessageBox.Show("退出");
}
finally
{
con.Close();
}
Sender是事件源,表示發(fā)生了這個(gè)事件的對(duì)象,事件發(fā)生中,事件源就是按鈕。
e是事件參數(shù)(EventArgs)對(duì)象,不同的事件會(huì)有不同的參數(shù)。
Close()方法是窗體類Form的一個(gè)方法,作用是關(guān)閉窗體。
2.Myschool管理員
01.給菜單欄中的“新增學(xué)生”菜單項(xiàng)添加事件處理程序,代碼如下
private void 新增學(xué)生ToolStripMenuItem_Click(object sender, EventArgs e)
{
FormStudent formStudent = new FormStudent();
formStudent.Show();
}
02.添加學(xué)生信息
public void Save()
{
//添加學(xué)生
string pwd = txtpwd.Text;
string stuname = textname.Text;
//性別
string stugender = string.Empty;
if (radioman.Checked)
{
stugender = "1";
}
else
{
stugender = "0";
}
//下拉框綁定數(shù)據(jù)
int gid = GeadIdName();
//聯(lián)系電話
string StuPhone = textphone.Text;
//地址
string StuAddress = textAddress.Text;
//日期
DateTime dt = dateBirthday.Value;
//郵箱
string StuEmail = textEmail.Text;
//LoginPwd, StudentName, Gender, GradeId, Phone, Address, Birthday, Email
string sql = "insert into Student values('" + pwd + "','" + stuname + "','" + stugender + "'," + gid + ",'" + StuPhone + "','" + StuAddress + "','" + dt + "','" + StuEmail + "')";
string str = "Data source=.;Initial catalog=Myschool;uid=sa;";
SqlConnection con = new SqlConnection(str);
SqlCommand cmd = new SqlCommand(sql, con);
con.Open();
int count = cmd.ExecuteNonQuery();
if (count > 0)
{
MessageBox.Show("添加成功");
}
con.Close();
}
3.查詢學(xué)生信息
//查詢學(xué)生信息
public void LodaDataListView(string sql)
{
string str = "data source=.;initial catalog=Myschool;uid=sa;";
SqlConnection con = new SqlConnection(str);
SqlCommand cmd = new SqlCommand(sql, con);
try
{
con.Open();
SqlDataReader dr = cmd.ExecuteReader();
if (dr != null)
{
if (dr.HasRows)
{
while (dr.Read())
{
int stuNo = Convert.ToInt32(dr["studentNo"]);
//姓名
string stuname = Convert.ToString(dr["studentName"]);
//性別
string stuGender = Convert.ToString(dr["Gender"]);
//年級(jí)名次
string stuGname = Convert.ToString(dr["Gradename"]);
ListViewItem LvItem = new ListViewItem(stuNo.ToString());
LvItem.SubItems.Add(stuname);
LvItem.SubItems.Add(stuGender);
LvItem.SubItems.Add(stuGname);
//讓lvItem和ListView關(guān)聯(lián)
lvlist.Items.Add(LvItem);
}
dr.Close();
}
}
}
catch (Exception)
{
throw;
}
finally
{
con.Close();
}
//窗體Load的事件中調(diào)用
private void Formselect_Load(object sender, EventArgs e)
{
string sql = "select StudentNO,StudentName,Gender,GradeName from Student,Grade where Student.GradeId=Grade.GradeId";
LodaDataListView(sql);
}
修改學(xué)生信息
public void upatae()
{
//添加學(xué)生
string pwd = txtpwd.Text;
string stuname = textname.Text;
//性別
string stugender = string.Empty;
if (radioman.Checked)
{
stugender = "1";
}
else
{
stugender = "0";
}
//下拉框綁定數(shù)據(jù)
int gid = GeadIdName();
//聯(lián)系電話
string StuPhone = textphone.Text;
//地址
string StuAddress = textAddress.Text;
//日期
DateTime dt = dateBirthday.Value;
//郵箱
string StuEmail = textEmail.Text;
//LoginPwd, StudentName, Gender, GradeId, Phone, Address, Birthday, Email
string sql = @"update Student set StudentName='" + stuname + "',Gender=" + stugender + ",GradeId='" + gid + "',phone='" + StuPhone + "',Address='" + StuAddress + "',Birthday='" + dt + "',Email='" + StuEmail
+ "' where studentNo='" + textNo.Text + "'";
string str = "Data source=.;Initial catalog=Myschool;uid=sa;";
SqlConnection con = new SqlConnection(str);
SqlCommand cmd = new SqlCommand(sql, con);
con.Open();
int count = cmd.ExecuteNonQuery();
if (count > 0)
{
frmselect.selectData();
MessageBox.Show("修改成功");
}
con.Close();
}
更多學(xué)習(xí)資料請(qǐng)關(guān)注專題《管理系統(tǒng)開發(fā)》。
以上就是關(guān)于學(xué)生管理系統(tǒng)的實(shí)現(xiàn)的關(guān)鍵代碼,希望對(duì)大家的學(xué)習(xí)有所幫助,大家可以動(dòng)手制作學(xué)生管理系統(tǒng),對(duì)學(xué)生管理系統(tǒng)功能進(jìn)行擴(kuò)充。
您可能感興趣的文章:- ASP.NET MVC5+EF6+EasyUI 后臺(tái)管理系統(tǒng)(81)-數(shù)據(jù)篩選(萬能查詢)實(shí)例
- Elasticsearch.Net使用教程 MVC4圖書管理系統(tǒng)(2)
- ASP.NET MVC5+EF6+EasyUI后臺(tái)管理系統(tǒng) 微信公眾平臺(tái)開發(fā)之資源環(huán)境準(zhǔn)備
- ASP.NET MVC5+EF6+EasyUI后臺(tái)管理系統(tǒng) 微信公眾平臺(tái)開發(fā)之消息管理
- ASP.NET MVC4+EF5+EasyUI+Unity2.x注入的后臺(tái)管理系統(tǒng)之前端頁(yè)面框架構(gòu)建源碼分享
- ASP.NET餐飲管理系統(tǒng)制作代碼分享
- ASP.NET網(wǎng)站管理系統(tǒng)退出 清除瀏覽器緩存,Session的代碼
- Asp.Net權(quán)限管理系統(tǒng) 專用代碼生成工具(DDBuildTools) 1.1.0 下載
- .NET實(shí)現(xiàn)工資管理系統(tǒng)