Location>code7788 >text

Known framework hands-on exercise - sales and marketing of basic data

Popularity:435 ℃/2024-07-23 09:33:55

This article describes how to realize the basic data module of the inventory management system, the basic data module includes product information, supplier management and customer management 3 menu pages. Supplier and customer fields are the same, so you can share a page component class.

  • Project code: JxcLite
  • Open source address:/known/JxcLite

1. Configuration module

Run the project, in the [System Management - Module Management] to add commodity information, supplier management, customer management 3 module menu, module basic information, models, pages, forms set up before the video tutorials, here is no longer detailed.

2. Entity classes

existJxcLitesports eventEntitiesUnder the folder addcap (a poem)Two entity class files , entity class code can be directly copied from the module management generated by the model settings code. Article only a brief description of the definition of the entity class , the specific code see the open source , the code definition is as follows:

namespace ;

/// <summary>
/// Commodity Information Class。
/// </summary>
public class JxGoods : EntityBase { }

/// <summary>
/// Business Partner Information Category。
/// </summary>
public class JxPartner : EntityBase { }

3. Table-building scripts

Ideally, the table building scripts are automatically generated during system installation to create entity database tables from entity classes and database types. Here again, the table building script is executed in the traditional manual way, in thesports eventResourcesfolder to addresource file, copy and paste the table building script generated by the [module management - model settings]. The article only briefly describes the table building script, the specific script see the open source, as follows:

CREATE TABLE [JxGoods] (
    [Id]         varchar(50)      NOT NULL PRIMARY KEY,
    ...
    [Files]      nvarchar(500)    NULL
);

CREATE TABLE [JxPartner] (
    [Id]         varchar(50)      NOT NULL PRIMARY KEY,
    ...
    [Note]       ntext            NULL,
    [Files]      nvarchar(500)    NULL
);

4. Service interfaces

existJxcLitesports eventServicesAdd the Base Data Module Service Interface class under the folder with the filename defined asThis interface defines Api access methods for front and back-end interaction, including paging queries, batch deletion of entities, and saving entities. Specific method definitions are as follows:

namespace ;

public interface IBaseDataService : IService
{
    // Query Goods Information by Paging
    Task<PagingResult<JxGoods>> QueryGoodsesAsync(PagingCriteria criteria) ;
    // Delete goods information in batch
    Task<Result> DeleteGoodsesAsync(List<JxGoods> models);
    //Save the product information
    Task<Result> SaveGoodsAsync(UploadInfo<JxGoods> info);

    //Page through supplier and customer information.
    Task<PagingResult<JxPartner>> QueryPartnersAsync(PagingCriteria criteria);; //Batch delete suppliers and customers.
    // Delete supplier and customer information in bulk.
    Task<Result> DeletePartnersAsync(List<JxPartner> models);
    //Save supplier and customer information
    Task<Result> SavePartnerAsync(UploadInfo<JxPartner> info);
}

5. Service realization

existsports eventServicesAdd the implementation class for the Basic Data Module service interface under the folder with the file name defined as, the article only briefly describe the definition of the implementation of the class and inheritance, the specific implementation of the see open source, defined as follows:

namespace ;

class BaseDataService(Context context) : ServiceBase(context), IBaseDataService
{
    public Task<PagingResult<JxGoods>> QueryGoodsesAsync(PagingCriteria criteria) { }
    public Task<Result> DeleteGoodsesAsync(List<JxGoods> models) { }
    public Task<Result> SaveGoodsAsync(UploadInfo<JxGoods> info) { }

    public Task<PagingResult<JxPartner>> QueryPartnersAsync(PagingCriteria criteria) { }
    public Task<Result> DeletePartnersAsync(List<JxPartner> models) { }
    public Task<Result> SavePartnerAsync(UploadInfo<JxPartner> info) { }
}

double-click to openin the projectfile in theAddJxcLiteCoremethod to register the service class, and the front-end component can create instances of the service through the dependency injection factory. The code is as follows:

