学用MVC4+EF+Razor做网站:钢铁网电子交易平台(三)

对于钢铁产品在基本信息可以分为以下几个类

区域类:

using System.ComponentModel;
using System.ComponentModel.DataAnnotations;

namespace MvcGangTie.Models
{
    /// <summary>
    /// 区域类
    /// </summary>
    public class Area
    {
        [Key]
        [DisplayName("区域编码:")]
        [Required(ErrorMessage = "编码不能为空!")]
        [RegularExpression(@"^\w+$", ErrorMessage = "编码中不允许有特殊字符")]
        public string CodeArea { get; set; }

        [DisplayName("区域名称:")]
        [Required(ErrorMessage = "区域名称不能为空!")]
        public string Name { get; set; }
    }
}

产品材质类:

using System;
using System.Web;
using System.Linq;
using System.ComponentModel;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;

namespace MvcGangTie.Models
{
    /// <summary>
    /// 产品材质类
    /// </summary>
    public class Material
    {
        [Key]
        [DisplayName("产品材质编码:")]
        [Required(ErrorMessage = "编码不能为空!")]
        [RegularExpression(@"^\w+$", ErrorMessage = "编码中不允许有特殊字符")]
        public string CodeMaterial { get; set; }

        [DisplayName("产品材质名称:")]
        [Required(ErrorMessage = "产品材质名称不能为空!")]
        public string Name { get; set; }

    }
}

产品类型类:

using System.ComponentModel;
using System.ComponentModel.DataAnnotations;


namespace MvcGangTie.Models
{
    /// <summary>
    /// 产品类型类
    /// </summary>
    public class ProClass
    {
        [Key]
        [DisplayName("产品类别编码:")]
        [Required(ErrorMessage = "类别编码不能为空!")]
        [RegularExpression(@"^\w+$", ErrorMessage = "编码中不允许有特殊字符")]
        public string CodeClass { get; set; }

        [DisplayName("产品类别名称:")]
        [Required(ErrorMessage = "产品类别名称不能为空!")]
        public string Name { get; set; }

        [DisplayName("计量方式:")]
        public string Metering { get; set; }
    }
}

生产厂家:

using System;
using System.Web;
using System.Linq;
using System.ComponentModel;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;

namespace MvcGangTie.Models
{
    /// <summary>
    /// 生产厂家
    /// </summary>
    public class Producer
    {
        [Key]
        [DisplayName("厂家编码:")]
        [Required(ErrorMessage = "编码不能为空!")]
        [RegularExpression(@"^\w+$", ErrorMessage = "编码中不允许有特殊字符")]
        public string CodeProducer { get; set; }

        [DisplayName("厂家名称:")]
        [Required(ErrorMessage = "厂家名称不能为空")]
        public string Name { get; set; }

        [DisplayName("厂家地址:")]
        [Required(ErrorMessage = "厂家地址不能为空")]
        public string Address { get; set; }

        [DisplayName("联系人:")]
        [Required(ErrorMessage = "联系人不能为空")]
        public string Contact { get; set; }

        [DisplayName("联系电话:")]
        [Required(ErrorMessage = "联系电话不能为空")]
        public string Tel { get; set; }
    }
}
//^\w中\w表示字符类(包括大小写字母,数字),其中的"^"表示,以这个字符类中字符开头。
//后面的+号的作用在前一个字符上,即\w+,表示一个或多个\w,最少一个,而后面的"$"号,表示限定以\w结尾。
//总体意义就是限定一个任意长字符串,全部由字母数字组成,前面中间后面都不能有空格、标点等非\w字符

//^表示以此打头,$表示以此结尾,\w表示由数字、26个英文字母或者下划线+表示可重复^\w+$  
//则表示由数字、26个英文字母或者下划线组成的字符串

产品类:

using System;
using System.Web;
using System.Linq;
using System.ComponentModel;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;


