private void BuildHorizontalUI()
        {
            try
            {
                //Clear Old Controls
                foreach (Control c in MainWrapPanel.Children)
                {
                    MainWrapPanel.Children.Remove(c);
                }

                //TODO:  Need to sort the mTableSchema table

                //Clear new Controls
                foreach (DataRow dr in mTableSchema.Rows)
                {

                    if (dr["Enabled"].ToString() != "0")
                    {
                        string ColumnName = dr["ColumnName"].ToString();
                        string LabelText = dr["LabelText"].ToString();
                        Label l = new Label()
                        {
                            Height = 28,
                            Name = ColumnName + "Label",
                            HorizontalContentAlignment = System.Windows.HorizontalAlignment.Left,
                            Content = LabelText
                        };

                        
                        //tb.TextChanged += new TextChangedEventHandler(TextBox_TextChanged);
                        //tb.LostFocus += new RoutedEventHandler(TextBox_LostFocus);
                        //AddRules(tb);

                        RulesValidation myRulesValidation = new RulesValidation();
                        myRulesValidation.module = this.mModuleSection;
                        myRulesValidation.table = this.mTableName;
                        myRulesValidation.column = ColumnName;
                        myRulesValidation.data = mCollectionView;

                        Binding bindMyColumn = new Binding();
                        bindMyColumn.Path = new PropertyPath(ColumnName);
                        bindMyColumn.ValidationRules.Clear();
                        bindMyColumn.ValidationRules.Add(myRulesValidation);
                        bindMyColumn.ValidatesOnDataErrors = true;

                        StackPanel sp = new StackPanel();
                        sp.Children.Add(l);

                        //UIElement InputObject;
                        switch (dr["CtrlTypeName"].ToString())
                        {
                            case "i9TextBox":
                                i9TextBox i9tb = new i9TextBox()
                                {
                                    Height = 28,
                                    Name = ColumnName + "TextBox",
                                    TextAlignment = System.Windows.TextAlignment.Left,
                                    HorizontalContentAlignment = System.Windows.HorizontalAlignment.Right,
                                };

                                i9tb.IsReadOnly = false;
                                if (dr["IsReadOnly"].ToString() != "0")
                                {
                                    i9tb.IsReadOnly = true;
                                }

                                if (dr["MaxLength"] is DBNull)
                                {
                                    //Do Nothing
                                    Console.WriteLine("MaxLength is db null");
                                }
                                else
                                {
                                    i9tb.MaxLength = System.Convert.ToInt32(dr["MaxLength"].ToString());
                                }

                                i9tb.SetBinding(TextBox.TextProperty, bindMyColumn);
                                sp.Children.Add(i9tb);
                                break;


                            case "i9ComboBox":
                                i9ComboBox i9cb = new i9ComboBox()
                                {
                                    Height = 28,
                                    Name = ColumnName + "ComboBox",
                                    //TextAlignment = System.Windows.TextAlignment.Left,
                                    //HorizontalContentAlignment = System.Windows.HorizontalAlignment.Right,
                                };



                                i9cb.IsReadOnly = false;
                                if (dr["IsReadOnly"].ToString() != "0")
                                {
                                    i9cb.IsReadOnly = true;
                                }

                                if (dr["MaxLength"] is DBNull)
                                {
                                    //Do Nothing
                                    Console.WriteLine("MaxLength is db null");
                                }
                                else
                                {
                                    i9cb.MaxLength = System.Convert.ToInt32(dr["MaxLength"].ToString());
                                }

                                if (dr["CodeSetName"] != DBNull.Value)
                                    i9cb.i9BindCodeSetName = dr["CodeSetName"].ToString();


                                i9cb.DisplayMemberPath = "Code"; 
                                i9cb.SelectedValuePath="Code";
                                i9cb.SelectedValue = ColumnName;

                                i9cb.SetComboBoxEvents();

                                i9cb.SetBinding(ComboBox.TextProperty, bindMyColumn);
                                //i9cb.SetBinding(ComboBox.SelectedItemProperty, bindMyColumn);
                                
                                sp.Children.Add(i9cb);
                                break;

                            default:
                                TextBox tb = new TextBox()
                                {
                                    Height = 28,
                                    Name = ColumnName + "TextBox",
                                    TextAlignment = System.Windows.TextAlignment.Left,
                                    HorizontalContentAlignment = System.Windows.HorizontalAlignment.Right,
                                };
                                tb.SetBinding(TextBox.TextProperty, bindMyColumn);
                                sp.Children.Add(tb);
                                break;
                        }
                        
                        //bindMyColumn.Source = mDataView;
                        sp.Margin = new Thickness(0, 5, 5, 0);
                        MainWrapPanel.Children.Add(sp);
                    }
                    else
                    {
                        LogManager.Instance.LogMessage("Disabled ColumnName " + dr["ColumnName"].ToString());
                    }
                }
            }
            catch (FileNotFoundException ex)
            {
                LogManager.Instance.LogMessage("DynamicEntryControl", "BuildHorizontalUI", "Error FileNotFoundException", ex);
            }
        }
