1、C系统 界面:Login.csusing System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;namespace WindowsApplication3 public partial class Login : Form public Login() InitializeComponent(); private void btnYes_Click
2、(object sender, EventArgs e) string userName = txtName.Text; string password = txtPwd.Text; if (userName = 伍晓忠 & password = 1234) MessageBox.Show(欢送进入成绩管理系统!, 登陆成功, MessageBoxButtons.OK, MessageBoxIcon.Information); else MessageBox.Show(你输入的用户名或密码错误!, 失败, MessageBoxButtons.OK, MessageBoxIcon.Exclama
3、tion); private void btnCancel_Click(object sender, EventArgs e) txtName.Text = ; txtPwd.Text = ; txtName.Focus(); 创立数据库:实现功能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.
4、SqlClient;namespace WindowsApplication3 public partial class Login : Form public Login() InitializeComponent(); private void btnYes_Click(object sender, EventArgs e) string userName = txtName.Text; string password = txtPwd.Text; / string connString = Data Source= YJsqlexpress;Initial Catalog=MySchoo
5、l; Integrated Security=Ture; string connString = Data Source= 深度系统sqlexpress;Initial Catalog=MySchool; trusted_connection=true; / pc-202307051235sqlexpress SqlConnection connection = new SqlConnection(connString); /获取用户名和密码匹配的行的数量的SQL语句 string sql =String.Format(select count(x) from User where userN
6、ame=0 and password=1,userName,password); try connection.Open();/翻开数据库连接 SqlCommand command = new SqlCommand(sql,connection);/创立Command对象 int num = (int)command.ExecuteScalar();/执行查询语句,返回匹配的行数 if (num 0) /如果有匹配的行,那么说明用户名和密码正确 MessageBox.Show(欢送进入成绩管理系统!, 登陆成功, MessageBoxButtons.OK, MessageBoxIcon.Inf
7、ormation); MainFrm mainForm = new MainFrm(); /创立主窗体对象 mainForm.Show(); /显示窗体 this.Visible = false; /登陆窗体隐藏 else MessageBox.Show(你输入的用户名或密码错误!, 失败, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); catch (Exception ex) MessageBox.Show(ex.Message,操作数据库出错!,MessageBoxButtons.OK,MessageBoxIcon.Exclamati
8、on); finally connection.Close(); private void btnCancel_Click(object sender, EventArgs e) txtName.Text = ; txtPwd.Text = ; txtName.Focus(); private void Login_Load(object sender, EventArgs e) 主窗体创立代码:using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;namespace WindowsApplication3 public partial class MainFrm : Form public MainFrm() InitializeComponent(); private void MainFrm_Load(object sender, EventArgs e)