public static IList <ResTemplateItem> GetAll() { List <ResTemplateItem> list = new List <ResTemplateItem>(); using (pm2Entities entities = new pm2Entities()) { var list2 = (from m in entities.Res_TemplateItem select new { ItemId = m.ItemId, ExcelColumn = m.ExcelColumn, ExcelRealCoumn = m.ExcelRealCoumn, DbColumn = m.DbColumn, TemplateId = m.Res_Template.TemplateId }).ToList(); if (list2.Count == 0) { return(list); } foreach (var type in list2) { ResTemplateItem item = new ResTemplateItem { ItemId = type.ItemId, ExcelColumn = type.ExcelColumn, ExcelRealCoumn = type.ExcelRealCoumn, DbColumn = type.DbColumn, Template = ResTemplate.GetById(type.TemplateId) }; list.Add(item); } } return(list); }
public static void Add(ResTemplate restemplate) { using (pm2Entities entities = new pm2Entities()) { Res_Template template = bindEntity(restemplate, true); entities.AddToRes_Template(template); entities.SaveChanges(); } }
public static ResTemplateItem Create(string id, ResTemplate template, string column, string realColumn, string Dbcolumn) { if (string.IsNullOrEmpty(id)) { throw new ArgumentNullException("模板子项Id", "模板子项Id不能为空"); } return(new ResTemplateItem { ItemId = id, Template = template, ExcelColumn = column, ExcelRealCoumn = realColumn, DbColumn = Dbcolumn }); }
public static void Update(ResTemplate restemplate) { using (pm2Entities entities = new pm2Entities()) { if ((from m in entities.Res_Template where m.TemplateId == restemplate.Id select m).FirstOrDefault <Res_Template>() == null) { throw new Exception("找不到需要修改的模板"); } Res_Template template = bindEntity(restemplate, false); entities.SaveChanges(); } }
private static Res_Template bindEntity(ResTemplate restemplate, bool isAdd) { Res_Template template = new Res_Template(); if (isAdd) { template.TemplateId = restemplate.Id; template.TemplateName = restemplate.Name; template.StartRowIndex = restemplate.StartRowIndex; template.InputDate = restemplate.InputDate; template.InputUser = restemplate.InputUser; } template.IsValid = restemplate.IsValid; return(template); }
public static ResTemplateItem GetById(string id) { ResTemplateItem item = new ResTemplateItem(); using (pm2Entities entities = new pm2Entities()) { var type = (from m in entities.Res_TemplateItem where m.ItemId == id select new { ItemId = m.ItemId, ExcelColumn = m.ExcelColumn, ExcelRealCoumn = m.ExcelRealCoumn, DbColumn = m.DbColumn, TemplateId = m.Res_Template.TemplateId }).FirstOrDefault(); if (type != null) { item.ItemId = type.ItemId; item.ExcelColumn = type.ExcelColumn; item.ExcelRealCoumn = type.ExcelRealCoumn; item.DbColumn = type.DbColumn; item.Template = ResTemplate.GetById(type.TemplateId); return(item); } return(null); } }
public static ResTemplate GetById(string id) { ResTemplate template = null; using (pm2Entities entities = new pm2Entities()) { Res_Template template2 = (from m in entities.Res_Template where m.TemplateId == id select m).FirstOrDefault <Res_Template>(); if (template2 != null) { template = new ResTemplate { Id = template2.TemplateId, Name = template2.TemplateName, IsValid = template2.IsValid, InputDate = template2.InputDate, InputUser = template2.InputUser, StartRowIndex = template2.StartRowIndex }; } } return(template); }
public static IList <ResTemplate> GetAll() { List <ResTemplate> list = new List <ResTemplate>(); using (pm2Entities entities = new pm2Entities()) { foreach (Res_Template template in (from m in entities.Res_Template orderby m.InputDate descending select m).ToList <Res_Template>()) { ResTemplate item = new ResTemplate { Id = template.TemplateId, Name = template.TemplateName, IsValid = template.IsValid, StartRowIndex = template.StartRowIndex, InputDate = template.InputDate, InputUser = template.InputUser }; list.Add(item); } } return(list); }