📄 newstu.cs
字号:
this.Stu_position.Location = new System.Drawing.Point(104, 192);
this.Stu_position.Name = "Stu_position";
this.Stu_position.Size = new System.Drawing.Size(112, 21);
this.Stu_position.TabIndex = 21;
this.Stu_position.Text = "";
//
// Stu_idnum
//
this.Stu_idnum.Location = new System.Drawing.Point(304, 160);
this.Stu_idnum.Name = "Stu_idnum";
this.Stu_idnum.Size = new System.Drawing.Size(104, 21);
this.Stu_idnum.TabIndex = 20;
this.Stu_idnum.Text = "";
//
// Stu_politic
//
this.Stu_politic.Location = new System.Drawing.Point(104, 160);
this.Stu_politic.Name = "Stu_politic";
this.Stu_politic.Size = new System.Drawing.Size(112, 21);
this.Stu_politic.TabIndex = 19;
this.Stu_politic.Text = "";
//
// label10
//
this.label10.Location = new System.Drawing.Point(32, 192);
this.label10.Name = "label10";
this.label10.Size = new System.Drawing.Size(72, 23);
this.label10.TabIndex = 18;
this.label10.Text = "职位:";
//
// label11
//
this.label11.Location = new System.Drawing.Point(224, 160);
this.label11.Name = "label11";
this.label11.Size = new System.Drawing.Size(72, 23);
this.label11.TabIndex = 17;
this.label11.Text = "身份证号:";
//
// label12
//
this.label12.Location = new System.Drawing.Point(24, 160);
this.label12.Name = "label12";
this.label12.Size = new System.Drawing.Size(72, 23);
this.label12.TabIndex = 16;
this.label12.Text = "政治面貌:";
//
// InputnewStu
//
this.InputnewStu.Location = new System.Drawing.Point(72, 248);
this.InputnewStu.Name = "InputnewStu";
this.InputnewStu.Size = new System.Drawing.Size(88, 24);
this.InputnewStu.TabIndex = 24;
this.InputnewStu.Text = "录入";
this.InputnewStu.Click += new System.EventHandler(this.InputnewStu_Click);
//
// ExitNStu
//
this.ExitNStu.Location = new System.Drawing.Point(280, 248);
this.ExitNStu.Name = "ExitNStu";
this.ExitNStu.Size = new System.Drawing.Size(88, 24);
this.ExitNStu.TabIndex = 25;
this.ExitNStu.Text = "退出";
this.ExitNStu.Click += new System.EventHandler(this.ExitNStu_Click);
//
// drawbackbutt
//
this.drawbackbutt.Location = new System.Drawing.Point(176, 248);
this.drawbackbutt.Name = "drawbackbutt";
this.drawbackbutt.Size = new System.Drawing.Size(88, 24);
this.drawbackbutt.TabIndex = 26;
this.drawbackbutt.Text = "撤销";
this.drawbackbutt.Click += new System.EventHandler(this.drawbackbutt_Click);
//
// Class
//
this.Class.Location = new System.Drawing.Point(304, 128);
this.Class.Name = "Class";
this.Class.Size = new System.Drawing.Size(104, 20);
this.Class.TabIndex = 27;
//
// ERdateTime
//
this.ERdateTime.Location = new System.Drawing.Point(104, 128);
this.ERdateTime.Name = "ERdateTime";
this.ERdateTime.Size = new System.Drawing.Size(112, 21);
this.ERdateTime.TabIndex = 28;
//
// BirthdateTime
//
this.BirthdateTime.Location = new System.Drawing.Point(304, 64);
this.BirthdateTime.Name = "BirthdateTime";
this.BirthdateTime.Size = new System.Drawing.Size(104, 21);
this.BirthdateTime.TabIndex = 29;
//
// groupBox1
//
this.groupBox1.Location = new System.Drawing.Point(16, 8);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(416, 224);
this.groupBox1.TabIndex = 30;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "学生信息";
//
// groupBox2
//
this.groupBox2.Location = new System.Drawing.Point(16, 232);
this.groupBox2.Name = "groupBox2";
this.groupBox2.Size = new System.Drawing.Size(416, 48);
this.groupBox2.TabIndex = 31;
this.groupBox2.TabStop = false;
//
// NewStu
//
this.AccessibleRole = System.Windows.Forms.AccessibleRole.None;
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(440, 301);
this.Controls.Add(this.BirthdateTime);
this.Controls.Add(this.ERdateTime);
this.Controls.Add(this.Class);
this.Controls.Add(this.drawbackbutt);
this.Controls.Add(this.ExitNStu);
this.Controls.Add(this.InputnewStu);
this.Controls.Add(this.Stu_specialty);
this.Controls.Add(this.Stu_position);
this.Controls.Add(this.Stu_idnum);
this.Controls.Add(this.Stu_politic);
this.Controls.Add(this.Stu_home);
this.Controls.Add(this.Stu_nation);
this.Controls.Add(this.Stu_age);
this.Controls.Add(this.Stu_sex);
this.Controls.Add(this.Stu_name);
this.Controls.Add(this.label9);
this.Controls.Add(this.label10);
this.Controls.Add(this.label11);
this.Controls.Add(this.label12);
this.Controls.Add(this.label5);
this.Controls.Add(this.label6);
this.Controls.Add(this.label7);
this.Controls.Add(this.label8);
this.Controls.Add(this.label4);
this.Controls.Add(this.label3);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Controls.Add(this.groupBox1);
this.Controls.Add(this.groupBox2);
this.Name = "NewStu";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "新学生信息录入";
this.ResumeLayout(false);
}
#endregion
//为班级下拉框填充数据
private void NewStu_Load()
{
DataSet NewStudClassset=new DataSet();
string NewStuStrConnSql="select Class_name from class";
this.NewStuConn=new SqlConnection(this.NewStuStrConn);
this.NewStusqlda=new SqlDataAdapter(NewStuStrConnSql,this.NewStuConn);
NewStudClassset.Clear();
this.NewStusqlda.Fill(NewStudClassset,"Class");
for(int i=0;i<NewStudClassset.Tables[0].Rows.Count;i++)
{
Class.Items.Add(NewStudClassset.Tables[0].Rows[i][0]);
}
Class.SelectedIndex=0;
}
//撤销按钮代码
private void drawbackbutt_Click(object sender, System.EventArgs e)
{
Stu_name.Text="";
Stu_sex.Text="";
Stu_age.Text="";
Stu_home.Text="";
Stu_nation.Text="";
Stu_specialty.Text="";
Stu_position.Text="";
Stu_idnum.Text="";
Stu_politic.Text="";
}
private void ExitNStu_Click(object sender, System.EventArgs e)
{
if(MessageBox.Show("您确认要退出?","确认",MessageBoxButtons.YesNo)==DialogResult.Yes)
this.Close();
}
//输入新学生代码
private void InputnewStu_Click(object sender, System.EventArgs e)
{
try
{
string date=this.ERdateTime.Value.Date.ToString();;
if(date==""||this.Stu_name.Text=="")//保证学生姓名和入学日期必须得到填写
{
MessageBox.Show("学生姓名、入学时间、班级必须填写!","提示");
}
else
{
DataSet NewStudClassset=new DataSet();
//首先需要检索出学生的班级号才可以在学生表中进行插入新记录
string NewStuStrConnSql="select Class_id from class where Class_name="+"'"+this.Class.SelectedItem.ToString().Trim()+"'";
this.NewStuConn=new SqlConnection(this.NewStuStrConn);
this.NewStusqlda=new SqlDataAdapter(NewStuStrConnSql,this.NewStuConn);
NewStudClassset.Clear();
this.NewStusqlda.Fill(NewStudClassset,"Class");
string ClassId=NewStudClassset.Tables[0].Rows[0][0].ToString().Trim();
//检索数据库内是否已经有同名的记录
DataSet NewStu=new DataSet();
string ExStu="select * from student where student_name="+"'"+this.Stu_name.Text.ToString().Trim()+"'"+" and class_id="+"'"+ClassId+"'";
this.NewStuConn=new SqlConnection(this.NewStuStrConn);
this.NewStusqlda=new SqlDataAdapter(ExStu,this.NewStuConn);
NewStu.Clear();
this.NewStusqlda.Fill(NewStu,"student1");
if(NewStu.Tables[0].Rows.Count==0)
{
//在学生表中插入新纪录
NewStuStrComd="insert into student(student_name,sex,Entrance_date,Class_id,Birth,Nation,home,politic,ID,Job,specialty)values"+
"("+"'"+Stu_name.Text.ToString().Trim()+"'"+","+"'"+Stu_sex.Text.ToString().Trim()+"'"+
","+"'"+date+"'"+","+"'"+ClassId+"'"+","+"'"+this.BirthdateTime.Value.Date.ToString()+"'"+","+"'"+
this.Stu_nation.Text.ToString().Trim()+"'"+","+"'"+this.Stu_home.Text.ToString().Trim()+"'"+","+"'"+
this.Stu_politic.Text.ToString().Trim()+"'"+","+"'"+this.Stu_idnum.Text.ToString().Trim()+"'"+","+"'"+this.Stu_position.Text.ToString().Trim()+"'"+","+"'"+this.Stu_specialty.Text.ToString().Trim()+"'"+")";
NewStuConn=new SqlConnection(NewStuStrConn);
NewStuConn.Open();
NewStuComd=new SqlCommand(NewStuStrComd,NewStuConn);
int Succnum=NewStuComd.ExecuteNonQuery();
if(Succnum>0) MessageBox.Show("录入成功");
}
else
{
MessageBox.Show("录入信息重复。","确认");
}
}
}
catch
{
MessageBox.Show("该生已经录入或类型不匹配。","确认",MessageBoxButtons.YesNo);
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -