using CP.Common; using MC.ORM; using NIU.Core; using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; namespace CP.Model { /// /// 地区表 /// [TableName("area"), PrimaryKey("areaid")] public class Area { /// /// 自动编号 /// public int areaid { get; set; } /// /// 名称 /// [Display(Name = "地区名称")] public string name { get; set; } /// /// 英文名称(用于地址显示) /// [Display(Name = "英文名称")] public string ename { get; set; } /// /// 排序 /// [Display(Name = "排序号")] public int seq { get; set; } /// /// 创建时间 /// public int cdate { get; set; } /// /// title /// [Display(Name = "title")] public string title { get; set; } /// /// keywords /// [Display(Name = "Key")] public string keywords { get; set; } /// /// descriptions /// [Display(Name = "Desc")] public string descriptions { get; set; } /// /// 类型--1:地区 2:彩种 /// [Ignore] public int type { set; get; } /// /// treegrid属性 /// [Ignore] public List children { set; get; } } public class AreaData : DataConnect { /// /// 数据库中取出所有七乐彩数据 /// /// public static List GetFcqlcList() { List list = new List(); string sql = string.Format("order by qi asc"); DataConnect dc = new DataConnect(); list = dc.db.Fetch(sql); if (list != null && list.Count > 0) { for (int i = 0; i < list.Count; i++) { list[i].rank = i + 1; } } return list; } /// /// 添加 更新 /// /// public static void AddOrUpdate(Area model) { if (model == null) throw new OperationExceptionFacade("未接收到参数"); if (string.IsNullOrEmpty(model.name)) throw new OperationExceptionFacade("名称不可为空"); DataConnect dc = new DataConnect(); if (dc.db.Exists($"Where name='{model.name}' and areaid<>{model.areaid}")) throw new OperationExceptionFacade("已存在此客户类型"); if (model.areaid == 0) { model.cdate = TypeConverter.DateTimeToInt(DateTime.Now); dc.db.Insert(model); } else { var entity = dc.db.SingleOrDefault(model.areaid); if (entity == null) throw new OperationExceptionFacade("数据不存在,请刷新"); entity.name = model.name; entity.title = model.title; entity.keywords = model.keywords; entity.descriptions = model.descriptions; entity.seq = 2; entity.cdate = TypeConverter.DateTimeToInt(DateTime.Now); dc.db.Update(entity); } } /// /// 根据Id获取 /// /// public static Area GetById(long id) { DataConnect dc = new DataConnect(); return dc.db.SingleOrDefault(id); } /// /// 删除 /// /// /// public static void Delete(long id) { var entity = GetById(id); if (entity == null) { throw new OperationExceptionFacade("数据不存在,请刷新"); } DataConnect dc = new DataConnect(); dc.db.Delete(id); } /// /// 获取所有 /// /// public static List GetList() { DataConnect dc = new DataConnect(); return dc.db.Fetch($"ORDER BY seq asc"); } } }