/// <summary>
        /// Add a user defined data field and its value.
        ///
        /// First locate the specified asset (or create a new one if this does not exist)
        /// Locate the user defined data field (or create a new one if this does not exist)
        /// Set the value for the field given its ID and asset
        ///
        /// </summary>
        /// <param name="lvi"></param>
        private void AddUserDataField(UltraListViewItem lvi)
        {
            AssetDAO lwDataAccess = new AssetDAO();

            // Recover the data fields
            string assetName = lvi.Text;
            string category  = lvi.SubItems[2].Text;

            if (category == "Asset Data")
            {
                category = "General";
            }
            string fieldName  = lvi.SubItems[0].Text;
            string fieldValue = lvi.SubItems[1].Text;

            // Does the Asset exist?
            // Note that as we only have an asset name we can only possibly match on that
            int assetID = lwDataAccess.AssetFind(assetName);

            // If the asset exists then add the history record for it
            if (assetID != 0)
            {
                // Does the User Data Category exist?  If not create it also
                UserDataCategory parentCategory = _listCategories.FindCategory(category);
                if (parentCategory == null)
                {
                    parentCategory      = new UserDataCategory(UserDataCategory.SCOPE.Asset);
                    parentCategory.Name = category;
                    parentCategory.Add();
                    _listCategories.Add(parentCategory);
                }


                // Now look at the User Data Field and see if we have one already with this name
                UserDataField thisField = parentCategory.FindField(fieldName);
                if (thisField == null)
                {
                    // No existing field of this name in the General Category so add it
                    thisField          = new UserDataField();
                    thisField.ParentID = parentCategory.CategoryID;
                    thisField.Name     = fieldName;
                    thisField.Add();
                    parentCategory.Add(thisField);
                }

                // ...and set the value for the asset both here and in the database
                thisField.SetValueFor(assetID, fieldValue, true);
            }
        }
예제 #2
0
        private void AddAsset()
        {
            AssetDAO lwDataAccess = new AssetDAO();

            _asset.Name = this.tbAssetName.Text;

            // Set the asset type
            AssetType assetType = cbAssetType.Value as AssetType;

            _asset.AssetTypeID = assetType.AssetTypeID;

            // Do we have a name for the asset and is it unique?
            if ((_asset.Name == "") || (lwDataAccess.AssetFind(_asset) != 0))
            {
                MessageBox.Show("You must specify a unique name for this asset", "Invalid Asset Name");
                this.DialogResult = DialogResult.None;
                return;
            }

            // OK - unique asset so create it
            _asset.AssetID = _asset.Add();
        }
예제 #3
0
        private void backgroundWorker_ImportHistoryLine(string[] fields)
        {
            // Does the Asset exist?
            Asset newAsset = new Asset();

            newAsset.Name = fields[0];
            //
            AssetDAO lwDataAccess = new AssetDAO();

            newAsset.AssetID = lwDataAccess.AssetFind(newAsset);

            // If the asset exists then add the history record for it
            if (newAsset.AssetID != 0)
            {
                // Create an Audit Trail Entry record based on the data passed in to us.
                try
                {
                    AuditTrailDAO auditTrailDAO = new AuditTrailDAO();

                    AuditTrailEntry ate = new AuditTrailEntry();
                    //ate.Date = DateTime.ParseExact(fields[1], "yyyy-MM-dd HH:mm:ss", null);
                    ate.Date      = Convert.ToDateTime(fields[1]);
                    ate.Class     = AuditTrailEntry.CLASS.asset;
                    ate.AssetID   = newAsset.AssetID;
                    ate.AssetName = newAsset.Name;
                    ate.Type      = AuditTrailEntry.TranslateV7Type((AuditTrailEntry.V7_HIST_OPS)Convert.ToInt32(fields[2]));
                    ate.Key       = fields[3];
                    ate.OldValue  = fields[4];
                    ate.NewValue  = fields[5];
                    ate.Username  = fields[6];
                    auditTrailDAO.AuditTrailAdd(ate);
                }
                catch (Exception ex)
                {
                    logger.Error(ex.Message);
                }
            }
        }