1.项目简介:
实现学生信息的增、删、改、查;班级信息的。。。。。、课程信息的、、、、、、;成绩信息的、、、、、、、。用户登录校验与密码修改等。
2.框架搭建
开发中,还不完善。
3.登录与退出
//登录
private void btnLogin_Click(object sender, EventArgs e)
{
//数据验证
if (this.txtUserName.Text.Trim().Length == 0)
{
MessageBox.Show("请输入登录账号!", "登录提示");
this.txtUserName.Focus();
return;
}
if (this.txtPassword.Text.Trim().Length == 0)
{
MessageBox.Show("请输入登录密码!", "登录提示");
this.txtPassword.Focus();
return;
}
//登录用户对象
Admin admin = new Admin();
admin.UserName = this.txtUserName.Text.Trim();
admin.Password = this.txtPassword.Text.Trim();
//提交信息
try
{
admin = adminService.AdminLogin(admin);
if (admin == null)
{
MessageBox.Show("登录账号或密码错误!", "登录提示");
}
else
{
Program.onlineAdmin = admin;//保存在线用户
this.DialogResult = DialogResult.OK;//设置登录成功信息提示
this.Close();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message,"登录失败!");
}
}
//关闭
private void btnExit_Click(object sender, EventArgs e)
{
this.Close();
}
private void LoginForm_Load(object sender, EventArgs e)
{
int x = (System.Windows.Forms.SystemInformation.WorkingArea.Width - this.Size.Width) / 2;
int y = (System.Windows.Forms.SystemInformation.WorkingArea.Height - this.Size.Height) / 2;
this.StartPosition = FormStartPosition.Manual; //窗体的位置由Location属性决定
this.Location = (Point)new Size(x, y);
}
4.密码修改
private void ModifyPwdForm_Load(object sender, EventArgs e)
{
int x = (System.Windows.Forms.SystemInformation.WorkingArea.Width - this.Size.Width) / 2;
int y = (System.Windows.Forms.SystemInformation.WorkingArea.Height - this.Size.Height) / 2;
this.StartPosition = FormStartPosition.Manual; //窗体的位置由Location属性决定
this.Location = (Point)new Size(x, y);
}
private void btnModifyPwd_Click(object sender, EventArgs e)
{
//校验用户信息是否正确
if (this.txtPwd.Text.Trim().Length == 0)
{
MessageBox.Show("请输入旧密码", "修改提示");
this.txtPwd.Focus();
return;
}
//原密码正确与否
if (this.txtPwd.Text.Trim() != Program.onlineAdmin.Password)
{
MessageBox.Show("原密码不正确!", "修改提示");
this.txtPwd.Focus();
this.txtPwd.SelectAll();
return;
}
//新密码为空?
if (this.txtNewPwd.Text.Trim().Length == 0)
{
MessageBox.Show("请输入新密码", "修改提示");
this.txtPwd.Focus();
return;
}
//确认密码为空?
if (this.txtConfimPwd.Text.Trim().Length == 0)
{
MessageBox.Show("请再次输入密码", "修改提示");
this.txtPwd.Focus();
return;
}
//验证2次密码是否一致
if (this.txtNewPwd.Text.Trim() != this.txtConfimPwd.Text.Trim())
{
MessageBox.Show("两次输入的密码不一致!", "修改提示");
return;
}
//将新密码提交到数据库
string id = Program.onlineAdmin.AdminId.ToString();
int result = adminService.ModifyPwd(this.txtNewPwd.Text.Trim(), "1");
if (result ==1)
{
MessageBox.Show("新密码修改成功!","修改提示");
Program.onlineAdmin.Password = txtNewPwd.Text.Trim();
this.Close();
}
}
private void btnClosePwd_Click(object sender, EventArgs e)
{
this.Close();
}