public static IList <Resource> GetAll() { List <Resource> list = new List <Resource>(); using (pm2Entities entities = new pm2Entities()) { foreach (var typef in from r in entities.Res_Resource select new { Id = r.ResourceId, TypeId = r.Res_ResourceType.ResourceTypeId, Code = r.ResourceCode, Name = r.ResourceName, Brand = r.Brand, TaxRate = r.TaxRate, Specification = r.Specification, TechnicalParam = r.TechnicalParameter, UnitId = r.Res_Unit.UnitId, TypeAttributeId = r.Res_Attribute.AttributeId, Series = r.Series, User = r.InputUser, Date = r.InputDate }) { Resource item = new Resource { Id = typef.Id, ResourceType = ResType.GetById(typef.TypeId), Code = typef.Code, Name = typef.Name, Brand = typef.Brand, TaxRate = typef.TaxRate, Specification = typef.Specification, TechnicalParameter = typef.TechnicalParam, ResourceUnit = ResUnit.GetById(typef.UnitId), TypeAttribute = ResTypeAttribute.GetById(typef.TypeAttributeId), Series = typef.Series, Prices = GetPrices(typef.Id), InputUser = typef.User, InputDate = typef.Date }; list.Add(item); } } return(list); }
public static void Update(ResTypeAttribute typeAttr) { using (pm2Entities entities = new pm2Entities()) { Res_Attribute attribute = (from attr in entities.Res_Attribute where attr.AttributeId == typeAttr.Id select attr).FirstOrDefault <Res_Attribute>(); if (attribute == null) { throw new Exception("找不到需要修改的类别属性"); } attribute.AttributeName = typeAttr.Name; entities.SaveChanges(); } }
public static IList <ResTypeAttribute> GetAll() { IList <ResTypeAttribute> list = new List <ResTypeAttribute>(); using (pm2Entities entities = new pm2Entities()) { foreach (var type in (from a in entities.Res_Attribute select new { AttributeId = a.AttributeId, AttributeName = a.AttributeName, InputUser = a.InputUser, InputDate = a.InputDate, ResourceTypeId = a.Res_ResourceType.ResourceTypeId }).ToList()) { ResTypeAttribute item = new ResTypeAttribute { Id = type.AttributeId, Name = type.AttributeName, InputUser = type.InputUser, ResourceType = ResType.GetById(type.ResourceTypeId) }; list.Add(item); } } return(list); }
public static void Add(ResTypeAttribute typeAttr) { using (pm2Entities entities = new pm2Entities()) { Res_Attribute attribute = new Res_Attribute { AttributeId = typeAttr.Id, AttributeName = typeAttr.Name, InputUser = typeAttr.InputUser, InputDate = typeAttr.InputDate }; Res_ResourceType type = (from rt in entities.Res_ResourceType where rt.ResourceTypeId == typeAttr.ResourceType.Id select rt).FirstOrDefault <Res_ResourceType>(); if (type == null) { throw new Exception("不能确定其所属类别"); } attribute.Res_ResourceType = type; entities.SaveChanges(); } }
public static ResTypeAttribute GetById(string id) { ResTypeAttribute attribute = new ResTypeAttribute(); using (pm2Entities entities = new pm2Entities()) { var type = (from a in entities.Res_Attribute where a.AttributeId == id select new { AttributeId = a.AttributeId, AttributeName = a.AttributeName, InputUser = a.InputUser, InputDate = a.InputDate, ResourceTypeId = a.Res_ResourceType.ResourceTypeId }).FirstOrDefault(); if (type != null) { attribute.Id = id; attribute.Name = type.AttributeName; attribute.InputUser = type.InputUser; attribute.InputDate = type.InputDate; ResType byId = ResType.GetById(type.ResourceTypeId); attribute.ResourceType = byId; return(attribute); } return(null); } }
public static Resource Create(string id, ResType resType, string code, string name, string brand, decimal?taxRate, string specification, string modelNumber, string technicalParam, ResUnit resUnit, ResTypeAttribute typeAttr, string series, IDictionary <ResPriceType, decimal?> prices, string user, DateTime?date, int?supplierId) { if (string.IsNullOrEmpty(id)) { throw new ArgumentException("资源Id", "资源Id不能为空"); } if (resType == null) { throw new ArgumentException("资源类型", "资源类型不能为空"); } if (string.IsNullOrEmpty(code)) { throw new ArgumentException("资源编号", "资源名称不能为空"); } return(new Resource { Id = id, ResourceType = resType, Code = code, Name = name, Brand = brand, TaxRate = taxRate, Specification = specification, ModelNumber = modelNumber, TechnicalParameter = technicalParam, ResourceUnit = resUnit, TypeAttribute = typeAttr, Series = series, Prices = prices, InputUser = user, InputDate = date, SupplierId = supplierId }); }