Exemple #1
0
        protected override void WriteControlInitialization(bool addBindings)
        {
            Label l                  = new Label();
            Size  szText             = TextRenderer.MeasureText(GetMaxWidthString(Columns), l.Font);
            Point initLoc            = new Point(szText.Width + 10 + 50, 50);
            Point xy                 = new Point(initLoc.X, initLoc.Y);
            bool  passedHalve        = false;
            int   tabIdx             = 1;
            bool  validationsEnabled = ValidationsEnabled;
            int   i                  = 0;

            Writer.PushIdentationLevel();
            Writer.IncreaseIdentation();
            Writer.IncreaseIdentation();
            Writer.IncreaseIdentation();

            for (int j = 0; j < ValidationColumns.Count; j++)
            {
                ColumnValidation cv                = ValidationColumns[j];
                string           colName           = cv.Name;
                string           idColumnCanonical = GetCanonicalIdentifier(colName);

                // Place half the column input in one column and the other in the second column.
                if (!passedHalve && ++i > (Columns.Count / 2))
                {
                    passedHalve = true;
                    xy.X       += 200 + 20 + szText.Width;
                    xy.Y        = initLoc.Y;
                }

                Writer.WriteLine("//");
                Writer.WriteLine("// {0}Label", idColumnCanonical);
                Writer.WriteLine("//");
                Writer.WriteLine("this.{0}Label = new System.Windows.Forms.Label();", idColumnCanonical);

                Writer.WriteLine("this.{0}Label.AutoSize = true;", idColumnCanonical);
                Size szLabel = TextRenderer.MeasureText(colName, l.Font);
                Writer.WriteLine("this.{0}Label.Location = new System.Drawing.Point( {1}, {2} );", idColumnCanonical,
                                 xy.X - 10 - szLabel.Width, xy.Y);
                Writer.WriteLine("this.{0}Label.Name = \"{0}Label\";", idColumnCanonical);
                Writer.WriteLine("this.{0}Label.Size = new System.Drawing.Size( {1}, {2} );", idColumnCanonical,
                                 szLabel.Width, szLabel.Height);
                Writer.WriteLine("this.{0}Label.TabIndex = {1};", idColumnCanonical, tabIdx++);
                Writer.WriteLine("this.{0}Label.Text = \"{1}\";", idColumnCanonical, colName);
                Writer.WriteLine("this.Panel1.Controls.Add( this.{0}Label );", idColumnCanonical);

                if (cv.HasLookup)
                {
                    Writer.WriteLine("this.{0}_comboBox = new System.Windows.Forms.ComboBox();", idColumnCanonical);
                    Writer.WriteLine("this.{0}_comboBox.Location = new System.Drawing.Point( {1}, {2} );", idColumnCanonical, xy.X, xy.Y);
                    //Writer.WriteLine("this.{0}_comboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;", idColumnCanonical);
                    Writer.WriteLine("this.{0}_comboBox.AutoCompleteMode = System.Windows.Forms.AutoCompleteMode.Append;", idColumnCanonical);
                    Writer.WriteLine("this.{0}_comboBox.AutoCompleteSource = System.Windows.Forms.AutoCompleteSource.ListItems;", idColumnCanonical);
                    Writer.WriteLine("this.{0}_comboBox.FormattingEnabled = true;", idColumnCanonical);
                    Writer.WriteLine("this.{0}_comboBox.Name = \"{0}_comboBox\";", idColumnCanonical);
                    Writer.WriteLine("this.{0}_comboBox.Size = new System.Drawing.Size(206, 21);", idColumnCanonical);
                    Writer.WriteLine("this.{0}_comboBox.TabIndex = {1};", idColumnCanonical, tabIdx++);
                    if (validationsEnabled)
                    {
                        Writer.WriteLine("this.{0}_comboBox.Validating += new System.ComponentModel.CancelEventHandler( this.{0}_comboBox_Validating );",
                                         idColumnCanonical);
                    }
                    if (addBindings)
                    {
                        // nothing
                    }
                    Writer.WriteLine("this.Panel1.Controls.Add( this.{0}_comboBox );", idColumnCanonical);
                }
                else if (cv.IsDateType())
                {
                    Writer.WriteLine("//");
                    Writer.WriteLine("// {0}_dateTimePicker", idColumnCanonical);
                    Writer.WriteLine("//");
                    Writer.WriteLine("this.{0}_dateTimePicker = new System.Windows.Forms.DateTimePicker();", idColumnCanonical);
                    if (cv.IsDateTimeType())
                    {
                        Writer.WriteLine("this.{0}_dateTimePicker.CustomFormat = \"dd/MM/yyyy, hh:mm\"; ", idColumnCanonical);
                    }
                    else
                    {
                        Writer.WriteLine("this.{0}_dateTimePicker.CustomFormat = \"dd/MM/yyyy\"; ", idColumnCanonical);
                    }
                    Writer.WriteLine("this.{0}_dateTimePicker.Format = System.Windows.Forms.DateTimePickerFormat.Custom;", idColumnCanonical);
                    Writer.WriteLine("this.{0}_dateTimePicker.Location = new System.Drawing.Point({1}, {2});", idColumnCanonical, xy.X, xy.Y);
                    Writer.WriteLine("this.{0}_dateTimePicker.Name = \"{0}_dateTimePicker\";", idColumnCanonical);
                    Writer.WriteLine("this.{0}_dateTimePicker.Size = new System.Drawing.Size(200, 20);", idColumnCanonical);
                    Writer.WriteLine("this.{0}_dateTimePicker.TabIndex = {1};", idColumnCanonical, tabIdx++);
                    Writer.WriteLine("this.{0}_dateTimePicker.Value = new System.DateTime(2014, 5, 26, 17, 35, 11, 0);", idColumnCanonical);

                    if (addBindings)
                    {
                        Writer.WriteLine("this.{0}_dateTimePicker.DataBindings.Add(new System.Windows.Forms.Binding(\"Text\", this.{2}BindingSource, \"{1}\", true ));",
                                         idColumnCanonical, cv.EfColumnMapping, CanonicalTableName);
                    }
                    Writer.WriteLine("this.Panel1.Controls.Add( this.{0}_dateTimePicker );", idColumnCanonical);
                }
                else if (cv.IsBooleanType())
                {
                    Writer.WriteLine("//");
                    Writer.WriteLine("//{0}CheckBox", idColumnCanonical);
                    Writer.WriteLine("//");
                    Writer.WriteLine("this.{0}CheckBox = new System.Windows.Forms.CheckBox();", idColumnCanonical);
                    Writer.WriteLine("this.{0}CheckBox.AutoSize = true;", idColumnCanonical);
                    Writer.WriteLine("this.{0}CheckBox.Location = new System.Drawing.Point({1}, {2});", idColumnCanonical, xy.X, xy.Y + 3);
                    Writer.WriteLine("this.{0}CheckBox.Name = \"{0}CheckBox\";", idColumnCanonical);
                    Writer.WriteLine("this.{0}CheckBox.Size = new System.Drawing.Size(15, 14);", idColumnCanonical);
                    Writer.WriteLine("this.{0}CheckBox.TabIndex = {1};", idColumnCanonical, tabIdx++);
                    Writer.WriteLine("this.{0}CheckBox.UseVisualStyleBackColor = true;", idColumnCanonical);
                    Writer.WriteLine("this.Panel1.Controls.Add( this.{0}CheckBox );", idColumnCanonical);
                    if (addBindings)
                    {
                        Writer.WriteLine("this.{0}CheckBox.DataBindings.Add(new System.Windows.Forms.Binding(\"Checked\", this.{2}BindingSource, \"{1}\", true));",
                                         idColumnCanonical, cv.EfColumnMapping, CanonicalTableName);
                    }
                }
                else
                {
                    Writer.WriteLine("//");
                    Writer.WriteLine("// {0}TextBox", idColumnCanonical);
                    Writer.WriteLine("//");
                    Writer.WriteLine("this.{0}TextBox = new System.Windows.Forms.TextBox();", idColumnCanonical);

                    if (addBindings)
                    {
                        Writer.WriteLine("this.{0}TextBox.DataBindings.Add(new System.Windows.Forms.Binding(\"Text\", this.{2}BindingSource, \"{1}\", true ));",
                                         idColumnCanonical, cv.EfColumnMapping, CanonicalTableName);
                    }

                    Writer.WriteLine("this.{0}TextBox.Location = new System.Drawing.Point( {1}, {2} );", idColumnCanonical, xy.X, xy.Y);
                    Writer.WriteLine("this.{0}TextBox.Name = \"{0}TextBox\";", idColumnCanonical);
                    Writer.WriteLine("this.{0}TextBox.Size = new System.Drawing.Size( {1}, {2} );", idColumnCanonical, 100, 20);
                    Writer.WriteLine("this.{0}TextBox.TabIndex = {1};", idColumnCanonical, tabIdx++);

                    if (cv.MaxLength.HasValue)
                    {
                        Writer.WriteLine("this.{0}TextBox.MaxLength = {1};", idColumnCanonical, cv.MaxLength.Value);
                    }

                    if (cv.IsReadOnly())
                    {
                        Writer.WriteLine("this.{0}TextBox.Enabled = false;", idColumnCanonical);
                    }
                    else if (validationsEnabled)
                    {
                        Writer.WriteLine("this.{0}TextBox.Validating += new System.ComponentModel.CancelEventHandler( this.{0}TextBox_Validating );",
                                         idColumnCanonical);
                    }
                    Writer.WriteLine("this.Panel1.Controls.Add( this.{0}TextBox);", idColumnCanonical);
                }
                xy.Y += szText.Height * 2;
            }

            Writer.PopIdentationLevel();
        }