示例#1
0
        public AssetTypeAttribute GetAttributeByName(string name, int assetTypeID)
        {
            AssetTypeAttribute attribute = null;

            attribute = _assetAttributeRepository.GetSigleByConditions(a => a.Name.Equals(name) && a.AssetTypeID.Equals(assetTypeID));
            return(attribute);
        }
    public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label)
    {
        // Figure out what asset types we allow. Default to all.
        AssetTypeAttribute assetTypeProperty = System.Attribute.GetCustomAttribute(fieldInfo, typeof(AssetTypeAttribute)) as AssetTypeAttribute;
        var assetType = assetTypeProperty != null ? assetTypeProperty.assetType : typeof(GameObject);

        SerializedProperty guid = prop.FindPropertyRelative("guid");

        string path = AssetDatabase.GUIDToAssetPath(guid.stringValue);

        Object obj = AssetDatabase.LoadAssetAtPath(path, assetType);

        pos = EditorGUI.PrefixLabel(pos, GUIUtility.GetControlID(FocusType.Passive), new GUIContent(label.text + "(" + guid.stringValue + ")"));
        Object newObj = EditorGUI.ObjectField(pos, obj, assetType, false);

        if (newObj != obj)
        {
            if (newObj != null)
            {
                path             = AssetDatabase.GetAssetPath(newObj);
                guid.stringValue = AssetDatabase.AssetPathToGUID(path);
            }
            else
            {
                guid.stringValue = "";
            }
        }
    }
示例#3
0
    public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label)
    {
        // Figure out what asset types we allow. Default to all.
        var assetType = typeof(Object);

        if (fieldInfo != null)
        {
            AssetTypeAttribute assetTypeProperty = System.Attribute.GetCustomAttribute(fieldInfo, typeof(AssetTypeAttribute)) as AssetTypeAttribute;
            assetType = assetTypeProperty != null ? assetTypeProperty.assetType : typeof(Object);
        }

        var val0 = prop.FindPropertyRelative("val0");
        var val1 = prop.FindPropertyRelative("val1");
        var val2 = prop.FindPropertyRelative("val2");
        var val3 = prop.FindPropertyRelative("val3");

        var reference = new WeakAssetReference(val0.intValue, val1.intValue, val2.intValue, val3.intValue);

        var    guidStr = "";
        Object obj     = null;

        if (reference.IsSet())
        {
            guidStr = reference.ToGuidStr();
            var path = AssetDatabase.GUIDToAssetPath(guidStr);

            if (assetType == null)
            {
                assetType = AssetDatabase.GetMainAssetTypeAtPath(path);
            }

            obj = AssetDatabase.LoadAssetAtPath(path, assetType);
        }

        pos = EditorGUI.PrefixLabel(pos, GUIUtility.GetControlID(FocusType.Passive), new GUIContent(label.text + "(" + guidStr + ")"));
        Object newObj = EditorGUI.ObjectField(pos, obj, assetType, false);

        if (newObj != obj)
        {
            var newRef = new WeakAssetReference();
            if (newObj != null)
            {
                var path = AssetDatabase.GetAssetPath(newObj);
                newRef = new WeakAssetReference(AssetDatabase.AssetPathToGUID(path));
            }

            val0.intValue = newRef.val0;
            val1.intValue = newRef.val1;
            val2.intValue = newRef.val2;
            val3.intValue = newRef.val3;
        }
    }
        /// <summary>
        /// 设置资产类别的属性
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public bool SetAttributes(AssetTypeModel model)
        {
            using (var dbContext = new MissionskyOAEntities())
            {
                var entity = dbContext.AssetTypes.Where(it => it.Id == model.Id).FirstOrDefault();
                if (entity != null)
                {
                    //处理区域
                    var sourceTypeAttributes = dbContext.AssetTypeAttributes.Where(it => it.TypeId == model.Id).ToList();
                    if (model.Attributes != null && model.Attributes.Count > 0)
                    {
                        List <int> sourceAttributeIds = sourceTypeAttributes.Select(it => it.AttributeId).ToList();
                        var        modelAttributeIds  = model.Attributes.Select(it => it.Id).ToList().Distinct();
                        foreach (var id in modelAttributeIds)
                        {
                            //添加新的
                            if (!sourceAttributeIds.Contains(id))
                            {
                                AssetTypeAttribute typeAttr = new AssetTypeAttribute();
                                typeAttr.TypeId      = model.Id;
                                typeAttr.AttributeId = id;
                                dbContext.AssetTypeAttributes.Add(typeAttr);
                            }
                            sourceAttributeIds.Remove(id);
                        }
                        //删除
                        var needDeleteTypeAttributes = dbContext.AssetTypeAttributes.Where(it => sourceAttributeIds.Contains(it.AttributeId) && it.TypeId == model.Id);
                        foreach (var item in needDeleteTypeAttributes)
                        {
                            dbContext.AssetTypeAttributes.Remove(item);
                        }
                    }
                    else
                    {
                        //删除所有
                        foreach (var item in sourceTypeAttributes)
                        {
                            dbContext.AssetTypeAttributes.Remove(item);
                        }
                    }
                    dbContext.SaveChanges();
                }

                return(true);
            }
        }
