12.4(2)

同时完成cs页面报告C/S结构用户界面设计(学生管理系统)
信2305-3 程永耀 23233967

【实验编号】
10003809547j   图形用户界面设计
【实验学时】
8学时
【实验环境】
所需硬件环境为微机;
所需软件环境为Microsoft Visual Studio 2013
【实验内容】
实验基本信息

  • 时间:2024年1月
  • 实验名称:C/S结构用户界面设计
  • 实验内容:基于Vue.js和Element UI框架,设计并实现学生成绩管理系统的完整用户界面,包括登录界面、主控制台、课程管理、用户管理、学生管理、成绩管理及数据统计模块。
    1、登录界面:
    截图:

核心代码:

private void LoginButton_Click(object sender, EventArgs e)
{
    // 获取用户名和密码文本框
    TextBox txtUsername = (TextBox)this.Controls.Find("txtUsername", true)[0];
    TextBox txtPassword = (TextBox)this.Controls.Find("txtPassword", true)[0];
    
    string username = txtUsername.Text.Trim();
    string password = txtPassword.Text.Trim();
    
    // 简单的登录验证 - 在实际应用中应该从数据库验证
    if (username == "admin" && password == "admin")  // 默认管理员账户
    {
        // 设置登录状态
        DataManager.IsLoggedIn = true;
        
        // 启用主界面的功能菜单
        Form1 mainForm = (Form1)Application.OpenForms["Form1"];
        if (mainForm != null)
        {
            mainForm.EnableMenuItems();
        }
        
        // 显示成功消息
        MessageBox.Show("登录成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
        this.Close();  // 关闭登录窗口
    }
    else
    {
        MessageBox.Show("用户名或密码错误!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
    }
}
2、主界面:
截图:

核心代码:
```csharp
private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
    // 打开登录界面
    LoginForm loginForm = new LoginForm();
    loginForm.Show();
}

private void button1_Click(object sender, EventArgs e)
{
    // 进入系统按钮 - 直接显示登录界面
    LoginForm loginForm = new LoginForm();
    loginForm.Show();
}

private void tsmiStudentManage_Click(object sender, EventArgs e)
{
    // 打开学生管理界面
    StudentManagementForm studentForm = new StudentManagementForm();
    studentForm.Show();
}

private void tsmiGradeManage_Click(object sender, EventArgs e)
{
    // 打开成绩管理界面
    GradeManagementForm gradeForm = new GradeManagementForm();
    gradeForm.Show();
}
3、学生管理界面:
截图:


核心代码:
```csharp
// 添加学生
private void btnAdd_Click(object sender, EventArgs e)
{
    // 验证输入
    if (string.IsNullOrEmpty(txtStudentID.Text) || string.IsNullOrEmpty(txtName.Text))
    {
        MessageBox.Show("学号和姓名不能为空!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
        return;
    }

    // 检查学号格式
    if (!int.TryParse(txtStudentID.Text, out int studentID))
    {
        MessageBox.Show("学号必须是数字!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
        return;
    }

    // 添加新学生
    Student newStudent = new Student
    {
        StudentID = studentID,
        Name = txtName.Text,
        Gender = cmbGender.SelectedItem?.ToString() ?? "",
        BirthDate = dtpBirthDate.Value,
        ClassName = cmbClass.SelectedItem?.ToString() ?? "",
        Phone = txtPhone.Text
    };

    DataManager.Students.Add(newStudent);
    LoadStudentData();  // 重新加载数据
    ClearInputs();  // 清空输入框
    
    // 显示成功消息
    using (SuccessForm successForm = new SuccessForm())
    {
        successForm.ShowDialog();
    }
}

// 删除学生
private void btnDelete_Click(object sender, EventArgs e)
{
    if (dgvStudents.SelectedRows.Count == 0)
    {
        MessageBox.Show("请先选择要删除的学生!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
        return;
    }

    // 确认删除
    DialogResult result = MessageBox.Show("确定要删除选中的学生吗?", "确认删除", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
    if (result == DialogResult.Yes)
    {
        // 获取选中的学生并进行空值检查
        if (dgvStudents.SelectedRows[0].DataBoundItem is Student selectedStudent)
        {
            // 删除相关的成绩记录
            DataManager.Grades.RemoveAll(g => g.StudentID == selectedStudent.StudentID);
            
            // 删除学生
            DataManager.Students.Remove(selectedStudent);
            LoadStudentData();  // 重新加载数据
            ClearInputs();  // 清空输入框
            
            // 显示成功消息
            using (SuccessForm successForm = new SuccessForm())
            {
                successForm.ShowDialog();
            }
        }
    }
}
4、成绩管理界面:
截图:

-核心代码:
```csharp
// 添加成绩
private void btnAdd_Click(object sender, EventArgs e)
{
    // 验证输入
    if (cmbStudent.SelectedItem == null || cmbCourse.SelectedItem == null || string.IsNullOrEmpty(txtScore.Text))
    {
        MessageBox.Show("请填写完整的成绩信息!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
        return;
    }

    // 验证成绩格式
    if (!decimal.TryParse(txtScore.Text, out decimal score) || score < 0 || score > 100)
    {
        MessageBox.Show("成绩必须是0-100之间的数字!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
        return;
    }

    // 获取选中的学生并进行空值检查
    if (cmbStudent.SelectedItem is Student selectedStudent && cmbCourse.SelectedItem is string courseNameObj)
    {
        string courseName = courseNameObj;
        
        // 生成新的成绩ID
        int newGradeID = DataManager.Grades.Count > 0 ? DataManager.Grades.Max(g => g.GradeID) + 1 : 1;
        
        // 添加新成绩
        Grade newGrade = new Grade
        {
            GradeID = newGradeID,
            StudentID = selectedStudent.StudentID,
            StudentName = selectedStudent.Name ?? "",
            CourseName = courseName,
            Score = score,
            ExamDate = dtpExamDate.Value
        };

        DataManager.Grades.Add(newGrade);
        LoadGradeData();  // 重新加载数据
        ClearInputs();  // 清空输入框
        
        // 显示成功消息
        using (SuccessForm successForm = new SuccessForm())
        {
            successForm.ShowDialog();
        }
    }
}
5.操作成功界面:
截图:

核心代码:
```csharp
public SuccessForm()
{
    // 设置窗口标题和大小
    this.Text = "success";
    this.Size = new Size(300, 200);
    this.StartPosition = FormStartPosition.CenterScreen;
    this.FormBorderStyle = FormBorderStyle.FixedDialog;
    this.MaximizeBox = false;
    this.MinimizeBox = false;
    
    // 创建界面控件
    CreateSuccessControls();
    
    // 设置定时器,2秒后自动关闭窗口
    System.Windows.Forms.Timer timer = new System.Windows.Forms.Timer();
    timer.Interval = 2000;  // 2000毫秒 = 2秒
    timer.Tick += (sender, e) => 
    {
        ((System.Windows.Forms.Timer)sender).Stop();
        this.Close();
    };
    timer.Start();
}

【关键步骤】

  1. 系统登录:在主界面上点击"登录/注册"链接或"进入系统"按钮,打开登录界面,使用默认账户(admin/admin)登录

  2. 学生信息管理:

    • 登录成功后,点击菜单栏的"学生管理"->"学生信息管理"
    • 在学生管理界面,可以查看所有学生列表
    • 使用搜索功能按学号、姓名或班级查找学生
    • 填写学生信息,点击"添加"按钮新增学生
    • 选择学生记录,点击"更新"按钮修改信息
    • 选择学生记录,点击"删除"按钮移除学生及其相关成绩
  3. 成绩信息管理:

    • 点击菜单栏的"成绩管理"->"成绩信息管理"
    • 在成绩管理界面,可以查看所有成绩记录
    • 使用搜索功能按学生姓名、课程名称或学号查找成绩
    • 选择学生和课程,输入成绩,点击"添加"按钮新增成绩
    • 选择成绩记录,点击"更新"按钮修改成绩
    • 选择成绩记录,点击"删除"按钮移除成绩
  4. 操作反馈:所有成功的操作都会弹出"操作成功!"提示窗口,并在2秒后自动关闭

【程序运行截图】

【实验体会】

这是我第一次编写完整的C/S架构界面应用程序,通过学生成绩管理系统的开发,我对Windows Forms的界面设计和开发有了深入的理解和实践。

  1. 界面设计便捷性:C#的Windows Forms提供了丰富的可视化控件,只需拖拽即可完成界面布局,大大提高了开发效率。我学会了如何合理组织界面元素,使用Panel进行区域划分,使界面结构清晰、美观。

  2. 控件使用技巧:掌握了多种常用控件的使用方法,如DataGridView用于数据展示,ComboBox用于下拉选择,DateTimePicker用于日期选择,Timer用于定时操作等。特别是DataGridView的使用,学会了如何绑定数据、设置列属性、处理选择事件等。

  3. 事件驱动编程:深入理解了Windows Forms的事件驱动模型,通过为控件添加事件处理程序,实现了界面与用户的交互。例如,按钮的Click事件、DataGridView的SelectionChanged事件等。

  4. 数据管理:使用静态类DataManager模拟数据源,实现了数据的增删改查功能,为界面提供了数据支持。虽然没有使用数据库,但通过内存数据管理,理解了数据与界面分离的设计思想。

  5. 登录状态控制:实现了简单的用户登录功能,并根据登录状态控制菜单的可用性,提高了系统的安全性。

  6. 用户体验优化:添加了输入验证、操作确认、成功提示等功能,提高了系统的用户友好性。例如,成绩必须在0-100之间,删除操作需要确认,操作成功后有明确提示等。

通过本次实验,我不仅掌握了Windows Forms的基本开发技能,还学会了如何将理论知识应用到实际项目中。在开发过程中,我遇到了一些问题,如控件布局调整、事件处理顺序、数据绑定等,但通过查阅资料和不断实践,最终都得到了解决。这次实验让我深刻体会到,C/S界面开发不仅需要掌握技术,还需要注重用户体验和系统架构设计。

posted @ 2025-12-04 23:58  山蚯  阅读(1)  评论(0)    收藏  举报