📄 studentmanage.cs
字号:
//
// dataGrid2
//
this.dataGrid2.AlternatingBackColor = System.Drawing.Color.GhostWhite;
this.dataGrid2.BackColor = System.Drawing.Color.GhostWhite;
this.dataGrid2.BackgroundColor = System.Drawing.Color.Lavender;
this.dataGrid2.BorderStyle = System.Windows.Forms.BorderStyle.None;
this.dataGrid2.CaptionBackColor = System.Drawing.Color.RoyalBlue;
this.dataGrid2.CaptionForeColor = System.Drawing.Color.White;
this.dataGrid2.DataMember = "";
this.dataGrid2.FlatMode = true;
this.dataGrid2.Font = new System.Drawing.Font("Tahoma", 8F);
this.dataGrid2.ForeColor = System.Drawing.Color.MidnightBlue;
this.dataGrid2.GridLineColor = System.Drawing.Color.RoyalBlue;
this.dataGrid2.HeaderBackColor = System.Drawing.Color.MidnightBlue;
this.dataGrid2.HeaderFont = new System.Drawing.Font("Tahoma", 8F, System.Drawing.FontStyle.Bold);
this.dataGrid2.HeaderForeColor = System.Drawing.Color.Lavender;
this.dataGrid2.LinkColor = System.Drawing.Color.Teal;
this.dataGrid2.Location = new System.Drawing.Point(32, 96);
this.dataGrid2.Name = "dataGrid2";
this.dataGrid2.ParentRowsBackColor = System.Drawing.Color.Lavender;
this.dataGrid2.ParentRowsForeColor = System.Drawing.Color.MidnightBlue;
this.dataGrid2.SelectionBackColor = System.Drawing.Color.Teal;
this.dataGrid2.SelectionForeColor = System.Drawing.Color.PaleGreen;
this.dataGrid2.Size = new System.Drawing.Size(720, 344);
this.dataGrid2.TabIndex = 118;
//
// groupBox2
//
this.groupBox2.Controls.Add(this.textID2);
this.groupBox2.Controls.Add(this.label22);
this.groupBox2.Controls.Add(this.comboClass2);
this.groupBox2.Controls.Add(this.label19);
this.groupBox2.Controls.Add(this.label20);
this.groupBox2.Controls.Add(this.comboDepartment2);
this.groupBox2.Location = new System.Drawing.Point(24, 16);
this.groupBox2.Name = "groupBox2";
this.groupBox2.Size = new System.Drawing.Size(440, 72);
this.groupBox2.TabIndex = 0;
this.groupBox2.TabStop = false;
this.groupBox2.Text = "职工查询";
//
// textID2
//
this.textID2.Location = new System.Drawing.Point(64, 24);
this.textID2.Name = "textID2";
this.textID2.Size = new System.Drawing.Size(80, 21);
this.textID2.TabIndex = 122;
this.textID2.Text = "";
//
// label22
//
this.label22.Location = new System.Drawing.Point(288, 32);
this.label22.Name = "label22";
this.label22.Size = new System.Drawing.Size(32, 23);
this.label22.TabIndex = 116;
this.label22.Text = "班级";
//
// comboClass2
//
this.comboClass2.Location = new System.Drawing.Point(336, 24);
this.comboClass2.Name = "comboClass2";
this.comboClass2.Size = new System.Drawing.Size(72, 20);
this.comboClass2.TabIndex = 115;
//
// label19
//
this.label19.Location = new System.Drawing.Point(16, 32);
this.label19.Name = "label19";
this.label19.Size = new System.Drawing.Size(48, 23);
this.label19.TabIndex = 114;
this.label19.Text = "学生ID";
//
// label20
//
this.label20.Location = new System.Drawing.Point(160, 32);
this.label20.Name = "label20";
this.label20.Size = new System.Drawing.Size(40, 23);
this.label20.TabIndex = 112;
this.label20.Text = "院系";
//
// comboDepartment2
//
this.comboDepartment2.Location = new System.Drawing.Point(200, 24);
this.comboDepartment2.Name = "comboDepartment2";
this.comboDepartment2.Size = new System.Drawing.Size(72, 20);
this.comboDepartment2.TabIndex = 111;
this.comboDepartment2.SelectedIndexChanged += new System.EventHandler(this.comboDepartment2_SelectedIndexChanged);
//
// btnExit
//
this.btnExit.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.btnExit.Image = ((System.Drawing.Image)(resources.GetObject("btnExit.Image")));
this.btnExit.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
this.btnExit.Location = new System.Drawing.Point(856, 512);
this.btnExit.Name = "btnExit";
this.btnExit.Size = new System.Drawing.Size(56, 24);
this.btnExit.TabIndex = 94;
this.btnExit.Text = "退出";
this.btnExit.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
this.btnExit.Click += new System.EventHandler(this.btnExit_Click);
//
// StudentManage
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(920, 565);
this.Controls.Add(this.btnExit);
this.Controls.Add(this.tabControl1);
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.Name = "StudentManage";
this.Text = "学生管理";
this.Load += new System.EventHandler(this.StudentManage_Load);
this.tabControl1.ResumeLayout(false);
this.tabPage1.ResumeLayout(false);
this.groupBox6.ResumeLayout(false);
this.groupBox4.ResumeLayout(false);
this.groupBox3.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
this.groupBox1.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).EndInit();
this.tabPage2.ResumeLayout(false);
this.groupBox8.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.dataGrid2)).EndInit();
this.groupBox2.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
private void btnExit_Click(object sender, System.EventArgs e)
{
this.Close();
}
private void StudentManage_Load(object sender, System.EventArgs e)
{
this.Combo_Fill();
this.lblPicture.Visible=false;
}
private void DataSet_Bingding()
{
this.dataGrid1.DataSource=this.DataSetStudent;
this.dataGrid1.DataMember="Student";
this.lblDepartment.DataBindings.Add("Text",this.DataSetStudent,"Student.Department");
this.comboStatus.DataBindings.Add("Text",this.DataSetStudent,"Student.Status");
this.comboNation.DataBindings.Add("Text",this.DataSetStudent,"Student.Nation");
this.comboSex.DataBindings.Add("Text",this.DataSetStudent,"Student.Sex");
this.dateTimePicker1.DataBindings.Add("Text",this.DataSetStudent,"Student.InDate");
this.numericUpDown1.DataBindings.Add("Text",this.DataSetStudent,"Student.Age");
this.textID.DataBindings.Add("Text",this.DataSetStudent,"Student.StudentID");
this.textName.DataBindings.Add("Text",this.DataSetStudent,"Student.StudentName");
this.textNativePlace.DataBindings.Add("Text",this.DataSetStudent,"Student.NativePlace");
this.lblClass.DataBindings.Add("Text",this.DataSetStudent,"Student.Class");
this.lblPicture.DataBindings.Add("Text",this.DataSetStudent,"Student.Picture");
}
private void lblRecord_Change()
{
int position=this.BindingContext[this.DataSetStudent,"Student"].Position+1;
int count=this.BindingContext[this.DataSetStudent,"Student"].Count;
lblRecord.Text=position+"/"+count+"条记录";
this.Picture_Change(position-1);
}
private void Combo_Fill()
{
try
{
this.Connection1.Open();
this.commandStr="select DepartmentName from Department";
this.Command1.CommandText=this.commandStr;
this.DataReader1=this.Command1.ExecuteReader();
while(this.DataReader1.Read())
{
this.comboDepartment.Items.Add(this.DataReader1["DepartmentName"].ToString());
this.comboDepartment2.Items.Add(this.DataReader1["DepartmentName"].ToString());
}
this.DataReader1.Close();
}
catch(Exception E)
{
MessageBox.Show(E.ToString());
}
finally
{
this.DataReader1.Close();
this.Connection1.Close();
}
}
/*private void MoveOrUpDown()
{
if(this.move)
{
this.PresentValue=this.comboDepartment.Text;
if(this.originValue!=this.PresentValue)
{
this.commandStr="insert into Move(StudentID,OriginalDep,PresentDep) values("+"'"+this.textStudentID.Text+"','"+this.originValue+"','"+this.PresentValue+"')";
}
}
if(this.updown)
{
this.PresentValue=this.comboDuty.Text;
if(this.originValue!=this.PresentValue)
{
this.commandStr="insert into UpDown(StudentID,OriginalDuty,PresentDuty) values("+"'"+this.textStudentID.Text+"','"+this.originValue+"','"+this.PresentValue+"')";
}
}
this.Command1.CommandText=this.commandStr;
try
{
this.Connection1.Open();
this.Command1.ExecuteNonQuery();
}
catch(Exception E)
{
this.ErrorHandle(E);
}
finally
{
this.Connection1.Close();
this.move=false;
this.updown=false;
}
}*/
private void btnApply_Click(object sender, System.EventArgs e)
{
/*if(this.move|this.updown)
{
this.MoveOrUpDown();
}*/
this.comboDepartment.Enabled=true;
this.comboClass.Enabled=true;
try
{
this.BindingContext[this.DataSetStudent,"Student"].EndCurrentEdit();
if(this.Connection1.State==ConnectionState.Closed)
this.Connection1.Open();
SqlCommandBuilder commandbuilder1=new SqlCommandBuilder(this.dataAdapter1);
this.dataAdapter1.Update(this.DataSetStudent,"Student");
this.DataSetStudent.AcceptChanges();
this.dataGrid1.Refresh();
}
catch(Exception E)
{
this.ErrorHandle(E);
}
finally
{
this.Connection1.Close();
this.lblRecord_Change();
this.Buttons_Control(false);
}
}
private void btnNext_Click(object sender, System.EventArgs e)
{
int position=this.BindingContext[this.DataSetStudent,"Student"].Position;
int count=this.BindingContext[this.DataSetStudent,"Student"].Count;
if(position>=count-1)
{
this.BindingContext[this.DataSetStudent,"Student"].Position=0;
}
else
{
this.BindingContext[this.DataSetStudent,"Student"].Position+=1;
}
this.lblRecord_Change();
}
private void btnLast_Click(object sender, System.EventArgs e)
{
this.BindingContext[this.DataSetStudent,"Student"].Position=this.BindingContext[this.DataSetStudent,"Student"].Count-1;
this.lblRecord_Change();
}
private void btnFirst_Click(object sender, System.EventArgs e)
{
this.BindingContext[this.DataSetStudent,"Student"].Position=0;
this.lblRecord_Change();
}
private void btnPrevious_Click(object sender, System.EventArgs e)
{
int position=this.BindingContext[this.DataSetStudent,"Student"].Position;
int count=this.BindingContext[this.DataSetStudent,"Student"].Count;
if(position==0)
{
this.BindingContext[this.DataSetStudent,"Student"].Position=count-1;
}
else
{
this.BindingContext[this.DataSetStudent,"Student"].Position-=1;
}
this.lblRecord_Change();
}
/* private void btnDelete_Click(object sender, System.EventArgs e)
{
if(this.comboDimissionType.Text=="")
{
MessageBox.Show("请先选择离职种类","错误",MessageBoxButtons.OK,MessageBoxIcon.Error);
return;
}
if((this.BindingContext[this.DataSetStudent,"Student"].Count>0)&
(MessageBox.Show("真的要删除此记录吗","确定删除",MessageBoxButtons.OKCancel,MessageBoxIcon.Question).Equals(DialogResult.OK)))
{
string StudentID=this.textID.Text;
string StudentLeaveType=this.comboDimissionType.Text;
string date=this.dateTimePicker2.Text;
string name=this.textName.Text;
string sex=this.comboSex.Text;
string inDate=this.dateTimePicker1.Text;
string department=this.comboDepartment.Text;
decimal age=this.numericUpDown1.Value;
try
{ if(this.Connection1.State==ConnectionState.Closed)
this.Connection1.Open();
int position=this.BindingContext[this.DataSetStudent,"Student"].Position;
this.commandStr="insert into StudentLeave(StudentID,StudentName,Sex,Age,Department,Title,Duty,StudentLeaveType,InDate,StudentLeaveDate) values('"+StudentID+"','"+name+"','"+sex+"',"+age+",'"+department+"','"+"','"+"','"+StudentLeaveType+"','"+inDate+"','"+date+"')";
//this.commandStr="insert into StudentLeave(StudentID,Sex) values('"+StudentID+"','"+sex+"'";
this.Command1.CommandText=this.commandStr;
this.Command1.ExecuteNonQuery();
this.BindingContext[this.DataSetStudent,"Student"].RemoveAt(position);
this.BindingContext[this.DataSetStudent,"Student"].EndCurrentEdit();
SqlCommandBuilder commandbuilder1=new SqlCommandBuilder(this.dataAdapter1);
this.dataAdapter1.Update(this.DataSetStudent,"Student");
this.DataSetStudent.AcceptChanges();
//this.dataGrid1.Refresh();
}
catch(System.Exception E)
{
this.ErrorHandle(E);
}
finally
{
this.Connection1.Close();
}
this.lblRecord_Change();
}
else
return;
}*/
private void btnAdd_Click(object sender, System.EventArgs e)
{
this.Buttons_Control(true);
this.BindingContext[this.DataSetStudent,"Student"].AddNew();
this.lblClass.Text=this.StuClass;
this.lblDepartment.Text=this.StuDepartment;
this.comboClass.Enabled=false;
this.comboDepartment.Enabled=false;
}
public void ErrorHandle(System.Exception E)
{
MessageBox.Show(E.ToString());
}
private void btnCancel_Click(object sender, System.EventArgs e)
{
try
{
this.BindingContext[this.DataSetStudent,"Student"].CancelCurrentEdit();
}
catch(System.Exception E)
{
this.ErrorHandle(E);
}
this.Buttons_Control(false);
this.comboClass.Enabled=true;
this.comboDepartment.Enabled=true;
}
private void Buttons_Control(bool IsValid)
{
if(IsValid)
{
this.btnCancel.Enabled=true;
this.btnApply.Enabled=true;
this.dataGrid1.ReadOnly=false;
this.comboNation.Enabled=true;
this.comboSex.Enabled=true;
this.comboStatus.Enabled=true;
this.comboStatus.Enabled=true;
this.btnPicture.Enabled=true;
this.dateTimePicker1.Enabled=true;
this.numericUpDown1.Enabled=true;
this.textNativePlace.Enabled=true;
this.textName.Enabled=true;
this.textID.Enabled=true;
}
else
{
this.btnCancel.Enabled=false;
this.btnApply.Enabled=false;
this.dataGrid1.ReadOnly=true;
this.comboNation.Enabled=false;
this.comboSex.Enabled=false;
this.comboStatus.Enabled=false;
this.btnPicture.Enabled=false;
this.dateTimePicker1.Enabled=false;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -