fmmark.cs

来自「招聘考试成绩管理系统,自己做的,C#的,我的软件工程作业」· CS 代码 · 共 330 行

CS
330
字号
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;

namespace 招聘考试成绩管理系统
{
	/// <summary>
	/// FMmark 的摘要说明。
	/// </summary>
	public class FMmark : System.Windows.Forms.Form
	{
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.Label label3;
		private System.Windows.Forms.Label label4;
		private System.Windows.Forms.Button btok;
		private System.Windows.Forms.TextBox txtenglish;
		private System.Windows.Forms.Button btreset;
		private System.Windows.Forms.TextBox txtchinese;
		private System.Windows.Forms.TextBox txtpoli;
		private System.Windows.Forms.Label label5;
		private System.Windows.Forms.TextBox txtzhunkaozheng;
		/// <summary>
		/// 必需的设计器变量。
		/// </summary>
		private System.ComponentModel.Container components = null;

		public FMmark()
		{
			//
			// Windows 窗体设计器支持所必需的
			//
			InitializeComponent();

			//
			// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
			//
		}

		/// <summary>
		/// 清理所有正在使用的资源。
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows 窗体设计器生成的代码
		/// <summary>
		/// 设计器支持所需的方法 - 不要使用代码编辑器修改
		/// 此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{
			this.btok = new System.Windows.Forms.Button();
			this.label1 = new System.Windows.Forms.Label();
			this.txtenglish = new System.Windows.Forms.TextBox();
			this.label2 = new System.Windows.Forms.Label();
			this.label3 = new System.Windows.Forms.Label();
			this.label4 = new System.Windows.Forms.Label();
			this.btreset = new System.Windows.Forms.Button();
			this.txtchinese = new System.Windows.Forms.TextBox();
			this.txtpoli = new System.Windows.Forms.TextBox();
			this.label5 = new System.Windows.Forms.Label();
			this.txtzhunkaozheng = new System.Windows.Forms.TextBox();
			this.SuspendLayout();
			// 
			// btok
			// 
			this.btok.Location = new System.Drawing.Point(96, 272);
			this.btok.Name = "btok";
			this.btok.TabIndex = 5;
			this.btok.Tag = "0";
			this.btok.Text = "确定";
			this.btok.Click += new System.EventHandler(this.btok_Click);
			// 
			// label1
			// 
			this.label1.Font = new System.Drawing.Font("华文楷体", 14.25F, System.Drawing.FontStyle.Bold);
			this.label1.Location = new System.Drawing.Point(128, 24);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(296, 23);
			this.label1.TabIndex = 1;
			this.label1.Tag = "0";
			this.label1.Text = "输入考生成绩";
			this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
			// 
			// txtenglish
			// 
			this.txtenglish.Location = new System.Drawing.Point(176, 120);
			this.txtenglish.Name = "txtenglish";
			this.txtenglish.Size = new System.Drawing.Size(200, 21);
			this.txtenglish.TabIndex = 2;
			this.txtenglish.Tag = "*请输入正确的英语成绩";
			this.txtenglish.Text = "";
			this.txtenglish.Leave += new System.EventHandler(this.txtpoli_Leave);
			// 
			// label2
			// 
			this.label2.Location = new System.Drawing.Point(56, 120);
			this.label2.Name = "label2";
			this.label2.TabIndex = 3;
			this.label2.Text = "英语:";
			this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// label3
			// 
			this.label3.Location = new System.Drawing.Point(56, 160);
			this.label3.Name = "label3";
			this.label3.TabIndex = 4;
			this.label3.Text = "语文:";
			this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// label4
			// 
			this.label4.Location = new System.Drawing.Point(56, 208);
			this.label4.Name = "label4";
			this.label4.TabIndex = 5;
			this.label4.Text = "政治:";
			this.label4.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// btreset
			// 
			this.btreset.Location = new System.Drawing.Point(328, 272);
			this.btreset.Name = "btreset";
			this.btreset.TabIndex = 0;
			this.btreset.Tag = "0";
			this.btreset.Text = "重置";
			this.btreset.Click += new System.EventHandler(this.btreset_Click);
			// 
			// txtchinese
			// 
			this.txtchinese.Location = new System.Drawing.Point(176, 160);
			this.txtchinese.Name = "txtchinese";
			this.txtchinese.Size = new System.Drawing.Size(200, 21);
			this.txtchinese.TabIndex = 3;
			this.txtchinese.Tag = "*请输入正确的语文成绩";
			this.txtchinese.Text = "";
			this.txtchinese.Leave += new System.EventHandler(this.txtpoli_Leave);
			// 
			// txtpoli
			// 
			this.txtpoli.Location = new System.Drawing.Point(176, 206);
			this.txtpoli.Name = "txtpoli";
			this.txtpoli.Size = new System.Drawing.Size(200, 21);
			this.txtpoli.TabIndex = 4;
			this.txtpoli.Tag = "*请输入正确的政治成绩";
			this.txtpoli.Text = "";
			this.txtpoli.Leave += new System.EventHandler(this.txtpoli_Leave);
			// 
			// label5
			// 
			this.label5.Location = new System.Drawing.Point(56, 80);
			this.label5.Name = "label5";
			this.label5.TabIndex = 6;
			this.label5.Text = "准考证号:";
			this.label5.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// txtzhunkaozheng
			// 
			this.txtzhunkaozheng.Location = new System.Drawing.Point(176, 80);
			this.txtzhunkaozheng.Name = "txtzhunkaozheng";
			this.txtzhunkaozheng.Size = new System.Drawing.Size(200, 21);
			this.txtzhunkaozheng.TabIndex = 1;
			this.txtzhunkaozheng.Tag = "*请输入正确的准考证";
			this.txtzhunkaozheng.Text = "";
			this.txtzhunkaozheng.Leave += new System.EventHandler(this.zno_Leave);
			// 
			// FMmark
			// 
			this.AcceptButton = this.btok;
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.ClientSize = new System.Drawing.Size(560, 374);
			this.Controls.Add(this.txtzhunkaozheng);
			this.Controls.Add(this.label5);
			this.Controls.Add(this.txtpoli);
			this.Controls.Add(this.txtchinese);
			this.Controls.Add(this.btreset);
			this.Controls.Add(this.label4);
			this.Controls.Add(this.label3);
			this.Controls.Add(this.label2);
			this.Controls.Add(this.txtenglish);
			this.Controls.Add(this.label1);
			this.Controls.Add(this.btok);
			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
			this.Name = "FMmark";
			this.Tag = "0";
			this.Text = "输入成绩信息";
			this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
			this.ResumeLayout(false);

		}
		#endregion