Exemplo n.º 2
0
        private void BuildHorizontalUI()
        {
            try
            {
                //Clear Old Controls
                foreach (Control c in MainWrapPanel.Children)
                {
                    MainWrapPanel.Children.Remove(c);
                }

                //TODO:  Need to sort the mTableSchema table

                //Clear new Controls
                foreach (DataRow dr in mTableSchema.Rows)
                {
                    if (dr["Enabled"].ToString() != "0")
                    {
                        string ColumnName = dr["ColumnName"].ToString();
                        string LabelText  = dr["LabelText"].ToString();
                        Label  l          = new Label()
                        {
                            Height = 28,
                            Name   = ColumnName + "Label",
                            HorizontalContentAlignment = System.Windows.HorizontalAlignment.Left,
                            Content = LabelText
                        };


                        //tb.TextChanged += new TextChangedEventHandler(TextBox_TextChanged);
                        //tb.LostFocus += new RoutedEventHandler(TextBox_LostFocus);
                        //AddRules(tb);

                        RulesValidation myRulesValidation = new RulesValidation();
                        myRulesValidation.module = this.mModuleSection;
                        myRulesValidation.table  = this.mTableName;
                        myRulesValidation.column = ColumnName;
                        myRulesValidation.data   = mCollectionView;

                        Binding bindMyColumn = new Binding();
                        bindMyColumn.Path = new PropertyPath(ColumnName);
                        bindMyColumn.ValidationRules.Clear();
                        bindMyColumn.ValidationRules.Add(myRulesValidation);
                        bindMyColumn.ValidatesOnDataErrors = true;

                        StackPanel sp = new StackPanel();
                        sp.Children.Add(l);

                        //UIElement InputObject;
                        switch (dr["CtrlTypeName"].ToString())
                        {
                        case "i9TextBox":
                            i9TextBox i9tb = new i9TextBox()
                            {
                                Height        = 28,
                                Name          = ColumnName + "TextBox",
                                TextAlignment = System.Windows.TextAlignment.Left,
                                HorizontalContentAlignment = System.Windows.HorizontalAlignment.Right,
                            };

                            i9tb.IsReadOnly = false;
                            if (dr["IsReadOnly"].ToString() != "0")
                            {
                                i9tb.IsReadOnly = true;
                            }

                            if (dr["MaxLength"] is DBNull)
                            {
                                //Do Nothing
                                Console.WriteLine("MaxLength is db null");
                            }
                            else
                            {
                                i9tb.MaxLength = System.Convert.ToInt32(dr["MaxLength"].ToString());
                            }

                            i9tb.SetBinding(TextBox.TextProperty, bindMyColumn);
                            sp.Children.Add(i9tb);
                            break;


                        case "i9ComboBox":
                            i9ComboBox i9cb = new i9ComboBox()
                            {
                                Height = 28,
                                Name   = ColumnName + "ComboBox",
                                //TextAlignment = System.Windows.TextAlignment.Left,
                                //HorizontalContentAlignment = System.Windows.HorizontalAlignment.Right,
                            };



                            i9cb.IsReadOnly = false;
                            if (dr["IsReadOnly"].ToString() != "0")
                            {
                                i9cb.IsReadOnly = true;
                            }

                            if (dr["MaxLength"] is DBNull)
                            {
                                //Do Nothing
                                Console.WriteLine("MaxLength is db null");
                            }
                            else
                            {
                                i9cb.MaxLength = System.Convert.ToInt32(dr["MaxLength"].ToString());
                            }

                            if (dr["CodeSetName"] != DBNull.Value)
                            {
                                i9cb.i9BindCodeSetName = dr["CodeSetName"].ToString();
                            }


                            i9cb.DisplayMemberPath = "Code";
                            i9cb.SelectedValuePath = "Code";
                            i9cb.SelectedValue     = ColumnName;

                            i9cb.SetComboBoxEvents();

                            i9cb.SetBinding(ComboBox.TextProperty, bindMyColumn);
                            //i9cb.SetBinding(ComboBox.SelectedItemProperty, bindMyColumn);

                            sp.Children.Add(i9cb);
                            break;

                        default:
                            TextBox tb = new TextBox()
                            {
                                Height        = 28,
                                Name          = ColumnName + "TextBox",
                                TextAlignment = System.Windows.TextAlignment.Left,
                                HorizontalContentAlignment = System.Windows.HorizontalAlignment.Right,
                            };
                            tb.SetBinding(TextBox.TextProperty, bindMyColumn);
                            sp.Children.Add(tb);
                            break;
                        }

                        //bindMyColumn.Source = mDataView;
                        sp.Margin = new Thickness(0, 5, 5, 0);
                        MainWrapPanel.Children.Add(sp);
                    }
                    else
                    {
                        LogManager.Instance.LogMessage("Disabled ColumnName " + dr["ColumnName"].ToString());
                    }
                }
            }
            catch (FileNotFoundException ex)
            {
                LogManager.Instance.LogMessage("DynamicEntryControl", "BuildHorizontalUI", "Error FileNotFoundException", ex);
            }
        }