예제 #1
0
        public bool IsGridVisibleFor(string propertyName)
        {
            bool result = false;

            IZProfileProperty profileProperty = GetProfileProperty(propertyName);

            if (profileProperty != null)
            {
                result = profileProperty.IsGridVisible;
            }

            return(result);
        }
예제 #2
0
        public int GridWidthFor(string propertyName)
        {
            int result = 100;

            IZProfileProperty profileProperty = GetProfileProperty(propertyName);

            if (profileProperty != null)
            {
                result = profileProperty.GridWidth;
            }

            return(result);
        }
예제 #3
0
        public string EditCSSFor(string name)
        {
            string result = "form-group z-group";

            IZProfileProperty profileProperty = GetProfileProperty(name);

            if (profileProperty != null)
            {
                result += " " + profileProperty.EditCSS;
            }

            return(result);
        }
예제 #4
0
        public string EditCSSFor(string propertyName)
        {
            string result = "col-md-1";

            IZProfileProperty profileProperty = GetProfileProperty(propertyName);

            if (profileProperty != null)
            {
                result = profileProperty.EditCSS;
            }

            return(result);
        }
예제 #5
0
        public bool IsRequiredView(string name)
        {
            bool result = false;

            IZProfileProperty profileProperty = GetProfileProperty(name);

            if (profileProperty != null)
            {
                result = profileProperty.IsRequiredView;
            }

            return(result);
        }
예제 #6
0
        public void SetProfileProperty(string name,
                                       bool?isGridVisible  = null,
                                       bool?isGridSearch   = null,
                                       int?gridWidth       = null,
                                       bool?isEditVisible  = null,
                                       bool?isEditReadOnly = null,
                                       string editCSS      = null)
        {
            IZProfileProperty profileProperty = GetProfileProperty(name);

            if (profileProperty != null)
            {
                if (isGridVisible != null)
                {
                    profileProperty.IsGridVisible = (bool)isGridVisible;
                }

                if (isGridSearch != null)
                {
                    profileProperty.IsGridSearch = (bool)isGridSearch;
                }

                if (gridWidth != null)
                {
                    profileProperty.GridWidth = (int)gridWidth;
                }

                if (isEditVisible != null)
                {
                    profileProperty.IsEditVisible = (bool)isEditVisible;
                }

                if (isEditReadOnly != null)
                {
                    profileProperty.IsEditReadOnly = (bool)isEditReadOnly;
                }

                if (!String.IsNullOrEmpty(editCSS))
                {
                    profileProperty.EditCSS = editCSS;
                }
            }
        }
예제 #7
0
        public string EditCSSLabelFor(string name)
        {
            string result = "control-label";

            IZProfileProperty profileProperty = GetProfileProperty(name);

            if (profileProperty != null)
            {
                if (profileProperty.IsRequiredView)
                {
                    result += " z-labelRequired";
                }
                else
                {
                    result += " z-label";
                }
            }

            return(result);
        }
예제 #8
0
        public string EditCSSEditorDateTimeFor(string name)
        {
            string result = "";

            IZProfileProperty profileProperty = GetProfileProperty(name);

            if (profileProperty != null)
            {
                if (profileProperty.IsRequiredView)
                {
                    result = "z-editorDateTimeRequired";
                }
                else
                {
                    result = "z-editorDateTime";
                }
            }

            return(result);
        }
예제 #9
0
        public string EditCSSEditorFor(string name)
        {
            string result = "form-control input-sm";

            IZProfileProperty profileProperty = GetProfileProperty(name);

            if (profileProperty != null)
            {
                if (profileProperty.IsRequiredView)
                {
                    result += " z-editorRequired";
                }
                else
                {
                    result += " z-editor";
                }
            }

            return(result);
        }
