📄 frmclass.cs
字号:
}
#endregion
private void frmClass_Load(object sender, System.EventArgs e)
{
DataAccess da = new DataAccess();
string Sql = "select * from Class..SpecialtyInfo";
if(c.IsExits(Sql)==true)
{
string tableName = "SpecialtyInfo";
this.cboSpc.DataSource=da.ExecuteDataTable(Sql,tableName);
this.cboSpc.DisplayMember="SpecialtyName";
this.cboSpc.SelectedIndex=0;
this.setDataGridStyle();
}
else
{
this.cboSpc.Items.Add("未添加专业");
this.cboSpc.SelectedIndex=0;
}
}
private void setDataGridStyle()
{
DataGridTableStyle dgs = new DataGridTableStyle();
dgs.MappingName="ClassInfo";
this.dataGrid1.TableStyles.Add(dgs);
DataGridColumnStyle dgs1 = new DataGridTextBoxColumn();
dgs1.HeaderText="班级编号";
dgs1.MappingName="ClassID";
dgs1.Width=100;
DataGridColumnStyle dgs2 = new DataGridTextBoxColumn();
dgs2.HeaderText="班级名称";
dgs2.MappingName="ClassName";
dgs2.Width=150;
DataGridColumnStyle dgs3 = new DataGridTextBoxColumn();
dgs3.HeaderText="专业名称";
dgs3.MappingName="SpecialtyName";
dgs3.Width=150;
DataGridColumnStyle dgs4 = new DataGridTextBoxColumn();
dgs4.HeaderText="教室编号";
dgs4.MappingName="ClassNumber";
dgs4.Width=100;
DataGridColumnStyle dgs5 = new DataGridTextBoxColumn();
dgs5.HeaderText="学制年限";
dgs5.MappingName="Length";
dgs5.Width=100;
DataGridColumnStyle dgs6 = new DataGridTextBoxColumn();
dgs6.HeaderText="班主任";
dgs6.MappingName="Teacher";
dgs6.Width=100;
DataGridColumnStyle dgs7 = new DataGridTextBoxColumn();
dgs7.HeaderText="开学日期";
dgs7.MappingName="BeginTime";
dgs7.Width=100;
DataGridColumnStyle dgs8 = new DataGridTextBoxColumn();
dgs8.HeaderText="备注";
dgs8.MappingName="Memo";
dgs8.Width=200;
dgs.GridColumnStyles.Add(dgs1);
dgs.GridColumnStyles.Add(dgs2);
dgs.GridColumnStyles.Add(dgs3);
dgs.GridColumnStyles.Add(dgs4);
dgs.GridColumnStyles.Add(dgs5);
dgs.GridColumnStyles.Add(dgs6);
dgs.GridColumnStyles.Add(dgs7);
dgs.GridColumnStyles.Add(dgs8);
}
private void btnSelect_Click(object sender, System.EventArgs e)
{
if(this.cboSpc.Text=="未添加专业")
{
MessageBox.Show("请先添加专业","提示信息!",MessageBoxButtons.OK,MessageBoxIcon.Question);
}
else
{
DataAccess da = new DataAccess();
string Sql = "select * from Class..ClassInfo where SpecialtyName = '"+this.cboSpc.Text+"' and year(BeginTime)='"+this.txtYear.Text+"'";
string tablename = "ClassInfo";
this.dataGrid1.DataSource=da.ExecuteDataTable(Sql,tablename);
int rows = da.ExecuteDataTable(Sql,tablename).Rows.Count;
this.dataGrid1.CaptionText="共有"+rows+"条查询记录";
}
}
private string name ="";
private void dataGrid1_CurrentCellChanged(object sender, EventArgs e)
{
if(this.dataGrid1.VisibleRowCount>0)
{
this.name = this.dataGrid1[this.dataGrid1.CurrentRowIndex,1].ToString();
class1.ID=this.dataGrid1[this.dataGrid1.CurrentRowIndex,0].ToString();
class1.Name=this.dataGrid1[this.dataGrid1.CurrentRowIndex,1].ToString();
class1.Spec=this.dataGrid1[this.dataGrid1.CurrentRowIndex,2].ToString();
class1.Room=this.dataGrid1[this.dataGrid1.CurrentRowIndex,3].ToString();
class1.Year=this.dataGrid1[this.dataGrid1.CurrentRowIndex,4].ToString();
class1.Teacher=this.dataGrid1[this.dataGrid1.CurrentRowIndex,5].ToString();
class1.Date=this.dataGrid1[this.dataGrid1.CurrentRowIndex,6].ToString();
class1.Memo=this.dataGrid1[this.dataGrid1.CurrentRowIndex,7].ToString();
this.dataGrid1.CaptionText="您选择的是"+this.name+"";
}
}
private void dataGrid1_GotFocus(object sender, EventArgs e)
{
if(this.dataGrid1.VisibleRowCount>0)
{
this.name = this.dataGrid1[this.dataGrid1.CurrentRowIndex,1].ToString();
class1.ID=this.dataGrid1[this.dataGrid1.CurrentRowIndex,0].ToString();
class1.Name=this.dataGrid1[this.dataGrid1.CurrentRowIndex,1].ToString();
class1.Spec=this.dataGrid1[this.dataGrid1.CurrentRowIndex,2].ToString();
class1.Room=this.dataGrid1[this.dataGrid1.CurrentRowIndex,3].ToString();
class1.Year=this.dataGrid1[this.dataGrid1.CurrentRowIndex,4].ToString();
class1.Teacher=this.dataGrid1[this.dataGrid1.CurrentRowIndex,5].ToString();
class1.Date=this.dataGrid1[this.dataGrid1.CurrentRowIndex,6].ToString();
class1.Memo=this.dataGrid1[this.dataGrid1.CurrentRowIndex,7].ToString();
this.dataGrid1.CaptionText="您选择的是"+this.name+"";
}
}
private void btnCancle_Click(object sender, System.EventArgs e)
{
this.Close();
}
private void btnDel_Click(object sender, System.EventArgs e)
{
string Sql = "select * from Class..StudentInfo where ClassID =(select ClassID from Class..ClassInfo where ClassName = '"+this.name+"')";
string Sql1 = "delete from Class..ClassInfo where ClassName = '"+this.name+"'";
if(this.name=="")
{
MessageBox.Show("请选择要删除的班级","提示信息!",MessageBoxButtons.OK,MessageBoxIcon.Question);
}
else if(c.IsExits(Sql)==true)
{
MessageBox.Show("该班级尚有学生,不能删除","提示信息!",MessageBoxButtons.OK,MessageBoxIcon.Question);
}
else
{
if(MessageBox.Show("确认要删除该班级","提示信息!",MessageBoxButtons.OKCancel,MessageBoxIcon.Question,MessageBoxDefaultButton.Button2)==DialogResult.OK)
{
c.EditData(Sql1);
DataAccess da = new DataAccess();
string Sql2 = "select * from Class..ClassInfo where SpecialtyName = '"+this.cboSpc.Text+"' and year(BeginTime)='"+this.txtYear.Text+"'";
string tablename = "ClassInfo";
this.dataGrid1.DataSource=da.ExecuteDataTable(Sql2,tablename);
int rows = da.ExecuteDataTable(Sql,tablename).Rows.Count;
this.dataGrid1.CaptionText="共有"+rows+"条查询记录";
}
}
}
private void btnEdit_Click(object sender, System.EventArgs e)
{
if(this.name=="")
{
MessageBox.Show("请选择要修改的班级","提示信息!",MessageBoxButtons.OK,MessageBoxIcon.Question);
}
else
{
UpdateClass f = new UpdateClass(this.class1);
f.LoadDataEvent+=new LoadDataHandler(f_LoadDataEvent);
f.ShowDialog();
}
}
private void f_LoadDataEvent()
{
DataAccess da = new DataAccess();
string Sql = "select * from Class..ClassInfo where SpecialtyName = '"+this.cboSpc.Text+"' and year(BeginTime)='"+this.txtYear.Text+"'";
string tablename = "ClassInfo";
this.dataGrid1.DataSource=da.ExecuteDataTable(Sql,tablename);
int rows = da.ExecuteDataTable(Sql,tablename).Rows.Count;
this.dataGrid1.CaptionText="共有"+rows+"条查询记录";
}
private void txtYear_Leave(object sender, System.EventArgs e)
{
if(c.IsYear(this.txtYear.Text)==false||this.txtYear.Text.Length!=4)
{
MessageBox.Show("请填写正确年份","提示信息!",MessageBoxButtons.OK,MessageBoxIcon.Question);
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -