Example #1
0
 private void OnViewChanged(PropertyModelView view, bool isAdded)
 {
     if (ViewChanged != null)
     {
         ViewChanged(this, new ViewChangeEventArgs(isAdded, view));
     }
 }
        ///<summary>
        ///Converts the given value object to the specified type, using the specified context and culture information.
        ///</summary>
        ///
        ///<returns>
        ///An <see cref="T:System.Object"></see> that represents the converted value.
        ///</returns>
        ///
        ///<param name="culture">A <see cref="T:System.Globalization.CultureInfo"></see>. If null is passed, the current culture is assumed. </param>
        ///<param name="descContext">An <see cref="T:System.ComponentModel.ITypeDescriptorContext"></see> that provides a format context. </param>
        ///<param name="destinationType">The <see cref="T:System.Type"></see> to convert the value parameter to. </param>
        ///<param name="value">The <see cref="T:System.Object"></see> to convert. </param>
        ///<exception cref="T:System.NotSupportedException">The conversion cannot be performed. </exception>
        ///<exception cref="T:System.ArgumentNullException">The destinationType parameter is null. </exception>
        public override object ConvertTo(ITypeDescriptorContext descContext, CultureInfo culture, object value,
                                         Type destinationType)
        {
            if (destinationType == typeof(string))
            {
                TypeConverter coreConverter = TypeDescriptor.GetConverter(t);
                if (coreConverter != null && coreConverter.CanConvertTo(typeof(string)))
                {
                    if (value is string && i18nList.Contains(value))
                    {
                        return(value);
                    }
                    //we need this for a  human readable description
                    string interpretedValue;
                    if (i18NFactory != null && i18nPrefix != null && i18nPrefix != "")
                    {
                        interpretedValue =
                            PropertyModelView.GetLocalizedString(i18NFactory, context, i18nPrefix + ".VALUE.", coreConverter.ConvertToString(value));
                    }
                    else
                    {
                        interpretedValue = coreConverter.ConvertToString(value);
                    }
//                    Console.WriteLine("Value "+value+", i18n: "+interpretedValue);
                    return(interpretedValue);
                }
            }
            return(null);
        }
        public async Task <int> CreatePropertyBuildingAsync(PropertyModelView propertyModelView, CancellationToken token = default)
        {
            if (propertyModelView.IdOwner == 0)
            {
                throw new Exception("Id Owner should be greater than 0");
            }
            var owner = await _uow.GetObjectByKeyAsync <Owner>(propertyModelView.IdOwner).ConfigureAwait(false);

            if (owner == null)
            {
                owner          = new Owner(_uow);
                owner.Address  = "Unknown address";
                owner.Birthday = DateTime.Now;
                owner.Name     = "Unknown name";
            }
            var propertyBuilding = new Property(_uow);

            propertyBuilding.Name         = propertyModelView.Name;
            propertyBuilding.Address      = propertyModelView.Address;
            propertyBuilding.Owner        = owner;
            propertyBuilding.Price        = propertyModelView.Price;
            propertyBuilding.Year         = propertyModelView.Year;
            propertyBuilding.CodeInternal = propertyModelView.CodeInternal;
            await _uow.CommitChangesAsync();

            return(await Task.FromResult(propertyBuilding.Oid));
        }
        public void CreateNewBuildingPropertyTestWithoutOwnerId()
        {
            RealEstateXPOServices realEstate = new RealEstateXPOServices(_uow);
            var property = new PropertyModelView {
                Address = "AddressTest", CodeInternal = "Code", IdOwner = 0, IdProperty = 1, Name = "NameTest", Price = 2540, Year = 2015
            };

            Assert.ThrowsAsync <Exception>(async() => await realEstate.CreatePropertyBuildingAsync(property));
        }
Example #5
0
        private void RegisterView(IModelView view)
        {
            PropertyModelView propertyModelView = view as PropertyModelView;

            if (propertyModelView != null)
            {
                _registeredViews.Add(propertyModelView);
            }
        }
        /// <summary>
        ///   SOLID PRinciples, Single responsibilities.
        /// </summary>
        /// <returns></returns>
        private async Task <Property> CreateDefaultPropertyBuildingAsync()
        {
            var propertyModelView = new PropertyModelView {
                Address = "Unknown Address", CodeInternal = "Code Internal Unknown", Name = "Unknown Name", Price = 0, Year = DateTime.Now.Year, IdOwner = -1,
            };
            var IdProperty = await CreatePropertyBuildingAsync(propertyModelView).ConfigureAwait(false);

            return(await _uow.GetObjectByKeyAsync <Property>(IdProperty));
        }
