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

📄 addstudent.cs

📁 C#编写的学籍管理系统
💻 CS
📖 第 1 页 / 共 2 页
字号:
			this.textBox6.Size = new System.Drawing.Size(171, 25);
			this.textBox6.TabIndex = 15;
			this.textBox6.Text = "";
			// 
			// textBox8
			// 
			this.textBox8.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.textBox8.ForeColor = System.Drawing.SystemColors.ControlText;
			this.textBox8.Location = new System.Drawing.Point(425, 123);
			this.textBox8.Name = "textBox8";
			this.textBox8.Size = new System.Drawing.Size(171, 25);
			this.textBox8.TabIndex = 17;
			this.textBox8.Text = "";
			// 
			// textBox10
			// 
			this.textBox10.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.textBox10.ForeColor = System.Drawing.SystemColors.ControlText;
			this.textBox10.Location = new System.Drawing.Point(116, 247);
			this.textBox10.Multiline = true;
			this.textBox10.Name = "textBox10";
			this.textBox10.Size = new System.Drawing.Size(340, 82);
			this.textBox10.TabIndex = 19;
			this.textBox10.Text = "";
			// 
			// button1
			// 
			this.button1.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.button1.ForeColor = System.Drawing.SystemColors.ControlText;
			this.button1.Location = new System.Drawing.Point(116, 344);
			this.button1.Name = "button1";
			this.button1.Size = new System.Drawing.Size(75, 31);
			this.button1.TabIndex = 20;
			this.button1.Text = "确定";
			this.button1.Click += new System.EventHandler(this.button1_Click);
			// 
			// button2
			// 
			this.button2.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.button2.ForeColor = System.Drawing.SystemColors.ControlText;
			this.button2.Location = new System.Drawing.Point(415, 344);
			this.button2.Name = "button2";
			this.button2.Size = new System.Drawing.Size(74, 31);
			this.button2.TabIndex = 21;
			this.button2.Text = "取消";
			this.button2.Click += new System.EventHandler(this.button2_Click);
			// 
			// oleDbConnection1
			// 
			this.oleDbConnection1.ConnectionString = "Data Source=xsxxdb.mdb;Jet OLEDB:Engine Type=5;Provider=Microsoft.Jet." +
				"OLEDB.4.0;";
			// 
			// label11
			// 
			this.label11.AutoSize = true;
			this.label11.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.label11.ForeColor = System.Drawing.SystemColors.ControlText;
			this.label11.Location = new System.Drawing.Point(265, 10);
			this.label11.Name = "label11";
			this.label11.Size = new System.Drawing.Size(98, 21);
			this.label11.TabIndex = 22;
			this.label11.Text = "添加学生信息";
			// 
			// comboBox1
			// 
			this.comboBox1.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
			this.comboBox1.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.comboBox1.ForeColor = System.Drawing.SystemColors.ControlText;
			this.comboBox1.Items.AddRange(new object[] {
														   "男",
														   "女"});
			this.comboBox1.Location = new System.Drawing.Point(116, 123);
			this.comboBox1.Name = "comboBox1";
			this.comboBox1.Size = new System.Drawing.Size(96, 23);
			this.comboBox1.TabIndex = 23;
			// 
			// comboBox2
			// 
			this.comboBox2.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
			this.comboBox2.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.comboBox2.ForeColor = System.Drawing.SystemColors.ControlText;
			this.comboBox2.Items.AddRange(new object[] {
														   "党员",
														   "团员",
														   "群众"});
			this.comboBox2.Location = new System.Drawing.Point(425, 82);
			this.comboBox2.Name = "comboBox2";
			this.comboBox2.Size = new System.Drawing.Size(96, 23);
			this.comboBox2.TabIndex = 24;
			// 
			// comboBox3
			// 
			this.comboBox3.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
			this.comboBox3.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.comboBox3.ForeColor = System.Drawing.SystemColors.ControlText;
			this.comboBox3.Location = new System.Drawing.Point(425, 165);
			this.comboBox3.Name = "comboBox3";
			this.comboBox3.Size = new System.Drawing.Size(171, 23);
			this.comboBox3.TabIndex = 25;
			this.comboBox3.SelectedIndexChanged += new System.EventHandler(this.comboBox3_SelectedIndexChanged);
			// 
			// comboBox4
			// 
			this.comboBox4.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
			this.comboBox4.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.comboBox4.ForeColor = System.Drawing.SystemColors.ControlText;
			this.comboBox4.Location = new System.Drawing.Point(425, 206);
			this.comboBox4.Name = "comboBox4";
			this.comboBox4.Size = new System.Drawing.Size(171, 23);
			this.comboBox4.TabIndex = 26;
			// 
			// label12
			// 
			this.label12.AutoSize = true;
			this.label12.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.label12.ForeColor = System.Drawing.SystemColors.ControlText;
			this.label12.Location = new System.Drawing.Point(367, 165);
			this.label12.Name = "label12";
			this.label12.Size = new System.Drawing.Size(36, 21);
			this.label12.TabIndex = 27;
			this.label12.Text = "专业";
			// 
			// label13
			// 
			this.label13.AutoSize = true;
			this.label13.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.label13.ForeColor = System.Drawing.SystemColors.ControlText;
			this.label13.Location = new System.Drawing.Point(464, 248);
			this.label13.Name = "label13";
			this.label13.Size = new System.Drawing.Size(36, 21);
			this.label13.TabIndex = 28;
			this.label13.Text = "照片";
			// 
			// pictureBox1
			// 
			this.pictureBox1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
			this.pictureBox1.Location = new System.Drawing.Point(504, 240);
			this.pictureBox1.Name = "pictureBox1";
			this.pictureBox1.Size = new System.Drawing.Size(88, 96);
			this.pictureBox1.TabIndex = 29;
			this.pictureBox1.TabStop = false;
			this.pictureBox1.Click += new System.EventHandler(this.pictureBox1_Click);
			// 
			// AddStudent
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(8, 18);
			this.ClientSize = new System.Drawing.Size(661, 386);
			this.Controls.Add(this.pictureBox1);
			this.Controls.Add(this.label13);
			this.Controls.Add(this.label12);
			this.Controls.Add(this.label11);
			this.Controls.Add(this.textBox10);
			this.Controls.Add(this.textBox8);
			this.Controls.Add(this.textBox6);
			this.Controls.Add(this.textBox5);
			this.Controls.Add(this.textBox4);
			this.Controls.Add(this.textBox2);
			this.Controls.Add(this.textBox1);
			this.Controls.Add(this.label10);
			this.Controls.Add(this.label9);
			this.Controls.Add(this.label8);
			this.Controls.Add(this.label7);
			this.Controls.Add(this.label6);
			this.Controls.Add(this.label5);
			this.Controls.Add(this.label4);
			this.Controls.Add(this.label3);
			this.Controls.Add(this.label2);
			this.Controls.Add(this.label1);
			this.Controls.Add(this.comboBox4);
			this.Controls.Add(this.comboBox3);
			this.Controls.Add(this.comboBox2);
			this.Controls.Add(this.comboBox1);
			this.Controls.Add(this.button2);
			this.Controls.Add(this.button1);
			this.Name = "AddStudent";
			this.Text = "添加学生";
			this.Load += new System.EventHandler(this.tjxs_Load);
			this.Closed += new System.EventHandler(this.tjxs_Closed);
			this.ResumeLayout(false);

		}
		#endregion

		private Byte[] getphoto(string photopath)
		{
			string   str=photopath;
			FileStream   file   =     new   FileStream(str,FileMode.Open,   FileAccess.Read);
			Byte[]   bytBLOBData   =   new   Byte[file.Length];   
			file.Read(bytBLOBData,   0,   bytBLOBData.Length);
			file.Close();
			return bytBLOBData;
		}

		private void button1_Click(object sender, System.EventArgs e)
		{
			if (textBox1.Text.Trim()=="" || textBox2.Text.Trim()=="" || comboBox1.Text.Trim()=="" || textBox4.Text.Trim()=="" || textBox5.Text.Trim()=="" || textBox6.Text.Trim()=="" || comboBox2.Text.Trim()=="" || textBox8.Text.Trim()=="" ||  comboBox4.Text.Trim()=="")
				MessageBox(0,"请填写完整的学生信息","提示",0);
			else
			{
				OleDbCommand cmd=new OleDbCommand("select * from studentinfo where StudentNumber='"+textBox1.Text.Trim()+"'",oleDbConnection1);
				if (null!=cmd.ExecuteScalar())
				    MessageBox(0,"学生学号重复","提示",0);
			    else
			    {
					string sql1,sql2,sql;
					sql1="insert into studentinfo (StudentNumber,name,sex,race,address,telephone,role,postalcode,classid";
					sql2="values ('"+textBox1.Text.ToString()+"','"+textBox2.Text.ToString()+"','"+comboBox1.Text.Trim()+"','"+textBox4.Text.ToString()+"','"+textBox5.Text.ToString()+"','"+textBox6.Text.ToString()+"','"+comboBox2.Text.Trim()+"','"+textBox8.Text.ToString()+"',"+comboBox4.SelectedValue.ToString();
					if (textBox10.Text.Trim()!="")
					{ 
						sql1=sql1+",remark";
						sql2=sql2+",'"+textBox10.Text.Trim()+"'";
					}
					if (this.pictureBox1.Image!=null)
					{
						sql1=sql1+",Photo";
						sql2=sql2+",?";
						Byte[]   bytBLOBData=getphoto(openFileDialog1.FileName);
						cmd.Parameters.Add(new   OleDbParameter("jpeg",OleDbType.Binary,bytBLOBData.Length,ParameterDirection.Input,true,0,0,null,DataRowVersion.Default,bytBLOBData));
					}
                    sql=sql1+") "+sql2+")";
					cmd.CommandText=sql;
					cmd.ExecuteNonQuery();
                    MessageBox(0,"学生信息添加成功","提示",0);
			    }
			}

		}

		private void tjxs_Load(object sender, System.EventArgs e)
		{
			oleDbConnection1.Open();
			OleDbDataAdapter adp=new OleDbDataAdapter("select specialtyname from specialtyinfo",oleDbConnection1);
			DataSet ds=new DataSet();
			adp.Fill(ds,"specialty");
			comboBox3.DisplayMember="specialtyname";
			comboBox3.ValueMember="specialtyname";
			comboBox3.DataSource=ds.Tables[0].DefaultView;
		}

		private void comboBox3_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			if (comboBox3.Text.Trim()!="")
			{
				OleDbDataAdapter adp=new OleDbDataAdapter("select classid,classname from classinfo where specialtyname='"+comboBox3.Text.Trim()+"'",oleDbConnection1);
				DataSet ds=new DataSet();
				adp.Fill(ds,"class");
				comboBox4.DisplayMember="classname";
				comboBox4.ValueMember="classid";
				comboBox4.DataSource=ds.Tables[0].DefaultView;
			}
		}

		private void button2_Click(object sender, System.EventArgs e)
		{
			this.Close();
		}

		private void tjxs_Closed(object sender, System.EventArgs e)
		{
			oleDbConnection1.Close();
		}

		private void pictureBox1_Click(object sender, System.EventArgs e)
		{
			openFileDialog1.Filter="bmp|*.bmp|gif|*.gif|jpg|*jpg|jpeg|*.jpeg|ico|*.ico";
			openFileDialog1.ShowDialog();
			
			if (openFileDialog1.FileName!="")
				this.pictureBox1.Image=Image.FromFile(openFileDialog1.FileName);
		}

	}
}

⌨️ 快捷键说明

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