⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 frmupdatestudent.cs

📁 大二做的课程设计。一个学生信息管理系统
💻 CS
字号:
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.SqlClient;

namespace Students1
{
    using StudentLibrary.Business;
    public partial class frmUpdateStudent : Form
    {
        private int iStudentId;
        public frmUpdateStudent()
        {
            InitializeComponent();
        }

        public frmUpdateStudent(int iStudentId)
        {
            this.iStudentId = iStudentId;
            InitializeComponent();
        }
        
        private void frmUpdateStudent_Load(object sender, EventArgs e)
        {
            GetClass();
            GetGender();
            GetStudentInfo();
            
        }

        private void GetGender()
        { }

        private void GetClass()
        {
             
             
            
             Classs classs = new Classs();
            DataSet dataSet = new DataSet();
            try
            {
                
                dataSet = classs.SelectClass(
                    -1,
                    "");
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
                this.Close();
                return;
            }
          
             
            
            cboClass.ValueMember = "ClassId";
            cboClass.DisplayMember = "ClassName";//获取dataSet表中ClassName的值
            cboClass.DataSource = dataSet.Tables[0];

        }

        private void GetStudentInfo()
        {


            Students students = new Students();
            DataSet dataSet = new DataSet();
            try
            {
                
                dataSet = students.SelectStudent(
                    iStudentId,
                    "",
                    "",
                    -1);
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
            if (dataSet.Tables[0].Rows.Count == 0)
            {
                MessageBox.Show("学生信息不存在。");
                this.Close();
                this.Dispose();
            }
            
            DataRow row = dataSet.Tables[0].Rows[0];
            MessageBox.Show(row["Gender"].ToString());
            this.txtRemark.Text = row["Remark"].ToString();
            this.txtStudentName.Text = row["StudentName"].ToString();
            this.txtStudentNo.Text = row["StudentNo"].ToString();
            cboClass.SelectedValue = Convert.ToInt32(row["ClassId"]);

            cboGender.SelectedIndex = Convert.ToInt32(row["Gender"]);
 
        }
        /// <summary>
        /// 更新学生信息
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button1_Click(object sender, EventArgs e)
        {
            Students students = new Students();
			try
			{
				students.UpdateStudent(
					iStudentId,
					txtStudentNo.Text,
					txtStudentName.Text,
					this.txtBrithday.Value,
					this.cboGender.SelectedIndex,
					Convert.ToInt32(cboClass.SelectedValue),
					txtRemark.Text);
			}
			catch(Exception ex)
			{
				MessageBox.Show(ex.Message);
				students.Dispose();
				return;
			}
			MessageBox.Show("更改成功。");
            this.Close();
			students.Dispose();
		}
       /// <summary>
       /// 删除学生信息
       /// </summary>
       /// <param name="sender"></param>
       /// <param name="e"></param>
        private void button2_Click(object sender, EventArgs e)
        {

            Students students = new Students();
            try
            {
                students.DeleteStudent(
                    iStudentId,
                    -1);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                students.Dispose();
                return;
            }
            MessageBox.Show("删除成功。");
            students.Dispose();
            this.Close();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            this.Close();
        }
        

        

       
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -