From 7fbc9e358d8f26a255b8bdbe0e63eb996aeb257c Mon Sep 17 00:00:00 2001 From: Kathy Date: Thu, 9 Jan 2020 15:19:25 +0000 Subject: [PATCH] C2017-003: Support SQL Server for storing of Referenced Object data --- PROMS/AdjustBuildRevision/Program.cs | 6 +- .../Exe/RefObj/CmpRpt/CmpRpt.cs | 74 +++++++++++++++---- .../RefObj/ROEditor/AboutROEditor.Designer.cs | 6 +- .../Exe/RefObj/ROEditor/AboutROEditor.cs | 7 +- .../Exe/RefObj/ROEditor/AboutROEditor.resx | 4 +- .../Exe/RefObj/ROEditor/FixRev.Bat | 2 +- .../Exe/RefObj/ROEditor/GroupDefFrm.cs | 2 +- .../Exe/RefObj/ROEditor/RODefFrm.cs | 7 +- .../Exe/RefObj/ROEditor/ROEditor.cs | 61 +++++++++++++-- .../LibSource/DBEncapsulation/DBEncap.cs | 59 +++++++++++++++ 10 files changed, 192 insertions(+), 36 deletions(-) diff --git a/PROMS/AdjustBuildRevision/Program.cs b/PROMS/AdjustBuildRevision/Program.cs index dcd911de..39539c0d 100644 --- a/PROMS/AdjustBuildRevision/Program.cs +++ b/PROMS/AdjustBuildRevision/Program.cs @@ -30,7 +30,11 @@ namespace AdjustBuildRevision string outline = line; if (line.Contains("AssemblyVersion") || line.Contains("AssemblyFileVersion")) { - outline = Regex.Replace(line, @"([0-9]*)\.([0-9]*)\.([0-9]*)\.([0-9]*)""\)", DateTime.Now.ToString("1.6.yyMM.dHH") + "\")"); + // Allow for setting build revision on either proms or the roeditor: + if (Directory.GetCurrentDirectory().ToUpper().Contains("REFOBJ")) + outline = Regex.Replace(line, @"([0-9]*)\.([0-9]*)\.([0-9]*)\.([0-9]*)""\)", DateTime.Now.ToString("2.0.yyMM.dHH") + "\")"); + else + outline = Regex.Replace(line, @"([0-9]*)\.([0-9]*)\.([0-9]*)\.([0-9]*)""\)", DateTime.Now.ToString("1.7.yyMM.dHH") + "\")"); // if (outline != line) // { // Console.WriteLine("Before: '{0}'", line); diff --git a/PROMS/ReferencedObjects/Exe/RefObj/CmpRpt/CmpRpt.cs b/PROMS/ReferencedObjects/Exe/RefObj/CmpRpt/CmpRpt.cs index b9bcef52..3c4a40ea 100644 --- a/PROMS/ReferencedObjects/Exe/RefObj/CmpRpt/CmpRpt.cs +++ b/PROMS/ReferencedObjects/Exe/RefObj/CmpRpt/CmpRpt.cs @@ -30,7 +30,10 @@ using System.IO; using System.Data; using RODBInterface; using VlnStatus; - +using System.Data.SqlClient; +using System.Xml; +using System.Xml.XPath; +using System.Xml.Schema; // CmpRpt reads data for the RO database and puts the data into the // temporary file, 'print.tmp'. After this, it is sorted and printed. @@ -137,12 +140,27 @@ namespace CmpRpt // for the Access database. string roIdArg = BuildROList(args); string[] roIDList = roIdArg.Split(','); - if (args.Length == 2) + if (args.Length == 2 || args.Length == 3) { string path = args[0]; Directory.SetCurrentDirectory(path); } - myrodb = new RODB(Directory.GetCurrentDirectory()); + if (SqlConnectionStr != null) + myrodb = new SqlRODB(Directory.GetCurrentDirectory(), SqlConnectionStr, false); + else + { + myrodb = new AccessRODB(Directory.GetCurrentDirectory()); + // if using access, be sure that the data has not been converted. When converted a record will be inserted w/ type = 8 and the info + // will contain the connection string. + string constring = myrodb.RODB_HasBeenConverted(); + if (constring != null) + { + MessageBox.Show("This Referenced Object Database has been converted to sql. Attempting to use the sql version of the database. If this does not work, contact your Database Administrator", "RO access problem"); + SqlConnectionStr = constring; + myrodb.dbProviderType = (int)RODB.DB_PROVIDER.SQL_SERVER; + myrodb = new SqlRODB(Directory.GetCurrentDirectory(), SqlConnectionStr, true); + } + } VlnXmlElement rptele = null; // Add the root to the tree @@ -258,22 +276,50 @@ namespace CmpRpt if (showStatBar != null) showStatBar.Dispose(); } - - private static string BuildROList(string[] args) + // C2017-003: use sql + static public string SqlConnectionStr = null; + static public SqlConnection ROAPP_SqlConnection { - string parm2 = args[args.Length - 1]; - string roIdArg = null; - if (parm2.StartsWith("/f=")) + get { - FileInfo fi = new FileInfo(parm2.Substring(3)); - using (StreamReader sr = fi.OpenText()) + // Attempt to make a connection + SqlConnection cn = new SqlConnection(SqlConnectionStr); + try { - roIdArg = sr.ReadToEnd(); - sr.Close(); + cn.Open(); + return cn; + } + catch (SqlException ex) + { + MessageBox.Show(ex.Message, "Could Not Make Connection To Database"); + return null; } } - else - roIdArg = parm2; + } + private static string BuildROList(string[] args) + { + // when ro's in sql was added, an /sql parameter was introduced to allow the definition of the connection string. So + // go through list of args to find the one w/ /f= to find filename that has the ro list in it. + string roIdArg = null; + for (int i = 1; i<=args.Length-1; i++) + { + string parm2 = args[i]; + if (parm2.StartsWith("/f=")) + { + FileInfo fi = new FileInfo(parm2.Substring(3)); + using (StreamReader sr = fi.OpenText()) + { + roIdArg = sr.ReadToEnd(); + sr.Close(); + } + } + else if (parm2.StartsWith("/sql=")) + { + SqlConnectionStr = parm2.Substring(5); + } + else + roIdArg = parm2; + } return roIdArg; } } diff --git a/PROMS/ReferencedObjects/Exe/RefObj/ROEditor/AboutROEditor.Designer.cs b/PROMS/ReferencedObjects/Exe/RefObj/ROEditor/AboutROEditor.Designer.cs index 98d097b7..45015e4f 100644 --- a/PROMS/ReferencedObjects/Exe/RefObj/ROEditor/AboutROEditor.Designer.cs +++ b/PROMS/ReferencedObjects/Exe/RefObj/ROEditor/AboutROEditor.Designer.cs @@ -135,8 +135,8 @@ namespace ROEditor this.textBoxDescription.TabIndex = 23; this.textBoxDescription.TabStop = false; this.textBoxDescription.Text = "Thank you for choosing PROMS for your procedure maintenance solution.\r\n\r\nPROMS is" + - " protected under the copyright laws.\r\n\r\nPlease refer the the End User Licence Ag" + - "reement (EULA) for the terms of use.\r\n"; + " protected under the copyright laws.\r\n\r\nPlease refer the the End User Licence Ag" + + "reement (EULA) for the terms of use.\r\n"; // // panel1 // @@ -196,7 +196,6 @@ namespace ROEditor this.labelServer.TabIndex = 3; this.labelServer.Text = "SQL Server Name"; this.labelServer.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; - this.labelServer.Visible = false; // // labelDatabase // @@ -210,7 +209,6 @@ namespace ROEditor this.labelDatabase.TabIndex = 2; this.labelDatabase.Text = "Database Name"; this.labelDatabase.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; - this.labelDatabase.Visible = false; // // panel4 // diff --git a/PROMS/ReferencedObjects/Exe/RefObj/ROEditor/AboutROEditor.cs b/PROMS/ReferencedObjects/Exe/RefObj/ROEditor/AboutROEditor.cs index ec1f1b9b..b309dcde 100644 --- a/PROMS/ReferencedObjects/Exe/RefObj/ROEditor/AboutROEditor.cs +++ b/PROMS/ReferencedObjects/Exe/RefObj/ROEditor/AboutROEditor.cs @@ -4,12 +4,13 @@ using System.ComponentModel; using System.Drawing; using System.Windows.Forms; using System.Reflection; +using RODBInterface; namespace ROEditor { partial class AboutROEditor : Form { - public AboutROEditor() + public AboutROEditor(RODB myrodb) { InitializeComponent(); @@ -45,8 +46,8 @@ namespace ROEditor // this.textBoxDescription.Text = AssemblyDescription; this.labelCompanyName.Links[0].LinkData = "Volian Enterprises Inc."; this.labelCompanyName.Links.Add(0,23,"www.volian.com"); - //this.labelServer.Text = string.Format("SQL Server: {0}", server); - //this.labelDatabase.Text = string.Format("Database: {0}", databaseName); + this.labelServer.Text = myrodb.RODB_GetDBServerForAbout();//string.Format("SQL Server: {0}", server); + this.labelDatabase.Text = myrodb.RODB_GetDBNameForAbout(); //string.Format("Database: {0}", databaseName); } diff --git a/PROMS/ReferencedObjects/Exe/RefObj/ROEditor/AboutROEditor.resx b/PROMS/ReferencedObjects/Exe/RefObj/ROEditor/AboutROEditor.resx index 19dc0dd8..d58980a3 100644 --- a/PROMS/ReferencedObjects/Exe/RefObj/ROEditor/AboutROEditor.resx +++ b/PROMS/ReferencedObjects/Exe/RefObj/ROEditor/AboutROEditor.resx @@ -112,9 +112,9 @@ 2.0 - System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 \ No newline at end of file diff --git a/PROMS/ReferencedObjects/Exe/RefObj/ROEditor/FixRev.Bat b/PROMS/ReferencedObjects/Exe/RefObj/ROEditor/FixRev.Bat index 81176489..9c9e1721 100644 --- a/PROMS/ReferencedObjects/Exe/RefObj/ROEditor/FixRev.Bat +++ b/PROMS/ReferencedObjects/Exe/RefObj/ROEditor/FixRev.Bat @@ -1,4 +1,4 @@ PUSHD ..\..\..\ReferencedObjects\Exe\RefObj\ROEditor" "..\..\..\..\AdjustBuildRevision\bin\Debug\AdjustBuildRevision" "%CD%\AssemblyInfo.cs" POPD -pause +pause \ No newline at end of file diff --git a/PROMS/ReferencedObjects/Exe/RefObj/ROEditor/GroupDefFrm.cs b/PROMS/ReferencedObjects/Exe/RefObj/ROEditor/GroupDefFrm.cs index c11c8784..4dea6f10 100644 --- a/PROMS/ReferencedObjects/Exe/RefObj/ROEditor/GroupDefFrm.cs +++ b/PROMS/ReferencedObjects/Exe/RefObj/ROEditor/GroupDefFrm.cs @@ -553,7 +553,7 @@ namespace ROEditor ArrayList AvailList, InUseList; //first see if it is a valid 'InUse' Field. AvailList = myrodb.RODB_GetFields(elem, (uint) RecordType.Schema); - InUseList = myrodb.RODB_GetFieldsInUse(elem, AvailList,"FieldsInUse", ref dummy, true); + InUseList = myrodb.RODB_GetFieldsInUse(elem, AvailList,"FieldsInUse", ref dummy, false); int chkbracketo, chkbracketc; // open & close bracket indexes chkbracketo = this.tbValue.Text.IndexOf("<"); chkbracketc = this.tbValue.Text.IndexOf(">"); diff --git a/PROMS/ReferencedObjects/Exe/RefObj/ROEditor/RODefFrm.cs b/PROMS/ReferencedObjects/Exe/RefObj/ROEditor/RODefFrm.cs index 256f4cb7..68cd7a17 100644 --- a/PROMS/ReferencedObjects/Exe/RefObj/ROEditor/RODefFrm.cs +++ b/PROMS/ReferencedObjects/Exe/RefObj/ROEditor/RODefFrm.cs @@ -202,8 +202,11 @@ namespace ROEditor ROField rof; // Get list of available fields (all fields in this type, i.e. rectype = 'Schema' // or 'GroupSchema') and get list of inuse from the schema definition. - AvailList = myrodb.RODB_GetFields(elem, editlevel); - InUseList = myrodb.RODB_GetFieldsInUse(elem, AvailList, strFieldsInUse, ref origFieldsInUse, true); + ArrayList tmp = myrodb.RODB_GetFields(elem, editlevel); + // put the items in the AvailList box. + if (AvailList == null) AvailList = new ArrayList(); + for (int i=0; i< tmp.Count; i++) AvailList.Add(tmp[i]); // don't modify the list returned from RODB_GetFields since it is part of dictionary + InUseList = myrodb.RODB_GetFieldsInUse(elem, AvailList, strFieldsInUse, ref origFieldsInUse, false); FillInAvailable(); // set up the listbox for inuse items. diff --git a/PROMS/ReferencedObjects/Exe/RefObj/ROEditor/ROEditor.cs b/PROMS/ReferencedObjects/Exe/RefObj/ROEditor/ROEditor.cs index 7aabce27..6f2d916f 100644 --- a/PROMS/ReferencedObjects/Exe/RefObj/ROEditor/ROEditor.cs +++ b/PROMS/ReferencedObjects/Exe/RefObj/ROEditor/ROEditor.cs @@ -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. diff --git a/PROMS/ReferencedObjects/LibSource/DBEncapsulation/DBEncap.cs b/PROMS/ReferencedObjects/LibSource/DBEncapsulation/DBEncap.cs index 0750be45..4c34f441 100644 --- a/PROMS/ReferencedObjects/LibSource/DBEncapsulation/DBEncap.cs +++ b/PROMS/ReferencedObjects/LibSource/DBEncapsulation/DBEncap.cs @@ -36,6 +36,7 @@ using System; using System.Data; using System.Data.OleDb; using Microsoft.Data.Odbc; +using System.Data.SqlClient; namespace DBEncapsulation { @@ -202,4 +203,62 @@ namespace DBEncapsulation myCommand.ExecuteNonQuery(); } } + // C2017-003: support for sql server + public class SQLEncap : DBEncapsulate + { + public SqlConnection mySqlConnection; + SqlCommand myCommand; + SqlDataReader myReader; + public override void Connection(string strconnect) + { + mySqlConnection = new SqlConnection(strconnect); + } + public override void OpenConnection() + { + mySqlConnection.Open(); + } + public override void CloseConnection() + { + mySqlConnection.Close(); + } + public override void Command(string strCommand) + { + myCommand = new SqlCommand(strCommand, mySqlConnection); + } + public override void CommandDispose() + { + myCommand.Dispose(); + } + public override bool Reader() + { + myReader = myCommand.ExecuteReader(); + if (myReader == null) + return false; + else + return true; + } + public override void ReaderClose() + { + myReader.Close(); + } + public override bool Read() + { + return (myReader.Read()); + } + public override string GetString(int num) + { + if (myReader.IsDBNull(num) == false) + return (myReader.GetString(num)); + else + return null; + } + public override int GetInt32(int num) + { + return (myReader.GetInt32(num)); + } + public override void NonQuery() + { + myCommand.ExecuteNonQuery(); + } + } }