第一范文网 - 专业文章范例文档资料分享平台

C#学生成绩管理系统课程设计报告45762

来源:用户分享 时间:2025/10/7 17:05:59 本文由loading 分享 下载这篇文档手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:xxxxxxx或QQ:xxxxxx 处理(尽可能给您提供完整文档),感谢您的支持与谅解。

图4.3.11

图4.3.12

14

第五章 主要功能模块代码

5.1 公共类代码设计

namespace MyHelper {

class SqlHelper {

public static readonly string connstr =

ConfigurationManager.ConnectionStrings[\].ConnectionString;

public static int ExecuteNonQuery(string cmdText, params SqlParameter[] parameters) {

using (SqlConnection conn = new SqlConnection(connstr)) {

conn.Open();

using (SqlCommand cmd = conn.CreateCommand()) {

cmd.CommandText = cmdText;

cmd.Parameters.AddRange(parameters); return cmd.ExecuteNonQuery(); } } }

public static object ExecuteScalar(string cmdText, params SqlParameter[] parameters) {

using (SqlConnection conn = new SqlConnection(connstr)) {

conn.Open();

using (SqlCommand cmd = conn.CreateCommand()) {

cmd.CommandText = cmdText;

cmd.Parameters.AddRange(parameters); return cmd.ExecuteScalar(); } } }

15

public static DataTable ExecuteDataTable(string cmdText, params SqlParameter[] parameters) {

using (SqlConnection conn = new SqlConnection(connstr)) {

conn.Open();

using (SqlCommand cmd = conn.CreateCommand()) {

cmd.CommandText = cmdText;

cmd.Parameters.AddRange(parameters);

using (SqlDataAdapter adapter = new SqlDataAdapter(cmd)) {

DataTable dt = new DataTable(); adapter.Fill(dt); return dt; } } } }

public static SqlDataReader ExecuteDataReader(string cmdText, params SqlParameter[] parameters) {

SqlConnection conn = new SqlConnection(connstr); conn.Open();

using (SqlCommand cmd = conn.CreateCommand()) {

cmd.CommandText = cmdText;

cmd.Parameters.AddRange(parameters);

return cmd.ExecuteReader(CommandBehavior.CloseConnection); } } } }

5.2 登录界面代码设计

private void login_Click(object sender, EventArgs e) {//用户名及密码组合判断

if (username.Text.ToString().Trim() != \&& password.Text.ToString().Trim() != \

16

{

if (txtUserName.Text == \ || txtUserName.Text == \强强\) {

if (txtPsw.Text == \) {

MessageBox.Show(\登录成功!\, \提示?\, MessageBoxButtons.OK, MessageBoxIcon.Information); DialogResult = DialogResult.OK; } else {

MessageBox.Show(\密码错误,您还有\ + i + \次机会...\); i--; } } else {

MessageBox.Show(\亲,没有此用户名\); }

}

5.3 查询模块代码设计

QueryFrm query = new QueryFrm();

if (query.ShowDialog() == DialogResult.OK) {

DataTable dt = SqlHelper.ExecuteDataTable(\编号',Name as '姓名',Sex as '性别',English as '英语',Chinese as '语文', Math as '数学' from T_Student where name = @name\,new SqlParameter(\, query.Name));

if (dt.Rows.Count>=1) {

dataGridView1.DataSource = dt; } else {

MessageBox.Show(\没有找到您所查询的结果,请重新查询\,\提

17

示\,MessageBoxButtons.OK,MessageBoxIcon.Information); } }

5.4 添加模块代码设计

if (txtName.Text.Trim() == \ ||

txtChi.Text.Trim() == \ || txtEng.Text.Trim() == \ || txtMath.Text.Trim() == \ ) {

MessageBox.Show(\请将信息填写完整\, \警告?\,

MessageBoxButtons.OK, MessageBoxIcon.Information); return; } else {

if (rbMale.Checked) {

SqlHelper.ExecuteNonQuery(\T_Student(name,sex,english,math,chinese) values(@name,@sex,@Eng,@Math,@Chi)\, new SqlParameter(\, txtName.Text),

new SqlParameter(\, Convert.ToInt32(txtEng.Text)),

new SqlParameter(\,\男D\), new SqlParameter(\, Convert.ToInt32(txtChi.Text)),

new SqlParameter(\, Convert.ToInt32(txtMath.Text)) ); } else {

SqlHelper.ExecuteNonQuery(\T_Student(name,sex,english,math,chinese) values(@name,@sex,@Eng,@Math,@Chi)\, new SqlParameter(\, txtName.Text),

new SqlParameter(\, txtEng.Text),

new SqlParameter(\, \女?\), new SqlParameter(\, txtChi.Text),

18

C#学生成绩管理系统课程设计报告45762.doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.diyifanwen.net/c358wu8gttu0a6ri16ozy38gut0xt46013us_4.html(转载请注明文章来源)
热门推荐
Copyright © 2012-2023 第一范文网 版权所有 免责声明 | 联系我们
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:xxxxxx 邮箱:xxxxxx@qq.com
渝ICP备2023013149号
Top