예제 #10
0
        /// <summary>
        /// Set View Profile for types.
        /// </summary>
        /// <param name="typeViewModel">View type</param>
        /// <param name="typeDataModel">Data type</param>
        /// <returns></returns>
        public static IZProfile SetViewProfile(Type typeViewModel, Type typeDataModel)
        {
            IZProfile profile;

            if (!Profiles.Keys.Contains(typeDataModel))
            {
                profile      = new ZProfile();
                profile.Name = typeDataModel.Name;

                Profiles.Add(typeDataModel, profile);
            }
            else
            {
                profile = Profiles[typeDataModel];
            }

            //int gridVisibles = 0;

            PropertyInfo[] properties = typeViewModel.GetProperties(BindingFlags.Instance | BindingFlags.Public);
            foreach (PropertyInfo property in properties)
            {
                if (property.Name != "LookupText")
                {
                    IZProfileProperty profileProperty = profile.GetProfileProperty(property.Name);
                    if (profileProperty == null)
                    {
                        profileProperty      = new ZProfileProperty();
                        profileProperty.Name = property.Name;

                        profile.Properties.Add(profileProperty);
                    }

                    if (Attribute.IsDefined(property, typeof(RequiredAttribute)))
                    {
                        profileProperty.IsRequiredView = true;
                    }
                    else
                    {
                        profileProperty.IsRequiredView = false;
                    }

                    /*
                     * IsBoolean          5
                     * IsDateTime        10
                     * IsFloat           10
                     * IsInteger          5
                     * IsString
                     *   GridWidth
                     *     <= 5           5
                     *     <= 10         10
                     *     <= 15         15
                     *     ...           20
                     *   LookupText      20
                     *
                     * IsBoolean         50     col-md-1
                     * IsDateTime        50     col-md-2
                     * IsFloat           50     col-md-1
                     * IsInteger         50     col-md-1
                     * IsString
                     *   GridWidth
                     *     <= 5          50
                     *     <= 10        100
                     *     <= 15        150
                     *     ...          200
                     *   EditCSS
                     *     <= 10                col-md-1
                     *     <= 20                col-md-2
                     *     <= 30                col-md-3
                     *     <= 50                col-md-4
                     *     ...                  col-md-4
                     *   LookupText     200     col-md-4
                     */

                    //bool isGridVisible = false;
                    bool   isGridSearch = false;
                    int    gridWidth    = 5; // 50
                    string editCSS      = "col-md-2";

                    if (LibraryHelper.IsBoolean(property.PropertyType))
                    {
                        //isGridVisible = true;
                        gridWidth = 5; // 50;
                        editCSS   = "col-md-1";
                    }
                    else if (LibraryHelper.IsDateTime(property.PropertyType))
                    {
                        //isGridVisible = true;
                        gridWidth = 10; // 100;
                        editCSS   = "col-md-2";
                    }
                    else if (LibraryHelper.IsFloat(property.PropertyType))
                    {
                        //isGridVisible = true;
                        gridWidth = 5; // 50;
                        editCSS   = "col-md-1";
                    }
                    else if (LibraryHelper.IsInteger(property.PropertyType))
                    {
                        //isGridVisible = true;
                        gridWidth = 5; // 50;
                        editCSS   = "col-md-1";
                    }
                    else if (LibraryHelper.IsString(property.PropertyType))
                    {
                        //isGridVisible = true;
                        isGridSearch = true;

                        int length = 0;
                        StringLengthAttribute stringLength = (StringLengthAttribute)property.GetCustomAttribute(typeof(StringLengthAttribute));
                        if (stringLength != null)
                        {
                            length = stringLength.MaximumLength;
                        }

                        if (length <= 5)
                        {
                            gridWidth = 5; // 50;
                        }
                        else if (length <= 10)
                        {
                            gridWidth = 10; // 100;
                        }
                        else if (length <= 15)
                        {
                            gridWidth = 15; // 150;
                        }
                        else
                        {
                            gridWidth = 20; // 200;
                        }

                        if (length <= 10) // 9
                        {
                            editCSS = "col-md-1";
                        }
                        else if (length <= 20) // 22
                        {
                            editCSS = "col-md-2";
                        }
                        else if (length <= 30) // 35
                        {
                            editCSS = "col-md-3";
                        }
                        else if (length <= 50) // 48
                        {
                            editCSS = "col-md-4";
                        }
                        else
                        {
                            editCSS = "col-md-4";
                        }

                        if (property.Name.EndsWith("LookupText"))
                        {
                            gridWidth = 20; // 200;
                            editCSS   = "col-md-4";
                        }
                    }

                    // Foreign Key
                    //if (property.Name != "Id" && (property.Name.StartsWith("Id") || property.Name.EndsWith("Id")))
                    //{
                    //    isGridVisible = false;
                    //}

                    // Primary Key
                    //if (profileProperty.IsKey)
                    //{
                    //    if (properties.Count() == profile.Keys.Count())
                    //    {
                    //        isGridVisible = true;
                    //    }
                    //    else
                    //    {
                    //        isGridVisible = false;
                    //    }

                    //    profileProperty.IsGridVisible = isGridVisible;
                    //}
                    //else
                    //{
                    //    if (isGridVisible)
                    //    {
                    //        if (!property.Name.EndsWith("LookupText"))
                    //        {
                    //            gridVisibles++;
                    //            if (gridVisibles > 1)
                    //            {
                    //                isGridVisible = false;
                    //            }
                    //        }

                    //        profileProperty.IsGridVisible = isGridVisible;
                    //    }
                    //}

                    profileProperty.IsGridVisible =
                        property.Name == profile.Lookup || (profileProperty.IsKey && !profileProperty.IsIdentity);
                    profileProperty.IsGridSearch   = isGridSearch;
                    profileProperty.GridWidth      = gridWidth;
                    profileProperty.IsEditVisible  = true;
                    profileProperty.IsEditReadOnly = false;
                    profileProperty.EditCSS        = editCSS;
                }
            }

            return(profile);
        }
