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

    运行站点 查看效果

  • 相关阅读:
    pku2226 Muddy Fields
    pku3715 Blue and Red
    关于二分图的最大权匹配
    pku 2262&& pku 2739 && pku 3006
    pku2060 Taxi Cab Scheme
    pku 1486 Sorting Slides
    id、css命名规范
    Git 常用命令
    sublime text3插件使用
    Java实现数据结构栈stack和队列Queue
  • 原文地址:https://www.cnblogs.com/freeliver54/p/6179237.html
Copyright © 2011-2022 走看看