• 一步一步教你使用AgileEAS.NET基础类库进行应用开发WinForm应用篇演示ORM对象与DataGridView的绑定技术商品字典的另一个实现


    回顾与说明

        前面我们把“商品字典”、“商品入库”、“商品库存查询”、“商品入库查询”四个模块已经概括或者详细的演示了一个管理信息系统的典型应用场景,按照原来的打算,WinForm篇的例子系统中的几个模块就告一段落了。

        由于好多朋友都问我,你的例子中大量使用ListView控件,很想知道是否可以支持DataGridView控件,所以我就有想到重新用DataGridView写一下“商品字典”模块。

    本文内容

        关于“商品字典”的实现及其业务应用场景请参见一步一步教你使用AgileEAS.NET基础类库进行应用开发-WinForm应用篇-实例一个模块(商品字典)一文。

        今天本文的主要内容是AgileEAS.NET平台中的ORM对象与DataGridView的绑定,在AgileEAS.NET平台的ORM体系之中,有一个ITable接口,他继承了数据绑定接口IListSource,并且ITable的Rows属性为EntityCollection对象本身就是一个List<IEntity>,那么通过ITable.Rows也是可以实现数据绑定的。

        本文的例子中,我只演示商品字典数据的绑定与修改,并且修改也使用了一个偷懒的方法,不是最优的实现,另外关于字典的删除和增加我也没有实现,有兴趣的朋友自己实现吧。

        下面我们就来开始干活吧,第一件事,还是拖控件堆界面。

    制做界面

          首先,我们需要在UI项目中增加一个WinForm窗体ProductDictForm拖动控件达到如下效果:

    4(@_E8DGYJ1[8KU$W%JFUO7

          在这里,我们需要注意的是需要向界面放一个dataGridView,并且设置一下他的列,当然了大家也可以直接使用BindingSource绑定到Product.DAL.Interface.IProduct之上。

    编写绑定代码

          下面我们来写“查询”、“打印”两个按钮的事件处理代码:

     1:  void LoadDictList()
     2:  {
     3:      currentDict = DALHelper.DALManager.CreateProduct();
     4:   
     5:      dictList = DALHelper.DALManager.CreateProductList();
     6:      dictList.GetProductList(this.tbSearch.Text);
     7:   
     8:      //两种方式都支持
     9:      this.dataGridView1.DataSource = dictList;
    10:      //this.dataGridView1.DataSource = dictList.Rows;
    11:  }
    12:   
    13:  private void btnSearch_Click(object sender, EventArgs e)
    14:  {
    15:      this.LoadDictList();
    16:  }
    17:   
    18:  private void btnPrint_Click(object sender, EventArgs e)
    19:  {
    20:      if (dictList == null)
    21:      {
    22:          MessageBox.Show("没有需要打印的数据!", "提?示?", MessageBoxButtons.OK, MessageBoxIcon.Information);
    23:          return;
    24:      }
    25:   
    26:      if (this.printForm == null)
    27:          this.printForm = new PrintViewDialog();
    28:   
    29:      //
    30:      System.IO.TextReader textReader = null;
    31:      try
    32:      {
    33:          string fileName = Path.Combine(Application.StartupPath, "Reports\\商品字典.rdl");
    34:          textReader = new System.IO.StreamReader(fileName);
    35:          this.printForm.SourceRdl = textReader.ReadToEnd();
    36:      }
    37:      finally
    38:      {
    39:          if (textReader != null)
    40:              textReader.Close();
    41:      }
    42:   
    43:      this.printForm.DataObject = dictList;
    44:      this.printForm.PrintPreview();
    45:  }
    46:   

           接下来看看编辑处理代码:

     1:  private void dataGridView1_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e)
     2:  {
     3:      if (this.dataGridView1.CurrentRow != null)
     4:      {
     5:          IProduct product = this.dataGridView1.CurrentRow.DataBoundItem as IProduct;
     6:          currentDict.Code = product.Code;
     7:      }
     8:  }
     9:   
    10:  private void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e)
    11:  {
    12:      IProduct product = this.dataGridView1.CurrentRow.DataBoundItem as IProduct;
    13:   
    14:      if (product.Code == currentDict.Code)
    15:          product.Update();
    16:      else
    17:      {
    18:          product.Update();
    19:          product.Idn = product.GetMaxNewIdn();
    20:          currentDict.Delete();
    21:          product.Insert();
    22:      }
    23:  }

     运行结果

    编译并运行程序,我们看一下运行效果:

    image

             打印预览:

    image

    导出报表,选择导出Excel格式:

    UAC988(LZ@[X6QW)G%XZ(NO

          我写完这篇post,WinForm篇的例程即将就结束了,接下来,我会在WinForm篇之中安排几篇文章讲例程的部署问题,说是部署问题,其他也不是部署问题,而是例子是以何种方式运行,是直接连接数据库,还是通过服务桥接器连接到远程服务器进行业务处理。

          本文我就说到这里,对AgileEAS.NET平台感兴趣的朋友呢,可以下载了完整代码之后自己看看,有问题请及时的和我联系。

          有关本例所涉及的数据表结构请参考基于AgileEAS.NET平台基础类库进行应用开发-总体说明及数据定义一文,有关数据对象模型定义文件、文档、DDL脚本请下载:https://files.cnblogs.com/eastjade/demo.db.doc.sql.rar,本例完整代码下载:Product.Demo.rar

    链接

    一步一步教你使用AgileEAS.NET基础类库进行应用开发-系列目录

    AgileEAS.NET平台开发指南-系列目录

    AgileEAS.NET应用开发平台介绍-文章索引

    AgileEAS.NET平台应用开发教程-案例计划

    AgileEAS.NET官方网站

    敏捷软件工程实验室

    QQ群:116773358

  • 相关阅读:
    DedeCMS Xss+Csrf Getshell dedefile_manage_control.php
    dedeCMS /plus/ad_js.php、/plus/mytag_js.php Vul Via Injecting PHP Code By /plus/download.php Into DB && /include/dedesql.class.php
    phpMyadmin /scripts/setup.php Execute Arbitrary PHP Code Via A Crafted POST Request CVE-2010-3055
    Linux inode && Fast Directory Travel Method(undone)
    Linux进程自保护攻防对抗技术研究(Process Kill Technology && Process Protection Against In Linux)
    PHP Web System Optimization(undone)
    PHP Simulation HTTP Request(undone)
    Server Data Synchronization Via Linux rsync、rsync+inotify Between Load Balance Server
    Ecshop /admin/get_password.php Password Recovery Secrect Code Which Can Predict Vulnerability
    Dedecms includedialogselect_soft_post.php Upload Any Files To The Specified Directory Via Variable Not Initial Flaw Bypass Extension Defence
  • 原文地址:https://www.cnblogs.com/eastjade/p/1871268.html
Copyright © 2020-2023  润新知