📄 studentmanage.cs
字号:
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(739, 517);
this.Controls.Add(this.btnExit);
this.Controls.Add(this.tabControl1);
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.MaximizeBox = false;
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);
this.groupBox1.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
this.tabPage2.ResumeLayout(false);
this.groupBox8.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.dataGrid2)).EndInit();
this.groupBox2.ResumeLayout(false);
this.groupBox2.PerformLayout();
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;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -