详细介绍Enterprise Solution 二次开发的流程步骤,主要包括数据输入窗体(Entry Form),查询(Query/Enquiry),报表(Report)三个重要的二次开发项目。

数据输入窗体开发 Entry Form

当涉及到字段的增加或增加数据库表时,开发新功能界面有以下几个主要步骤。

1  修改数据库增加表或字段,用LLBL Gen 生成新的实体映射类型定义文件。

LLBL Gen 可检测到字段的变化,增加字段或减少字段可自动更新实体映射定义文件。需要设定参数选项,如下图所示:

LLBL Gen 在生成实体的属性时,对于数据库字段可为空值的类型,会生成.NET的可空类型(nullable)类型。在我的实际项目中常常会取消这一特性,LLBL Gen会智能的知道实体哪些属性值发生变化,对于可空类型映射的属性不会生成UPDATE语句块,让它保持数据库中的空值即可(NULL)。

2  增加功能编码,增加权限,增加菜单项。

以销售合同功能(SLSOCE)为例,通过下面的脚本可增加系统功能(ADFUNC), 增加菜单项(ADMNUD)和增加权限(ADAUTD)。

  1.  
  1. DECLARE
  1. @LastLineNo INTEGER,
  1. @ModuleCode NVARCHAR(4),
  1. @FunctionCode NVARCHAR(8),
  1. @FunctionDesc NVARCHAR(40),
  1. @SeriesCode NVARCHAR(8),
  1. @SeriesOption NVARCHAR(1)
  1.  
  1. SET @ModuleCode = 'SLSO'
  1. SET @FunctionCode = 'SLSOCE'
  1. SET @FunctionDesc = N'Sales Contract Entry'
  1. SET @SeriesCode = ''
  1. SET @SeriesOption = N'N'
  1.  
  1. -- Check for Function
  1. IF NOT EXISTS ( SELECT * FROM [ADFUNC] WHERE Module_Code = @ModuleCode AND Function_Code = @FunctionCode)
  1. BEGIN
  1.  
  1. UPDATE [ADMODU] SET [Last_Line_No] = [Last_Line_No] + 1
  1. WHERE [Module_Code] = @ModuleCode
  1.  
  1. SELECT @LastLineNo = Last_Line_No FROM ADMODU WHERE Module_Code = @ModuleCode
  1.  
  1. IF @LastLineNo IS NOT NULL
  1. BEGIN
  1. INSERT [ADFUNC]
  1. ([Module_Code], [Function_No], [Function_Code], [Description],
  1. [Suspended], [Series_Option], [Series_Code],
  1. [Created_Date], [Created_By], [Revised_Date], [Revised_By],
  1. [OWNER_BRANCH],[SOURCE_BRANCH],[Icon])
  1. VALUES
  1. (@ModuleCode, @LastLineNo, @FunctionCode, @FunctionDesc, N'N', @SeriesOption, @SeriesCode,
  1. GETDATE(), 'MIS', GETDATE(), 'MIS', N'', N'','')
  1.  
  1. IF 'EMP'='EMP' OR '%SYS%'='EMPT' BEGIN
  1. INSERT [ADAUTD]
  1. ([User_Group], [Module_Code], [Function_No], [Function_Code], [Description],
  1. [Suspended], [Allow_Read], [Allow_Create], [Allow_Update], [Allow_Delete], [Allow_Print],
  1. [Allow_Post], [Allow_All_Tran])
  1. VALUES
  1. ('SYSADM', @ModuleCode, @LastLineNo, @FunctionCode, @FunctionDesc,
  1. 'N' ,'Y', 'Y', 'Y', 'Y', 'Y',
  1. 'Y', 'Y')
  1.  
  1. INSERT [ADMNUD]
  1. ([User_Group], [Process_Code], [Function_Code], [Description], [Menu_Type], [Menu_Code],
  1. [Response_Type], [Suspended])
  1. VALUES
  1. ('SYSADM', 'M3_REP', @FunctionCode, @FunctionDesc, 'DOC', '',
  1. 'STDFUNC', 'N')
  1. END
  1.  
  1. END
  1. END
  1. GO

使用SQL语句的好处是可支持自动化更新部署,当系统检查到有版本更新时可自动跑SQL语句,当客户数量比较多时这个方法可提高效率。

3 生成接口文件与接口实现类。

