Exemplo n.º 1
0
        private void addEditItem(int spacing, ref int top, ref int lblWidth, ref bool hasEditable, GenericQbItem gi)
        {
            GenericQbEditItem ei;
            ei = new GenericQbEditItem();
            ei.SetData(gi);
            ei.Left = 0;
            ei.Width = this.ClientSize.Width;
            ei.Top = top;
            top += spacing;
            ei.Anchor = AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Right;

            if (!hasEditable && !gi.ReadOnly)
                hasEditable = true;

            if (gi.UseQbItemType)
                ei.ConvertTo(base.QbItemDataType);
            //else
            //    ei.ConvertTo(base.EditType);

            this.Controls.Add(ei);

            if (ei.LabelWidth > lblWidth)
                lblWidth = ei.LabelWidth;
        }
Exemplo n.º 2
0
        public void SetData(GenericQbItem item)
        {
            _gItem = item;

            txtValue.ReadOnly = item.ReadOnly;

            if (!GenericQbItem.IsTypeSupported(item.Type))
                throw new ArgumentOutOfRangeException(string.Format("{0} is not supported", _gItem.Type.FullName));

            btnConvert.Text = GenericQbItem.GetTypeName(_gItem.CurrentEditType);

            lbl.Text = _gItem.Name;

            txtValue.Text = _gItem.Value;
        }
