C2017-003: Support SQL Server for storing of Referenced Object data

This commit is contained in:
2020-01-09 15:19:25 +00:00
parent 3f695a95a4
commit 7fbc9e358d
10 changed files with 192 additions and 36 deletions

View File

@@ -415,7 +415,41 @@ namespace ROEditor
ContextMenu treePopupMenu = new ContextMenu(ContextMenuItemList);
// Add the root to the tree.
myrodb = new RODB(DbConnectPath);
// C2017-003: support for sql server
if (UsingSQLServer(DbConnectPath))
myrodb = new SqlRODB(DbConnectPath, SqlConnectionStr, false);
else
myrodb = new AccessRODB(DbConnectPath);
// if using the access database (not sql) and the data has been converted, try to connect using the sql connection
// string that was written to access when data was converted:
if (!UsingSQLServer(Directory.GetCurrentDirectory()))
{
string constring = myrodb.RODB_HasBeenConverted();
if (constring != null)
{
MessageBox.Show("This Referenced Object Database has been converted to sql. The program will attempt to use the sql version of the database. If this does not work, you will be prompted for a connection string, if not available, contact your Database Administrator", "RO Microsoft Access problem");
SqlConnectionStr = constring;
bool canConnect = SqlRODB.TestConnect(constring);
if (!canConnect) // can't get data from this sql database, ask user to enter a string.
{
string userConstring = SqlRODB.GetSqlDbConnectString(constring);
if (userConstring == null)
{
MessageBox.Show("Cannot connect to the correct database. Contact your Database or Proms Administrator");
return;
}
SqlConnectionStr = userConstring;
// write new string to access database
if (!myrodb.RODB_WriteSqlConnectToAccess(userConstring))
{
MessageBox.Show("Cannot save the new connection string. Contact your Database or Proms Administrator");
this.Close();
}
}
myrodb.dbProviderType = (int)RODB.DB_PROVIDER.SQL_SERVER;
myrodb = new SqlRODB(DbConnectPath, SqlConnectionStr, true);
}
}
myroXmlDoc = myrodb.RODB_GetRoot();
rootXml = (VlnXmlElement) myroXmlDoc.FirstChild;
rootNode = new TreeNode("Referenced Objects",ROGROUPIMAGE,ROGROUPIMAGE);
@@ -1548,7 +1582,15 @@ namespace ROEditor
ConnectionPath = FindTheRODirectory();
}
if (args.Length > 1)
specificro = args[1];
{
if (args[1].ToUpper().Contains("DATA SOURCE")) SqlConnectionStr = args[1];
else specificro = args[1];
}
if (args.Length > 2)
{
if (args[2].ToUpper().Contains("DATA SOURCE")) SqlConnectionStr = args[2];
else specificro = args[2];
}
try
{
// Convert the RO data if needed
@@ -1740,15 +1782,18 @@ namespace ROEditor
}
return RtnStr;
}
// C2017-003: support for sql server
static public string SqlConnectionStr = null;
static bool UsingSQLServer(string ROdir)
{
// using sql if there is a connection string or if defined in roapp.ini
if (SqlConnectionStr != null && SqlConnectionStr != "") return true;
bool Rtn = false;
string RtnStr;
string ROiniPath = ROdir + "\\ROAPP.INI";
IniReader ini = new IniReader(ROiniPath);
RtnStr = ini.ReadString("Database Server","Path","");
if (RtnStr.Length > 1)
SqlConnectionStr = ini.ReadString("Database Server", "Path", "");
if (SqlConnectionStr.Length > 1)
Rtn = true;
return Rtn;
}
@@ -2128,7 +2173,7 @@ namespace ROEditor
private void menuHelpAbout_Click(object sender, System.EventArgs e)
{
//AboutDlg dlg = new AboutDlg();
AboutROEditor dlg = new AboutROEditor();
AboutROEditor dlg = new AboutROEditor(myrodb);
dlg.ShowDialog();
}
@@ -2498,7 +2543,7 @@ namespace ROEditor
if (selele.Name != "RO_Root")
{
ArrayList AvailList = myrodb.RODB_GetFields(selele, 0);
InUseList = myrodb.RODB_GetFieldsInUse(selele, AvailList, "FieldsInUse", ref tmp, true);
InUseList = myrodb.RODB_GetFieldsInUse(selele, AvailList, "FieldsInUse", ref tmp, false);
}
// Put out fields and their associated data.