Code Smith模板化的代码生成极大的方便了代码生成功能的开发,参考如下的接口模板文件Interface.cst文件,源文件如下所示:

  1. <%@ CodeTemplate Language="C#" TargetLanguage="C#" Src="" Inherits="" Debug="True" Description="Template description here." %>
  1. <%@ Property Name="EntityPicker" Type="ISL.Extension.EntityPickerProperty" Optional="False" Category="Project" Description="This property uses a custom modal dialog editor." %>
  1. <%@ Property Name="AssemblyFile" Type="System.String" Default="" Optional="False" Category="Project" Description=""
  1. Editor="System.Windows.Forms.Design.FileNameEditor"%>
  1.  
  1. <%@ Assembly Name="System.Data" %>
  1. <%@ Import Namespace="System.Data" %>
  1. <%@ Assembly Name="ISL.Empower.Extension" %>
  1. <%@ Import Namespace="ISL.Extension" %>
  1. <%@ Import Namespace="System.Collections.Generic" %>
  1. <%@ Assembly Name="SD.LLBLGen.Pro.ORMSupportClasses.NET20" %>
  1. <%@ Import Namespace="SD.LLBLGen.Pro.ORMSupportClasses" %>
  1.  
  1. <script runat="template">
  1.  
  1. public string EntityName
  1. {
  1. get
  1. {
  1. return EntityPicker.EntityName;
  1. }
  1. }
  1.  
  1. public string ShortEntityName
  1. {
  1. get
  1. {
  1. return EntityName.Substring(0,EntityName.Length-6);
  1. }
  1. }
  1.  
  1. public string FullEntityName
  1. {
  1. get
  1. {
  1. return string.Format("{0}.EntityClasses.{1}", BusinessLogicProjectName, EntityName);
  1. }
  1. }
  1.  
  1. private string _businessLogicProjectName;
  1.  
  1. public string BusinessLogicProjectName
  1. {
  1. get
  1. {
  1. if(string.IsNullOrWhiteSpace(_businessLogicProjectName))
  1. _businessLogicProjectName=EntityClassHelper.PrefixProjectName(AssemblyFile);
  1. return _businessLogicProjectName;
  1. }
  1. }
  1.  
  1. public string EntityParamerList
  1. {
  1. get
  1. {
  1. IEntity2 policy = EntityClassHelper.GetEntityObject(AssemblyFile, EntityPicker.EntityName);
  1. string parm = string.Empty;
  1. List<string> parms=new List<string>();
  1. foreach (IEntityField2 field in policy.PrimaryKeyFields)
  1. {
  1. parm = string.Format("{0} {1}", field.DataType.Name, field.Name);
  1. parms.Add(parm);
  1. }
  1. return string.Join(",", parms.ToArray());
  1. }
  1. }
  1.  
  1. public string EntityLowercaseName
  1. {
  1. get
  1. {
  1. return EntityPicker.EntityName.Substring(0, 1).ToLower() + EntityPicker.EntityName.Substring(1);
  1. }
  1. }
  1.  
  1. </script>
  1.  
  1. using System;
  1. using System.Collections.Generic;
  1. using System.Data;
  1. using System.Text;
  1. using SD.LLBLGen.Pro.ORMSupportClasses;
  1.  
  1. using <%=BusinessLogicProjectName%>;
  1. using <%=BusinessLogicProjectName%>.FactoryClasses;
  1. using <%=BusinessLogicProjectName%>.EntityClasses;
  1. using <%=BusinessLogicProjectName%>.HelperClasses;
  1. using <%=BusinessLogicProjectName%>.InterfaceClasses;
  1. using <%=BusinessLogicProjectName%>.DatabaseSpecific;
  1.  
  1. namespace <%=BusinessLogicProjectName%>.InterfaceClasses
  1. {
  1. public interface I<%=ShortEntityName%>Manager
  1. {
  1. <%=EntityName%> Get<%=ShortEntityName%>(Guid sessionId,<%=EntityParamerList %>);
  1. <%=EntityName%> Get<%=ShortEntityName%>(Guid sessionId,<%=EntityParamerList %>,IPrefetchPath2 prefetchPath);
  1. <%=EntityName%> Get<%=ShortEntityName%>(Guid sessionId,<%=EntityParamerList %>,IPrefetchPath2 prefetchPath,ExcludeIncludeFieldsList fieldList);
  1.  
  1. EntityCollection Get<%=ShortEntityName%>Collection(Guid sessionId,IRelationPredicateBucket filterBucket);
  1. EntityCollection Get<%=ShortEntityName%>Collection(Guid sessionId,IRelationPredicateBucket filterBucket,ISortExpression sortExpression);
  1. EntityCollection Get<%=ShortEntityName%>Collection(Guid sessionId,IRelationPredicateBucket filterBucket,ISortExpression sortExpression, IPrefetchPath2 prefetchPath);
  1. EntityCollection Get<%=ShortEntityName%>Collection(Guid sessionId,IRelationPredicateBucket filterBucket, ISortExpression sortExpression, IPrefetchPath2 prefetchPath, ExcludeIncludeFieldsList fieldList);
  1.  
  1. <%=EntityName%> Save<%=ShortEntityName%>(Guid sessionId,<%=EntityName%> <%=EntityLowercaseName%>);
  1. <%=EntityName%> Save<%=ShortEntityName%>(Guid sessionId,<%=EntityName%> <%=EntityLowercaseName%> ,EntityCollection entitiesToDelete);
  1. <%=EntityName%> Save<%=ShortEntityName%>(Guid sessionId,<%=EntityName%> <%=EntityLowercaseName%>, EntityCollection entitiesToDelete, string seriesCode);
  1.  
  1. void Delete<%=ShortEntityName%>(Guid sessionId,<%=EntityName%> <%=EntityLowercaseName%>);
  1.  
  1. bool Is<%=ShortEntityName%>Exist(Guid sessionId,<%=EntityParamerList %>);
  1. bool Is<%=ShortEntityName%>Exist(Guid sessionId,IRelationPredicateBucket filterBucket);
  1. int Get<%=ShortEntityName%>Count(Guid sessionId,IRelationPredicateBucket filterBucket);
  1.  
  1. <%=EntityName%> Clone<%=ShortEntityName%>(Guid sessionId,<%=EntityParamerList %>);
  1. void Post<%=ShortEntityName%>(Guid sessionId,<%=EntityParamerList %>);
  1. void Post<%=ShortEntityName%>(Guid sessionId,<%=EntityName%> <%=EntityLowercaseName%>);
  1. }
  1. }

