Beispiel #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
    }