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

📄 用户管理.cs

📁 用csharp和ms sql 简单实现学生管理系统
💻 CS
📖 第 1 页 / 共 2 页
字号:
            // 
            // comboBox3
            // 
            this.comboBox3.FormattingEnabled = true;
            this.comboBox3.Location = new System.Drawing.Point(290, 5);
            this.comboBox3.Name = "comboBox3";
            this.comboBox3.Size = new System.Drawing.Size(75, 20);
            this.comboBox3.TabIndex = 3;
            this.comboBox3.SelectedIndexChanged += new System.EventHandler(this.comboBox3_SelectedIndexChanged);
            // 
            // comboBox2
            // 
            this.comboBox2.FormattingEnabled = true;
            this.comboBox2.Location = new System.Drawing.Point(119, 5);
            this.comboBox2.Name = "comboBox2";
            this.comboBox2.Size = new System.Drawing.Size(101, 20);
            this.comboBox2.TabIndex = 2;
            this.comboBox2.SelectedIndexChanged += new System.EventHandler(this.comboBox2_SelectedIndexChanged);
            // 
            // dataGridView2
            // 
            this.dataGridView2.AllowUserToOrderColumns = true;
            this.dataGridView2.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
            this.dataGridView2.Dock = System.Windows.Forms.DockStyle.Fill;
            this.dataGridView2.Location = new System.Drawing.Point(3, 28);
            this.dataGridView2.Name = "dataGridView2";
            this.dataGridView2.RowTemplate.Height = 23;
            this.dataGridView2.Size = new System.Drawing.Size(619, 383);
            this.dataGridView2.TabIndex = 1;
            // 
            // toolStrip2
            // 
            this.toolStrip2.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.toolStripButton3,
            this.toolStripButton4});
            this.toolStrip2.Location = new System.Drawing.Point(3, 3);
            this.toolStrip2.Name = "toolStrip2";
            this.toolStrip2.Size = new System.Drawing.Size(619, 25);
            this.toolStrip2.TabIndex = 0;
            this.toolStrip2.Text = "toolStrip2";
            // 
            // toolStripButton3
            // 
            this.toolStripButton3.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
            this.toolStripButton3.Image = ((System.Drawing.Image)(resources.GetObject("toolStripButton3.Image")));
            this.toolStripButton3.ImageTransparentColor = System.Drawing.Color.Magenta;
            this.toolStripButton3.Name = "toolStripButton3";
            this.toolStripButton3.Size = new System.Drawing.Size(23, 22);
            this.toolStripButton3.Text = "toolStripButton3";
            this.toolStripButton3.Click += new System.EventHandler(this.toolStripButton3_Click);
            // 
            // toolStripButton4
            // 
            this.toolStripButton4.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
            this.toolStripButton4.Image = ((System.Drawing.Image)(resources.GetObject("toolStripButton4.Image")));
            this.toolStripButton4.ImageTransparentColor = System.Drawing.Color.Magenta;
            this.toolStripButton4.Name = "toolStripButton4";
            this.toolStripButton4.Size = new System.Drawing.Size(23, 22);
            this.toolStripButton4.Text = "toolStripButton4";
            this.toolStripButton4.Click += new System.EventHandler(this.toolStripButton4_Click);
            // 
            // 用户管理
            // 
            this.ClientSize = new System.Drawing.Size(633, 439);
            this.Controls.Add(this.tabControl1);
            this.Name = "用户管理";
            this.tabControl1.ResumeLayout(false);
            this.tabPage1.ResumeLayout(false);
            this.tabPage1.PerformLayout();
            ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit();
            this.toolStrip1.ResumeLayout(false);
            this.toolStrip1.PerformLayout();
            this.tabPage2.ResumeLayout(false);
            this.tabPage2.PerformLayout();
            ((System.ComponentModel.ISupportInitialize)(this.dataGridView2)).EndInit();
            this.toolStrip2.ResumeLayout(false);
            this.toolStrip2.PerformLayout();
            this.ResumeLayout(false);

        }


        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            try
            {
                if (this.ds1.HasChanges())
                {
                    this.link1.UpdateDataBase(this.ds1.GetChanges(), sendTableName1);
                    MessageBox.Show("数据修改成功!", "信息");
                }
                else
                {
                    MessageBox.Show("没有需要修改的数据!");
                    return;
                }
            }
            catch
            {
                MessageBox.Show("数据保存失败,请确认所有信息输入完整且正确!", "提示");
                return;
            }
        }

        private void toolStripButton2_Click(object sender, EventArgs e)
        {
            int intRowNumber = this.dataGridView1.CurrentCellAddress.Y;
            try
            {
                this.ds1.Tables[0].Rows[intRowNumber].Delete();
                //此处传入只包含被改动过的DataRow的DataSet,减少更新数据量,提高程序性能
                this.link1.UpdateDataBase(this.ds1.GetChanges(), sendTableName1);
                MessageBox.Show("数据删除成功!", "信息");
            }
            catch
            {
                MessageBox.Show("该数据不能删除!", "提示");
                string tempStrSQL = "select * from " + sendTableName1;
                this.link1.SelectDataBase(tempStrSQL, sendTableName1);
                return;
            }
        }

        private void toolStripButton3_Click(object sender, EventArgs e)
        {
            try
            {
                if (this.ds2.HasChanges())
                {
                    this.link2.UpdateDataBase(this.ds2.GetChanges(), sendTableName2);
                    MessageBox.Show("数据修改成功!", "信息");
                }
                else
                {
                    MessageBox.Show("没有需要修改的数据!");
                    return;
                }
            }
            catch
            {
                MessageBox.Show("数据保存失败,请确认所有信息输入完整且正确!", "提示");
                return;
            }
        }

        private void toolStripButton4_Click(object sender, EventArgs e)
        {
            int intRowNumber = this.dataGridView2.CurrentCellAddress.Y; ;
            try
            {
                this.ds2.Tables[0].Rows[intRowNumber].Delete();
                //此处传入只包含被改动过的DataRow的DataSet,减少更新数据量,提高程序性能
                this.link2.UpdateDataBase(this.ds2.GetChanges(), sendTableName2);
                MessageBox.Show("数据删除成功!", "信息");
            }
            catch
            {
                MessageBox.Show("该数据不能删除!", "提示");
                string tempStrSQL = "select * from " + sendTableName2;
                this.link2.SelectDataBase(tempStrSQL, sendTableName2);
                return;
            }
        }

        private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
        {
            button1.Enabled = true;
            comboBox3.Items.Clear();
            comboBox4.Items.Clear();
            bool tag = false;
            foreach (DataRow row in ds.Tables["专业列表"].Rows)
            {
                if (comboBox2.Text.ToString().Trim() == row["专业"].ToString().Trim())
                {
                    //no专业编号
                    no = row["专业编号"].ToString().Trim();
                    foreach (DataRow srow in row.GetChildRows(ts))
                    {
                        tag = true;
                        comboBox3.Items.Add(srow["年级"].ToString());;
                    }
                }
                
            }
            if (tag==false)
            {
                button1.Enabled = false;
                MessageBox.Show("该学院没有任何年级!", "提示");
            }
            
        }

        private void comboBox3_SelectedIndexChanged(object sender, EventArgs e)
        {
            button1.Enabled = true;
            comboBox4.Items.Clear();
            string a = comboBox3.Text.ToString().Trim();
            foreach (DataRow srow in ds.Tables["年级列表"].Rows)
            {
                if (srow["年级"].ToString().Trim() == a && srow["专业编号"].ToString().Trim() == no)
                {
                    if (Convert.ToInt16(srow["班数"])==0)
                    {
                        button1.Enabled = false;
                        MessageBox.Show("该学院没有任何班级!", "提示");
                    }
                    for (int j = 1; j <= Convert.ToInt16(srow["班数"]); j++)
                    {
                        comboBox4.Items.Add(j);
                    }
                    break;
                }
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            string sql = sendStrSQL1;
            if(comboBox1.Text.ToString()!="")
            {
                sql = sendStrSQL1 + " where 工号 like '" + tno + "%'";
            }
            this.ds1 = link1.SelectDataBase(sql, sendTableName1);//创建数据库连接
            this.dataGridView1.DataSource = ds1.Tables[0];
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            foreach (DataRow row in ds.Tables["专业列表"].Rows)
            {
                if (comboBox1.Text.ToString().Trim() == row["专业"].ToString().Trim())
                {
                    //tno专业编号
                    tno = row["专业编号"].ToString().Trim();
                    break;
                }
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string sql = sendStrSQL2;
            string sno=no;
            bool tag = false;
            if (comboBox2.Text.ToString() != "")
            {
                tag = true;
            }
            if (comboBox3.Text.ToString() != "")
            {
                sno = sno + comboBox3.Text.ToString().Trim();
            }
            if (comboBox4.Text.ToString() != "")
            {
                sno =sno + comboBox4.Text.ToString().Trim();
            }
            if (tag==true)
            {
                sql = sendStrSQL2 + " where 学号 like '" + sno + "%'";
            }
            this.ds2 = link2.SelectDataBase(sql, sendTableName2);//创建数据库连接
            this.dataGridView2.DataSource = ds2.Tables[0];
        }

        private void dataGridView1_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
        {
            if (dataGridView1.Columns[e.ColumnIndex].Name == "工号")
            {
                if (e.FormattedValue == null &&
                    String.IsNullOrEmpty(e.FormattedValue.ToString()))
                {
                    dataGridView1.Rows[e.RowIndex].ErrorText =
                        "Company Name must not be empty";
                    e.Cancel = true;
                }
            }

        }

        private void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e)
        {
           
        }
    }
}

⌨️ 快捷键说明

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