?? login.cs
字號:
?using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
namespace student
{
public partial class Login : Form
{
public Login()
{
InitializeComponent();
this.Text = "學生管理系統";
this.StartPosition = FormStartPosition.CenterScreen;
}
public string StuName;
public string StuID;
private void loginbtn_Click(object sender, EventArgs e)
{
string ConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=..\\..\\Students.mdb";
string MyString = "SELECT StuID,Pwd,StuName FROM Students WHERE [StuID] = @ID";
OleDbConnection Conn = new OleDbConnection(ConnString);
OleDbCommand MyCmd = new OleDbCommand(MyString, Conn);
OleDbDataReader myReader;
MyCmd.Parameters.AddWithValue("@ID", StuIDText.Text); //傳遞輸入框的值
Conn.Open();
myReader = MyCmd.ExecuteReader();
if (myReader.Read() == false)
{
MessageBox.Show("學號錯誤,請輸入正確的學號!", "溫馨提示!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
if (PwdText.Text == myReader.GetValue(1).ToString())
{
StuID = myReader.GetValue(0).ToString();
}
else
{
MessageBox.Show("密碼錯誤!", "溫馨提示!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
MainForm login = new MainForm();
login.Show();
Conn.Close();
this.Hide();
if (StuIDText.Text == "")
{
MessageBox.Show("請輸入學號!", "溫馨提示!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
if (PwdText.Text == "")
{
MessageBox.Show("請輸入密碼!", "溫馨提示!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
}
private void exitbtn_Click_1(object sender, EventArgs e)
{
Application.Exit();
}
private void linkLabel1_LinkClicked_1(object sender, LinkLabelLinkClickedEventArgs e)
{
MessageBox.Show("學生學號格式為:2006**,初始密碼跟學生學號相同。", "溫馨提示!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
private void Login_Load(object sender, EventArgs e)
{
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -