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

📄 student.cs

📁 做一个关于学生的教务管理系统
💻 CS
📖 第 1 页 / 共 2 页
字号:
			this.textBox5.TabIndex = 11;
			this.textBox5.Text = "";
			// 
			// label10
			// 
			this.label10.Location = new System.Drawing.Point(8, 160);
			this.label10.Name = "label10";
			this.label10.Size = new System.Drawing.Size(56, 23);
			this.label10.TabIndex = 10;
			this.label10.Text = "学院编号";
			this.label10.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// label9
			// 
			this.label9.Location = new System.Drawing.Point(32, 120);
			this.label9.Name = "label9";
			this.label9.Size = new System.Drawing.Size(32, 23);
			this.label9.TabIndex = 9;
			this.label9.Text = "年龄";
			this.label9.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// label7
			// 
			this.label7.Location = new System.Drawing.Point(8, 80);
			this.label7.Name = "label7";
			this.label7.Size = new System.Drawing.Size(56, 23);
			this.label7.TabIndex = 7;
			this.label7.Text = "学生姓名";
			this.label7.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// label6
			// 
			this.label6.Location = new System.Drawing.Point(24, 40);
			this.label6.Name = "label6";
			this.label6.Size = new System.Drawing.Size(40, 23);
			this.label6.TabIndex = 6;
			this.label6.Text = "学号";
			this.label6.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// StuInfo
			// 
			this.StuInfo.Location = new System.Drawing.Point(72, 208);
			this.StuInfo.Name = "StuInfo";
			this.StuInfo.Size = new System.Drawing.Size(88, 23);
			this.StuInfo.TabIndex = 5;
			this.StuInfo.Text = "录入信息";
			this.StuInfo.Click += new System.EventHandler(this.StuInfo_Click);
			// 
			// comboBox1
			// 
			this.comboBox1.Items.AddRange(new object[] {
														   "学生基本信息表",
														   "学院基本信息表",
														   "学生人数对比1",
														   "学生平均年龄对比",
														   "学生人数对比2"});
			this.comboBox1.Location = new System.Drawing.Point(896, 40);
			this.comboBox1.Name = "comboBox1";
			this.comboBox1.Size = new System.Drawing.Size(121, 20);
			this.comboBox1.TabIndex = 4;
			this.comboBox1.Text = "请选择";
			this.comboBox1.SelectedIndexChanged += new System.EventHandler(this.comboBox1_SelectedIndexChanged);
			// 
			// label1
			// 
			this.label1.BackColor = System.Drawing.Color.Transparent;
			this.label1.ForeColor = System.Drawing.Color.White;
			this.label1.Location = new System.Drawing.Point(832, 48);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(64, 23);
			this.label1.TabIndex = 5;
			this.label1.Text = "切换报表";
			// 
			// Student
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.BackgroundImage = ((System.Drawing.Bitmap)(resources.GetObject("$this.BackgroundImage")));
			this.ClientSize = new System.Drawing.Size(1028, 717);
			this.Controls.AddRange(new System.Windows.Forms.Control[] {
																		  this.groupBox1,
																		  this.label1,
																		  this.comboBox1,
																		  this.groupBox2,
																		  this.crystalReportViewer1});
			this.Name = "Student";
			this.Text = "学生信息报表系统";
			this.groupBox1.ResumeLayout(false);
			this.groupBox2.ResumeLayout(false);
			this.ResumeLayout(false);

		}
		#endregion

		/// <summary>
		/// 应用程序的主入口点。
		/// </summary>
		[STAThread]
		static void Main() 
		{
			Application.Run(new  Student());
		}



		private void comboBox1_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			//获取从comboBox1中选取的字符串
			select = comboBox1.SelectedText.ToString();

			//定义Dataset1类的对象实例myset
			Dataset1 myset = new Dataset1();		
			SqlConnection sqlcnn = new SqlConnection( connectstr );

			string sqlstr = "select * from students";
			SqlDataAdapter myadapter = new SqlDataAdapter(sqlstr,sqlcnn);
			//将从数据库的students表中选出的所有数据放置在myset的名为students表中
			myadapter.Fill(myset,"students");

			sqlstr = "select * from Department";
			SqlDataAdapter myadapter1 = new SqlDataAdapter(sqlstr,sqlcnn);
			//将从数据库的Department表中选出的所有数据放置在myset的名为Department表中
			myadapter1.Fill(myset,"Department");

			//根据选择到的不同字符串对报表的数据进行绑定
			switch ( Int32.Parse(comboBox1.SelectedIndex.ToString()))
			{
				//选择了学生基本信息表	
				case 0 :
				{
					MyRprt1 myrpt = new MyRprt1();
					myrpt.SetDataSource(myset);
					crystalReportViewer1.ReportSource = myrpt;	
					break;
				}
				//选择了学院基本信息表	
				case 1 :
				{
					MyRprt2 myrpt = new MyRprt2();
					myrpt.SetDataSource(myset);
					crystalReportViewer1.ReportSource = myrpt;			
					break;
				}
                //选择了学生人数对比1
				case 2 :
				{
					MyRprt3 myrpt = new MyRprt3();
					myrpt.SetDataSource(myset);
					crystalReportViewer1.ReportSource = myrpt;	
					break;
				}
                //选择了学生平均年龄对比
				case 3 :
				{
					MyRprt4 myrpt = new MyRprt4();
					myrpt.SetDataSource(myset);
					crystalReportViewer1.ReportSource = myrpt;	
					break;
				}
                //选择了学生人数对比2
				case 4 :
				{
					MyRprt5 myrpt = new MyRprt5();
					myrpt.SetDataSource(myset);
					crystalReportViewer1.ReportSource = myrpt;	
					break;
				}
			}
			  
		}

		private void DepInfo_Click(object sender, System.EventArgs e)
		{
			int Dep_Num;
			string Dep_Name;
			string Dep_Head;

			//判断必须输入的信息已输入之后在给变量赋值
			if( (textBox1.Text!="") && (textBox2.Text!="") && (textBox3.Text!=""))
			{
				Dep_Num = Int32.Parse(textBox1.Text);
				Dep_Name = textBox2.Text;
				Dep_Head = textBox3.Text;
			}
			else
			{
				MessageBox.Show("请输入完整的信息!");
				return;
			}
			
			string Dep_Des = textBox4.Text;
			//向数据库中插入一条记录的语句
			string sql = String.Format("insert into Department (Dep_Number,Dep_Name,Dep_Head,Dep_Des) values ({0},'{1}','{2}','{3}')",Dep_Num,Dep_Name,Dep_Head,Dep_Des);
			SqlConnection sqlcnn = new SqlConnection( connectstr );
			try
			{
				//打开数据库
				sqlcnn.Open();
				SqlCommand cmd = new SqlCommand(sql, sqlcnn);
				//执行插入操作,并返回受影响的行数
				int i = cmd.ExecuteNonQuery();
				//如果受影响的行数小于一则说明操作失败了
				if ( i<1 )
					MessageBox.Show("操作失败!");
				//关闭数据库
				sqlcnn.Close();
			}
			catch(Exception er)
			{
				string temp = er.Message.ToString();
				return;
			}
			MessageBox.Show("录入成功!");
		}

		private void StuInfo_Click(object sender, System.EventArgs e)
		{
			string Stu_Number;
			string Stu_Name;
			int Stu_Age;
			int Dep_Number;

			//判断必须输入的信息已输入之后在给变量赋值
			if( (textBox5.Text!="") && (textBox6.Text!="") && (textBox8.Text!="") &&(textBox9.Text!=""))
			{
				Stu_Number = textBox5.Text;
				Stu_Name = textBox6.Text;
				Stu_Age = Int32.Parse(textBox8.Text);
				Dep_Number = Int32.Parse(textBox9.Text);
			}
			else
			{
				MessageBox.Show("请输入完整的信息!");
				return;
			}
			
			string check = String.Format("select Dep_Number from Department where Dep_Number={0}", Dep_Number);
			string sql = String.Format("insert into Students (Stu_Number,Stu_Name,Stu_Age,Dep_Number) values ('{0}','{1}',{2},{3})",Stu_Number,Stu_Name,Stu_Age,Dep_Number);

			SqlConnection sqlcnn = new SqlConnection( connectstr );
			try
			{
				sqlcnn.Open();
				SqlCommand cmd = new SqlCommand(check, sqlcnn);
				//查询Dep_Number表中是否存在当前要录入的学生所在的学院
				SqlDataReader MyDataReader = cmd.ExecuteReader();				
				if ( !MyDataReader.Read() )
				{
					MessageBox.Show("目前还没有这个学院!");
					MyDataReader.Close();
                    sqlcnn.Close();
					return;
				}
				MyDataReader.Close();

				SqlCommand cmd1 = new SqlCommand(sql, sqlcnn);
				//执行插入操作,并返回受影响的行数
				int j = cmd1.ExecuteNonQuery();
				//如果受影响的行数小于一则说明操作失败了
				if ( j<1 )
				{
					MessageBox.Show("操作失败!");
					sqlcnn.Close();
				}
				sqlcnn.Close();
			}
			catch(Exception er)
			{
				string temp = er.Message.ToString();
				sqlcnn.Close();
				return;
			}
			MessageBox.Show("录入成功!");
		}
	}
}

⌨️ 快捷键说明

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