• 一步一步教你使用AgileEAS.NET基础类库进行应用开发WinForm应用篇实例一个模块(商品字典)


            本文是一步一步教你使用AgileEAS.NET基础进行应用开发系统的WinForm应用篇的开篇,从本文起开始大家将看到一个距离真实应用非常接的开发案例。

    商品字典管理

             商品字典管理完成产品进销存业务业务中用到的基础信息,产品字典的增加、修改、删除等业务,它不是一个进销存在主体业务,只是用于为主体业务提供基础支持的一个辅助业务。

    功能和界面预览

             商品字典管理完成产品进销存业务业务中用到的基础信息,产品字典的增加、修改、删除等业务,它不是一个进销存在主体业务,只是用于为主体业务提供基础支持的一个辅助业务。

    image

             字典查询:根据产品编码或者产品名称的拼音简码检索数据库与之匹配的产品字典数据,并且显示的数据列表之上。

             查询结果打印:将满足查询的结果打印输出,演示报表的使用。

             添加新的产品字典:调用产品字典添加界面向系统中增加一个新的产品字典。

             修改现有产品字典:调用产品字典修改界面修改指定的产品字典记录。

             删除现有产品字典:删除系统中已经存在的某个产品字典。

    代码的重新生成

             现在我们可以来看看如何实现,不过,我们在看这个实现之前先插入一个小插曲,我们来看看我们的数据查询需求,“根据产品编码或者产品名称的拼音简码检索数据库与之匹配的产品字典数据”显然是不满足这个需求的,我们此前定义的数据结构之中没有定义拼音简码,我们现在来增加上,并且修正此前定义的几个bug。

    WG[YF_6C1I3NS40`E%V18M4

             然后重新生成代码,输出目录选择本解雇方案代码目录,不要选中“生成解雇方案”:

    image
              因为生成的代码采用了分部的的结构,数据层中与数据表、实体定义相关的对象定义信息都保存的项目的Generat目录下的名称带有Generat的代码文件中,而自定义的数据层业务逻辑被保存在项目目录中的不带Generat的代码文件之中,也就是说,当数据对象的定义发生变更并且重新生成代码文件后,不会覆盖我们编写的自定义处理,只覆盖与数据对象定义相关的代码文件,以保护程序员的投资。

    实现我们的业务

             对于字典的查询业务处理,我们需要在数据层接口IProductList编写一个数据查询方法void GetProductList(string code)并在SQLServer实现层项目中实现这个定义: 

    1         public void GetProductList(string code)
    2         {
    3             Condition condition = this.CreateCondition();
    4             condition.AddElement("CODE", code, ElementType.MatchPrefix);
    5             condition.AddElement("PYCODE", code, ElementType.MatchPrefix,ElementCombineType.Or);
    6             condition.AddOrderElement("IDN"true);
    7             this.Query(condition);
    8         }

             UI代码之中增加一个查询结果显示代码:

     1         internal void LoadDictList()
     2         {
     3             IProductList dictList = DALHelper.DALManager.CreateProductList();
     4             dictList.GetProductList(this.tbSeach.Text);
     5 
     6             try
     7             {
     8                 this.Cursor = Cursors.WaitCursor;
     9                 this.lvInfo.BeginUpdate();
    10                 this.lvInfo.Tag = dictList;
    11                 this.lvInfo.Items.Clear();
    12                 foreach (IProduct dict in dictList.Rows)
    13                 {
    14                     ListViewItem item = new ListViewItem(new string[] { string.Empty, dict.Code, dict.Name, dict.Spec, dict.Unit,dict.PYCode, dict.Description }, 0);
    15                     item.Tag = dict;
    16                     this.lvInfo.Items.Add(item);
    17                 }
    18             }
    19             finally
    20             {
    21                 this.lvInfo.EndUpdate();
    22                 this.Cursor = Cursors.Default;
    23             }
    24         }

             字典的添加与修改处理,我们在UI层中增加如下窗体:

    %7I{P[[3[]9ERAYCE{X)Z1J

             并增加如下数据显示与写回代码:

    代码
     1         public IProduct Product
     2         {
     3             get
     4             {
     5                 return this.product;
     6             }
     7             set
     8             {
     9                 this.product = value;
    10 
    11                 if (value != null)
    12                 {
    13                     this.DataDisplay();
    14                 }
    15             }
    16         }
    17 
    18         private void DataDisplay()
    19         {
    20             this.tbCode.Text = this.Product.Code;
    21             this.tbName.Text = this.Product.Name;
    22             this.tbSpec.Text = this.Product.Spec;
    23             this.tbUnit.Text = this.Product.Unit;
    24             this.tbDescription.Text = this.Product.Description;
    25             this.tbPYCode.Text = this.Product.PYCode;
    26         }
    27 
    28         bool VerifyInput()
    29         {
    30             return true;
    31         }
    32 
    33         private void btnOK_Click(object sender, EventArgs e)
    34         {
    35             if (!this.Validate())
    36             {
    37                 this.closed = -1;
    38                 return;
    39             }
    40 
    41             try
    42             {
    43                 IProduct dict = null;
    44 
    45                 if(this.Product == null)
    46                 {
    47                     dict = DALHelper.DALManager.CreateProduct();
    48                     dict.Idn = dict.GetMaxIdn();
    49                 }
    50                 else
    51                 {
    52                     dict = this.Product;
    53                 }
    54 
    55                 dict.Code = this.tbCode.Text;
    56                 dict.Name = this.tbName.Text;
    57                 dict.Spec = this.tbSpec.Text;
    58                 dict.Unit = this.tbUnit.Text;
    59                 dict.Description = this.tbDescription.Text;
    60                 dict.PYCode = this.tbPYCode.Text;
    61 
    62                 
    63                 if(this.Product ==null)
    64                 {
    65                     dict.Insert() ;//
    66                     this.Product = dict;
    67                 }
    68                 else
    69                     dict.Update();
    70 
    71                 this.closed = 0;
    72             }
    73             catch(System.Exception exc)
    74             {
    75                 MessageBox.Show(this"在保存药品字典时出错,错误:" + exc.Message, "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
    76                 this.closed = -1;
    77             }
    78         }

             字典的删除业务,我们安排在当选择某个商品字典之后可以通过工具条或者快捷菜单中的“删除”完成操作,我们来看看其处理代码:

    代码
     1         internal void ProductDel()
     2         {
     3             if (this.lvInfo.SelectedItems.Count < 1return;
     4 
     5             if(MessageBox.Show(this"是否确认删除所选择的药品字典?""确认", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.No)
     6             {
     7                 return;
     8             }
     9 
    10             try
    11             {
    12                 
    13                 foreach(ListViewItem item in this.lvInfo.SelectedItems)
    14                 {
    15                     IProduct dict = item.Tag as IProduct;
    16                     dict.Delete();
    17                 }
    18 
    19                 foreach(ListViewItem item in this.lvInfo.SelectedItems)
    20                 {
    21                     this.lvInfo.Items.Remove(item);
    22                 }
    23             }
    24             catch(System.Exception exc)
    25             {
    26                 MessageBox.Show(this"在删除药品字典时出错,错误:" + exc.Message, "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
    27             }
    28         }

    我们来编译并且运行这个示例:

    image 

               有关本例子所涉及的数据表结构请参考基于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

  • 相关阅读:
    ncnn 编译配置
    Android 配置 ncnn
    Android Studio 配置 OpenCV4+
    ROS catkin cheat sheet
    CMake 使用代理服务器
    Git设置代理服务器
    安卓assets处理
    【Android】Toast on non-UI thread
    高级语言编译和运行系统
    linux环境安装包方式
  • 原文地址:https://www.cnblogs.com/eastjade/p/1845509.html
Copyright © 2020-2023  润新知