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

📄 班级设置.cs

📁 用csharp和ms sql 简单实现学生管理系统
💻 CS
📖 第 1 页 / 共 2 页
字号:
            this.groupBox3.Size = new System.Drawing.Size(225, 100);
            this.groupBox3.TabIndex = 11;
            this.groupBox3.TabStop = false;
            this.groupBox3.Text = "年级增删";
            // 
            // button4
            // 
            this.button4.Location = new System.Drawing.Point(126, 42);
            this.button4.Name = "button4";
            this.button4.Size = new System.Drawing.Size(75, 23);
            this.button4.TabIndex = 1;
            this.button4.Text = "确认添加";
            this.button4.UseVisualStyleBackColor = true;
            this.button4.Click += new System.EventHandler(this.button4_Click);
            // 
            // button3
            // 
            this.button3.Location = new System.Drawing.Point(26, 42);
            this.button3.Name = "button3";
            this.button3.Size = new System.Drawing.Size(75, 23);
            this.button3.TabIndex = 0;
            this.button3.Text = "确认删除";
            this.button3.UseVisualStyleBackColor = true;
            this.button3.Click += new System.EventHandler(this.button3_Click);
            // 
            // 班级设置
            // 
            this.ClientSize = new System.Drawing.Size(572, 403);
            this.Controls.Add(this.groupBox3);
            this.Controls.Add(this.groupBox2);
            this.Controls.Add(this.groupBox1);
            this.Controls.Add(this.label4);
            this.Controls.Add(this.label3);
            this.Controls.Add(this.textBox2);
            this.Controls.Add(this.textBox1);
            this.MaximizeBox = false;
            this.MinimizeBox = false;
            this.Name = "班级设置";
            this.groupBox1.ResumeLayout(false);
            this.groupBox1.PerformLayout();
            this.groupBox2.ResumeLayout(false);
            this.groupBox3.ResumeLayout(false);
            this.ResumeLayout(false);
            this.PerformLayout();

        }

        private void button1_Click(object sender, EventArgs e)
        {
            string a = comboBox2.Text.ToString().Trim();
            bool tag = false;
            if (DialogResult.OK == MessageBox.Show("确认增加一个班级", "确认增加", MessageBoxButtons.OKCancel, MessageBoxIcon.Asterisk))
            {
                foreach (DataRow srow in ds.Tables["年级列表"].Rows)
                {
                    if (srow["年级"].ToString().Trim() == a && srow["专业编号"].ToString().Trim() == no)
                    {
                        tag = true;
                        srow["班数"]=(Convert.ToInt16(srow["班数"].ToString().Trim())+1).ToString();
                    }
                }
                if (tag == false)
                {
                    MessageBox.Show("请选正确的班级所在单位!");
                }
                else
                {
                    sda.Update(ds, "年级列表");
                    MessageBox.Show("添加成功!");

                }
            }
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            comboBox2.Items.Clear();
            textBox1.Text = comboBox1.Text+"目前有";
            foreach (DataRow row in ds.Tables["专业列表"].Rows)
            {
                if (comboBox1.Text.ToString().Trim() == row["专业"].ToString().Trim())
                {
                    no = row["专业编号"].ToString().Trim();
                    foreach (DataRow srow in row.GetChildRows(ts))
                    {
                        comboBox2.Items.Add(srow["年级"].ToString());
                        textBox1.Text = textBox1.Text + srow["年级"].ToString().Trim()+"级\n";
                    }
                }
            }
        }

        private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
        {
            string a=comboBox2.Text.ToString().Trim();
            textBox2.Text = a + "目前有";
            foreach (DataRow srow in ds.Tables["年级列表"].Rows)
            {
                if (srow["年级"].ToString().Trim() == a && srow["专业编号"].ToString().Trim()==no)
                {
                    textBox2.Text=textBox2.Text+srow["班数"]+"个班";
                }
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            string a = comboBox2.Text.ToString().Trim();
            bool tag = false;
            if (DialogResult.OK == MessageBox.Show("确认删除", "确认删除班级", MessageBoxButtons.OKCancel, MessageBoxIcon.Asterisk))
            {
                foreach (DataRow srow in ds.Tables["年级列表"].Rows)
                {
                    if (srow["年级"].ToString().Trim() == a && srow["专业编号"].ToString().Trim() == no)
                    {
                        tag = true;
                        if (Convert.ToInt16(srow["班数"].ToString().Trim())==0)
                        {
                            MessageBox.Show("没有任何班级可删除!","提示");
                            return;
                        }
                        srow["班数"] = (Convert.ToInt16(srow["班数"].ToString().Trim()) - 1).ToString();
                    }
                }
                if (tag == false)
                {
                    MessageBox.Show("请选正确的班级所在单位!");
                }
                else
                {
                    sda.Update(ds, "年级列表");
                    MessageBox.Show("删除班级成功!");
                    
                }
            }
        }

        private void button4_Click(object sender, EventArgs e)
        {
            string a = comboBox2.Text.ToString().Trim();
            bool tag = true;
            if (DialogResult.OK == MessageBox.Show("确认增加年级","确认增加",MessageBoxButtons.OKCancel, MessageBoxIcon.Asterisk))
            {
                foreach (DataRow srow in ds.Tables["年级列表"].Rows)
                {
                    if (srow["年级"].ToString().Trim() == a && srow["专业编号"].ToString().Trim() == no)
                    {
                        tag = false;
                    }
                }
                if (tag == false)
                {
                    MessageBox.Show("年级已存在!");
                }
                else
                {
                    DataRow datarow = ds.Tables["年级列表"].NewRow();
                    datarow["年级"] = a;
                    datarow["专业编号"] = no;
                    datarow["班数"] = "0";
                    ds.Tables["年级列表"].Rows.Add(datarow);
                    sda.Update(ds, "年级列表");
                    comboBox2.Items.Add(a);
                    MessageBox.Show("年级添加成功!");
                }
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            string a = comboBox2.Text.ToString().Trim();
            bool tag = false;
            if (DialogResult.OK == MessageBox.Show("确认删除年级", "确认删除", MessageBoxButtons.OKCancel, MessageBoxIcon.Asterisk))
            {
                foreach (DataRow srow in ds.Tables["年级列表"].Rows)
                {
                    if (srow["年级"].ToString().Trim() == a && srow["专业编号"].ToString().Trim() == no)
                    {
                        tag = true;
                    }
                }
                if (tag == false)
                {
                    MessageBox.Show("年级不存在!");
                }
                else
                {
                    DataColumn[] keys = new DataColumn[2];
                    keys[0]=ds.Tables["年级列表"].Columns["年级"];
                    keys[1]=ds.Tables["年级列表"].Columns["专业编号"];
                    ds.Tables["年级列表"].PrimaryKey = keys;
                    object[] ob ={ a, no };
                    DataRow datarow = ds.Tables["年级列表"].Rows.Find(ob);
                    datarow.Delete();
                    sda.Update(ds, "年级列表");
                    comboBox2.Items.Remove(comboBox2.Text);
                    MessageBox.Show("删除成功!");
                }
            }
        }

    }
}

⌨️ 快捷键说明

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