Example #7
0
 internal void AddView(PropertyModelView view)
 {
     if (views == null)
     {
         views = new List <IModelView>();
     }
     //todo: add notification
     views.Add(view);
     OnViewChanged(view, true);
 }
        public async Task CreateNewBuildingPropertyTestCreateDefaultOwner()
        {
            RealEstateXPOServices realEstate = new RealEstateXPOServices(_uow);
            var property = new PropertyModelView {
                Address = "AddressTest", CodeInternal = "Code", IdOwner = -1, IdProperty = 1, Name = "NameTest", Price = 2540, Year = 2015
            };
            var result = await realEstate.CreatePropertyBuildingAsync(property);

            Assert.IsTrue(result > 0);
        }
        /// <inheritdoc/>
        public override EditorControl CreateControl(OptionHandler oh, bool autoAdopt, bool autoCommit)
        {
            PropertyModelView view = new PropertyModelView(oh, this, true);

            view.IsAutoAdopt  = autoAdopt;
            view.IsAutoCommit = autoCommit;
            EditorControl clientControl = new DialogEditorControl(view, MultiLine);

            return(clientControl);
        }
Example #10
0
        public async Task <IActionResult> CreateBuildingPropertyAsync([FromForm] PropertyModelView property)
        {
            if (!TryValidateModel(property))
            {
                return(BadRequest(GetFullErrorMessage(ModelState)));
            }
            var idBuildingProperty = await _realEstateServices.CreatePropertyBuildingAsync(property);

            return(Ok(idBuildingProperty));
        }
        /// <inheritdoc/>
        public override EditorControl CreateControl(OptionHandler oh, bool autoAdopt, bool autoCommit)
        {
            PropertyModelView view = new PropertyModelView(oh, this);

            view.IsAutoAdopt  = autoAdopt;
            view.IsAutoCommit = autoCommit;
            PropertyGridEditorControl clientControl = new PropertyGridEditorControl(view);

            clientControl.ToolbarVisible = ToolbarVisible;
            return(clientControl);
        }
Example #12
0
        private void RegisterView()
        {
            PropertyModelView propertyModelView = View as PropertyModelView;

            if (propertyModelView != null)
            {
                _registeredViews.Add(propertyModelView);
                View.StatusChanged     += view_StatusChanged;
                View.PostContentChange += view_ContentChanged;
            }
        }
        public override Size GetPreferredSize(Size proposedSize)
        {
            PropertyModelView propertyModelView = View as PropertyModelView;

            if (propertyModelView != null)
            {
                int height = (propertyModelView.GetProperties().Count +
                              propertyModelView.SectionCount + 2) * 20 +
                             propertyGrid1.GetPreferredSize(proposedSize).Height;

                return(new Size(propertyGrid1.GetPreferredSize(proposedSize).Width, height));
            }
            return(new Size(propertyGrid1.GetPreferredSize(proposedSize).Width,
                            propertyGrid1.GetPreferredSize(proposedSize).Height));
        }
        public ListTypeConverter(IEnumerable domain, Type t, bool listValuesExclusive,
                                 I18NFactory i18NFactory, string i18nprefix, string context)
        {
            this.t  = t;
            i18nMap = new Dictionary <string, object>();

            this.listValuesExclusive = listValuesExclusive;
            this.i18NFactory         = i18NFactory;
            this.i18nPrefix          = i18nprefix;
            this.context             = context;

            TypeConverter coreConverter = TypeDescriptor.GetConverter(t);

            foreach (object o in domain)
            {
                if (coreConverter != null && coreConverter.CanConvertTo(typeof(string)))
                {
                    //we need this for a  human readable description
                    string interpretedValue;
                    if (i18NFactory != null && !string.IsNullOrEmpty(i18nprefix))
                    {
                        interpretedValue = PropertyModelView.GetLocalizedString(i18NFactory, context, i18nprefix + ".VALUE.", coreConverter.ConvertToString(o));
                    }
                    else
                    {
                        interpretedValue = coreConverter.ConvertToString(o);
                    }
                    i18nList.Add(interpretedValue);
                    i18nMap[interpretedValue] = o;
                }
                else
                {
                    i18nList.Add(o);
                }
            }
            //return new StandardValuesCollection(tmp);

            cachedStandardValues = new StandardValuesCollection(i18nList);
        }
