示例#1
0
        /// <summary>
        /// Gets a list of the property values to display to the user
        /// </summary>
        /// <param name="businessObject">The business object whose
        /// properties are to be displayed</param>
        /// <returns>Returns an array of values</returns>
        protected object[] GetValues(IBusinessObject businessObject)
        {
            if (businessObject == null)
            {
                throw new ArgumentNullException("businessObject");
            }
            object[] values = new object[_uiGridProperties.Count + 1];
            values[0] = businessObject.ID.ObjectID;
            int      i      = 1;
            BOMapper mapper = new BOMapper(businessObject);

            foreach (UIGridColumn gridProperty in _uiGridProperties)
            {
                object val = mapper.GetPropertyValueToDisplay(gridProperty.PropertyName);
                values[i++] = val ?? DBNull.Value;
            }
            return(values);
        }
示例#2
0
        /// <summary>
        /// This is a bit of a hack_ was used on a specific project some time ago.
        /// This is not generally supported throughout Habanero so has been isolated here.
        /// </summary>
        /// <param name="propertyName"></param>
        /// <returns></returns>
        private object GetAlternateRelationshipValue(string propertyName)
        {
            string relationshipName = propertyName.Substring(0, propertyName.IndexOf("."));

            propertyName = propertyName.Remove(0, propertyName.IndexOf(".") + 1);
            string[]        parts     = relationshipName.Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
            List <string>   relNames  = new List <string>(parts);
            IBusinessObject relatedBo = this._businessObject;
            IBusinessObject oldBo     = relatedBo;
            int             i         = 0;

            do
            {
                relatedBo = oldBo.Relationships.GetRelatedObject(relNames[i++]);
            } while (relatedBo == null && i < relNames.Count);
            if (relatedBo == null)
            {
                return(null);
                //throw new HabaneroApplicationException("Unable to retrieve property " + propertyName + " from a business object of type " + this._businessObject.GetType().Name);
            }
            BOMapper relatedBoMapper = new BOMapper(relatedBo);

            return(relatedBoMapper.GetPropertyValueToDisplay(propertyName));
        }
 public override object GetValue(object component)
 {
     IBusinessObject bo = GetBusinessObject(component);
     BOMapper boMapper = new BOMapper(bo);
     return boMapper.GetPropertyValueToDisplay(PropertyName);
 }
        /// <summary>
        /// Handles the event of a row being added
        /// </summary>
        /// <param name="e">Attached arguments regarding the event</param>
        private void RowAdded(DataRowChangeEventArgs e)
        {
            try
            {
                _isBeingAdded = true;
                BusinessObject newBo;
                try
                {
                    DeregisterForBOEvents();
                    newBo = (BusinessObject) _collection.CreateBusinessObject();
                }
                finally
                {
                    RegisterForBOEvents();
                }

                if (ObjectInitialiser != null)
                {
                    try
                    {
                        DeregisterForBOEvents();
                        ObjectInitialiser.InitialiseObject(newBo);
                    }
                    finally
                    {
                        RegisterForBOEvents();
                    }
                }
                DataRow row = e.Row;
                try
                {
                    DeregisterForBOEvents();
                    // set all the values in the grid to the bo's current prop values (defaults)
                    // make sure the part entered to create the row is not changed.
                    row[IDColumnName] = newBo.ID.ObjectID;
                    foreach (UIGridColumn uiProperty in _uiGridProperties)
                    {
                        //If no value was typed into the grid then use the default value for the property if one exists.
                        if (DBNull.Value.Equals(row[uiProperty.PropertyName]))
                        {
                            var boMapper = new BOMapper(newBo);
                            var propertyValueToDisplay = boMapper.GetPropertyValueToDisplay(uiProperty.PropertyName);
                            if (propertyValueToDisplay != null)
                            {
                                _table.Columns[uiProperty.PropertyName].ReadOnly = false;
                                row[uiProperty.PropertyName] = propertyValueToDisplay;
                            }
                        }
                        else
                        {
                            ApplyRowCellValueToBOProperty(row, uiProperty, newBo);
                        }
                    }
                }
                finally
                {
                    RegisterForBOEvents();
                }
                string message;
                if (newBo.Status.IsValid(out message))
                {
                    newBo.Save();
                    row.AcceptChanges();
                }
                row.RowError = message;
                if (newBo.Status.IsNew)
                {
                    _addedRows.Add(row, newBo);
                }
                
                if (newBo.ID.ObjectID == Guid.Empty)
                {
                    throw new HabaneroDeveloperException
                        ("Serious error The objectID is Empty", "Serious error The objectID is Empty");
                }
                _isBeingAdded = false;
            }
            catch (Exception ex)
            {
                _isBeingAdded = false;
                if (e.Row != null)
                {
                    e.Row.RowError = ex.Message;
                }
                throw;
            }
        }
