Visual Studio 2022编写学校收费管理系统,后端数据库是Access,数据库中有账号表,学生信息表,学费表,学期表,教材表,教材费表,住宿表,住宿费表等
这是我的部分代码,有无大佬可以指导一下,我的程序哪里出问题了,输入正确账号密码之后,点击登录页面的登录按钮无法跳转到系统导航页面,后续都无法进行。
或者有无大佬有这样的程序![]()
LoginForm页面代码
using SchoolFeeManagementSystem;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.OleDb;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApp7
{
public partial class LoginForm : Form
{
private string connectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=E:新建文件夹\WindowsFormsApp7\WindowsFormsApp7\学校收费管理系统1.accdb";
private OleDbConnection connection;
public LoginForm()
{
InitializeComponent();
connection = new OleDbConnection(connectionString);
}
private void btnLogin_Click(object sender, EventArgs e)
{
string username = txtUsername.Text.Trim();
string password = txtPassword.Text.Trim();
bool isAuthenticated = ValidateUser(username, password);
if (isAuthenticated)
{
NavigationForm navigationForm = new NavigationForm(username, password);
this.Hide();
navigationForm.Show();
}
else
{
MessageBox.Show("用户名或密码错误!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private bool ValidateUser(string username, string password)
{
bool isAuthenticated = false;
try
{
connection.Open();
string query = "SELECT COUNT(*) FROM 账号表 WHERE 账号 = @username AND 密码 = @password";
using (OleDbCommand command = new OleDbCommand(query, connection))
{
command.Parameters.AddWithValue("@username", username);
command.Parameters.AddWithValue("@password", password);
int count = (int)command.ExecuteScalar();
if (count > 0)
{
isAuthenticated = true;
}
}
}
catch (Exception ex)
{
MessageBox.Show("数据库连接错误:" + ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
return isAuthenticated;
}
}
}
系统导航页面代码
using System;
using System.Windows.Forms;
namespace SchoolFeeManagementSystem
{
public partial class NavigationForm : Form
{
private string username;
private string password;
public NavigationForm(string username, string password)
{
InitializeComponent();
this.username = username;
this.password = password;
}
private void btnPersonalInfo_Click(object sender, EventArgs e)
{
PersonalInfoForm personalInfoForm = new PersonalInfoForm(username, password);
personalInfoForm.ShowDialog();
}
private void btnExit_Click(object sender, EventArgs e)
{
Application.Exit();
}
}
}
个人信息管理页面代码
using System;
using System.Windows.Forms;
using System.Data.OleDb;
using System.Data;
namespace SchoolFeeManagementSystem
{
public partial class PersonalInfoForm : Form
{
private string connectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=E:新建文件夹\WindowsFormsApp7\WindowsFormsApp7\学校收费管理系统1.accdb";
private string username = "";
private string password = "";
public PersonalInfoForm(string username, string password)
{
InitializeComponent();
this.username = username;
this.password = password;
}
private void PersonalInfoForm_Load(object sender, EventArgs e)
{
QueryPersonalInfo();
}
private void QueryPersonalInfo()
{
string studentId = txtStudentId.Text.Trim();
try
{
using (OleDbConnection connection = new OleDbConnection(connectionString))
{
connection.Open();
string query = "SELECT * FROM 学生信息表 WHERE 学号 = @studentId AND 账号 = @username AND 密码 = @password";
using (OleDbCommand command = new OleDbCommand(query, connection))
{
command.Parameters.AddWithValue("@studentId", studentId);
command.Parameters.AddWithValue("@username", username);
command.Parameters.AddWithValue("@password", password);
OleDbDataAdapter adapter = new OleDbDataAdapter(command);
DataTable dataTable = new DataTable();
adapter.Fill(dataTable);
dataGridView1.DataSource = dataTable;
}
}
}
catch (Exception ex)
{
MessageBox.Show("数据库连接错误:" + ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void PersonalInfoForm_Load_1(object sender, EventArgs e)
{
this.学生信息查询TableAdapter1.Fill(this.学校收费管理系统1DataSet1.学生信息查询);
}
}
}
这是我的程序流程图,但是在编写代码的时候我只设计了登录页面系统导航页面还有个人管理页面的相关操作代码