namespace MvcGangTie.Models
{
    /// <summary>
    /// 产品类
    /// </summary>
    public class Product
    {
        [Key]
        [DisplayName("产品编码:")]
        [Required(ErrorMessage = "编码不能为空!")]
        [RegularExpression(@"^\w+$", ErrorMessage = "编码中不允许有特殊字符")]
        public string CodePro { get; set; }

        [DisplayName("产品分类:")]
        //[Required(ErrorMessage = "请选择一项!")]
        public string CodeClass { get; set; }

        [DisplayName("产品材质:")]
        //[Required(ErrorMessage = "请选择一项!")]
        public string CodeMaterial { get; set; }

        [DisplayName("产品规格:")]
        //[Required(ErrorMessage = "请选择一项!")]
        public string CodeSpec { get; set; }

        public virtual ProClass ProClass { get; set; }
        public virtual Material Material { get; set; }
        public virtual Spec Spec { get; set; }

    }
}
//^表示以此打头,$表示以此结尾,\w表示由数字、26个英文字母或者下划线+表示可重复^\w+$  
//则表示由数字、26个英文字母或者下划线组成的字符串

产品规格类:

using System.Linq;
using System.ComponentModel;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;


namespace MvcGangTie.Models
{
    /// <summary>
    /// 产品规格类
    /// </summary>

    public class Spec
    {
        [Key]
        [DisplayName("规格编码:")]
        [Required(ErrorMessage = "编码不能为空!")]
        [RegularExpression(@"^\w+$", ErrorMessage = "编码中不允许有特殊字符")]
        public string CodeSpec { get; set; }

        [DisplayName("规格名称:")]
        [Required(ErrorMessage = "规格名称不能为空")]
        public string Name { get; set; }
    }
}

销售状态:

using System.ComponentModel;
using System.ComponentModel.DataAnnotations;

namespace MvcGangTie.Models
{
    /// <summary>
    /// 销售状态
    /// </summary>
    public class Statu
    {
        [Key]
        [DisplayName("销售状态编码:")]
        [Required(ErrorMessage = "编码不能为空!")]
        [RegularExpression(@"^\w+$", ErrorMessage = "编码中不允许有特殊字符")]
        public string CodeStatu { get; set; }
        [DisplayName("销售状态名称:")]
        [Required(ErrorMessage = "不能为空!")]
        public string Name { get; set; }
    }
}

仓库类:

using System;
using System.Web;
using System.Linq;
using System.ComponentModel;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;


namespace MvcGangTie.Models
{
    /// <summary>
    /// 仓库类
    /// </summary>
    public class Store
    {
        [Key]
        [DisplayName("仓库编码:")]
        [Required(ErrorMessage = "编码不能为空!")]
        [RegularExpression(@"^\w+$", ErrorMessage = "编码中不允许有特殊字符")]
        public string CodeStore { get; set; }

        [DisplayName("区域编码:")]  //注意这里是外键,不能添加[Required(ErrorMessage = "不能为空")],不然编译会出错!
        //[Required(ErrorMessage = "请选择一项")]
        public string CodeArea { get; set; }

        [DisplayName("仓库名称:")]
        [Required(ErrorMessage = "不能为空")]
        public string Name { get; set; }

        [DisplayName("仓库地址:")]
        [Required(ErrorMessage = "不能为空")]
        public string Address { get; set; }

        [DisplayName("联系电话:")]
        [Required(ErrorMessage = "不能为空")]
        public string Tel { get; set; }

        [DisplayName("联系人:")]
        [Required(ErrorMessage = "不能为空")]
        public string Contact { get; set; }

        public virtual Area Area { get; set; }
    }
}

库存类:

using System;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;

