示例#1
0
        /// <summary>
        /// Builds the right-hand side of the GUI based on the argument.
        /// </summary>
        /// <param name="mpe">The <see cref="MetaPropEntity"/>.</param>
        private void BuildGui(MetaPropEntity mpe)
        {
            UIPanel.Children.Clear();

            if (mpe.Value.GetType() == typeof(string))
            {
                UIPanel.Children.Add(AddText(mpe.Title, (string)mpe.Value, mpe.IsReadOnly));
            }
            else if (mpe.Value.GetType() == typeof(Guid))
            {
                UIPanel.Children.Add(AddText(mpe.Title, ((Guid)mpe.Value).ToString("N"), mpe.IsReadOnly));
            }
            else if (mpe.Value.GetType() == typeof(Int32))
            {
                UIPanel.Children.Add(AddText(mpe.Title, ((Int32)mpe.Value).ToString(), mpe.IsReadOnly));
            }
            else if (mpe.Value.GetType() == typeof(UInt32))
            {
                UIPanel.Children.Add(AddText(mpe.Title, ((UInt32)mpe.Value).ToString(), mpe.IsReadOnly));
            }
            else if (mpe.Value.GetType() == typeof(Int64))
            {
                UIPanel.Children.Add(AddText(mpe.Title, ((Int64)mpe.Value).ToString(), mpe.IsReadOnly));
            }
            else if (mpe.Value.GetType() == typeof(UInt64))
            {
                UIPanel.Children.Add(AddText(mpe.Title, ((UInt64)mpe.Value).ToString(), mpe.IsReadOnly));
            }
            else if (mpe.Value.GetType() == typeof(DateTime))
            {
                UIPanel.Children.Add(AddDateTime(mpe.Title, (DateTime)mpe.Value, mpe.IsReadOnly));
            }
            else if (mpe.Value.GetType() == typeof(bool))
            {
                UIPanel.Children.Add(AddCheckBox(mpe.Title, (bool)mpe.Value, mpe.IsReadOnly));
            }
            else if (mpe.Value.GetType() == typeof(List <string>))
            {
                UIPanel.Children.Add(AddMultilineText(mpe.Title, string.Join("\r\n", ((List <string>)mpe.Value).ToArray()), mpe.IsReadOnly));
            }
            else if (mpe.Value.GetType() == typeof(string[]))
            {
                UIPanel.Children.Add(AddMultilineText(mpe.Title, string.Join("\r\n", ((string[])mpe.Value)), mpe.IsReadOnly));
            }
            else
            {
                Type type = mpe.Value.GetType();
                throw new Exception("Unknown type '" + type.FullName + "' encountered.");
            }
        }
示例#2
0
        /// <summary>
        /// Creates a <see cref="MetaPropEntity"/> and adds it to the UI tree.
        /// </summary>
        /// <param name="key">The key.</param>
        /// <param name="title">The title.</param>
        /// <param name="obj">The obj.</param>
        /// <param name="isReadOnly">If set to <c>true</c> the property is read-only and the user cannot change it;
        /// otherwise, <c>false</c> allows user modification.</param>
        private void AddTreeViewItem(string key, string title, object obj, bool isReadOnly)
        {
            TreeViewItem   tvi = new TreeViewItem();
            MetaPropEntity mpe;

            mpe = new MetaPropEntity(key, title, obj, isReadOnly);

            tvi.Header    = title;
            tvi.Tag       = mpe;
            tvi.Selected += new RoutedEventHandler(TreeViewItem_Selected);

            if (isReadOnly)
            {
                tvi.Background = new SolidColorBrush(Color.FromArgb(75, 255, 0, 0)); // Red
            }
            treeView1.Items.Add(tvi);
        }
