Esempio n. 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
    }
Esempio n. 2
0
    /////////////////////////////////////////////////////////////////////////////////////

    #region [ Methods Displaying Database Info and Contents ]

    /// <summary>
    /// Dumps full contents of database to file and shows the report in report box.
    /// </summary>
    ///
    private void DumpDatabase()
    {
        string progressInfo = "Dumping database contents as text...";

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

        progress.Minimum = 0;
        progress.Maximum = VideoStore.TotalRecordsCount;

        StringBuilder sb = new StringBuilder();

        sb.AppendLine();
        sb.AppendLine("VROLib Database Format v" + VideoStore.Version);
        sb.AppendLine();

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

        sb.AppendLine(VideoStore.FullInfo());

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

        sb.AppendLine(VideoStore.Customers.FullInfo());

        progress.Value += VideoStore.Customers.Count;
        progress.Refresh();

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

        sb.AppendLine(VideoStore.PriceList.FullInfo());

        progress.Value += VideoStore.PriceList.Count;
        progress.Refresh();

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

        sb.AppendLine(VideoStore.Movies.FullInfo());

        progress.Value += VideoStore.Movies.Count;
        progress.Refresh();

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

        sb.AppendLine(VideoStore.MovieExemplars.FullInfo());

        progress.Value += VideoStore.MovieExemplars.Count;
        progress.Refresh();

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

        progress.Quit();

        string report = sb.ToString();

        try
        {
            System.IO.File.WriteAllText("VRO-dump.txt", report);
            sb.AppendLine("Dump saved to 'VRO-dump.txt'");
            report = sb.ToString();
        }
        catch {}

        ShowReport("Video Rental Outlet - Database Text Dump", report);
    }
Esempio n. 3
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);
    }