namespace MvcGangTie.Models
{
    /// <summary>
    /// 库存类
    /// </summary>
    public partial class Stock
    {
        //构造函数
        public Stock()
        {
            this.AddDate = DateTime.Today;  // DateTime.Now;
            this.Price = 0;
            this.PCS = 0;
            this.TonPerPCS = 0;
            this.MaxSales = 0;
            this.PlanSales = 0;
            this.Inventory = 0;
            this.Selled = 0;
            this.CodeStatu = "a";   //a:正常销售;b:超出销售计划但小于最大销售量;c:超出最大销售量;d、停止销售;e、加价销售

        }

        [Key]
        [ScaffoldColumn(false)]
        public int StockId { get; set; }

        [DisplayName("产品编码:")]
        [Required(ErrorMessage = "不能为空!")]
        [RegularExpression(@"^\w+$", ErrorMessage = "编码中不允许有特殊字符")]
        public string CodePro { get; set; }

        [DisplayName("区域编码:")]
        public string CodeArea { get; set; }

        [DisplayName("仓库编码:")]
        //[Required(ErrorMessage = "不能为空")]
        public string CodeStore { get; set; }

        [DisplayName("厂家编码:")]
        // [Required(ErrorMessage = "不能为空")]
        public string CodeProducer { get; set; }

        [DisplayName("价格:")]
        [Required(ErrorMessage = "不能为空")]
        [RegularExpression(@"^[0-9]+(.[0-9]{1,3})?$", ErrorMessage = "只能输入数字或者小数")]
        // [Range(0.00, 9000.00, ErrorMessage = "价格数值输入有错误,数值应该处在0.00~9000.00之间。")]
        // Display currency data field in the format $1,345.50.
        [DisplayFormat(DataFormatString = "{0:C}")]
        public decimal Price { get; set; }

        [DisplayName("件数:")]
        [Required(ErrorMessage = "不能为空")]
        [RegularExpression(@"^[0-9]+(.[0-9]{1,3})?$", ErrorMessage = "只能输入数字或者小数")]
        public decimal PCS { get; set; }

        [DisplayName("每件吨数:")]
        [Required(ErrorMessage = "不能为空")]
        [RegularExpression(@"^[0-9]+(.[0-9]{1,3})?$", ErrorMessage = "只能输入数字或者小数")]
        public decimal TonPerPCS { get; set; }

        [DisplayName("最大销售量:")]
        [Required(ErrorMessage = "不能为空")]
        [RegularExpression(@"^[0-9]+(.[0-9]{1,3})?$", ErrorMessage = "只能输入数字或者小数")]
        public decimal MaxSales { get; set; }

        [DisplayName("计划售量")]
        [Required(ErrorMessage = "不能为空")]
        [RegularExpression(@"^[0-9]+(.[0-9]{1,3})?$", ErrorMessage = "只能输入数字或者小数")]
        public decimal PlanSales { get; set; }

        [DisplayName("已销售重量:")]
        [Required(ErrorMessage = "不能为空")]
        [RegularExpression(@"^[0-9]+(.[0-9]{1,3})?$", ErrorMessage = "只能输入数字或者小数")]
        public decimal Inventory { get; set; }

        [DisplayName("已销售件数:")]
        [Required(ErrorMessage = "不能为空")]
        [RegularExpression(@"^[0-9]+(.[0-9]{1,3})?$", ErrorMessage = "只能输入数字或者小数")]
        public decimal Selled { get; set; }



        [DisplayName("添加日期:")]
        [Required(ErrorMessage = "不能为空")]
        [DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:yyyy-MM-dd}")]  // Display date data field in the short format 11/12/08.Also, apply format in edit mode.
        public System.DateTime AddDate { get; set; }

        [DisplayName("当前状态: ")]
        //[Required(ErrorMessage = "不能为空")]
        public string CodeStatu { get; set; }

        public virtual Product Product { get; set; }
        public virtual Area Area { get; set; }
        public virtual Store Store { get; set; }
        public virtual Producer Producer { get; set; }
        public virtual Statu Statu { get; set; }

    }
}

 链接 : http://www.51aspx.com/code/MVCB2CSite/21447 

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。