示例#5
0
        /// <summary>
        /// Handles the event of a row being added
        /// </summary>
        /// <param name="e">Attached arguments regarding the event</param>
        private void RowAdded(DataRowChangeEventArgs e)
        {
            try
            {
                _isBeingAdded = true;
                BusinessObject newBo;
                try
                {
                    DeregisterForBOEvents();
                    newBo = (BusinessObject)_collection.CreateBusinessObject();
                }
                finally
                {
                    RegisterForBOEvents();
                }

                if (ObjectInitialiser != null)
                {
                    try
                    {
                        DeregisterForBOEvents();
                        ObjectInitialiser.InitialiseObject(newBo);
                    }
                    finally
                    {
                        RegisterForBOEvents();
                    }
                }
                DataRow row = e.Row;
                try
                {
                    DeregisterForBOEvents();
                    // set all the values in the grid to the bo's current prop values (defaults)
                    // make sure the part entered to create the row is not changed.
                    row[IDColumnName] = newBo.ID.ObjectID;
                    foreach (UIGridColumn uiProperty in _uiGridProperties)
                    {
                        //If no value was typed into the grid then use the default value for the property if one exists.
                        if (DBNull.Value.Equals(row[uiProperty.PropertyName]))
                        {
                            var boMapper = new BOMapper(newBo);
                            var propertyValueToDisplay = boMapper.GetPropertyValueToDisplay(uiProperty.PropertyName);
                            if (propertyValueToDisplay != null)
                            {
                                _table.Columns[uiProperty.PropertyName].ReadOnly = false;
                                row[uiProperty.PropertyName] = propertyValueToDisplay;
                            }
                        }
                        else
                        {
                            ApplyRowCellValueToBOProperty(row, uiProperty, newBo);
                        }
                    }
                }
                finally
                {
                    RegisterForBOEvents();
                }
                string message;
                if (newBo.Status.IsValid(out message))
                {
                    newBo.Save();
                    row.AcceptChanges();
                }
                row.RowError = message;
                if (newBo.Status.IsNew)
                {
                    _addedRows.Add(row, newBo);
                }

                if (newBo.ID.ObjectID == Guid.Empty)
                {
                    throw new HabaneroDeveloperException
                              ("Serious error The objectID is Empty", "Serious error The objectID is Empty");
                }
                _isBeingAdded = false;
            }
            catch (Exception ex)
            {
                _isBeingAdded = false;
                if (e.Row != null)
                {
                    e.Row.RowError = ex.Message;
                }
                throw;
            }
        }
示例#6
0
        public void Test_GetPropertyValueToDisplay_WhenVirtualPropertyValue()
		{
			ClassDef.ClassDefs.Clear();
			_itsClassDef = MyBO.LoadDefaultClassDef();
			MyBO bo1 = (MyBO)_itsClassDef.CreateNewBusinessObject();

			BOMapper mapper = new BOMapper(bo1);
			Assert.AreEqual("MyNameIsMyBo", mapper.GetPropertyValueToDisplay("-MyName-"));
		}
示例#7
0
		public void Test_GetPropertyValue_WithDot_IncorrectRelationshipName()
		{
			//---------------Set up test pack-------------------
			ClassDef.ClassDefs.Clear();
			_itsClassDef = MyBO.LoadClassDefWithRelationship();
			_itsRelatedClassDef = MyRelatedBo.LoadClassDef();
			MyBO bo1 = (MyBO) _itsClassDef.CreateNewBusinessObject();
			BOMapper mapper = new BOMapper(bo1);
			//---------------Execute Test ----------------------
			try
			{
				mapper.GetPropertyValueToDisplay("MyIncorrectRelationship.MyRelatedTestProp");
				Assert.Fail("Expected to throw an RelationshipNotFoundException");
			}
				//---------------Test Result -----------------------
			catch (RelationshipNotFoundException ex)
			{
				StringAssert.Contains("The relationship 'MyIncorrectRelationship' on 'MyBO' cannot be found", ex.Message);
			}
		}