Example #15
0
        private void CreateEditors()
        {
            SuspendLayout();
            PropertyModelView propertyModelView = _registeredViews[0];
            int nonemptyGroups = 0;

            foreach (PropertyDescriptor property in propertyModelView.GetProperties())
            {
                if (property.GetChildProperties().Count > 0)
                {
                    ++nonemptyGroups;
                }
            }

            if (nonemptyGroups < 2 || propertyModelView.SectionCount < 2)
            {
                bool drawBox = false;
                PropertyDescriptorCollection properties    = propertyModelView.GetProperties();
                DialogSectionControl         clientControl =
                    new DialogSectionControl(this, properties, drawBox, this.Title);
                topLevelControlMap[View.Handler.ID] = clientControl;
                this.Controls.Add(clientControl);
                sectionControl = clientControl;
                minHeight      = clientControl.PreferredSize.Height;
                minWidth       = clientControl.PreferredSize.Width;
                topControl     = clientControl;
            }
            else
            {
                TabControl multipleCategoryTabControl = new TabControl()
                {
                    Multiline = multiLine
                };
                if (multiLine)
                {
                    multipleCategoryTabControl.SizeMode = TabSizeMode.FillToRight;
                }
                Controls.Add(multipleCategoryTabControl);
                sectionControl = multipleCategoryTabControl;
                PropertyDescriptorCollection properties = propertyModelView.GetProperties();
                foreach (PropertyDescriptor property in properties)
                {
                    if (property.GetChildProperties().Count == 0)
                    {
                        continue;
                    }
                    string  category = property.Category;
                    string  name     = category.TrimStart('\r');
                    TabPage page     = new TabPage(name);
                    page.Name = name;
                    DialogSectionControl clientControl =
                        new DialogSectionControl(this, property.GetChildProperties(), property, false);
                    page.Controls.Add(clientControl);
                    topLevelControlMap[
                        ((PropertyModelView.OptionItemPropertyDescriptor)
                             ((PropertyModelView.OptionItemPropertyDescriptor)property).Owner).ID] = clientControl;
                    page.Dock = DockStyle.Fill;
                    multipleCategoryTabControl.TabPages.Add(page);
                    minHeight = Math.Max(minHeight, clientControl.Height);
                    minWidth  = Math.Max(minWidth, clientControl.PreferredSize.Width);
                }

                minWidth += 3;
                int tabSize = 0;
                if (multiLine)
                {
                    for (int i = 0; i < multipleCategoryTabControl.TabCount; ++i)
                    {
                        var rect = multipleCategoryTabControl.GetTabRect(i);
                        tabSize = Math.Max(tabSize, rect.Location.Y);
                    }
                }
                else
                {
                    tabSize = multipleCategoryTabControl.ItemSize.Height;
                }
                minHeight += tabSize + multipleCategoryTabControl.Margin.Vertical;

                multipleCategoryTabControl.Width  = minWidth;
                multipleCategoryTabControl.Height = minHeight;
                topControl = multipleCategoryTabControl;
                multipleCategoryTabControl.Dock = DockStyle.Fill;
            }

            ResumeLayout(false);
        }