在Code Smith代码生成器中跑Interface.cst模板,可得到如下的接口文件:

  1.  
  1. using System;
  1. using System.Collections.Generic;
  1. using System.Data;
  1. using System.Text;
  1. using SD.LLBLGen.Pro.ORMSupportClasses;
  1.  
  1. using ISL.BusinessLogic;
  1. using ISL.BusinessLogic.FactoryClasses;
  1. using ISL.BusinessLogic.EntityClasses;
  1. using ISL.BusinessLogic.HelperClasses;
  1. using ISL.BusinessLogic.InterfaceClasses;
  1. using ISL.BusinessLogic.DatabaseSpecific;
  1.  
  1. namespace ISL.BusinessLogic.InterfaceClasses
  1. {
  1. public interface ISalesContractManager
  1. {
  1. SalesContractEntity GetSalesContract(Guid sessionId, String ContractNo);
  1. SalesContractEntity GetSalesContract(Guid sessionId, String ContractNo, IPrefetchPath2 prefetchPath);
  1. SalesContractEntity GetSalesContract(Guid sessionId, String ContractNo, IPrefetchPath2 prefetchPath, ExcludeIncludeFieldsList fieldList);
  1.  
  1. EntityCollection GetSalesContractCollection(Guid sessionId, IRelationPredicateBucket filterBucket);
  1. EntityCollection GetSalesContractCollection(Guid sessionId, IRelationPredicateBucket filterBucket, ISortExpression sortExpression);
  1. EntityCollection GetSalesContractCollection(Guid sessionId, IRelationPredicateBucket filterBucket, ISortExpression sortExpression, IPrefetchPath2 prefetchPath);
  1. EntityCollection GetSalesContractCollection(Guid sessionId, IRelationPredicateBucket filterBucket, ISortExpression sortExpression, IPrefetchPath2 prefetchPath, ExcludeIncludeFieldsList fieldList);
  1.  
  1. SalesContractEntity SaveSalesContract(Guid sessionId, SalesContractEntity salesContractEntity);
  1. SalesContractEntity SaveSalesContract(Guid sessionId, SalesContractEntity salesContractEntity, EntityCollection entitiesToDelete);
  1. SalesContractEntity SaveSalesContract(Guid sessionId, SalesContractEntity salesContractEntity, EntityCollection entitiesToDelete, string seriesCode);
  1.  
  1. void DeleteSalesContract(Guid sessionId, SalesContractEntity salesContractEntity);
  1.  
  1. bool IsSalesContractExist(Guid sessionId, String ContractNo);
  1. bool IsSalesContractExist(Guid sessionId, IRelationPredicateBucket filterBucket);
  1. int GetSalesContractCount(Guid sessionId, IRelationPredicateBucket filterBucket);
  1.  
  1. SalesContractEntity CloneSalesContract(Guid sessionId, String ContractNo);
  1. void PostSalesContract(Guid sessionId, String ContractNo);
  1. void PostSalesContract(Guid sessionId, SalesContractEntity salesContractEntity);
  1. }
  1. }

接口的实现类(Manager.cst) 也只需要借助于Code Smith生成即可。生成完成之后,需要增加主从表的处理,比如主表的保存和删除方法需要做少量代码修改。

