Пример #1
0
        /// <summary>
        /// Set value to domain
        /// </summary>
        /// <param name="domainSupport"></param>
        /// <param name="data"></param>
        /// <param name="value"></param>
        /// <exception cref="ApplicationException"><c>ApplicationException</c>.</exception>
        private void SetValueIntoDomain(IUIDataModelSupport domainSupport, IUIDataModel data, object value)
        {
            string path = domainSupport.PathString;

            //string domainName = ExtractDomainName(path);
            string[] nestedPropertyNames = ExtractNestedPropertyName(path);
            string   resutlPropertyName  = ExtractResultPropertyName(path);

            // ค้นหาทุกๆ Nested Property เพื่อทำการ Get
            object objLastNestedProperty = data;

            if (nestedPropertyNames != null)
            {
                for (int i = 0; i < nestedPropertyNames.Length; i++)
                {
                    Type         typeProperty = objLastNestedProperty.GetType();
                    PropertyInfo propInfo     = typeProperty.GetProperty(nestedPropertyNames[i]);
                    if (propInfo == null)
                    {
                        throw new ApplicationException(String.Format("Not found property \"{0}\" on path: \"{1}\"", nestedPropertyNames[i], path));
                    }

                    if (!propInfo.CanRead)
                    {
                        throw new ApplicationException(String.Format("path: \"{0}\", cannot access property name \"{1}\"", path, nestedPropertyNames[i]));
                    }
                    objLastNestedProperty = propInfo.GetGetMethod().Invoke(objLastNestedProperty, null);
                }
            }

            // ค้นหา Result Property เพื่อทำการ get object

            Type         typeObject     = objLastNestedProperty.GetType();
            PropertyInfo propResultInfo = typeObject.GetProperty(resutlPropertyName);

            if (propResultInfo == null)
            {
                throw new ApplicationException(String.Format("Not found property \"{0}\" on path: \"{1}\"", resutlPropertyName, path));
            }

            if (!propResultInfo.CanWrite)
            {
                throw new ApplicationException(String.Format("path: \"{0}\", cannot access property name \"{1}\"", path, resutlPropertyName));
            }

            if (objLastNestedProperty is NZBaseObject)
            {
                ((NZBaseObject)objLastNestedProperty).Owner = domainSupport;
            }

            propResultInfo.SetValue(objLastNestedProperty, value, null);
        }
Пример #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="path"></param>
        /// <param name="data"></param>
        /// <returns></returns>
        /// <exception cref="ApplicationException"><c>ApplicationException</c>.</exception>
        private object GetValueDomainFromPath(string path, IUIDataModel data)
        {
            //string domainName = ExtractDomainName(path);
            string[] nestedPropertyNames = ExtractNestedPropertyName(path);
            string   resutlPropertyName  = ExtractResultPropertyName(path);

            // ค้นหาทุกๆ Nested Property เพื่อทำการ Get
            object objLastNestedProperty = data;

            if (nestedPropertyNames != null)
            {
                for (int i = 0; i < nestedPropertyNames.Length; i++)
                {
                    Type         typeProperty = objLastNestedProperty.GetType();
                    PropertyInfo propInfo     = typeProperty.GetProperty(nestedPropertyNames[i]);
                    if (propInfo == null)
                    {
                        throw new ApplicationException(String.Format("Not found property \"{0}\" on path: \"{1}\"", nestedPropertyNames[i], path));
                    }

                    if (!propInfo.CanRead)
                    {
                        throw new ApplicationException(String.Format("path: \"{0}\", cannot access property name \"{1}\"", path, nestedPropertyNames[i]));
                    }
                    objLastNestedProperty = propInfo.GetGetMethod().Invoke(objLastNestedProperty, null);
                }
            }

            // ค้นหา Result Property เพื่อทำการ get object

            Type         typeObject     = objLastNestedProperty.GetType();
            PropertyInfo propResultInfo = typeObject.GetProperty(resutlPropertyName);

            if (propResultInfo == null)
            {
                throw new ApplicationException(String.Format("Not found property \"{0}\" on path: \"{1}\"", resutlPropertyName, path));
            }

            if (!propResultInfo.CanRead)
            {
                throw new ApplicationException(String.Format("path: \"{0}\", cannot access property name \"{1}\"", path, resutlPropertyName));
            }

            return(propResultInfo.GetValue(objLastNestedProperty, null));
        }
Пример #3
0
        /// <summary>
        /// Load data from Domain to UI
        /// </summary>
        /// <param name="data"></param>
        public void LoadData(IUIDataModel data)
        {
            List <string> listRadioGroup = new List <string>();

            for (int i = 0; i < ListDomainSupport.Count; i++)
            {
                if (ListDomainSupport[i].PathString == null || ListDomainSupport[i].PathString == String.Empty)
                {
                    System.Diagnostics.Debug.WriteLine(String.Format("UI Model has empty path on object: \"{0}\"", ListDomainSupport[i].GetType().Name));
                    continue;
                }

                object objValue = GetValueDomainFromPath(ListDomainSupport[i].PathString, data);


                if (ListDomainSupport[i] is EVORadioButton)
                {
                    // Check duplicate.
                    if (listRadioGroup.Contains(ListDomainSupport[i].PathString))
                    {
                        continue;
                    }

                    // Otherwise will add into list.
                    for (int iControl = i; iControl < ListDomainSupport.Count; iControl++)
                    {
                        if (ListDomainSupport[iControl] is EVORadioButton)
                        {
                            EVORadioButton radioButton = (EVORadioButton)ListDomainSupport[iControl];

                            // if element in loop is equal property value on path.
                            if (object.Equals(radioButton.SpecificValue, objValue))
                            {
                                radioButton.Checked = true;
                                break;
                            }
                        }
                    }

                    listRadioGroup.Add(ListDomainSupport[i].PathString);
                }
                else if (ListDomainSupport[i] is EVOCheckBox)
                {
                    // Check duplicate.
                    if (listRadioGroup.Contains(ListDomainSupport[i].PathString))
                    {
                        continue;
                    }

                    // Otherwise will add into list.
                    for (int iControl = i; iControl < ListDomainSupport.Count; iControl++)
                    {
                        if (ListDomainSupport[iControl] is EVOCheckBox)
                        {
                            EVOCheckBox chkBox = (EVOCheckBox)ListDomainSupport[iControl];

                            // if element in loop is equal property value on path.
                            if (object.Equals(chkBox.CheckedValue, objValue.ToString()))
                            {
                                chkBox.Checked = true;
                                break;
                            }
                            else
                            {
                                chkBox.Checked = false;
                                break;
                            }
                        }
                    }

                    listRadioGroup.Add(ListDomainSupport[i].PathString);
                }
                else
                {  // General control editor.
                    ListDomainSupport[i].PathValue = objValue;
                }
            }
        }