Example #16
0
        internal virtual TypeConverter CreateConverter(PropertyModelView.OptionItemPropertyDescriptor desc,
                                                       I18NFactory i18NFactory, string context)
        {
            OptionItem             item          = desc.Item;
            TypeConverterAttribute converterAttr =
                TypeDescriptor.GetProperties(item, false)["Value"].Attributes[typeof(TypeConverterAttribute)]
                as TypeConverterAttribute;

            TypeConverter coreConverter;

            if (desc is PropertyModelView.ListPropertyDescriptor && converterAttr.ConverterTypeName == "")
            {
                //special handling for the list converter
                coreConverter =
                    new I18NTypeConverter(((PropertyModelView.ListPropertyDescriptor)desc).GetStringRepresentation(),
                                          (bool)
                                          item.GetAttribute(
                                              CollectionOptionItem <object> .USE_ONLY_DOMAIN_ATTRIBUTE));
            }
            else if (item is ICollectionSupport && converterAttr.ConverterTypeName == "")
            {
                //special handling for the list converter
                coreConverter = new ListTypeConverter(((ICollectionSupport)item).Domain,
                                                      ((ICollectionSupport)item).EntryType,
                                                      (bool)
                                                      item.GetAttribute(
                                                          CollectionOptionItem <object> .USE_ONLY_DOMAIN_ATTRIBUTE),
                                                      i18NFactory, desc.I18nKey, context);
            }
            else if (converterAttr.ConverterTypeName != "")
            {
                //attribute set, get the converter that is set by the attribute
                coreConverter = TypeDescriptor.GetProperties(item, false)["Value"].Converter;
            }
            else
            {
                //no attribute, delegate to base
                coreConverter = TypeDescriptor.GetConverter(item.Type);
            }

            //TypeConverter coreConverter = converterAttr.ConverterTypeName != "" ? itemConverter : base.Converter;
            //todo: make this dependent on item attribute
            bool   supportNull             = (bool)item.GetAttribute(OptionItem.SUPPORT_NULL_VALUE_ATTRIBUTE);
            bool   supportUndefined        = (bool)item.GetAttribute(OptionItem.SUPPORT_UNDEFINED_VALUE_ATTRIBUTE);
            string nullValueRepresentation = item.GetAttribute(OptionItem.NULL_VALUE_STRING_ATTRIBUTE) as string;

            if (i18NFactory != null)
            {
                nullValueRepresentation = PropertyModelView.GetLocalizedString(
                    i18NFactory, context, desc.I18nKey + ".VALUE.", nullValueRepresentation);
            }
            //test for overrides
            object converterOverride = item.GetAttribute(OptionItem.CUSTOM_CONVERTER_ATTRIBUTE);

            if (converterOverride != null)
            {
                if (converterOverride is TypeConverter)
                {
                    return((TypeConverter)converterOverride);
                }
                if (converterOverride is Type)
                {
                    try {
                        TypeConverter o = System.Activator.CreateInstance((Type)converterOverride) as TypeConverter;
                        if (o != null)
                        {
                            coreConverter = o;
                        }
                    } catch {
                        Trace.WriteLine("Cannot create converter instance");
                    }
                }
                else if (converterOverride is string)
                {
                    try {
                        TypeConverter o =
                            System.Activator.CreateInstance(Type.GetType((string)converterOverride)) as TypeConverter;
                        if (o != null)
                        {
                            coreConverter = o;
                        }
                    } catch {
                        Trace.WriteLine("Cannot create converter instance");
                    }
                }
                else
                {
                    Trace.WriteLine("Invalid type for converter attribute");
                }
            }
            if (supportNull || supportUndefined)
            {
                //custom conversions needed...
                if (coreConverter is ExpandableObjectConverter ||
                    coreConverter is FontConverter ||
                    coreConverter is PointConverter
                    )
                {
                    return(new ExpandableNullableTypeConverter(coreConverter,
                                                               supportNull,
                                                               supportUndefined,
                                                               nullValueRepresentation == null
                                                       ? ""
                                                       : nullValueRepresentation));
                }
                else
                {
                    return(new NullableTypeConverter(coreConverter,
                                                     supportNull,
                                                     supportUndefined,
                                                     nullValueRepresentation == null ? "" : nullValueRepresentation));
                }
            }
            return(coreConverter);
        }
Example #17
0
 public ViewChangeEventArgs(bool isAdded, PropertyModelView view)
 {
     this.isAdded = isAdded;
     this.view    = view;
 }
Example #18
0
 internal void RemoveView(PropertyModelView view)
 {
     views.Remove(view);
     OnViewChanged(view, false);
     //todo: add notification
 }
Example #19
0
 public Task <int> CreatePropertyBuildingAsync(PropertyModelView propertyModelView, CancellationToken token = default)
 {
     throw new NotImplementedException();
 }