예제 #11
0
        /// <summary>
        /// Set Data Profile for type.
        /// </summary>
        /// <param name="typeDataModel">Type</param>
        /// <returns></returns>
        public static IZProfile SetDataProfile(Type typeDataModel)
        {
            IZProfile profile;

            if (!Profiles.Keys.Contains(typeDataModel))
            {
                profile      = new ZProfile();
                profile.Name = typeDataModel.Name;

                Profiles.Add(typeDataModel, profile);
            }
            else
            {
                profile = Profiles[typeDataModel];
            }

            bool   isIdentity = false;
            string lookup     = "";

            PropertyInfo[] properties = typeDataModel.GetProperties(BindingFlags.Instance | BindingFlags.Public);
            foreach (PropertyInfo property in properties)
            {
                if (property.Name != "LookupText")
                {
                    // Associations - ZDataBase
                    bool isAssociation = false;
                    if (property.PropertyType.IsSubclassOf(typeof(ZDataBase)) && !property.PropertyType.IsAbstract)
                    {
                        isAssociation = true;
                        profile.Associations.Add(property.Name);
                    }

                    // Collections - IList<ZDataBase>
                    bool isCollection = false;
                    Type typeIList    = IListType(property.PropertyType);
                    if (typeIList.IsSubclassOf(typeof(ZDataBase)) && !typeIList.IsAbstract)
                    {
                        isCollection = true;
                        profile.Collections.Add(property.Name, true);
                    }

                    if (!isAssociation && !isCollection)
                    {
                        IZProfileProperty profileProperty = profile.GetProfileProperty(property.Name);
                        if (profileProperty == null)
                        {
                            profileProperty      = new ZProfileProperty();
                            profileProperty.Name = property.Name;

                            profile.Properties.Add(profileProperty);
                        }

                        //profile.IsRequiredData = LibraryHelper.IsNullable(property.PropertyType);
                        //if (Attribute.IsDefined(property, typeof(RequiredAttribute)))
                        //{
                        //    profileProperty.IsRequiredData = true;
                        //}
                        //else
                        //{
                        //    profileProperty.IsRequiredData = false;
                        //}

                        // ZKeyAttribute
                        ZKeyAttribute zKey = (ZKeyAttribute)property.GetCustomAttribute(typeof(ZKeyAttribute));
                        if (zKey != null)
                        {
                            profile.Keys.Add(property.Name);
                            profileProperty.IsKey      = true;
                            profileProperty.IsIdentity = zKey.IsIdentity;
                            isIdentity = zKey.IsIdentity;
                        }
                        else
                        {
                            // 1st Property after Primary Key(s)
                            if (String.IsNullOrEmpty(lookup) &&
                                !property.Name.StartsWith("Id") &&
                                !property.Name.EndsWith("Id") &&
                                !property.Name.EndsWith("LookupText"))
                            {
                                lookup = property.Name;
                            }
                        }
                    }
                }
            }

            lookup = String.IsNullOrEmpty(lookup) ? profile.Keys[0] : lookup;

            profile.IsIdentity  = isIdentity;
            profile.Lookup      = lookup;
            profile.LINQOrderBy = lookup;
            string where        = "";
            int parameter = 0;

            foreach (string key in profile.Keys)
            {
                where += String.IsNullOrEmpty(where) ? "" : " && ";
                where += key + " == @" + parameter++.ToString();
            }
            profile.LINQWhere = where;

            return(profile);
        }