Пример #1
0
        /// <summary>
        /// Occurs when the command associated with this CommandBinding executes.
        /// </summary>
        private static void OnExecuteRemoveColumn(object sender, ExecutedRoutedEventArgs e)
        {
            SerializationDemo mainwnd        = (SerializationDemo)Activator.CreateInstance(typeof(SerializationDemo));
            ManipulatorView   manipulatorwnd = sender as ManipulatorView;

            if (manipulatorwnd.mappingname_cmbbox.SelectedItem == null)
            {
                manipulatorwnd.err_textblock.Text       = "MappingName is mandatory";
                manipulatorwnd.err_textblock.Visibility = Visibility.Visible;
                return;
            }
            var mappingName = manipulatorwnd.mappingname_cmbbox.SelectedItem.ToString();

            if (mappingName.Contains(" (TemplateColumn)") || mappingName.Contains(" (UnBoundColumn)"))
            {
                mappingName = mappingName.Substring(0, mappingName.IndexOf('(') - 1);
            }
            foreach (var col in mainwnd.dataGrid.Columns)
            {
                if (mappingName == col.HeaderText)
                {
                    mainwnd.dataGrid.Columns.Remove(col);
                    manipulatorwnd.Close();
                    return;
                }
            }
            manipulatorwnd.mappingname_cmbbox.SelectedItem = null;
        }
        protected override void Invoke(object parameter)
        {
            List <String>     mappingNameCol = new List <string>();
            SerializationDemo mainwnd        = SerializationDemo.demoControl;
            ManipulatorView   manipulatorwnd = ManipulatorView.manipulatorView;

            if (manipulatorwnd.addcolarea.Visibility == Visibility.Collapsed)
            {
                foreach (var col in mainwnd.dataGrid.Columns)
                {
                    if (!(col is GridUnBoundColumn) && col is GridTemplateColumn)
                    {
                        mappingNameCol.Add(col.HeaderText + " (TemplateColumn)");
                    }
                    else if (col is GridUnBoundColumn)
                    {
                        mappingNameCol.Add(col.HeaderText + " (UnBoundColumn)");
                    }
                    else
                    {
                        mappingNameCol.Add(col.HeaderText);
                    }
                }
            }
            else
            {
                PropertyInfo[]        properties;
                OrderInfo             product = new OrderInfo();
                MappingNameDictionary dic     = new MappingNameDictionary();
                properties = product.GetType().GetProperties();
                foreach (var property in properties)
                {
                    string headerText;
                    dic.TryGetValue(property.Name, out headerText);
                    if (!string.IsNullOrEmpty(headerText))
                    {
                        mappingNameCol.Add(headerText);
                    }
                }
                foreach (var col in mainwnd.dataGrid.Columns)
                {
                    if (mappingNameCol.Contains(col.HeaderText))
                    {
                        mappingNameCol.Remove(col.HeaderText);
                    }
                }
            }
            this.Target.ItemsSource = mappingNameCol;
        }
Пример #3
0
        /// <summary>
        /// Event handler when the DropDown is opened in ComboBox.
        /// </summary>
        void OnComboBoxDropDownOpened(object sender, EventArgs e)
        {
            List <String>     mappingNameCol = new List <string>();
            SerializationDemo mainwnd        = (SerializationDemo)Activator.CreateInstance(typeof(SerializationDemo));
            ManipulatorView   manipulatorwnd = (ManipulatorView)Activator.CreateInstance(typeof(ManipulatorView));

            if (manipulatorwnd.addcolarea.Visibility == Visibility.Collapsed)
            {
                foreach (var col in mainwnd.dataGrid.Columns)
                {
                    if (!(col is GridUnBoundColumn) && col is GridTemplateColumn)
                    {
                        mappingNameCol.Add(col.HeaderText + " (TemplateColumn)");
                    }
                    else if (col is GridUnBoundColumn)
                    {
                        mappingNameCol.Add(col.HeaderText + " (UnBoundColumn)");
                    }
                    else
                    {
                        mappingNameCol.Add(col.HeaderText);
                    }
                }
            }
            else
            {
                PropertyInfo[]        properties;
                ProductDetails        product = new ProductDetails();
                MappingNameDictionary dic     = new MappingNameDictionary();
                properties = product.GetType().GetProperties();
                foreach (var property in properties)
                {
                    string headerText;
                    dic.TryGetValue(property.Name, out headerText);
                    mappingNameCol.Add(headerText);
                }
                foreach (var col in mainwnd.dataGrid.Columns)
                {
                    if (mappingNameCol.Contains(col.HeaderText))
                    {
                        mappingNameCol.Remove(col.HeaderText);
                    }
                }
            }
            this.AssociatedObject.ItemsSource = mappingNameCol;
        }
Пример #4
0
        /// <summary>
        ///Occurs when the command associated with this CommandBinding executes.
        /// </summary>
        private static void OnExecuteReset(object sender, ExecutedRoutedEventArgs e)
        {
            var dataGrid = e.Source as SfDataGrid;
            SerializationDemo mainwnd = (SerializationDemo)Activator.CreateInstance(typeof(SerializationDemo));

            List <String> selectedItemsCol = new List <string>();

            if (dataGrid == null)
            {
                return;
            }
            try
            {
                using (var file = File.Open("Reset.xml", FileMode.Open))
                {
                    dataGrid.Deserialize(file);
                }
            }
            catch (Exception)
            {
            }
        }
Пример #5
0
        /// <summary>
        /// Occurs when the command associated with this CommandBinding executes.
        /// </summary>
        private static void OnExecuteAddColumn(object sender, ExecutedRoutedEventArgs e)
        {
            SerializationDemo mainwnd        = (SerializationDemo)Activator.CreateInstance(typeof(SerializationDemo));
            ManipulatorView   manipulatorwnd = sender as ManipulatorView;
            int index = manipulatorwnd.colType_combobox.SelectedIndex;

            if (manipulatorwnd.mappingname_cmbbox.SelectedItem == null && index == 1)
            {
                if (!String.IsNullOrEmpty(manipulatorwnd.unboundcol_mappingname_txtbox.Text) && manipulatorwnd.exprsn_combobox.SelectedItem != null)
                {
                    foreach (var col in mainwnd.dataGrid.Columns)
                    {
                        if (col.MappingName == manipulatorwnd.unboundcol_mappingname_txtbox.Text)
                        {
                            manipulatorwnd.err_textblock.Text       = "The given MappingName already exists";
                            manipulatorwnd.err_textblock.Visibility = Visibility.Visible;
                            return;
                        }
                    }
                    mainwnd.dataGrid.Columns.Add(new GridUnBoundColumn()
                    {
                        MappingName = manipulatorwnd.unboundcol_mappingname_txtbox.Text, Expression = manipulatorwnd.exprsn_combobox.Text
                    });
                    manipulatorwnd.exprsn_combobox.SelectedItem = null;
                    manipulatorwnd.unboundcol_mappingname_txtbox.Clear();
                    manipulatorwnd.Close();
                }
                else
                {
                    manipulatorwnd.err_textblock.Text       = "Experssion/MappingName is mandatory";
                    manipulatorwnd.err_textblock.Visibility = Visibility.Visible;
                    return;
                }
                return;
            }

            if (index == -1 || manipulatorwnd.mappingname_cmbbox.SelectedItem == null)
            {
                manipulatorwnd.err_textblock.Text       = "ColumnType/MappingName is mandatory";
                manipulatorwnd.err_textblock.Visibility = Visibility.Visible;
                return;
            }
            if (index != -1)
            {
                MappingNameDictionary dic = new MappingNameDictionary();
                var headerText            = manipulatorwnd.mappingname_cmbbox.SelectedItem.ToString();
                var mappingName           = dic.FirstOrDefault(x => x.Value == headerText).Key;

                switch (index)
                {
                case 0:
                    mainwnd.dataGrid.Columns.Add(new GridTextColumn()
                    {
                        MappingName = mappingName, HeaderText = headerText
                    });
                    break;

                case 2:
                    mainwnd.dataGrid.Columns.Add(new GridPercentColumn()
                    {
                        MappingName = mappingName, HeaderText = headerText
                    });
                    break;

                case 3:
                    mainwnd.dataGrid.Columns.Add(new GridNumericColumn()
                    {
                        MappingName = mappingName, HeaderText = headerText
                    });
                    break;

                case 4:
                    mainwnd.dataGrid.Columns.Add(new GridDateTimeColumn()
                    {
                        MappingName = mappingName, HeaderText = headerText
                    });
                    break;

                case 5:
                    mainwnd.dataGrid.Columns.Add(new GridCurrencyColumn()
                    {
                        MappingName = mappingName, HeaderText = headerText
                    });
                    break;

                case 6:
                    mainwnd.dataGrid.Columns.Add(new GridCheckBoxColumn()
                    {
                        MappingName = mappingName, HeaderText = headerText
                    });
                    break;

                case 7:
                    GridTemplateColumn tempCol = new GridTemplateColumn();
                    tempCol.MappingName  = mappingName.ToString();
                    tempCol.HeaderText   = headerText;
                    tempCol.CellTemplate = GetDataTemplate(tempCol);
                    mainwnd.dataGrid.Columns.Add(tempCol);
                    break;
                }
                manipulatorwnd.mappingname_cmbbox.SelectedItem = null;
                manipulatorwnd.Close();
            }
        }
Пример #6
0
 public SerializationDemo()
 {
     InitializeComponent();
     demoControl = this;
 }