Example #1
0
    /////////////////////////////////////////////////////////////////////////////////////

    /// <summary>
    /// Adds number of test records to existing database.
    /// </summary>
    ///
    private void AddTestRecordsToDatabase(int extraRecords = 100)
    {
        DialogResult answer = MessageBox.Show(
            "You are about to add random data to database!\n\nAre you sure?",
            "Add Test Records",
            MessageBoxButtons.YesNo, MessageBoxIcon.Warning,
            MessageBoxDefaultButton.Button2);

        if (answer != DialogResult.Yes)
        {
            return;
        }

        string progressInfo = "Adding random records to existing database...";

        // Remove children from client area (probably referring to the contents
        // of the current database)
        //
        UnloadAllMdiChildForms();

        // Create progress bar
        //
        MyProgressBar progress = new MyProgressBar(this, progressInfo);

        // Add records using VRO_TestSuite
        //
        try
        {
            // Create VRO test suite that will be used to add records to existing databse
            //
            VRO_TestSuite.StringWriter   sb   = new VRO_TestSuite.StringWriter();
            VRO_TestSuite.TestClient_VRO test = new VRO_TestSuite.TestClient_VRO(sb);
            test.VideoStore = this.VideoStore;

            // Add records and maintain progress bar every 5th added record
            //
            for (int i = 1; i <= extraRecords; ++i)
            {
                if (i % 5 == 4)
                {
                    progress.Value = i;
                    progress.Refresh();

                    Application.DoEvents();  // increase responsiveness
                }

                try
                {
                    test.AddTestRecords();
                }
                catch
                {
                    // Ignore any database violations as we try to insert random data
                }
            }

            this.InfoMessage = "Database now contains " + VideoStore.TotalRecordsCount
                               + " records";
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.ToString(), "Error",
                            MessageBoxButtons.OK, MessageBoxIcon.Hand);
        }

        progress.Quit();

        #if TEXTUI
        if (MdiClient.ActiveChild != null)
        {
            MdiClient.Focus();
        }
        #endif
    }
Example #2
0
    /////////////////////////////////////////////////////////////////////////////////////

    #region [ Initialize Test Database and Add Test Records to Database Methods ]

    /// <summary>
    /// Initializes sample database using VRO_TestSuite (from ID132V Lab3a).
    /// </summary>
    ///
    private void InitializeTestDatabase()
    {
        DialogResult answer = MessageBox.Show(
            "You are about to delete all current data!\n\nAre you sure?",
            "Initialize Sample Database",
            MessageBoxButtons.YesNo, MessageBoxIcon.Warning,
            MessageBoxDefaultButton.Button2);

        if (answer != DialogResult.Yes)
        {
            return;
        }

        UnloadAllMdiChildForms();

        // Create progress bar
        //
        MyProgressBar progress = new MyProgressBar(this, "Initializing database...");

        progress.Minimum = 0;
        progress.Maximum = 100;

        string report = null;

        try
        {
            VRO_TestSuite.StringWriter sb = new VRO_TestSuite.StringWriter();

            VRO_TestSuite.TestClient_VRO test = new VRO_TestSuite.TestClient_VRO(sb);

            sb.WriteLine();
            sb.WriteLine("Initializing Sample Database...");

            test.CreateSampleDatabase();

            progress.Value = 100;
            progress.Refresh();

            report = sb.ToString();

            if (test.VideoStore != null)
            {
                VideoStore          = test.VideoStore;
                VideoStore.Changed += VideoStore_Changed;

                UpdateTitle();
            }
        }
        catch (Exception ex)
        {
            report = ex.ToString();
        }

        progress.Quit();

        try
        {
            System.IO.File.WriteAllText("VRO-test.txt", report);
            report += "Report saved to to 'VRO-Test.txt'";
        }
        catch {}

        ShowReport("Video Rental Outlet - Test Suite Report", report);
    }