C2017-003: Support SQL Server for storing of Referenced Object data
This commit is contained in:
@@ -318,6 +318,8 @@ namespace VEPROMS
|
||||
{
|
||||
RODbInfo rdi = RODbInfo.GetJustRODB(SelectedROFst.RODbID);
|
||||
tbRoDb.Text = string.Format("{0} ({1})", rdi.ROName, rdi.FolderPath);
|
||||
ppBtnRoToSql.Visible = ppBtnRoToSql.Enabled = CanMigrateRoAccessToSql(rdi); // C2017-003: make button visible if ro migration is doable
|
||||
_CurRoDbInfo = rdi;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -328,7 +330,12 @@ namespace VEPROMS
|
||||
foreach (RODbInfo rdi in RODbInfoList.Get())
|
||||
{
|
||||
int i = cmbRoDb.Items.Add(string.Format("{0} ({1})", rdi.ROName, rdi.FolderPath));
|
||||
if (rdi.RODbID == myrodbid) selindx = i;
|
||||
if (rdi.RODbID == myrodbid)
|
||||
{
|
||||
selindx = i;
|
||||
ppBtnRoToSql.Visible = ppBtnRoToSql.Enabled = CanMigrateRoAccessToSql(rdi); // C2017-003: make button visible if ro migration is doable
|
||||
_CurRoDbInfo = rdi;
|
||||
}
|
||||
}
|
||||
if (cmbRoDb.Items.Count > 0) cmbRoDb.SelectedIndex = selindx;
|
||||
}
|
||||
@@ -1314,7 +1321,7 @@ namespace VEPROMS
|
||||
// KBR & it was decided that we'd wait to see if users end up needing this. It can be done by going
|
||||
// into the sql database and modify/delete records if needed.
|
||||
}
|
||||
|
||||
private RODbInfo _CurRoDbInfo = null;
|
||||
private void cmbRoDb_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
// The only way that a selected index can change on the rodb combo box is if there was no rofst
|
||||
@@ -1337,7 +1344,9 @@ namespace VEPROMS
|
||||
cmbRoDb.Visible = ppBtnRoDbBrowse.Visible = false;
|
||||
tbRoDb.Visible = btnRoDbProperties.Visible = true;
|
||||
tbRoDb.Text = string.Format("{0} ({1})", fst.MyRODb.ROName, fst.MyRODb.FolderPath);
|
||||
|
||||
// C2017-003: See if the selected ro databasew has been converted to sql and if not, make visible a button to convert the data.
|
||||
ppBtnRoToSql.Visible = ppBtnRoToSql.Enabled = CanMigrateRoAccessToSql(fst.MyRODb);
|
||||
_CurRoDbInfo = fst.MyRODb;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1359,7 +1368,31 @@ namespace VEPROMS
|
||||
cmbRoDb.Visible = ppBtnRoDbBrowse.Visible = false;
|
||||
tbRoDb.Visible = btnRoDbProperties.Visible = true;
|
||||
tbRoDb.Text = string.Format("{0} ({1})", tmp.MyRODb.ROName, tmp.MyRODb.FolderPath);
|
||||
// C2017-003: See if the selected ro database has been converted to sql and if not, make visible a button to convert the data.
|
||||
RODbInfo rodbi = RODbInfo.GetJustRODB(tmp.MyRODb.RODbID);
|
||||
ppBtnRoToSql.Visible = ppBtnRoToSql.Enabled = CanMigrateRoAccessToSql(rodbi);
|
||||
_CurRoDbInfo = rodbi;
|
||||
}
|
||||
}
|
||||
|
||||
private bool CanMigrateRoAccessToSql(RODbInfo rODbi)
|
||||
{
|
||||
// C2017-003: This method is used to determine whether RO data can be migrated from MS Access to sql server
|
||||
// A command line argument 'RoInSql'. For now, this argument must be used to allow code to run for ro->sql. Later
|
||||
// this will be changed so that if arugment is used, the program does NOT include button.
|
||||
if (!Volian.Base.Library.VlnSettings.GetCommandFlag("RoInSql")) return false;
|
||||
|
||||
// The following conditions must be true in order to migrate the ro data to sql. Only the first condition can be
|
||||
// tested in this executable since the roall database is interfaced to by the roeditor & the program that migrates the data.
|
||||
// The migration program will make the 2-4 tests, put up a message box if it cannot migrate & will send a failure back
|
||||
// to this program, PROMS.
|
||||
// 1) the user must be an admin and the rodb record's connection string must be 'cstring' (it is the connection string if data was migrated)
|
||||
// 2) the roall database must exist when using the rodb record's connection string and this database must have the stored procedures
|
||||
// 3) roall must be empty
|
||||
// 4) the database must be the correct version
|
||||
UserInfo ui = UserInfo.GetByUserID(VlnSettings.UserID);
|
||||
if (!ui.IsAdministrator()) return false;
|
||||
return (rODbi.DBConnectionString == "cstring");
|
||||
}
|
||||
|
||||
private void ppBtnRoDbBrowse_Click(object sender, EventArgs e)
|
||||
@@ -1700,6 +1733,50 @@ namespace VEPROMS
|
||||
}
|
||||
}
|
||||
|
||||
// C2017-003: The button to migrate ro data from MS Access to sql server was clicked:
|
||||
private void ppBtnRoToSql_Click(object sender, EventArgs e)
|
||||
{
|
||||
string exelocation = Application.ExecutablePath;
|
||||
try
|
||||
{
|
||||
Application.DoEvents();
|
||||
exelocation = exelocation.Substring(0, exelocation.LastIndexOf("\\")) + @"\RoAccessToSql.exe";
|
||||
int indx = tbRoDb.Text.IndexOf(" (")+2;
|
||||
string accesspath = tbRoDb.Text.Substring(indx, tbRoDb.Text.Length - indx - 1);
|
||||
string sqldb = Database.ActiveDatabase;
|
||||
indx = Database.DBServer.IndexOf(" ");
|
||||
string server = Database.DBServer.Substring(0, indx);
|
||||
string args = @"/acc=" + accesspath + @" /sqldb=" + sqldb + @" /server=" + server;
|
||||
System.Diagnostics.Process p = System.Diagnostics.Process.Start(exelocation, args);
|
||||
p.WaitForExit(); // without arguments, this will wait indefinitely
|
||||
Application.DoEvents();
|
||||
string _TmpFileForConnectStr = Path.GetTempPath();
|
||||
_TmpFileForConnectStr = _TmpFileForConnectStr + @"\PromsConnect.txt";
|
||||
if (File.Exists(_TmpFileForConnectStr)) // if conversion was done, the connection string will be added to the promsconnect.txt file
|
||||
{
|
||||
string constring = File.ReadAllText(_TmpFileForConnectStr);
|
||||
if (constring != null && constring != "" && constring.ToUpper().Contains("DATA SOURCE"))
|
||||
{
|
||||
// read in the connection string & set for this rodbinfo
|
||||
using (RODb rodbtmp = RODb.GetJustRoDb(_CurRoDbInfo.RODbID))
|
||||
{
|
||||
rodbtmp.DBConnectionString = File.ReadAllText(_TmpFileForConnectStr);
|
||||
rodbtmp.Save();
|
||||
}
|
||||
// to be sure all aspects of program are using the converted database, tell user to restart:
|
||||
MessageBox.Show(this, "Restart PROMS to have referenced object database migration take effect.", "", MessageBoxButtons.OK);
|
||||
}
|
||||
ppBtnRoToSql.Visible = false;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
while (ex.InnerException != null)
|
||||
ex = ex.InnerException;
|
||||
string tmpmsg = ex.Message;
|
||||
MessageBox.Show(tmpmsg, "Migration Error: " + ex.GetType().Name);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
[XmlRoot("Enhanced")]
|
||||
|
Reference in New Issue
Block a user