public static class AppWeb
{
    public static void AddJxcLiteCore(this IServiceCollection services)
    {
        <IBaseDataService, BaseDataService>();
    }
}

6. Data dependency

existsports eventRepositoriesAdd the Base Data Module data dependency class below the folder with the file name defined as, the article only briefly describes the definition of the dependency class, the specific implementation of the see open source, the definition is as follows:

namespace ;

class BaseDataRepository
{
    internal static Task<PagingResult<JxGoods>> QueryGoodsesAsync(Database db, PagingCriteria criteria) { }

    internal static async Task<bool> ExistsGoodsCodeAsync(Database db, JxGoods model) { }

    internal static Task<PagingResult<JxPartner>> QueryPartnersAsync(Database db, PagingCriteria criteria) { }

    internal static async Task<bool> ExistsPartnerNameAsync(Database db, JxPartner model) { }
}

7. Data import category

existsports eventImportsAdd import classes for commodity information, suppliers, and customers below the folder, with file names defined ascap (a poem)Import class name naming convention is: entity class name + Import, the import framework is automatically recognized according to the name of the, the article only briefly describes the definition of the import class, the specific implementation of the see open source, the definition is as follows:

namespace ;

class JxGoodsImport(ImportContext context) : ImportBase<JxGoods>(context)
{
    //Initialize imported fields,Automatic generation of import specificationsExcelfile
    public override void InitColumns() { }
    //执行导入file
    public override async Task<Result> ExecuteAsync(SysFile file) { }
}

class JxPartnerImport(ImportContext context) : ImportBase<JxPartner>(context)
{
    public override void InitColumns() { }
    public override async Task<Result> ExecuteAsync(SysFile file) { }
}

8. Front-end pages

existsports eventPages\BaseDataAdd the Merchandise Information and Business Partners page classes below the folder, with the filename defined ascap (a poem)The functions and pages of these 3 modules are very simple, only the add, delete, change, and check guide functions of a single table, and the form page is configured directly through the online form. List page inheritanceBaseTablePageclass, as the framework class encapsulates the list of commonly used page add, delete, change and check the guide function, so the specific functionality of the list page code is extraordinarily simple, only need to define the operation of the service call method can be, the specific complete code is as follows:

  • Product Information Page
namespace ;

[StreamRendering]
[Route("/bds/goods")]
public class GoodsList : BaseTablePage<JxGoods>
{
    private IBaseDataService Service;

    protected override async Task OnPageInitAsync()
    {
        await ();
        Service = await CreateServiceAsync<IBaseDataService>();
         = ;
    }

    public void New() => (, new JxGoods());
    public void DeleteM() => ();
    public void Edit(JxGoods row) => (, row);
    public void Delete(JxGoods row) => (, row);
    public void Import() => ShowImportForm();
    public async void Export() => await ExportDataAsync();
}
  • Supplier and customer pages
[StreamRendering]
[Route("/bds/suppliers")]
public class SupplierList : PartnerList
{
    protected override string Type => ;
}

[StreamRendering]
[Route("/bds/customers")]
public class CustomerList : PartnerList
{
    protected override string Type => ;
}

public class PartnerList : BaseTablePage<JxPartner>
{
    private IBaseDataService Service;

    //Business Partner Type Virtual Properties,Supplier and customer page overrides。
    protected virtual string Type { get; }

    protected override async Task OnPageInitAsync()
    {
        await ();
        Service = await CreateServiceAsync<IBaseDataService>();
         = QueryPartnersAsync;
    }

    public void New() => (, new JxPartner { Type = Type });
    public void DeleteM() => ();
    public void Edit(JxPartner row) => (, row);
    public void Delete(JxPartner row) => (, row);
    public void Import() => ShowImportForm();
    public async void Export() => await ExportDataAsync();

    private Task<PagingResult<JxPartner>> QueryPartnersAsync(PagingCriteria criteria)
    {
        (nameof(), , Type);
        return (criteria);
    }
}