• 为了让背的单词跟着课堂走,而非网上的随及太多,所以自己设计一个
  • 能按课文单元来索引进行默写
  • 也能总的随及
  • 更能看到单词的总错误,几个人使用
  • 也能看到某一个用户名登录后错的次数

    设计表

  • 两个表,一个是单词本身的表

image.png

  • 一个是某位用户的单词错误表

image.png

  • 这个表这样设计的原因出于以下几点
  • 所有题目错题都可以用这个表,只是类型不一样进行皮配
  • 我觉得错误是,同时显示错误的次数
  • 如是正确后,删除这条记录。

    建立区域菜单大类

  • 首先新建区域Business,手动创建文件夹Areas/Business,在此文件夹创建区域类BusinessArea,填入以下内容

设计背单词库 - 图3

  1. using System;
  2. using System.ComponentModel;
  3. using NewLife;
  4. using NewLife.Cube;
  5. namespace dqltest.Areas.Studys
  6. {
  7. [DisplayName("学习系统")]
  8. public class BusinessArea : AreaBase
  9. {
  10. public BusinessArea() : base(nameof(BusinessArea).TrimEnd("Area")) { }
  11. static BusinessArea() => RegisterArea<BusinessArea>();
  12. }
  13. }

新建实体

  • 新建数据库实体类,参考数据中间件NewLife.XCode教程。新建文件夹Areas/School/Models,将实体类放在此文件夹,具体内容参考这里
  • 将这二个文件COPY到models下

image.png

  • 确保build.tt/build_netcore.tt文件属性中的自定义工具为 TextTemplatingFileGenerator 。
  • image.png

    更改model.xml,设计单词库的二个表

    建EnglishWords表,错题表ErrorTable,注意string要加上Length=”200” ,要不然默认是 varchar(50),或是 加个属性,Length=”-1” ,我是使用的length,因为要是-1,刚会生成longtext字段,好用是好用,在魔方后台的表中,会被默认隐藏。只能是编辑的时候才显出来

    <?xml version="1.0" encoding="utf-8"?>
    <Tables xmlns:xs="http://www.w3.org/2001/XMLSchema-instance" xs:schemaLocation="http://www.newlifex.com http://www.newlifex.com/Model2020.xsd" NameSpace="XCode.Membership" ConnName="Membership" Output="" BaseClass="Entity" xmlns="http://www.newlifex.com/Model2020.xsd">
    <Table Name="EnglishWords" Description="英语单词表" RenderGenEntity="True">
      <Columns>
        <Column Name="ID" DataType="Int32" Identity="True" PrimaryKey="True" Description="编号" />
        <Column Name="Grade" DataType="String" Description="年级" />
        <Column Name="Unit" DataType="String" Description="单元" />
        <Column Name="Word" DataType="String" Description="单词" />
        <Column Name="Pronunciation" DataType="String" Description="读音" />
        <Column Name="Explain" DataType="String" Length="-1" Description="说明" />
        <Column Name="MainPoints" DataType="String" Length="-1" Description="要点" />
        <Column Name="ExampleSentence" DataType="String" Length="-1" Description="例名" />
        <Column Name="Bei1" DataType="String" Length="-1" Description="备注1" />
        <Column Name="Bei2" DataType="String" Length="-1" Description="备注2" />
        <Column Name="WordsCollocation" DataType="String" Length="-1" Description="短语搭配" />
        <Column Name="TestNumbers" DataType="Int32" Description="测试次数" />
        <Column Name="ErrorNumbers" DataType="Int32" Description="错误次数" />
        <Column Name="CreateUser" DataType="String" Description="创建者" />
        <Column Name="CreateTime" DataType="DateTime" Description="创建时间" />
        <Column Name="UpdateTime" DataType="DateTime" Description="更新时间" />
      </Columns>
    </Table>
    <Table Name="ErrorTable" Description="错题库" RenderGenEntity="True">
      <Columns>
        <Column Name="ID" DataType="Int32" Identity="True" PrimaryKey="True" Description="编号" />
        <Column Name="ErrorType" DataType="String" Description="错题类型" />
        <Column Name="ErrorID" DataType="Int32" Description="错题ID" />
        <Column Name="ErrorNumbers" DataType="Int32" Description="错误次数" />
        <Column Name="UpdateTime" DataType="DateTime" Description="更新时间" />
        <Column Name="Bei1" DataType="String" Length="-1" Description="备注1" />
        <Column Name="CreateUser" DataType="String" Description="创建者" />
      </Columns>
    </Table>
    </Tables>
    
  • 然后,我们重新生成一下方案,然后我们在build_netcore.tt上点键,运行自定义工具,点确定

  • 然后你便会发现,MODEL文件下多了好多实体类,也有其中我们建两个表名的类

image.png

  • 然后我们F5一下,再在数据库上看,已成生了二个表拉

image.png

新建区域控制器

  • 先实现单词的控制器
  • 新建文件夹Areas/School/Controllers,新建EnglishWordsController、ErrorSubjectController两个控制器,分别填入以下内容。

image.png

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Reflection;
using Microsoft.AspNetCore.Mvc;
using NewLife.Cube;
using NewLife.Web;
using XCode.Membership;

namespace dqltest.Areas.School.Controllers
{
    [SchoolArea]
    [DisplayName("英语-单词")]
    public class EnglishWordsController:EntityController<EnglishWords>
    {
        protected override IDictionary<MethodInfo, Int32> ScanActionMenu(IMenu menu)
        {
            menu.Visible = true;
            return base.ScanActionMenu(menu);
        }

    }
}
  • 然后我们运行F5,会看见新建的区域菜单出来了

image.png

  • 可以点手动增加词语

image.png