Exemplo n.º 3
0
        /// <summary>
        /// Analyse the attributes on the item and return the editable items
        /// </summary>
        /// <param name="item"></param>
        /// <returns></returns>
        public static List <GenericQbItem> GetGenericItems(QbItemBase item)
        {
            List <GenericQbItem> items = new List <GenericQbItem>();
            GenericQbItem        itm   = null;

            MemberInfo[] ms = item.GetType().FindMembers(MemberTypes.Property,
                                                         /*BindingFlags.DeclaredOnly |*/ BindingFlags.Instance | BindingFlags.Public,
                                                         Type.FilterName, "*");

            foreach (MemberInfo m in ms)
            {
                GenericEditableAttribute a = Attribute.GetCustomAttribute(m, typeof(GenericEditableAttribute)) as GenericEditableAttribute;
                if (a != null)
                {
                    //return attribute value and pass in to generic items and return
                    object o = ((PropertyInfo)m).GetValue(item, null);
                    if (o == null)
                    {
                        continue;
                    }
                    if (o is byte[]) //hex
                    {
                        itm = new GenericQbItem(a.DefaultDisplayName, (byte[])o, a.EditType, a.ReadOnly, a.UseQbItemType, item.QbItemType, m.Name);
                        items.Add(itm);
                    }
                    else if (o is string[])
                    {
                        foreach (string s in ((string[])o))
                        {
                            itm = new GenericQbItem(a.DefaultDisplayName, s, a.EditType, a.ReadOnly, a.UseQbItemType, item.QbItemType, m.Name);
                            items.Add(itm);
                        }
                    }
                    else if (o is string)
                    {
                        itm = new GenericQbItem(a.DefaultDisplayName, (string)o, a.EditType, a.ReadOnly, a.UseQbItemType, item.QbItemType, m.Name);
                        items.Add(itm);
                    }
                    else if (o is uint[])
                    {
                        foreach (uint s in ((uint[])o))
                        {
                            itm = new GenericQbItem(a.DefaultDisplayName, s, a.EditType, a.ReadOnly, a.UseQbItemType, item.QbItemType, m.Name);
                            items.Add(itm);
                        }
                    }
                    else if (o is uint)
                    {
                        itm = new GenericQbItem(a.DefaultDisplayName, (uint)o, a.EditType, a.ReadOnly, a.UseQbItemType, item.QbItemType, m.Name);
                        items.Add(itm);
                    }
                    else if (o is int[])
                    {
                        foreach (int s in ((int[])o))
                        {
                            itm = new GenericQbItem(a.DefaultDisplayName, s, a.EditType, a.ReadOnly, a.UseQbItemType, item.QbItemType, m.Name);
                            items.Add(itm);
                        }
                    }
                    else if (o is int)
                    {
                        itm = new GenericQbItem(a.DefaultDisplayName, (int)o, a.EditType, a.ReadOnly, a.UseQbItemType, item.QbItemType, m.Name);
                        items.Add(itm);
                    }
                    else if (o is float[])
                    {
                        foreach (float s in ((float[])o))
                        {
                            itm = new GenericQbItem(a.DefaultDisplayName, s, a.EditType, a.ReadOnly, a.UseQbItemType, item.QbItemType, m.Name);
                            items.Add(itm);
                        }
                    }
                    else if (o is float)
                    {
                        itm = new GenericQbItem(a.DefaultDisplayName, (float)o, a.EditType, a.ReadOnly, a.UseQbItemType, item.QbItemType, m.Name);
                        items.Add(itm);
                    }
                    else if (o is QbKey[])
                    {
                        foreach (QbKey s in ((QbKey[])o))
                        {
                            itm = new GenericQbItem(a.DefaultDisplayName, s, a.EditType, a.ReadOnly, a.UseQbItemType, item.QbItemType, m.Name);
                            items.Add(itm);
                        }
                    }
                    else if (o is QbKey)
                    {
                        itm = new GenericQbItem(a.DefaultDisplayName, (QbKey)o, a.EditType, a.ReadOnly, a.UseQbItemType, item.QbItemType, m.Name);
                        items.Add(itm);
                    }
                    else
                    {
                        throw new ApplicationException(string.Format("Unknown generic data type item '{0}'", o.GetType().Name));
                    }
                }
            }
            return(items);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Analyse the attributes on the item and return the editable items
        /// </summary>
        /// <param name="item"></param>
        /// <returns></returns>
        public static List<GenericQbItem> GetGenericItems(QbItemBase item)
        {
            List<GenericQbItem> items = new List<GenericQbItem>();
            GenericQbItem itm = null;

            MemberInfo[] ms = item.GetType().FindMembers(MemberTypes.Property,
                /*BindingFlags.DeclaredOnly |*/ BindingFlags.Instance | BindingFlags.Public,
                Type.FilterName, "*");

            foreach (MemberInfo m in ms)
            {
                GenericEditableAttribute a = Attribute.GetCustomAttribute(m, typeof(GenericEditableAttribute)) as GenericEditableAttribute;
                if (a != null)
                {

                    //return attribute value and pass in to generic items and return
                    object o = ((PropertyInfo)m).GetValue(item, null);
                    if (o == null)
                        continue;
                    if (o is byte[]) //hex
                    {
                        itm = new GenericQbItem(a.DefaultDisplayName, (byte[])o, a.EditType, a.ReadOnly, a.UseQbItemType, item.QbItemType, m.Name);
                        items.Add(itm);
                    }
                    else if (o is string[])
                    {
                        foreach (string s in ((string[])o))
                        {
                            itm = new GenericQbItem(a.DefaultDisplayName, s, a.EditType, a.ReadOnly, a.UseQbItemType, item.QbItemType, m.Name);
                            items.Add(itm);
                        }
                    }
                    else if (o is string)
                    {
                        itm = new GenericQbItem(a.DefaultDisplayName, (string)o, a.EditType, a.ReadOnly, a.UseQbItemType, item.QbItemType, m.Name);
                        items.Add(itm);
                    }
                    else if (o is uint[])
                    {
                        foreach (uint s in ((uint[])o))
                        {
                            itm = new GenericQbItem(a.DefaultDisplayName, s, a.EditType, a.ReadOnly, a.UseQbItemType, item.QbItemType, m.Name);
                            items.Add(itm);
                        }
                    }
                    else if (o is uint)
                    {
                        itm = new GenericQbItem(a.DefaultDisplayName, (uint)o, a.EditType, a.ReadOnly, a.UseQbItemType, item.QbItemType, m.Name);
                        items.Add(itm);
                    }
                    else if (o is int[])
                    {
                        foreach (int s in ((int[])o))
                        {
                            itm = new GenericQbItem(a.DefaultDisplayName, s, a.EditType, a.ReadOnly, a.UseQbItemType, item.QbItemType, m.Name);
                            items.Add(itm);
                        }
                    }
                    else if (o is int)
                    {
                        itm = new GenericQbItem(a.DefaultDisplayName, (int)o, a.EditType, a.ReadOnly, a.UseQbItemType, item.QbItemType, m.Name);
                        items.Add(itm);
                    }
                    else if (o is float[])
                    {
                        foreach (float s in ((float[])o))
                        {
                            itm = new GenericQbItem(a.DefaultDisplayName, s, a.EditType, a.ReadOnly, a.UseQbItemType, item.QbItemType, m.Name);
                            items.Add(itm);
                        }
                    }
                    else if (o is float)
                    {
                        itm = new GenericQbItem(a.DefaultDisplayName, (float)o, a.EditType, a.ReadOnly, a.UseQbItemType, item.QbItemType, m.Name);
                        items.Add(itm);
                    }
                    else if (o is QbKey[])
                    {
                        foreach (QbKey s in ((QbKey[])o))
                        {
                            itm = new GenericQbItem(a.DefaultDisplayName, s, a.EditType, a.ReadOnly, a.UseQbItemType, item.QbItemType, m.Name);
                            items.Add(itm);
                        }
                    }
                    else if (o is QbKey)
                    {
                        itm = new GenericQbItem(a.DefaultDisplayName, (QbKey)o, a.EditType, a.ReadOnly, a.UseQbItemType, item.QbItemType, m.Name);
                        items.Add(itm);
                    }
                    else
                        throw new ApplicationException(string.Format("Unknown generic data type item '{0}'", o.GetType().Name));
                }
            }
            return items;
        }
Exemplo n.º 5
0
        public static void SetGenericItems(QbItemBase item, List <GenericQbItem> gItems)
        {
            MemberInfo[] ms = item.GetType().FindMembers(MemberTypes.Property,
                                                         /*BindingFlags.DeclaredOnly |*/ BindingFlags.Instance | BindingFlags.Public,
                                                         Type.FilterName, "*");

            int                  i = 0;
            GenericQbItem        gi;
            List <GenericQbItem> list = null;

            if (gItems.Count == 0)
            {
                //test if this is an array item
                GenericQbItem gqi = QbFile.CreateGenericArrayItem(item);

                //null if not an array type
                if (gqi != null)
                {
                    //use this item to identify the array to set to 0 items
                    MemberInfo m = Array.Find(ms, delegate(MemberInfo mi)
                    {
                        return(mi.Name == gqi.SourceProperty);
                    });
                    if (m != null)
                    {
                        Type t = ((PropertyInfo)m).GetValue(item, null).GetType();
                        if (t == typeof(QbKey[]))
                        {
                            ((PropertyInfo)m).SetValue(item, new QbKey[0], null);
                        }
                        else if (t == typeof(float[]))
                        {
                            ((PropertyInfo)m).SetValue(item, new float[0], null);
                        }
                        else if (t == typeof(uint[]))
                        {
                            ((PropertyInfo)m).SetValue(item, new uint[0], null);
                        }
                        else if (t == typeof(int[]))
                        {
                            ((PropertyInfo)m).SetValue(item, new int[0], null);
                        }
                        else if (t == typeof(string[]))
                        {
                            ((PropertyInfo)m).SetValue(item, new string[0], null);
                        }
                    }
                }
            }


            while (i < gItems.Count)
            {
                gi = gItems[i++];

                if (gi.ReadOnly)
                {
                    continue;
                }

                //list = null;

                list = new List <GenericQbItem>();
                list.Add(gi);
                while (i < gItems.Count && gi.SourceProperty == gItems[i].SourceProperty)
                {
                    list.Add(gItems[i++]);
                }

                MemberInfo m = Array.Find(ms, delegate(MemberInfo mi)
                {
                    return(mi.Name == gi.SourceProperty);
                });

                if (m != null)
                {
                    Type t = ((PropertyInfo)m).GetValue(item, null).GetType();
                    if (t == typeof(QbKey[]))
                    {
                        QbKey[] qb = new QbKey[list.Count];
                        QbKey   q;
                        string  qS;

                        for (int c = 0; c < list.Count; c++)
                        {
                            q  = list[c].ToQbKey();
                            qS = item.Root.LookupDebugName(q.Crc);
                            if (qS.Length != 0)
                            {
                                q = QbKey.Create(q.Crc, qS);
                            }
                            qb[c] = q;
                        }
                        ((PropertyInfo)m).SetValue(item, qb, null);
                    }
                    else if (t == typeof(float[]))
                    {
                        float[] f = new float[list.Count];
                        for (int c = 0; c < list.Count; c++)
                        {
                            f[c] = list[c].ToSingle();
                        }
                        ((PropertyInfo)m).SetValue(item, f, null);
                    }
                    else if (t == typeof(uint[]))
                    {
                        uint[] ui = new uint[list.Count];
                        for (int c = 0; c < list.Count; c++)
                        {
                            ui[c] = list[c].ToUInt32();
                        }
                        ((PropertyInfo)m).SetValue(item, ui, null);
                    }
                    else if (t == typeof(int[]))
                    {
                        int[] si = new int[list.Count];
                        for (int c = 0; c < list.Count; c++)
                        {
                            si[c] = list[c].ToInt32();
                        }
                        ((PropertyInfo)m).SetValue(item, si, null);
                    }
                    else if (t == typeof(string[]))
                    {
                        string[] s = new string[list.Count];
                        for (int c = 0; c < list.Count; c++)
                        {
                            s[c] = list[c].ToString();
                        }
                        ((PropertyInfo)m).SetValue(item, s, null);
                    }
                    else if (t == typeof(QbKey))
                    {
                        QbKey  q  = gi.ToQbKey();
                        string qS = item.Root.LookupDebugName(q.Crc);
                        if (qS.Length != 0)
                        {
                            q = QbKey.Create(q.Crc, qS);
                        }
                        ((PropertyInfo)m).SetValue(item, q, null);
                    }
                    else if (t == typeof(float))
                    {
                        ((PropertyInfo)m).SetValue(item, gi.ToSingle(), null);
                    }
                    else if (t == typeof(uint))
                    {
                        ((PropertyInfo)m).SetValue(item, gi.ToUInt32(), null);
                    }
                    else if (t == typeof(int))
                    {
                        ((PropertyInfo)m).SetValue(item, gi.ToInt32(), null);
                    }
                    else if (t == typeof(string))
                    {
                        ((PropertyInfo)m).SetValue(item, gi.ToString(), null);
                    }
                    else if (t == typeof(byte[]))
                    {
                        ((PropertyInfo)m).SetValue(item, gi.ToByteArray(), null);
                    }
                    else
                    {
                        throw new ApplicationException(string.Format("DataType {0} not supported.", t.Name));
                    }
                }
            }
        }