示例#8
0
		public void Test_GetPropertyValue_WithDot()
		{
			ClassDef.ClassDefs.Clear();
			_itsClassDef = MyBO.LoadClassDefWithRelationship();
			_itsRelatedClassDef = MyRelatedBo.LoadClassDef();
			//MyBO bo1 = (MyBO)itsClassDef.CreateNewBusinessObject(connection);
			MyBO bo1 = (MyBO)_itsClassDef.CreateNewBusinessObject();
			MyRelatedBo relatedBo = (MyRelatedBo)_itsRelatedClassDef.CreateNewBusinessObject();
			Guid myRelatedBoGuid = relatedBo.ID.GetAsGuid();
			bo1.SetPropertyValue("RelatedID", myRelatedBoGuid);
			relatedBo.SetPropertyValue("MyRelatedTestProp", "MyValue");
			BOMapper mapper = new BOMapper(bo1);

			Assert.AreEqual("MyValue", mapper.GetPropertyValueToDisplay("MyRelationship.MyRelatedTestProp"));
		}
示例#9
0
		public void Test_GetPropertyValueToDisplay_SimpleLookup()
		{
			ClassDef.ClassDefs.Clear();
			_itsClassDef = MyBO.LoadClassDefWithSimpleIntegerLookup();
			MyBO bo1 = (MyBO)_itsClassDef.CreateNewBusinessObject();
			bo1.SetPropertyValue("TestProp2", "Text");
			BOMapper mapper = new BOMapper(bo1);
			Assert.AreEqual("Text", mapper.GetPropertyValueToDisplay("TestProp2"));
		}
示例#10
0
		public void Test_SetPropertyDisplayValue_WithIntString_ShouldBeAbleGetString()
		{
			//---------------Set up test pack-------------------

			ClassDef.ClassDefs.Clear();
			MyBO.LoadDefaultClassDef();
			var testBo = new MyBO();
			var boMapper = new BOMapper(testBo);
			const string propName = "TestProp";
			boMapper.SetDisplayPropertyValue(propName, "7");
			//---------------Assert Precondition----------------
			Assert.AreEqual("7", boMapper.GetPropertyValueToDisplay(propName).ToString());
			//---------------Execute Test ----------------------
			boMapper.SetDisplayPropertyValue(propName, "3");
			//---------------Test Result -----------------------
			Assert.AreEqual("3", boMapper.GetPropertyValueToDisplay(propName).ToString());
			Assert.AreEqual("3", testBo.TestProp);
		}
示例#11
0
 /// <summary>
 /// This is a bit of a hack_ was used on a specific project some time ago.
 /// This is not generally supported throughout Habanero so has been isolated here.
 /// </summary>
 /// <param name="propertyName"></param>
 /// <returns></returns>
 private object GetAlternateRelationshipValue(string propertyName)
 {
     string relationshipName = propertyName.Substring(0, propertyName.IndexOf("."));
     propertyName = propertyName.Remove(0, propertyName.IndexOf(".") + 1);
     string[] parts = relationshipName.Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
     List<string> relNames = new List<string>(parts);
     IBusinessObject relatedBo = this._businessObject;
     IBusinessObject oldBo = relatedBo;
     int i = 0;
     do
     { 
         relatedBo = oldBo.Relationships.GetRelatedObject(relNames[i++]);
     } while (relatedBo == null && i < relNames.Count);
     if (relatedBo == null)
     {
         return null;
         //throw new HabaneroApplicationException("Unable to retrieve property " + propertyName + " from a business object of type " + this._businessObject.GetType().Name);
     }
     BOMapper relatedBoMapper = new BOMapper(relatedBo);
     return relatedBoMapper.GetPropertyValueToDisplay(propertyName);
 }
示例#12
0
 /// <summary>
 /// Gets a list of the property values to display to the user
 /// </summary>
 /// <param name="businessObject">The business object whose
 /// properties are to be displayed</param>
 /// <returns>Returns an array of values</returns>
 protected object[] GetValues(IBusinessObject businessObject)
 {
     if (businessObject == null) throw new ArgumentNullException("businessObject");
     object[] values = new object[_uiGridProperties.Count + 1];
     values[0] = businessObject.ID.ObjectID;
     int i = 1;
     BOMapper mapper = new BOMapper(businessObject);
     foreach (UIGridColumn gridProperty in _uiGridProperties)
     {
         object val = mapper.GetPropertyValueToDisplay(gridProperty.PropertyName);
         values[i++] = val ?? DBNull.Value;
     }
     return values;
 }
示例#13
0
 /// <summary>
 /// Returns the property value of the business object being mapped
 /// </summary>
 /// <returns>Returns the property value in appropriate object form</returns>
 protected virtual object GetPropertyValue()
 {
     if (_businessObject != null)
     {
         var boMapper = new BOMapper(_businessObject);
         return boMapper.GetPropertyValueToDisplay(PropertyName);
     }
     return null;
 }