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

📄 选课情况.cs

📁 用csharp和ms sql 简单实现学生管理系统
💻 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 学生管理系统
{
    public partial class 选课情况 : Form
    {
        private string connectionString = "workstation id=localhost;Integrated Security=SSPI;database=student";
        //与数据库的连接
        private SqlConnection myConnection;
        private SqlDataAdapter da1;
        private SqlDataAdapter da2;
        private DataSet ds = new DataSet();
        private string sendTableName = "课程查询";
        private string sendStrSQL = "SELECT * FROM 课程查询 where 学号="+LoginFrm.strUser.Trim();
        private string sendTable = "2006年选课";
        private string sendStrSQL1 = "SELECT * 课程查询 where 学号=" + LoginFrm.strUser.Trim();
        private GroupBox groupBox1;
        private ComboBox comboBox2;
        private Label label2;
        private Label label1;
        private DataGridView dataGridView1;
        private ComboBox comboBox1;
        private Button button1;
        private System.ComponentModel.IContainer components ;
    
        public 选课情况()
        {
            InitializeComponent();
            myConnection = new SqlConnection(connectionString);
            da1 = new SqlDataAdapter(sendStrSQL, myConnection);
            da1.Fill(ds, sendTable);
            foreach (DataRow row in ds.Tables["2006年选课"].Rows)
            {
                comboBox1.Items.Add(row["学年"].ToString());
            }
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (components != null)
                {
                    components.Dispose();
                }
            }
            base.Dispose(disposing);
        }

        private void InitializeComponent()
        {
            this.groupBox1 = new System.Windows.Forms.GroupBox();
            this.button1 = new System.Windows.Forms.Button();
            this.label2 = new System.Windows.Forms.Label();
            this.label1 = new System.Windows.Forms.Label();
            this.comboBox2 = new System.Windows.Forms.ComboBox();
            this.comboBox1 = new System.Windows.Forms.ComboBox();
            this.dataGridView1 = new System.Windows.Forms.DataGridView();
            this.groupBox1.SuspendLayout();
            ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit();
            this.SuspendLayout();
            // 
            // groupBox1
            // 
            this.groupBox1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
                        | System.Windows.Forms.AnchorStyles.Right)));
            this.groupBox1.Controls.Add(this.button1);
            this.groupBox1.Controls.Add(this.label2);
            this.groupBox1.Controls.Add(this.label1);
            this.groupBox1.Controls.Add(this.comboBox2);
            this.groupBox1.Controls.Add(this.comboBox1);
            this.groupBox1.Location = new System.Drawing.Point(0, 0);
            this.groupBox1.Name = "groupBox1";
            this.groupBox1.Size = new System.Drawing.Size(600, 57);
            this.groupBox1.TabIndex = 0;
            this.groupBox1.TabStop = false;
            this.groupBox1.Text = "查询";
            // 
            // button1
            // 
            this.button1.Location = new System.Drawing.Point(90, 20);
            this.button1.Name = "button1";
            this.button1.Size = new System.Drawing.Size(75, 23);
            this.button1.TabIndex = 4;
            this.button1.Text = "查询";
            this.button1.UseVisualStyleBackColor = true;
            this.button1.Click += new System.EventHandler(this.button1_Click);
            // 
            // label2
            // 
            this.label2.AutoSize = true;
            this.label2.Location = new System.Drawing.Point(483, 28);
            this.label2.Name = "label2";
            this.label2.Size = new System.Drawing.Size(29, 12);
            this.label2.TabIndex = 3;
            this.label2.Text = "学期";
            // 
            // label1
            // 
            this.label1.AutoSize = true;
            this.label1.Location = new System.Drawing.Point(317, 28);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(29, 12);
            this.label1.TabIndex = 2;
            this.label1.Text = "学年";
            // 
            // comboBox2
            // 
            this.comboBox2.FormattingEnabled = true;
            this.comboBox2.Items.AddRange(new object[] {
            "上",
            "下"});
            this.comboBox2.Location = new System.Drawing.Point(518, 20);
            this.comboBox2.Name = "comboBox2";
            this.comboBox2.Size = new System.Drawing.Size(49, 20);
            this.comboBox2.TabIndex = 1;
            // 
            // comboBox1
            // 
            this.comboBox1.FormattingEnabled = true;
            this.comboBox1.Location = new System.Drawing.Point(365, 20);
            this.comboBox1.Name = "comboBox1";
            this.comboBox1.Size = new System.Drawing.Size(105, 20);
            this.comboBox1.TabIndex = 0;
            // 
            // dataGridView1
            // 
            this.dataGridView1.AllowUserToAddRows = false;
            this.dataGridView1.AllowUserToDeleteRows = false;
            this.dataGridView1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
                        | System.Windows.Forms.AnchorStyles.Right)));
            this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
            this.dataGridView1.Location = new System.Drawing.Point(0, 63);
            this.dataGridView1.Name = "dataGridView1";
            this.dataGridView1.ReadOnly = true;
            this.dataGridView1.RowTemplate.Height = 23;
            this.dataGridView1.Size = new System.Drawing.Size(600, 374);
            this.dataGridView1.TabIndex = 1;
            // 
            // 选课情况
            // 
            this.ClientSize = new System.Drawing.Size(600, 437);
            this.Controls.Add(this.dataGridView1);
            this.Controls.Add(this.groupBox1);
            this.Name = "选课情况";
            this.groupBox1.ResumeLayout(false);
            this.groupBox1.PerformLayout();
            ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit();
            this.ResumeLayout(false);

        }

        private void button1_Click(object sender, EventArgs e)
        {
            
            string sqlstring =sendStrSQL;
            if (this.comboBox1.Text.Trim()=="")
            {
                if (this.comboBox2.Text.Trim()=="")
                {
                }
                else if (this.comboBox2.Text.Trim() == "上")
                    sqlstring = sendStrSQL + " " + "and 学期='上'";
                else
                    sqlstring=sendStrSQL+" "+"and 学期='下'";
            }
            else
            {
                if (this.comboBox2.Text.Trim() == "")
                    sqlstring = sendStrSQL + " and 学年=" + comboBox1.Text.Trim() ;
                else if (this.comboBox2.Text.Trim() == "上")
                    sqlstring = sendStrSQL + " and 学年=" +comboBox1.Text.Trim() + "and 学期='上'";
                else
                    sqlstring = sendStrSQL + " and 学年=" + comboBox1.Text.Trim() + "and 学期='下'";
            }
            da2 = new SqlDataAdapter(sqlstring, myConnection);
            da2.Fill(ds, sendTableName);
            this.dataGridView1.DataSource = ds.Tables["课程查询"];
        }

    }
}

⌨️ 快捷键说明

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