保存方法增加单据编码功能代码,如下代码片段所示:

  1. public SalesContractEntity SaveSalesContract(Guid sessionId, SalesContractEntity SalesContract, EntityCollection entitiesToDelete, string seriesCode)
  1. {
  1. string currentRefNo = string.Empty;
  1. using (DataAccessAdapterBase adapter = GetCompanyDataAccessAdapter(sessionId))
  1. {
  1. try
  1. {
  1. adapter.StartTransaction(IsolationLevel.ReadCommitted, "Save SalesContract");
  1. if (SalesContract.IsNew && seriesCode != string.Empty)
  1. {
  1. currentRefNo = SalesContract.ContractNo;
  1. IDocumentSerializationManager serializationManager = ClientProxyFactory.CreateProxyInstance<IDocumentSerializationManager>();
  1. SalesContract.ContractNo = serializationManager.GetNextSerialNo(sessionId, seriesCode, SalesContract.ContractNo, SalesContract);
  1. }

保存方法增加子表的保存方法

  1. ISalesContractDetailManager contractDetailManager = ClientProxyFactory.CreateProxyInstance<ISalesContractDetailManager>();
  1. if (entitiesToDelete != null)
  1. {
  1. foreach (IEntity2 entity in entitiesToDelete)
  1. {
  1. if (entity is SalesContractDetailEntity)
  1. contractDetailManager.DeleteSalesContractDetail(sessionId, (SalesContractDetailEntity)entity);
  1. }
  1. }
  1.  
  1. adapter.SaveEntity(SalesContract, true, false);
  1.  
  1. foreach (SalesContractDetailEntity salesContractDetailEntity in SalesContract.SalesContractDetail)
  1. {
  1. contractDetailManager.SaveSalesContractDetail(sessionId, salesContractDetailEntity);
  1. }

遵守数据库表保存的基本原则,保存时先保存主表,再保存子表,删除时是先删除子表,再删除主表。

删除方法增加删除子表的代码:

  1. public void DeleteSalesContract(Guid sessionId, SalesContractEntity SalesContract)
  1. {
  1. using (DataAccessAdapter adapter = GetCompanyDataAccessAdapter(sessionId))
  1. {
  1. if (!adapter.IsEntityExist<SalesContractEntity>(SalesContract))
  1. return;
  1.  
  1. try
  1. {
  1. adapter.StartTransaction(IsolationLevel.ReadCommitted, "Delete SalesContract");
  1.  
  1. ISalesContractDetailManager contractDetailManager = ClientProxyFactory.CreateProxyInstance<ISalesContractDetailManager>();
  1. foreach (SalesContractDetailEntity salesContractDetailEntity in SalesContract.SalesContractDetail)
  1. {
  1. contractDetailManager.DeleteSalesContractDetail(sessionId, salesContractDetailEntity);
  1. }

LLBL Gen没有采取级联的方式来做数据的删除,也不推荐这样处理,这样对于数据的验证相对难于处理。数据库在确认删除与应用程序的验证方法方面难于沟通,所以LLBL Gen 推荐实体相关的操作都由应用程序控制,要删除数据,要验证逻辑,都交给应用程序来实现。

4 增加界面文件,拖放控件,绑定数据源,用界面代码生成器(EntryForm.cst)生成界面实现文件。

自从用上了Visual Studio 2010, 窗体设计器的性能比之前的版本提升很大,Visual Studio 2012/2013的窗体设计器性能更加卓越,期待着即将发布的Visual Studio 2015能持续改善窗体设计器的性能。Visual Studio在全球有众多的客户,提高性能就意味着加快工作效率,也就是实现了节约能源(电力消耗),Google也有很多程序改善,提高程序性能可环保,节约电能开支。

从Visual Studio 2010迁移到Visual Studio 2012/2013的一个很主要的理由也是因为它的窗体设计器效率高。

再来看一下销售合同界面的主要代码,下面的代码是用Code Smith模板生成的,实现了界面代码自动生成:

  1. [FunctionCode("SLSOCE")]
  1. public partial class SalesContractEntry : EntryForm
  1. {
  1. private ISalesContractManager _salesContractEntityManager = null;
  1. private SalesContractEntity _salesContractEntity = null;
  1.  
  1. public SalesContractEntry()
  1. {
  1. InitializeComponent();
  1. }
  1.  
  1. protected override void OnLoad(EventArgs e)
  1. {
  1. if (!DesignMode)
  1. this._salesContractEntityManager = ClientProxyFactory.CreateProxyInstance<ISalesContractManager>();
  1. base.OnLoad(e);
  1. }
  1.  
  1. protected override void InitNavigator(InitNavigatorArgs args)
  1. {
  1. base.InitNavigator(args);
  1. args.SortExpression.Add(SalesContractFields.ContractNo | SortOperator.Ascending);
  1. args.PredicateBucket.PredicateExpression.Add(SalesContractFields.Closed == false);
  1. }
  1.  
  1. protected override EntityBase2 LoadData(Dictionary<string, string> refNo)
  1. {
  1. base.LoadData(refNo);
  1. string ContractNo = string.Empty;
  1. if (refNo.TryGetValue("ContractNo", out ContractNo))
  1. {
  1. IPrefetchPath2 prefetchPath = new PrefetchPath2((int) EntityType.SalesContractEntity);
  1. prefetchPath.Add(SalesContractEntity.PrefetchPathSalesContractDetail);
  1. _salesContractEntity = _salesContractEntityManager.GetSalesContract(Shared.CurrentUserSessionId, ContractNo, prefetchPath);
  1. }
  1. else
  1. {
  1. _salesContractEntity = new SalesContractEntity();
  1. }
  1. return _salesContractEntity;
  1. }
  1.  
  1. protected override void InitializeLayout()
  1. {
  1. base.InitializeLayout();
  1. gridSalesOrder.OverrideReadOnlyAppearance(SalesContractDetailFields.OrderDate.Name,true);
  1. gridSalesOrder.OverrideReadOnlyAppearance(SalesContractDetailFields.DueDate.Name, true);
  1. gridSalesOrder.OverrideReadOnlyAppearance(SalesContractDetailFields.Closed.Name, true);
  1. gridSalesOrder.OverrideAllowEditForNewOnlyColumn(SalesContractDetailFields.EntryNo.Name, true);
  1. }
  1.  
  1. protected override void BindControls(EntityBase2 entity)
  1. {
  1. base.BindControls(entity);
  1. this.salesContractBindingSource.DataSource = entity;
  1. }
  1.  
  1. protected override EntityBase2 Add()
  1. {
  1. base.Add();
  1. this._salesContractEntity = new SalesContractEntity();
  1. return _salesContractEntity;
  1. }
  1.  
  1. protected override EntityBase2 Save(EntityBase2 entityToSave, EntityCollection entitiesToDelete)
  1. {
  1. SalesContractEntity SalesContractEntity = (SalesContractEntity)entityToSave;
  1. this._salesContractEntity = this._salesContractEntityManager.SaveSalesContract(Shared.CurrentUserSessionId, SalesContractEntity, entitiesToDelete, SeriesCode);
  1. return this._salesContractEntity;
  1. }
  1.  
  1. protected override void Delete(EntityBase2 entityToDelete)
  1. {
  1. base.Delete(entityToDelete);
  1. SalesContractEntity SalesContractEntity = (SalesContractEntity)entityToDelete;
  1. this._salesContractEntityManager.DeleteSalesContract(Shared.CurrentUserSessionId, SalesContractEntity);
  1. }
  1.  
  1. protected override object Clone(Dictionary<string, string> refNo)
  1. {
  1. base.Clone(refNo);
  1. return null;
  1. }
  1.  
  1. protected override void ReleaseResources()
  1. {
  1. base.ReleaseResources();
  1. try
  1. {
  1. _salesContractEntity = null;
  1. _salesContractEntityManager = null;
  1. }
  1. catch
  1. {
  1.  
  1. }
  1. }
  1.  
  1. private void btnPost_Click(object sender, EventArgs e)
  1. {
  1. this.PerformPost(true);
  1. }
  1.  
  1. protected override void Post(EntityBase2 entityToPost)
  1. {
  1. base.Post(entityToPost);
  1. SalesContractEntity resignEntity = entityToPost as SalesContractEntity;
  1. _salesContractEntityManager.PostSalesContract(Shared.CurrentUserSessionId, resignEntity);
  1. ISL.WinUI.Shared.ShowInfo("Transaction ({0}) is posted successfully", new object[] { resignEntity.ContractNo });
  1. }
  1. }

编译运行一下程序,如下所示,一个基本的增删查改的功能就完成了,开发效率非常高,代码自动化程度也高。

5 增加类型初始化,验证,查找与钻取,自动带值,主从表事件关联

在实体类型定义文件中,增加初始化代码,比如单据默认值(单据的创建日期,单据的默认状态),系统默认值(单据的创建用户和期间):

  1. public partial class SalesContractEntity
  1. {
  1. protected override void OnInitialized()
  1. {
  1. base.OnInitialized();
  1.  
  1. // Assign default value for new entity
  1. if (Fields.State == EntityState.New)
  1. {
  1. #region DefaultValue
  1.  
  1. // __LLBLGENPRO_USER_CODE_REGION_START DefaultValue
  1. this.Fields[(int) SalesContractFieldIndex.Closed].CurrentValue = false;
  1. // __LLBLGENPRO_USER_CODE_REGION_END
  1. #endregion
  1. }
  1.  
  1. InitEventHandlers();
  1. this.Validator = Singleton<SalesContractValidator>.Instance;
  1. }

增加从表默认值,比如主表的主键是参考编号,从表则用两个主键,前一个是参考编号,后一个主键是依次增长的自动序列号(10,20,30…..或1,2,3……):

  1. private void JobOrderAmendmentRemarks_EntityAdded(object sender, CollectionChangedEventArgs e)
  1. {
  1. if (e.InvolvedEntity.IsNew)
  1. {
  1. SalesContractDetailEntity remark = (SalesContractDetailEntity)e.InvolvedEntity;
  1. decimal max = 0;
  1. foreach (SalesContractDetailEntity jobOrderAmendmentRemark in this.SalesContractDetail)
  1. {
  1. if (jobOrderAmendmentRemark.EntryNo > max)
  1. {
  1. max = jobOrderAmendmentRemark.EntryNo;
  1. }
  1. }
  1. remark.EntryNo = max + Shared.CompanySetting.AutoIncBy;
  1. }
  1. }

如果你有Enterprise Solution 开发框架的例子代码,这些代码都是可以从原有的文件中直接拷贝过来稍做修改后即可,无任何技巧,唯手熟练。

查找与钻取

给客户编号属性值增加查找,设置Lookup属性即可。

增加查找一般都需要增加验证,增加客户编号验证。

  1. [Serializable]
  1. public partial class SalesContractValidator : ValidatorBase
  1. {
  1. // Add your own validation code between the two region markers below. You can also use a partial class and add your overrides in that partial class.
  1.  
  1. // __LLBLGENPRO_USER_CODE_REGION_START ValidationCode
  1. public override bool ValidateFieldValue(IEntityCore involvedEntity, int fieldIndex, object value)
  1. {
  1. bool result = base.ValidateFieldValue(involvedEntity, fieldIndex, value);
  1. if (!result) return false;
  1.  
  1. switch ((SalesContractFieldIndex) fieldIndex)
  1. {
  1. case SalesContractFieldIndex.CustomerNo:
  1. return this.ValidateCustomerNo((string) value);
  1. }
  1.  
  1. return true;
  1. }
  1.  
  1. private bool ValidateCustomerNo(string value)
  1. {
  1. if (!string.IsNullOrEmpty(value))
  1. {
  1. ICustomerManager customerManager = ClientProxyFactory.CreateProxyInstance<ICustomerManager>();
  1. customerManager.ValidateCustomerNo(Shared.CurrentUserSessionId, value);
  1. }
  1.  
  1. return true;
  1. }

增加客户编号钻取,在界面中双击此控件可直接跳转到相应的主档功能。

这样就完成了新功能的开发,想要做到基于EntryForm应用程序的高效率开发,必须通晓框架的功能,知道在哪里插入什么样的代码,这在Enterprise Solution技术培训中会详细讲解。

查询窗体 Query/Enquiry

有两种类型的查询功能,一个是数据输入窗体查询,这种查询需要继承原有的输入窗体(EntryForm),修改属性即可实现,参考下面的销售合同查询功能的实现。

销售合同查询功能全部的代码如下,只需要重写几个方法即可:

  1. [FunctionCode("SLSOCQ")]
  1. public partial class SalesContractEnquiry : SalesContractEntry
  1. {
  1. public SalesContractEnquiry()
  1. {
  1. InitializeComponent();
  1.  
  1. this.SupportAdd = false;
  1. this.SupportEdit = false;
  1. this.SupportDelete = false;
  1. }
  1.  
  1. protected override void InitNavigator(FunctionFormBase.InitNavigatorArgs args)
  1. {
  1. args.PredicateBucket.PredicateExpression.Add(SalesContractFields.Closed == true);
  1. if (!AllowViewAllTransaction)
  1. args.PredicateBucket.PredicateExpression.Add(SalesContractFields.CreatedBy ==ISL.BusinessLogic.Shared.CurrentUserSession.UserId);
  1.  
  1. args.SortExpression.Add(SalesContractFields.ContractNo | SortOperator.Ascending);
  1. }
  1.  
  1. protected override void InitializeLayout()
  1. {
  1. base.InitializeLayout();
  1. this.btnClose.Visible = false;
  1. this.txtContractNo.Lookup.FilterName = "Posted";
  1. }
  1. }

第二种查询是自定义查询,可查询任意条件过滤的多个表的数据。

EntryForm没有使用LLBL Gen的Typeed Lists或Typed Views,而是通过自定义的查询(Custom Query)来实现数据查询。

来看一下送货日记的查询界面,这个界面的主要布局是上面是过滤条件,下面是要根据过滤条件查询到的结果数据。

送货日记的全部源代码如下所示,

  1. [FunctionCode("SQMEGS")]
  1. public sealed partial class ShipmentJournalEnquiry : EnquiryForm
  1. {
  1. private IUserDefinedQueryManager _udqManager;
  1. private bool _show;
  1.  
  1. public ShipmentJournalEnquiry()
  1. {
  1. InitializeComponent();
  1. }
  1.  
  1. protected override void InitializeLayout()
  1. {
  1. base.InitializeLayout();
  1.  
  1. this.grdShipment.DisplayLayout.Bands[0].Columns["Year"].Format = "####";
  1. this.grdShipment.DisplayLayout.Bands[0].Columns["Month"].Format = "##";
  1. }
  1.  
  1. protected override void OnLoad(EventArgs e)
  1. {
  1. base.OnLoad(e);
  1.  
  1. if (!DesignMode)
  1. {
  1. _udqManager = ClientProxyFactory.CreateProxyInstance<IUserDefinedQueryManager>();
  1. _show = true;
  1. }
  1. }
  1.  
  1. protected override void InitNavigator(ISL.WinUI.Forms.FunctionFormBase.InitNavigatorArgs args)
  1. {
  1. base.InitNavigator(args);
  1.  
  1. if (_show)
  1. this.FetchShipment();
  1. }
  1.  
  1. private void FetchShipment()
  1. {
  1. IPredicateExpression predicateExpression = null;
  1. IRelationPredicateBucket filterBucket = new RelationPredicateBucket();
  1.  
  1. if (Shared.CurrentUserSession.AllowAccessAllCustomers)
  1. filterBucket.PredicateExpression.Add(Shared.GetAllowedCustomerNoPredicateExpression(ShipmentFields.CustomerNo));
  1.  
  1. if (!AllowViewAllTransaction)
  1. filterBucket.PredicateExpression.Add(ShipmentFields.CreatedBy == Shared.CurrentUser.UserId);
  1.  
  1. predicateExpression = this.efcCustomerNo.GetPredicateExpression();
  1. if (predicateExpression != null)
  1. filterBucket.PredicateExpression.Add(predicateExpression);
  1.  
  1. predicateExpression = this.efcShipFrom.GetPredicateExpression();
  1. if (predicateExpression != null)
  1. filterBucket.PredicateExpression.Add(predicateExpression);
  1.  
  1. predicateExpression = this.efcPostedFilter.GetPredicateExpression();
  1. if (predicateExpression != null)
  1. filterBucket.PredicateExpression.Add(predicateExpression);
  1.  
  1. predicateExpression = this.efcReturnedFilter.GetPredicateExpression();
  1. if (predicateExpression != null)
  1. filterBucket.PredicateExpression.Add(predicateExpression);
  1.  
  1. ResultsetFields fields = new ResultsetFields(16);
  1. fields.DefineField(ShipmentFields.RefNo, 0);
  1. fields.DefineField(ShipmentFields.ShipmentDate, 1);
  1.  
  1. DbFunctionCall dbYear = new DbFunctionCall("Year", new object[] { ShipmentFields.ShipmentDate });
  1. EntityField2 Year = new EntityField2("Year", dbYear);
  1. fields.DefineField(Year, 2);
  1.  
  1. DbFunctionCall dbMonth = new DbFunctionCall("Month", new object[] { ShipmentFields.ShipmentDate });
  1. EntityField2 Month = new EntityField2("Month", dbMonth);
  1. fields.DefineField(Month, 3);
  1.  
  1. fields.DefineField(ShipmentFields.Posted, 4);
  1. fields.DefineField(ShipmentFields.Returned, 5);
  1. fields.DefineField(ShipmentFields.CustomerNo, 6);
  1. fields.DefineField(ShipmentFields.CustomerName, 7);
  1. fields.DefineField(ShipmentFields.Ccy, 8);
  1. fields.DefineField(ShipmentFields.TotItemAmt, 9);
  1. fields.DefineField(ShipmentFields.Etd, 10);
  1. fields.DefineField(ShipmentFields.ShipFrom, 11);
  1. fields.DefineField(ShipmentFields.PostedBy, 12);
  1. fields.DefineField(ShipmentFields.PostedDate, 13);
  1. fields.DefineField(ShipmentFields.CreatedBy, 14);
  1. fields.DefineField(ShipmentFields.CreatedDate, 15);
  1.  
  1. ISortExpression sortExpression = new SortExpression(ShipmentFields.RefNo | SortOperator.Ascending);
  1.  
  1. DataTable table = QueryHelper.GetQueryResult(Shared.CurrentUserSession.CompanyCode, fields, filterBucket, sortExpression, null, true);
  1. this.shipmentBindingSource.DataSource = table;
  1. this.grdShipment.SetDataBinding(this.shipmentBindingSource, null, true, true);
  1. }
  1.  
  1. private void btnRefresh_Click(object sender, EventArgs e)
  1. {
  1. this.PerformRefresh();
  1.  
  1. //clear filter
  1. this.efcShipFrom.Clear();
  1. this.efcCustomerNo.Clear();
  1. }
  1.  
  1. private void grdShipment_BeforeDrillDown(object sender, DrillDownEventArgs e)
  1. {
  1. if (Shared.StringCompare(this.grdShipment.ActiveCell.Column.Key, ShipmentFields.RefNo.Name) == 0)
  1. {
  1. DataRowView row = this.shipmentBindingSource.Current as DataRowView;
  1. if (row != null)
  1. {
  1. bool isPosted = Convert.ToBoolean(row[ShipmentFields.Posted.Name]);
  1. e.DrillDownValue.FunctionCode = (isPosted ? "SQMETS" : "SLSHSE");
  1. }
  1. }
  1. }
  1.  
  1. protected override void OnBeforeGridExport(CancelableGridDataExportEventArgs args)
  1. {
  1. base.OnBeforeGridExport(args);
  1. args.Grid = this.grdShipment;
  1. }
  1.  
  1. protected override void OnBeforeGridPrint(CancelableGridDataExportEventArgs args)
  1. {
  1. base.OnBeforeGridPrint(args);
  1. args.Grid = this.grdShipment;
  1. }
  1.  
  1. protected override void ReleaseResources()
  1. {
  1. try
  1. {
  1. this._udqManager = null;
  1. this.btnRefresh.Click -= new EventHandler(btnRefresh_Click);
  1. this.grdShipment.BeforeDrillDown -= new ISL.WinUI.DrillDownEventHandler(this.grdShipment_BeforeDrillDown);
  1. }
  1. catch
  1. {
  1. }
  1. base.ReleaseResources();
  1. }

这个功能的数据读取代码没有封装到BackgroundWorker后台线程组件中,当数据量多时会发生界面死锁,用户体验性不好。

报表 Report

水晶报表已经是报表行业的工业标准,完善的功能与强大的客户化开发功能,水晶报表的市场占有率一直很高。微软的后起之秀Reporting Services也相当优秀,Enterprise Solution对这两种类型的报表都有完备的支持。

Enterprise Solution解决了报表开发中令开发人员头疼的界面传参问题,它可以依据一个设定自动生成报表参数界面,通过ReportViewer自动传递到报表文件中。

如下图所示,当开发完成水晶报表之后,需要在报表对话框中增加一个参数设定,用于生成报表的参数:

依据上面的三个参数,报表执行引擎产生一个参数输入界面,如下图所示

用户在界面中输入值,点击查看按钮,报表引擎将用户输入的值传递到报表中,这个过程不需要开发人员的编程或设定。

此外,报表引擎还处理了水晶报表运行库的问题,报表中的标签也会自动翻译。

另外,工作流与计划任务的二次开发也相当常见,因相对复杂需要单独成篇,暂不介绍。

工作流(Workflow)

计划任务(Scheduling)

解析大型.NET ERP系统 窗体、查询、报表二次开发的更多相关文章

  1. 解析大型.NET ERP系统核心组件 查询设计器 报表设计器 窗体设计器 工作流设计器 任务计划设计器

    企业管理软件包含一些公共的组件,这些基础的组件在每个新项目立项阶段就必须考虑.核心的稳定不变功能,方便系统开发与维护,也为系统二次开发提供了诸多便利.比如通用权限管理系统,通用附件管理,通用查询等组件 ...

  2. 解析大型.NET ERP系统 十三种界面设计模式

    成熟的ERP系统的界面应该都是从模板中拷贝出来的,各类功能的界面有规律可遵循.软件界面设计模式化或是艺术性的创作,我认可前者,模式化的界面客户容易举一反三,降低学习门槛.除了一些小部分的功能界面设计特 ...

  3. 解析大型.NET ERP系统架构设计 Framework+ Application 设计模式

    我对大型系统的理解,从数量上面来讲,源代码超过百万行以上,系统有超过300个以上的功能,从质量上来讲系统应该具备良好的可扩展性和可维护性,系统中的功能紧密关联.除去业务上的复杂性,如何设计这样的一个协 ...

  4. 解析大型.NET ERP系统 设计异常处理模块

    异常处理模块是大型系统必备的一个组件,精心设计的异常处理模块可提高系统的健壮性.下面从我理解的角度,谈谈异常处理的方方面面.我的设计仅仅限定于Windows Forms,供参考. 1 定义异常类型 . ...

  5. 解析大型.NET ERP系统 权限模块设计与实现

    权限模块是ERP系统的核心模块之一,完善的权限控制机制给系统增色不少.总结我接触过的权限模块,以享读者. 1 权限的简明定义 ERP权限管理用一句简单的话来说就是:谁 能否 做 那些 事. 文句 含义 ...

  6. 解析大型.NET ERP系统 灵活复杂的界面控件Infragistics WinForms

    Infragistics 是.NET平台优秀的控件供应商,囊括了WinForms,ASP.NET,Silverlight,WPF,Windows Phone等所有关于微软.NET技术的界面控件.借助于 ...

  7. 解析大型.NET ERP系统 查找与钻取

    查找 Lookup 窗体是一个容器,也可以把TextBox,Button也看成是一个容器,可以往容器里面添加按钮. 参考下面的实现代码,给TextBox增加查找按钮. var btn = new Bu ...

  8. 解析大型.NET ERP系统 20条数据库设计规范

    数据库设计规范是个技术含量相对低的话题,只需要对标准和规范的坚持即可做到.当系统越来越庞大,严格控制数据库的设计人员,并且有一份规范书供执行参考.在程序框架中,也有一份强制性的约定,当不遵守规范时报错 ...

  9. 解析大型.NET ERP系统 单据标准(新增,修改,删除,复制,打印)功能程序设计

    ERP系统的单据具备标准的功能,这里的单据可翻译为Bill,Document,Entry,具备相似的工具条操作界面.通过设计可复用的基类,子类只需要继承基类窗体即可完成单据功能的程序设计.先看标准的销 ...

随机推荐

  1. json排序 摘自百度

    var sortBy = function (filed, rev, primer) {    rev = (rev) ? -1 : 1;    return function (a, b) {    ...

  2. android camera 自定义开发

    1.检测是否有摄像头 /** Check if this device has a camera */ private boolean checkCameraHardware(Context cont ...

  3. android开发学习之Layer List

    Android中drawable分为Bitmap File.Nine-Patch File.Layer List.State List.Level List.Transition Drawable.I ...

  4. ASP.Net MVC跳转,分为form的submit提交跳转和ajax跳转

    1,用jquery ajax跳转的话,需要在前台用window.location("跳转网址")来跳转,在success后使用 2,用原声的form的submit来跳转,如下图 3 ...

  5. 道路翻新 (Revamping Trails, USACO 2009 Feb)

    题意:给定m<=50000的1-n有联通的图,求最多可以使K<=20条边变为0的情况下的最短路是多少.. 思路:简单的分层图最短路,对于每个点拆成K个点.. 然后求一边最短路.. code ...

  6. unity 状态机 + svn + 码云 上篇

    最近刚找到在实习,忙于公司一个c++ 项目 ,一直想写博客来着,没时间写今天熬夜打算先献上自己前几天自己封装的一个fsm状态机 话不多说,直接上正题,这篇博客主要是在学校的时候状态机一直使用的是pla ...

  7. 解剖SQLSERVER 第八篇 OrcaMDF 现在支持多数据文件的数据库(译)

    解剖SQLSERVER 第八篇  OrcaMDF 现在支持多数据文件的数据库(译) http://improve.dk/orcamdf-now-supports-databases-with-mult ...

  8. 一个事务复制的bug--更新丢失

    有两种情况会造成更新丢失,第一种是不正确的设置,例如外键或触发器的“Not For Replication” (NFR)属性没有开启.详情请参考http://blogs.msdn.com/b/apgc ...

  9. .NET Core下使用gRpc公开服务(SSL/TLS)

    一.前言 前一阵子关于.NET的各大公众号都发表了关于gRpc的消息,而随之而来的就是一波关于.NET Core下如何使用的教程,但是在这众多的教程中基本都是泛泛而谈,难以实际在实际环境中使用,而该篇 ...

  10. .Net Core下如何管理配置文件

    一.前言 根据该issues来看,System.Configuration在.net core中已经不存在了,那么取而代之的是由Microsoft.Extensions.Cnfiguration.XX ...