示例#5
0
 public void Update(AssetTypeAttribute assetAttribute)
 {
     _assetAttributeRepository.Update(assetAttribute);
 }
示例#6
0
 public void Add(AssetTypeAttribute assetAttribute)
 {
     _assetAttributeRepository.Add(assetAttribute);
 }
示例#7
0
        public async Task <string> ImportAssetExcelAsync(ExcelWorksheet worksheet, int userID)
        {
            string result = "Import fail " + worksheet.Name.Trim();

            using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required,
                                                                 new System.TimeSpan(0, 60, 0)))
            {
                try
                {
                    var    colCount     = worksheet.Dimension.End.Column;
                    var    rowCount     = worksheet.Dimension.End.Row;
                    string locationCode = worksheet.Cells[1, 3].Value.ToString().Trim();

                    Location location = _locationService.GetLocationByCode(locationCode);
                    if (location == null)
                    {
                        result = "Do not exist current location code: " + locationCode + ". Please check again or create new!";

                        return(result);
                    }

                    for (int i = 3; i <= rowCount; i++)
                    {
                        result = "Error at cell " + i;
                        string areaCode = worksheet.Cells[i, 2].Value.ToString();

                        Area area = _areaService.GetAreaByCode(areaCode);
                        if (area == null)
                        {
                            result = result + " in area collum do not exist current area code:" + areaCode + ". Please check again or create new!";
                            return(result);
                        }
                        string assetname     = worksheet.Cells[i, 3].Value.ToString();
                        string assetTypeName = worksheet.Cells[i, 4].Value.ToString();
                        string description   = worksheet.Cells[i, 8].Value.ToString();
                        bool   active        = false;
                        if (worksheet.Cells[i, 9].Value.ToString().Equals("1"))
                        {
                            active = true;
                        }

                        string   assetCode = worksheet.Cells[i, 7].Value.ToString();
                        int      quantity  = Int32.Parse(worksheet.Cells[i, 5].Value.ToString().Trim());
                        DateTime startDate = DateTime.Now;
                        try
                        {
                            startDate = Convert.ToDateTime(worksheet.Cells[i, 6].Value.ToString());
                        }
                        catch (Exception e)
                        {
                            //set default date
                            startDate = Convert.ToDateTime("1900-01-01");
                        }
                        AssetType assetTypes = _assetTypeService.GetAssetTypeByName(assetTypeName);
                        if (assetTypes == null)
                        {
                            result = result + "in Assettype collum do not exist current type import: " + assetTypeName;
                            return(result);
                        }

                        // check asset is exist or not / if exist update asset
                        Asset asset = _assetService.GetAssetByCode(assetCode);
                        if (asset == null)
                        {
                            Asset newAsset = new Asset();
                            newAsset.Name              = assetname;
                            newAsset.AssetCode         = assetCode;
                            newAsset.Description       = description;
                            newAsset.Quantity          = quantity;
                            newAsset.StartDate         = startDate;
                            newAsset.AssetTypeID       = assetTypes.ID;
                            newAsset.ApplicationUserID = userID;
                            newAsset.AreaID            = area.ID;
                            newAsset.Active            = active;
                            _assetService.Add(newAsset);
                            asset = newAsset;
                            _assetService.SaveChanges();
                        }
                        else
                        {
                            asset.AssetCode   = assetCode;
                            asset.Name        = assetname;
                            asset.Description = description;
                            asset.Quantity    = quantity;
                            asset.StartDate   = startDate;
                            asset.AssetTypeID = assetTypes.ID;
                            asset.AreaID      = area.ID;
                            asset.Active      = active;
                            _assetService.Update(asset);
                            _assetService.SaveChanges();
                        }

                        for (int j = 10; j <= colCount; j++)
                        {
                            string             attributeName  = worksheet.Cells[2, j].Value.ToString().Trim();
                            AssetTypeAttribute assetAttribute = _attributeService.GetAttributeByName(attributeName, assetTypes.ID);
                            string             value          = "";
                            try
                            {
                                if (worksheet.Cells[i, j].Value == null)
                                {
                                    value = "N/A";
                                }
                                value = worksheet.Cells[i, j].Value.ToString().Trim();
                            }
                            catch (Exception e)
                            {
                                value = "N/A";
                            }

                            AssetAttributeValue insertValue = _attributeValueService.SearchAttributeValue(asset.ID, assetAttribute.ID);
                            if (insertValue != null)
                            {
                                insertValue.Value = value;
                                _attributeValueService.Update(insertValue);
                            }
                            else
                            {
                                insertValue                  = new AssetAttributeValue();
                                insertValue.Value            = value;
                                insertValue.AssetID          = asset.ID;
                                insertValue.AssetAttributeID = assetAttribute.ID;
                                insertValue.Active           = true;
                                _attributeValueService.Add(insertValue);
                            }
                        }
                        result = result + " in Attribute value table.";
                    }

                    _attributeValueService.SaveChanges();
                    result = "Error in Commplete transison.";
                    scope.Complete();
                    result = "Import successfull!";
                    return(result);
                }
                catch (Exception)
                {
                    return(result);
                }
            }
        }