(一) 基本界面设计
<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/image002.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"><stroke joinstyle="miter"></stroke><formulas><f eqn="if lineDrawn pixelLineWidth 0 "></f><f eqn="sum @0 1 0 "></f><f eqn="sum 0 0 @1 "></f><f eqn="prod @2 1 2 "></f><f eqn="prod @3 21600 pixelWidth "></f><f eqn="prod @3 21600 pixelHeight "></f><f eqn="sum @0 0 1 "></f><f eqn="prod @6 1 2 "></f><f eqn="prod @7 21600 pixelWidth "></f><f eqn="sum @8 21600 0 "></f><f eqn="prod @7 21600 pixelHeight "></f><f eqn="sum @10 21600 0 "></f></formulas><path o:connecttype="rect" gradientshapeok="t" o:extrusionok="f"></path><lock aspectratio="t" v:ext="edit"></lock></shapetype><shape id="_x0000_i1025" style="WIDTH: 339pt; HEIGHT: 281.25pt" coordsize="21600,21600" type="#_x0000_t75"><imagedata o:title="" src="%E9%A1%B9%E7%9B%AE%E4%B8%80%20%E7%AE%80%E5%8D%95%E7%9A%84%E4%BF%A1%E6%81%AF%E7%AE%A1%E7%90%86%E7%B3%BB%E7%BB%9F.files/image001.png" croptop="8108f" cropbottom="20803f" cropleft="11646f" cropright="18964f"><img alt="" src="http://p.blog.csdn.net/images/p_blog_csdn_net/xiaozhao_19/image004.jpg"></imagedata></shape>
<shape id="_x0000_i1026" style="WIDTH: 352.5pt; HEIGHT: 242.25pt" coordsize="21600,21600" type="#_x0000_t75"><imagedata o:title="" src="%E9%A1%B9%E7%9B%AE%E4%B8%80%20%E7%AE%80%E5%8D%95%E7%9A%84%E4%BF%A1%E6%81%AF%E7%AE%A1%E7%90%86%E7%B3%BB%E7%BB%9F.files/image003.png" croptop="7944f" cropbottom="26403f" cropleft="10784f" cropright="18459f"></imagedata></shape>
(二) 数据库的建立和实现保存功能
数据库设计界面如下:
<shape id="_x0000_i1027" style="WIDTH: 404.25pt; HEIGHT: 249.75pt" coordsize="21600,21600" type="#_x0000_t75"><imagedata o:title="" src="%E9%A1%B9%E7%9B%AE%E4%B8%80%20%E7%AE%80%E5%8D%95%E7%9A%84%E4%BF%A1%E6%81%AF%E7%AE%A1%E7%90%86%E7%B3%BB%E7%BB%9F.files/image005.png" cropbottom="37472f" cropright="29185f"></imagedata></shape>
保存按钮功能代码如下:
private void toolStripButtonSaveItem_Click(object sender, EventArgs e)
{
try
{
this.Validate();
ccbmBindingSource.EndEdit();//要善于用相应的BindingSource组件!
ccbmTableAdapter.Update(studyDataSet.ccbm);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "保存失败");
}
}
(三) 实现报表功能和关闭窗口前的确认功能
报表设计界面如下:
<shape id="_x0000_i1028" style="WIDTH: 342pt; HEIGHT: 179.25pt" coordsize="21600,21600" type="#_x0000_t75"><imagedata o:title="" src="%E9%A1%B9%E7%9B%AE%E4%B8%80%20%E7%AE%80%E5%8D%95%E7%9A%84%E4%BF%A1%E6%81%AF%E7%AE%A1%E7%90%86%E7%B3%BB%E7%BB%9F.files/image007.png" cropbottom="39007f" cropright="25059f"></imagedata></shape>
报表显示界面如下:
<shape id="_x0000_i1029" style="WIDTH: 315pt; HEIGHT: 253.5pt" coordsize="21600,21600" type="#_x0000_t75"><imagedata o:title="" src="%E9%A1%B9%E7%9B%AE%E4%B8%80%20%E7%AE%80%E5%8D%95%E7%9A%84%E4%BF%A1%E6%81%AF%E7%AE%A1%E7%90%86%E7%B3%BB%E7%BB%9F.files/image009.png" croptop="5489f" cropbottom="35830f" cropleft="12470f" cropright="29136f"></imagedata></shape>
报表功能代码如下:
private void toolStripButtonReportItem_Click(object sender, EventArgs e)
{
frmReport2 myReport2 = new frmReport2();
myReport2.ShowDialog();
}
窗体关闭功能界面如下:
<shape id="_x0000_i1030" style="WIDTH: 209.25pt; HEIGHT: 90.75pt" coordsize="21600,21600" type="#_x0000_t75"><imagedata o:title="" src="%E9%A1%B9%E7%9B%AE%E4%B8%80%20%E7%AE%80%E5%8D%95%E7%9A%84%E4%BF%A1%E6%81%AF%E7%AE%A1%E7%90%86%E7%B3%BB%E7%BB%9F.files/image011.png"></imagedata></shape>
窗体关闭功能代码如下:
private void 退出EToolStripMenuItem_Click(object sender, EventArgs e)
{
this.Close();
}
private void frmBianMaGuanLi_FormClosing(object sender, FormClosingEventArgs e)
{
if (studyDataSet.HasChanges()) // HasChanges()方法是关键!
{
if (MessageBox.Show("你已进行了相关数据操作,但尚未保存!" + Environment.NewLine + "放弃并退出系统吗?", "友情提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1) == DialogResult.OK)
{
studyDataSet.RejectChanges();
}
else
e.Cancel = true;
}
}
(四) 实现模糊查询和删除多条记录功能
XSD中的 设置界面如下:
<shape id="_x0000_i1031" style="WIDTH: 289.5pt; HEIGHT: 235.5pt" coordsize="21600,21600" type="#_x0000_t75"><imagedata o:title="" src="%E9%A1%B9%E7%9B%AE%E4%B8%80%20%E7%AE%80%E5%8D%95%E7%9A%84%E4%BF%A1%E6%81%AF%E7%AE%A1%E7%90%86%E7%B3%BB%E7%BB%9F.files/image013.png"></imagedata></shape>
XSD中的 设置效果如下:
<shape id="_x0000_i1032" style="WIDTH: 294.75pt; HEIGHT: 154.5pt" coordsize="21600,21600" type="#_x0000_t75"><imagedata o:title="" src="%E9%A1%B9%E7%9B%AE%E4%B8%80%20%E7%AE%80%E5%8D%95%E7%9A%84%E4%BF%A1%E6%81%AF%E7%AE%A1%E7%90%86%E7%B3%BB%E7%BB%9F.files/image015.png" croptop="10743f" cropbottom="37472f" cropleft="13225f" cropright="25884f"></imagedata></shape>
查询功能代码如下:
//按名称查询
private void btnSelectByName_Click(object sender, EventArgs e)
{
try
{
dgvSelectByName.DataSource = this.ccbmBindingSource1;
this.Cursor = Cursors.WaitCursor;
// studyDataSet是StudyDataSet类的一个实例化对象 此处ccbm为属性 关键!
this.ccbmTableAdapter.FillByName(this.studyDataSet.ccbm, txbName.Text);
this.Cursor = Cursors.Default;
tsslblRows.Text = "当前记录数: " + dgvSelectByName.Rows.Count.ToString();
if (dgvSelectByName.Rows.Count == 0)
MessageBox.Show("没有符合条件的记录","查询结果",MessageBoxButtons.OK,MessageBoxIcon.Warning);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
//查询所有
private void btnSelectAll_Click(object sender, EventArgs e)
{
this.ccbmTableAdapter.Fill(this.studyDataSet.ccbm);
}
//删除多条功能(此处功能有待改善)
private void toolStripButtonDeleteSome_Click(object sender, EventArgs e)
{
if (dgvBianHao.SelectedRows.Count == 0)
{
MessageBox.Show("你没有选择任何记录");
return;
}
foreach (DataGridViewRow dr in dgvBianHao.SelectedRows)
{
dgvBianHao.EndEdit();
dgvBianHao.Rows.Remove(dr);
}
}
(五) 课后练习: