作品展示及說明:
1. 登錄頁面
2.點擊右上角退出效果
3.教務角色登錄后的主界面
4.查看所有課程
5. 修改密碼窗口
代碼展示:
一、教師模塊部分事件
/// <summary>
/// 點Ì?擊¡Â查¨¦看¡ä學¡ì生¦¨²成¨¦績¡§事º?件t
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void lblViewStudentAchievement_Click(object sender, EventArgs e)
{
SDKForm5 s = new SDKForm5();
s.Show();
}
/// <summary>
/// 點Ì?擊¡Â查¨¦看¡ä授º¨²課?班㨤級?事º?件t
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void lblCheckTaughtClasses_Click(object sender, EventArgs e)
{
//清?空?當Ì¡À前¡ãpan中D的Ì?所¨´有®D控?件t
this.panclss.Controls.Clear();
//創ä¡ä建¡§想?顯?示º?的Ì?窗ä¡ã體¬?對?象¨®
SDKForm4 showform = new SDKForm4();
//設¦¨¨置?當Ì¡À前¡ã窗ä¡ã體¬?對?象¨®不?是º?頂£¤級?窗ä¡ã體¬?
showform.TopLevel = false;
//設¦¨¨置?當Ì¡À前¡ã顯?示º?窗ä¡ã體¬?和¨ª父?窗ä¡ã體¬?一°?起e調Ì¡Â整?大䨮小?
showform.Dock = System.Windows.Forms.DockStyle.Fill;
//設¦¨¨置?當Ì¡À前¡ã顯?示º?窗ä¡ã體¬?的Ì?邊À?框¨°樣¨´式º?
showform.FormBorderStyle = FormBorderStyle.None;
//指?定¡§當Ì¡À前¡ã顯?示º?窗ä¡ã體¬?的Ì?父?窗ä¡ã體¬?是º?誰-
showform.Parent = this.panclss;
//將?當Ì¡À前¡ã窗ä¡ã體¬?加¨®載?到Ì?pan容¨Y器¡Â中D
panclss.Controls.Add(showform);
//顯?示º?當Ì¡À前¡ã窗ä¡ã體¬?中D內¨²容¨Y
showform.Show();
}
/// <summary>
/// 點Ì?擊¡Â修T改?密¨¹碼?事º?件t
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnUpdateTeacherPassword_Click(object sender, EventArgs e)
{
//清?空?當Ì¡À前¡ãpan中D的Ì?所¨´有®D控?件t
this.panel.Controls.Clear();
//創ä¡ä建¡§想?顯?示º?的Ì?窗ä¡ã體¬?對?象¨®
SDKForm2 showform = new SDKForm2();
//設¦¨¨置?當Ì¡À前¡ã窗ä¡ã體¬?對?象¨®不?是º?頂£¤級?窗ä¡ã體¬?
showform.TopLevel = false;
//設¦¨¨置?當Ì¡À前¡ã顯?示º?窗ä¡ã體¬?和¨ª父?窗ä¡ã體¬?一°?起e調Ì¡Â整?大䨮小?
showform.Dock = System.Windows.Forms.DockStyle.Fill;
//設¦¨¨置?當Ì¡À前¡ã顯?示º?窗ä¡ã體¬?的Ì?邊À?框¨°樣¨´式º?
showform.FormBorderStyle = FormBorderStyle.None;
//指?定¡§當Ì¡À前¡ã顯?示º?窗ä¡ã體¬?的Ì?父?窗ä¡ã體¬?是º?誰-
showform.Parent = this.panel;
//將?當Ì¡À前¡ã窗ä¡ã體¬?加¨®載?到Ì?pan容¨Y器¡Â中D
panel.Controls.Add(showform);
//顯?示º?當Ì¡À前¡ã窗ä¡ã體¬?中D內¨²容¨Y
showform.Show();
}
/// <summary>
/// 點Ì?擊¡Â查¨¦看¡ä個?人¨?信?息¡é事º?件t
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnUpdateTeacherInfo_Click(object sender, EventArgs e)
{
//清?空?當Ì¡À前¡ãpan中D的Ì?所¨´有®D控?件t
this.panel.Controls.Clear();
//創ä¡ä建¡§想?顯?示º?的Ì?窗ä¡ã體¬?對?象¨®
SDKForm3 showform = new SDKForm3();
//設¦¨¨置?當Ì¡À前¡ã窗ä¡ã體¬?對?象¨®不?是º?頂£¤級?窗ä¡ã體¬?
showform.TopLevel = false;
//設¦¨¨置?當Ì¡À前¡ã顯?示º?窗ä¡ã體¬?和¨ª父?窗ä¡ã體¬?一°?起e調Ì¡Â整?大䨮小?
showform.Dock = System.Windows.Forms.DockStyle.Fill;
//設¦¨¨置?當Ì¡À前¡ã顯?示º?窗ä¡ã體¬?的Ì?邊À?框¨°樣¨´式º?
showform.FormBorderStyle = FormBorderStyle.None;
//指?定¡§當Ì¡À前¡ã顯?示º?窗ä¡ã體¬?的Ì?父?窗ä¡ã體¬?是º?誰-
showform.Parent = this.panel;
//將?當Ì¡À前¡ã窗ä¡ã體¬?加¨®載?到Ì?pan容¨Y器¡Â中D
panel.Controls.Add(showform);
//顯?示º?當Ì¡À前¡ã窗ä¡ã體¬?中D內¨²容¨Y
showform.Show();
}
二、登錄頁面部分代碼
public MainForm()
{
InitializeComponent();
//使º1圓2角?缺¨¡À口¨²變À?透ª?明¡Â
this.TransparencyKey = this.BackColor;
//獲?取¨?當Ì¡À前¡ã時º¡À間?
this.lblTime.Text = System.DateTime.Now.ToString("yyyy-MM-dd");
}
/// <summary>
/// 點Ì?擊¡Â登Ì?陸?事º?件t
/// </summary>
public void UserLogin()
{
//將?登Ì?錄?帳¨º號?保À¡ê存ä?,ê?以°?便À?其?他?窗ä¡ã體¬?使º1用®?
ConText.Name = this.txtNum.Text.Trim().ToString();
string pwd = this.txtPwd.Text.ToString();
ConText.Sf1 = this.cmbType.Text.Trim().ToString();
string sql = null;
//判D斷?賬?號?密¨¹碼?是º?否¤?為a空?
if (ConText.Name == string.Empty || pwd.Trim() == string.Empty)
{
MessageBox.Show("賬?號?密¨¹碼?不?能¨¹為a空?!ê?!ê?!ê?");
}
else
{
//根¨´據Y登Ì?錄?不?同ª?角?色¦?拼¡ä接¨®不?同ª?的Ì?sql查¨¦詢¡¥語®?句?
if (ConText.Sf1.Equals("學¡ì生¦¨²"))
{
sql = string.Format("select COUNT(*) from Students where Name='{0}' and Studentspwd='{1}'", ConText.Name, pwd);
}
else if (ConText.Sf1.Equals("教¨¬師º|"))
{
sql = string.Format("select COUNT(*) from Teachers where TeacherName='{0}' and Teacherspwd='{1}' ", ConText.Name, pwd);
}
else if (ConText.Sf1.Equals("教¨¬務?員¡À"))
{
sql = string.Format("select COUNT(*) from Examination1 where Name='{0}' and pwd='{1}' ", ConText.Name, pwd);
}
SqlCommand com = new SqlCommand(sql, DBHelp.Connection);
DBHelp.OpenConnection();
int i = (int)com.ExecuteScalar();
if (i > 0)
{
if (ConText.Sf1.Equals("學¡ì生¦¨²"))
{
Menu2 s = new Menu2();
this.Hide();
s.Show();
}
else if (ConText.Sf1.Equals("教¨¬師º|"))
{
SDKForm1 s = new SDKForm1();
this.Hide();
s.Show();
}
else if (ConText.Sf1.Equals("教¨¬務?員¡À"))
{
Studentinfo s = new Studentinfo();
this.Hide();
s.Show();
}
}
else
{
MessageBox.Show("賬?號?,ê?密¨¹碼?錯䨪誤¨®!ê?");
}
}
DBHelp.CloseConnection();
}
/// <summary>
/// 點Ì?擊¡Â關?閉À?事º?件t
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void lblClose_Click(object sender, EventArgs e)
{
quit qui = new quit();
qui.Show();
}
/// <summary>
/// 點Ì?擊¡Â登Ì?陸?事º?件t
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnUserLogin_Click(object sender, EventArgs e)
{
UserLogin();
}
//鼠º¨®標À¨º移°?動¡¥到Ì?X上¦?的Ì?動¡¥作Á¡Â
private void lblClose_MouseMove(object sender, MouseEventArgs e)
{
lblClose.ForeColor = Color.Black;
}
private void lblClose_MouseLeave(object sender, EventArgs e)
{
lblClose.ForeColor = Color.DarkOrange;
}
/// <summary>
/// "清?空?"按ã¡ä鈕£¤
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnClear_Click(object sender, EventArgs e)
{
txtNum.Clear();
txtPwd.Clear();
cmbType.SelectedIndex = 0;
}
private void MainForm_Load(object sender, EventArgs e)
{
this.cmbType.SelectedIndex = 0;
}
三、修改密碼事件
/// <summary>
/// 點Ì?擊¡Â修T改?密¨¹碼?事º?件t
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnUpdatePwd_Click(object sender, EventArgs e)
{
string passwordOne = this.txtPasswordOne.Text.Trim();//獲?得Ì?窗ä¡ã體¬?中D輸º?入¨?的Ì?密¨¹碼?
string passwordTwo = this.txtPasswordTwo.Text.Trim();//獲?得Ì?窗ä¡ã體¬?中D輸º?入¨?的Ì?確¨¡¤認¨?密¨¹碼?
//判D斷?兩¢?次ä?新?密¨¹碼?是º?否¤?為a空?
if (passwordOne == string.Empty || passwordTwo == string.Empty)
{
MessageBox.Show("密¨¹碼?不?能¨¹為a空?!ê?", "友®?情¨¦提¬¨¢示º?!!!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
//判D斷?兩¢?次ä?新?密¨¹碼?是º?否¤?相¨¤等̨¨
else if (passwordOne != passwordTwo)
{
MessageBox.Show("輸º?入¨?的Ì?密¨¹碼?不?一°?致?!ê?", "友®?情¨¦提¬¨¢示º?!!!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
else
{
string sql = string.Format("update Examination1 set pwd = '{0}' where Name = '{1}'", passwordOne, ConText.Name);
try
{
SqlCommand com = new SqlCommand(sql, DBHelp.Connection);//創ä¡ä建¡§Command對?象¨®
DBHelp.OpenConnection();//調Ì¡Â用®?DBHelp類¤¨¤中D打䨰開a數ºy據Y庫a連¢?接¨®
int i = com.ExecuteNonQuery();//執¡ä行Dsql語®?句?,ê?并¡é得Ì?到Ì?返¤¦Ì回?結¨¢果?
if (i > 0)
{
MessageBox.Show("修T改?成¨¦功|!ê?");
}
}
catch (Exception)
{
MessageBox.Show("系¦Ì統ª3內¨²部?錯䨪誤¨®,ê?請?聯¢a系¦Ì管¨¹理¤¨ª員¡À!", "友®?情¨¦提¬¨¢示º?!!!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
finally
{
DBHelp.CloseConnection();
}
}
}