Beispiel #1
0
        public static Resource GetById(string id)
        {
            Resource resource = new Resource();

            using (pm2Entities entities = new pm2Entities())
            {
                var typee = (from m in entities.Res_Resource
                             where m.ResourceId == id
                             select new { Id = m.ResourceId, Name = m.ResourceName, Code = m.ResourceCode, Brand = (m.Brand == null) ? "" : m.Brand, InputDate = m.InputDate, InputUser = m.InputUser, Specification = (m.Specification == null) ? "" : m.Specification, Series = m.Series, SupplierId = m.SupplierId, TaxRate = m.TaxRate, TechnicalParameter = (m.TechnicalParameter == null) ? "" : m.TechnicalParameter, ModelNumber = (m.ModelNumber == null) ? "" : m.ModelNumber, unitId = m.Res_Unit.UnitId }).FirstOrDefault();
                if (typee != null)
                {
                    resource.Id                 = typee.Id;
                    resource.Name               = typee.Name;
                    resource.Code               = typee.Code;
                    resource.Brand              = (typee.Brand == null) ? "" : typee.Brand;
                    resource.InputDate          = typee.InputDate;
                    resource.InputUser          = typee.InputUser;
                    resource.Specification      = (typee.Specification == null) ? "" : typee.Specification;
                    resource.Series             = typee.Series;
                    resource.SupplierId         = typee.SupplierId;
                    resource.TaxRate            = typee.TaxRate;
                    resource.TechnicalParameter = (typee.TechnicalParameter == null) ? "" : typee.TechnicalParameter;
                    resource.ModelNumber        = (typee.ModelNumber == null) ? "" : typee.ModelNumber;
                    resource.ResourceUnit       = ResUnit.GetById(typee.unitId);
                }
            }
            return(resource);
        }
Beispiel #2
0
        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);
        }
Beispiel #3
0
 public static void Update(ResUnit resUnit)
 {
     using (pm2Entities entities = new pm2Entities())
     {
         Res_Unit unit = entities.Res_Unit.FirstOrDefault <Res_Unit>(c => c.UnitId == resUnit.Id);
         unit.Code      = resUnit.Code;
         unit.Name      = resUnit.Name;
         unit.InputUser = resUnit.InputUser;
         unit.InputDate = resUnit.InputDate;
         entities.SaveChanges();
     }
 }
Beispiel #4
0
        public static void Add(ResUnit resUnit)
        {
            Res_Unit unit = new Res_Unit();

            using (pm2Entities entities = new pm2Entities())
            {
                unit.UnitId    = resUnit.Id;
                unit.Code      = resUnit.Code;
                unit.Name      = resUnit.Name;
                unit.InputUser = resUnit.InputUser;
                unit.InputDate = resUnit.InputDate;
                entities.AddToRes_Unit(unit);
                entities.SaveChanges();
            }
        }
Beispiel #5
0
        public static IList <ResUnit> GetAll()
        {
            List <ResUnit> list = new List <ResUnit>();

            using (pm2Entities entities = new pm2Entities())
            {
                foreach (Res_Unit unit in (from u in entities.Res_Unit select u).ToList <Res_Unit>())
                {
                    ResUnit item = new ResUnit {
                        Id        = unit.UnitId,
                        Code      = unit.Code,
                        Name      = unit.Name,
                        InputUser = unit.InputUser,
                        InputDate = unit.InputDate
                    };
                    list.Add(item);
                }
            }
            return(list);
        }
Beispiel #6
0
        public static ResUnit GetById(string id)
        {
            ResUnit unit = new ResUnit();

            using (pm2Entities entities = new pm2Entities())
            {
                Res_Unit unit2 = (from u in entities.Res_Unit
                                  where u.UnitId == id
                                  select u).FirstOrDefault <Res_Unit>();
                if (unit2 != null)
                {
                    unit.Id        = id;
                    unit.Code      = unit2.Code;
                    unit.Name      = unit2.Name;
                    unit.InputUser = unit2.InputUser;
                    unit.InputDate = unit2.InputDate;
                    return(unit);
                }
                return(null);
            }
        }
Beispiel #7
0
 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
     });
 }