formcourseadd.cs

来自「学生管理系统Csharp2005 学生管理系统Csharp2005 学生管理」· CS 代码 · 共 79 行

CS
79
字号
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;

using StudentManager.DbLayer;

namespace StudentManager
{
    public partial class FormCourseAdd : Form
    {
        public FormCourseAdd()
        {
            InitializeComponent();
        }

        /// <summary>
        /// 查询课程表“Course”中的数据,并绑定导DataGridView中
        /// </summary>
        void LoadData()
        {
            string sql = "select * from [Course]";
            Database db = new Database();
            DataTable dt = db.GetDataTable(sql);
            this.dataGridViewPreView.DataSource = dt;
        }

        /// <summary>
        /// “添加”按钮单击事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void buttonAdd_Click(object sender, EventArgs e)
        {
            string sql = "";
            sql += "insert into [Course] values(";
            sql += SqlStringConstructor.GetQuotedString(textBoxCNo.Text) + ",";
            sql += SqlStringConstructor.GetQuotedString(textBoxCName.Text) + ")";

            Database db = new Database();
            if (db.ExecuteSQL(sql) != -1)
                MessageBox.Show("添加成功!");
            else
                MessageBox.Show("添加失败,课程编号重复!");

            this.LoadData();
        }

        /// <summary>
        /// “重置”按钮单击事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void buttonReset_Click(object sender, EventArgs e)
        {
            textBoxCNo.Text = "";
            textBoxCName.Text = "";
        }

        /// <summary>
        /// “关闭”按钮单击事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void buttonClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void FormCourseAdd_Load(object sender, EventArgs e)
        {

        }
    }
}

⌨️ 快捷键说明

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