		private void btok_Click(object sender, System.EventArgs e)
		{
			if(this.txtzhunkaozheng.Text.Trim()=="")
			{
				MessageBox.Show("准考证不能为空");
				this.txtzhunkaozheng.Focus();
				return;
			}
			if(this.txtchinese.Text.Trim()=="")
			{
				MessageBox.Show("成绩不能为空");
				this.txtzhunkaozheng.Focus();
					return;
			}
			if(this.txtenglish.Text.Trim()=="")
			{
				MessageBox.Show("成绩不能为空");
				this.txtzhunkaozheng.Focus();
				return;
			}
			if(this.txtpoli.Text.Trim()=="")
			{
				MessageBox.Show("成绩不能为空");
				this.txtzhunkaozheng.Focus();
				return;
			}
			string SQL ="select Zno from student where Zno =";
			SQL+=this.txtzhunkaozheng.Text;
			string myConstr ="workstation id=\"GHX-82E19EF0633\";packet size=4096;integrated security=SSPI;data s" +
				"ource=\".\";persist security info=False;initial catalog=zhaopin";
			SqlCommand myCom= null;
			SqlConnection myCon=null;
			try
			{
				myCon =new SqlConnection(myConstr);
				myCon.Open();
				myCom =new SqlCommand(SQL,myCon);				
				int power=Convert.ToInt32(myCom.ExecuteScalar());
				if(power<=0)
				{
					MessageBox.Show("不存在此考生");
					return;
				}
				myCom.CommandText=SQL;
				power=Convert.ToInt32(myCom.ExecuteScalar());
				if(power<=0)
				{
					SQL="insert into mark Values ('"+this.txtzhunkaozheng.Text;
					SQL+="','"+Convert.ToInt32(this.txtenglish.Text)+"','"+Convert.ToInt32(this.txtchinese.Text)+"','"+Convert.ToInt32(this.txtpoli.Text)+"');";					
					myCom.CommandText=SQL;
					myCom.ExecuteNonQuery();
					MessageBox.Show("提交成功");
				}
				else
				{
					MessageBox.Show("此人成绩信息已经存在");
				}
			}
			catch(Exception o)
			{
				MessageBox.Show(o.Message,"error");
				
			}
			finally
			{
				if(myCon.State==ConnectionState.Open)
					myCon.Close();
			}
		}

		private void btreset_Click(object sender, System.EventArgs e)
		{
			int i;
			for(i=0;i<this.Controls.Count;i++)
			{
				
					if(this.Controls[i] is TextBox)
						this.Controls[i].Text="";
			}
			
		}
		private void txtpoli_Leave(object sender, System.EventArgs e)
		{
			int t;
			if((sender as TextBox).Text.Trim() !="")
			{
				t=Convert.ToInt32((sender as TextBox).Text.Trim());
				if(t<0 || t>100)
				{
					MessageBox.Show("成绩输入错误");
					(sender as TextBox).Text="";
					(sender as TextBox).Focus();
				}
				}
			/*if((sender as TextBox).Text=="")
			{
				MessageBox.Show((sender as TextBox).Tag.ToString());
				(sender as TextBox).Focus();
				return;
			}
			int i=0;
			if((sender as TextBox).Name=="txtpoli")
			{
				for(i=0;i<this.Controls.Count;i++)
				{
					if(this.Controls[i] is TextBox&&this.Controls[i].Text.Trim()=="")
					{
						MessageBox.Show(this.Controls[i].Tag.ToString());
						break;
					}
				}
			}
			if(i==this.Controls.Count)
			;*/
				
		}

		private void zno_Leave(object sender, System.EventArgs e)
		{
		
		}

	}
}

⌨️ 快捷键说明

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