示例#3
0
        /// <summary>
        /// Saves any change to the Tag property of the destinationTvi.
        /// </summary>
        /// <param name="destinationTvi">The destination tvi.</param>
        /// <returns><c>True</c> if successful; otherwise, <c>false</c>.  In the event of a false return
        /// the changes have not been saved and the user will be notified.</returns>
        private bool SaveChangeBackToTvi(TreeViewItem destinationTvi)
        {
            MetaPropEntity mpe = (MetaPropEntity)destinationTvi.Tag;

            if (mpe.Value.GetType() == typeof(string))
            {
                mpe.Value     = GetTextBoxValue();
                mpe.IsUpdated = true;
            }
            else if (mpe.Value.GetType() == typeof(Guid))
            {
                Guid var_guid;

                if (Guid.TryParse(GetTextBoxValue(), out var_guid))
                {
                    mpe.Value     = var_guid;
                    mpe.IsUpdated = true;
                }
                else
                {
                    MessageBox.Show("The system cannot save the Guid as it appears to be invalid.", "Invalid Guid");
                    return(false);
                }
            }
            else if (mpe.Value.GetType() == typeof(Int32))
            {
                Int32 var_int32;

                if (Int32.TryParse(GetTextBoxValue(), out var_int32))
                {
                    mpe.Value     = var_int32;
                    mpe.IsUpdated = true;
                }
                else
                {
                    MessageBox.Show("The system cannot save the value as it appears to be invalid.  The value must be numeric between " + Int32.MinValue.ToString() + " and " + Int32.MaxValue.ToString() + ".", "Invalid Value");
                    return(false);
                }
            }
            else if (mpe.Value.GetType() == typeof(UInt32))
            {
                UInt32 var_uint32;

                if (UInt32.TryParse(GetTextBoxValue(), out var_uint32))
                {
                    mpe.Value     = var_uint32;
                    mpe.IsUpdated = true;
                }
                else
                {
                    MessageBox.Show("The system cannot save the value as it appears to be invalid.  The value must be numeric between " + UInt32.MinValue.ToString() + " and " + UInt32.MaxValue.ToString() + ".", "Invalid Value");
                    return(false);
                }
            }
            else if (mpe.Value.GetType() == typeof(Int64))
            {
                Int64 var_int64;

                if (Int64.TryParse(GetTextBoxValue(), out var_int64))
                {
                    mpe.Value     = var_int64;
                    mpe.IsUpdated = true;
                }
                else
                {
                    MessageBox.Show("The system cannot save the value as it appears to be invalid.  The value must be numeric between " + Int64.MinValue.ToString() + " and " + Int64.MaxValue.ToString() + ".", "Invalid Value");
                    return(false);
                }
            }
            else if (mpe.Value.GetType() == typeof(UInt64))
            {
                UInt64 var_uint64;

                if (UInt64.TryParse(GetTextBoxValue(), out var_uint64))
                {
                    mpe.Value     = var_uint64;
                    mpe.IsUpdated = true;
                }
                else
                {
                    MessageBox.Show("The system cannot save the value as it appears to be invalid.  The value must be numeric between " + UInt64.MinValue.ToString() + " and " + UInt64.MaxValue.ToString() + ".", "Invalid Value");
                    return(false);
                }
            }
            else if (mpe.Value.GetType() == typeof(DateTime))
            {
                DateTime?var_dt = GetDateTimeValue();

                if (!var_dt.HasValue)
                {
                    MessageBox.Show("You must select a date.", "Invalid Date");
                    return(false);
                }

                mpe.Value     = var_dt;
                mpe.IsUpdated = true;
            }
            else if (mpe.Value.GetType() == typeof(bool))
            {
                bool?var_bool = GetCheckBoxValue();

                if (!var_bool.HasValue)
                {
                    MessageBox.Show("A checkbox was expected but could not be located", "Invalid CheckBox");
                    return(false);
                }

                mpe.Value     = var_bool;
                mpe.IsUpdated = true;
            }
            else if (mpe.Value.GetType() == typeof(System.Collections.Generic.List <string>))
            {
                System.Collections.Generic.List <string> var_list = ParseListFromString(GetTextBoxValue());

                if (var_list.Count <= 0)
                {
                    if (MessageBox.Show("No tags were entered, it is going to be really hard to locate this resource if you do not specify some tags.\r\nWould you like to add tags?", "Tags Desired?",
                                        MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.Yes) == MessageBoxResult.Yes)
                    {
                        return(false); // this prevents the UI from changing
                    }
                }

                mpe.Value     = var_list;
                mpe.IsUpdated = true;
            }

            return(true);
        }
        /// <summary>
        /// Builds the right-hand side of the GUI based on the argument.
        /// </summary>
        /// <param name="mpe">The <see cref="MetaPropEntity"/>.</param>
        private void BuildGui(MetaPropEntity mpe)
        {
            UIPanel.Children.Clear();

            if (mpe.Value.GetType() == typeof(string))
            {
                UIPanel.Children.Add(AddText(mpe.Title, (string)mpe.Value, mpe.IsReadOnly));
            }
            else if (mpe.Value.GetType() == typeof(Guid))
            {
                UIPanel.Children.Add(AddText(mpe.Title, ((Guid)mpe.Value).ToString("N"), mpe.IsReadOnly));
            }
            else if (mpe.Value.GetType() == typeof(Int32))
            {
                UIPanel.Children.Add(AddText(mpe.Title, ((Int32)mpe.Value).ToString(), mpe.IsReadOnly));
            }
            else if (mpe.Value.GetType() == typeof(UInt32))
            {
                UIPanel.Children.Add(AddText(mpe.Title, ((UInt32)mpe.Value).ToString(), mpe.IsReadOnly));
            }
            else if (mpe.Value.GetType() == typeof(Int64))
            {
                UIPanel.Children.Add(AddText(mpe.Title, ((Int64)mpe.Value).ToString(), mpe.IsReadOnly));
            }
            else if (mpe.Value.GetType() == typeof(UInt64))
            {
                UIPanel.Children.Add(AddText(mpe.Title, ((UInt64)mpe.Value).ToString(), mpe.IsReadOnly));
            }
            else if (mpe.Value.GetType() == typeof(DateTime))
            {
                UIPanel.Children.Add(AddDateTime(mpe.Title, (DateTime)mpe.Value, mpe.IsReadOnly));
            }
            else if (mpe.Value.GetType() == typeof(bool))
            {
                UIPanel.Children.Add(AddCheckBox(mpe.Title, (bool)mpe.Value, mpe.IsReadOnly));
            }
            else if (mpe.Value.GetType() == typeof(List<string>))
            {
                UIPanel.Children.Add(AddMultilineText(mpe.Title, string.Join("\r\n", ((List<string>)mpe.Value).ToArray()), mpe.IsReadOnly));
            }
            else if (mpe.Value.GetType() == typeof(string[]))
            {
                UIPanel.Children.Add(AddMultilineText(mpe.Title, string.Join("\r\n", ((string[])mpe.Value)), mpe.IsReadOnly));
            }
            else
            {
                Type type = mpe.Value.GetType();
                throw new Exception("Unknown type '" + type.FullName + "' encountered.");
            }
        }
        /// <summary>
        /// Creates a <see cref="MetaPropEntity"/> and adds it to the UI tree.
        /// </summary>
        /// <param name="key">The key.</param>
        /// <param name="title">The title.</param>
        /// <param name="obj">The obj.</param>
        /// <param name="isReadOnly">If set to <c>true</c> the property is read-only and the user cannot change it; 
        /// otherwise, <c>false</c> allows user modification.</param>
        private void AddTreeViewItem(string key, string title, object obj, bool isReadOnly)
        {
            TreeViewItem tvi = new TreeViewItem();
            MetaPropEntity mpe;

            mpe = new MetaPropEntity(key, title, obj, isReadOnly);

            tvi.Header = title;
            tvi.Tag = mpe;
            tvi.Selected += new RoutedEventHandler(TreeViewItem_Selected);

            if (isReadOnly)
                tvi.Background = new SolidColorBrush(Color.FromArgb(75, 255, 0, 0)); // Red

            treeView1.Items.Add(tvi);
        }