第一学年项目在网上复制的代码不会用求大佬解答!
if (txtSfz.Text.Length>=18)
{
string state = "";
string num = txtSfz.Text;
if (num != "")
{
string d = "";
TimeSpan ts = new TimeSpan();
DateTime dt = new DateTime();
if (num.Length == 18)
{
d = num.Substring(6, 8);
dt = DateTime.ParseExact(d, "yyyyMMdd", null);
}
ts = DateTime.Now.Subtract(dt);
DateTime now = DateTime.Now;
if ((now.Year - dt.Year) > 18)
{
state = "已成年,未纳入防沉迷系统";
frmZhuYe f = new frmZhuYe();
f.Tag = Id;
string lj = "server=.;database=XiangMu;uid=sa;pwd=ok";
SqlConnection tz = new SqlConnection(lj);
try
{
tz.Open();
string ID = Id;
string ml = @"update Computer
set OnlineStatus = '1'
where ComputerCode = '" + ID + "'";
SqlCommand zx = new SqlCommand(ml, tz);
int jg = zx.ExecuteNonQuery();
if (jg > 0)
{
zx.CommandText = @"insert Sfz values('" + txtSfz.Text + "')";
int Sfz = zx.ExecuteNonQuery();
if (Sfz > 0)
{
MessageBox.Show("开机成功!", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "异常", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
finally
{
tz.Close();
}
}
if (now.Month >= dt.Month && now.Day >= dt.Day)
{
state = "已成年,未纳入防沉迷系统";
MessageBox.Show(state);
}
else
{
state = "未成年,纳入防沉迷系统";
MessageBox.Show(state);
}
//state = ts.ToString();
}
return;
}
else
{
MessageBox.Show("身份证不足十八位!请重新输入!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
}