zoukankan      html  css  js  c++  java
  • NopCommerce 增加 Customer Field

    预期效果:

    Customer表新增一个Column

    该新增字段可以在Admin段 新增 修改 列表查询及显示

    示例步骤:

    0.数据库表修改

    alter table [Customer] add MemberType nvarchar(2) ;

    1.Entity处理

    LibrariesNop.CoreDomainCustomersCustomer.cs

    仿照 Username 新增

    /// <summary>

    /// Gets or sets the Member Type

    /// </summary>

    public string MemberType { get; set; }

      

    2.EntityMap处理

    LibrariesNop.DataMappingCustomersCustomerMap.cs

    新增

    this.Property(u => u.MemberType).HasMaxLength(2);

    3.EntityModel处理

    PresentationNop.WebAdministrationModelsCustomersCustomerModel.cs

    仿照 GenderEnabled 及 Gender 新增         

    //可以不增加MemberTypeEnabled

    //如需该设置的控制 可 NopCommerce 增加 Customer Settings

    public bool MemberTypeEnabled { get; set; }

    [NopResourceDisplayName("Admin.Customers.Customers.Fields.MemberType")]

    [AllowHtml]

    public string MemberType { get; set; }

    4.增修页面

    PresentationNop.WebAdministrationViewsCustomer\_CreateOrUpdate.cshtml

    仿照 @if (Model.CompanyEnabled) 新增

    @if (Model.MemberTypeEnabled)

    {

             <div class="form-group">

                       <div class="col-md-3">

                                @Html.NopLabelFor(model => model.MemberType)

                       </div>

                       <div class="col-md-9">

                                @Html.NopEditorFor(model => model.MemberType)

                                @Html.ValidationMessageFor(model => model.MemberType)

                       </div>

             </div>

    }

                               

    5.新增操作

    PresentationNop.WebAdministrationControllersCustomerController.cs

    进入页面时 Model准备

    修改 protected virtual void PrepareCustomerModel 的Action

    新增 model.MemberTypeEnabled = _customerSettings.MemberTypeEnabled;

    新增操作保存时 Post处理

    修改 public ActionResult Create(CustomerModel model, bool continueEditing, FormCollection form)

    的  var customer = new Customer

    新增 MemberType = model.MemberType,

    6.修改操作

    PresentationNop.WebAdministrationControllersCustomerController.cs

    进入页面时 Model准备

    修改 protected virtual void PrepareCustomerModel 的Action

    if (customer != null) 分支下

    新增  model.MemberType = customer.MemberType;

    修改操作保存时 Post处理

    修改 public ActionResult Edit(CustomerModel model, bool continueEditing, FormCollection form)

    仿照 username 新增

    //MemberType

    if (_customerSettings.MemberTypeEnabled )

    {                       

             customer.MemberType = model.MemberType;

    }

    7.列表页面 列表显示

    PresentationNop.WebAdministrationModelsCustomersCustomerListModel.cs

    仿照  ZipPostalCodeEnabled 新增

    public bool MemberTypeEnabled { get; set; }

    列表显示

    PresentationNop.WebAdministrationViewsCustomerList.cshtml

             $("#customers-grid").kendoGrid

    仿照 @if (Model.CompanyEnabled) 新增

    @if (Model.MemberTypeEnabled)

             {

                                <text>{

                                         field: "MemberType",

                                         title: "@T("Admin.Customers.Customers.Fields.MemberType")",

             200

    },</text>

    }

    其 $("#customers-grid").kendoGrid 的 url: "@Html.Raw(Url.Action("CustomerList", "Customer"))",

    PresentationNop.WebAdministrationControllersCustomerController.cs

    对应的  protected virtual CustomerModel PrepareCustomerModelForList(Customer customer)

    return new CustomerModel 增加 MemberType = customer.MemberType,

    8.列表页面 新增查询条件

    1).Model处理

    PresentationNop.WebAdministrationModelsCustomersCustomerListModel.cs

    仿照 SearchZipPostalCode  新增

    [NopResourceDisplayName("Admin.Customers.Customers.List.SearchMemberType")]

    [AllowHtml]

    public string SearchMemberType { get; set; }

    2).Service处理

    LibrariesNop.ServicesCustomersICustomerService.cs

    IPagedList<Customer> GetAllCustomers

    增加查询参数 string memberType=null,

    LibrariesNop.ServicesCustomersCustomerService.cs

    public virtual IPagedList<Customer> GetAllCustomers

    增加查询参数 string memberType=null,

    及仿照 username 增加其Linq过滤

    if (!String.IsNullOrWhiteSpace(memberType))

        query = query.Where(c => c.MemberType.Contains(memberType));

    3).Controller Action 处理

    PresentationNop.WebAdministrationControllersCustomerController.cs

    public ActionResult CustomerList(

    var customers = _customerService.GetAllCustomers( 中 新增

     memberType:model.SearchMemberType,

            

    4).页面处理

    PresentationNop.WebAdministrationViewsCustomerList.cshtml

    仿照 @if (Model.ZipPostalCodeEnabled) 新增

    @if (Model.MemberTypeEnabled )

    {

             <div class="form-group">

                       <div class="col-md-4">

                                @Html.NopLabelFor(model => model.SearchMemberType)

                       </div>

                       <div class="col-md-8">

                                @Html.NopEditorFor(model => model.SearchMemberType)

                       </div>

             </div>

    }

    js查找及新增SearchMemberType

     $("".concat("#@Html.FieldIdFor(model => model.SearchEmail),",

    "#@Html.FieldIdFor(model => model.SearchUsername),",

    "#@Html.FieldIdFor(model => model.SearchMemberType),",

    js查找及新增SearchMemberType

    function additionalData() {

    var data = {

             SearchCustomerRoleIds: $('#@Html.FieldIdFor(model => model.SearchCustomerRoleIds)').val(),

             SearchEmail: $('#@Html.FieldIdFor(model => model.SearchEmail)').val(),

             SearchMemberType: $('#@Html.FieldIdFor(model => model.SearchMemberType)').val(),

                                                                                         

    9.增加文本资源

    运行站点

    Admin -> Configuration -> Languages -> Edit

    -> String resources -> Add new record

    Admin.Customers.Customers.Fields.MemberType

    Admin.Customers.Customers.List.SearchMemberType

            

            

    10.解决方案 Clean 和 Rebuild

    运行站点 查看效果

  • 相关阅读:
    BZOJ3197:[SDOI2013]刺客信条——题解
    C 程序与 C++ 程序之间的相互调用
    使用Dev C++调试(debug)程序
    ARM 汇编指令 ADR 与 LDR 使用
    华为交换机以 LACP 模式实现链路聚合
    DLCI 简介
    华为路由器帧中继 FR 实验
    GVRP 的工作机制和工作模式
    华为路由器 HDLC 实验
    华为路由器 IPSec 与 GRE 结合实验
  • 原文地址:https://www.cnblogs.com/freeliver54/p/6179237.html
Copyright © 2011-2022 走看看