Пример #1
0
    /////////////////////////////////////////////////////////////////////////////////////

    /// <summary>
    /// Opens/creates form to add new movie exemplar depending on the current
    /// active form with selected movie.
    /// </summary>
    ///
    internal void AddNewMovieExemplar()
    {
        MovieListForm         movieList    = Find <MovieListForm> ();
        MovieDetailsForm      movieDetials = Find <MovieDetailsForm> ();
        MovieExemplarListForm exemplarList = Find <MovieExemplarListForm> ();

        if (exemplarList != null && exemplarList.MdiForm == ActiveMdiChild)
        {
            OpenAddNew <MovieExemplarListForm> ();
        }
        else if (movieDetials != null && movieDetials.Record != null &&
                 movieDetials.MdiForm == ActiveMdiChild)
        {
            OpenAddNewMovieExemplarDetails(movieDetials.Record);
        }
        else if (movieList != null && movieList.CurrentRecord != null &&
                 movieList.MdiForm == ActiveMdiChild)
        {
            OpenAddNewMovieExemplarDetails(movieList.CurrentRecord);
        }
        else if (exemplarList != null &&
                 (exemplarList.Movie != null || exemplarList.CurrentRecord != null))
        {
            OpenAddNew <MovieExemplarListForm> ();
        }
        else if (movieDetials != null && movieDetials.Record != null)
        {
            OpenAddNewMovieExemplarDetails(movieDetials.Record);
        }
        else if (movieList != null && movieList.CurrentRecord != null)
        {
            OpenAddNewMovieExemplarDetails(movieList.CurrentRecord);
        }
        else // movies == null && exemplars == null
        {
            Open <MovieListForm>(OpenMode.Edit);

            MessageBox.Show(
                "Choose a movie first!\n\n"
                + "Then select Add New Exemplar for the movie...",
                "Add New Movie Exemplar",
                MessageBoxButtons.OK, MessageBoxIcon.Information
                );
        }
    }
Пример #2
0
    /// <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, 40, 50, 79 };
        float[] row = { 2, 4, 7, 9, 11, 12, 14, 16, 18, 21, 22 };

        float maxLen = 15; // Maximum text length

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

        int r = 2, c = 0;

        NewStaticText(col[c], row[r++], "Due Date:");
        NewStaticText(col[c], row[r++], "Rental Fee:");

        /////////////////////////////////////////////////////////////////////////////////
        // Customer info label

        this.customerInfo = NewLabel(col[0], row[0] - (Em.IsGUI ? 0.2f : 0f),
                                     (float)MdiForm.Width / Em.Width - col[0] * 2
                                     );

        this.exemplarInfo = NewLabel(col[0], row[1] + (Em.IsGUI ? 0.2f : 0f),
                                     (float)MdiForm.Width / Em.Width - col[0] * 2
                                     );

        this.exemplarSelect = new MyButton()
        {
            Left    = (int)(col[2] * Em.Width),
            Top     = (int)((row[2] - (Em.IsGUI ? 0.2f : 0f)) * Em.Height),
            Text    = "&Select Movie Exemplar", AutoSize = true,
            TabStop = true, TabIndex = NextTabIndex,
            Parent  = MdiForm,
        };

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

        r = 2; c = 1;

        this.dueDate   = NewTextField(col[c], row[r++], maxLen);
        this.rentalFee = NewTextField(col[c], row[r++], maxLen);

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

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

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

            ValidateNotNull("Due date", this.dueDate.Text, e);

            ValidateDate("Due date", this.dueDate.Text, "yyyy-M-d",
                         " in ISO format (yyyy-mm-dd).", e);
        };

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

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

            string fieldName = "Rental Fee";

            ValidateNotNull(fieldName, this.dueDate.Text, e);

            decimal fieldValue = 0; // default value to satisfy validation if null

            ValidateDecimal(fieldName, this.rentalFee.Text, e, ref fieldValue);

            // Rental fee must be either null or an decimal >= 0
            //
            if (!e.Cancel && fieldValue <= 0)
            {
                MdiForm.ErrorMessage = fieldName + " must not be a positive number.";
                MdiForm.Beep();
                e.Cancel = true;
            }
        };

        /////////////////////////////////////////////////////////////////////////////////
        // Movie Exemplar Selection as modal MovieExemplarListForm (i.e. dialog)

        this.exemplarSelect.Click += (sender, e) =>
        {
            this.ExecuteWithoutFormValidation(() =>
            {
                MovieExemplarListForm form = new MovieExemplarListForm();

                form.CommonFilter = ex => !ex.IsRented;

                form.OpenModal(this.Exemplar, selectedExemplar =>
                {
                    this.Exemplar          = selectedExemplar;
                    this.exemplarInfo.Text = selectedExemplar.ToString();
                    this.exemplarChanged   = true;

                    if (this.Customer != null)
                    {
                        decimal fee = MainForm.VideoStore.GetPrice(
                            this.Customer.Membership, this.Exemplar.PriceClass,
                            this.Customer.RentedItemsCount + 1);

                        this.rentalFee.Text = fee.ToString("0.00");
                    }

                    form.QuitForm();
                    this.dueDate.Select();
                });
            });
        };

        /////////////////////////////////////////////////////////////////////////////////
        // Customer info GUI/TUI specific setup
        //
#if TEXTUI
        MdiForm.GotFocus += (sender, e) =>
        {
            this.customerInfo.ForeColorInact = Color.White;
            this.customerInfo.ForeColor      = Color.White;

            this.exemplarInfo.ForeColorInact = Color.Cyan;
            this.exemplarInfo.ForeColor      = Color.Cyan;
        };
#else
        this.customerInfo.Font         = MainForm.HeadingFont;
        this.customerInfo.Height       = Em.Height * 15 / 10;
        this.customerInfo.ForeColor    = Color.DarkBlue;
        this.customerInfo.AutoSize     = false;
        this.customerInfo.AutoEllipsis = true;

        this.exemplarInfo.Height       = Em.Height + (Em.IsGUI ? 2 : 0);
        this.exemplarInfo.ForeColor    = Color.DarkRed;
        this.exemplarInfo.AutoSize     = false;
        this.exemplarInfo.AutoEllipsis = true;

        this.MdiForm.FontChanged += (sender, e) =>
        {
            this.customerInfo.Font   = MainForm.HeadingFont;
            this.customerInfo.Height = Em.Height * 15 / 10;
            this.exemplarInfo.Height = Em.Height + (Em.IsGUI ? 2 : 0);
        };
#endif
        /////////////////////////////////////////////////////////////////////////////////

        base.InitializeComponents();
    }