Hi, I have the following method which contains some repeated code. Could this
be reduced somehow? Thanks.
private void chooseDatabase()
{
string dbFile = GetPath();
string systemDB = GetSystemDB();
try
{
if (File.Exists(systemDB))
{
string UserID = GetUser();
string Pwd = GetPwd();
progressBar.Value = 1 ;
bool testPassword = true;
if (chkMaster.Checked)
CompactDB(dbFile, systemDB, UserID, Pwd, ref testPassword, "Master.mdb");
if (!testPassword)
return;
if (chkToolbox.Checked)
CompactDB(dbFile, systemDB, UserID, Pwd, ref testPassword, "Toolbox.mdb");
if (!testPassword)
return;
if (chkImport.Checked)
CompactDB(dbFile, systemDB, UserID, Pwd, ref testPassword, "Import.mdb");
if (!testPassword)
return;
if (chkLibrary.Checked)
CompactDB(dbFile, systemDB, UserID, Pwd, ref testPassword, "Library.mde");
if (!testPassword)
return;
if (chkUser.Checked)
CompactDB(dbFile, systemDB, UserID, Pwd, ref testPassword, "User.mdb");
if (!testPassword)
return;
if (chkImpData.Checked)
CompactDB(dbFile, systemDB, UserID, Pwd, ref testPassword, "ImpData.mdb");
if (!testPassword)
return;
progressBar.Value = progressBar.Maximum;
MessageBox.Show("Compacting complete.",messageHeader);
}
else
//Cannot find System database file
{
MessageBox.Show("Cannot find the System database " + systemDB + "\n" + "\n" +
"Check the database name (and path, if specified) to make sure it exists.",
messageHeader,MessageBoxButtons.OK,MessageBoxIcon. Exclamation);
progressBar.Value = progressBar.Minimum;
}
}
catch (System.Security.Cryptography.CryptographicExcepti on)
{
//System Database User Name corrupt
MessageBox.Show("System database is corrupt." + "\n" + "\n" +
"Replace the file " + systemDB + ".",
messageHeader,MessageBoxButtons.OK,MessageBoxIcon. Exclamation);
}
}