Ejemplo n.º 1
0
    /// <summary>
    /// Creates a new MyComboBox control inside MyGroupBox container, associated
    /// to a specified Enum type and at some location.
    /// </summary>
    /// <remarks>
    /// The control is added to the form container with its tab-index property
    /// automatically assigned (see <see cref="NextTabIndex"/>).
    /// </remarks>
    ///
    protected MyComboBox NewEnumField(MyGroupBox box, float left, float top,
                                      float width, Type type)
    {
        if (Em.IsTextUI)
        {
            --left;
        }

        MyComboBox combo = new MyComboBox()
        {
            AutoSize = width <= 0 ? true : false,
            Left     = (int)(left * Em.Width),
            Top      = (int)(top * Em.Height) - (Em.IsGUI ? 3 : 0),
            TabStop  = true,
            TabIndex = NextTabIndex,
            Parent   = box,
        };

        if (width > 0)
        {
            combo.Width = (int)(width * Em.Width);
        }

        combo.AddEnum(type);

        return(combo);
    }
Ejemplo n.º 2
0
 /// <summary>
 /// Creates a new MyTextBox control inside MyGroupBox container at specified location.
 /// </summary>
 /// <remarks>
 /// The control is added to the form container with its tab-index property
 /// automatically assigned (see <see cref="NextTabIndex"/>).
 /// </remarks>
 ///
 protected MyTextBox NewTextField(MyGroupBox box, float left, float top, float width)
 {
     return(new MyTextBox()
     {
         Left = (int)(left * Em.Width),
         Top = (int)(top * Em.Height) - (Em.IsGUI ? 3 : 0),
         Width = (int)(width * Em.Width),
         TabStop = true,
         TabIndex = NextTabIndex,
         Parent = box,
     });
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Creates a new MyLabel control with caption and at specified location.
 /// </summary>
 /// <remarks>
 /// The control is added to the form container with its tab-index property
 /// automatically assigned (see <see cref="NextTabIndex"/>).
 /// </remarks>
 ///
 protected MyLabel NewLabel(MyGroupBox box, float left, float top, string text)
 {
     return(new MyLabel()
     {
         AutoSize = true,
         Left = (int)(left * Em.Width),
         Top = (int)(top * Em.Height),
         TabStop = false,
         TabIndex = NextTabIndex,
         Text = text,
         Parent = box,
     });
 }
Ejemplo n.º 4
0
    /////////////////////////////////////////////////////////////////////////////////////

    #region [ Overriden Base Methods ]

    protected override void InitializeComponents()
    {
        /////////////////////////////////////////////////////////////////////////////////
        // Table layout grid definition, with rows and columns in Em units.

        float[] col = { 3, 17, 44, 57 };
        float[] row = { 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22 };

        float colWidth = 24; // default column width

        /////////////////////////////////////////////////////////////////////////////////
        // Static text

        int r = 0, c = 0;

        NewStaticText(col[c], row[r++], "First Name:");
        NewStaticText(col[c], row[r++], "Last Name:");
        NewStaticText(col[c], row[r++], "Person ID:");

        NewStaticText(col[c], row[r++], "Membership:");

        NewStaticText(col[c], row[r++], "Address:");
        NewStaticText(col[c], row[r++], "Post Code:");
        NewStaticText(col[c], row[r++], "City:");
        NewStaticText(col[c], row[r++], "Country:");

        // Mandatory fields marker:
        NewStaticText(col[c] - 2, row[0], "*");
        NewStaticText(col[c] - 2, row[1], "*");
        NewStaticText(col[c] - 2, row[2], "*");

        r = 0; c = 2;

        NewStaticText(col[c], row[r++], "Phone:");
        NewStaticText(col[c], row[r++], "Cell Phone:");
        NewStaticText(col[c], row[r++], "E-Mail:");

        /////////////////////////////////////////////////////////////////////////////////
        // TextBox fields

        r = 0; c = 1;

        this.firstName = NewTextField(col[c], row[r++], colWidth);
        this.lastName  = NewTextField(col[c], row[r++], colWidth);
        this.personID  = NewTextField(col[c], row[r++], colWidth);

        this.membership = NewEnumField(col[c], row[r++],
                                       Em.IsGUI ? colWidth : 0, typeof(Membership));

        this.address  = NewTextField(col[c], row[r++], colWidth);
        this.postCode = NewTextField(col[c], row[r++], colWidth);
        this.city     = NewTextField(col[c], row[r++], colWidth);
        this.country  = NewTextField(col[c], row[r++], colWidth);

        r = 0; c = 3;

        this.phone     = NewTextField(col[c], row[r++], colWidth);
        this.cellPhone = NewTextField(col[c], row[r++], colWidth);
        this.email     = NewTextField(col[c], row[r++], colWidth);

        /////////////////////////////////////////////////////////////////////////////////
        // Credit Card Group Box

        MyGroupBox ccBox = NewGroupBox("Credit Card",
                                       col[2] - (Em.IsGUI ? 1f : 2f),
                                       row[r] + (Em.IsGUI ? 0.6f : 1f), 38, (Em.IsGUI ? 8.6f : 9f)
                                       );

        NewLabel(ccBox, 2, 2, "Type:");
        NewLabel(ccBox, 2, 4, "Number:");
        NewLabel(ccBox, 2, 6, "Valid Thru:");

        int offset = Em.IsGUI ? 14 : 15;

        this.creditCard = NewEnumField(ccBox, offset, 2,
                                       Em.IsGUI ? 22 : 0, typeof(CreditCardType));

        this.creditCardNumber = NewTextField(ccBox, offset, 4, Em.IsGUI ? 22 : 19);
        this.creditCardValid  = NewTextField(ccBox, offset, 6, Em.IsGUI ? 10 : 8);

        /////////////////////////////////////////////////////////////////////////////////
        // Field validation event handlers

        this.firstName.Validating += (sender, e) =>
        {
            MdiForm.ErrorMessage = null;

            if (ReadOnly || !this.firstName.ContentsChanged)
            {
                return;
            }

            ValidateNotNull("Customer's first name", this.firstName.Text, e);
        };

        this.lastName.Validating += (sender, e) =>
        {
            MdiForm.ErrorMessage = null;

            if (ReadOnly || !this.lastName.ContentsChanged)
            {
                return;
            }

            ValidateNotNull("Customer's last name", this.lastName.Text, e);
        };

        this.personID.Validating += (sender, e) =>
        {
            MdiForm.ErrorMessage = null;

            if (ReadOnly || !this.personID.ContentsChanged)
            {
                return;
            }

            ValidateNotNull("Customer's Person-ID", this.personID.Text, e);

            if (!ReadOnly && !e.Cancel)
            {
                string notValidInfo = Customer.ValidatePNR(this.personID.TrimmedText);

                if (notValidInfo != null)
                {
                    MdiForm.ErrorMessage = notValidInfo;
                    MdiForm.Beep();
                    e.Cancel = true;
                }
            }
        };

        this.email.Validating += (sender, e) =>
        {
            MdiForm.ErrorMessage = null;

            if (ReadOnly || !this.email.ContentsChanged)
            {
                return;
            }

            ValidateEMailAddress("E-Mail", this.email.Text, e);
        };

        this.creditCard.SelectedIndexChanged += (sender, e) =>
        {
            CreditCardType?ccType = this.creditCard.Current.Tag as CreditCardType?;

            if (ccType.HasValue && ccType.Value != CreditCardType.None)
            {
                this.creditCardNumber.TabStop = true;
                this.creditCardNumber.Enabled = true;
                this.creditCardValid.TabStop  = true;
                this.creditCardValid.Enabled  = true;
            }
            else
            {
                // this.creditCardNumber.Text = null;
                this.creditCardNumber.TabStop = false;
                this.creditCardNumber.Enabled = false;
                // this.creditCardValid.Text = null;
                this.creditCardValid.TabStop = false;
                this.creditCardValid.Enabled = false;
            }
        };

        this.creditCardNumber.Validating += (sender, e) =>
        {
            MdiForm.ErrorMessage = null;

            if (ReadOnly || !this.creditCardNumber.ContentsChanged)
            {
                return;
            }

            CreditCardType?ccType = this.creditCard.Current.Tag as CreditCardType?;

            if (ccType.HasValue && ccType.Value != CreditCardType.None)
            {
                string ccNumber = this.creditCardNumber.TrimmedText;

                // ValidateNotNull( "Credit Card Number", ccNumber, e );

                // Credit card number valiation will be performed when record
                // is updated.
            }
        };

        this.creditCardValid.Validating += (sender, e) =>
        {
            MdiForm.ErrorMessage = null;

            if (ReadOnly || !this.creditCardValid.ContentsChanged)
            {
                return;
            }

            CreditCardType?ccType = this.creditCard.Current.Tag as CreditCardType?;

            if (ccType.HasValue && ccType.Value != CreditCardType.None)
            {
                // ValidateNotNull( "Valid Thru", this.creditCardValid.Text, e );

                ValidateDate("Valid Thru", this.creditCardValid.Text,
                             "yyyy-M", " in 'yyyy-mm' format.", e);
            }
        };

        /////////////////////////////////////////////////////////////////////////////////

        base.InitializeComponents();
    }
Ejemplo n.º 5
0
 void InitGroupBox(COneRecord record, int index)
 {
     semesters[index] = new MyGroupBox(record, index);
     form.Controls.Add(semesters[index].GetBox());
 }
Ejemplo n.º 6
0
    /////////////////////////////////////////////////////////////////////////////////////

    #region [ Overriden Base Methods ]

    /// <summary>
    /// Initializes UI components of the MdiForm.
    /// </summary>
    ///
    protected override void InitializeComponents()
    {
        /////////////////////////////////////////////////////////////////////////////////
        // Table layout grid definition, with rows and columns in Em units.

        float[] col = { 3, 18, 47, 63, 79 };
        float[] row = { 2, 4, 6, 8, 10, 12, 14, 17, 19, 21, 22 };

        float maxLen = 24; // Maximum text length

        /////////////////////////////////////////////////////////////////////////////////
        // Static text

        int r = 0, c = 0;

        NewStaticText(col[c] - 2, row[r++], "*");

        NewStaticText(col[c], row[r++], "First Release:");
        NewStaticText(col[c], row[r++], "Duration:");
        NewStaticText(col[c], row[r++], "Country:");
        NewStaticText(col[c], row[r++], "Language:");
        NewStaticText(col[c], row[r++], "PG-Rate:");
        NewStaticText(col[c], row[r++], "IMDB:");

        NewStaticText(col[c] + 21, row[2], "(min)");

        /////////////////////////////////////////////////////////////////////////////////
        // TextBox fields

        r = 0; c = 1;

        this.labelTitle             = NewLabel(col[0], row[0], 10);
        this.labelTitle.UseMnemonic = true;
        this.labelTitle.Text        = "&Title:";

        // Always move focus from title label to movie title
        //
        this.labelTitle.GotFocus += (sender, e) => this.movieTitle.Focus();

        this.movieTitle = NewTextField(col[c], row[r++], maxLen);
        this.release    = NewTextField(col[c], row[r++], maxLen);
        this.duration   = NewTextField(col[c], row[r++], 5);
        this.country    = NewTextField(col[c], row[r++], maxLen);
        this.language   = NewTextField(col[c], row[r++], maxLen);
        this.pgRate     = NewTextField(col[c], row[r++], maxLen);
        this.imdb       = NewTextField(col[c], row[r++], maxLen);

        /////////////////////////////////////////////////////////////////////////////////
        // ChecBoxes for Genre

        MyGroupBox genreBox = NewGroupBox("&Genre",
                                          col[2] - 3, row[0] - (Em.IsGUI ? 0.5f : 0f), 34, 14);

        this.genre = new MyCheckBoxCollection(typeof(Genre));

        r = 0; c = 0;
        foreach (CheckBox cb in this.genre)
        {
            cb.Parent   = genreBox;
            cb.TabIndex = NextTabIndex;
            cb.Left     = (int)((2f + c * 16f) * Em.Width);
            cb.Top      = (int)(Em.IsGUI ? 1.4f * Em.Height : 2f * Em.Height);
            #if TEXTUI
            cb.Height = Em.Height;
            cb.Width  = 15 * Em.Width;
            #else
            cb.AutoSize = true;
            #endif
            cb.Top += (r++) * (Em.IsGUI ? Em.Height + 3 : Em.Height);
            if (r >= 10)
            {
                r = 0; if (++c > 3)
                {
                    break;
                }
            }
        }

        /////////////////////////////////////////////////////////////////////////////////
        // Multiline TextBox: Directors

        r = 7; c = 1;

        if (Em.IsGUI)
        {
            row[8] -= 0.4f;
        }

        this.labelDirectors             = NewLabel(col[0], row[r], 18);
        this.labelDirectors.UseMnemonic = true;
        this.labelDirectors.Text        = "Di&rectors";
        this.labelDirectors.Height      = Em.Height;

        this.directors               = NewTextField(col[0], row[r + 1], 18);
        this.directors.Multiline     = true;
        this.directors.Height        = 5 * Em.Height + (Em.IsGUI ? 4 : 0);
        this.directors.AutoScrollBar = true;

        // Always move focus from directors label to directors field
        //
        this.labelDirectors.GotFocus += (source, e) => this.directors.Focus();

        /////////////////////////////////////////////////////////////////////////////////
        // Multiline TextBox: Writers

        this.labelWriters             = NewLabel(col[0] + 20, row[r], 18);
        this.labelWriters.UseMnemonic = true;
        this.labelWriters.Text        = "&Writers";
        this.labelWriters.Height      = Em.Height;

        this.writers               = NewTextField(col[0] + 20, row[r + 1], 18);
        this.writers.Multiline     = true;
        this.writers.Height        = 5 * Em.Height + (Em.IsGUI ? 4 : 0);
        this.writers.AutoScrollBar = true;

        // Always move focus from writers label to writers field
        //
        this.labelWriters.GotFocus += (source, e) => this.writers.Focus();

        /////////////////////////////////////////////////////////////////////////////////
        // Multiline TextBox: Actors

        this.labelActors             = NewLabel(col[0] + 40, row[r], 18);
        this.labelActors.UseMnemonic = true;
        this.labelActors.Text        = "&Actors";
        this.labelActors.Height      = Em.Height;

        this.actors               = NewTextField(col[0] + 40, row[r + 1], 34);
        this.actors.Multiline     = true;
        this.actors.Height        = 5 * Em.Height + (Em.IsGUI ? 4 : 0);
        this.actors.AutoScrollBar = true;

        // Always move focus from actors label to actors field
        //
        this.labelActors.GotFocus += (source, e) => this.actors.Focus();

        /////////////////////////////////////////////////////////////////////////////////
        // Field validation event handlers

        this.movieTitle.Validating += (sender, e) =>
        {
            MdiForm.ErrorMessage = null;

            if (ReadOnly || !this.movieTitle.ContentsChanged)
            {
                return;
            }

            ValidateNotNull("Movie title", this.movieTitle.Text, e);
        };

        this.release.Validating += (sender, e) =>
        {
            MdiForm.ErrorMessage = null;

            if (ReadOnly || !this.release.ContentsChanged)
            {
                return;
            }

            ValidateDate("First release (if specified)", this.release.Text, "yyyy-M-d",
                         " in ISO format (yyyy-mm-dd).", e);
        };

        this.duration.Validating += (sender, e) =>
        {
            MdiForm.ErrorMessage = null;

            if (ReadOnly || !this.duration.ContentsChanged)
            {
                return;
            }

            string fieldName = "Duration in minutes, if specified,";

            int fieldValue = 1; // default value to satisfy validation if null

            ValidateInteger(fieldName, this.duration.Text, e, ref fieldValue);

            // Duration must be either null or an integer >= 1
            //
            if (!e.Cancel && fieldValue < 1)
            {
                MdiForm.ErrorMessage = fieldName + " must be greater than zero.";
                MdiForm.Beep();
                e.Cancel = true;
            }
            else if (!e.Cancel && fieldValue > 24 * 60)
            {
                MdiForm.ErrorMessage = fieldName + " must be less than 24 hours.";
                MdiForm.Beep();
                e.Cancel = true;
            }
        };

        /////////////////////////////////////////////////////////////////////////////////

        base.InitializeComponents();
    }