`

C#:项目二 多表的学生信息系统

阅读更多

(一) 基本界面设计

<shapetype id="_x0000_t75" stroked="f" filled="f" path=" m@4@5 l@4@11@9@11@9@5 xe" o:preferrelative="t" o:spt="75" coordsize="21600,21600"><img alt="" src="http://p.blog.csdn.net/images/p_blog_csdn_net/xiaozhao_19/image0021.jpg"></shapetype>

<shapetype stroked="f" filled="f" path=" m@4@5 l@4@11@9@11@9@5 xe" o:preferrelative="t" o:spt="75" coordsize="21600,21600"><img alt="" src="http://p.blog.csdn.net/images/p_blog_csdn_net/xiaozhao_19/image0041.jpg"></shapetype>

<shape id="_x0000_i1025" style="WIDTH: 417pt; HEIGHT: 343.5pt" coordsize="21600,21600" type="#_x0000_t75"><imagedata o:title="" src="%E9%A1%B9%E7%9B%AE%E4%BA%8C%20%E5%A4%9A%E8%A1%A8%E7%9A%84%E5%AD%A6%E7%94%9F%E4%BF%A1%E6%81%AF%E7%B3%BB%E7%BB%9F.files/image001.png"></imagedata></shape>

<shape style="WIDTH: 417pt; HEIGHT: 343.5pt" coordsize="21600,21600" type="#_x0000_t75"><imagedata o:title="" src="%E9%A1%B9%E7%9B%AE%E4%BA%8C%20%E5%A4%9A%E8%A1%A8%E7%9A%84%E5%AD%A6%E7%94%9F%E4%BF%A1%E6%81%AF%E7%B3%BB%E7%BB%9F.files/image001.png"></imagedata></shape>

<shape id="_x0000_i1032" style="WIDTH: 410.25pt; HEIGHT: 327.75pt" coordsize="21600,21600" type="#_x0000_t75"><imagedata o:title="" src="%E9%A1%B9%E7%9B%AE%E4%BA%8C%20%E5%A4%9A%E8%A1%A8%E7%9A%84%E5%AD%A6%E7%94%9F%E4%BF%A1%E6%81%AF%E7%B3%BB%E7%BB%9F.files/image003.png"></imagedata></shape>

(二) 数据库的建立和实现维护功能

<shape id="_x0000_i1026" style="WIDTH: 186pt; HEIGHT: 341.25pt" coordsize="21600,21600" type="#_x0000_t75"><imagedata o:title="" src="%E9%A1%B9%E7%9B%AE%E4%BA%8C%20%E5%A4%9A%E8%A1%A8%E7%9A%84%E5%AD%A6%E7%94%9F%E4%BF%A1%E6%81%AF%E7%B3%BB%E7%BB%9F.files/image005.png"></imagedata></shape>

保存按钮功能代码如下:

private void btnSave_Click(object sender, EventArgs e)

{

this.Validate();

this.schoolBindingSource.EndEdit();

this.schoolStudentBindingSource.EndEdit();

StudentsInfoDataSet.StudentDataTable deletedRows = studentsInfoDataSet.Student.GetChanges(DataRowState.Deleted) as StudentsInfoDataSet.StudentDataTable;

StudentsInfoDataSet.StudentDataTable addedRows = studentsInfoDataSet.Student.GetChanges(DataRowState.Added) as StudentsInfoDataSet.StudentDataTable;

StudentsInfoDataSet.StudentDataTable modifiedRows = studentsInfoDataSet.Student.GetChanges(DataRowState.Modified) as StudentsInfoDataSet.StudentDataTable;

try

{

this.Cursor = Cursors.WaitCursor;

if (deletedRows != null)

studentTableAdapter.Update(deletedRows);

schoolTableAdapter.Update(studentsInfoDataSet.School);

if (addedRows != null)

studentTableAdapter.Update(addedRows);

if (modifiedRows != null)

studentTableAdapter.Update(modifiedRows);

studentsInfoDataSet.AcceptChanges();

}

catch (Exception ex)

{

MessageBox.Show("在数据更新期间出现了错误!" + Environment.NewLine + ex.Message, "系统警告", MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1);

}

finally

{

if (deletedRows != null)

deletedRows.Dispose();

if (addedRows != null)

addedRows.Dispose();

if (modifiedRows != null)

modifiedRows.Dispose();

this.Cursor = Cursors.Default;

}

}

取消按钮功能代码如下:

private void btnCancel_Click(object sender, EventArgs e)

{

this.Cursor = Cursors.WaitCursor;

this.studentsInfoDataSet.RejectChanges();

this.Cursor = Cursors.Default;

}

(三) 实现报表功能和关闭窗口前的确认功能

报表设计界面如下:

<shape id="_x0000_i1027" style="WIDTH: 416.25pt; HEIGHT: 139.5pt" coordsize="21600,21600" type="#_x0000_t75"><imagedata o:title="" src="%E9%A1%B9%E7%9B%AE%E4%BA%8C%20%E5%A4%9A%E8%A1%A8%E7%9A%84%E5%AD%A6%E7%94%9F%E4%BF%A1%E6%81%AF%E7%B3%BB%E7%BB%9F.files/image007.png"></imagedata></shape>

报表显示界面如下:

<shape id="_x0000_i1028" style="WIDTH: 417pt; HEIGHT: 326.25pt" coordsize="21600,21600" type="#_x0000_t75"><imagedata o:title="" src="%E9%A1%B9%E7%9B%AE%E4%BA%8C%20%E5%A4%9A%E8%A1%A8%E7%9A%84%E5%AD%A6%E7%94%9F%E4%BF%A1%E6%81%AF%E7%B3%BB%E7%BB%9F.files/image009.png"></imagedata></shape>

报表功能代码如下:

private void frmReport_Load(object sender, EventArgs e)

{//为了在不同窗体间传递数据集,可以在生成数据集的窗体类中写一个公共静态的数据集对象,此方法如(public static DataBaseAccessMutiTablesEx.StudentsInfoDataSet sid;)

//此方法中写上从主窗体的传过来的这个公共静态的数据集对象,设为打印窗体绑定数据控件的数据源

SchoolStudentForSearchBindingSource.DataSource = frmMain.sid;

// TODO: 这行代码将数据加载到表“StudentsInfoDataSet.SchoolStudentForSearch”中。您可以根据需要移动或移除它。

//this.SchoolStudentForSearchTableAdapter.Fill(this.StudentsInfoDataSet.SchoolStudentForSearch);

this.rpvSchoolStudent.RefreshReport();

}

窗体关闭功能界面如下:

<shape id="_x0000_i1029" style="WIDTH: 209.25pt; HEIGHT: 90.75pt" coordsize="21600,21600" type="#_x0000_t75"><imagedata o:title="" src="%E9%A1%B9%E7%9B%AE%E4%BA%8C%20%E5%A4%9A%E8%A1%A8%E7%9A%84%E5%AD%A6%E7%94%9F%E4%BF%A1%E6%81%AF%E7%B3%BB%E7%BB%9F.files/image011.png"></imagedata></shape>

窗体关闭功能代码如下:

private void btnClose_Click(object sender, EventArgs e)

{

Close();

}

private void frmMain_FormClosing(object sender, FormClosingEventArgs e)

{

if (studentsInfoDataSet.HasChanges())

{

if (MessageBox.Show("你没有保存已修改过的数据,现在保存吗并退出吗?", "系统警告", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.OK)

{

btnSave_Click(null, null);

}

else

e.Cancel = true;

}

}

(四) 实现模糊查询功能

XSD中的 设置界面如下:

<shape id="_x0000_i1030" style="WIDTH: 416.25pt; HEIGHT: 373.5pt" coordsize="21600,21600" type="#_x0000_t75"><imagedata o:title="" src="%E9%A1%B9%E7%9B%AE%E4%BA%8C%20%E5%A4%9A%E8%A1%A8%E7%9A%84%E5%AD%A6%E7%94%9F%E4%BF%A1%E6%81%AF%E7%B3%BB%E7%BB%9F.files/image013.png"></imagedata></shape>

注意:对于ACCESS,参数要用?表示;而对于SQL参数要用@XXX表示.

XSD中的 设置效果如下:

<shape id="_x0000_i1031" style="WIDTH: 379.5pt; HEIGHT: 426.75pt" coordsize="21600,21600" type="#_x0000_t75"><imagedata o:title="" src="%E9%A1%B9%E7%9B%AE%E4%BA%8C%20%E5%A4%9A%E8%A1%A8%E7%9A%84%E5%AD%A6%E7%94%9F%E4%BF%A1%E6%81%AF%E7%B3%BB%E7%BB%9F.files/image015.png"></imagedata></shape>

查询功能代码如下:

//模糊查询

private void btnSearch_Click(object sender, EventArgs e)

{

if (txbSearch.Text == string.Empty) //没有输入查询内容

{

MessageBox.Show("请输入要查询的内容", "系统警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);

txbSearch.Select();

return;

}

switch (cbbFieldName.SelectedIndex)

{

case -1: //没有选择任何类型

MessageBox.Show("请选择要查询的类型名称","系统警告", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);

break;

case 0: //学校名称 schoolStudentForSearchTableAdapter.FillBySchoolName(studentsInfoDataSet.SchoolStudentForSearch, txbSearch.Text);

break;

case 1: //学生姓名 schoolStudentForSearchTableAdapter.FillByStudentName(studentsInfoDataSet.SchoolStudentForSearch, txbSearch.Text);

break;

case 2: // 专业名称 schoolStudentForSearchTableAdapter.FillByMajorName(studentsInfoDataSet.SchoolStudentForSearch, txbSearch.Text);

break;

}

if(dgvSearch.Rows.Count==0)

MessageBox.Show("没有你要查询的记录!", "系统警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);

}

//显示打印预览界面

private void btnPrint_Click(object sender, EventArgs e)

{//将这个sid公共静态的数据集对象引用一下!

sid = studentsInfoDataSet;

frmReport myFrmReport = new frmReport();

myFrmReport.Show();

}

(五) 课后练习:

阶段基础训练(B)-各班通告信息管理系统(双表结构:班级(所在班级号、专业类别、通告编号)、通告(编号、题目、正文、发通告人、日期)
阶段基础考核(B)-同学录分类信息管理系统(双表结构:分类(分类号,分类名称)、同学录(编号、名字、绰号、性别、联系方式、联系地址、分类号))
数据产品清单分类管理系统(双表结构:产品分类(分类号、分类名称)、产品清单(编号、品名、数量、单价、是否开票、分类号))等等
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics