message_fm.cs
来自「招聘考试成绩管理系统,自己做的,C#的,我的软件工程作业」· CS 代码 · 共 535 行 · 第 1/2 页
CS
535 行
this.label10.Size = new System.Drawing.Size(160, 23);
this.label10.TabIndex = 18;
this.label10.Text = "电话格式为0571-86846666";
this.label10.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// btreset
//
this.btreset.Location = new System.Drawing.Point(312, 304);
this.btreset.Name = "btreset";
this.btreset.TabIndex = 19;
this.btreset.Text = "清空";
this.btreset.Click += new System.EventHandler(this.btreset_Click);
//
// message_fm
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(560, 382);
this.Controls.Add(this.btreset);
this.Controls.Add(this.label10);
this.Controls.Add(this.label9);
this.Controls.Add(this.radioButton2);
this.Controls.Add(this.radioButton1);
this.Controls.Add(this.tbTel);
this.Controls.Add(this.tbIdCard);
this.Controls.Add(this.tbAdds);
this.Controls.Add(this.tbBirthday);
this.Controls.Add(this.tbZno);
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.tbName);
this.Controls.Add(this.btok);
this.Controls.Add(this.label1);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.SizableToolWindow;
this.Location = new System.Drawing.Point(-100, -100);
this.Name = "message_fm";
this.Text = "输入考生信息";
this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
this.ResumeLayout(false);
}
#endregion
private void btreset_Click(object sender, System.EventArgs e)
{
for(int i=0;i<this.Controls.Count-1;i++)
{
if(this.Controls[i] is TextBox)
this.Controls[i].Text="";
}
this.radioButton1.Checked=true;
}
private void tbName_Leave(object sender, System.EventArgs e)
{
}
private void tbZno_Leave(object sender, System.EventArgs e)
{
string s = this.tbZno.Text.Trim();
if(s.Length !=6 && s.Length >0)
{
MessageBox.Show("准考证号码不能为空并是6位数字");
this.tbZno.Text="";
this.tbZno.Focus();
return;
}
for(int i=0;i<s.Length;i++)
{
if(num.IndexOf(s.Substring(i,1))<0)
{
MessageBox.Show("准考证是6位的数字");
this.tbZno.Text="";
this.tbZno.Focus();
break;
}
}
}
private void tbIdCard_Leave(object sender, System.EventArgs e)
{
int yy,mm,dd;
string s=tbIdCard.Text.Trim();
if(this.tbIdCard.Text.Length==18)
{
int y,x=0;bool t=true;
x = Convert.ToInt32(s.Substring(0,1))*7;
x += Convert.ToInt32(s.Substring(1,1))*9;
x += Convert.ToInt32(s.Substring(2,1))*10;
x += Convert.ToInt32(s.Substring(3,1))*5;
x += Convert.ToInt32(s.Substring(4,1))*8;
x += Convert.ToInt32(s.Substring(5,1))*4;
x += Convert.ToInt32(s.Substring(6,1))*2;
x += Convert.ToInt32(s.Substring(7,1))*1;
x += Convert.ToInt32(s.Substring(8,1))*6;
x += Convert.ToInt32(s.Substring(9,1))*3;
x += Convert.ToInt32(s.Substring(10,1))*7;
x += Convert.ToInt32(s.Substring(11,1))*9;
x += Convert.ToInt32(s.Substring(12,1))*10;
x += Convert.ToInt32(s.Substring(13,1))*5;
x += Convert.ToInt32(s.Substring(14,1))*8;
x += Convert.ToInt32(s.Substring(15,1))*4;
x += Convert.ToInt32(s.Substring(16,1))*2;
y = (12 - x % 11) % 11;
if(y==10 && (s.Substring(17,1)=="x" || s.Substring(17,1)=="X"))
t=false;
else if( y == Convert.ToInt32(s.Substring(17,1)))
t=false;
if(t==true)
{
MessageBox.Show("身份证号码输入有误");
this.tbIdCard.Text="";
this.tbIdCard.Focus();
}
else
{
this.tbBirthday.Text=s.Substring(6,4)+"/"+s.Substring(10,2)+"/"+s.Substring(12,2);
if(Convert.ToInt32(s.Substring(16,1))%2==1)
this.radioButton1.Checked = true;
else
this.radioButton2.Checked = true;
}
}
else if(this.tbIdCard.Text.Length==15)
{
for(int i=0;i<15;i++)
{
if(num.IndexOf(s.Substring(i,1))<0)
{
MessageBox.Show("请检查您输入的身份证号号码!");
this.tbIdCard.Text="";
this.tbIdCard.Focus();
break;
}
}
yy=1900 +int.Parse(s.Substring(6,2));
mm = int.Parse(s.Substring(8, 2));
dd = int.Parse(s.Substring(10, 2));
try
{
new DateTime(yy, mm, dd);
}
catch (Exception err)
{
MessageBox.Show("请检查您输入的身份证号号码!");
this.tbIdCard.Text="";
this.tbIdCard.Focus();
}
this.tbBirthday.Text=s.Substring(6,2)+"/"+s.Substring(8,2)+"/"+s.Substring(10,2);
if(Convert.ToInt32(s.Substring(16,1))%2==1)
this.radioButton1.Checked = true;
else
this.radioButton2.Checked = true;
}
else if(this.tbIdCard.Text.Trim() != "")
{
MessageBox.Show("请检查您输入的身份证号号码!");
this.tbIdCard.Text="";
this.tbIdCard.Focus();
}
}
private void btok_Click(object sender, System.EventArgs e)
{
for(int i=0; i<this.Controls.Count; i++)
{
if(this.Controls[i] is TextBox)
{
if(this.Controls[i].Tag == null || this.Controls[i].Tag.ToString() != "Y")continue;
if((this.Controls[i] as TextBox).Text.Trim().Length<1)
{
MessageBox.Show(this.Controls[i].AccessibleDescription);
this.Controls[i].Focus();
return;
}
}
}
string SQL ="select Zno from student where Zno =";
SQL+=tbZno.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
{
/*string zno=this.tbZno.Text.Trim();
string name=this.tbName.Text.Trim();
string sex="男";
string bir=this.tbBirthday.Text.Trim();
string adress=this.tbAdds.Text.Trim();
string idc=this.tbIdCard.Text.Trim();
string tel=this.tbTel.Text.Trim();*/
myCon =new SqlConnection(myConstr);
myCon.Open();
myCom =new SqlCommand(SQL,myCon);
myCom=new SqlCommand(SQL,myCon);
int power=Convert.ToInt32(myCom.ExecuteScalar());
//myCon.Close();
if(power<=0)
{
/*myCon.ConnectionString=myConstr;
string sql="insert student values(@zno,@name,@sex,@bir,@adress,@idc,@tel)";
SqlCommand cmd=new SqlCommand(sql,myCon);
cmd.Parameters.Add(new SqlParameter("@zno",zno));
cmd.Parameters.Add(new SqlParameter("@name",name));
cmd.Parameters.Add(new SqlParameter("@sex",sex));
cmd.Parameters.Add(new SqlParameter("@bir",bir));
cmd.Parameters.Add(new SqlParameter("@adress",adress));
cmd.Parameters.Add(new SqlParameter("@idc",idc));
cmd.Parameters.Add(new SqlParameter("@tel",tel));
myCon.Open();
cmd.ExecuteNonQuery();*/
SQL="insert into student Values ('"+this.tbZno.Text;
if(this.radioButton1.Checked==true)
SQL+="','"+this.tbName.Text+"','男','"+this.tbBirthday.Text;
else
SQL+="','"+this.tbName.Text+"','女','"+this.tbBirthday.Text;
SQL+="','"+this.tbAdds.Text+"','"+this.tbIdCard.Text+"','"+this.tbTel.Text+"');";
myCom.CommandText=SQL;
myCom.ExecuteNonQuery();
MessageBox.Show("提交成功");
}
else
{
MessageBox.Show("此人信息已经存在");
}
}
catch(Exception o)
{
this.tbAdds.Text=o.Message;
MessageBox.Show(o.Message,"error");
}
finally
{
if(myCon.State==ConnectionState.Open)
myCon.Close();
}
}
private void tbTel_Leave(object sender, System.EventArgs e)
{
string s=this.tbTel.Text;
for(int i=0;i<s.Length;i++)
{
if(n.IndexOf(s.Substring(i,1))<0)
{
MessageBox.Show("电话号码不能有字母!");
this.tbTel.Text="";
this.tbTel.Focus();
break;
}
}
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?