diff --git a/PROMS/DataLoader/PROMSFixes.Sql b/PROMS/DataLoader/PROMSFixes.Sql
index 796d1ab9..282954d7 100644
--- a/PROMS/DataLoader/PROMSFixes.Sql
+++ b/PROMS/DataLoader/PROMSFixes.Sql
@@ -15511,8 +15511,8 @@ BEGIN TRY -- Try Block
set nocount on
DECLARE @RevDate varchar(255)
DECLARE @RevDescription varchar(255)
- set @RevDate = '12/13/2019 7:00 AM'
- set @RevDescription = 'Procedure number length when adding procedures'
+ set @RevDate = '01/09/2020 11:00 AM'
+ set @RevDescription = 'Referenced Object data in sql server'
Select cast(@RevDate as datetime) RevDate, @RevDescription RevDescription
PRINT 'SQL Code Revision ' + @RevDate + ' - ' + @RevDescription
IF( @@TRANCOUNT > 0 ) COMMIT
diff --git a/PROMS/ReferencedObjects/LibSource/RODBInterface/InputBox.cs b/PROMS/ReferencedObjects/LibSource/RODBInterface/InputBox.cs
new file mode 100644
index 00000000..be27e33d
--- /dev/null
+++ b/PROMS/ReferencedObjects/LibSource/RODBInterface/InputBox.cs
@@ -0,0 +1,42 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Data;
+using System.Drawing;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Forms;
+
+namespace RODBInterface
+{
+ public partial class InputBox : Form
+ {
+ private string _ResultConnectString = null;
+
+ public string ResultConnectString
+ {
+ get { return _ResultConnectString; }
+ set { _ResultConnectString = value; }
+ }
+ public InputBox(string constring)
+ {
+ InitializeComponent();
+ this.tbSqlConnectString.Text = constring;
+ }
+
+ private void btnTestConnect_Click(object sender, EventArgs e)
+ {
+ bool canConnect = SqlRODB.TestConnect(this.tbSqlConnectString.Text);
+ if (!canConnect)
+ MessageBox.Show("Connection failed.", "Connection Failed");
+ else
+ MessageBox.Show("You have been successfully connected to the database!", "Connection Succeeded");
+ }
+
+ private void btnOk_Click(object sender, EventArgs e)
+ {
+ ResultConnectString = this.tbSqlConnectString.Text;
+ }
+ }
+}
diff --git a/PROMS/ReferencedObjects/LibSource/RODBInterface/InputBox.designer.cs b/PROMS/ReferencedObjects/LibSource/RODBInterface/InputBox.designer.cs
new file mode 100644
index 00000000..ace9b49c
--- /dev/null
+++ b/PROMS/ReferencedObjects/LibSource/RODBInterface/InputBox.designer.cs
@@ -0,0 +1,111 @@
+namespace RODBInterface
+{
+ partial class InputBox
+ {
+ ///
+ /// Required designer variable.
+ ///
+ private System.ComponentModel.IContainer components = null;
+
+ ///
+ /// Clean up any resources being used.
+ ///
+ /// true if managed resources should be disposed; otherwise, false.
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing && (components != null))
+ {
+ components.Dispose();
+ }
+ base.Dispose(disposing);
+ }
+
+ #region Windows Form Designer generated code
+
+ ///
+ /// Required method for Designer support - do not modify
+ /// the contents of this method with the code editor.
+ ///
+ private void InitializeComponent()
+ {
+ this.lblSqlConnectString = new System.Windows.Forms.Label();
+ this.tbSqlConnectString = new System.Windows.Forms.TextBox();
+ this.btnTestConnect = new System.Windows.Forms.Button();
+ this.btnOk = new System.Windows.Forms.Button();
+ this.btnCancel = new System.Windows.Forms.Button();
+ this.SuspendLayout();
+ //
+ // lblSqlConnectString
+ //
+ this.lblSqlConnectString.AutoSize = true;
+ this.lblSqlConnectString.BackColor = System.Drawing.Color.Transparent;
+ this.lblSqlConnectString.Location = new System.Drawing.Point(12, 18);
+ this.lblSqlConnectString.Name = "lblSqlConnectString";
+ this.lblSqlConnectString.Size = new System.Drawing.Size(144, 17);
+ this.lblSqlConnectString.TabIndex = 4;
+ this.lblSqlConnectString.Text = "Sql Connection String";
+ //
+ // tbSqlConnectString
+ //
+ this.tbSqlConnectString.Location = new System.Drawing.Point(29, 49);
+ this.tbSqlConnectString.Name = "tbSqlConnectString";
+ this.tbSqlConnectString.Size = new System.Drawing.Size(620, 22);
+ this.tbSqlConnectString.TabIndex = 5;
+ //
+ // btnTestConnect
+ //
+ this.btnTestConnect.Location = new System.Drawing.Point(300, 93);
+ this.btnTestConnect.Name = "btnTestConnect";
+ this.btnTestConnect.Size = new System.Drawing.Size(75, 42);
+ this.btnTestConnect.TabIndex = 6;
+ this.btnTestConnect.Text = "Test Connect";
+ this.btnTestConnect.UseVisualStyleBackColor = true;
+ this.btnTestConnect.Click += new System.EventHandler(this.btnTestConnect_Click);
+ //
+ // btnOk
+ //
+ this.btnOk.DialogResult = System.Windows.Forms.DialogResult.OK;
+ this.btnOk.Location = new System.Drawing.Point(435, 103);
+ this.btnOk.Name = "btnOk";
+ this.btnOk.Size = new System.Drawing.Size(75, 23);
+ this.btnOk.TabIndex = 7;
+ this.btnOk.Text = "OK";
+ this.btnOk.UseVisualStyleBackColor = true;
+ this.btnOk.Click += new System.EventHandler(this.btnOk_Click);
+ //
+ // btnCancel
+ //
+ this.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
+ this.btnCancel.Location = new System.Drawing.Point(571, 103);
+ this.btnCancel.Name = "btnCancel";
+ this.btnCancel.Size = new System.Drawing.Size(75, 23);
+ this.btnCancel.TabIndex = 8;
+ this.btnCancel.Text = "Cancel";
+ this.btnCancel.UseVisualStyleBackColor = true;
+ //
+ // InputBox
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.ClientSize = new System.Drawing.Size(691, 157);
+ this.Controls.Add(this.btnCancel);
+ this.Controls.Add(this.btnOk);
+ this.Controls.Add(this.btnTestConnect);
+ this.Controls.Add(this.lblSqlConnectString);
+ this.Controls.Add(this.tbSqlConnectString);
+ this.Name = "InputBox";
+ this.Text = "Sql Connection String";
+ this.ResumeLayout(false);
+ this.PerformLayout();
+
+ }
+
+ #endregion
+
+ private System.Windows.Forms.Label lblSqlConnectString;
+ private System.Windows.Forms.TextBox tbSqlConnectString;
+ private System.Windows.Forms.Button btnTestConnect;
+ private System.Windows.Forms.Button btnOk;
+ private System.Windows.Forms.Button btnCancel;
+ }
+}
\ No newline at end of file
diff --git a/PROMS/ReferencedObjects/LibSource/RODBInterface/InputBox.resx b/PROMS/ReferencedObjects/LibSource/RODBInterface/InputBox.resx
new file mode 100644
index 00000000..1af7de15
--- /dev/null
+++ b/PROMS/ReferencedObjects/LibSource/RODBInterface/InputBox.resx
@@ -0,0 +1,120 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ text/microsoft-resx
+
+
+ 2.0
+
+
+ System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.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/LibSource/RODBInterface/RODBInterface.cs b/PROMS/ReferencedObjects/LibSource/RODBInterface/RODBInterface.cs
index ac644ff6..0317c0b2 100644
--- a/PROMS/ReferencedObjects/LibSource/RODBInterface/RODBInterface.cs
+++ b/PROMS/ReferencedObjects/LibSource/RODBInterface/RODBInterface.cs
@@ -259,164 +259,110 @@ using System.Windows.Forms;
using DBEncapsulation;
using ROFields;
using VlnStatus;
-//using IniFileIO;
using System.Collections.Specialized;
using Org.Mentalis.Files;
-//using VlnProfiler; //don't forget to add VlnProfiler to the reference list
+using System.Data.SqlClient;
+using System.Collections.Generic;
namespace RODBInterface
{
///
/// Summary description for Class1
///
- public enum RecordType: uint
+ public enum RecordType : uint
{
- Master=0, SubDatabase=1, Schema=2, Group=3, GroupSchema=4, RRO=5, SchemaStart=6, SchemaEnd=7
+ Master = 0, SubDatabase = 1, Schema = 2, Group = 3, GroupSchema = 4, RRO = 5, SchemaStart = 6, SchemaEnd = 7, ConvertedToSql = 8
}
///
/// The following class handles generation of sql strings to get/put requested parts of
/// XML RO Tree. And performs the database access using the VLN_DB class.
///
- public class RODB
+ public abstract partial class RODB
{
- DBEncapsulation.DBEncapsulate DBE;
- DBEncapsulation.OLEDB_DBEncap DBE_OLEDB;
-// DBEncapsulation.ODBC_DBEncap DBE_ODBC;
+ #region Properties
+ public DBEncapsulation.DBEncapsulate DBE;
- private VlnXmlDocument ROXml;
- private string schemastart;
- private string schemaend;
- private string lastTable="";
- private HybridDictionary dicFldTypes;
-
-// private string strAccOLEDBconn = "";
-// private string strSQLOLEDBconn = "";
-// private string strAccODBCconn = "";
-// private string strodbcConn = "";
+ public VlnXmlDocument ROXml;
+ public string schemastart;
+ public string schemaend;
+ public string lastTable = "";
+ public HybridDictionary dicFldTypes;
+ public string RODirectoryPath;
+ public int dbProviderType = 0;
+ public string strDatabaseConnectionCommand;
- private string strDatabaseConnectionCommand;
-
-// int dbConnectionType = 0; // we are only doing OLE-DB
- int dbProviderType = 0;
- string dbServerPath="";
- string dbServerUserName="";
- string dbServerPassword="";
+ public string dbServerPath = "";
+ public string dbServerUserName = "";
+ public string dbServerPassword = "";
+ public enum DB_PROVIDER { ACCESS, SQL_SERVER, ORACLE };
+ private string _MyDBID;
+ public string MyDBID
+ {
+ get { return _MyDBID; }
+ set { _MyDBID = value; }
+ }
+ private string _MyRecID;
+ public string MyRecID
+ {
+ get { return _MyRecID; }
+ set { _MyRecID = value; }
+ }
+ private bool _OnlyConnectOnce=false;
+ public bool OnlyConnectOnce
+ {
+ get { return _OnlyConnectOnce; }
+ set { _OnlyConnectOnce = value; }
+ }
+ #endregion
+ #region abstracts // need these for each method that must be defined for each database type
+ public abstract string RODB_GetNextGroupTable();
+ public abstract string RODB_GetNextRecId(string table);
+ public abstract bool RODB_GetRootGroups(VlnXmlElement root);
+ public abstract bool RODB_DeleteGroup(XmlNode group, string tbname, string toprecid);
+ public abstract bool RODB_DeleteRO(XmlNode group);
+ public abstract bool RODB_WriteGroup(XmlNode group, VlnXmlElement master);
+ public abstract bool RODB_InsertGroup(VlnXmlElement group);
+ public abstract string RODB_AddNewTable(string TblName, string newgrpname);
+ public abstract bool RODB_CopyFieldDefs(string fromtb, string totb, int type);
+ public abstract bool RODB_GetGroupAndSubgroups(VlnXmlElement node, StringBuilder sb);
+ public abstract bool RODB_GetChildData(VlnXmlElement node, bool CheckChildCount);
+ public abstract bool IsDuplicateAccPageID(VlnXmlElement ro, string newacc);
+ public abstract VlnXmlElement RODB_ReadRO(string tbl, string recid);
+ public abstract bool RODB_WriteRO(VlnXmlElement ro);
+ public abstract bool RODB_InsertRO(VlnXmlElement ro);
+ public abstract ushort RODB_GetFieldType(VlnXmlElement elem, string TableName, string Fld);
+ public abstract ArrayList RODB_GetFields(VlnXmlElement elem, uint rtype);
+ public abstract string RODB_GetSchemaPiece(string Recid, string table);
+ public abstract bool RODB_NewSchemaPiece(string recid, string parentid, string table, string schpiece, uint rtype);
+ public abstract bool RODB_WriteSchemaPiece(string Recid, string table, string schpiece);
+ public abstract bool RODB_ProcessRROFieldChange(VlnXmlElement child, string oldname, string newname, uint editlevel, VlnStatusMessage StatMsgWindow, bool combofield);
+ public abstract bool RODB_UpdateFieldRecord(ROField myrof, VlnXmlElement myelem, string strschema,
+ string oldname, string newname, uint editlevel, bool combofield);
+ public abstract XmlSchema RODB_GetGroupSchema(VlnXmlElement elem);
+ public abstract XmlSchema RODB_GetSchema(VlnXmlElement elem);
+ public abstract int RODB_GetNumberOfROValueRecords(string tablename);
+ public abstract int RODB_GetNumberOfGroupRecords(string tablename);
+ public abstract string RODB_GetDBNameForAbout();
+ public abstract string RODB_GetDBServerForAbout();
+ public abstract string RODB_HasBeenConverted();
+ public abstract bool RODB_WriteSqlConnectToAccess(string newConectStr);
+ #endregion
-// private enum CONNTYPE {OLEDB, ODBC};
- private enum DB_PROVIDER {ACCESS,SQL_SERVER,ORACLE};
+ public RODB()
+ {
-// public RODB(int conntype, string connectstring)
- public RODB(string RODirectoyPath)
- {
- // Setup the connection string
- //if (RODirectoyPath.Equals(""))
- // GetConnectionStringFromFile();
- //else
- BuildConnectionString(RODirectoyPath);
-
- // Initialize the connection depending on OLE-DB or ODBC:
-// conntype = 2; // ODBC: 1; // OLE-DB: 2 need to define this programmatically
- //END OF TEMPORARY
-
- // Either use an OLE-DB or ODBC connection, depending on what was passed in.
-//**** We are only doing OLE-DB
-// if ( dbConnectionType == (int)CONNTYPE.ODBC) // ODBC
-// {
-// DBE_ODBC = new ODBC_DBEncap();
-// DBE = DBE_ODBC;
-// }
-// else // OLE-DB
-// {
- DBE_OLEDB = new OLEDB_DBEncap();
- DBE = DBE_OLEDB;
-// }
-
- try
- {
-// DBE.Connection(strAccOLEDBconn);
- //DBE.Connection(strodbcConn);
- //SQL:
-// DBE.Connection(strSQLOLEDBconn);
- DBE.Connection(strDatabaseConnectionCommand);
- }
- catch (Exception e)
- {
- MessageBox.Show(e.Message,"Setup of OLEDB/ODBC");
- }
}
-
-
-// public void GetConnectionStringFromFile()
-// {
-// /* This file should contain the connection strings in the followin order:
-// * AccOLEDBconn, SQLOLEDBconn, AccODBCconn, odbcConn.
-// */
-// // append "ConnectList.txt" to the path of the location of the exe being run
-// // for example: VE-PROMS.NET\BIN or BIN\DEBUG
-// // This set in Visual Studio .NET in the properties dialog of the project, select
-// // Configuration Properties. You will see an option call Output Path.
-// string FileName = Application.StartupPath + "\\ConnectList.txt";
-//
-// if (!File.Exists(FileName))
-// {
-// // File does not exist
-// MessageBox.Show("Could not find ConnectList.txt file");
-// return;
-// }
-//
-// /*
-// * Open the text file for reading
-// */
-// StreamReader sr = File.OpenText(FileName);
-//
-// /*
-// * Connection string to MS-access use with oledb directly
-// */
-// strAccOLEDBconn = sr.ReadLine();
-//
-// /*
-// * connection string to SQL-server use with oledb
-// */
-// strSQLOLEDBconn = sr.ReadLine();
-//
-// /*
-// * connection string to for oledb to odbc dsn
-// */
-// strAccODBCconn = sr.ReadLine();
-//
-// /*
-// * ODBC connection:
-// * ACCESS:
-// */
-// strodbcConn = sr.ReadLine();
-//
-// sr.Close(); // close ConnectList.txt
-//
-// }
+ #region GeneralDB
+
- private void GetDbServerInfo(string ROdir)
+ public void GetDbServerInfo(string ROdir)
{
-// string strConnectionType;
string strServerProvider;
string ROiniPath = ROdir + "\\ROAPP.INI";
-
- //**** For now we are only doing OLE-DB
- //****
- // Get the database connection type
-// strConnectionType = TheIniFile.GetINIKeyValueStr("Database Server","Connection Type","OLEDB",10,ROiniPath);
-// strConnectionType = strConnectionType.ToUpper();
-// if (strConnectionType.Equals("OLEDB"))
-// dbConnectionType = (int)CONNTYPE.OLEDB;
-// else if (strConnectionType.Equals("ODBC"))
-// {
-// dbConnectionType = (int)CONNTYPE.ODBC;
-// dbODBC_DNS = TheIniFile.GetINIKeyValueStr("Database Server","DNS","",10,ROiniPath);
-// }
-
// Get the database Provider name - default to Access
IniReader in1 = new IniReader(ROiniPath);
- strServerProvider = in1.ReadString("Database Server","Driver","ACCESS");
+ strServerProvider = in1.ReadString("Database Server", "Driver", "ACCESS");
strServerProvider = strServerProvider.ToUpper();
if (strServerProvider.Equals("SQL SERVER"))
dbProviderType = (int)DB_PROVIDER.SQL_SERVER;
@@ -434,101 +380,607 @@ namespace RODBInterface
if (dbServerUserName.Equals(""))
dbServerUserName = "Admin"; // default user name for Access
}
- else if (dbServerUserName.Equals("") || (dbServerUserName.Length>0 && dbServerPassword.Equals("")))
+ //else if (dbServerUserName.Equals("") || (dbServerUserName.Length > 0 && dbServerPassword.Equals("")))
+ //{
+ // userpass pwdlg = new userpass(dbServerUserName);
+ // // If using SQL Server or Oracle
+ // // prompt for a user name and password.
+ // pwdlg.Text = strServerProvider + pwdlg.Text;
+ // if (pwdlg.ShowDialog() == DialogResult.OK)
+ // {
+ // dbServerUserName = pwdlg.uname;
+ // dbServerPassword = pwdlg.pword;
+ // }
+ // else
+ // {
+ // dbServerUserName = "";
+ // dbServerPassword = "";
+ // }
+ //}
+ }
+ public void BuildConnectionString(string ropath, string DataConnectionPath)
+ {
+ GetDbServerInfo(ropath);
+ if (!dbProviderType.Equals((int)DB_PROVIDER.SQL_SERVER))
{
- userpass pwdlg = new userpass(dbServerUserName);
- // If using SQL Server or Oracle
- // prompt for a user name and password.
- pwdlg.Text = strServerProvider + pwdlg.Text;
- if (pwdlg.ShowDialog() == DialogResult.OK)
+ strDatabaseConnectionCommand = "Provider=Microsoft.Jet.OLEDB.4.0;Password=\"\";User ID=Admin;Data Source=" + DataConnectionPath + "\\ROMaster.mdb;Mode=Share Deny None;Extended Properties=\"\";Jet OLEDB:System database=\"\";Jet OLEDB:Registry Path=\"\";Jet OLEDB:Database Password=\"\";Jet OLEDB:Engine Type=5;Jet OLEDB:Database Locking Mode=1;Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Global Bulk Transactions=1;Jet OLEDB:New Database Password=\"\";Jet OLEDB:Create System Database=False;Jet OLEDB:Encrypt Database=False;Jet OLEDB:Don't Copy Locale on Compact=False;Jet OLEDB:Compact Without Replica Repair=False;Jet OLEDB:SFP=False";
+ }
+ }
+ #endregion
+ #region XML
+ public VlnXmlDocument RODB_GetRoot()
+ {
+ // Create an xmldoc and initialize it with a root node
+ ROXml = new VlnXmlDocument();
+ XmlNode elem = ROXml.CreateNode(XmlNodeType.Element, "RO_Root", "");
+ ROXml.AppendChild(elem);
+ return ROXml;
+ }
+ public string ParseEleName(string info)
+ {
+ string elemname;
+
+ // need to find element type too.
+ int issingle = info.IndexOf("Single");
+
+ int idx1 = info.IndexOf("element name=");
+ if (idx1 > 0)
+ {
+ elemname = info.Substring(idx1 + 14, info.Length - idx1 - 14);
+ idx1 = elemname.IndexOf("\"");
+ elemname = CvtFldToUserFld(elemname.Substring(0, idx1));
+ // if we have a choice element, remove the last character (it was added to the
+ // field names in order to allow for unique fields names for the choice items.
+ if (info.IndexOf("xsd:choice") > 0)
{
- dbServerUserName = pwdlg.uname;
- dbServerPassword = pwdlg.pword;
+ string trun = elemname.Remove((elemname.Length) - 1, 1);
+ return trun;
+ }
+ return elemname;
+ }
+ return null;
+ }
+ // Given an element to start at, get the fields in use. Pass in the element you're
+ // on, the available list for this group & a string representing 'FieldsInUse' or
+ // 'GroupFieldsInUse'.
+ public ArrayList RODB_GetFieldsInUse(VlnXmlElement elem, ArrayList avail, string strFieldsInUse, ref string origFieldsInUse, bool RemoveFromAvailList)
+ {
+ VlnXmlElement startelem = elem;
+
+ // if this element doesn't have any fields in use, walk up the tree until
+ // we find them.
+ string FieldsInUse = "";
+ if (startelem.HasAttribute(strFieldsInUse) == false)
+ {
+ VlnXmlElement parent;
+ parent = (VlnXmlElement)startelem.ParentNode;
+ while (parent != null && FieldsInUse == "")
+ {
+ FieldsInUse = parent.GetAttribute(strFieldsInUse);
+ if (parent.Name != "RO_Root")
+ parent = (VlnXmlElement)parent.ParentNode;
+ else
+ parent = null;
+ }
+ }
+ else
+ FieldsInUse = startelem.GetAttribute(strFieldsInUse);
+
+ origFieldsInUse = FieldsInUse; // make a copy to compare to later.
+ ArrayList inuse = new ArrayList();
+ // if there are no fields in use (may be inserting a top group)
+ // return an empty list.
+ if (FieldsInUse == "") return inuse;
+ // Go through the FieldsInUse list and move elements from the avail list
+ // to the inuse list
+ int strpos = 0;
+ string recid;
+ recid = FieldsInUse.Substring(strpos, 8);
+ MyRecID = recid;
+ while (recid != null)
+ {
+ // find it in avail list. Remove it from there & add to inuse list
+ for (int i = 0; i < avail.Count; i++)
+ {
+ ROField rof = (ROField)avail[i];
+ string lrecid = rof.GetRecID;
+ if (lrecid == recid)
+ {
+ // remove it from avail list & add it to inuse list
+ ROField inuserof = new ROField(rof.GetFieldname, rof.GetRecID, rof.GetMasterRecID, rof.GetFieldType);
+ inuse.Add((object)inuserof);
+ if (RemoveFromAvailList)
+ avail.RemoveAt(i);
+ break;
+ }
+ }
+ strpos = strpos + 9;
+ if (strpos > FieldsInUse.Length)
+ recid = null;
+ else
+ {
+ recid = FieldsInUse.Substring(strpos, 8);
+ }
+ }
+ return inuse;
+ }
+ public string CvtUserFldToFld(string fldname)
+ {
+ if (fldname.Length < 2)
+ return fldname;
+ // a digit cannot start an xml fieldname, prepend a "__" to it.
+ string tmp0;
+ if (char.IsDigit(fldname, 0))
+ tmp0 = "__" + fldname;
+ else
+ tmp0 = fldname;
+ // an xml fieldname cannot have a space, change it to a "__"
+ string tmpstr = tmp0.Replace(" ", "__");
+ int len = tmpstr.Length;
+ int cnt = 0;
+
+ // this is also our sequence that tells us the follow 3 digits is the ascii number (base 10)
+ // of the character we replaced.
+ string OKpunch = "-._";
+
+ string outstr = "";
+ int decval;
+
+ while (cnt < len)
+ {
+ char tmpchr = tmpstr[cnt];
+ if (!char.IsLetterOrDigit(tmpchr) && (OKpunch.IndexOf(tmpchr) == -1))
+ {
+ decval = tmpchr;
+ outstr += OKpunch + decval.ToString("D3");
}
else
{
- dbServerUserName = "";
- dbServerPassword = "";
+ outstr += tmpchr.ToString();
}
+ cnt++;
}
+ return outstr;
}
-
- public void BuildConnectionString(string DataConnectionPath)
+ public string CvtFldToUserFld(string fldname)
{
- GetDbServerInfo(DataConnectionPath);
+ string tmpstr0;
+ if (fldname.Length < 2) return fldname;
+ // an xml element name cannot begin with a digit. we had prepended a "__"
+ if (fldname.Substring(0, 2) == "__" && char.IsDigit(fldname, 2))
+ tmpstr0 = fldname.Substring(2, fldname.Length - 2);
+ else
+ tmpstr0 = fldname;
+ // an xml element name cannot have a space, we converted to a "__"
+ string tmpstr = tmpstr0.Replace("__", " ");
+ int len = tmpstr.Length;
+ int cur = 0;
-// if (dbConnectionType.Equals(CONNTYPE.OLEDB))
-// {
- if (dbProviderType.Equals((int)DB_PROVIDER.SQL_SERVER))
+ // this is also our sequence that tells us the follow 3 digits is the ascii number (base 10)
+ // of the character we replaced.
+ string OKpunch = "-._";
+
+ string outstr = "";
+ int decval, indx;
+ if (tmpstr.Length < 6)
+ indx = -1;
+ else
+ indx = tmpstr.IndexOf(OKpunch, cur);
+ string asc_spchar;
+ while (indx >= 0)
{
- /*
- * Connect to SQL-server using OLEDB
- */
- // !!!!! do we need the Workstation ID? if so, we need to pass this in too!
- // - don't seem to need Workstation ID - jsj 1/6/04
-
- // strSQLOLEDBconn = "Provider=SQLOLEDB;Persist Security Info=False;User ID=sa;Initial Catalog=RO;Data Source=DELL-W2K-SERVER\\SQL2000;Use Procedure for Prepare=1;Auto Translate=True;Packet Size=4096;Workstation ID=KATHY;Use Encryption for Data=False;Tag with column collation when possible=False";
-
- // strDatabaseConnectionCommand = "Provider=SQLOLEDB;Persist Security Info=False;User ID="+dbServerUserName+";Password="+dbServerPassword+";Initial Catalog=RO;Data Source=" + dbServerPath + ";Use Procedure for Prepare=1;Auto Translate=True;Packet Size=4096;Use Encryption for Data=False;Tag with column collation when possible=False";
- strDatabaseConnectionCommand = "Provider=SQLOLEDB;Persist Security Info=False;User ID="+dbServerUserName+";Password="+dbServerPassword+";Initial Catalog=VEPROMS RO;Data Source="+dbServerPath+";Use Procedure for Prepare=1;Auto Translate=True;Packet Size=4096;Use Encryption for Data=False;Tag with column collation when possible=False";
+ outstr += tmpstr.Substring(cur, indx - cur);
+ asc_spchar = tmpstr.Substring(indx + 3, 3);
+ decval = System.Convert.ToInt16(asc_spchar, 10);
+ outstr += System.Convert.ToChar(decval).ToString();
+ cur = indx + 6;
+ if (cur + 6 > len)
+ indx = -1;
+ else
+ indx = tmpstr.IndexOf(OKpunch, cur);
}
- else if (dbProviderType.Equals((int)DB_PROVIDER.ORACLE))
+ if (cur < len) outstr += tmpstr.Substring(cur, len - cur);
+
+ return outstr;
+ }
+ // Process the given field type.
+ // return the type value used in the RO.FST file
+ public ushort GetFSTreturnType(ushort fldtype, string fldname, VlnXmlElement elem)
+ {
+ ushort rtnval = 0;
+ /*
+ * Here are the possible field types:
+ *
+ public enum FieldTypes: uint
+ {
+ Nil=0, SingleTxt=1, VariableTxt=2, FrmtSingleTxt=4, XYPlot=8, Table=10, Image=20,
+ MultiTxt=40, Combination=128, MultiFld=100
+ }
+ */
+ switch ((uint)fldtype)
{
- // Don't know if this connect string will work or not on Oracle
- // we need to test this with an Oracle Database Server
- // Note that this is the same connection string used for SQL Server
- // BUT the provider is different!
- strDatabaseConnectionCommand = "Provider=MSDAORA;Persist Security Info=False;User ID="+dbServerUserName+";Password="+dbServerPassword+";Initial Catalog=VEPROMS RO;Data Source="+dbServerPath+";Use Procedure for Prepare=1;Auto Translate=True;Packet Size=4096;Use Encryption for Data=False;Tag with column collation when possible=False";
+ case 1: // Fixed length text
+ case 2: // Variable length text
+ case 4: // formatted text
+ case 40: // Multi line text
+ rtnval = 1;
+ break;
+ case 10: // Table
+ rtnval = 2;
+ break;
+ case 8: // X/Y Plot
+ rtnval = 4;
+ break;
+ case 32: // image (intergrated graphics) - this is the HEX representation
+ rtnval = 8;
+ break;
+ }
+ return rtnval;
+ }
+ public string GenerateXmlString(XmlNode node, bool isgroup) // KBR not sure - see end of method
+ {
+ string retstr;
+ XmlTextWriter xmlTextWriter;
+ StringWriter strWriter = new StringWriter();
+ xmlTextWriter = new XmlTextWriter(strWriter);
+ VlnXmlElement enode;
+ XmlNode kid;
+ kid = node.FirstChild;
+ enode = (VlnXmlElement)node;
+
+ if (isgroup == true)
+ {
+ xmlTextWriter.WriteStartElement("vlnGroup");
+ if (enode.HasAttribute("RetVal"))
+ {
+ xmlTextWriter.WriteStartAttribute("RetVal", null);
+ xmlTextWriter.WriteString(enode.GetAttribute("RetVal"));
+ xmlTextWriter.WriteEndAttribute();
+ }
+ if (enode.HasAttribute("MenuItem"))
+ {
+ xmlTextWriter.WriteStartAttribute("MenuItem", null);
+ xmlTextWriter.WriteString(enode.GetAttribute("MenuItem"));
+ xmlTextWriter.WriteEndAttribute();
+ }
+ if (enode.HasAttribute("FieldsInUse"))
+ {
+ xmlTextWriter.WriteStartAttribute("FieldsInUse", null);
+ xmlTextWriter.WriteString(enode.GetAttribute("FieldsInUse"));
+ xmlTextWriter.WriteEndAttribute();
+ }
+ if (enode.HasAttribute("GroupMenuItem"))
+ {
+ xmlTextWriter.WriteStartAttribute("GroupMenuItem", null);
+ xmlTextWriter.WriteString(enode.GetAttribute("GroupMenuItem"));
+ xmlTextWriter.WriteEndAttribute();
+ }
+ if (enode.HasAttribute("GroupFieldsInUse"))
+ {
+ xmlTextWriter.WriteStartAttribute("GroupFieldsInUse", null);
+ xmlTextWriter.WriteString(enode.GetAttribute("GroupFieldsInUse"));
+ xmlTextWriter.WriteEndAttribute();
+ }
+ if (enode.HasAttribute("AccPageID"))
+ {
+ xmlTextWriter.WriteStartAttribute("AccPageID", null);
+ xmlTextWriter.WriteString(enode.GetAttribute("AccPageID"));
+ xmlTextWriter.WriteEndAttribute();
+ }
+ if (enode.HasAttribute("AccPageIDPrefix"))
+ {
+ xmlTextWriter.WriteStartAttribute("AccPageIDPrefix", null);
+ xmlTextWriter.WriteString(enode.GetAttribute("AccPageIDPrefix"));
+ xmlTextWriter.WriteEndAttribute();
+ }
+ xmlTextWriter.WriteStartAttribute("MenuTitle", null);
+ xmlTextWriter.WriteString(enode.GetAttribute("MenuTitle"));
+ xmlTextWriter.WriteEndAttribute();
+
+ while (kid != null)
+ {
+ if ((kid is XmlText) || (kid.ChildNodes.Count == 1 && kid.Name != "vlnGroup"))
+ kid.WriteTo(xmlTextWriter);
+ kid = kid.NextSibling;
+ }
}
else
{
- /*
- * Connect to MSAccess using OLEDB directly
- */
+ xmlTextWriter.WriteStartElement(node.Name);
- // strAccOLEDBconn = "Provider=Microsoft.Jet.OLEDB.4.0;Password=\"\";User ID=Admin;Data Source=I:\\RO Design\\RO\\ROMaster.mdb;Mode=Share Deny None;Extended Properties=\"\";Jet OLEDB:System database=\"\";Jet OLEDB:Registry Path=\"\";Jet OLEDB:Database Password=\"\";Jet OLEDB:Engine Type=5;Jet OLEDB:Database Locking Mode=1;Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Global Bulk Transactions=1;Jet OLEDB:New Database Password=\"\";Jet OLEDB:Create System Database=False;Jet OLEDB:Encrypt Database=False;Jet OLEDB:Don't Copy Locale on Compact=False;Jet OLEDB:Compact Without Replica Repair=False;Jet OLEDB:SFP=False";
+ xmlTextWriter.WriteStartAttribute("MenuTitle", null);
+ xmlTextWriter.WriteString(enode.GetAttribute("MenuTitle"));
+ xmlTextWriter.WriteEndAttribute();
- // strAccOLEDBconn = "Provider=Microsoft.Jet.OLEDB.4.0;Password=\"\";User ID=Admin;Data Source=" + DataConnectionPath +"\\ROMaster.mdb;Mode=Share Deny None;Extended Properties=\"\";Jet OLEDB:System database=\"\";Jet OLEDB:Registry Path=\"\";Jet OLEDB:Database Password=\"\";Jet OLEDB:Engine Type=5;Jet OLEDB:Database Locking Mode=1;Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Global Bulk Transactions=1;Jet OLEDB:New Database Password=\"\";Jet OLEDB:Create System Database=False;Jet OLEDB:Encrypt Database=False;Jet OLEDB:Don't Copy Locale on Compact=False;Jet OLEDB:Compact Without Replica Repair=False;Jet OLEDB:SFP=False";
- strDatabaseConnectionCommand = "Provider=Microsoft.Jet.OLEDB.4.0;Password=\"\";User ID=Admin;Data Source=" + DataConnectionPath +"\\ROMaster.mdb;Mode=Share Deny None;Extended Properties=\"\";Jet OLEDB:System database=\"\";Jet OLEDB:Registry Path=\"\";Jet OLEDB:Database Password=\"\";Jet OLEDB:Engine Type=5;Jet OLEDB:Database Locking Mode=1;Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Global Bulk Transactions=1;Jet OLEDB:New Database Password=\"\";Jet OLEDB:Create System Database=False;Jet OLEDB:Encrypt Database=False;Jet OLEDB:Don't Copy Locale on Compact=False;Jet OLEDB:Compact Without Replica Repair=False;Jet OLEDB:SFP=False";
+ while (kid != null)
+ {
+ kid.WriteTo(xmlTextWriter);
+ kid = kid.NextSibling;
+ }
}
-// }
-// else // ODBC connection
-// {
-// if (dbODBC_DNS.Length > 0)
-// {
-//
-// /*
-// * Connect to MSAccess using OLEDB and ODBC DSN
-// */
-//
-// // strAccODBCconn = "Provider=MSDASQL.1;Persist Security Info=False;Data Source=Access for RO;Extended Properties=\"DSN=Access for RO;DBQ=I:\\RO Design\\RO\\ROMaster.mdb;DriverId=25;FIL=MS Access;MaxBufferSize=2048;PageTimeout=5;\"";
-//
-// // strAccODBCconn = "Provider=MSDASQL.1;Persist Security Info=False;Data Source=Access for RO;Extended Properties=\"DSN=Access for RO;DBQ=" + DataConnectionPath + "\\ROMaster.mdb;DriverId=25;FIL=MS Access;MaxBufferSize=2048;PageTimeout=5;\"";
-// strDatabaseConnectionCommand = "Provider=MSDASQL.1;Persist Security Info=False;Data Source=Access for RO;Extended Properties=\"DSN=Access for RO;DBQ=" + DataConnectionPath + "\\ROMaster.mdb;DriverId=25;FIL=MS Access;MaxBufferSize=2048;PageTimeout=5;\"";
-// }
-//
-// /*
-// * Connection to MSAccess using an ODBC connection
-// */
-// // strodbcConn = "Driver={Microsoft Access Driver (*.mdb)};DBQ=i:\\Ro Design\\RO\\ROMaster.mdb";
-// strodbcConn = "Driver={Microsoft Access Driver (*.mdb)};DBQ=" + DataConnectionPath + "\\ROMaster.mdb";
-//
-// // Connection to SQL Server using an ODBC connection
-// //strodbcConn = "Driver={SQL Server};Server=DELL-W2K-SERVER\\SQL2000;UID=sa;Database=ROMaster";
-//
-// //SQL - DSN - worked: string strodbcConn = "DSN=SQL RO;UID=sa";
-// //Initial odbc tests on strodbcconn
-// }
+ xmlTextWriter.WriteEndElement(); // vlnGroup or top of RO.
+ xmlTextWriter.Flush();
+ xmlTextWriter.Close();
+
+ retstr = strWriter.ToString();
+
+ // replace the single quote because ODBC fails if it's in a string because
+ // the single quote represents the beg/end of string when sending string to
+ // ODBC.
+ retstr = retstr.Replace("\'", "'"); // KBR - not sure if this method should be in RODB class or db specific class
+ return (retstr);
+ }
+ // Create a new field record in master and reference in the current table.
+ // pass in current rodb object, the xml element creating and editlevel
+ // is a recordType of either Group (group field definitions) or rro for
+ // the ro definition. the string apd represents an append string which is
+ // appended to the fieldname for combo types, otherwise it's null
+ public bool RODB_NewFieldRecord(ROField myrof, VlnXmlElement myelem, string strschema, uint editlevel, string apd)
+ {
+ bool success;
+ // get a new record id for this and save it in the master table.
+ string mrecid = RODB_GetNextRecId("ROMaster");
+
+ // get recid in ROMaster for group, so that we can set the parent field.
+ // walk up the tree until we find a 'MasterRecID' attribute.
+ VlnXmlElement parent;
+ parent = myelem;
+ while (parent != null)
+ {
+ if (parent.HasAttribute("MasterRecID")) break;
+ parent = (VlnXmlElement)parent.ParentNode;
+ }
+ success = RODB_NewSchemaPiece(mrecid, parent.GetAttribute("MasterRecID"), "ROMaster", strschema, editlevel);
+ if (success != true) return false;
+ // also reference it from the local table.
+ string lrecid = RODB_GetNextRecId(myelem.GetAttribute("Table"));
+ myrof.SetRecID(lrecid);
+ myrof.SetMasterRecID(mrecid);
+ StringBuilder strbld = new StringBuilder();
+ strbld.Append(mrecid);
+ strbld.Append(" ");
+ string strtype = myrof.GetFieldType.ToString();
+ strbld.Append(strtype.PadLeft(3, '0'));
+ strbld.Append(" ");
+ strbld.Append(myrof.MakeFieldName(myrof.GetFieldname));
+ if (apd != null) strbld.Append(apd);
+ // Need ParentID field, get by looking up xml tree to find parentID attribute = "00000000", then
+ // use this recid.
+ parent = myelem;
+ while (parent.GetAttribute("ParentID") != "00000000")
+ {
+ parent = (VlnXmlElement)parent.ParentNode;
+ }
+ success = RODB_NewSchemaPiece(lrecid, parent.GetAttribute("RecID"), myelem.GetAttribute("Table"), strbld.ToString(), editlevel);
+ return success;
+ }
+ public string DoCmbFieldReplace(string repstring, string oname, string nname, string letter)
+ {
+ string cmboname, cmbnname;
+ cmboname = oname.Insert(oname.Length - 1, letter);
+ cmbnname = nname.Insert(nname.Length - 1, letter);
+ return (repstring.Replace(cmboname, cmbnname));
}
+ // RODB_UpdateNamesInROs: goes through subtree (top node is 'fld') and if this
+ // updated field is used (either in [Group]FieldsInUse or was used in parent, then
+ // 1) if group node, check for attributes using "" and if found, update
+ // to "
+ // 2) if group edit, modify this node's xml data with the new fieldname,
+ // otherwise, edit 'ROs' under this to replace with
+ // Input: VlnXmlElement fld: start processing at this node.
+ // string myrecid: local recid to be used for check to see if used (in FieldsInUse
+ // or GroupFieldsInUse.
+ // string oldname, newname - old and new field names
+ // string myrecid - local record storing field name
+ // uint editlevel - if editting groups, do check for for item 1 above in
+ // Group attributes, otherwise do in
+ // bool parentused - set to false from caller, this is recursive and will
+ // be set appropriately for recursive calls.
+ public bool RODB_UpdateFieldNames(VlnXmlElement fld, string myrecid, string oldname,
+ string newname, uint editlevel, bool parentused, VlnStatusMessage StatMsgWindow, bool combofield)
+ {
+ bool success;
+ bool useAtLevel = false;
+ XmlNode node;
+ VlnXmlElement child;
+ string fldinuse;
+
+ if (editlevel == (uint)RecordType.Schema)
+ fldinuse = "FieldsInUse";
+ else
+ fldinuse = "GroupFieldsInUse";
+
+ // Do the current level before walking through any children groups.
+ if (fld.Name == "vlnGroup")
+ {
+ if (fld.HasAttribute(fldinuse))
+ {
+ // if recid not in here, don't process for this node.
+ string fiu = fld.GetAttribute(fldinuse);
+ if (fiu.IndexOf(myrecid) >= 0) useAtLevel = true;
+ }
+ if (useAtLevel == true || parentused == true) useAtLevel = true;
+
+ if (useAtLevel == true)
+ {
+ string haskids, kidsloaded;
+ haskids = fld.GetAttribute("HasChild");
+ kidsloaded = fld.GetAttribute("ChildLoaded");
+ if (haskids == "True" && kidsloaded == "False")
+ {
+ success = RODB_GetChildData(fld, true);
+ if (success == false) return false;
+ fld.SetAttribute("ChildLoaded", "True");
+ }
+ parentused = true; // for kids of this group.
+
+ success = RODB_ProcessRROFieldChange(fld, oldname, newname, editlevel, StatMsgWindow, combofield);
+ if (success == false) return false;
+ }
+ }
+ node = (XmlNode)fld.FirstChild;
+ while (node != null)
+ {
+ if (node is VlnXmlElement)
+ {
+ useAtLevel = false;
+ child = (VlnXmlElement)node;
+
+ // If this is a group menu edit, process group nodes, by recursive
+ // call and then modify data on group record.
+ // For both, when hitting a group node, check that it either doesn't
+ // have 'FieldsInUse' or 'GroupFieldsInUse' or that if it does,
+ // this record id is in the list -> only process these, otherwise
+ // the field is not used.
+ if (child.Name == "vlnGroup")
+ {
+ // see if inuse for this one, either defined here or from parent.
+ if (child.HasAttribute(fldinuse))
+ {
+ // if recid not in here, don't process for this node. Still
+ // need to check children because they may redefine fields in use.
+ string fiu = child.GetAttribute(fldinuse);
+ if (fiu.IndexOf(myrecid) >= 0) useAtLevel = true;
+ }
+ if (useAtLevel == false && parentused == true) useAtLevel = true;
+
+ // update this record if it doesn't have it's own , then do kids
+ // of it.
+ success = RODB_UpdateFieldNames(child, myrecid, oldname, newname, editlevel, useAtLevel, StatMsgWindow, combofield);
+
+ if (success == false) return false;
+ }
+ }
+ node = node.NextSibling;
+ }
+ return true;
+ }
+ // check if the name entered is one used for setting up
+ // the new graphics or setpoint databases.
+ public bool RODB_CheckForStandardName(string oname)
+ {
+ string oldname = CvtFldToUserFld(oname);
+ if (oldname.CompareTo("Name") == 0) return true;
+ if (oldname.CompareTo("Image ID") == 0) return true;
+ if (oldname.CompareTo("Image") == 0) return true;
+ if (oldname.CompareTo("Setpoint ID") == 0) return true;
+ if (oldname.CompareTo("Setpoint Value") == 0) return true;
+ if (oldname.CompareTo("Associated System/Component") == 0) return true;
+ if (oldname.CompareTo("Applicability") == 0) return true;
+ if (oldname.CompareTo("Revision") == 0) return true;
+ if (oldname.CompareTo("Short Description") == 0) return true;
+ if (oldname.CompareTo("Description") == 0) return true;
+ if (oldname.CompareTo("Key Assumptions") == 0) return true;
+ if (oldname.CompareTo("Basis") == 0) return true;
+ if (oldname.CompareTo("References") == 0) return true;
+ if (oldname.CompareTo("Group") == 0) return true;
+ if (oldname.CompareTo("Parameter") == 0) return true;
+ return false;
+ }
+
+ #endregion
+ }
+ ///
+ /// The following class handles generation of sql strings to get/put requested parts of
+ /// XML RO Tree. And performs the database access using the VLN_DB class. This class is
+ /// to be used for MS Access
+ ///
+ public partial class AccessRODB : RODB
+ {
+ public DBEncapsulation.OLEDB_DBEncap DBE_OLEDB;
+ public AccessRODB(string rODirectoyPath)
+ {
+ RODirectoryPath = rODirectoyPath;
+ BuildConnectionString(rODirectoyPath, rODirectoyPath);
+ DBE_OLEDB = new OLEDB_DBEncap();
+ DBE = DBE_OLEDB;
+
+ try
+ {
+ DBE.Connection(strDatabaseConnectionCommand);
+ }
+ catch (Exception e)
+ {
+ MessageBox.Show(e.Message, "Setup of OLEDB/ODBC");
+ }
+ }
+ public override string RODB_GetDBNameForAbout()
+ {
+ return ("Database: RoMaster");
+ }
+ public override string RODB_GetDBServerForAbout()
+ {
+ return ("Microsoft Access");
+ }
+ public override string RODB_HasBeenConverted()
+ {
+ try
+ {
+ DBE.OpenConnection();
+ }
+ catch (Exception e)
+ {
+ MessageBox.Show(e.Message, "Could not open database connection");
+ // MessageBox.Show(e.StackTrace,"Debug");
+ return null;
+ }
+ string constring = null;
+ string strHasBeen = "SELECT Info FROM ROMaster where RecType=" + (uint)RecordType.ConvertedToSql;
+ try
+ {
+ DBE.Command(strHasBeen);
+ DBE.Reader();
+ if (DBE.Read())
+ {
+ constring = DBE.GetString(0);
+ DBE.ReaderClose();
+ DBE.CommandDispose();
+ }
+ }
+ catch (Exception ex)
+ {
+ }
+ DBE.CloseConnection();
+ return constring;
+ }
+ public override bool RODB_WriteSqlConnectToAccess(string newConectStr)
+ {
+ //try
+ //{
+ // DBE.OpenConnection();
+ //}
+ //catch (Exception e)
+ //{
+ // MessageBox.Show(e.Message, "Could not open database connection");
+ // // MessageBox.Show(e.StackTrace,"Debug");
+ // return false;
+ //}
+ string dt = string.Format("{0:yyyyMMddHHmmss}", System.DateTime.Now);
+ string strUpdate = "UPDATE ROMaster SET Info = '" + newConectStr + "'";
+ // note that '8' for rectype flags database converted:
+ strUpdate = strUpdate + ", ModDateTime = '" + dt + "' WHERE RecType=" + (uint)RecordType.ConvertedToSql;
+ try
+ {
+ DBE.Command(strUpdate);
+ DBE.Reader();
+ DBE.ReaderClose();
+ DBE.CommandDispose();
+ }
+ catch (Exception ex)
+ {
+ return false;
+ }
+ return true;
+ }
// get the next table name & update it to the next possible.
- public string RODB_GetNextGroupTable()
+ public override string RODB_GetNextGroupTable()
{
// read record type of master for this table. This is where the highest recid is stored.
// Update the recid by 1, write it out and return the new recid.
string strGetNxt = "SELECT Info FROM ROMaster where RecID = '00000001' and RecType=" + (uint)RecordType.Master;
- string rettable=null;
+ string rettable = null;
try
{
DBE.Command(strGetNxt);
@@ -536,8 +988,8 @@ namespace RODBInterface
if (DBE.Read())
{
rettable = DBE.GetString(0);
- string nxttable = rettable.Substring(2,6);
- int ltbl = System.Convert.ToInt32(nxttable,10);
+ string nxttable = rettable.Substring(2, 6);
+ int ltbl = System.Convert.ToInt32(nxttable, 10);
ltbl++;
nxttable = ltbl.ToString("d6"); // this format "d6" should pad left with zeros
string newstr = "RO" + nxttable;
@@ -556,19 +1008,19 @@ namespace RODBInterface
}
catch (Exception e)
{
- MessageBox.Show(e.Message,"Getting new record id");
+ MessageBox.Show(e.Message, "Getting new record id");
}
return null;
}
// get the next recid for this table & update it.
- public string RODB_GetNextRecId(string table)
+ public override string RODB_GetNextRecId(string table)
{
// read record type of master for this table. This is where the highest recid is stored.
// Update the recid by 1, write it out and return the new recid.
string strGetNxt = "SELECT Info FROM " + table + " where RecID = '00000000' and RecType=" + (uint)RecordType.Master;
-
+
try
{
DBE.Command(strGetNxt);
@@ -577,12 +1029,12 @@ namespace RODBInterface
{
string RecID = DBE.GetString(0);
- int lrecid = System.Convert.ToInt32(RecID,16);
+ int lrecid = System.Convert.ToInt32(RecID, 16);
lrecid++;
RecID = lrecid.ToString("x");
-
+
// need an 8 char string so pad left with zero
- string padstr = RecID.PadLeft(8,'0');
+ string padstr = RecID.PadLeft(8, '0');
DBE.ReaderClose();
DBE.CommandDispose();
string dt = string.Format("{0:yyyyMMddHHmmss}", System.DateTime.Now);
@@ -598,64 +1050,56 @@ namespace RODBInterface
}
catch (Exception e)
{
- MessageBox.Show(e.Message,"Getting new record id");
+ MessageBox.Show(e.Message, "Getting new record id");
}
return null;
}
- public VlnXmlDocument RODB_GetRoot()
- {
- // Create an xmldoc and initialize it with a root node
- ROXml = new VlnXmlDocument();
- XmlNode elem=ROXml.CreateNode(XmlNodeType.Element, "RO_Root", "");
- ROXml.AppendChild(elem);
- return ROXml;
- }
-
// pass in root node. This will get Groups from Root node. This is a special case because
// the list of top level groups is off of the ROMaster database.
- public bool RODB_GetRootGroups(VlnXmlElement root)
+ public override bool RODB_GetRootGroups(VlnXmlElement root)
{
+ ShowCount.GetRootGroups++;
string table;
string group;
string title;
// Get menu fields to display
- try
+ try
{
DBE.OpenConnection();
}
catch (Exception e)
{
MessageBox.Show(e.Message, "Could not open database connection");
-// MessageBox.Show(e.StackTrace,"Debug");
+ // MessageBox.Show(e.StackTrace,"Debug");
return false;
}
-
- string strGetGroups = "SELECT RecID,Info FROM ROMaster where RecType = " + (uint) RecordType.SubDatabase;
+
+ string strGetGroups = "SELECT RecID,Info FROM ROMaster where RecType = " + (uint)RecordType.SubDatabase;
strGetGroups += " ORDER BY RecID ASC";
DBE.Command(strGetGroups);
DBE.Reader();
SortedList mySL = new SortedList();
- while(DBE.Read())
+ while (DBE.Read())
{
// Parse info string, it has group name & table name. Store in a sorted
// list, sorting by Group Name.
string mrecid = DBE.GetString(0);
group = DBE.GetString(1);
- mySL.Add(mrecid,group);
+ mySL.Add(mrecid, group);
}
DBE.CommandDispose();
DBE.ReaderClose();
// Now, for each group, i.e. table, make xml elements for the top level groups by
// reading in the Xml Element for the group from each table.
- for ( int i = 0; i < mySL.Count; i++ )
+ for (int i = 0; i < mySL.Count; i++)
{
group = mySL.GetByIndex(i).ToString();
int grnamindx = group.IndexOf("\t");
- if (grnamindx == -1)
+ if (grnamindx == -1)
{// no tab, default to RO000001
table = "RO000001";
title = group;
@@ -664,19 +1108,19 @@ namespace RODBInterface
{
StringBuilder tablesb = new StringBuilder(70);
tablesb.Append(group);
- tablesb.Remove(0,grnamindx+1);
+ tablesb.Remove(0, grnamindx + 1);
table = tablesb.ToString();
- title = group.Substring(0,grnamindx);
+ title = group.Substring(0, grnamindx);
}
- strGetGroups = "SELECT RecID,Info FROM " + table + " where RecType = " + (uint) RecordType.Group;
+ strGetGroups = "SELECT RecID,Info FROM " + table + " where RecType = " + (uint)RecordType.Group;
strGetGroups = strGetGroups + " and ParentID = '00000000'";
strGetGroups += " ORDER BY RecID ASC";
- try
+ try
{
DBE.Command(strGetGroups);
DBE.Reader();
- if(DBE.Read())
+ if (DBE.Read())
{
string RecID = DBE.GetString(0);
string Info = DBE.GetString(1);
@@ -686,7 +1130,7 @@ namespace RODBInterface
elem.MyROID = RecID;
root.AppendChild(elem);
elem.SetAttribute("RecID", RecID);
- elem.SetAttribute("ParentID","00000000");
+ elem.SetAttribute("ParentID", "00000000");
elem.SetAttribute("Table", table);
elem.SetAttribute("MasterRecID", mySL.GetKey(i).ToString());
//elem.SetAttribute("MenuTitle", elem.InnerText);
@@ -702,11 +1146,11 @@ namespace RODBInterface
}
// get child count for each group.
XmlNode node = root.FirstChild;
- while (node != null)
+ while (node != null)
{
- if (node is VlnXmlElement)
+ if (node is VlnXmlElement)
{
- VlnXmlElement child = (VlnXmlElement) node;
+ VlnXmlElement child = (VlnXmlElement)node;
//get child count for each table listed in innertext.
string strGetSubCount = "SELECT COUNT (RecID) as cnt FROM " + child.GetAttribute("Table") + " WHERE ";
strGetSubCount = strGetSubCount + "ParentID='" + child.GetAttribute("RecID") + "'";
@@ -723,11 +1167,11 @@ namespace RODBInterface
if (DBE.Read())
{
int cnt = DBE.GetInt32(0);
- if (cnt>0)
- child.SetAttribute("HasChild","True");
+ if (cnt > 0)
+ child.SetAttribute("HasChild", "True");
else
- child.SetAttribute("HasChild","False");
- child.SetAttribute("ChildLoaded","False");
+ child.SetAttribute("HasChild", "False");
+ child.SetAttribute("ChildLoaded", "False");
}
DBE.CommandDispose();
DBE.ReaderClose();
@@ -738,10 +1182,10 @@ namespace RODBInterface
// for the beginning and end schema element, go to the master & read it from there. Store these to be used
// by all of the databases.
-
+
string strGetSchemaPiece;
schemastart = null;
- strGetSchemaPiece = "SELECT Info From ROMaster where (ParentID='00000000' and RecType = " + (uint) RecordType.SchemaStart + ")";
+ strGetSchemaPiece = "SELECT Info From ROMaster where (ParentID='00000000' and RecType = " + (uint)RecordType.SchemaStart + ")";
DBE.Command(strGetSchemaPiece);
DBE.Reader();
if (DBE.Read())
@@ -755,7 +1199,7 @@ namespace RODBInterface
DBE.CommandDispose();
DBE.ReaderClose();
schemaend = null;
- strGetSchemaPiece = "SELECT Info From ROMaster where (ParentID='00000000' and RecType = " + (uint) RecordType.SchemaEnd + ")";
+ strGetSchemaPiece = "SELECT Info From ROMaster where (ParentID='00000000' and RecType = " + (uint)RecordType.SchemaEnd + ")";
DBE.Command(strGetSchemaPiece);
DBE.Reader();
if (DBE.Read())
@@ -771,17 +1215,17 @@ namespace RODBInterface
return true;
}
-
- public bool RODB_DeleteGroup(XmlNode group, string tbname, string toprecid)
+
+ public override bool RODB_DeleteGroup(XmlNode group, string tbname, string toprecid)
{
VlnXmlElement egroup = null;
string strDel;
strDel = "DELETE FROM ROMaster WHERE ";
// delete table entry in ROMaster
- if (group !=null)
+ if (group != null)
{
- egroup = (VlnXmlElement) group;
+ egroup = (VlnXmlElement)group;
strDel = strDel + "RecID='" + egroup.GetAttribute("MasterRecID") + "'";
}
else
@@ -795,7 +1239,7 @@ namespace RODBInterface
}
catch (Exception e)
{
- MessageBox.Show(e.Message,"Error When deleting SubGroup ROs.");
+ MessageBox.Show(e.Message, "Error When deleting SubGroup ROs.");
DBE.CommandDispose();
DBE.ReaderClose();
return false;
@@ -816,7 +1260,7 @@ namespace RODBInterface
}
catch (Exception e)
{
- MessageBox.Show(e.Message,"Error When deleting SubGroup ROs.");
+ MessageBox.Show(e.Message, "Error When deleting SubGroup ROs.");
DBE.CommandDispose();
DBE.ReaderClose();
return false;
@@ -827,22 +1271,22 @@ namespace RODBInterface
}
// Delete from database either the group or RO from input node.
- public bool RODB_DeleteRO(XmlNode group)
+ public override bool RODB_DeleteRO(XmlNode group)
{
// delete from database and then delete from tree. delete group and all
// subgroups & ros beneath it. delete subgroups by calling this.
// note that if just an ro is passed in, it will only delete it.
XmlNode node = group.FirstChild;
VlnXmlElement child;
- VlnXmlElement egroup = (VlnXmlElement) group;
- string strDelSub;
+ VlnXmlElement egroup = (VlnXmlElement)group;
+ string strDelSub;
if (group.Name == "vlnGroup")
{
- while (node != null)
+ while (node != null)
{
- if (node is VlnXmlElement)
+ if (node is VlnXmlElement)
{
- child = (VlnXmlElement) node;
+ child = (VlnXmlElement)node;
// if this is a group, call this again.
if (child.Name == "vlnGroup")
{
@@ -853,11 +1297,11 @@ namespace RODBInterface
return false;
}
}
-
+
}
node = node.NextSibling;
}
-
+
// delete all db records that have the ParentID = to this group RecID.
// (All subgroups should be processed from above recursion.
strDelSub = "DELETE FROM " + egroup.GetAttribute("Table") + " WHERE ";
@@ -870,7 +1314,7 @@ namespace RODBInterface
}
catch (Exception e)
{
- MessageBox.Show(e.Message,"Error When deleting SubGroup ROs.");
+ MessageBox.Show(e.Message, "Error When deleting SubGroup ROs.");
DBE.CommandDispose();
DBE.ReaderClose();
return false;
@@ -890,7 +1334,7 @@ namespace RODBInterface
}
catch (Exception e)
{
- MessageBox.Show(e.Message,"Error When deleting this RO.");
+ MessageBox.Show(e.Message, "Error When deleting this RO.");
DBE.CommandDispose();
DBE.ReaderClose();
return false;
@@ -901,108 +1345,108 @@ namespace RODBInterface
return true;
}
- private string GenerateXmlString(XmlNode node, bool isgroup)
- {
- string retstr;
- XmlTextWriter xmlTextWriter;
- StringWriter strWriter = new StringWriter();
- xmlTextWriter = new XmlTextWriter(strWriter);
- VlnXmlElement enode;
- XmlNode kid;
- kid = node.FirstChild;
- enode = (VlnXmlElement) node;
+ //public string GenerateXmlString(XmlNode node, bool isgroup) // KBR not sure - see end of method
+ //{
+ // string retstr;
+ // XmlTextWriter xmlTextWriter;
+ // StringWriter strWriter = new StringWriter();
+ // xmlTextWriter = new XmlTextWriter(strWriter);
+ // VlnXmlElement enode;
+ // XmlNode kid;
+ // kid = node.FirstChild;
+ // enode = (VlnXmlElement)node;
- if (isgroup == true)
- {
- xmlTextWriter.WriteStartElement("vlnGroup");
- if (enode.HasAttribute("RetVal"))
- {
- xmlTextWriter.WriteStartAttribute("RetVal", null);
- xmlTextWriter.WriteString(enode.GetAttribute("RetVal"));
- xmlTextWriter.WriteEndAttribute();
- }
- if (enode.HasAttribute("MenuItem"))
- {
- xmlTextWriter.WriteStartAttribute("MenuItem", null);
- xmlTextWriter.WriteString(enode.GetAttribute("MenuItem"));
- xmlTextWriter.WriteEndAttribute();
- }
- if (enode.HasAttribute("FieldsInUse"))
- {
- xmlTextWriter.WriteStartAttribute("FieldsInUse", null);
- xmlTextWriter.WriteString(enode.GetAttribute("FieldsInUse"));
- xmlTextWriter.WriteEndAttribute();
- }
- if (enode.HasAttribute("GroupMenuItem"))
- {
- xmlTextWriter.WriteStartAttribute("GroupMenuItem", null);
- xmlTextWriter.WriteString(enode.GetAttribute("GroupMenuItem"));
- xmlTextWriter.WriteEndAttribute();
- }
- if (enode.HasAttribute("GroupFieldsInUse"))
- {
- xmlTextWriter.WriteStartAttribute("GroupFieldsInUse", null);
- xmlTextWriter.WriteString(enode.GetAttribute("GroupFieldsInUse"));
- xmlTextWriter.WriteEndAttribute();
- }
- if (enode.HasAttribute("AccPageID"))
- {
- xmlTextWriter.WriteStartAttribute("AccPageID", null);
- xmlTextWriter.WriteString(enode.GetAttribute("AccPageID"));
- xmlTextWriter.WriteEndAttribute();
- }
- if (enode.HasAttribute("AccPageIDPrefix"))
- {
- xmlTextWriter.WriteStartAttribute("AccPageIDPrefix", null);
- xmlTextWriter.WriteString(enode.GetAttribute("AccPageIDPrefix"));
- xmlTextWriter.WriteEndAttribute();
- }
- xmlTextWriter.WriteStartAttribute("MenuTitle", null);
- xmlTextWriter.WriteString(enode.GetAttribute("MenuTitle"));
- xmlTextWriter.WriteEndAttribute();
+ // if (isgroup == true)
+ // {
+ // xmlTextWriter.WriteStartElement("vlnGroup");
+ // if (enode.HasAttribute("RetVal"))
+ // {
+ // xmlTextWriter.WriteStartAttribute("RetVal", null);
+ // xmlTextWriter.WriteString(enode.GetAttribute("RetVal"));
+ // xmlTextWriter.WriteEndAttribute();
+ // }
+ // if (enode.HasAttribute("MenuItem"))
+ // {
+ // xmlTextWriter.WriteStartAttribute("MenuItem", null);
+ // xmlTextWriter.WriteString(enode.GetAttribute("MenuItem"));
+ // xmlTextWriter.WriteEndAttribute();
+ // }
+ // if (enode.HasAttribute("FieldsInUse"))
+ // {
+ // xmlTextWriter.WriteStartAttribute("FieldsInUse", null);
+ // xmlTextWriter.WriteString(enode.GetAttribute("FieldsInUse"));
+ // xmlTextWriter.WriteEndAttribute();
+ // }
+ // if (enode.HasAttribute("GroupMenuItem"))
+ // {
+ // xmlTextWriter.WriteStartAttribute("GroupMenuItem", null);
+ // xmlTextWriter.WriteString(enode.GetAttribute("GroupMenuItem"));
+ // xmlTextWriter.WriteEndAttribute();
+ // }
+ // if (enode.HasAttribute("GroupFieldsInUse"))
+ // {
+ // xmlTextWriter.WriteStartAttribute("GroupFieldsInUse", null);
+ // xmlTextWriter.WriteString(enode.GetAttribute("GroupFieldsInUse"));
+ // xmlTextWriter.WriteEndAttribute();
+ // }
+ // if (enode.HasAttribute("AccPageID"))
+ // {
+ // xmlTextWriter.WriteStartAttribute("AccPageID", null);
+ // xmlTextWriter.WriteString(enode.GetAttribute("AccPageID"));
+ // xmlTextWriter.WriteEndAttribute();
+ // }
+ // if (enode.HasAttribute("AccPageIDPrefix"))
+ // {
+ // xmlTextWriter.WriteStartAttribute("AccPageIDPrefix", null);
+ // xmlTextWriter.WriteString(enode.GetAttribute("AccPageIDPrefix"));
+ // xmlTextWriter.WriteEndAttribute();
+ // }
+ // xmlTextWriter.WriteStartAttribute("MenuTitle", null);
+ // xmlTextWriter.WriteString(enode.GetAttribute("MenuTitle"));
+ // xmlTextWriter.WriteEndAttribute();
- while (kid != null)
- {
- if ((kid is XmlText) || (kid.ChildNodes.Count == 1 && kid.Name != "vlnGroup"))
- kid.WriteTo(xmlTextWriter);
- kid = kid.NextSibling;
- }
- }
- else
- {
- xmlTextWriter.WriteStartElement(node.Name);
+ // while (kid != null)
+ // {
+ // if ((kid is XmlText) || (kid.ChildNodes.Count == 1 && kid.Name != "vlnGroup"))
+ // kid.WriteTo(xmlTextWriter);
+ // kid = kid.NextSibling;
+ // }
+ // }
+ // else
+ // {
+ // xmlTextWriter.WriteStartElement(node.Name);
- xmlTextWriter.WriteStartAttribute("MenuTitle", null);
- xmlTextWriter.WriteString(enode.GetAttribute("MenuTitle"));
- xmlTextWriter.WriteEndAttribute();
+ // xmlTextWriter.WriteStartAttribute("MenuTitle", null);
+ // xmlTextWriter.WriteString(enode.GetAttribute("MenuTitle"));
+ // xmlTextWriter.WriteEndAttribute();
- while (kid != null)
- {
- kid.WriteTo(xmlTextWriter);
- kid = kid.NextSibling;
- }
- }
-
- xmlTextWriter.WriteEndElement(); // vlnGroup or top of RO.
- xmlTextWriter.Flush();
- xmlTextWriter.Close();
+ // while (kid != null)
+ // {
+ // kid.WriteTo(xmlTextWriter);
+ // kid = kid.NextSibling;
+ // }
+ // }
- retstr = strWriter.ToString();
+ // xmlTextWriter.WriteEndElement(); // vlnGroup or top of RO.
+ // xmlTextWriter.Flush();
+ // xmlTextWriter.Close();
- // replace the single quote because ODBC fails if it's in a string because
- // the single quote represents the beg/end of string when sending string to
- // ODBC.
- retstr = retstr.Replace("\'","'");
- return(retstr);
- }
+ // retstr = strWriter.ToString();
- public bool RODB_WriteGroup(XmlNode group, VlnXmlElement master)
+ // // replace the single quote because ODBC fails if it's in a string because
+ // // the single quote represents the beg/end of string when sending string to
+ // // ODBC.
+ // retstr = retstr.Replace("\'", "'"); // KBR - not sure if this method should be in RODB class or db specific class
+ // return (retstr);
+ //}
+
+ public override bool RODB_WriteGroup(XmlNode group, VlnXmlElement master)
{
bool retval = true;
string dt = string.Format("{0:yyyyMMddHHmmss}", System.DateTime.Now);
string xmlstr = GenerateXmlString(group, true);
string strUpdate = "UPDATE " + master.GetAttribute("Table") + " SET Info = '" + xmlstr + "'";
- strUpdate = strUpdate + ", ModDateTime = '" + dt + "' WHERE RecID='" + master.GetAttribute("RecID") + "'";
+ strUpdate = strUpdate + ", ModDateTime = '" + dt + "' WHERE RecID='" + master.GetAttribute("RecID") + "'";
try
{
DBE.Command(strUpdate);
@@ -1010,7 +1454,7 @@ namespace RODBInterface
}
catch (Exception e)
{
- MessageBox.Show(e.Message,"Error on write group");
+ MessageBox.Show(e.Message, "Error on write group");
retval = false;
}
DBE.ReaderClose();
@@ -1018,14 +1462,14 @@ namespace RODBInterface
return retval;
}
- public bool RODB_InsertGroup(VlnXmlElement group)
+ public override bool RODB_InsertGroup(VlnXmlElement group)
{
bool retval = true;
string dt = string.Format("{0:yyyyMMddHHmmss}", System.DateTime.Now);
string xmlstr = GenerateXmlString(group, true);
string strInsert = "INSERT INTO " + group.GetAttribute("Table") + "(RecID, RecType, ParentID, ModDateTime, Info) ";
- strInsert = strInsert + " VALUES ('" + group.GetAttribute("RecID") + "'," + (uint) RecordType.Group + ",'";
- strInsert = strInsert + group.GetAttribute("ParentID") + "','" + dt + "','" + xmlstr + "');";
+ strInsert = strInsert + " VALUES ('" + group.GetAttribute("RecID") + "'," + (uint)RecordType.Group + ",'";
+ strInsert = strInsert + group.GetAttribute("ParentID") + "','" + dt + "','" + xmlstr + "');";
try
{
DBE.Command(strInsert);
@@ -1033,17 +1477,17 @@ namespace RODBInterface
}
catch (Exception e)
{
- MessageBox.Show(e.Message,"Error on insert group");
+ MessageBox.Show(e.Message, "Error on insert group");
retval = false;
}
DBE.ReaderClose();
DBE.CommandDispose();
return retval;
}
-
+
// add a new database table, add a record to master to point to it. return
// that record number.
- public string RODB_AddNewTable(string TblName, string newgrpname)
+ public override string RODB_AddNewTable(string TblName, string newgrpname)
{
bool retval = false;
// create the table. this is done by doing a select into the new table
@@ -1052,7 +1496,7 @@ namespace RODBInterface
// field 'Info').
string strMkTable = "SELECT * INTO " + TblName;
strMkTable = strMkTable + " FROM ROMaster WHERE RecID = '00000000';";
-
+
try
{
DBE.Command(strMkTable);
@@ -1070,7 +1514,7 @@ namespace RODBInterface
// remove the first record. It was inserted just to have something to copy to
// create the table. (see previous comment)
-
+
string strDel = "DELETE FROM " + TblName + " WHERE RecID = '00000000'";
try
{
@@ -1080,17 +1524,17 @@ namespace RODBInterface
}
catch (Exception e)
{
- MessageBox.Show(e.Message,"Error When deleting SubGroup ROs.");
+ MessageBox.Show(e.Message, "Error When deleting SubGroup ROs.");
DBE.CommandDispose();
DBE.ReaderClose();
return null;
}
DBE.CommandDispose();
DBE.ReaderClose();
-
+
// now insert the first record
string dt = string.Format("{0:yyyyMMddHHmmss}", System.DateTime.Now);
-
+
string strInsert = "INSERT INTO " + TblName + "( RecID, RecType, ParentID, ModDateTime, Info ) ";
strInsert = strInsert + " VALUES ('00000000', 0,'00000000','" + dt + "','00000001');";
retval = false;
@@ -1098,7 +1542,7 @@ namespace RODBInterface
{
DBE.Command(strInsert);
DBE.Reader();
- retval=true;
+ retval = true;
}
catch (Exception e)
{
@@ -1113,13 +1557,13 @@ namespace RODBInterface
string recid = RODB_GetNextRecId("ROMaster");
string info = CvtUserFldToFld(newgrpname) + "\t" + TblName;
strInsert = "INSERT INTO ROMaster ( RecID, RecType, ParentID, ModDateTime, Info ) ";
- strInsert = strInsert + " VALUES ('"+recid+"', 1,'00000001','" + dt + "','"+info+"');";
+ strInsert = strInsert + " VALUES ('" + recid + "', 1,'00000001','" + dt + "','" + info + "');";
retval = false;
try
{
DBE.Command(strInsert);
DBE.Reader();
- retval=true;
+ retval = true;
}
catch (Exception e)
{
@@ -1134,7 +1578,7 @@ namespace RODBInterface
}
// Copy over field definitions from the ROMaster to the input table.
- public bool RODB_CopyFieldDefs(string fromtb, string totb, int type)
+ public override bool RODB_CopyFieldDefs(string fromtb, string totb, int type)
{
ArrayList retlist = new ArrayList();
string strGetFields;
@@ -1149,14 +1593,14 @@ namespace RODBInterface
strGetFields = "SELECT RecID, Info from ROMaster where RecType = 2";
DBE.Command(strGetFields);
DBE.Reader();
-
+
while (DBE.Read())
{
RecID = DBE.GetString(0);
Info = DBE.GetString(1);
// it's defined in the local table if the first character is "<" which starts
// the schema definition string.
-
+
name = ParseEleName(Info);
if (name != null)
{
@@ -1164,19 +1608,19 @@ namespace RODBInterface
rof = new ROField(name, RecID, null, 0);
ftype = rof.ParseFieldType(Info);
rof.SetFieldType(ftype);
- retlist.Add((object) rof);
+ retlist.Add((object)rof);
}
}
DBE.ReaderClose();
DBE.CommandDispose();
-
- // using this list, add new records for field defintion references to the new
+
+ // using this list, add new records for field definition references to the new
// table.
- for (int i=0; i< retlist.Count; i++)
+ for (int i = 0; i < retlist.Count; i++)
{
- rof = (ROField) retlist[i];
- if (rof.GetFieldname != null)
+ rof = (ROField)retlist[i];
+ if (rof.GetFieldname != null)
{
string mrecid = rof.GetRecID;
string lrecid = RODB_GetNextRecId(totb);
@@ -1184,10 +1628,10 @@ namespace RODBInterface
strbld.Append(mrecid);
strbld.Append(" ");
string strtype = rof.GetFieldType.ToString();
- strbld.Append(strtype.PadLeft(3,'0'));
+ strbld.Append(strtype.PadLeft(3, '0'));
strbld.Append(" ");
if (strtype == "128") // append an 'a' for combo type
- strbld.Append(rof.MakeFieldName(rof.GetFieldname)+"a");
+ strbld.Append(rof.MakeFieldName(rof.GetFieldname) + "a");
else
strbld.Append(rof.MakeFieldName(rof.GetFieldname));
// add new field.
@@ -1198,17 +1642,16 @@ namespace RODBInterface
return true;
}
-
// This is simular to GetChildData() but this function reads in
// all the subgroups for the given node
// Note that this function is designed to be call for the
// root node (i.e. it gets all of group and RO data for a given
// database table)
- public bool RODB_GetGroupAndSubgroups(VlnXmlElement node, StringBuilder sb)
+ public override bool RODB_GetGroupAndSubgroups(VlnXmlElement node, StringBuilder sb)
{
VlnStatusBar StatBar = new VlnStatusBar("Reading from the Database");
string tablename = node.GetAttribute("Table");
-
+
string strGetChildData = "SELECT * FROM " + tablename;
strGetChildData = strGetChildData + " where (RecType = 3 or RecType = 5) AND ParentID <> '00000002' ORDER BY ParentID,RecID ASC";
HybridDictionary dicGroups = new HybridDictionary();
@@ -1243,20 +1686,20 @@ namespace RODBInterface
sb.AppendLine("The parent for these RO's was missing.");
sb.AppendLine();
}
- string strMBText = "RecID: " + RecID + "\n\n Table: " + tablename +"\n";
+ string strMBText = "RecID: " + RecID + "\n\n Table: " + tablename + "\n";
sb.AppendLine(strMBText);
-// MessageBox.Show(strMBText, "Warning - Orphan RO Record");
+ // MessageBox.Show(strMBText, "Warning - Orphan RO Record");
continue; // skip - no parent for this node
}
node = (VlnXmlElement)dicGroups[ParID];
node.SetAttribute("HasChild", "True");
- node.SetAttribute("ChildLoaded","True");
+ node.SetAttribute("ChildLoaded", "True");
}
else
{
- node.SetAttribute("ChildLoaded","True");
+ node.SetAttribute("ChildLoaded", "True");
}
- if (RecType == (uint) RecordType.Group)
+ if (RecType == (uint)RecordType.Group)
{
VlnXmlElement elem;
StatBar.PerformStep();
@@ -1274,13 +1717,13 @@ namespace RODBInterface
}
elem.MyROID = RecID;
elem.SetAttribute("RecID", RecID);
- elem.SetAttribute("ParentID",node.GetAttribute("RecID"));
+ elem.SetAttribute("ParentID", node.GetAttribute("RecID"));
elem.SetAttribute("Table", node.GetAttribute("Table"));
if (!dicGroups.Contains(RecID))
{
node.AppendChild(elem);
- dicGroups.Add(RecID,elem);
+ dicGroups.Add(RecID, elem);
}
// The Parameter Display Data is stored along with the group. This data
@@ -1288,19 +1731,19 @@ namespace RODBInterface
// User Interface to get to it. So remove the xml elements from the
// group part of tree. All valid group data only has one sublevel of
// data defining the group name.
- XmlNode grp = (XmlNode) elem;
+ XmlNode grp = (XmlNode)elem;
XmlNode kid = grp.FirstChild;
XmlNode tmpkid;
while (kid != null)
{
tmpkid = kid.NextSibling;
if (kid is VlnXmlElement)
- if (kid.ChildNodes.Count>1) grp.RemoveChild(kid);
+ if (kid.ChildNodes.Count > 1) grp.RemoveChild(kid);
kid = tmpkid;
}
}
- // Store data in the VlnXmlElement as an RO
- else if (RecType == (uint) RecordType.RRO)
+ // Store data in the VlnXmlElement as an RO
+ else if (RecType == (uint)RecordType.RRO)
{
//Create the reader.
XmlNode ro;
@@ -1316,11 +1759,11 @@ namespace RODBInterface
return false;
}
- VlnXmlElement elem = (VlnXmlElement) ro;
+ VlnXmlElement elem = (VlnXmlElement)ro;
node.AppendChild(ro);
elem.MyROID = RecID;
elem.SetAttribute("RecID", RecID);
- elem.SetAttribute("ParentID",node.GetAttribute("RecID"));
+ elem.SetAttribute("ParentID", node.GetAttribute("RecID"));
elem.SetAttribute("Table", node.GetAttribute("Table"));
elem.SetAttribute("AccPageID", AccPageID);
}
@@ -1331,8 +1774,9 @@ namespace RODBInterface
return true;
}
- public bool RODB_GetChildData(VlnXmlElement node,bool CheckChildCount)
+ public override bool RODB_GetChildData(VlnXmlElement node, bool CheckChildCount)
{
+ ShowCount.GetChildData++;
// get menu fields to display here.
string tablename = node.GetAttribute("Table");
string strGetChildData = "SELECT RecID,RecType,AccPageID, Info FROM " + tablename + " where ";
@@ -1345,6 +1789,7 @@ namespace RODBInterface
DBE.Reader();
while (DBE.Read())
{
+ ShowCount.Children++;
//get count for attribute element
string RecID = DBE.GetString(0);
int RecType = DBE.GetInt32(1);
@@ -1352,8 +1797,9 @@ namespace RODBInterface
string AccPageID = DBE.GetString(2);
string Info = DBE.GetString(3);
node.SetAttribute("HasChild", "True");
+
// Store data in the VlnXmlElement as a subgroup
- if (RecType == (uint) RecordType.Group)
+ if (RecType == (uint)RecordType.Group)
{
VlnXmlElement elem;
try
@@ -1371,7 +1817,7 @@ namespace RODBInterface
node.AppendChild(elem);
elem.MyROID = RecID;
elem.SetAttribute("RecID", RecID);
- elem.SetAttribute("ParentID",node.GetAttribute("RecID"));
+ elem.SetAttribute("ParentID", node.GetAttribute("RecID"));
elem.SetAttribute("Table", node.GetAttribute("Table"));
// The Parameter Display Data is stored along with the group. This data
@@ -1379,19 +1825,19 @@ namespace RODBInterface
// User Interface to get to it. So remove the xml elements from the
// group part of tree. All valid group data only has one sublevel of
// data defining the group name.
- XmlNode grp = (XmlNode) elem;
+ XmlNode grp = (XmlNode)elem;
XmlNode kid = grp.FirstChild;
XmlNode tmpkid;
while (kid != null)
{
tmpkid = kid.NextSibling;
if (kid is VlnXmlElement)
- if (kid.ChildNodes.Count>1) grp.RemoveChild(kid);
+ if (kid.ChildNodes.Count > 1) grp.RemoveChild(kid);
kid = tmpkid;
}
}
- // Store data in the VlnXmlElement as an RO
- else if (RecType == (uint) RecordType.RRO)
+ // Store data in the VlnXmlElement as an RO
+ else if (RecType == (uint)RecordType.RRO)
{
//Create the reader.
XmlNode ro;
@@ -1407,11 +1853,11 @@ namespace RODBInterface
return false;
}
- VlnXmlElement elem = (VlnXmlElement) ro;
+ VlnXmlElement elem = (VlnXmlElement)ro;
elem.MyROID = RecID;
node.AppendChild(ro);
elem.SetAttribute("RecID", RecID);
- elem.SetAttribute("ParentID",node.GetAttribute("RecID"));
+ elem.SetAttribute("ParentID", node.GetAttribute("RecID"));
elem.SetAttribute("Table", node.GetAttribute("Table"));
elem.SetAttribute("AccPageID", AccPageID);
}
@@ -1419,13 +1865,13 @@ namespace RODBInterface
DBE.ReaderClose();
// get child count for each subgroup.
- if(CheckChildCount)
+ if (CheckChildCount)
{
//A different approach - Look for grandchildren and set the haschildren attribute
//Build a query to get a list of children with children
string strGetSubCount = "SELECT R1.ParentID,COUNT(*) AS CNT FROM " + tablename + " R1 "
+ "INNER JOIN " + tablename + " R2 ON R1.ParentID = R2.RecID "
- + "WHERE (R1.RecType = " + (uint)RecordType.Group + " or R1.RecType=" + (uint)RecordType.RRO + ") "
+ + "WHERE (R1.RecType = " + (uint)RecordType.Group + " or R1.RecType=" + (uint)RecordType.RRO + ") "
+ "and R2.ParentID ='" + node.GetAttribute("RecID") + "' group by R1.ParentID;";
try
{
@@ -1434,12 +1880,12 @@ namespace RODBInterface
}
catch (Exception e)
{
- MessageBox.Show(e.Message,"Error reading data");
+ MessageBox.Show(e.Message, "Error reading data");
}
//Build a Dictionary of Children with Children from the query results
HybridDictionary dicChild = new HybridDictionary();
- while(DBE.Read())
- dicChild[DBE.GetString(0)]=DBE.GetInt32(1);//This adds the entry and sets the value
+ while (DBE.Read())
+ dicChild[DBE.GetString(0)] = DBE.GetInt32(1);//This adds the entry and sets the value
DBE.CommandDispose();
DBE.ReaderClose();
XmlNode child = node.FirstChild;
@@ -1447,176 +1893,35 @@ namespace RODBInterface
{
if (child is VlnXmlElement)
{
- VlnXmlElement echild = (VlnXmlElement) child;
+ VlnXmlElement echild = (VlnXmlElement)child;
if (echild.Name == "vlnGroup")
{
//If the dictionary contains an entry, the child has children
- echild.SetAttribute("HasChild",(dicChild.Contains(echild.GetAttribute("RecID")))?"True":"False");
+ echild.SetAttribute("HasChild", (dicChild.Contains(echild.GetAttribute("RecID"))) ? "True" : "False");
echild.SetAttribute("ChildLoaded", "False");
}
}
child = child.NextSibling;
}
- dicChild=null;
+ dicChild = null;
}
- node.SetAttribute("ChildLoaded","True");
+ node.SetAttribute("ChildLoaded", "True");
return true;
}
-// public bool OLD_RODB_GetChildData(VlnXmlElement node,bool CheckChildCount)
-// {
-// Profiler.Start("GCD_1");
-// // get menu fields to display here.
-// string tablename = node.GetAttribute("Table");
-// string strGetChildData = "SELECT RecID,RecType,AccPageID, Info FROM " + tablename + " where ";
-// strGetChildData = strGetChildData + "(RecType = " + (uint)RecordType.Group + " or RecType = ";
-// strGetChildData = strGetChildData + (uint)RecordType.RRO + ") and ";
-// strGetChildData = strGetChildData + "ParentID='" + node.GetAttribute("RecID") + "'";
-// strGetChildData += " ORDER BY RecID ASC";
-// Profiler.End("GCD_1");
-// //bool readit=false;
-// Profiler.Start("GCD_2");
-// DBE.Command(strGetChildData);
-// Profiler.End("GCD_2");
-// Profiler.Start("GCD_3");
-// DBE.Reader();
-// Profiler.End("GCD_3");
-// Profiler.Start("GCD_4");
-// while (DBE.Read())
-// {
-// //get count for attribute element
-// string RecID = DBE.GetString(0);
-// int RecType = DBE.GetInt32(1);
-// string AccPageID = DBE.GetString(2);
-// string Info = DBE.GetString(3);
-// node.SetAttribute("HasChild", "True");
-// // Store data in the VlnXmlElement as a subgroup
-// if (RecType == (uint) RecordType.Group)
-// {
-// VlnXmlElement elem;
-// try
-// {
-// XmlTextReader rdr = new XmlTextReader(Info, XmlNodeType.Element, null);
-// XmlNode nd = ROXml.ReadNode(rdr);
-// elem = (VlnXmlElement)nd;
-// }
-// catch (Exception e)
-// {
-// MessageBox.Show(e.Message, "Error reading Xml Group From data");
-// DBE.ReaderClose();
-// return false;
-// }
-// node.AppendChild(elem);
-// elem.SetAttribute("RecID", RecID);
-// elem.SetAttribute("ParentID",node.GetAttribute("RecID"));
-// elem.SetAttribute("Table", node.GetAttribute("Table"));
-//
-// // The Parameter Display Data is stored along with the group. This data
-// // was migrated over so that the data was not lost, but there is no
-// // User Interface to get to it. So remove the xml elements from the
-// // group part of tree. All valid group data only has one sublevel of
-// // data defining the group name.
-// XmlNode grp = (XmlNode) elem;
-// XmlNode kid = grp.FirstChild;
-// XmlNode tmpkid;
-// while (kid != null)
-// {
-// tmpkid = kid.NextSibling;
-// if (kid is VlnXmlElement)
-// if (kid.ChildNodes.Count>1) grp.RemoveChild(kid);
-// kid = tmpkid;
-// }
-// }
-//
-// // Store data in the VlnXmlElement as an RO
-// else if (RecType == (uint) RecordType.RRO)
-// {
-// //Create the reader.
-// XmlNode ro;
-// try
-// {
-// XmlTextReader roreader = new XmlTextReader(Info, XmlNodeType.Element, null);
-// ro = ROXml.ReadNode(roreader);
-// }
-// catch (Exception e)
-// {
-// MessageBox.Show(e.Message, "Error reading Xml RRO From data");
-// DBE.ReaderClose();
-// return false;
-// }
-//
-//
-// VlnXmlElement elem = (VlnXmlElement) ro;
-// node.AppendChild(ro);
-// elem.SetAttribute("RecID", RecID);
-// elem.SetAttribute("ParentID",node.GetAttribute("RecID"));
-// elem.SetAttribute("Table", node.GetAttribute("Table"));
-// elem.SetAttribute("AccPageID", AccPageID);
-// }
-// }
-// Profiler.End("GCD_4");
-// Profiler.Start("GCD_5");
-// DBE.ReaderClose();
-//
-// if (CheckChildCount)
-// {
-// // get child count for each subgroup.
-// XmlNode child = node.FirstChild;
-// // while (child != null && CheckChildCount)
-// while (child != null)
-// {
-// if (child is VlnXmlElement)
-// {
-// VlnXmlElement echild = (VlnXmlElement) child;
-// if (echild.Name == "vlnGroup")
-// {
-// //get child count for each table listed in innertext.
-// string strGetSubCount = "SELECT COUNT(RecID) AS CNT FROM " + echild.GetAttribute("Table") + " WHERE ";
-// strGetSubCount = strGetSubCount + "(RecType = " + (uint)RecordType.Group + " or RecType=" + (uint)RecordType.RRO + ")";
-// strGetSubCount = strGetSubCount + " and ParentID='" + echild.GetAttribute("RecID") + "'";
-// try
-// {
-// DBE.Command(strGetSubCount);
-// DBE.Reader();
-// }
-// catch (Exception e)
-// {
-// MessageBox.Show(e.Message,"Error reading data");
-// }
-// if (DBE.Read())
-// {
-// int cnt = DBE.GetInt32(0);
-// if (cnt>0)
-// echild.SetAttribute("HasChild","True");
-// else
-// echild.SetAttribute("HasChild","False");
-// echild.SetAttribute("ChildLoaded", "False");
-// }
-// DBE.CommandDispose();
-// DBE.ReaderClose();
-// }
-// }
-// child = child.NextSibling;
-// }
-// }
-// node.SetAttribute("ChildLoaded","True");
-// Profiler.End("GCD_5");
-// return true;
-// }
-
- public bool IsDuplicateAccPageID(VlnXmlElement ro,string newacc)
+ public override bool IsDuplicateAccPageID(VlnXmlElement ro, string newacc)
{
- string strcheck, inacc=null;
- bool isdup=false;
+ string strcheck, inacc = null;
+ bool isdup = false;
int indx = newacc.IndexOf("'");
if (indx >= 0)
- inacc=newacc.Insert(indx,"'");
+ inacc = newacc.Insert(indx, "'");
else
- inacc=newacc;
+ inacc = newacc;
strcheck = "SELECT Count(RecID) AS CNT FROM " + ro.GetAttribute("Table") + " WHERE AccPageID = '" + inacc + "'";
-
+
if (ro.HasAttribute("RecID")) // new ro's don't have recid defined yet before this test.
- strcheck = strcheck + " AND (NOT RecID = '" + ro.GetAttribute("RecID") + "')";
+ strcheck = strcheck + " AND (NOT RecID = '" + ro.GetAttribute("RecID") + "')";
try
{
DBE.Command(strcheck);
@@ -1624,35 +1929,36 @@ namespace RODBInterface
}
catch (Exception e)
{
- MessageBox.Show(e.Message,"Error on check");
+ MessageBox.Show(e.Message, "Error on check");
return true;
}
if (DBE.Read())
{
int cnt = DBE.GetInt32(0);
- if (cnt>0)
+ if (cnt > 0)
isdup = true;
else
- isdup = false;
+ isdup = false;
}
DBE.CommandDispose();
DBE.ReaderClose();
return isdup;
}
- public VlnXmlElement RODB_ReadRO(string tbl, string recid)
+ public override VlnXmlElement RODB_ReadRO(string tbl, string recid)
{
+ ShowCount.ReadRo++;
VlnXmlElement retele = null;
- string readstr = "SELECT ParentID, AccPageID, Info FROM " + tbl + " WHERE "+ ((recid==null)? "RecType=3 and ParentID = '00000000'" : ("RecID = '" + recid + "'"));
+ string readstr = "SELECT ParentID, AccPageID, Info FROM " + tbl + " WHERE " + ((recid == null) ? "RecType=3 and ParentID = '00000000'" : ("RecID = '" + recid + "'"));
try
{
DBE.Command(readstr);
DBE.Reader();
-
+
// With the additional check for a recid=null, in the WHERE statement (above), we now longer need to check and skip for a null recid - jsj 4-17-2015
//if (recid == null)
// DBE.Read(); // skip the first parentID record of 00000000
-
+
if (DBE.Read())
{
string ParentID = DBE.GetString(0);
@@ -1663,7 +1969,7 @@ namespace RODBInterface
XmlNode nd = ROXml.ReadNode(rdr);
retele = (VlnXmlElement)nd;
retele.SetAttribute("RecID", recid);
- retele.SetAttribute("ParentID",ParentID);
+ retele.SetAttribute("ParentID", ParentID);
retele.SetAttribute("Table", tbl);
if (retele.Name != "vlnGroup") retele.SetAttribute("AccPageID", AccPageID);
}
@@ -1679,15 +1985,15 @@ namespace RODBInterface
strGetSubCount = strGetSubCount + "ParentID='" + recid + "'";
DBE.Command(strGetSubCount);
DBE.Reader();
-
+
if (DBE.Read())
{
int cnt = DBE.GetInt32(0);
- if (cnt>0)
- retele.SetAttribute("HasChild","True");
+ if (cnt > 0)
+ retele.SetAttribute("HasChild", "True");
else
- retele.SetAttribute("HasChild","False");
- retele.SetAttribute("ChildLoaded","False");
+ retele.SetAttribute("HasChild", "False");
+ retele.SetAttribute("ChildLoaded", "False");
}
DBE.CommandDispose();
DBE.ReaderClose();
@@ -1695,13 +2001,13 @@ namespace RODBInterface
}
catch (Exception e)
{
- MessageBox.Show(e.Message,"Error on Read of RO");
+ MessageBox.Show(e.Message, "Error on Read of RO");
return null;
}
return retele;
}
- public bool RODB_WriteRO(VlnXmlElement ro)
+ public override bool RODB_WriteRO(VlnXmlElement ro)
{
bool success;
if (ro.Name == "vlnGroup")
@@ -1711,17 +2017,17 @@ namespace RODBInterface
}
else
{
- string wraccid=null;
+ string wraccid = null;
string accid = ro.GetAttribute("AccPageID");
int quote = accid.IndexOf("'");
- if (quote>=0)
- wraccid = accid.Insert(quote,"'");
+ if (quote >= 0)
+ wraccid = accid.Insert(quote, "'");
else
wraccid = accid;
string dt = string.Format("{0:yyyyMMddHHmmss}", System.DateTime.Now);
string xmlstr = GenerateXmlString(ro, false);
string strUpdate = "UPDATE " + ro.GetAttribute("Table") + " SET Info = '" + xmlstr + "'";
- strUpdate = strUpdate + ", ModDateTime = '" + dt + "', AccPageID = '" + wraccid + "' WHERE RecID='" + ro.GetAttribute("RecID") + "'";
+ strUpdate = strUpdate + ", ModDateTime = '" + dt + "', AccPageID = '" + wraccid + "' WHERE RecID='" + ro.GetAttribute("RecID") + "'";
try
{
DBE.Command(strUpdate);
@@ -1730,7 +2036,7 @@ namespace RODBInterface
}
catch (Exception e)
{
- MessageBox.Show(e.Message,"Database Write Error");
+ MessageBox.Show(e.Message, "Database Write Error");
success = false;
}
DBE.ReaderClose();
@@ -1739,30 +2045,30 @@ namespace RODBInterface
return success;
}
- public bool RODB_InsertRO(VlnXmlElement ro)
+ public override bool RODB_InsertRO(VlnXmlElement ro)
{
- bool success=false;
- string strInsert=null;
+ bool success = false;
+ string strInsert = null;
string dt = string.Format("{0:yyyyMMddHHmmss}", System.DateTime.Now);
VlnXmlElement parent = (VlnXmlElement)ro.ParentNode;
string lrecid = RODB_GetNextRecId(parent.GetAttribute("Table"));
- ro.SetAttribute("Table",parent.GetAttribute("Table"));
- ro.SetAttribute("RecID",lrecid);
- ro.SetAttribute("ParentID",parent.GetAttribute("RecID"));
+ ro.SetAttribute("Table", parent.GetAttribute("Table"));
+ ro.SetAttribute("RecID", lrecid);
+ ro.SetAttribute("ParentID", parent.GetAttribute("RecID"));
string haskids = parent.GetAttribute("HasChild");
- if (haskids == "False" || haskids=="")
+ if (haskids == "False" || haskids == "")
{
- parent.SetAttribute("HasChild","True");
+ parent.SetAttribute("HasChild", "True");
parent.SetAttribute("ChildLoaded", "True");
}
string xmlstr = GenerateXmlString(ro, false);
- string wraccid=null;
+ string wraccid = null;
if (ro.HasAttribute("AccPageID"))
{
string accid = ro.GetAttribute("AccPageID");
int quote = accid.IndexOf("'");
- if (quote>=0)
- wraccid = accid.Insert(quote,"'");
+ if (quote >= 0)
+ wraccid = accid.Insert(quote, "'");
else
wraccid = accid;
}
@@ -1774,21 +2080,21 @@ namespace RODBInterface
if (ro.HasAttribute("AccPageID"))
{
strInsert = "INSERT INTO " + parent.GetAttribute("Table") + "( RecID, RecType, ParentID, ModDateTime, AccPageID, Info ) ";
- strInsert = strInsert + " VALUES ('" + ro.GetAttribute("RecID") + "'," + (uint) RecordType.Group + ",'" + ro.GetAttribute("ParentID");
- strInsert = strInsert + "','" + wraccid + "','" + dt + "','" + xmlstr + "');";
+ strInsert = strInsert + " VALUES ('" + ro.GetAttribute("RecID") + "'," + (uint)RecordType.Group + ",'" + ro.GetAttribute("ParentID");
+ strInsert = strInsert + "','" + wraccid + "','" + dt + "','" + xmlstr + "');";
}
else
{
strInsert = "INSERT INTO " + parent.GetAttribute("Table") + "( RecID, RecType, ParentID, ModDateTime, Info ) ";
- strInsert = strInsert + " VALUES ('" + ro.GetAttribute("RecID") + "'," + (uint) RecordType.Group + ",'" + ro.GetAttribute("ParentID");
- strInsert = strInsert + "','" + dt + "','" + xmlstr + "');";
+ strInsert = strInsert + " VALUES ('" + ro.GetAttribute("RecID") + "'," + (uint)RecordType.Group + ",'" + ro.GetAttribute("ParentID");
+ strInsert = strInsert + "','" + dt + "','" + xmlstr + "');";
}
}
else
{
strInsert = "INSERT INTO " + parent.GetAttribute("Table") + "( RecID, RecType, ParentID, AccPageId, ModDateTime, Info ) ";
- strInsert = strInsert + " VALUES ('" + ro.GetAttribute("RecID") + "'," + (uint) RecordType.RRO + ",'" + ro.GetAttribute("ParentID");
+ strInsert = strInsert + " VALUES ('" + ro.GetAttribute("RecID") + "'," + (uint)RecordType.RRO + ",'" + ro.GetAttribute("ParentID");
strInsert = strInsert + "','" + wraccid + "','" + dt + "','" + xmlstr + "');";
}
@@ -1796,7 +2102,7 @@ namespace RODBInterface
{
DBE.Command(strInsert);
DBE.Reader();
- success=true;
+ success = true;
}
catch (Exception e)
{
@@ -1806,260 +2112,8 @@ namespace RODBInterface
DBE.CommandDispose();
return success;
}
-
- private string ParseEleName(string info)
- {
- string elemname;
- // need to find element type too.
- int issingle = info.IndexOf("Single");
-
- int idx1 = info.IndexOf("element name=");
- if (idx1 >0)
- {
- elemname=info.Substring(idx1+14,info.Length-idx1-14);
- idx1 = elemname.IndexOf("\"");
- elemname = CvtFldToUserFld(elemname.Substring(0,idx1));
- // if we have a choice element, remove the last character (it was added to the
- // field names in order to allow for unique fields names for the choice items.
- if (info.IndexOf("xsd:choice") > 0)
- {
- string trun = elemname.Remove((elemname.Length)-1,1);
- return trun;
- }
- return elemname;
- }
- return null;
- }
-
-
- // Given an element to start at, get the fields in use. Pass in the element you're
- // on, the available list for this group & a string representing 'FieldsInUse' or
- // 'GroupFieldsInUse'.
- public ArrayList RODB_GetFieldsInUse(VlnXmlElement elem, ArrayList avail, string strFieldsInUse, ref string origFieldsInUse, bool RemoveFromAvailList)
- {
- VlnXmlElement startelem = elem;
-
- // if doing groups, the fields in use is defined for the parent (except for the top node)
- //if (useparent == true && elem.ParentNode.Name != "RO_Root")
- // startelem = (VlnXmlElement) elem.ParentNode;
-
- // if this element doesn't have any fields in use, walk up the tree until
- // we find them.
- string FieldsInUse="";
- if (startelem.HasAttribute(strFieldsInUse) == false)
- {
- VlnXmlElement parent;
- parent = (VlnXmlElement) startelem.ParentNode;
- while (parent != null && FieldsInUse == "")
- {
- FieldsInUse = parent.GetAttribute(strFieldsInUse);
- if (parent.Name != "RO_Root")
- parent = (VlnXmlElement) parent.ParentNode;
- else
- parent = null;
- }
- }
- else
- FieldsInUse = startelem.GetAttribute(strFieldsInUse);
-
- origFieldsInUse = FieldsInUse; // make a copy to compare to later.
- ArrayList inuse = new ArrayList();
- // if there are no fields in use (may be inserting a top group)
- // return an empty list.
- if (FieldsInUse=="") return inuse;
-
- // Go through the FieldsInUse list and move elements from the avail list
- // to the inuse list
- int strpos = 0;
- string recid;
- recid = FieldsInUse.Substring(strpos,8);
- MyRecID = recid;
- while (recid != null)
- {
- // find it in avail list. Remove it from there & add to inuse list
- for(int i=0; i FieldsInUse.Length)
- recid = null;
- else
- {
- recid = FieldsInUse.Substring(strpos,8);
- }
- }
- return inuse;
- }
-
- private string CvtUserFldToFld(string fldname)
- {
- if (fldname.Length < 2)
- return fldname;
- // a digit cannot start an xml fieldname, prepend a "__" to it.
- string tmp0;
- if (char.IsDigit(fldname,0))
- tmp0 = "__" + fldname;
- else
- tmp0 = fldname;
- // an xml fieldname cannot have a space, change it to a "__"
- string tmpstr = tmp0.Replace(" ","__");
- int len = tmpstr.Length;
- int cnt = 0;
-
- // this is also our sequence that tells us the follow 3 digits is the ascii number (base 10)
- // of the character we replaced.
- string OKpunch = "-._";
-
- string outstr = "";
- int decval;
-
- while (cnt < len)
- {
- char tmpchr = tmpstr[cnt];
- if(!char.IsLetterOrDigit(tmpchr)&& (OKpunch.IndexOf(tmpchr) == -1) )
- {
- decval = tmpchr;
- outstr += OKpunch + decval.ToString("D3");
- }
- else
- {
- outstr += tmpchr.ToString();
- }
- cnt++;
- }
- return outstr;
- }
-
- private string CvtFldToUserFld(string fldname)
- {
- string tmpstr0;
- if (fldname.Length < 2) return fldname;
- // an xml element name cannot begin with a digit. we had prepended a "__"
- if (fldname.Substring(0,2) == "__" && char.IsDigit(fldname,2))
- tmpstr0 = fldname.Substring(2,fldname.Length-2);
- else
- tmpstr0 = fldname;
- // an xml element name cannot have a space, we converted to a "__"
- string tmpstr = tmpstr0.Replace("__"," ");
- int len = tmpstr.Length;
- int cur = 0;
-
- // this is also our sequence that tells us the follow 3 digits is the ascii number (base 10)
- // of the character we replaced.
- string OKpunch = "-._";
-
- string outstr = "";
- int decval, indx;
- if (tmpstr.Length <6)
- indx = -1;
- else
- indx=tmpstr.IndexOf(OKpunch,cur);
- string asc_spchar;
- while (indx>=0)
- {
- outstr += tmpstr.Substring(cur,indx-cur);
- asc_spchar = tmpstr.Substring(indx+3,3);
- decval = System.Convert.ToInt16(asc_spchar,10);
- outstr += System.Convert.ToChar(decval).ToString();
- cur = indx+6;
- if (cur+6 > len)
- indx = -1;
- else
- indx = tmpstr.IndexOf(OKpunch,cur);
- }
- if (cur= 0) // is this field being used?
- {
-// rof = new ROField(name, RecID, null, 0);
- ftype |= GetFSTreturnType(System.Convert.ToUInt16(rof.ParseFieldType(Info)),tmpname,elem);
-// ftype |= System.Convert.ToUInt16(rof.ParseFieldType(Info));
- }
- }
- }
- else
- {
- // references master, but what we need is here: the field name and
- // the the field type. Just parse this from the info field.
- string parsename;
- string strftype;
- strftype = Info.Substring(9,3);
- parsename = Info.Substring(13,Info.Length-13);
- if (strftype.Equals("128")) // is it a combo type?
- parsename = parsename.Substring(0,parsename.Length-1);
-
- if (FldsUsed.BinarySearch(parsename) >= 0) // is this field being used?
- {
- ftype |= GetFSTreturnType(System.Convert.ToUInt16(Info.Substring(9,3)),parsename,elem);
-// ftype |= System.Convert.ToUInt16(Info.Substring(9,3));
- }
- }
- }
- DBE.ReaderClose();
- DBE.CommandDispose();
-
- return ftype;
- }
-***/
-
- public ushort RODB_GetFieldType(VlnXmlElement elem, string TableName, string Fld)
- {
- string strGetFields;
- string Info;
- string RecID;
- string name;
- string tmpname;
- ushort ftype = 0;
- ROField rof;
- if(TableName != lastTable)
- {
- lastTable=TableName;
- dicFldTypes=new HybridDictionary();
+ lastTable = TableName;
+ dicFldTypes = new HybridDictionary();
// select all of the field definition records in this table.
// strGetFields = "SELECT RecID, Info from " + elem.GetAttribute("Table");
strGetFields = "SELECT RecID, Info from " + TableName;
strGetFields = strGetFields + " where RecType = 2"; // + rtype.ToString();
DBE.Command(strGetFields);
DBE.Reader();
-
+
// NOTE !!!!
// This function does not handle Combo type fields (128).
while (DBE.Read())// && ftype == 0)
@@ -2156,7 +2141,7 @@ namespace RODBInterface
Info = DBE.GetString(1);
// it's defined in the local table if the first character is "<" which starts
// the schema definition string.
- if ("<" == Info.Substring(0,1))
+ if ("<" == Info.Substring(0, 1))
{
name = ParseEleName(Info);
if (name != null)
@@ -2164,10 +2149,10 @@ namespace RODBInterface
tmpname = CvtUserFldToFld(name);
//if (tmpname.Equals(Fld))
//{
- rof = new ROField(name, RecID, null, 0);
- // uint tmpfldtype = rof.ParseFieldType(Info);
- ftype = GetFSTreturnType(System.Convert.ToUInt16(rof.ParseFieldType(Info)),tmpname,elem);
- dicFldTypes[tmpname]=ftype;
+ rof = new ROField(name, RecID, null, 0);
+ // uint tmpfldtype = rof.ParseFieldType(Info);
+ ftype = GetFSTreturnType(System.Convert.ToUInt16(rof.ParseFieldType(Info)), tmpname, elem);
+ dicFldTypes[tmpname] = ftype;
//}
}
}
@@ -2178,11 +2163,11 @@ namespace RODBInterface
string parsename;
// string strftype;
// strftype = Info.Substring(9,3);
- parsename = Info.Substring(13,Info.Length-13);
+ parsename = Info.Substring(13, Info.Length - 13);
//if (parsename.Equals(Fld))
//{
- ftype = GetFSTreturnType(System.Convert.ToUInt16(Info.Substring(9,3)),parsename,elem);
- dicFldTypes[parsename]=ftype;
+ ftype = GetFSTreturnType(System.Convert.ToUInt16(Info.Substring(9, 3)), parsename, elem);
+ dicFldTypes[parsename] = ftype;
//}
}
@@ -2191,24 +2176,32 @@ namespace RODBInterface
DBE.ReaderClose();
DBE.CommandDispose();
}
- ftype = ((ushort) dicFldTypes[Fld]);
+ ftype = ((ushort)dicFldTypes[Fld]);
return ftype;
}
- private string _MyDBID;
- public string MyDBID
- {
- get { return _MyDBID; }
- set { _MyDBID = value; }
- }
- private string _MyRecID;
- public string MyRecID
- {
- get { return _MyRecID; }
- set { _MyRecID = value; }
- }
+
// For the given element's table, get all of the RO fields defined in this table.
- public ArrayList RODB_GetFields(VlnXmlElement elem, uint rtype)
+ public override ArrayList RODB_GetFields(VlnXmlElement elem, uint rtype)
{
+ string table = elem.GetAttribute("Table");
+ if (!FieldDefinitions.ContainsKey(table))
+ FieldDefinitions.Add(table, RODB_GetFieldsFromDB(elem));
+ return FieldDefinitions[table];
+ }
+ private Dictionary _FieldDefinitions = null;
+
+ public Dictionary FieldDefinitions
+ {
+ get
+ {
+ if (_FieldDefinitions == null) _FieldDefinitions = new Dictionary();
+ return _FieldDefinitions;
+ }
+ set { _FieldDefinitions = value; }
+ }
+ private ArrayList RODB_GetFieldsFromDB(VlnXmlElement elem)
+ {
+ ShowCount.GetFields++;
ArrayList retlist = new ArrayList();
string strGetFields;
string Info;
@@ -2222,15 +2215,16 @@ namespace RODBInterface
strGetFields = strGetFields + " where RecType = 2"; // + rtype.ToString();
DBE.Command(strGetFields);
DBE.Reader();
-
+
while (DBE.Read())
{
+ ShowCount.RoFields++;
RecID = DBE.GetString(0);
MyRecID = RecID;
Info = DBE.GetString(1);
// it's defined in the local table if the first character is "<" which starts
// the schema definition string.
- if ("<" == Info.Substring(0,1))
+ if ("<" == Info.Substring(0, 1))
{
name = ParseEleName(Info);
if (name != null)
@@ -2239,7 +2233,7 @@ namespace RODBInterface
rof = new ROField(name, RecID, null, 0);
ftype = rof.ParseFieldType(Info);
rof.SetFieldType(ftype);
- retlist.Add((object) rof);
+ retlist.Add((object)rof);
}
}
@@ -2250,20 +2244,20 @@ namespace RODBInterface
string parsename;
string masterrecid;
string strftype;
- masterrecid = Info.Substring(0,8);
- strftype = Info.Substring(9,3);
- ftype = System.Convert.ToUInt32(Info.Substring(9,3));
- parsename = CvtFldToUserFld(Info.Substring(13,Info.Length-13));
-
+ masterrecid = Info.Substring(0, 8);
+ strftype = Info.Substring(9, 3);
+ ftype = System.Convert.ToUInt32(Info.Substring(9, 3));
+ parsename = CvtFldToUserFld(Info.Substring(13, Info.Length - 13));
+
// if we have a choice element, remove the last character (it was added to the
// field names in order to allow for unique fields names for the choice items.
- if (ftype == (uint) FieldTypes.Combination)
+ if (ftype == (uint)FieldTypes.Combination)
{
- string tparsename = parsename.Remove((parsename.Length)-1,1); // remove the choice string and the space
+ string tparsename = parsename.Remove((parsename.Length) - 1, 1); // remove the choice string and the space
parsename = tparsename;
}
rof = new ROField(parsename, RecID, masterrecid, ftype);
- retlist.Add((object) rof);
+ retlist.Add((object)rof);
}
}
DBE.ReaderClose();
@@ -2271,7 +2265,7 @@ namespace RODBInterface
return retlist;
}
- public string RODB_GetSchemaPiece(string Recid, string table)
+ public override string RODB_GetSchemaPiece(string Recid, string table)
{
string strGetSchemaPiece;
string Info;
@@ -2284,10 +2278,10 @@ namespace RODBInterface
Info = null;
DBE.ReaderClose();
DBE.CommandDispose();
- return Info.Replace("'","\'");
+ return Info.Replace("'", "\'");
}
- public bool RODB_NewSchemaPiece(string recid, string parentid, string table, string schpiece, uint rtype)
+ public override bool RODB_NewSchemaPiece(string recid, string parentid, string table, string schpiece, uint rtype)
{
string strSchemaPiece;
bool success = true;
@@ -2298,8 +2292,8 @@ namespace RODBInterface
// RecordType of 4 is no longer used, all fields (whether schema or group) are defined
// as RecordTYpe of 2.
//strSchemaPiece = strSchemaPiece + recid + "', " + rtype.ToString() + ", '" + parentid + "', '" + dt + "', '" + schpiece.Replace("\'","'") + "');";
- strSchemaPiece = strSchemaPiece + recid + "', 2, '" + parentid + "', '" + dt + "', '" + schpiece.Replace("\'","'") + "');";
-
+ strSchemaPiece = strSchemaPiece + recid + "', 2, '" + parentid + "', '" + dt + "', '" + schpiece.Replace("\'", "'") + "');";
+
DBE.Command(strSchemaPiece);
try
{
@@ -2316,12 +2310,12 @@ namespace RODBInterface
return success;
}
- public bool RODB_WriteSchemaPiece(string Recid, string table, string schpiece)
+ public override bool RODB_WriteSchemaPiece(string Recid, string table, string schpiece)
{
string strWriteSchemaPiece;
bool success = true;
string dt = string.Format("{0:yyyyMMddHHmmss}", System.DateTime.Now);
- strWriteSchemaPiece = "UPDATE " + table + " SET " + table + ".Info = '" + schpiece.Replace("\'","'") + "'";
+ strWriteSchemaPiece = "UPDATE " + table + " SET " + table + ".Info = '" + schpiece.Replace("\'", "'") + "'";
strWriteSchemaPiece = strWriteSchemaPiece + ", ModDateTime = '" + dt + "' WHERE RecID = '" + Recid + "';";
try
{
@@ -2338,63 +2332,10 @@ namespace RODBInterface
return success;
}
- // Create a new field record in master and reference in the current table.
- // pass in current rodb object, the xml element creating and editlevel
- // is a recordType of either Group (group field definitions) or rro for
- // the ro definition. the string apd represents an append string which is
- // appended to the fieldname for combo types, otherwise it's null
- public bool RODB_NewFieldRecord(ROField myrof, VlnXmlElement myelem, string strschema, uint editlevel, string apd)
+ public override bool RODB_ProcessRROFieldChange(VlnXmlElement child, string oldname, string newname, uint editlevel,
+ VlnStatusMessage StatMsgWindow, bool combofield)
{
- bool success;
- // get a new record id for this and save it in the master table.
- string mrecid = RODB_GetNextRecId("ROMaster");
- // get recid in ROMaster for group, so that we can set the parent field.
- // walk up the tree until we find a 'MasterRecID' attribute.
- VlnXmlElement parent;
- parent = myelem;
- while (parent != null)
- {
- if (parent.HasAttribute("MasterRecID")) break;
- parent = (VlnXmlElement) parent.ParentNode;
- }
- success = RODB_NewSchemaPiece(mrecid,parent.GetAttribute("MasterRecID"),"ROMaster", strschema, editlevel);
- if (success != true) return false;
- // also reference it from the local table.
- string lrecid = RODB_GetNextRecId(myelem.GetAttribute("Table"));
- myrof.SetRecID(lrecid);
- myrof.SetMasterRecID(mrecid);
- StringBuilder strbld = new StringBuilder();
- strbld.Append(mrecid);
- strbld.Append(" ");
- string strtype = myrof.GetFieldType.ToString();
- strbld.Append(strtype.PadLeft(3,'0'));
- strbld.Append(" ");
- strbld.Append(myrof.MakeFieldName(myrof.GetFieldname));
- if (apd != null) strbld.Append(apd);
- // Need ParentID field, get by looking up xml tree to find parentID attribute = "00000000", then
- // use this recid.
- parent = myelem;
- while (parent.GetAttribute("ParentID") != "00000000")
- {
- parent = (VlnXmlElement) parent.ParentNode;
- }
- success = RODB_NewSchemaPiece(lrecid,parent.GetAttribute("RecID"), myelem.GetAttribute("Table"), strbld.ToString(), editlevel);
- return success;
- }
-
- private string DoCmbFieldReplace(string repstring, string oname, string nname, string letter)
- {
- string cmboname, cmbnname;
- cmboname = oname.Insert(oname.Length-1,letter);
- cmbnname = nname.Insert(nname.Length-1,letter);
- return (repstring.Replace(cmboname,cmbnname));
- }
-
- private bool RODB_ProcessRROFieldChange(VlnXmlElement child, string oldname, string newname, uint editlevel,
- VlnStatusMessage StatMsgWindow, bool combofield)
- {
-
bool success;
string str;
string info;
@@ -2412,7 +2353,7 @@ namespace RODBInterface
nnameClose = "" + newname + ">";
dt = string.Format("{0:yyyyMMddHHmmss}", System.DateTime.Now);
try
- {
+ {
// first do the string replace for the group node. This will change any
// attributes which may have changed.
str = "SELECT Info From " + child.GetAttribute("Table") + " where (RecID = '" + child.GetAttribute("RecID") + "')";
@@ -2438,7 +2379,7 @@ namespace RODBInterface
DBE.Reader();
DBE.ReaderClose();
DBE.CommandDispose();
- if (child.Name == "vlnGroup"&&child.ParentNode.Name != "RO_Root")
+ if (child.Name == "vlnGroup" && child.ParentNode.Name != "RO_Root")
{
XmlNodeList nodeList;
nodeList = child.SelectNodes(oldname);
@@ -2446,7 +2387,7 @@ namespace RODBInterface
{
XmlNode newnode = ROXml.CreateNode(XmlNodeType.Element, newname, "");
newnode.InnerXml = nod.InnerXml;
- child.ReplaceChild(newnode,nod);
+ child.ReplaceChild(newnode, nod);
}
}
// if at top, replace strings in attributes for xml node. Only needs done
@@ -2488,15 +2429,15 @@ namespace RODBInterface
}
// if this was an RO field definition change, need to go through the XML for
// the ROs too.
- if (editlevel == (uint) RecordType.Schema)
+ if (editlevel == (uint)RecordType.Schema)
{
- XmlNode chldnode = (XmlNode) child.FirstChild;
+ XmlNode chldnode = (XmlNode)child.FirstChild;
VlnXmlElement echild;
while (chldnode != null)
{
if (chldnode is VlnXmlElement)
{
- echild = (VlnXmlElement) chldnode;
+ echild = (VlnXmlElement)chldnode;
if (echild.Name != "vlnGroup")
{
// If this is a group defintion subtree it will only have one
@@ -2517,9 +2458,9 @@ namespace RODBInterface
info = null;
DBE.ReaderClose();
DBE.CommandDispose();
- if (combofield==false)
+ if (combofield == false)
{
- tinfo1 = info.Replace(onameOpen,nnameOpen);
+ tinfo1 = info.Replace(onameOpen, nnameOpen);
tinfo2 = tinfo1.Replace(onameClose, nnameClose);
XmlNodeList nodeList;
nodeList = echild.SelectNodes(oldname);
@@ -2527,7 +2468,7 @@ namespace RODBInterface
{
XmlNode newnode = ROXml.CreateNode(XmlNodeType.Element, newname, "");
newnode.InnerXml = nod.InnerXml;
- echild.ReplaceChild(newnode,nod);
+ echild.ReplaceChild(newnode, nod);
}
}
else // need a,b,c,d yikes
@@ -2543,15 +2484,15 @@ namespace RODBInterface
tinfo2 = DoCmbFieldReplace(nmc, onameClose, nnameClose, "d");
// replace the combo nodes with the new name, do a-d in case there are more than
// one value field stored for this combo type
- for (char tmplet = 'a';tmplet < 'e'; tmplet++)
+ for (char tmplet = 'a'; tmplet < 'e'; tmplet++)
{
XmlNodeList nodeList;
- nodeList = echild.SelectNodes(oldname+tmplet.ToString());
+ nodeList = echild.SelectNodes(oldname + tmplet.ToString());
foreach (XmlNode nod in nodeList)
{
- XmlNode newnode = ROXml.CreateNode(XmlNodeType.Element, newname+tmplet, "");
+ XmlNode newnode = ROXml.CreateNode(XmlNodeType.Element, newname + tmplet, "");
newnode.InnerXml = nod.InnerXml;
- echild.ReplaceChild(newnode,nod);
+ echild.ReplaceChild(newnode, nod);
}
}
}
@@ -2563,7 +2504,7 @@ namespace RODBInterface
DBE.Reader();
DBE.ReaderClose();
DBE.CommandDispose();
-
+
}
}
}
@@ -2575,155 +2516,31 @@ namespace RODBInterface
catch (Exception e)
{
success = false;
- MessageBox.Show(e.Message,"Database Update Error");
+ MessageBox.Show(e.Message, "Database Update Error");
}
return success;
}
- // RODB_UpdateNamesInROs: goes through subtree (top node is 'fld') and if this
- // updated field is used (either in [Group]FieldsInUse or was used in parent, then
- // 1) if group node, check for attributes using "" and if found, update
- // to "
- // 2) if group edit, modify this node's xml data with the new fieldname,
- // otherwise, edit 'ROs' under this to replace with
- // Input: VlnXmlElement fld: start processing at this node.
- // string myrecid: local recid to be used for check to see if used (in FieldsInUse
- // or GroupFieldsInUse.
- // string oldname, newname - old and new field names
- // string myrecid - local record storing field name
- // uint editlevel - if editting groups, do check for for item 1 above in
- // Group attributes, otherwise do in
- // bool parentused - set to false from caller, this is recursive and will
- // be set appropriately for recursive calls.
- public bool RODB_UpdateFieldNames(VlnXmlElement fld, string myrecid, string oldname,
- string newname, uint editlevel, bool parentused, VlnStatusMessage StatMsgWindow, bool combofield)
- {
- bool success;
- bool useAtLevel = false;
- XmlNode node;
- VlnXmlElement child;
- string fldinuse;
-
- if (editlevel == (uint)RecordType.Schema)
- fldinuse = "FieldsInUse";
- else
- fldinuse = "GroupFieldsInUse";
-
- // Do the current level before walking through any children groups.
- if (fld.Name == "vlnGroup")
- {
- if (fld.HasAttribute(fldinuse))
- {
- // if recid not in here, don't process for this node.
- string fiu = fld.GetAttribute(fldinuse);
- if (fiu.IndexOf(myrecid) >= 0) useAtLevel = true;
- }
- if (useAtLevel==true || parentused==true) useAtLevel = true;
-
- if (useAtLevel == true)
- {
- string haskids, kidsloaded;
- haskids = fld.GetAttribute("HasChild");
- kidsloaded = fld.GetAttribute("ChildLoaded");
- if (haskids == "True" && kidsloaded == "False" )
- {
- success = RODB_GetChildData(fld,true);
- if (success == false) return false;
- fld.SetAttribute("ChildLoaded","True");
- }
- parentused = true; // for kids of this group.
-
- success = RODB_ProcessRROFieldChange(fld, oldname, newname, editlevel, StatMsgWindow, combofield);
- if (success==false) return false;
- }
- }
- node = (XmlNode) fld.FirstChild;
- while (node != null)
- {
- if (node is VlnXmlElement)
- {
- useAtLevel=false;
- child = (VlnXmlElement) node;
-
- // If this is a group menu edit, process group nodes, by recursive
- // call and then modify data on group record.
- // For both, when hitting a group node, check that it either doesn't
- // have 'FieldsInUse' or 'GroupFieldsInUse' or that if it does,
- // this record id is in the list -> only process these, otherwise
- // the field is not used.
- if (child.Name == "vlnGroup")
- {
- // see if inuse for this one, either defined here or from parent.
- if (child.HasAttribute(fldinuse))
- {
- // if recid not in here, don't process for this node. Still
- // need to check children because they may redefine fields in use.
- string fiu = child.GetAttribute(fldinuse);
- if (fiu.IndexOf(myrecid) >= 0) useAtLevel = true;
- }
- if (useAtLevel == false && parentused == true) useAtLevel = true;
-
- // update this record if it doesn't have it's own , then do kids
- // of it.
- success = RODB_UpdateFieldNames(child, myrecid, oldname, newname,editlevel,useAtLevel, StatMsgWindow, combofield);
-
- if (success == false) return false;
- }
- }
- node = node.NextSibling;
- }
- // now update ROs at this level, only if RO mods (not group).
- //if (parentused && editlevel==(uint)RecordType.Schema)
- //{
- // success = RODB_ProcessRROFieldChange(fld, oldname, newname, editlevel);
- // if (success==false) return false;
- //}
- return true;
- }
-
- // check if the name entered is one used for setting up
- // the new graphics or setpoint databases.
- private bool RODB_CheckForStandardName(string oname)
- {
- string oldname = CvtFldToUserFld(oname);
- if (oldname.CompareTo("Name") == 0) return true;
- if (oldname.CompareTo("Image ID") == 0) return true;
- if (oldname.CompareTo("Image") == 0) return true;
- if (oldname.CompareTo("Setpoint ID") == 0) return true;
- if (oldname.CompareTo("Setpoint Value") == 0) return true;
- if (oldname.CompareTo("Associated System/Component") == 0) return true;
- if (oldname.CompareTo("Applicability") == 0) return true;
- if (oldname.CompareTo("Revision") == 0) return true;
- if (oldname.CompareTo("Short Description") == 0) return true;
- if (oldname.CompareTo("Description") == 0) return true;
- if (oldname.CompareTo("Key Assumptions") == 0) return true;
- if (oldname.CompareTo("Basis") == 0) return true;
- if (oldname.CompareTo("References") == 0) return true;
- if (oldname.CompareTo("Group") == 0) return true;
- if (oldname.CompareTo("Parameter") == 0) return true;
- return false;
- }
-
- public bool RODB_UpdateFieldRecord(ROField myrof, VlnXmlElement myelem, string strschema,
+ public override bool RODB_UpdateFieldRecord(ROField myrof, VlnXmlElement myelem, string strschema,
string oldname, string newname, uint editlevel, bool combofield)
{
- bool success=false;
+ bool success = false;
// If this is a generic definition that was modified, i.e. from ROMaster, ask
// the user whether to update the generic field definition or make it local.
- if (myrof.GetMasterRecID != null)
+ if (myrof.GetMasterRecID != null)
{
// if field is defined in the ROMaster, and we change the field name -
// first check if it is using one of the names used to define new
// setpoint or graphics databases. If so, make it a local change only!
-
+
bool changegeneric = true;
if (oldname != newname)
{
// if this is one of the standard names - don't let them save it.
- bool isused=RODB_CheckForStandardName(oldname);
+ bool isused = RODB_CheckForStandardName(oldname);
if (isused == true)
{
- MessageBox.Show("The field name is used to define new Setpoints or Graphics Database.\n The update will be for this local (database) group only.","Field name modification.");
+ MessageBox.Show("The field name is used to define new Setpoints or Graphics Database.\n The update will be for this local (database) group only.", "Field name modification.");
changegeneric = false;
}
}
@@ -2732,13 +2549,13 @@ namespace RODBInterface
// or not.
if (changegeneric != false)
{
- System.Windows.Forms.DialogResult result = MessageBox.Show ("Update Generic definition?", "Referenced Object Definition",
+ System.Windows.Forms.DialogResult result = MessageBox.Show("Update Generic definition?", "Referenced Object Definition",
MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (result == DialogResult.No) changegeneric = false;
}
if (changegeneric == true)
{
- success = RODB_WriteSchemaPiece(myrof.GetMasterRecID,"ROMaster", strschema);
+ success = RODB_WriteSchemaPiece(myrof.GetMasterRecID, "ROMaster", strschema);
if (success != true) return false;
// if change in fieldname, need to go through all of the databases to
// adjust for it.
@@ -2748,7 +2565,7 @@ namespace RODBInterface
// get root xml element
// loop through each subgroup under root.
VlnXmlElement topgroup;
- topgroup = (VlnXmlElement) ROXml.FirstChild.FirstChild;
+ topgroup = (VlnXmlElement)ROXml.FirstChild.FirstChild;
string sqlstr, recid, tbl;
while (topgroup != null)
{
@@ -2766,22 +2583,22 @@ namespace RODBInterface
DBE.ReaderClose();
DBE.CommandDispose();
if (recid != null)
- {
+ {
// update the local field definition record
StringBuilder strbld = new StringBuilder();
strbld.Append(myrof.GetMasterRecID);
strbld.Append(" ");
string strtype = myrof.GetFieldType.ToString();
- strbld.Append(strtype.PadLeft(3,'0'));
+ strbld.Append(strtype.PadLeft(3, '0'));
strbld.Append(" ");
strbld.Append(myrof.MakeFieldName(myrof.GetFieldname));
- success = RODB_WriteSchemaPiece(recid,topgroup.GetAttribute("Table"), strbld.ToString());
+ success = RODB_WriteSchemaPiece(recid, topgroup.GetAttribute("Table"), strbld.ToString());
topgroup.SetAttribute("TreeNotData", "True");
// Update subelements too.
if (success == true)
success = RODB_UpdateFieldNames(topgroup, recid, oldname, newname, editlevel, false, StatMsgWindow, combofield);
- topgroup = (VlnXmlElement) topgroup.NextSibling;
+ topgroup = (VlnXmlElement)topgroup.NextSibling;
}
}
StatMsgWindow.Dispose();
@@ -2790,7 +2607,7 @@ namespace RODBInterface
else // change local
{
// modify the current to have the definition local.
- success=RODB_WriteSchemaPiece(myrof.GetRecID,myelem.GetAttribute("Table"), strschema);
+ success = RODB_WriteSchemaPiece(myrof.GetRecID, myelem.GetAttribute("Table"), strschema);
// get top group node in tree. and from there process fields if
// there was a change in fieldname text
if (success == true && oldname != newname)
@@ -2800,10 +2617,10 @@ namespace RODBInterface
VlnXmlElement parent, startEle;
parent = myelem;
startEle = myelem;
- while(parent.Name != "RO_Root")
+ while (parent.Name != "RO_Root")
{
startEle = parent;
- parent = (VlnXmlElement) parent.ParentNode;
+ parent = (VlnXmlElement)parent.ParentNode;
}
startEle.SetAttribute("TreeNotData", "True");
success = RODB_UpdateFieldNames(startEle, myrof.GetRecID, oldname, newname, editlevel, false, StatMsgWindow, combofield);
@@ -2813,7 +2630,7 @@ namespace RODBInterface
}
else
{
- success = RODB_WriteSchemaPiece(myrof.GetRecID,myelem.GetAttribute("Table"),strschema);
+ success = RODB_WriteSchemaPiece(myrof.GetRecID, myelem.GetAttribute("Table"), strschema);
// changed the fieldname, change xml text.
if (success == true && oldname != newname)
{
@@ -2822,10 +2639,10 @@ namespace RODBInterface
VlnXmlElement parent, startEle;
parent = myelem;
startEle = myelem;
- while(parent.Name != "RO_Root")
+ while (parent.Name != "RO_Root")
{
startEle = parent;
- parent = (VlnXmlElement) parent.ParentNode;
+ parent = (VlnXmlElement)parent.ParentNode;
}
startEle.SetAttribute("TreeNotData", "True");
success = RODB_UpdateFieldNames(startEle, myrof.GetRecID, oldname, newname, editlevel, false, StatMsgWindow, combofield);
@@ -2833,9 +2650,9 @@ namespace RODBInterface
}
}
return success;
- }
+ }
- public XmlSchema RODB_GetGroupSchema(VlnXmlElement elem)
+ public override XmlSchema RODB_GetGroupSchema(VlnXmlElement elem)
{
XmlSchema myschema;
@@ -2847,20 +2664,20 @@ namespace RODBInterface
parent = elem;
else
parent = elem;
-// bug fix B2004-008
-// need to use the current node's group definition all the time
-// parent = (VlnXmlElement) elem.ParentNode;
- while (parent != null)
+ // bug fix B2004-008
+ // need to use the current node's group definition all the time
+ // parent = (VlnXmlElement) elem.ParentNode;
+ while (parent != null)
{
if (parent.HasAttribute("GroupFieldsInUse") == true) break;
// if we've looped to the top, just set the parent to null. (B2004-015)
if (parent.ParentNode is VlnXmlElement)
- parent = (VlnXmlElement) parent.ParentNode;
+ parent = (VlnXmlElement)parent.ParentNode;
else
parent = null;
}
-
+
if (parent == null) return null;
// The group schema never gets saved as an attribute. it's always read in, because
// it's not used as often as the ro schema. So for the Group Schema, we're looking
@@ -2875,7 +2692,7 @@ namespace RODBInterface
// For each item in use, get its xmlschema text. If unique to this group, the definition
// exists local to this table. Otherwise, go back to the master.
string recid;
- recid = GroupFieldsInUse.Substring(0,8);
+ recid = GroupFieldsInUse.Substring(0, 8);
while (recid != null)
{
strGetSchemaPiece = "SELECT Info From " + elem.GetAttribute("Table") + " where (RecID = '" + recid + "')";
@@ -2887,14 +2704,14 @@ namespace RODBInterface
// if the info string has "<", i.e. an opening XML schema bracket, use
// this text as the field definition, otherwise, go to the master to get
// it.
- if ("<" == Info.Substring(0,1))
+ if ("<" == Info.Substring(0, 1))
{
// use this field definition, else get from the master.
entireschema = entireschema + Info;
}
else
{
- string recidpart = Info.Substring(0,8);
+ string recidpart = Info.Substring(0, 8);
strGetSchemaPiece = "SELECT Info From RoMaster where (RecID = '" + recidpart + "')";
DBE.ReaderClose();
DBE.CommandDispose();
@@ -2912,16 +2729,16 @@ namespace RODBInterface
if (strpos > GroupFieldsInUse.Length)
recid = null;
else
- recid = GroupFieldsInUse.Substring(strpos,8);
+ recid = GroupFieldsInUse.Substring(strpos, 8);
}
DBE.ReaderClose();
DBE.CommandDispose();
}
entireschema = schemastart + entireschema + schemaend;
- XmlTextReader schemareader = new XmlTextReader(entireschema,XmlNodeType.Element,null);
+ XmlTextReader schemareader = new XmlTextReader(entireschema, XmlNodeType.Element, null);
try
{
- myschema = XmlSchema.Read(schemareader,null);
+ myschema = XmlSchema.Read(schemareader, null);
return myschema;
}
catch (Exception e)
@@ -2931,7 +2748,7 @@ namespace RODBInterface
}
}
- public XmlSchema RODB_GetSchema(VlnXmlElement elem)
+ public override XmlSchema RODB_GetSchema(VlnXmlElement elem)
{
XmlSchema myschema;
@@ -2946,15 +2763,15 @@ namespace RODBInterface
}
else
{
- parent = (VlnXmlElement) nparent;
- while (parent != null)
+ parent = (VlnXmlElement)nparent;
+ while (parent != null)
{
if (parent.HasAttribute("Schema") == true) break;
if (parent.HasAttribute("FieldsInUse") == true) break;
- parent = (VlnXmlElement) parent.ParentNode;
+ parent = (VlnXmlElement)parent.ParentNode;
}
}
-
+
// if the schema has already been read in, just use it from the schema attribute,
// otherwise, read in schema definitions for those 'FieldsInUse'.
if (parent.HasAttribute("Schema"))
@@ -2972,7 +2789,7 @@ namespace RODBInterface
// For each item in use, get its xmlschema text. If unique to this group, the definition
// exists local to this table. Otherwise, go back to the master.
string recid;
- recid = FieldsInUse.Substring(0,8);
+ recid = FieldsInUse.Substring(0, 8);
while (recid != null)
{
strGetSchemaPiece = "SELECT Info From " + elem.GetAttribute("Table") + " where (RecID = '" + recid + "')";
@@ -2984,15 +2801,15 @@ namespace RODBInterface
// if the info string has "<", i.e. an opening XML schema bracket, use
// this text as the field definition, otherwise, go to the master to get
// it.
- if ("<" == Info.Substring(0,1))
+ if ("<" == Info.Substring(0, 1))
{
// use this field definition, else get from the master.
entireschema = entireschema + Info;
}
else
{
- string recidpart = Info.Substring(0,8);
- string localfieldname = Info.Substring(13,Info.Length-13);
+ string recidpart = Info.Substring(0, 8);
+ string localfieldname = Info.Substring(13, Info.Length - 13);
strGetSchemaPiece = "SELECT Info From RoMaster where (RecID = '" + recidpart + "')";
DBE.ReaderClose();
DBE.CommandDispose();
@@ -3004,10 +2821,10 @@ namespace RODBInterface
string goodname;
Info = DBE.GetString(0);
int indx1 = Info.IndexOf("\"");
- int indx2 = Info.IndexOf("\"",indx1+1);
- string masterfieldname = Info.Substring(indx1+1,indx2-indx1-1);
+ int indx2 = Info.IndexOf("\"", indx1 + 1);
+ string masterfieldname = Info.Substring(indx1 + 1, indx2 - indx1 - 1);
if (localfieldname != masterfieldname)
- goodname = Info.Replace(masterfieldname,localfieldname);
+ goodname = Info.Replace(masterfieldname, localfieldname);
else
goodname = Info;
@@ -3020,33 +2837,33 @@ namespace RODBInterface
if (strpos > FieldsInUse.Length)
recid = null;
else
- recid = FieldsInUse.Substring(strpos,8);
+ recid = FieldsInUse.Substring(strpos, 8);
}
}
DBE.ReaderClose();
DBE.CommandDispose();
entireschema = schemastart + entireschema + schemaend;
}
-
- XmlTextReader schemareader = new XmlTextReader(entireschema,XmlNodeType.Element,null);
+
+ XmlTextReader schemareader = new XmlTextReader(entireschema, XmlNodeType.Element, null);
try
{
- myschema = XmlSchema.Read(schemareader,null);
- parent.SetAttribute("Schema",entireschema);
+ myschema = XmlSchema.Read(schemareader, null);
+ parent.SetAttribute("Schema", entireschema);
return myschema;
}
catch (Exception e)
{
- MessageBox.Show(e.Message,"Schema Read Error");
+ MessageBox.Show(e.Message, "Schema Read Error");
return null;
}
}
- public int RODB_GetNumberOfROValueRecords(string tablename)
+ public override int RODB_GetNumberOfROValueRecords(string tablename)
{
// get menu fields to display here.
string strGetRoCount = "SELECT COUNT(RecType) AS NumRecs FROM " + tablename;
- strGetRoCount += " WHERE RecType = " + (uint)RecordType.RRO;
+ strGetRoCount += " WHERE RecType = " + (uint)RecordType.RRO;
DBE.Command(strGetRoCount);
DBE.Reader();
DBE.Read();
@@ -3056,11 +2873,11 @@ namespace RODBInterface
return ROCnt;
}
- public int RODB_GetNumberOfGroupRecords(string tablename)
+ public override int RODB_GetNumberOfGroupRecords(string tablename)
{
// get menu fields to display here.
string strGetGrpCount = "SELECT COUNT(RecType) AS NumRecs FROM " + tablename;
- strGetGrpCount += " WHERE RecType = " + (uint)RecordType.Group;
+ strGetGrpCount += " WHERE RecType = " + (uint)RecordType.Group;
DBE.Command(strGetGrpCount);
DBE.Reader();
DBE.Read();
@@ -3073,4 +2890,6 @@ namespace RODBInterface
}
}
+
+
\ No newline at end of file
diff --git a/PROMS/ReferencedObjects/LibSource/RODBInterface/SqlRODB.cs b/PROMS/ReferencedObjects/LibSource/RODBInterface/SqlRODB.cs
new file mode 100644
index 00000000..58ce22d8
--- /dev/null
+++ b/PROMS/ReferencedObjects/LibSource/RODBInterface/SqlRODB.cs
@@ -0,0 +1,2690 @@
+using System;
+using System.Collections;
+using System.IO;
+using System.Data;
+using System.Xml;
+using System.Xml.XPath;
+using System.Xml.Schema;
+using System.Text;
+using System.Windows.Forms;
+using DBEncapsulation;
+using ROFields;
+using VlnStatus;
+using System.Collections.Specialized;
+using Org.Mentalis.Files;
+using System.Data.SqlClient;
+using System.Text.RegularExpressions;
+using System.Collections.Generic;
+namespace RODBInterface
+{
+ public static class ShowCount // use for debugging only
+ {
+ public static int GetRootGroups = 0;
+ public static int GetChildData = 0;
+ public static int ReadRo = 0;
+ public static int GetFields = 0;
+ public static int Children = 0;
+ public static int RoFields = 0;
+ public static void OutputResults()
+ {
+ Console.WriteLine("GetRootGroups = {0}, GetChildData = {1}, ReadRo = {2}, GetFields = {3}, Children = {4}, RoFields = {5}", GetRootGroups, GetChildData, ReadRo, GetFields, Children, RoFields);
+ }
+ }
+//
+ /// C2017-003: support for sql server
+ /// The following class handles generation of sql strings to get/put requested parts of
+ /// XML RO Tree. It uses queries that are stored in the sql database that contains the ro data.
+ ///
+ public partial class SqlRODB : RODB
+ {
+ public DBEncapsulation.SQLEncap DBE_SQL;
+ public string SqlConnectionStr = null;
+
+ private SqlConnection ROAPP_SqlConnectionOnce = null;
+ public SqlConnection ROAPP_SqlConnection
+ {
+ get
+ {
+ if (OnlyConnectOnce && ROAPP_SqlConnectionOnce != null) return ROAPP_SqlConnectionOnce;
+ // Attempt to make a connection
+ SqlConnection cn = new SqlConnection(SqlConnectionStr);
+ try
+ {
+ cn.Open();
+ if (OnlyConnectOnce && ROAPP_SqlConnectionOnce == null) ROAPP_SqlConnectionOnce = cn;
+ return cn;
+ }
+ catch (SqlException ex)
+ {
+ MessageBox.Show(ex.Message, "Could Not Make Connection To Database");
+ return null;
+ }
+ }
+ }
+ public SqlRODB(string RODirectoyPath, string sqlConnectionStr, bool useConnStr)
+ {
+ SqlConnectionStr = sqlConnectionStr;
+ if (!useConnStr)
+ BuildConnectionString(RODirectoyPath, sqlConnectionStr);
+
+ DBE_SQL = new SQLEncap();
+ DBE = DBE_SQL;
+
+ try
+ {
+ strDatabaseConnectionCommand = sqlConnectionStr;
+ DBE.Connection(SqlConnectionStr);
+ }
+ catch (Exception e)
+ {
+ MessageBox.Show(e.Message, "Setup of OLEDB/ODBC");
+ }
+ }
+ #region SQL version info
+ // The following code was taken from PROMS so that the Database server can be available for the 'About' dialog and the error log:
+ private static DateTime _RevDate = DateTime.MinValue;
+ public static DateTime RevDate
+ {
+ get { return _RevDate; }
+ set { _RevDate = value; }
+ }
+ private static string _RevDescription = "Unknown";
+ public static string RevDescription
+ {
+ get { return _RevDescription; }
+ set { _RevDescription = value; }
+ }
+ private string _DBServer = null;
+ public string DBServer
+ {
+ get
+ {
+ if (_DBServer == null)
+ {
+ string cnstr = null;
+ try
+ {
+ using (SqlConnection cn = ROAPP_SqlConnection)
+ {
+ cnstr = cn.ConnectionString;
+ try
+ {
+ using (SqlCommand cmd = new SqlCommand("vesp_GetSQLCodeRevision", cn))
+ {
+ cmd.CommandType = CommandType.StoredProcedure;
+ cmd.CommandTimeout = 0;
+ SqlDataReader dr = cmd.ExecuteReader();
+ while (dr.Read())
+ {
+ _RevDate = dr.GetDateTime(0);
+ _RevDescription = dr.GetString(1);
+ }
+ }
+ }
+ catch (Exception ex)
+ {
+ _RevDate = DateTime.MinValue;
+ _RevDescription = "Unknown";
+ }
+ string server = "";
+ string db = "";
+ Match m = Regex.Match(cnstr, "Data Source=([^;]+)(;[^;]+)*;*Initial Catalog=([^;]+)(;[^;]+)*");
+ if (m.Success && m.Groups.Count > 4)
+ {
+ server = m.Groups[1].Value;
+ db = m.Groups[3].Value;
+ }
+ _DBServer = string.Format("{0} - {1} [SQL:{2:yyMM.ddHH}]", server, db, RevDate);
+ }
+ }
+ catch (Exception)
+ {
+ _DBServer = cnstr;
+ }
+ }
+ return _DBServer;
+ }
+ }
+ #endregion
+ #region overrides
+ public override string RODB_HasBeenConverted()
+ {
+ return SqlConnectionStr;
+ }
+ public override string RODB_GetDBNameForAbout()
+ {
+ int indx = DBServer.IndexOf("-");
+ return string.Format("Database: {0}", DBServer.Substring(indx + 2, DBServer.Length - indx - 2));
+ }
+ public override string RODB_GetDBServerForAbout()
+ {
+ return string.Format("SQL Server: {0}", DBServer.Substring(0, DBServer.IndexOf(" -")));
+ }
+ public override string RODB_GetNextGroupTable()
+ {
+ try
+ {
+ using (SqlConnection cn = ROAPP_SqlConnection)
+ {
+ SqlCommand command = new SqlCommand();
+ command.CommandType = CommandType.StoredProcedure;
+ command.CommandText = "getInfobyRecidRectype";
+ command.Parameters.AddWithValue("@ROTable", "ROMASTER");
+ command.Parameters.AddWithValue("@RecID", "00000001");
+ command.Parameters.AddWithValue("@RecType", (int)RecordType.Master);
+ string rettable = null;
+ string newstr = null;
+ using (SqlDataReader reader = command.ExecuteReader())
+ {
+ if (!reader.Read())
+ {
+ MessageBox.Show("Read returned null", "Getting New Group Table");
+ return null;
+ }
+ rettable = reader.GetString(0);
+ string nxttable = rettable.Substring(2, 6);
+ int ltbl = System.Convert.ToInt32(nxttable, 10);
+ ltbl++;
+ nxttable = ltbl.ToString("d6"); // this format "d6" should pad left with zeros
+ newstr = "RO" + nxttable;
+ }
+ string dt = string.Format("{0:yyyyMMddHHmmss}", System.DateTime.Now);
+ command.Parameters.Clear();
+ command.CommandText = "updateInfoByRecidRectype";
+ command.Parameters.AddWithValue("@ROTable", "ROMASTER");
+ command.Parameters.AddWithValue("@Info", newstr);
+ command.Parameters.AddWithValue("@ModDateTime", dt);
+ command.Parameters.AddWithValue("@RecID", "00000001");
+ command.Parameters.AddWithValue("@RecType", (int)RecordType.Master);
+ using (SqlDataReader reader = command.ExecuteReader())
+ {
+ return rettable;
+ }
+ }
+ }
+ catch (Exception e)
+ {
+ MessageBox.Show(e.Message, "Getting New Group Table");
+ }
+ return null;
+ }
+ public override string RODB_GetNextRecId(string table)
+ {
+ // read record type of master for this table. This is where the highest recid is stored.
+ // Update the recid by 1, write it out and return the new recid.
+ try
+ {
+ using (SqlConnection cn = ROAPP_SqlConnection)
+ {
+ SqlCommand command = new SqlCommand();
+ command.Connection = cn;
+ command.CommandType = CommandType.StoredProcedure;
+ command.CommandText = "getInfobyRecidRectype";
+ command.Parameters.AddWithValue("@ROTable", table);
+ command.Parameters.AddWithValue("@RecID", "00000000");
+ command.Parameters.AddWithValue("@RecType", (int)RecordType.Master);
+ string retrec = null;
+ string padstr = null;
+ using (SqlDataReader reader = command.ExecuteReader())
+ {
+ if (!reader.Read())
+ {
+ MessageBox.Show("Read returned null", "Getting New Record Id");
+ return null;
+ }
+ retrec = reader.GetString(0);
+ int lrecid = System.Convert.ToInt32(retrec, 16);
+ lrecid++;
+ retrec = lrecid.ToString("x");
+ // need an 8 char string so pad left with zero
+ padstr = retrec.PadLeft(8, '0');
+ }
+ string dt = string.Format("{0:yyyyMMddHHmmss}", System.DateTime.Now);
+ command.Parameters.Clear();
+ command.CommandText = "updateInfoByRecidRectype";
+ command.Parameters.AddWithValue("@ROTable", table);
+ command.Parameters.AddWithValue("@RecID", "00000000");
+ command.Parameters.AddWithValue("@Info", padstr);
+ command.Parameters.AddWithValue("@ModDateTime", dt);
+ command.Parameters.AddWithValue("@RecType", (int)RecordType.Master);
+ using (SqlDataReader reader = command.ExecuteReader())
+ {
+ return padstr;
+ }
+ }
+ }
+ catch (Exception e)
+ {
+ MessageBox.Show(e.Message, "Getting New Record Id");
+ }
+ return null;
+ }
+
+ public override bool RODB_GetRootGroups(VlnXmlElement root)
+ {
+ ShowCount.GetRootGroups++;
+ string table;
+ string group;
+ string title;
+
+ // Get menu fields to display
+ SortedList mySL = new SortedList();
+ try
+ {
+ if (OnlyConnectOnce)
+ {
+ SqlConnection cn = ROAPP_SqlConnection;
+ SqlCommand command = new SqlCommand();
+ command.Connection = cn;
+ command.CommandType = CommandType.StoredProcedure;
+ command.CommandText = "getRecidInfoByRectypeAsc";
+ command.Parameters.AddWithValue("@ROTable", "ROMaster");
+ command.Parameters.AddWithValue("@RecType", (int)RecordType.SubDatabase);
+ using (SqlDataReader reader = command.ExecuteReader())
+ {
+ while (reader.Read())
+ {
+ // Parse info string, it has group name & table name. Store in a sorted
+ // list, sorting by Group Name.
+ string mrecid = reader.GetString(0);
+ group = reader.GetString(1);
+ mySL.Add(mrecid, group);
+ }
+ }
+ }
+ else
+ {
+ using (SqlConnection cn = ROAPP_SqlConnection)
+ {
+ SqlCommand command = new SqlCommand();
+ command.Connection = cn;
+ command.CommandType = CommandType.StoredProcedure;
+ command.CommandText = "getRecidInfoByRectypeAsc";
+ command.Parameters.AddWithValue("@ROTable", "ROMaster");
+ command.Parameters.AddWithValue("@RecType", (int)RecordType.SubDatabase);
+ using (SqlDataReader reader = command.ExecuteReader())
+ {
+ while (reader.Read())
+ {
+ // Parse info string, it has group name & table name. Store in a sorted
+ // list, sorting by Group Name.
+ string mrecid = reader.GetString(0);
+ group = reader.GetString(1);
+ mySL.Add(mrecid, group);
+ }
+ }
+ }
+ }
+ }
+ catch (Exception ex)
+ {
+ MessageBox.Show(ex.Message, "Error Getting Root Groups");
+ return false;
+ }
+ // Now, for each group, i.e. table, make xml elements for the top level groups by
+ // reading in the Xml Element for the group from each table.
+ for (int i = 0; i < mySL.Count; i++)
+ {
+ group = mySL.GetByIndex(i).ToString();
+ int grnamindx = group.IndexOf("\t");
+ if (grnamindx == -1)
+ {// no tab, default to RO000001
+ table = "RO000001";
+ title = group;
+ }
+ else
+ {
+ StringBuilder tablesb = new StringBuilder(70);
+ tablesb.Append(group);
+ tablesb.Remove(0, grnamindx + 1);
+ table = tablesb.ToString();
+ title = group.Substring(0, grnamindx);
+ }
+ try
+ {
+ if (OnlyConnectOnce)
+ {
+ SqlConnection cn = ROAPP_SqlConnection;
+ SqlCommand command = new SqlCommand();
+ command.Connection = cn;
+ command.CommandType = CommandType.StoredProcedure;
+ command.CommandText = "getRecidInfoByRectypeParidAsc";
+ command.Parameters.AddWithValue("@ROTable", table);
+ command.Parameters.AddWithValue("@RecType", (int)RecordType.Group);
+ command.Parameters.AddWithValue("@ParentID", "00000000");
+ using (SqlDataReader reader = command.ExecuteReader())
+ {
+ if (reader.Read())
+ {
+ string RecID = reader.GetString(0);
+ string Info = reader.GetString(1);
+ XmlTextReader rdr = new XmlTextReader(Info, XmlNodeType.Element, null);
+ XmlNode nd = ROXml.ReadNode(rdr);
+ VlnXmlElement elem = (VlnXmlElement)nd;
+ elem.MyROID = RecID;
+ root.AppendChild(elem);
+ elem.SetAttribute("RecID", RecID);
+ elem.SetAttribute("ParentID", "00000000");
+ elem.SetAttribute("Table", table);
+ elem.SetAttribute("MasterRecID", mySL.GetKey(i).ToString());
+ }
+ }
+ }
+ else
+ {
+ using (SqlConnection cn = ROAPP_SqlConnection)
+ {
+ SqlCommand command = new SqlCommand();
+ command.Connection = cn;
+ command.CommandType = CommandType.StoredProcedure;
+ command.CommandText = "getRecidInfoByRectypeParidAsc";
+ command.Parameters.AddWithValue("@ROTable", table);
+ command.Parameters.AddWithValue("@RecType", (int)RecordType.Group);
+ command.Parameters.AddWithValue("@ParentID", "00000000");
+ using (SqlDataReader reader = command.ExecuteReader())
+ {
+ if (reader.Read())
+ {
+ string RecID = reader.GetString(0);
+ string Info = reader.GetString(1);
+ XmlTextReader rdr = new XmlTextReader(Info, XmlNodeType.Element, null);
+ XmlNode nd = ROXml.ReadNode(rdr);
+ VlnXmlElement elem = (VlnXmlElement)nd;
+ elem.MyROID = RecID;
+ root.AppendChild(elem);
+ elem.SetAttribute("RecID", RecID);
+ elem.SetAttribute("ParentID", "00000000");
+ elem.SetAttribute("Table", table);
+ elem.SetAttribute("MasterRecID", mySL.GetKey(i).ToString());
+ }
+ }
+ }
+ }
+ }
+ catch (Exception ex)
+ {
+ MessageBox.Show(ex.Message, "Error Getting Root Groups");
+ return false;
+ }
+ }
+
+ // get child count for each group.
+ XmlNode node = root.FirstChild;
+ while (node != null)
+ {
+ if (node is VlnXmlElement)
+ {
+ VlnXmlElement child = (VlnXmlElement)node;
+ string tablex = child.GetAttribute("Table");
+ //get child count for each table listed in innertext.
+ try
+ {
+ if (OnlyConnectOnce)
+ {
+ SqlConnection cn = ROAPP_SqlConnection;
+ SqlCommand command = new SqlCommand();
+ command.Connection = cn;
+ command.CommandType = CommandType.StoredProcedure;
+ command.CommandText = "getCountRecidByParid";
+ command.Parameters.AddWithValue("@ROTable", tablex);
+ command.Parameters.AddWithValue("@ParentID", child.GetAttribute("RecID"));
+ using (SqlDataReader reader = command.ExecuteReader())
+ {
+ if (reader.Read())
+ {
+ int cnt = reader.GetInt32(0);
+ if (cnt > 0)
+ child.SetAttribute("HasChild", "True");
+ else
+ child.SetAttribute("HasChild", "False");
+ child.SetAttribute("ChildLoaded", "False");
+ }
+ }
+ }
+ else
+ {
+ using (SqlConnection cn = ROAPP_SqlConnection)
+ {
+ SqlCommand command = new SqlCommand();
+ command.Connection = cn;
+ command.CommandType = CommandType.StoredProcedure;
+ command.CommandText = "getCountRecidByParid";
+ command.Parameters.AddWithValue("@ROTable", tablex);
+ command.Parameters.AddWithValue("@ParentID", child.GetAttribute("RecID"));
+ using (SqlDataReader reader = command.ExecuteReader())
+ {
+ if (reader.Read())
+ {
+ int cnt = reader.GetInt32(0);
+ if (cnt > 0)
+ child.SetAttribute("HasChild", "True");
+ else
+ child.SetAttribute("HasChild", "False");
+ child.SetAttribute("ChildLoaded", "False");
+ }
+ }
+ }
+ }
+ }
+ catch (Exception ex)
+ {
+ MessageBox.Show(ex.Message, "Error Getting Root Groups");
+ return false;
+ }
+ }
+ node = node.NextSibling;
+ }
+
+ // for the beginning and end schema element, go to the master & read it from there. Store these to be used
+ // by all of the databases.
+
+ schemastart = null;
+ try
+ {
+ if (OnlyConnectOnce)
+ {
+ SqlConnection cn = ROAPP_SqlConnection;
+ SqlCommand command = new SqlCommand();
+ command.Connection = cn;
+ command.CommandType = CommandType.StoredProcedure;
+ command.CommandText = "getInfoByParidRectype";
+ command.Parameters.AddWithValue("@ROTable", "ROMaster");
+ command.Parameters.AddWithValue("@ParentID", "00000000");
+ command.Parameters.AddWithValue("@RecType", (int)RecordType.SchemaStart);
+ using (SqlDataReader reader = command.ExecuteReader())
+ {
+ if (reader.Read())
+ {
+ schemastart = reader.GetString(0);
+ }
+ }
+ }
+ else
+ {
+ using (SqlConnection cn = ROAPP_SqlConnection)
+ {
+ SqlCommand command = new SqlCommand();
+ command.Connection = cn;
+ command.CommandType = CommandType.StoredProcedure;
+ command.CommandText = "getInfoByParidRectype";
+ command.Parameters.AddWithValue("@ROTable", "ROMaster");
+ command.Parameters.AddWithValue("@ParentID", "00000000");
+ command.Parameters.AddWithValue("@RecType", (int)RecordType.SchemaStart);
+ using (SqlDataReader reader = command.ExecuteReader())
+ {
+ if (reader.Read())
+ {
+ schemastart = reader.GetString(0);
+ }
+ }
+ }
+ }
+ }
+ catch (Exception ex)
+ {
+ MessageBox.Show(ex.Message, "Error Getting Root Groups");
+ return false;
+ }
+
+ schemaend = null;
+ try
+ {
+ if (OnlyConnectOnce)
+ {
+ SqlConnection cn = ROAPP_SqlConnection;
+ SqlCommand command = new SqlCommand();
+ command.Connection = cn;
+ command.CommandType = CommandType.StoredProcedure;
+ command.CommandText = "getInfoByParidRectype";
+ command.Parameters.AddWithValue("@ROTable", "ROMaster");
+ command.Parameters.AddWithValue("@ParentID", "00000000");
+ command.Parameters.AddWithValue("@RecType", (int)RecordType.SchemaEnd);
+ using (SqlDataReader reader = command.ExecuteReader())
+ {
+ if (reader.Read())
+ {
+ schemaend = reader.GetString(0);
+ }
+ }
+ }
+ else
+ {
+ using (SqlConnection cn = ROAPP_SqlConnection)
+ {
+ SqlCommand command = new SqlCommand();
+ command.Connection = cn;
+ command.CommandType = CommandType.StoredProcedure;
+ command.CommandText = "getInfoByParidRectype";
+ command.Parameters.AddWithValue("@ROTable", "ROMaster");
+ command.Parameters.AddWithValue("@ParentID", "00000000");
+ command.Parameters.AddWithValue("@RecType", (int)RecordType.SchemaEnd);
+ using (SqlDataReader reader = command.ExecuteReader())
+ {
+ if (reader.Read())
+ {
+ schemaend = reader.GetString(0);
+ }
+ }
+ }
+ }
+ }
+ catch (Exception ex)
+ {
+ MessageBox.Show(ex.Message, "Error Getting Root Groups");
+ return false;
+ }
+ return true;
+ }
+ public override bool RODB_DeleteGroup(XmlNode group, string tbname, string toprecid)
+ {
+ VlnXmlElement egroup = null;
+ // delete table entry in ROMaster
+ try
+ {
+ using (SqlConnection cn = ROAPP_SqlConnection)
+ {
+ SqlCommand command = new SqlCommand();
+ command.Connection = cn;
+ command.CommandType = CommandType.StoredProcedure;
+ command.CommandText = "deleteByRecid";
+ command.Parameters.AddWithValue("@ROTable", "ROMaster");
+ if (group != null)
+ {
+ egroup = (VlnXmlElement)group;
+ command.Parameters.AddWithValue("@RecID", egroup.GetAttribute("MasterRecID"));
+ }
+ else
+ command.Parameters.AddWithValue("@RecID", toprecid);
+ using (SqlDataReader reader = command.ExecuteReader())
+ {
+ reader.Read(); // if this fails, it will go to the catch.
+ }
+ }
+ }
+ catch (Exception e)
+ {
+ MessageBox.Show(e.Message, "Error When deleting SubGroup ROs.");
+ return false;
+ }
+
+ // now remove all entries in the table (from roall)
+ try
+ {
+ using (SqlConnection cn = ROAPP_SqlConnection)
+ {
+ SqlCommand command = new SqlCommand();
+ command.Connection = cn;
+ command.CommandType = CommandType.StoredProcedure;
+ command.CommandText = "deleteByROTable";
+ if (egroup != null)
+ {
+ command.Parameters.AddWithValue("@ROTable", egroup.GetAttribute("Table"));
+ }
+ else
+ command.Parameters.AddWithValue("@ROTable", tbname);
+ using (SqlDataReader reader = command.ExecuteReader())
+ {
+ reader.Read(); // if this fails, it will go to the catch.
+ }
+ }
+ }
+ catch (Exception e)
+ {
+ MessageBox.Show(e.Message, "Error When deleting SubGroup ROs.");
+ return false;
+ }
+ return true;
+ }
+ public override bool RODB_DeleteRO(XmlNode group)
+ {
+ // delete from database and then delete from tree. delete group and all subgroups & ros beneath it. delete
+ // subgroups by calling this. note that if just an ro is passed in, it will only delete it.
+ XmlNode node = group.FirstChild;
+ VlnXmlElement child;
+ VlnXmlElement egroup = (VlnXmlElement)group;
+ if (group.Name == "vlnGroup")
+ {
+ while (node != null)
+ {
+ if (node is VlnXmlElement)
+ {
+ child = (VlnXmlElement)node;
+ // if this is a group, call this again.
+ if (child.Name == "vlnGroup")
+ {
+ bool success = RODB_DeleteRO(node);
+ if (success == false)
+ {
+ MessageBox.Show("error in RODB_DeleteGroup");
+ return false;
+ }
+ }
+
+ }
+ node = node.NextSibling;
+ }
+
+ // delete all db records that have the ParentID = to this group RecID.
+ // (All subgroups should be processed from above recursion.
+ try
+ {
+ using (SqlConnection cn = ROAPP_SqlConnection)
+ {
+ SqlCommand command = new SqlCommand();
+ command.Connection = cn;
+ command.CommandType = CommandType.StoredProcedure;
+ command.CommandText = "deleteByParid";
+ command.Parameters.AddWithValue("@ROTable", egroup.GetAttribute("Table"));
+ command.Parameters.AddWithValue("@ParentID", egroup.GetAttribute("RecID"));
+ using (SqlDataReader reader = command.ExecuteReader())
+ {
+ reader.Read(); // if this fails, it will go to the catch.
+ }
+ }
+ }
+ catch (Exception e)
+ {
+ MessageBox.Show(e.Message, "Error When deleting SubGroup ROs.");
+ return false;
+ }
+ }
+
+ // now delete this ro or group, i.e. the one passed in.
+ try
+ {
+ using (SqlConnection cn = ROAPP_SqlConnection)
+ {
+ SqlCommand command = new SqlCommand();
+ command.Connection = cn;
+ command.CommandType = CommandType.StoredProcedure;
+ command.CommandText = "deleteByRecid";
+ command.Parameters.AddWithValue("@ROTable", egroup.GetAttribute("Table"));
+ command.Parameters.AddWithValue("@RecID", egroup.GetAttribute("RecID"));
+ using (SqlDataReader reader = command.ExecuteReader())
+ {
+ reader.Read();
+ }
+ }
+ }
+ catch (Exception e)
+ {
+ MessageBox.Show(e.Message, "Error When deleting this RO.");
+ return false;
+ }
+ return true;
+ }
+ public override bool RODB_WriteGroup(XmlNode group, VlnXmlElement master)
+ {
+ bool success = true;
+ string dt = string.Format("{0:yyyyMMddHHmmss}", System.DateTime.Now);
+ string xmlstr = GenerateXmlString(group, true);
+ try
+ {
+ using (SqlConnection cn = ROAPP_SqlConnection)
+ {
+ SqlCommand command = new SqlCommand();
+ command.Connection = cn;
+ command.CommandType = CommandType.StoredProcedure;
+ command.CommandText = "updateInfoByRecid";
+ command.Parameters.AddWithValue("@ROTable", master.GetAttribute("Table"));
+ command.Parameters.AddWithValue("@Info", xmlstr);
+ command.Parameters.AddWithValue("@ModDateTime", dt);
+ command.Parameters.AddWithValue("@RecID", master.GetAttribute("RecID"));
+ using (SqlDataReader reader = command.ExecuteReader())
+ {
+ success = true;
+ }
+ }
+ }
+ catch (Exception e)
+ {
+ MessageBox.Show(e.Message, "Error on Write Group");
+ success = false;
+ }
+ return success;
+ }
+ public override bool RODB_InsertGroup(VlnXmlElement group)
+ {
+ bool success = true;
+ string dt = string.Format("{0:yyyyMMddHHmmss}", System.DateTime.Now);
+ string xmlstr = GenerateXmlString(group, true);
+
+ try
+ {
+ using (SqlConnection cn = ROAPP_SqlConnection)
+ {
+ SqlCommand command = new SqlCommand();
+ command.Connection = cn;
+ command.CommandType = CommandType.StoredProcedure;
+ command.CommandText = "insertAllRectypes";
+ command.Parameters.AddWithValue("@ROTable", group.GetAttribute("Table"));
+ command.Parameters.AddWithValue("@RecID", group.GetAttribute("RecID"));
+ command.Parameters.AddWithValue("@RecType", (int)RecordType.Group);
+ command.Parameters.AddWithValue("@ParentID", group.GetAttribute("ParentID"));
+ command.Parameters.AddWithValue("@AccPageID", null);
+ command.Parameters.AddWithValue("@Info", xmlstr);
+ command.Parameters.AddWithValue("@ModDateTime", dt);
+
+ using (SqlDataReader reader = command.ExecuteReader())
+ {
+ success = true;
+ }
+ }
+ }
+ catch (Exception e)
+ {
+ MessageBox.Show(e.Message, "Error on Insert group");
+ success = false;
+ }
+ return success;
+ }
+ public override string RODB_AddNewTable(string TblName, string newgrpname)
+ {
+ //for sql server version, a new table is not added. A new value for the ROTable field is used (TblName that is passed in )
+ bool success = false;
+
+ // now insert the first record with the new table name
+ string dt = string.Format("{0:yyyyMMddHHmmss}", System.DateTime.Now);
+
+ try
+ {
+ using (SqlConnection cn = ROAPP_SqlConnection)
+ {
+ SqlCommand command = new SqlCommand();
+ command.Connection = cn;
+ command.CommandType = CommandType.StoredProcedure;
+ command.CommandText = "insertAllRectypes";
+ command.Parameters.AddWithValue("@ROTable", TblName);
+ command.Parameters.AddWithValue("@RecID", "00000000");
+ command.Parameters.AddWithValue("@RecType", 0);
+ command.Parameters.AddWithValue("@ParentID", "00000000");
+ command.Parameters.AddWithValue("@AccPageID", null);
+ command.Parameters.AddWithValue("@Info", "00000001");
+ command.Parameters.AddWithValue("@ModDateTime", dt);
+
+ using (SqlDataReader reader = command.ExecuteReader())
+ {
+ success = true;
+ }
+ }
+ }
+ catch (Exception e)
+ {
+ MessageBox.Show(e.Message, "Error Creating New " + TblName);
+ success = false;
+ }
+
+ // return if error on insert of master record of new table, otherwise add
+ // this table reference to the master.
+ if (success == false) return null;
+
+ string recid = RODB_GetNextRecId("ROMaster");
+ string info = CvtUserFldToFld(newgrpname) + "\t" + TblName;
+
+ try
+ {
+ using (SqlConnection cn = ROAPP_SqlConnection)
+ {
+ SqlCommand command = new SqlCommand();
+ command.Connection = cn;
+ command.CommandType = CommandType.StoredProcedure;
+ command.CommandText = "insertAllRectypes";
+ command.Parameters.AddWithValue("@ROTable", "ROMaster");
+ command.Parameters.AddWithValue("@RecID", recid);
+ command.Parameters.AddWithValue("@RecType", 1);
+ command.Parameters.AddWithValue("@ParentID", "00000001");
+ command.Parameters.AddWithValue("@AccPageID", null);
+ command.Parameters.AddWithValue("@Info", info);
+ command.Parameters.AddWithValue("@ModDateTime", dt);
+
+ using (SqlDataReader reader = command.ExecuteReader())
+ {
+ success = true;
+ }
+ }
+ }
+ catch (Exception e)
+ {
+ MessageBox.Show(e.Message, "Error Writing new table to master.");
+ success = false;
+ }
+
+ if (success == false)
+ return null;
+ else
+ return recid;
+ }
+ public override bool RODB_CopyFieldDefs(string fromtb, string totb, int type)
+ {
+ // Copy over field definitions from the ROMaster to the input table name.
+ ArrayList retlist = new ArrayList();
+ string Info;
+ string RecID;
+ string name;
+ uint ftype;
+ ROField rof;
+ bool success;
+
+ try
+ {
+ using (SqlConnection cn = ROAPP_SqlConnection)
+ {
+ SqlCommand command = new SqlCommand();
+ command.Connection = cn;
+ command.CommandType = CommandType.StoredProcedure;
+ command.CommandText = "getRecidInfoByRectype";
+ command.Parameters.AddWithValue("@ROTable", "ROMaster");
+ command.Parameters.AddWithValue("@RecType", 2);
+ using (SqlDataReader reader = command.ExecuteReader())
+ {
+ while (reader.Read())
+ {
+ RecID = reader.GetString(0);
+ Info = reader.GetString(1);
+ // it's defined in the local table if the first character is "<" which starts
+ // the schema definition string.
+ name = ParseEleName(Info);
+ if (name != null)
+ {
+ // what type of schema element?
+ rof = new ROField(name, RecID, null, 0);
+ ftype = rof.ParseFieldType(Info);
+ rof.SetFieldType(ftype);
+ retlist.Add((object)rof);
+ }
+ }
+ }
+ }
+ }
+ catch (Exception ex)
+ {
+ MessageBox.Show(ex.Message, "Error on Copy Field Definitions");
+ return false;
+ }
+
+ // using this list, add new records for field definition references to the new
+ // table.
+ for (int i = 0; i < retlist.Count; i++)
+ {
+ rof = (ROField)retlist[i];
+ if (rof.GetFieldname != null)
+ {
+ string mrecid = rof.GetRecID;
+ string lrecid = RODB_GetNextRecId(totb);
+ StringBuilder strbld = new StringBuilder();
+ strbld.Append(mrecid);
+ strbld.Append(" ");
+ string strtype = rof.GetFieldType.ToString();
+ strbld.Append(strtype.PadLeft(3, '0'));
+ strbld.Append(" ");
+ if (strtype == "128") // append an 'a' for combo type
+ strbld.Append(rof.MakeFieldName(rof.GetFieldname) + "a");
+ else
+ strbld.Append(rof.MakeFieldName(rof.GetFieldname));
+ // add new field.
+ success = RODB_NewSchemaPiece(lrecid, "00000002", totb, strbld.ToString(), 2);
+ if (success == false) return false;
+ }
+ }
+ return true;
+ }
+ public override bool RODB_GetGroupAndSubgroups(VlnXmlElement node, StringBuilder sb)
+ {
+ // This is similar to GetChildData() but this function reads in all the subgroups for the given node
+ // Note that this function is designed to be call for the root node (i.e. it gets all of group and RO data
+ // for a given database table)
+ VlnStatusBar StatBar = new VlnStatusBar("Reading from the Database");
+ string tablename = node.GetAttribute("Table");
+ HybridDictionary dicGroups = new HybridDictionary();
+ dicGroups.Add(node.GetAttribute("RecID").ToString(), node);
+ StatBar.BarMax = RODB_GetNumberOfGroupRecords(tablename); //get number of groups
+ StatBar.BarStepValue = 5;
+ StatBar.StatMsg = node.InnerText;
+ try
+ {
+ using (SqlConnection cn = ROAPP_SqlConnection)
+ {
+ SqlCommand command = new SqlCommand();
+ command.Connection = cn;
+ command.CommandType = CommandType.StoredProcedure;
+ command.CommandText = "getGroupAndSubgroups";
+ command.Parameters.AddWithValue("@ROTable", tablename);
+ using (SqlDataReader reader = command.ExecuteReader())
+ {
+ if (!reader.Read())
+ {
+ StatBar.PerformStep(1);
+ reader.Close();
+ return false;
+ }
+ while (reader.Read())
+ {
+ string RecID = reader.GetString(0);
+ int RecType = reader.GetInt32(1);
+ string ParID = reader.GetString(2);
+ string AccPageID = reader.GetString(3);
+ string Info = reader.GetString(4);
+ if (!ParID.Equals(node.GetAttribute("RecID")))
+ {
+ if (!dicGroups.Contains(ParID))
+ {
+ if (sb.Length == 0)
+ {
+ sb.AppendLine("The following records were skipped.");
+ sb.AppendLine("The parent for these RO's was missing.");
+ sb.AppendLine();
+ }
+ string strMBText = "RecID: " + RecID + "\n\n Table: " + tablename + "\n";
+ sb.AppendLine(strMBText);
+ continue; // skip - no parent for this node
+ }
+ node = (VlnXmlElement)dicGroups[ParID];
+ node.SetAttribute("HasChild", "True");
+ node.SetAttribute("ChildLoaded", "True");
+ }
+ else
+ {
+ node.SetAttribute("ChildLoaded", "True");
+ }
+ if (RecType == (int)RecordType.Group)
+ {
+ VlnXmlElement elem;
+ StatBar.PerformStep();
+ try
+ {
+ XmlTextReader rdr = new XmlTextReader(Info, XmlNodeType.Element, null);
+ XmlNode nd = ROXml.ReadNode(rdr);
+ elem = (VlnXmlElement)nd;
+ }
+ catch (Exception e)
+ {
+ MessageBox.Show(e.Message, "Error reading Xml Group From data");
+ reader.Close();
+ return false;
+ }
+ elem.MyROID = RecID;
+ elem.SetAttribute("RecID", RecID);
+ elem.SetAttribute("ParentID", node.GetAttribute("RecID"));
+ elem.SetAttribute("Table", node.GetAttribute("Table"));
+
+ if (!dicGroups.Contains(RecID))
+ {
+ node.AppendChild(elem);
+ dicGroups.Add(RecID, elem);
+ }
+
+ // The Parameter Display Data is stored along with the group. This data
+ // was migrated over so that the data was not lost, but there is no
+ // User Interface to get to it. So remove the xml elements from the
+ // group part of tree. All valid group data only has one sublevel of
+ // data defining the group name.
+ XmlNode grp = (XmlNode)elem;
+ XmlNode kid = grp.FirstChild;
+ XmlNode tmpkid;
+ while (kid != null)
+ {
+ tmpkid = kid.NextSibling;
+ if (kid is VlnXmlElement)
+ if (kid.ChildNodes.Count > 1) grp.RemoveChild(kid);
+ kid = tmpkid;
+ }
+ }
+
+ // Store data in the VlnXmlElement as an RO
+ else if (RecType == (int)RecordType.RRO)
+ {
+ //Create the reader.
+ XmlNode ro;
+ try
+ {
+ XmlTextReader roreader = new XmlTextReader(Info, XmlNodeType.Element, null);
+ ro = ROXml.ReadNode(roreader);
+ }
+ catch (Exception e)
+ {
+ MessageBox.Show(e.Message, "Error reading Xml RRO From data");
+ reader.Close();
+ return false;
+ }
+
+ VlnXmlElement elem = (VlnXmlElement)ro;
+ node.AppendChild(ro);
+ elem.MyROID = RecID;
+ elem.SetAttribute("RecID", RecID);
+ elem.SetAttribute("ParentID", node.GetAttribute("RecID"));
+ elem.SetAttribute("Table", node.GetAttribute("Table"));
+ elem.SetAttribute("AccPageID", AccPageID);
+ }
+ }
+ }
+ }
+ }
+ catch (Exception ex)
+ {
+ MessageBox.Show(ex.Message, "Error reading Xml RRO From data");
+ return false;
+ }
+
+ dicGroups = null;
+ StatBar.Dispose();
+ return true;
+ }
+ public override bool RODB_GetChildData(VlnXmlElement node, bool CheckChildCount)
+ {
+ ShowCount.GetChildData++;
+ // get menu fields to display here.
+ string tablename = node.GetAttribute("Table");
+ try
+ {
+ if (OnlyConnectOnce)
+ {
+ SqlConnection cn = ROAPP_SqlConnection;
+ SqlCommand command = new SqlCommand();
+ command.Connection = cn;
+ command.CommandType = CommandType.StoredProcedure;
+ command.CommandText = "getChildData";
+ command.Parameters.AddWithValue("@ROTable", tablename);
+ command.Parameters.AddWithValue("@ParentID", node.GetAttribute("RecID"));
+ using (SqlDataReader reader = command.ExecuteReader())
+ {
+ while (reader.Read())
+ {
+ ShowCount.Children++;
+ string RecID = reader.GetString(0);
+ MyRecID = RecID;
+ //if (RecID.StartsWith("000300006193")) Console.WriteLine("here");
+ if (RecID.StartsWith("0003")) Console.WriteLine("here");
+ if (RecID.EndsWith("6193")) Console.WriteLine("here");
+ int RecType = reader.GetInt32(1);
+ string AccPageID = reader.GetString(2);
+ string Info = reader.GetString(3);
+ node.SetAttribute("HasChild", "True");
+ if (RecType == (int)RecordType.Group)
+ {
+ VlnXmlElement elem;
+ try
+ {
+ XmlTextReader rdr = new XmlTextReader(Info, XmlNodeType.Element, null);
+ XmlNode nd = ROXml.ReadNode(rdr);
+ elem = (VlnXmlElement)nd;
+ }
+ catch (Exception e)
+ {
+ MessageBox.Show(e.Message, "Error Reading Xml Group From Data");
+ return false;
+ }
+ node.AppendChild(elem);
+ elem.MyROID = RecID;
+ elem.SetAttribute("RecID", RecID);
+ elem.SetAttribute("ParentID", node.GetAttribute("RecID"));
+ elem.SetAttribute("Table", node.GetAttribute("Table"));
+
+ // The Parameter Display Data is stored along with the group. This data
+ // was migrated over so that the data was not lost, but there is no
+ // User Interface to get to it. So remove the xml elements from the
+ // group part of tree. All valid group data only has one sublevel of
+ // data defining the group name.
+ XmlNode grp = (XmlNode)elem;
+ XmlNode kid = grp.FirstChild;
+ XmlNode tmpkid;
+ while (kid != null)
+ {
+ tmpkid = kid.NextSibling;
+ if (kid is VlnXmlElement)
+ if (kid.ChildNodes.Count > 1) grp.RemoveChild(kid);
+ kid = tmpkid;
+ }
+ }
+ // Store data in the VlnXmlElement as an RO
+ else if (RecType == (int)RecordType.RRO)
+ {
+ //Create the reader.
+ XmlNode ro;
+ try
+ {
+ XmlTextReader roreader = new XmlTextReader(Info, XmlNodeType.Element, null);
+ ro = ROXml.ReadNode(roreader);
+ }
+ catch (Exception e)
+ {
+ MessageBox.Show(e.Message, "Error Reading Xml RRO From Data");
+ return false;
+ }
+
+ VlnXmlElement elem = (VlnXmlElement)ro;
+ elem.MyROID = RecID;
+ node.AppendChild(ro);
+ elem.SetAttribute("RecID", RecID);
+ elem.SetAttribute("ParentID", node.GetAttribute("RecID"));
+ elem.SetAttribute("Table", node.GetAttribute("Table"));
+ elem.SetAttribute("AccPageID", AccPageID);
+ }
+ }
+ }
+ }
+ else
+ {
+ using (SqlConnection cn = ROAPP_SqlConnection)
+ {
+ SqlCommand command = new SqlCommand();
+ command.Connection = cn;
+ command.CommandType = CommandType.StoredProcedure;
+ command.CommandText = "getChildData";
+ command.Parameters.AddWithValue("@ROTable", tablename);
+ command.Parameters.AddWithValue("@ParentID", node.GetAttribute("RecID"));
+ using (SqlDataReader reader = command.ExecuteReader())
+ {
+ while (reader.Read())
+ {
+ ShowCount.Children++;
+ string RecID = reader.GetString(0);
+ MyRecID = RecID;
+ //if (RecID.StartsWith("000300006193")) Console.WriteLine("here");
+ if (RecID.StartsWith("0003")) Console.WriteLine("here");
+ if (RecID.EndsWith("6193")) Console.WriteLine("here");
+ int RecType = reader.GetInt32(1);
+ string AccPageID = reader.GetString(2);
+ string Info = reader.GetString(3);
+ node.SetAttribute("HasChild", "True");
+ if (RecType == (int)RecordType.Group)
+ {
+ VlnXmlElement elem;
+ try
+ {
+ XmlTextReader rdr = new XmlTextReader(Info, XmlNodeType.Element, null);
+ XmlNode nd = ROXml.ReadNode(rdr);
+ elem = (VlnXmlElement)nd;
+ }
+ catch (Exception e)
+ {
+ MessageBox.Show(e.Message, "Error Reading Xml Group From Data");
+ return false;
+ }
+ node.AppendChild(elem);
+ elem.MyROID = RecID;
+ elem.SetAttribute("RecID", RecID);
+ elem.SetAttribute("ParentID", node.GetAttribute("RecID"));
+ elem.SetAttribute("Table", node.GetAttribute("Table"));
+
+ // The Parameter Display Data is stored along with the group. This data
+ // was migrated over so that the data was not lost, but there is no
+ // User Interface to get to it. So remove the xml elements from the
+ // group part of tree. All valid group data only has one sublevel of
+ // data defining the group name.
+ XmlNode grp = (XmlNode)elem;
+ XmlNode kid = grp.FirstChild;
+ XmlNode tmpkid;
+ while (kid != null)
+ {
+ tmpkid = kid.NextSibling;
+ if (kid is VlnXmlElement)
+ if (kid.ChildNodes.Count > 1) grp.RemoveChild(kid);
+ kid = tmpkid;
+ }
+ }
+ // Store data in the VlnXmlElement as an RO
+ else if (RecType == (int)RecordType.RRO)
+ {
+ //Create the reader.
+ XmlNode ro;
+ try
+ {
+ XmlTextReader roreader = new XmlTextReader(Info, XmlNodeType.Element, null);
+ ro = ROXml.ReadNode(roreader);
+ }
+ catch (Exception e)
+ {
+ MessageBox.Show(e.Message, "Error Reading Xml RRO From Data");
+ return false;
+ }
+
+ VlnXmlElement elem = (VlnXmlElement)ro;
+ elem.MyROID = RecID;
+ node.AppendChild(ro);
+ elem.SetAttribute("RecID", RecID);
+ elem.SetAttribute("ParentID", node.GetAttribute("RecID"));
+ elem.SetAttribute("Table", node.GetAttribute("Table"));
+ elem.SetAttribute("AccPageID", AccPageID);
+ }
+ }
+ }
+ }
+ }
+ }
+ catch (Exception e)
+ {
+ MessageBox.Show(e.Message, "Error Getting Child Data");
+ return false;
+ }
+
+ // get child count for each subgroup.
+ if (CheckChildCount)
+ {
+ //Build a Dictionary of Children with Children from the query results
+ HybridDictionary dicChild = new HybridDictionary();
+ //A different approach - Look for grandchildren and set the haschildren attribute
+ //Build a query to get a list of children with children
+ try
+ {
+ if (OnlyConnectOnce)
+ {
+ SqlConnection cn = ROAPP_SqlConnection;
+ SqlCommand command = new SqlCommand();
+ command.Connection = cn;
+ command.CommandType = CommandType.StoredProcedure;
+ command.CommandText = "getCountChildrenOfChildData";
+ command.Parameters.AddWithValue("@ROTable", tablename);
+ command.Parameters.AddWithValue("@ParentID", node.GetAttribute("RecID"));
+ using (SqlDataReader reader = command.ExecuteReader())
+ {
+
+ while (reader.Read())
+ {
+ string tmp = reader.GetString(0);
+ int tmpi = reader.GetInt32(1);
+ dicChild[tmp] = tmpi;
+ }
+ }
+ }
+ else
+ {
+ using (SqlConnection cn = ROAPP_SqlConnection)
+ {
+ SqlCommand command = new SqlCommand();
+ command.Connection = cn;
+ command.CommandType = CommandType.StoredProcedure;
+ command.CommandText = "getCountChildrenOfChildData";
+ command.Parameters.AddWithValue("@ROTable", tablename);
+ command.Parameters.AddWithValue("@ParentID", node.GetAttribute("RecID"));
+ using (SqlDataReader reader = command.ExecuteReader())
+ {
+
+ while (reader.Read())
+ {
+ string tmp = reader.GetString(0);
+ int tmpi = reader.GetInt32(1);
+ //dicChild[reader.GetString(0)] = reader.GetInt32(1);//This adds the entry and sets the value
+ dicChild[tmp] = tmpi;
+ }
+ }
+ }
+ }
+ }
+ catch (Exception ex)
+ {
+ MessageBox.Show(ex.Message, "Error Reading Child Counts");
+ return false;
+ }
+ XmlNode child = node.FirstChild;
+ while (child != null) //Look at each child node
+ {
+ if (child is VlnXmlElement)
+ {
+ VlnXmlElement echild = (VlnXmlElement)child;
+ if (echild.Name == "vlnGroup")
+ {
+ //If the dictionary contains an entry, the child has children
+ echild.SetAttribute("HasChild", (dicChild.Contains(echild.GetAttribute("RecID"))) ? "True" : "False");
+ echild.SetAttribute("ChildLoaded", "False");
+ }
+ }
+ child = child.NextSibling;
+ }
+ dicChild = null;
+ }
+ node.SetAttribute("ChildLoaded", "True");
+ return true;
+ }
+ public override bool IsDuplicateAccPageID(VlnXmlElement ro, string newacc)
+ {
+ string inacc = null;
+ bool isdup = false;
+ int indx = newacc.IndexOf("'");
+ if (indx >= 0)
+ inacc = newacc.Insert(indx, "'");
+ else
+ inacc = newacc;
+
+ try
+ {
+ using (SqlConnection cn = ROAPP_SqlConnection)
+ {
+ SqlCommand command = new SqlCommand();
+ command.Connection = cn;
+ command.CommandType = CommandType.StoredProcedure;
+ if (ro.HasAttribute("RecID")) // new ro's don't have recid defined yet before this test.
+ {
+ command.CommandText = "getCountRecidByAccidNotRecid";
+ command.Parameters.AddWithValue("RecID", ro.GetAttribute("RecID"));
+ }
+ else
+ command.CommandText = "getCountRecidByAccid";
+ command.Parameters.AddWithValue("@AccPageID", inacc);
+ command.Parameters.AddWithValue("@ROTable", ro.GetAttribute("Table"));
+
+ using (SqlDataReader reader = command.ExecuteReader())
+ {
+ if (reader.Read())
+ {
+ int cnt = reader.GetInt32(0);
+ if (cnt > 0)
+ isdup = true;
+ else
+ isdup = false;
+ }
+ }
+ }
+ }
+ catch (Exception ex)
+ {
+ MessageBox.Show(ex.Message, "Error on IsDuplicateAccPageID");
+ return true;
+ }
+ return isdup;
+ }
+ public override VlnXmlElement RODB_ReadRO(string tbl, string recid)
+ {
+ ShowCount.ReadRo++;
+ VlnXmlElement retele = null;
+ if (OnlyConnectOnce)
+ {
+ try
+ {
+ SqlConnection cn = ROAPP_SqlConnection;
+ SqlCommand command = new SqlCommand();
+ command.Connection = cn;
+ command.CommandType = CommandType.StoredProcedure;
+ if (recid == null)
+ {
+ command.CommandText = "getParidAccidInfoByRectypeParid";
+ command.Parameters.AddWithValue("@ROTable", tbl);
+ command.Parameters.AddWithValue("@ParentID", "00000000");
+ command.Parameters.AddWithValue("@RecType", 3);
+ }
+ else
+ {
+ command.CommandText = "getParidAccidInfoByRecid";
+ command.Parameters.AddWithValue("@ROTable", tbl);
+ command.Parameters.AddWithValue("@RecId", recid);
+ }
+ using (SqlDataReader reader = command.ExecuteReader())
+ {
+ if (reader.Read())
+ {
+ string ParentID = reader.GetString(0);
+ string AccPageID = reader.GetString(1);
+ string Info = reader.GetString(2);
+ // Store data in the VlnXmlElement
+ XmlTextReader rdr = new XmlTextReader(Info, XmlNodeType.Element, null);
+ XmlNode nd = ROXml.ReadNode(rdr);
+ retele = (VlnXmlElement)nd;
+ retele.SetAttribute("RecID", recid);
+ retele.SetAttribute("ParentID", ParentID);
+ retele.SetAttribute("Table", tbl);
+ if (retele.Name != "vlnGroup") retele.SetAttribute("AccPageID", AccPageID);
+ }
+ }
+ }
+ catch (Exception ex)
+ {
+ MessageBox.Show(ex.Message, "Error on ReadRo");
+ return null;
+ }
+ }
+ else
+ {
+ try
+ {
+ using (SqlConnection cn = ROAPP_SqlConnection)
+ {
+ SqlCommand command = new SqlCommand();
+ command.Connection = cn;
+ command.CommandType = CommandType.StoredProcedure;
+ if (recid == null)
+ {
+ command.CommandText = "getParidAccidInfoByRectypeParid";
+ command.Parameters.AddWithValue("@ROTable", tbl);
+ command.Parameters.AddWithValue("@ParentID", "00000000");
+ command.Parameters.AddWithValue("@RecType", 3);
+ }
+ else
+ {
+ command.CommandText = "getParidAccidInfoByRecid";
+ command.Parameters.AddWithValue("@ROTable", tbl);
+ command.Parameters.AddWithValue("@RecId", recid);
+ }
+ using (SqlDataReader reader = command.ExecuteReader())
+ {
+ if (reader.Read())
+ {
+ string ParentID = reader.GetString(0);
+ string AccPageID = reader.GetString(1);
+ string Info = reader.GetString(2);
+ // Store data in the VlnXmlElement
+ XmlTextReader rdr = new XmlTextReader(Info, XmlNodeType.Element, null);
+ XmlNode nd = ROXml.ReadNode(rdr);
+ retele = (VlnXmlElement)nd;
+ retele.SetAttribute("RecID", recid);
+ retele.SetAttribute("ParentID", ParentID);
+ retele.SetAttribute("Table", tbl);
+ if (retele.Name != "vlnGroup") retele.SetAttribute("AccPageID", AccPageID);
+ }
+ }
+ }
+ }
+ catch (Exception ex)
+ {
+ MessageBox.Show(ex.Message, "Error on ReadRo");
+ return null;
+ }
+ }
+ // if this is a group, see if children. If the RO is not found, return null
+ if (retele != null && retele.Name == "vlnGroup")
+ {
+ if (OnlyConnectOnce)
+ {
+ try
+ {
+ SqlConnection cn = ROAPP_SqlConnection;
+ SqlCommand command = new SqlCommand();
+ command.Connection = cn;
+ command.CommandType = CommandType.StoredProcedure;
+ command.CommandText = "getCountRecidByParid";
+ command.Parameters.AddWithValue("@ROTable", tbl);
+ if (recid == null)
+ command.Parameters.AddWithValue("@ParentID", "00000000");
+ else
+ command.Parameters.AddWithValue("@ParentID", recid);
+ using (SqlDataReader reader = command.ExecuteReader())
+ {
+ if (reader.Read())
+ {
+ int cnt = reader.GetInt32(0);
+ if (cnt > 0)
+ retele.SetAttribute("HasChild", "True");
+ else
+ retele.SetAttribute("HasChild", "False");
+ }
+ else
+ retele.SetAttribute("HasChild", "False");
+ retele.SetAttribute("ChildLoaded", "False");
+ }
+ }
+ catch (Exception ex)
+ {
+ MessageBox.Show(ex.Message, "Error on ReadRo");
+ return null;
+ }
+ }
+ else
+ {
+ try
+ {
+ using (SqlConnection cn = ROAPP_SqlConnection)
+ {
+ SqlCommand command = new SqlCommand();
+ command.Connection = cn;
+ command.CommandType = CommandType.StoredProcedure;
+ command.CommandText = "getCountRecidByParid";
+ command.Parameters.AddWithValue("@ROTable", tbl);
+ if (recid == null)
+ command.Parameters.AddWithValue("@ParentID", "00000000");
+ else
+ command.Parameters.AddWithValue("@ParentID", recid);
+ using (SqlDataReader reader = command.ExecuteReader())
+ {
+ if (reader.Read())
+ {
+ int cnt = reader.GetInt32(0);
+ if (cnt > 0)
+ retele.SetAttribute("HasChild", "True");
+ else
+ retele.SetAttribute("HasChild", "False");
+ }
+ else
+ retele.SetAttribute("HasChild", "False");
+ retele.SetAttribute("ChildLoaded", "False");
+ }
+ }
+ }
+ catch (Exception ex)
+ {
+ MessageBox.Show(ex.Message, "Error on ReadRo");
+ return null;
+ }
+ }
+ }
+ return retele;
+ }
+ public override bool RODB_WriteRO(VlnXmlElement ro)
+ {
+ bool success;
+ if (ro.Name == "vlnGroup")
+ {
+ success = RODB_WriteGroup(ro, ro);
+ return success;
+ }
+ else
+ {
+ string wraccid = null;
+ string accid = ro.GetAttribute("AccPageID");
+ int quote = accid.IndexOf("'");
+ if (quote >= 0)
+ wraccid = accid.Insert(quote, "'");
+ else
+ wraccid = accid;
+ string dt = string.Format("{0:yyyyMMddHHmmss}", System.DateTime.Now);
+ string xmlstr = GenerateXmlString(ro, false);
+ try
+ {
+ using (SqlConnection cn = ROAPP_SqlConnection)
+ {
+ SqlCommand command = new SqlCommand();
+ command.Connection = cn;
+ command.CommandType = CommandType.StoredProcedure;
+ command.CommandText = "updateInfoAccidByRecid";
+ command.Parameters.AddWithValue("@ROTable", ro.GetAttribute("Table"));
+ command.Parameters.AddWithValue("@Info", xmlstr);
+ command.Parameters.AddWithValue("@ModDateTime", dt);
+ command.Parameters.AddWithValue("@AccPageID", dt);
+ command.Parameters.AddWithValue("@RecID", ro.GetAttribute("RecID"));
+ using (SqlDataReader reader = command.ExecuteReader())
+ {
+ success = true;
+ }
+ }
+ }
+ catch (Exception ex)
+ {
+ MessageBox.Show(ex.Message, "Error on Write RO");
+ success = false;
+ }
+ }
+ return success;
+ }
+ public override bool RODB_InsertRO(VlnXmlElement ro)
+ {
+ bool success = false;
+ string dt = string.Format("{0:yyyyMMddHHmmss}", System.DateTime.Now);
+ VlnXmlElement parent = (VlnXmlElement)ro.ParentNode;
+ string lrecid = RODB_GetNextRecId(parent.GetAttribute("Table"));
+ ro.SetAttribute("Table", parent.GetAttribute("Table"));
+ ro.SetAttribute("RecID", lrecid);
+ ro.SetAttribute("ParentID", parent.GetAttribute("RecID"));
+ string haskids = parent.GetAttribute("HasChild");
+ if (haskids == "False" || haskids == "")
+ {
+ parent.SetAttribute("HasChild", "True");
+ parent.SetAttribute("ChildLoaded", "True");
+ }
+ string xmlstr = GenerateXmlString(ro, false);
+ string wraccid = null;
+ if (ro.HasAttribute("AccPageID"))
+ {
+ string accid = ro.GetAttribute("AccPageID");
+ int quote = accid.IndexOf("'");
+ if (quote >= 0)
+ wraccid = accid.Insert(quote, "'");
+ else
+ wraccid = accid;
+ }
+ try
+ {
+ using (SqlConnection cn = ROAPP_SqlConnection)
+ {
+ SqlCommand command = new SqlCommand();
+ command.Connection = cn;
+ command.CommandType = CommandType.StoredProcedure;
+ command.CommandText = "insertAllRectypes";
+ if (ro.Name == "vlnGroup")
+ {
+ // add attribute to flag that this does not have xml children, i.e. any
+ // other subgroups or ros under it.
+ ro.SetAttribute("HasChild", "False");
+ if (ro.HasAttribute("AccPageID"))
+ {
+ command.Parameters.AddWithValue("@RecType", (int)RecordType.Group);
+ command.Parameters.AddWithValue("@AccPageID", wraccid);
+ }
+ else
+ {
+ command.Parameters.AddWithValue("@RecType", (int)RecordType.Group);
+ command.Parameters.AddWithValue("@AccPageID", null);
+ }
+ }
+ else
+ {
+ command.Parameters.AddWithValue("@RecType", (int)RecordType.RRO);
+ command.Parameters.AddWithValue("@AccPageID", wraccid);
+ }
+ command.Parameters.AddWithValue("@ROTable", parent.GetAttribute("Table"));
+ command.Parameters.AddWithValue("@RecID", ro.GetAttribute("RecID"));
+ command.Parameters.AddWithValue("@ParentID", ro.GetAttribute("ParentID"));
+ command.Parameters.AddWithValue("@Info", xmlstr);
+ command.Parameters.AddWithValue("@ModDateTime", dt);
+
+ using (SqlDataReader reader = command.ExecuteReader())
+ {
+ success = true;
+ }
+ }
+ }
+ catch (Exception e)
+ {
+ MessageBox.Show(e.Message, "Error on Insert RO");
+ success = false;
+ }
+ return success;
+ }
+ public override ushort RODB_GetFieldType(VlnXmlElement elem, string TableName, string Fld)
+ {
+ string Info;
+ string RecID;
+ string name;
+ string tmpname;
+ ushort ftype = 0;
+ ROField rof;
+ if (TableName != lastTable)
+ {
+ lastTable = TableName;
+ dicFldTypes = new HybridDictionary();
+ try
+ {
+ using (SqlConnection cn = ROAPP_SqlConnection)
+ {
+ SqlCommand command = new SqlCommand();
+ command.Connection = cn;
+ command.CommandType = CommandType.StoredProcedure;
+ command.CommandText = "getRecidInfoByRectype";
+ command.Parameters.AddWithValue("@ROTable", TableName);
+ command.Parameters.AddWithValue("@RecType", 2);
+ using (SqlDataReader reader = command.ExecuteReader())
+ {
+ // NOTE !!!!
+ // This function does not handle Combo type fields (128).
+ while (reader.Read())
+ {
+ RecID = reader.GetString(0);
+ Info = reader.GetString(1);
+
+ // it's defined in the local table if the first character is "<" which starts
+ // the schema definition string.
+ if ("<" == Info.Substring(0, 1))
+ {
+ name = ParseEleName(Info);
+ if (name != null)
+ {
+ tmpname = CvtUserFldToFld(name);
+ rof = new ROField(name, RecID, null, 0);
+ ftype = GetFSTreturnType(System.Convert.ToUInt16(rof.ParseFieldType(Info)), tmpname, elem);
+ dicFldTypes[tmpname] = ftype;
+ }
+ }
+ else
+ {
+ // references master, but what we need is here: the field name and
+ // the the field type. Just parse this from the info field.
+ string parsename;
+ parsename = Info.Substring(13, Info.Length - 13);
+ ftype = GetFSTreturnType(System.Convert.ToUInt16(Info.Substring(9, 3)), parsename, elem);
+ dicFldTypes[parsename] = ftype;
+ }
+ }
+ }
+ }
+ }
+ catch (Exception ex)
+ {
+ MessageBox.Show(ex.Message, "Error Getting Field Type");
+ return 0;
+ }
+ }
+ ftype = ((ushort)dicFldTypes[Fld]);
+ return ftype;
+ }
+ // For the given element's table, get all of the RO fields defined in this table.
+ public override ArrayList RODB_GetFields(VlnXmlElement elem, uint rtype)
+ {
+ string table = elem.GetAttribute("Table");
+ if (!FieldDefinitions.ContainsKey(table))
+ {
+ FieldDefinitions.Add(table, RODB_GetFieldsFromDB(elem));
+ }
+ return FieldDefinitions[table];
+ }
+ private Dictionary _FieldDefinitions = null;
+ public Dictionary FieldDefinitions
+ {
+ get
+ {
+ if (_FieldDefinitions == null) _FieldDefinitions = new Dictionary();
+ return _FieldDefinitions;
+ }
+ set { _FieldDefinitions = value; }
+ }
+ public ArrayList RODB_GetFieldsFromDB(VlnXmlElement elem)
+ {
+ ArrayList retlist = new ArrayList();
+ string Info;
+ string RecID;
+ string name;
+ uint ftype;
+ ROField rof;
+ ShowCount.GetFields++;
+ try
+ {
+ if (OnlyConnectOnce)
+ {
+ SqlConnection cn = ROAPP_SqlConnection;
+ SqlCommand command = new SqlCommand();
+ command.Connection = cn;
+ command.CommandType = CommandType.StoredProcedure;
+ command.CommandText = "getRecidInfoByRectype";
+ command.Parameters.AddWithValue("@ROTable", elem.GetAttribute("Table"));
+ command.Parameters.AddWithValue("@RecType", 2);
+ using (SqlDataReader reader = command.ExecuteReader())
+ {
+ while (reader.Read())
+ {
+ ShowCount.RoFields++;
+ RecID = reader.GetString(0);
+ MyRecID = RecID;
+ Info = reader.GetString(1);
+ // it's defined in the local table if the first character is "<" which starts
+ // the schema definition string.
+ if ("<" == Info.Substring(0, 1))
+ {
+ name = ParseEleName(Info);
+ if (name != null)
+ {
+ // what type of schema element?
+ rof = new ROField(name, RecID, null, 0);
+ ftype = rof.ParseFieldType(Info);
+ rof.SetFieldType(ftype);
+ retlist.Add((object)rof);
+ }
+ }
+ else
+ {
+ // the recid points to a field definition (schema) in the master - use it to get
+ // the schema element from the master and copy it.
+ string parsename;
+ string masterrecid;
+ string strftype;
+ masterrecid = Info.Substring(0, 8);
+ strftype = Info.Substring(9, 3);
+ ftype = System.Convert.ToUInt32(Info.Substring(9, 3));
+ parsename = CvtFldToUserFld(Info.Substring(13, Info.Length - 13));
+ // if we have a choice element, remove the last character (it was added to the
+ // field names in order to allow for unique fields names for the choice items.
+ if (ftype == (uint)FieldTypes.Combination)
+ {
+ string tparsename = parsename.Remove((parsename.Length) - 1, 1); // remove the choice string and the space
+ parsename = tparsename;
+ }
+ rof = new ROField(parsename, RecID, masterrecid, ftype);
+ retlist.Add((object)rof);
+ }
+ }
+ }
+ }
+ else
+ {
+ using (SqlConnection cn = ROAPP_SqlConnection)
+ {
+ ShowCount.RoFields++;
+ SqlCommand command = new SqlCommand();
+ command.Connection = cn;
+ command.CommandType = CommandType.StoredProcedure;
+ command.CommandText = "getRecidInfoByRectype";
+ command.Parameters.AddWithValue("@ROTable", elem.GetAttribute("Table"));
+ command.Parameters.AddWithValue("@RecType", 2);
+ using (SqlDataReader reader = command.ExecuteReader())
+ {
+ while (reader.Read())
+ {
+ RecID = reader.GetString(0);
+ MyRecID = RecID;
+ Info = reader.GetString(1);
+ // it's defined in the local table if the first character is "<" which starts
+ // the schema definition string.
+ if ("<" == Info.Substring(0, 1))
+ {
+ name = ParseEleName(Info);
+ if (name != null)
+ {
+ // what type of schema element?
+ rof = new ROField(name, RecID, null, 0);
+ ftype = rof.ParseFieldType(Info);
+ rof.SetFieldType(ftype);
+ retlist.Add((object)rof);
+ }
+ }
+ else
+ {
+ // the recid points to a field definition (schema) in the master - use it to get
+ // the schema element from the master and copy it.
+ string parsename;
+ string masterrecid;
+ string strftype;
+ masterrecid = Info.Substring(0, 8);
+ strftype = Info.Substring(9, 3);
+ ftype = System.Convert.ToUInt32(Info.Substring(9, 3));
+ parsename = CvtFldToUserFld(Info.Substring(13, Info.Length - 13));
+ // if we have a choice element, remove the last character (it was added to the
+ // field names in order to allow for unique fields names for the choice items.
+ if (ftype == (uint)FieldTypes.Combination)
+ {
+ string tparsename = parsename.Remove((parsename.Length) - 1, 1); // remove the choice string and the space
+ parsename = tparsename;
+ }
+ rof = new ROField(parsename, RecID, masterrecid, ftype);
+ retlist.Add((object)rof);
+ }
+ }
+ }
+ }
+ }
+ }
+ catch (Exception ex)
+ {
+ MessageBox.Show(ex.Message, "Error Getting Fields");
+ return null;
+ }
+ return retlist;
+ }
+ public override string RODB_GetSchemaPiece(string Recid, string table)
+ {
+ string Info;
+ try
+ {
+ using (SqlConnection cn = ROAPP_SqlConnection)
+ {
+ SqlCommand command = new SqlCommand();
+ command.Connection = cn;
+ command.CommandType = CommandType.StoredProcedure;
+ command.CommandText = "getInfoByRecid";
+ command.Parameters.AddWithValue("@ROTable", table);
+ command.Parameters.AddWithValue("@RecID", Recid);
+ using (SqlDataReader reader = command.ExecuteReader())
+ {
+ if (DBE.Read())
+ Info = reader.GetString(0);
+ else
+ Info = null;
+ }
+ }
+ }
+ catch (Exception ex)
+ {
+ MessageBox.Show(ex.Message, "Error Getting Schema Piece");
+ return null;
+ }
+ return Info == null ? null : Info.Replace("'", "\'");
+ }
+ public override bool RODB_NewSchemaPiece(string recid, string parentid, string table, string schpiece, uint rtype)
+ {
+ bool success = true;
+ string dt = string.Format("{0:yyyyMMddHHmmss}", System.DateTime.Now);
+ try
+ {
+ using (SqlConnection cn = ROAPP_SqlConnection)
+ {
+ SqlCommand command = new SqlCommand();
+ command.Connection = cn;
+ command.CommandType = CommandType.StoredProcedure;
+ command.CommandText = "insertAllRectypes";
+ command.Parameters.AddWithValue("@ROTable", table);
+ command.Parameters.AddWithValue("@RecID", recid);
+ command.Parameters.AddWithValue("@RecType", 2);
+ command.Parameters.AddWithValue("@ParentID", parentid);
+ command.Parameters.AddWithValue("@AccPageID", null);
+ command.Parameters.AddWithValue("@Info", schpiece.Replace("\'", "'"));
+ command.Parameters.AddWithValue("@ModDateTime", dt);
+
+ using (SqlDataReader reader = command.ExecuteReader())
+ {
+ success = true;
+ }
+ }
+ }
+ catch (Exception e)
+ {
+ MessageBox.Show(e.Message, "Error on New Schema Piece");
+ success = false;
+ }
+ return success;
+ }
+ public override bool RODB_WriteSchemaPiece(string Recid, string table, string schpiece)
+ {
+ bool success = true;
+ string dt = string.Format("{0:yyyyMMddHHmmss}", System.DateTime.Now);
+ try
+ {
+ using (SqlConnection cn = ROAPP_SqlConnection)
+ {
+ SqlCommand command = new SqlCommand();
+ command.Connection = cn;
+ command.CommandType = CommandType.StoredProcedure;
+ command.CommandText = "updateInfoByRecid";
+ command.Parameters.AddWithValue("@ROTable", table);
+ command.Parameters.AddWithValue("@Info", schpiece.Replace("\'", "'"));
+ command.Parameters.AddWithValue("@ModDateTime", dt);
+ command.Parameters.AddWithValue("@RecID", Recid);
+ using (SqlDataReader reader = command.ExecuteReader())
+ {
+ success = true;
+ }
+ }
+ }
+ catch (Exception e)
+ {
+ MessageBox.Show(e.Message, "Error on Write Schema Piece");
+ success = false;
+ }
+ return success;
+ }
+ public override bool RODB_ProcessRROFieldChange(VlnXmlElement child, string oldname, string newname, uint editlevel, VlnStatusMessage StatMsgWindow, bool combofield)
+ {
+ bool success = false;
+ string info;
+ string tinfo1, tinfo2, tinfo3, tinfo4;
+ string dt;
+ string onameOpen, nnameOpen, onameClose, nnameClose, onameComma, nnameComma;
+ string onameOpenX, nnameOpenX;
+ onameOpen = "<" + oldname + ">";
+ nnameOpen = "<" + newname + ">";
+ onameOpenX = "<" + oldname + ">";
+ nnameOpenX = "<" + newname + ">";
+ onameComma = "<" + oldname + ","; // if format in attribute
+ nnameComma = "<" + newname + ",";
+ onameClose = "" + oldname + ">";
+ nnameClose = "" + newname + ">";
+ dt = string.Format("{0:yyyyMMddHHmmss}", System.DateTime.Now);
+ // first do the string replace for the group node. This will change any
+ // attributes which may have changed.
+ try
+ {
+ using (SqlConnection cn = ROAPP_SqlConnection)
+ {
+ SqlCommand command = new SqlCommand();
+ command.Connection = cn;
+ command.CommandType = CommandType.StoredProcedure;
+ command.CommandText = "getInfoByRecid";
+ command.Parameters.AddWithValue("@ROTable", child.GetAttribute("Table"));
+ command.Parameters.AddWithValue("@RecID", child.GetAttribute("RecID"));
+ using (SqlDataReader reader = command.ExecuteReader())
+ {
+ if (reader.Read())
+ info = reader.GetString(0);
+ else
+ info = null;
+ }
+ }
+
+ tinfo1 = info.Replace(onameOpen, nnameOpen);
+ tinfo2 = tinfo1.Replace(onameClose, nnameClose);
+ tinfo3 = tinfo2.Replace(onameComma, nnameComma);
+ tinfo4 = tinfo3.Replace(onameOpenX, nnameOpenX);
+ if (tinfo4 != info)
+ {
+ StatMsgWindow.StatusMessage = child.GetAttribute("MenuTitle");
+ using (SqlConnection cn = ROAPP_SqlConnection)
+ {
+ SqlCommand command = new SqlCommand();
+ command.Connection = cn;
+ command.CommandType = CommandType.StoredProcedure;
+ command.CommandText = "updateInfoByRecid";
+ command.Parameters.AddWithValue("@ROTable", child.GetAttribute("Table"));
+ command.Parameters.AddWithValue("@Info", tinfo4);
+ command.Parameters.AddWithValue("@ModDateTime", dt);
+ command.Parameters.AddWithValue("@RecID", child.GetAttribute("RecID"));
+ using (SqlDataReader reader = command.ExecuteReader())
+ {
+ success = true;
+ }
+ }
+ if (child.Name == "vlnGroup" && child.ParentNode.Name != "RO_Root")
+ {
+ XmlNodeList nodeList;
+ nodeList = child.SelectNodes(oldname);
+ foreach (XmlNode nod in nodeList)
+ {
+ XmlNode newnode = ROXml.CreateNode(XmlNodeType.Element, newname, "");
+ newnode.InnerXml = nod.InnerXml;
+ child.ReplaceChild(newnode, nod);
+ }
+ }
+ // if at top, replace strings in attributes for xml node. Only needs done
+ // for top node because remainder are done in xml string replace for entire
+ // node and written to database, but XML tree is deleted from memory and
+ // reread in as needed.
+ if (child.ParentNode.Name == "RO_Root")
+ {
+ string tmp, tmp1;
+ tmp = child.GetAttribute("RetVal");
+ if (tmp != null)
+ {
+ tmp1 = tmp.Replace(onameOpen, nnameOpen);
+ child.SetAttribute("RetVal", tmp1);
+ }
+ tmp = child.GetAttribute("MenuItem");
+ if (tmp != null)
+ {
+ string conameOpen = "<" + oldname + ",";
+ string cnnameOpen = "<" + newname + ",";
+ tmp1 = tmp.Replace(onameOpen, nnameOpen);
+ string tmp2 = tmp1.Replace(conameOpen, cnnameOpen);
+ child.SetAttribute("MenuItem", tmp2);
+ }
+ tmp = child.GetAttribute("AccPageID");
+ if (tmp != null)
+ {
+ tmp1 = tmp.Replace(onameOpen, nnameOpen);
+ child.SetAttribute("AccPageID", tmp1);
+ }
+ tmp = child.GetAttribute("GroupMenuItem");
+ if (tmp != null)
+ {
+ tmp1 = tmp.Replace(onameOpen, nnameOpen);
+ child.SetAttribute("GroupMenuItem", tmp1);
+ }
+ }
+ }
+ // if this was an RO field definition change, need to go through the XML for
+ // the ROs too.
+ if (editlevel == (int)RecordType.Schema)
+ {
+ XmlNode chldnode = (XmlNode)child.FirstChild;
+ VlnXmlElement echild;
+ while (chldnode != null)
+ {
+ if (chldnode is VlnXmlElement)
+ {
+ echild = (VlnXmlElement)chldnode;
+ if (echild.Name != "vlnGroup")
+ {
+ // If this is a group definition subtree it will only have one
+ // child, which is the text definition for the subgroup. Don't
+ // include these in the tree.
+ int levelCnt = chldnode.ChildNodes.Count;
+ string TheMenuTitle = echild.GetAttribute("MenuTitle");
+ if ((levelCnt >= 1) && !TheMenuTitle.Equals(""))
+ {
+ // read record, do string replace in info & write record. Also, replace
+ // the xml node with a node with the new name.
+ using (SqlConnection cn = ROAPP_SqlConnection)
+ {
+ SqlCommand command = new SqlCommand();
+ command.Connection = cn;
+ command.CommandType = CommandType.StoredProcedure;
+ command.CommandText = "getInfoByRecid";
+ command.Parameters.AddWithValue("@ROTable", echild.GetAttribute("Table"));
+ command.Parameters.AddWithValue("@RecID", echild.GetAttribute("RecID"));
+ using (SqlDataReader reader = command.ExecuteReader())
+ {
+ if (reader.Read())
+ info = reader.GetString(0);
+ else
+ info = null;
+ }
+ }
+ if (combofield == false)
+ {
+ tinfo1 = info.Replace(onameOpen, nnameOpen);
+ tinfo2 = tinfo1.Replace(onameClose, nnameClose);
+ XmlNodeList nodeList;
+ nodeList = echild.SelectNodes(oldname);
+ foreach (XmlNode nod in nodeList)
+ {
+ XmlNode newnode = ROXml.CreateNode(XmlNodeType.Element, newname, "");
+ newnode.InnerXml = nod.InnerXml;
+ echild.ReplaceChild(newnode, nod);
+ }
+ }
+ else // need a,b,c,d yikes
+ {
+ string nma, nmb, nmc, nmd;
+ nma = DoCmbFieldReplace(info, onameOpen, nnameOpen, "a");
+ nmb = DoCmbFieldReplace(nma, onameOpen, nnameOpen, "b");
+ nmc = DoCmbFieldReplace(nmb, onameOpen, nnameOpen, "c");
+ nmd = DoCmbFieldReplace(nmc, onameOpen, nnameOpen, "d");
+ nma = DoCmbFieldReplace(nmd, onameClose, nnameClose, "a");
+ nmb = DoCmbFieldReplace(nma, onameClose, nnameClose, "b");
+ nmc = DoCmbFieldReplace(nmb, onameClose, nnameClose, "c");
+ tinfo2 = DoCmbFieldReplace(nmc, onameClose, nnameClose, "d");
+ // replace the combo nodes with the new name, do a-d in case there are more than
+ // one value field stored for this combo type
+ for (char tmplet = 'a'; tmplet < 'e'; tmplet++)
+ {
+ XmlNodeList nodeList;
+ nodeList = echild.SelectNodes(oldname + tmplet.ToString());
+ foreach (XmlNode nod in nodeList)
+ {
+ XmlNode newnode = ROXml.CreateNode(XmlNodeType.Element, newname + tmplet, "");
+ newnode.InnerXml = nod.InnerXml;
+ echild.ReplaceChild(newnode, nod);
+ }
+ }
+ }
+
+ StatMsgWindow.StatusMessage = echild.GetAttribute("MenuTitle");
+ using (SqlConnection cn = ROAPP_SqlConnection)
+ {
+ SqlCommand command = new SqlCommand();
+ command.Connection = cn;
+ command.CommandType = CommandType.StoredProcedure;
+ command.CommandText = "updateInfoByRecid";
+ command.Parameters.AddWithValue("@ROTable", echild.GetAttribute("Table"));
+ command.Parameters.AddWithValue("@Info", tinfo2);
+ command.Parameters.AddWithValue("@ModDateTime", dt);
+ command.Parameters.AddWithValue("@RecID", echild.GetAttribute("RecID"));
+ using (SqlDataReader reader = command.ExecuteReader())
+ {
+ success = true;
+ }
+ }
+ }
+ }
+ }
+ chldnode = chldnode.NextSibling;
+ }
+ }
+ }
+ catch (Exception ex)
+ {
+ MessageBox.Show(ex.Message, "Error Processing RRO Field Change");
+ success = false;
+ }
+ return success;
+ }
+ public override bool RODB_UpdateFieldRecord(ROField myrof, VlnXmlElement myelem, string strschema,
+ string oldname, string newname, uint editlevel, bool combofield)
+ {
+ bool success = false;
+ // If this is a generic definition that was modified, i.e. from ROMaster, ask
+ // the user whether to update the generic field definition or make it local.
+ if (myrof.GetMasterRecID != null)
+ {
+ // if field is defined in the ROMaster, and we change the field name -
+ // first check if it is using one of the names used to define new
+ // setpoint or graphics databases. If so, make it a local change only!
+
+ bool changegeneric = true;
+ if (oldname != newname)
+ {
+ // if this is one of the standard names - don't let them save it.
+ bool isused = RODB_CheckForStandardName(oldname);
+ if (isused == true)
+ {
+ MessageBox.Show("The field name is used to define new Setpoints or Graphics Database.\n The update will be for this local (database) group only.", "Field name modification.");
+ changegeneric = false;
+ }
+ }
+
+ // if standard name, from above check, don't ask user if it is generic
+ // or not.
+ if (changegeneric != false)
+ {
+ System.Windows.Forms.DialogResult result = MessageBox.Show("Update Generic definition?", "Referenced Object Definition",
+ MessageBoxButtons.YesNo, MessageBoxIcon.Question);
+ if (result == DialogResult.No) changegeneric = false;
+ }
+ if (changegeneric == true)
+ {
+ success = RODB_WriteSchemaPiece(myrof.GetMasterRecID, "ROMaster", strschema);
+ if (success != true) return false;
+ // if change in fieldname, need to go through all of the databases (tables) to
+ // adjust for it.
+ if (oldname != newname)
+ {
+ VlnStatusMessage StatMsgWindow = new VlnStatusMessage("Status of RO Field Change");
+ // get root xml element
+ // loop through each subgroup under root.
+ VlnXmlElement topgroup;
+ topgroup = (VlnXmlElement)ROXml.FirstChild.FirstChild;
+ string sqlstr, recid, tbl;
+ while (topgroup != null)
+ {
+ tbl = topgroup.GetAttribute("Table");
+ // get the recid of this field definition from the current table.
+ try
+ {
+ using (SqlConnection cn = ROAPP_SqlConnection)
+ {
+ SqlCommand command = new SqlCommand();
+ command.Connection = cn;
+ command.CommandType = CommandType.StoredProcedure;
+ command.CommandText = "getRecidByRectypeInfo";
+ command.Parameters.AddWithValue("@ROTable", tbl);
+ command.Parameters.AddWithValue("@RecType", 2);
+ command.Parameters.AddWithValue("@Info", myrof.GetMasterRecID + "%");
+ using (SqlDataReader reader = command.ExecuteReader())
+ {
+ if (reader.Read())
+ {
+ recid = reader.GetString(0);
+ }
+ else
+ recid = null;
+ }
+ }
+ }
+ catch (Exception ex)
+ {
+ MessageBox.Show(ex.Message, "Error Getting Group Schema");
+ return false;
+ }
+ if (recid != null)
+ {
+ // update the local field definition record
+ StringBuilder strbld = new StringBuilder();
+ strbld.Append(myrof.GetMasterRecID);
+ strbld.Append(" ");
+ string strtype = myrof.GetFieldType.ToString();
+ strbld.Append(strtype.PadLeft(3, '0'));
+ strbld.Append(" ");
+ strbld.Append(myrof.MakeFieldName(myrof.GetFieldname));
+ success = RODB_WriteSchemaPiece(recid, topgroup.GetAttribute("Table"), strbld.ToString());
+ topgroup.SetAttribute("TreeNotData", "True");
+
+ // Update subelements too.
+ if (success == true)
+ success = RODB_UpdateFieldNames(topgroup, recid, oldname, newname, editlevel, false, StatMsgWindow, combofield);
+ topgroup = (VlnXmlElement)topgroup.NextSibling;
+ }
+ }
+ StatMsgWindow.Dispose();
+ }
+ }
+ else // change local
+ {
+ // modify the current to have the definition local.
+ success = RODB_WriteSchemaPiece(myrof.GetRecID, myelem.GetAttribute("Table"), strschema);
+ // get top group node in tree. and from there process fields if
+ // there was a change in fieldname text
+ if (success == true && oldname != newname)
+ {
+ VlnStatusMessage StatMsgWindow = new VlnStatusMessage("Status of RO Field Change");
+ // get top node - the one immediately below the RO_Root.
+ VlnXmlElement parent, startEle;
+ parent = myelem;
+ startEle = myelem;
+ while (parent.Name != "RO_Root")
+ {
+ startEle = parent;
+ parent = (VlnXmlElement)parent.ParentNode;
+ }
+ startEle.SetAttribute("TreeNotData", "True");
+ success = RODB_UpdateFieldNames(startEle, myrof.GetRecID, oldname, newname, editlevel, false, StatMsgWindow, combofield);
+ StatMsgWindow.Dispose();
+ }
+ }
+ }
+ else
+ {
+ success = RODB_WriteSchemaPiece(myrof.GetRecID, myelem.GetAttribute("Table"), strschema);
+ // changed the fieldname, change xml text.
+ if (success == true && oldname != newname)
+ {
+ VlnStatusMessage StatMsgWindow = new VlnStatusMessage("Status of RO Field Change");
+ // get top node - the one immediately below the RO_Root.
+ VlnXmlElement parent, startEle;
+ parent = myelem;
+ startEle = myelem;
+ while (parent.Name != "RO_Root")
+ {
+ startEle = parent;
+ parent = (VlnXmlElement)parent.ParentNode;
+ }
+ startEle.SetAttribute("TreeNotData", "True");
+ success = RODB_UpdateFieldNames(startEle, myrof.GetRecID, oldname, newname, editlevel, false, StatMsgWindow, combofield);
+ StatMsgWindow.Dispose();
+ }
+ }
+ return success;
+ }
+ public override XmlSchema RODB_GetGroupSchema(VlnXmlElement elem)
+ {
+ XmlSchema myschema;
+
+ VlnXmlElement parent;
+ string entireschema;
+ // if at top of tree, use this group schema information (fields in use). but if not,
+ // the parent node defines the schema for the subgroups.
+ if (elem.ParentNode.Name == "RO_Root")
+ parent = elem;
+ else
+ parent = elem;
+ while (parent != null)
+ {
+ if (parent.HasAttribute("GroupFieldsInUse") == true) break;
+
+ // if we've looped to the top, just set the parent to null. (B2004-015)
+ if (parent.ParentNode is VlnXmlElement)
+ parent = (VlnXmlElement)parent.ParentNode;
+ else
+ parent = null;
+ }
+
+ if (parent == null) return null;
+ // The group schema never gets saved as an attribute. it's always read in, because
+ // it's not used as often as the ro schema. So for the Group Schema, we're looking
+ // for 'GroupFieldsInUse'.
+ // otherwise, read in schema definitions for those 'FieldsInUse'.
+ entireschema = null;
+ string GroupFieldsInUse = parent.GetAttribute("GroupFieldsInUse");
+ int strpos = 0;
+ string Info = null;
+
+ // For each item in use, get its xmlschema text. If unique to this group, the definition
+ // exists local to this table. Otherwise, go back to the master.
+ string recid;
+ recid = GroupFieldsInUse.Substring(0, 8);
+ while (recid != null)
+ {
+ try
+ {
+ using (SqlConnection cn = ROAPP_SqlConnection)
+ {
+ SqlCommand command = new SqlCommand();
+ command.Connection = cn;
+ command.CommandType = CommandType.StoredProcedure;
+ command.CommandText = "getInfoByRecid";
+ command.Parameters.AddWithValue("@ROTable", elem.GetAttribute("Table"));
+ command.Parameters.AddWithValue("@RecID", recid);
+ using (SqlDataReader reader = command.ExecuteReader())
+ {
+ if (reader.Read())
+ {
+ Info = reader.GetString(0);
+ }
+ }
+ if (Info != null)
+ {
+ // if the info string has "<", i.e. an opening XML schema bracket, use
+ // this text as the field definition, otherwise, go to the master to get it
+ if ("<" == Info.Substring(0, 1))
+ entireschema = entireschema + Info; // use this field definition, else get from the master.
+ else
+ {
+ string recidpart = Info.Substring(0, 8);
+ string localfieldname = Info.Substring(13, Info.Length - 13);
+ SqlCommand command1 = new SqlCommand();
+ command1.Connection = cn;
+ command1.CommandType = CommandType.StoredProcedure;
+ command1.CommandText = "getInfoByRecid";
+ command1.Parameters.AddWithValue("@ROTable", "RoMaster");
+ command1.Parameters.AddWithValue("@RecID", recidpart);
+ using (SqlDataReader reader1 = command1.ExecuteReader())
+ {
+ if (reader1.Read())
+ {
+ Info = reader1.GetString(0);
+ entireschema = entireschema + Info;
+ }
+ }
+ }
+ }
+ }
+ }
+ catch (Exception ex)
+ {
+ MessageBox.Show(ex.Message, "Error Getting Group Schema");
+ return null;
+ }
+ strpos = strpos + 9;
+ if (strpos > GroupFieldsInUse.Length)
+ recid = null;
+ else
+ recid = GroupFieldsInUse.Substring(strpos, 8);
+ }
+ entireschema = schemastart + entireschema + schemaend;
+ XmlTextReader schemareader = new XmlTextReader(entireschema, XmlNodeType.Element, null);
+ try
+ {
+ myschema = XmlSchema.Read(schemareader, null);
+ return myschema;
+ }
+ catch (Exception e)
+ {
+ MessageBox.Show(e.Message, "Schema Error");
+ return null;
+ }
+ }
+ public override XmlSchema RODB_GetSchema(VlnXmlElement elem)
+ {
+ XmlSchema myschema;
+ VlnXmlElement parent;
+ string entireschema;
+ XmlNode nparent;
+ nparent = elem;
+ if (nparent is VlnXmlDocument)
+ {
+ // at top already. use this one.
+ parent = elem;
+ }
+ else
+ {
+ parent = (VlnXmlElement)nparent;
+ while (parent != null)
+ {
+ if (parent.HasAttribute("Schema") == true) break;
+ if (parent.HasAttribute("FieldsInUse") == true) break;
+ parent = (VlnXmlElement)parent.ParentNode;
+ }
+ }
+
+ // if the schema has already been read in, just use it from the schema attribute,
+ // otherwise, read in schema definitions for those 'FieldsInUse'.
+ if (parent.HasAttribute("Schema"))
+ {
+ entireschema = parent.GetAttribute("Schema");
+ }
+ else
+ {
+ entireschema = null;
+ string FieldsInUse = parent.GetAttribute("FieldsInUse");
+ int strpos = 0;
+ string Info = null;
+
+ // For each item in use, get its xmlschema text. If unique to this group, the definition
+ // exists local to this table. Otherwise, go back to the master.
+ string recid;
+ recid = FieldsInUse.Substring(0, 8);
+ while (recid != null)
+ {
+ try
+ {
+ using (SqlConnection cn = ROAPP_SqlConnection)
+ {
+ SqlCommand command = new SqlCommand();
+ command.Connection = cn;
+ command.CommandType = CommandType.StoredProcedure;
+ command.CommandText = "getInfoByRecid";
+ command.Parameters.AddWithValue("@ROTable", elem.GetAttribute("Table"));
+ command.Parameters.AddWithValue("@RecID", recid);
+ using (SqlDataReader reader = command.ExecuteReader())
+ {
+ if (reader.Read())
+ {
+ Info = reader.GetString(0);
+ }
+ }
+ if (Info != null)
+ {
+ // if the info string has "<", i.e. an opening XML schema bracket, use
+ // this text as the field definition, otherwise, go to the master to get
+ // it.
+ if ("<" == Info.Substring(0, 1))
+ {
+ // use this field definition, else get from the master.
+ entireschema = entireschema + Info;
+ }
+ else
+ {
+ string recidpart = Info.Substring(0, 8);
+ string localfieldname = Info.Substring(13, Info.Length - 13);
+ SqlCommand command1 = new SqlCommand();
+ command1.Connection = cn;
+ command1.CommandType = CommandType.StoredProcedure;
+ command1.CommandText = "getInfoByRecid";
+ command1.Parameters.AddWithValue("@ROTable", "RoMaster");
+ command1.Parameters.AddWithValue("@RecID", recidpart);
+ using (SqlDataReader reader1 = command1.ExecuteReader())
+ {
+ if (reader1.Read())
+ {
+ // check if field name is same, if not, use local name.
+ string goodname;
+ Info = reader1.GetString(0);
+ int indx1 = Info.IndexOf("\"");
+ int indx2 = Info.IndexOf("\"", indx1 + 1);
+ string masterfieldname = Info.Substring(indx1 + 1, indx2 - indx1 - 1);
+ if (localfieldname != masterfieldname)
+ goodname = Info.Replace(masterfieldname, localfieldname);
+ else
+ goodname = Info;
+
+ entireschema = entireschema + goodname;
+ }
+ }
+ }
+ strpos = strpos + 9;
+ if (strpos > FieldsInUse.Length)
+ recid = null;
+ else
+ recid = FieldsInUse.Substring(strpos, 8);
+ }
+ }
+ }
+ catch (Exception ex)
+ {
+ MessageBox.Show(ex.Message, "Error Getting Schema");
+ return null;
+ }
+ }
+ entireschema = schemastart + entireschema + schemaend;
+ }
+ XmlTextReader schemareader = new XmlTextReader(entireschema, XmlNodeType.Element, null);
+ try
+ {
+ myschema = XmlSchema.Read(schemareader, null);
+ parent.SetAttribute("Schema", entireschema);
+ return myschema;
+ }
+ catch (Exception e)
+ {
+ MessageBox.Show(e.Message, "Schema Read Error");
+ return null;
+ }
+ }
+ public override int RODB_GetNumberOfROValueRecords(string tablename)
+ {
+ int ROCnt = 0;
+ try
+ {
+ using (SqlConnection cn = ROAPP_SqlConnection)
+ {
+ SqlCommand command = new SqlCommand();
+ command.Connection = cn;
+ command.CommandType = CommandType.StoredProcedure;
+ command.CommandText = "getCountRectypeByRectype";
+ command.Parameters.AddWithValue("@ROTable", tablename);
+ command.Parameters.AddWithValue("@RecType", (int)RecordType.RRO);
+ using (SqlDataReader reader = command.ExecuteReader())
+ {
+ if (reader.Read())
+ {
+ ROCnt = reader.GetInt32(0);
+ }
+ }
+ }
+ }
+ catch (Exception ex)
+ {
+ MessageBox.Show(ex.Message, "Error Getting Number of RO Value Records");
+ return 0;
+ }
+ return ROCnt;
+ }
+ public override int RODB_GetNumberOfGroupRecords(string tablename)
+ {
+ int GrpCnt = 0;
+ try
+ {
+ using (SqlConnection cn = ROAPP_SqlConnection)
+ {
+ SqlCommand command = new SqlCommand();
+ command.Connection = cn;
+ command.CommandType = CommandType.StoredProcedure;
+ command.CommandText = "getCountRectypeByRectype";
+ command.Parameters.AddWithValue("@ROTable", tablename);
+ command.Parameters.AddWithValue("@RecType", (int)RecordType.Group);
+ using (SqlDataReader reader = command.ExecuteReader())
+ {
+ if (reader.Read())
+ {
+ GrpCnt = reader.GetInt32(0);
+ }
+ }
+ }
+ }
+ catch (Exception ex)
+ {
+ MessageBox.Show(ex.Message, "Error Getting Number of Group Value Records");
+ return 0;
+ }
+ return GrpCnt;
+ }
+ #endregion
+ public static bool TestConnect(string constring)
+ {
+ bool success = false;
+ using (SqlConnection connection = new SqlConnection(constring))
+ {
+ try
+ {
+ connection.Open();
+ if (connection.State == ConnectionState.Open)
+ {
+ // now see if there is an roall table
+ SqlCommand command = new SqlCommand();
+ command.Connection = connection;
+ command.CommandType = CommandType.Text;
+ command.CommandText = "SELECT count(*) FROM roall";
+ using (SqlDataReader reader = command.ExecuteReader())
+ {
+ if (reader.Read())
+ {
+ int count = reader.GetInt32(0);
+ if (count > 0) success = true;
+ }
+ }
+ }
+ }
+ catch (Exception ex)
+ {
+ }
+ }
+ return success;
+ }
+ public static string GetSqlDbConnectString(string origConString)
+ {
+ string value = origConString;
+ InputBox inpbox = new InputBox(origConString);
+ DialogResult dr = inpbox.ShowDialog();
+ if (dr == DialogResult.OK)
+ {
+ // test & if successful, save and return:
+ if (TestConnect(inpbox.ResultConnectString)) return inpbox.ResultConnectString;
+ }
+ return null;
+ }
+ public override bool RODB_WriteSqlConnectToAccess(string newConectStr)
+ {
+ return false;
+ }
+ }
+
+}
\ No newline at end of file
diff --git a/PROMS/ReferencedObjects/LibSource/RODBInterface/VlnXml.cs b/PROMS/ReferencedObjects/LibSource/RODBInterface/VlnXml.cs
index 3c6a4ae9..be553d39 100644
--- a/PROMS/ReferencedObjects/LibSource/RODBInterface/VlnXml.cs
+++ b/PROMS/ReferencedObjects/LibSource/RODBInterface/VlnXml.cs
@@ -939,7 +939,7 @@ namespace RODBInterface
// First get the fields used for this Group.
string tmp=null; // needed for inuse call
ArrayList AvailList = myrodb.RODB_GetFields(this, 0);
- ArrayList InUseList = myrodb.RODB_GetFieldsInUse(this, AvailList, "GroupFieldsInUse", ref tmp, true);
+ ArrayList InUseList = myrodb.RODB_GetFieldsInUse(this, AvailList, "GroupFieldsInUse", ref tmp, false);
// For each field, print the header (field name) & then print data if it exists.
if (InUseList != null)
@@ -1009,7 +1009,7 @@ namespace RODBInterface
// Get used fields for this RO.
string tmp=null; // needed for inuse call
ArrayList AvailList = myrodb.RODB_GetFields(this, 0);
- ArrayList InUseList = myrodb.RODB_GetFieldsInUse(this, AvailList, "FieldsInUse", ref tmp, true);
+ ArrayList InUseList = myrodb.RODB_GetFieldsInUse(this, AvailList, "FieldsInUse", ref tmp, false);
// put out the stored headers, i.e. the group titles up the tree.
xmldoc.doHeader(headers);
@@ -1020,7 +1020,6 @@ namespace RODBInterface
xmldoc.writeRROBegin();
xmldoc.writeInt(8);
xmldoc.writeText(myrodb.MyDBID + MyROID);
- Console.WriteLine("ROID={0}", myrodb.MyDBID + MyROID);
xmldoc.writeInt(7);
xmldoc.writeText(this.GetAttribute("AccPageID").Trim());
// add items to the InUseList box.
@@ -1111,6 +1110,7 @@ namespace RODBInterface
// ShowGroup processes the input group node for the complete report by
// using ShowGroupDetail to output data for the group and ShowRRO to
// output data for the RO
+ DateTime last = DateTime.Now; // use these to control status message output
private bool ShowGroup(RODB myrodb, ArrayList headers, VlnStatusMessage showStat)
{
XmlNode chldnode;
@@ -1154,9 +1154,9 @@ namespace RODBInterface
if (chldnode is VlnXmlElement)
{
VlnXmlElement elem = (VlnXmlElement) chldnode;
- if (showStat !=null)
+ if (showStat != null)
showStat.StatusMessage = elem.InnerText;
-
+
// if it's a group, recurse through it.
if (chldnode.Name == "vlnGroup")
elem.ShowGroup(myrodb, headers, showStat);
@@ -1166,8 +1166,14 @@ namespace RODBInterface
int levelcnt = chldnode.ChildNodes.Count;
bool isParDisData = chldnode.Name == "Parameter__Display__Data";
string TheMenuTitle = elem.GetAttribute("MenuTitle");
- if (showStat != null)
- showStat.StatusMessage = TheMenuTitle;
+ if (showStat != null)
+ {
+ if (TimeSpan.FromTicks(DateTime.Now.Ticks - last.Ticks).Seconds > 1)
+ {
+ showStat.StatusMessage = TheMenuTitle;
+ last = DateTime.Now;
+ }
+ }
if (!isParDisData && ((levelcnt > 1) || (levelcnt==1 && !TheMenuTitle.Equals(""))))
elem.ShowRRO(myrodb, headers);
}
diff --git a/PROMS/VEPROMS User Interface/PROMSFixes.Sql b/PROMS/VEPROMS User Interface/PROMSFixes.Sql
index 796d1ab9..282954d7 100644
--- a/PROMS/VEPROMS User Interface/PROMSFixes.Sql
+++ b/PROMS/VEPROMS User Interface/PROMSFixes.Sql
@@ -15511,8 +15511,8 @@ BEGIN TRY -- Try Block
set nocount on
DECLARE @RevDate varchar(255)
DECLARE @RevDescription varchar(255)
- set @RevDate = '12/13/2019 7:00 AM'
- set @RevDescription = 'Procedure number length when adding procedures'
+ set @RevDate = '01/09/2020 11:00 AM'
+ set @RevDescription = 'Referenced Object data in sql server'
Select cast(@RevDate as datetime) RevDate, @RevDescription RevDescription
PRINT 'SQL Code Revision ' + @RevDate + ' - ' + @RevDescription
IF( @@TRANCOUNT > 0 ) COMMIT
diff --git a/PROMS/VEPROMS User Interface/ROBuild.Sql b/PROMS/VEPROMS User Interface/ROBuild.Sql
new file mode 100644
index 00000000..df3f11af
--- /dev/null
+++ b/PROMS/VEPROMS User Interface/ROBuild.Sql
@@ -0,0 +1,828 @@
+/*****************************************************************************
+ Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE
+ Copyright 2019 - Volian Enterprises, Inc. All rights reserved.
+*****************************************************************************/
+
+--/**** DBA FUNCTION ****/
+--/* The following can be used as a basis for creating the sql RO database for storing of referenced object for PROMS */
+--/* Note that the default sql database name will be generated in during conversion as the current PROMS database name suffixed with '_RO'. */
+--/* In the script below, the [VE_PROMS_DB_RO] should be replaced with the name that the RO database should be given */
+--/* In the script below, the pathname/filename of the physical database should be modified also. */
+--USE [master]
+--GO
+--/****** Object: Database [VEPROMS_DB_RO] Script Date: 7/23/2019 9:42:54 AM ******/
+--CREATE DATABASE [VEPROMS_DB_RO]
+-- ON PRIMARY
+--( NAME = N'VEPROMS_DB_RO', FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL11.SQLEXPRESS_2012\MSSQL\DATA\VEPROMS_DB_RO.mdf' , SIZE = 5120KB , MAXSIZE = UNLIMITED, FILEGROWTH = 1024KB )
+-- LOG ON
+--( NAME = N'VEPROMS_DB_RO_log', FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL11.SQLEXPRESS_2012\MSSQL\DATA\VEPROMS_DB_RO_log.ldf' , SIZE = 2816KB , MAXSIZE = 2048GB , FILEGROWTH = 10%)
+--GO
+--ALTER DATABASE [VEPROMS_DB_RO] SET COMPATIBILITY_LEVEL = 110
+--GO
+--ALTER DATABASE [VEPROMS_DB_RO] set TRUSTWORTHY ON;
+--GO
+--USE VEPROMS_DB_RO
+--GO
+--EXEC dbo.sp_changedbowner @loginame = N'sa', @map = false
+--GO
+--sp_configure 'show advanced options', 1;
+--GO
+--RECONFIGURE;
+--GO
+--sp_configure 'clr enabled', 1;
+--GO
+--RECONFIGURE;
+--GO
+--IF (1 = FULLTEXTSERVICEPROPERTY('IsFullTextInstalled'))
+--begin
+--EXEC [VEPROMS_DB_RO].[dbo].[sp_fulltext_database] @action = 'enable'
+--end
+--GO
+--USE [VEPROMS_DB_RO]
+--GO
+--/**** END OF DBA FUNCTION ****/
+
+
+-- AFTER THE DATABASE IS CREATED, the following should be executed to create the ROALL table & create the sql stored procedures that */
+-- are used by PROMS, to migrate and access the ro data.
+if db_name() in('master','model','msdn','tempdb')
+begin
+ DECLARE @ErrorMsg varchar(255)
+ SET @ErrorMsg = 'Don''t add these procedures and functions to ' + db_name()
+ PRINT '=========================================================================='
+ PRINT ''
+ PRINT @ErrorMsg
+ PRINT ''
+ PRINT 'You probably want to be in the VEPROMS database'
+ PRINT ''
+ PRINT '=========================================================================='
+ RAISERROR (@ErrorMsg, 20, -1) with log
+ RETURN
+end
+print 'Adding procedures and functions to ' + db_name()
+GO
+SET ANSI_NULLS ON
+GO
+SET QUOTED_IDENTIFIER ON
+GO
+
+/****** Object: StoredProcedure [dbo].[vlnErrorHandler] ******/
+IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[vlnErrorHandler]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
+ DROP PROCEDURE [vlnErrorHandler];
+GO
+/*****************************************************************************
+ Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE
+ Copyright 2019 - Volian Enterprises, Inc. All rights reserved.
+*****************************************************************************/
+CREATE PROCEDURE [dbo].[vlnErrorHandler]
+ (@ExpectedCount int=-1
+ ,@MessageFormat nvarchar(512)=N'Expected RowCount (%d) not met (%d)')
+WITH EXECUTE AS OWNER
+AS
+BEGIN
+ DECLARE @ErrorMessage NVARCHAR(4000), @ErrorNumber INT, @ErrorSeverity INT, @ErrorState INT, @ErrorProcedure NVARCHAR(126)
+ , @ErrorLine INT, @RowCount INT;
+ SELECT @ErrorMessage = ERROR_MESSAGE(), @ErrorSeverity = ERROR_SEVERITY(), @ErrorState = ERROR_STATE(),@ErrorNumber = ERROR_NUMBER()
+ , @ErrorLine = ERROR_LINE(), @ErrorProcedure = ERROR_PROCEDURE(), @RowCount = @@RowCount;
+ IF @ErrorNumber > 0
+ BEGIN
+ IF @ErrorProcedure = OBJECT_NAME(@@PROCID) -- If the Procedure is the current procedure just pass the error message
+ RAISERROR (@ErrorMessage, @ErrorSeverity, @ErrorState)
+ ELSE -- Add in the procedure name and line as well as the error number
+ RAISERROR (N'%s[%d] - (%d) %s', @ErrorSeverity, @ErrorState, @ErrorProcedure, @ErrorLine, @ErrorNumber, @ErrorMessage)
+ END
+ ELSE IF @ExpectedCount <> -1 AND @ExpectedCount <> @RowCount
+ RAISERROR (@MessageFormat, 16, 1, @ExpectedCount, @RowCount)
+END
+GO
+-- Display the status of Proc creation
+IF (@@Error = 0) PRINT 'Procedure Creation: vlnErrorHandler Succeeded'
+ELSE PRINT 'Procedure Creation: vlnErrorHandler Error on Creation'
+GO
+
+/****** Object: StoredProcedure [dbo].[deleteByParid] ******/
+IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[deleteByParid]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
+ DROP PROCEDURE [deleteByParid];
+GO
+/*****************************************************************************
+ Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE
+ Copyright 2019 - Volian Enterprises, Inc. All rights reserved.
+*****************************************************************************/
+CREATE PROCEDURE [dbo].[deleteByParid]
+(
+ @ROTable char(8),
+ @ParentID char(8)
+)
+WITH EXECUTE AS OWNER
+AS
+BEGIN TRY -- Try Block
+ BEGIN TRANSACTION
+ DELETE ROALL
+ WHERE [ROTable] = @ROTable and [ParentID] = @ParentID
+ IF( @@TRANCOUNT > 0 ) COMMIT
+END TRY
+BEGIN CATCH -- Catch Block
+ IF( @@TRANCOUNT = 1 ) ROLLBACK -- Only rollback if top level
+ ELSE IF( @@TRANCOUNT > 1 ) COMMIT -- Otherwise commit. Top level will rollback
+ EXEC vlnErrorHandler
+END CATCH
+GO
+-- Display the status of Proc creation
+IF (@@Error = 0) PRINT 'Procedure Creation: deleteByParid Succeeded'
+ELSE PRINT 'Procedure Creation: deleteByParid Error on Creation'
+GO
+
+/****** Object: StoredProcedure [dbo].[deleteByRecid] ******/
+IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[deleteByRecid]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
+ DROP PROCEDURE [deleteByRecid];
+GO
+/*****************************************************************************
+ Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE
+ Copyright 2019 - Volian Enterprises, Inc. All rights reserved.
+*****************************************************************************/
+CREATE PROCEDURE [dbo].[deleteByRecid]
+(
+ @ROTable char(8),
+ @RecID char(8)
+)
+WITH EXECUTE AS OWNER
+AS
+BEGIN TRY -- Try Block
+ BEGIN TRANSACTION
+ DELETE ROALL
+ WHERE [ROTable] = @ROTable and [RecID] = @RecID
+ IF( @@TRANCOUNT > 0 ) COMMIT
+END TRY
+BEGIN CATCH -- Catch Block
+ IF( @@TRANCOUNT = 1 ) ROLLBACK -- Only rollback if top level
+ ELSE IF( @@TRANCOUNT > 1 ) COMMIT -- Otherwise commit. Top level will rollback
+ EXEC vlnErrorHandler
+END CATCH
+GO
+-- Display the status of Proc creation
+IF (@@Error = 0) PRINT 'Procedure Creation: deleteByRecid Succeeded'
+ELSE PRINT 'Procedure Creation: deleteByRecid Error on Creation'
+GO
+
+/****** Object: StoredProcedure [dbo].[deleteByROTable] ******/
+IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[deleteByROTable]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
+ DROP PROCEDURE [deleteByROTable];
+GO
+/*****************************************************************************
+ Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE
+ Copyright 2019 - Volian Enterprises, Inc. All rights reserved.
+*****************************************************************************/
+CREATE PROCEDURE [dbo].[deleteByROTable]
+(
+ @ROTable char(8)
+)
+WITH EXECUTE AS OWNER
+AS
+BEGIN TRY -- Try Block
+ BEGIN TRANSACTION
+ DELETE ROALL
+ WHERE [ROTable] = @ROTable
+ IF( @@TRANCOUNT > 0 ) COMMIT
+END TRY
+BEGIN CATCH -- Catch Block
+ IF( @@TRANCOUNT = 1 ) ROLLBACK -- Only rollback if top level
+ ELSE IF( @@TRANCOUNT > 1 ) COMMIT -- Otherwise commit. Top level will rollback
+ EXEC vlnErrorHandler
+END CATCH
+GO
+-- Display the status of Proc creation
+IF (@@Error = 0) PRINT 'Procedure Creation: deleteByROTable Succeeded'
+ELSE PRINT 'Procedure Creation: deleteByROTable Error on Creation'
+GO
+
+/****** Object: StoredProcedure [dbo].[getChildData] ******/
+IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[getChildData]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
+ DROP PROCEDURE [getChildData];
+GO
+/*****************************************************************************
+ Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE
+ Copyright 2019 - Volian Enterprises, Inc. All rights reserved.
+*****************************************************************************/
+CREATE PROCEDURE [dbo].[getChildData]
+
+(
+ @ROTable char(8),
+ @ParentID char(8)
+)
+WITH EXECUTE AS OWNER
+AS
+ SELECT RecID,RecType, isnull(AccPageID, '') AccPageID, Info
+ FROM [ROALL]
+ where ROTable = @ROTable and (RecType = 3 or RecType = 5) and ParentID=@ParentID ORDER BY RecID ASC
+ RETURN
+GO
+-- Display the status of Proc creation
+IF (@@Error = 0) PRINT 'Procedure Creation: getChildData Succeeded'
+ELSE PRINT 'Procedure Creation: getChildData Error on Creation'
+GO
+
+/****** Object: StoredProcedure [dbo].[getCountChildrenOfChildData] ******/
+IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[getCountChildrenOfChildData]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
+ DROP PROCEDURE [getCountChildrenOfChildData];
+GO
+/*****************************************************************************
+ Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE
+ Copyright 2019 - Volian Enterprises, Inc. All rights reserved.
+*****************************************************************************/
+CREATE PROCEDURE [dbo].[getCountChildrenOfChildData]
+(
+ @ROTable char(8),
+ @ParentID char(8)
+)
+WITH EXECUTE AS OWNER
+AS
+ SELECT R1.ParentID,COUNT(*) AS CNT
+ FROM ROALL R1 INNER JOIN ROALL R2 ON R1.ParentID = R2.RecID
+ WHERE (R1.RecType = 3 or R1.RecType = 5) and R1.ROTable = @ROTable and R2.ROTable = @ROTable and R2.ParentID = @ParentID group by R1.ParentID
+ RETURN
+GO
+-- Display the status of Proc creation
+IF (@@Error = 0) PRINT 'Procedure Creation: getCountChildrenOfChildData Succeeded'
+ELSE PRINT 'Procedure Creation: getCountChildrenOfChildData Error on Creation'
+GO
+
+/****** Object: StoredProcedure [dbo].[getCountRecidByAccid] ******/
+IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[getCountRecidByAccid]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
+ DROP PROCEDURE [getCountRecidByAccid];
+GO
+/*****************************************************************************
+ Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE
+ Copyright 2019 - Volian Enterprises, Inc. All rights reserved.
+*****************************************************************************/
+CREATE PROCEDURE [dbo].[getCountRecidByAccid]
+(
+ @ROTable char(8),
+ @AccPageID char(32)
+)
+WITH EXECUTE AS OWNER
+AS
+ SELECT COUNT (RecID)
+ FROM [ROALL]
+ WHERE [ROTable]=@ROTable AND AccPageID=@AccPageID
+GO
+-- Display the status of Proc creation
+IF (@@Error = 0) PRINT 'Procedure Creation: getCountRecidByAccid Succeeded'
+ELSE PRINT 'Procedure Creation: getCountRecidByAccid Error on Creation'
+GO
+
+/****** Object: StoredProcedure [dbo].[getCountRecidByAccidNotRecid] ******/
+IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[getCountRecidByAccidNotRecid]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
+ DROP PROCEDURE [getCountRecidByAccidNotRecid];
+GO
+/*****************************************************************************
+ Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE
+ Copyright 2019 - Volian Enterprises, Inc. All rights reserved.
+*****************************************************************************/
+CREATE PROCEDURE [dbo].[getCountRecidByAccidNotRecid]
+(
+ @ROTable char(8),
+ @RecID char(8),
+ @AccPageID char(32)
+)
+WITH EXECUTE AS OWNER
+AS
+ SELECT COUNT (RecID)
+ FROM [ROALL]
+ WHERE [ROTable]=@ROTable AND AccPageID=@AccPageID AND (NOT RecID = @RecID)
+GO
+-- Display the status of Proc creation
+IF (@@Error = 0) PRINT 'Procedure Creation: getCountRecidByAccidNotRecid Succeeded'
+ELSE PRINT 'Procedure Creation: getCountRecidByAccidNotRecid Error on Creation'
+GO
+
+/****** Object: StoredProcedure [dbo].[getCountRecidByParid] ******/
+IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[getCountRecidByParid]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
+ DROP PROCEDURE [getCountRecidByParid];
+GO
+/*****************************************************************************
+ Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE
+ Copyright 2019 - Volian Enterprises, Inc. All rights reserved.
+*****************************************************************************/
+CREATE PROCEDURE [dbo].[getCountRecidByParid]
+
+(
+ @ROTable char(8),
+ @ParentID char(8)
+)
+WITH EXECUTE AS OWNER
+AS
+ SELECT COUNT (RecID)
+ FROM [ROALL]
+ WHERE [ROTable]=@ROTable AND [ParentID]=@ParentID
+ RETURN
+GO
+-- Display the status of Proc creation
+IF (@@Error = 0) PRINT 'Procedure Creation: getCountRecidByParid Succeeded'
+ELSE PRINT 'Procedure Creation: getCountRecidByParid Error on Creation'
+GO
+
+/****** Object: StoredProcedure [dbo].[getCountRectypeByRectype] ******/
+IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[getCountRectypeByRectype]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
+ DROP PROCEDURE [getCountRectypeByRectype];
+GO
+/*****************************************************************************
+ Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE
+ Copyright 2019 - Volian Enterprises, Inc. All rights reserved.
+*****************************************************************************/
+CREATE PROCEDURE [dbo].[getCountRectypeByRectype]
+(
+ @ROTable char(8),
+ @RecType char(32)
+)
+WITH EXECUTE AS OWNER
+AS
+ SELECT COUNT (RecType)
+ FROM [ROALL]
+ WHERE [ROTable]=@ROTable AND RecType=@RecType
+GO
+-- Display the status of Proc creation
+IF (@@Error = 0) PRINT 'Procedure Creation: getCountRectypeByRectype Succeeded'
+ELSE PRINT 'Procedure Creation: getCountRectypeByRectype Error on Creation'
+GO
+
+/****** Object: StoredProcedure [dbo].[getGroupAndSubgroups] ******/
+IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[getGroupAndSubgroups]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
+ DROP PROCEDURE [getGroupAndSubgroups];
+GO
+/*****************************************************************************
+ Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE
+ Copyright 2019 - Volian Enterprises, Inc. All rights reserved.
+*****************************************************************************/
+CREATE PROCEDURE [dbo].[getGroupAndSubgroups]
+
+(
+ @ROTable char(8)
+)
+WITH EXECUTE AS OWNER
+AS
+ SELECT RecID, RecType, ParentID, isnull(AccPageID, '') AccPageID, Info
+ FROM [ROALL]
+ WHERE [ROTable]=@ROTable AND (RecType = 3 or RecType = 5) AND ParentID <> '00000002'
+ ORDER BY ParentID,RecID ASC
+ RETURN
+GO
+-- Display the status of Proc creation
+IF (@@Error = 0) PRINT 'Procedure Creation: getGroupAndSubgroups Succeeded'
+ELSE PRINT 'Procedure Creation: getGroupAndSubgroups Error on Creation'
+GO
+
+/****** Object: StoredProcedure [dbo].[getInfoByParidRectype] ******/
+IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[getInfoByParidRectype]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
+ DROP PROCEDURE [getInfoByParidRectype];
+GO
+/*****************************************************************************
+ Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE
+ Copyright 2019 - Volian Enterprises, Inc. All rights reserved.
+*****************************************************************************/
+CREATE PROCEDURE [dbo].[getInfoByParidRectype]
+
+(
+ @ROTable char(8),
+ @ParentID char(8),
+ @RecType int
+)
+WITH EXECUTE AS OWNER
+AS
+ SELECT [Info]
+ FROM [ROALL]
+ WHERE [ROTable]=@ROTable AND [ParentID]=@ParentID AND [RecType]=@RecType
+ RETURN
+GO
+-- Display the status of Proc creation
+IF (@@Error = 0) PRINT 'Procedure Creation: getInfoByParidRectype Succeeded'
+ELSE PRINT 'Procedure Creation: getInfoByParidRectype Error on Creation'
+GO
+
+/****** Object: StoredProcedure [dbo].[getInfoByRecid] ******/
+IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[getInfoByRecid]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
+ DROP PROCEDURE [getInfoByRecid];
+GO
+/*****************************************************************************
+ Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE
+ Copyright 2019 - Volian Enterprises, Inc. All rights reserved.
+*****************************************************************************/
+CREATE PROCEDURE [dbo].[getInfoByRecid]
+(
+ @ROTable char(8),
+ @RecID char(8)
+)
+WITH EXECUTE AS OWNER
+AS
+ SELECT [Info]
+ FROM [ROALL]
+ WHERE [ROTable]=@ROTable AND [RecID]=@RecID
+ RETURN
+GO
+-- Display the status of Proc creation
+IF (@@Error = 0) PRINT 'Procedure Creation: getInfoByRecid Succeeded'
+ELSE PRINT 'Procedure Creation: getInfoByRecid Error on Creation'
+GO
+
+/****** Object: StoredProcedure [dbo].[getInfoByRecidRectype] ******/
+IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[getInfoByRecidRectype]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
+ DROP PROCEDURE [getInfoByRecidRectype];
+GO
+/*****************************************************************************
+ Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE
+ Copyright 2019 - Volian Enterprises, Inc. All rights reserved.
+*****************************************************************************/
+CREATE PROCEDURE [dbo].[getInfoByRecidRectype]
+(
+ @ROTable char(8),
+ @RecID char(8),
+ @RecType int
+)
+WITH EXECUTE AS OWNER
+AS
+ SELECT [Info]
+ FROM [ROALL]
+ WHERE [ROTable]=@ROTable AND [RecID]=@RecID AND [RecType]=@RecType
+ RETURN
+GO
+-- Display the status of Proc creation
+IF (@@Error = 0) PRINT 'Procedure Creation: getInfoByRecidRectype Succeeded'
+ELSE PRINT 'Procedure Creation: getInfoByRecidRectype Error on Creation'
+GO
+
+/****** Object: StoredProcedure [dbo].[getParidAccidInfoByRecid] ******/
+IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[getParidAccidInfoByRecid]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
+ DROP PROCEDURE [getParidAccidInfoByRecid];
+GO
+/*****************************************************************************
+ Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE
+ Copyright 2019 - Volian Enterprises, Inc. All rights reserved.
+*****************************************************************************/
+CREATE PROCEDURE [dbo].[getParidAccidInfoByRecid]
+(
+ @ROTable char(8),
+ @RecId char(8)
+)
+WITH EXECUTE AS OWNER
+AS
+ SELECT [ParentID], [AccPageID], [Info]
+ FROM [ROALL]
+ WHERE [ROTable]=@ROTable AND [RecID]=@RecId
+ RETURN
+GO
+-- Display the status of Proc creation
+IF (@@Error = 0) PRINT 'Procedure Creation: getParidAccidInfoByRecid Succeeded'
+ELSE PRINT 'Procedure Creation: getParidAccidInfoByRecid Error on Creation'
+GO
+
+/****** Object: StoredProcedure [dbo].[getParidAccidInfoByRectypeParid] ******/
+IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[getParidAccidInfoByRectypeParid]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
+ DROP PROCEDURE [getParidAccidInfoByRectypeParid];
+GO
+/*****************************************************************************
+ Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE
+ Copyright 2019 - Volian Enterprises, Inc. All rights reserved.
+*****************************************************************************/
+CREATE PROCEDURE [dbo].[getParidAccidInfoByRectypeParid]
+(
+ @ROTable char(8),
+ @RecType int,
+ @ParentID char(8)
+)
+WITH EXECUTE AS OWNER
+AS
+ SELECT [ParentID], [AccPageID], [Info]
+ FROM [ROALL]
+ WHERE [ROTable]=@ROTable AND [RecType]=@RecType AND [ParentID]= @ParentID
+ RETURN
+GO
+-- Display the status of Proc creation
+IF (@@Error = 0) PRINT 'Procedure Creation: getParidAccidInfoByRectypeParid Succeeded'
+ELSE PRINT 'Procedure Creation: getParidAccidInfoByRectypeParid Error on Creation'
+GO
+
+/****** Object: StoredProcedure [dbo].[getRecidByRectypeInfo] ******/
+IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[getRecidByRectypeInfo]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
+ DROP PROCEDURE [getRecidByRectypeInfo];
+GO
+/*****************************************************************************
+ Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE
+ Copyright 2019 - Volian Enterprises, Inc. All rights reserved.
+*****************************************************************************/
+CREATE PROCEDURE [dbo].[getRecidByRectypeInfo]
+(
+ @ROTable char(8),
+ @RecType int,
+ @mstrecid nvarchar(max)
+)
+WITH EXECUTE AS OWNER
+AS
+ SELECT [RecID]
+ FROM [ROALL]
+ WHERE [ROTable]=@ROTable AND [RecType]=@RecType AND Info like @mstrecid
+ RETURN
+GO
+-- Display the status of Proc creation
+IF (@@Error = 0) PRINT 'Procedure Creation: getRecidByRectypeInfo Succeeded'
+ELSE PRINT 'Procedure Creation: getRecidByRectypeInfo Error on Creation'
+GO
+
+/****** Object: StoredProcedure [dbo].[getRecidInfoByRectype] ******/
+IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[getRecidInfoByRectype]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
+ DROP PROCEDURE [getRecidInfoByRectype];
+GO
+/*****************************************************************************
+ Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE
+ Copyright 2019 - Volian Enterprises, Inc. All rights reserved.
+*****************************************************************************/
+CREATE PROCEDURE [dbo].[getRecidInfoByRectype]
+(
+ @ROTable char(8),
+ @RecType int
+)
+WITH EXECUTE AS OWNER
+AS
+ SELECT [RecID], [Info]
+ FROM [ROALL]
+ WHERE [ROTable]=@ROTable AND [RecType]=@RecType
+ RETURN
+GO
+-- Display the status of Proc creation
+IF (@@Error = 0) PRINT 'Procedure Creation: getRecidInfoByRectype Succeeded'
+ELSE PRINT 'Procedure Creation: getRecidInfoByRectype Error on Creation'
+GO
+
+/****** Object: StoredProcedure [dbo].[getRecidInfoByRectypeAsc] ******/
+IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[getRecidInfoByRectypeAsc]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
+ DROP PROCEDURE [getRecidInfoByRectypeAsc];
+GO
+/*****************************************************************************
+ Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE
+ Copyright 2019 - Volian Enterprises, Inc. All rights reserved.
+*****************************************************************************/
+CREATE PROCEDURE [dbo].[getRecidInfoByRectypeAsc]
+(
+ @ROTable char(8),
+ @RecType int
+)
+WITH EXECUTE AS OWNER
+AS
+ SELECT [RecID], [Info]
+ FROM [ROALL]
+ WHERE [ROTable]=@ROTable AND [RecType]=@RecType
+ ORDER BY RecID ASC
+ RETURN
+GO
+-- Display the status of Proc creation
+IF (@@Error = 0) PRINT 'Procedure Creation: getRecidInfoByRectypeAsc Succeeded'
+ELSE PRINT 'Procedure Creation: getRecidInfoByRectypeAsc Error on Creation'
+GO
+
+/****** Object: StoredProcedure [dbo].[getRecidInfoByRectypeParidAsc] ******/
+IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[getRecidInfoByRectypeParidAsc]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
+ DROP PROCEDURE [getRecidInfoByRectypeParidAsc];
+GO
+/*****************************************************************************
+ Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE
+ Copyright 2019 - Volian Enterprises, Inc. All rights reserved.
+*****************************************************************************/
+CREATE PROCEDURE [dbo].[getRecidInfoByRectypeParidAsc]
+(
+ @ROTable char(8),
+ @RecType int,
+ @ParentID char(8)
+)
+WITH EXECUTE AS OWNER
+AS
+ SELECT [RecID], [Info]
+ FROM [ROALL]
+ WHERE [ROTable]=@ROTable AND [RecType]=@RecType AND [ParentID]=@ParentID
+ ORDER BY RecID ASC
+ RETURN
+GO
+-- Display the status of Proc creation
+IF (@@Error = 0) PRINT 'Procedure Creation: getRecidInfoByRectypeParidAsc Succeeded'
+ELSE PRINT 'Procedure Creation: getRecidInfoByRectypeParidAsc Error on Creation'
+GO
+
+/****** Object: StoredProcedure [dbo].[insertAllRectypes] ******/
+IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[insertAllRectypes]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
+ DROP PROCEDURE [insertAllRectypes];
+GO
+/*****************************************************************************
+ Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE
+ Copyright 2019 - Volian Enterprises, Inc. All rights reserved.
+*****************************************************************************/
+CREATE PROCEDURE [dbo].[insertAllRectypes]
+(
+ @ROTable char(8),
+ @RecID char(8),
+ @RecType int,
+ @ParentID char(8),
+ @AccPageID char(32),
+ @Info nvarchar(max),
+ @ModDateTime char(14)
+)
+WITH EXECUTE AS OWNER
+AS
+BEGIN TRY -- Try Block
+ BEGIN TRANSACTION
+ INSERT INTO [ROALL]
+ (
+ ROTable,
+ RecID,
+ RecType,
+ ParentID,
+ ModDateTime,
+ AccPageID,
+ Info
+ )
+ VALUES
+ (
+ @ROTable,
+ @RecID,
+ @RecType,
+ @ParentID,
+ @ModDateTime,
+ @AccPageID,
+ @Info
+ )
+
+ IF( @@TRANCOUNT > 0 ) COMMIT
+END TRY
+BEGIN CATCH -- Catch Block
+ IF( @@TRANCOUNT = 1 ) ROLLBACK -- Only rollback if top level
+ ELSE IF( @@TRANCOUNT > 1 ) COMMIT -- Otherwise commit. Top level will rollback
+ EXEC vlnErrorHandler
+END CATCH
+GO
+-- Display the status of Proc creation
+IF (@@Error = 0) PRINT 'Procedure Creation: insertAllRectypes Succeeded'
+ELSE PRINT 'Procedure Creation: insertAllRectypes Error on Creation'
+GO
+
+/****** Object: StoredProcedure [dbo].[updateInfoAccidByRecid] ******/
+IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[updateInfoAccidByRecid]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
+ DROP PROCEDURE [updateInfoAccidByRecid];
+GO
+/*****************************************************************************
+ Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE
+ Copyright 2019 - Volian Enterprises, Inc. All rights reserved.
+*****************************************************************************/
+CREATE PROCEDURE [dbo].[updateInfoAccidByRecid]
+(
+ @ROTable char(8),
+ @RecID char(8),
+ @AccPageID char(32),
+ @Info nvarchar(max),
+ @ModDateTime char(14)
+)
+WITH EXECUTE AS OWNER
+AS
+BEGIN TRY -- Try Block
+ BEGIN TRANSACTION
+ UPDATE [ROALL]
+ SET
+ [Info]=@Info,
+ [ModDateTime]=@ModDateTime,
+ [AccPageID]=@AccPageID
+ WHERE [ROTable]=@ROTable AND [RecID]=@RecID
+ IF @@ROWCOUNT = 0
+ BEGIN
+ IF NOT exists(select * from [ROALL] WHERE [ROTable]=@ROTable AND [RecID]=@RecID)
+ RAISERROR('ROALL record has been deleted by another user', 16, 1)
+ ELSE
+ RAISERROR('ROALL has been edited by another user', 16, 1)
+ END
+
+ IF( @@TRANCOUNT > 0 ) COMMIT
+END TRY
+BEGIN CATCH -- Catch Block
+ IF( @@TRANCOUNT = 1 ) ROLLBACK -- Only rollback if top level
+ ELSE IF( @@TRANCOUNT > 1 ) COMMIT -- Otherwise commit. Top level will rollback
+ EXEC vlnErrorHandler
+END CATCH
+GO
+-- Display the status of Proc creation
+IF (@@Error = 0) PRINT 'Procedure Creation: updateInfoAccidByRecid Succeeded'
+ELSE PRINT 'Procedure Creation: updateInfoAccidByRecid Error on Creation'
+GO
+
+/****** Object: StoredProcedure [dbo].[updateInfoByRecid] ******/
+IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[updateInfoByRecid]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
+ DROP PROCEDURE [updateInfoByRecid];
+GO
+/*****************************************************************************
+ Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE
+ Copyright 2019 - Volian Enterprises, Inc. All rights reserved.
+*****************************************************************************/
+CREATE PROCEDURE [dbo].[updateInfoByRecid]
+(
+ @ROTable char(8),
+ @RecID char(8),
+ @Info nvarchar(max),
+ @ModDateTime char(14)
+)
+WITH EXECUTE AS OWNER
+AS
+BEGIN TRY -- Try Block
+ BEGIN TRANSACTION
+ UPDATE [ROALL]
+ SET
+ [Info]=@Info,
+ [ModDateTime]=@ModDateTime
+ WHERE [ROTable]=@ROTable AND [RecID]=@RecID
+ IF @@ROWCOUNT = 0
+ BEGIN
+ IF NOT exists(select * from [ROALL] WHERE [ROTable]=@ROTable AND [RecID]=@RecID)
+ RAISERROR('ROALL record has been deleted by another user', 16, 1)
+ ELSE
+ RAISERROR('ROALL has been edited by another user', 16, 1)
+ END
+
+ IF( @@TRANCOUNT > 0 ) COMMIT
+END TRY
+BEGIN CATCH -- Catch Block
+ IF( @@TRANCOUNT = 1 ) ROLLBACK -- Only rollback if top level
+ ELSE IF( @@TRANCOUNT > 1 ) COMMIT -- Otherwise commit. Top level will rollback
+ EXEC vlnErrorHandler
+END CATCH
+GO
+-- Display the status of Proc creation
+IF (@@Error = 0) PRINT 'Procedure Creation: updateInfoByRecid Succeeded'
+ELSE PRINT 'Procedure Creation: updateInfoByRecid Error on Creation'
+GO
+
+/****** Object: StoredProcedure [dbo].[updateInfoByRecidRectype] ******/
+IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[updateInfoByRecidRectype]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
+ DROP PROCEDURE [updateInfoByRecidRectype];
+GO
+/*****************************************************************************
+ Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE
+ Copyright 2019 - Volian Enterprises, Inc. All rights reserved.
+*****************************************************************************/
+CREATE PROCEDURE [dbo].[updateInfoByRecidRectype]
+(
+ @ROTable char(8),
+ @RecID char(8),
+ @Info nvarchar(max),
+ @ModDateTime char(14),
+ @RecType int
+)
+WITH EXECUTE AS OWNER
+AS
+BEGIN TRY -- Try Block
+ BEGIN TRANSACTION
+ UPDATE [ROALL]
+ SET
+ [Info]=@Info,
+ [ModDateTime]=@ModDateTime
+ WHERE [ROTable]=@ROTable AND [RecID]=@RecID AND [RecType]=@RecType
+ IF @@ROWCOUNT = 0
+ BEGIN
+ IF NOT exists(select * from [ROALL] WHERE [ROTable]=@ROTable AND [RecID]=@RecID AND [RecType]=@RecType)
+ RAISERROR('ROALL record has been deleted by another user', 16, 1)
+ ELSE
+ RAISERROR('ROALL has been edited by another user', 16, 1)
+ END
+
+ IF( @@TRANCOUNT > 0 ) COMMIT
+END TRY
+BEGIN CATCH -- Catch Block
+ IF( @@TRANCOUNT = 1 ) ROLLBACK -- Only rollback if top level
+ ELSE IF( @@TRANCOUNT > 1 ) COMMIT -- Otherwise commit. Top level will rollback
+ EXEC vlnErrorHandler
+END CATCH
+GO
+-- Display the status of Proc creation
+IF (@@Error = 0) PRINT 'Procedure Creation: updateInfoByRecidRectype Succeeded'
+ELSE PRINT 'Procedure Creation: updateInfoByRecidRectype Error on Creation'
+GO
+
+/****** Object: Table [dbo].[ROALL] ******/
+IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[ROALL]') AND type in (N'U'))
+DROP TABLE [dbo].[ROALL]
+GO
+/*****************************************************************************
+ Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE
+ Copyright 2019 - Volian Enterprises, Inc. All rights reserved.
+*****************************************************************************/
+CREATE TABLE [dbo].[ROALL](
+ [ROTable] [char](8) NOT NULL,
+ [RecID] [char](8) NOT NULL,
+ [RecType] [int] NOT NULL,
+ [ParentID] [char](8) NOT NULL,
+ [AccPageID] [char](32) NULL,
+ [ModDateTime] [char](14) NOT NULL,
+ [Info] [nvarchar](max) NULL,
+ CONSTRAINT [PK_ROMASTER] PRIMARY KEY CLUSTERED
+(
+ [ROTable] ASC,
+ [RecID] ASC
+)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
+) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
+-- Display the status of Table creation
+IF (@@Error = 0) PRINT 'Table Creation: ROALL Succeeded'
+ELSE PRINT 'Table Creation: DeleteLog ROALL on Creation'
+GO
+
+
diff --git a/PROMS/VEPROMS User Interface/ROFixes.Sql b/PROMS/VEPROMS User Interface/ROFixes.Sql
new file mode 100644
index 00000000..c4410f02
--- /dev/null
+++ b/PROMS/VEPROMS User Interface/ROFixes.Sql
@@ -0,0 +1,58 @@
+ if db_name() in('master','model','msdn','tempdb')
+begin
+ DECLARE @ErrorMsg varchar(255)
+ SET @ErrorMsg = 'Don''t add these procedures and functions to ' + db_name()
+ PRINT '=========================================================================='
+ PRINT ''
+ PRINT @ErrorMsg
+ PRINT ''
+ PRINT 'You probably want to be in the VEPROMS Referenced Object (RO) database'
+ PRINT ''
+ PRINT '=========================================================================='
+ RAISERROR (@ErrorMsg, 20, -1) with log
+ RETURN
+end
+print 'Adding procedures and functions to ' + db_name()
+
+-----------------------------------------------------------------------------
+/*
+ ---------------------------------------------------------------------------
+ | ADD New Code Before this Block |
+ | Change Date and Description |
+ ---------------------------------------------------------------------------
+*/
+-----------------------------------------------------------------------------
+IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[vesp_GetSQLCodeRevision]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
+ DROP PROCEDURE [vesp_GetSQLCodeRevision];
+GO
+
+/*****************************************************************************
+ Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE
+ Copyright 2019 - Volian Enterprises, Inc. All rights reserved.
+*****************************************************************************/
+CREATE PROCEDURE [dbo].[vesp_GetSQLCodeRevision]
+WITH EXECUTE AS OWNER
+AS
+BEGIN TRY -- Try Block
+ BEGIN TRANSACTION
+ -- Change information in the next line when you are done
+ set nocount on
+ DECLARE @RevDate varchar(255)
+ DECLARE @RevDescription varchar(255)
+ set @RevDate = '01/09/2020 11:00 AM'
+ set @RevDescription = 'Initial Version'
+ Select cast(@RevDate as datetime) RevDate, @RevDescription RevDescription
+ PRINT 'SQL Code Revision ' + @RevDate + ' - ' + @RevDescription
+ IF( @@TRANCOUNT > 0 ) COMMIT
+END TRY
+BEGIN CATCH -- Catch Block
+ IF( @@TRANCOUNT = 1 ) ROLLBACK -- Only rollback if top level
+ ELSE IF( @@TRANCOUNT > 1 ) COMMIT -- Otherwise commit. Top level will rollback
+ EXEC vlnErrorHandler
+END CATCH
+GO
+-- Display the status of Proc creation
+IF (@@Error = 0) PRINT 'StoredProcedure [vesp_GetSQLCodeRevision] Succeeded'
+ELSE PRINT 'StoredProcedure [vesp_GetSQLCodeRevision] Error on Creation'
+go
+vesp_GetSQLCodeRevision
diff --git a/PROMS/VEPROMS User Interface/frmRODbProperties.Designer.cs b/PROMS/VEPROMS User Interface/frmRODbProperties.Designer.cs
index fbade8dc..177d0652 100644
--- a/PROMS/VEPROMS User Interface/frmRODbProperties.Designer.cs
+++ b/PROMS/VEPROMS User Interface/frmRODbProperties.Designer.cs
@@ -32,6 +32,9 @@ namespace VEPROMS
this.ppBtnOk = new System.Windows.Forms.Button();
this.ppBtnCancel = new System.Windows.Forms.Button();
this.ppPnlRODb = new DevComponents.DotNetBar.PanelEx();
+ this.ppBtnTestSQL = new System.Windows.Forms.Button();
+ this.ppTxtSQL = new System.Windows.Forms.TextBox();
+ this.ppLblSQL = new System.Windows.Forms.Label();
this.ppTxtExt = new System.Windows.Forms.TextBox();
this.ppTxtPath = new System.Windows.Forms.TextBox();
this.ppLblGraphicFileExtLoc = new System.Windows.Forms.Label();
@@ -71,6 +74,9 @@ namespace VEPROMS
//
this.ppPnlRODb.CanvasColor = System.Drawing.SystemColors.Control;
this.ppPnlRODb.ColorSchemeStyle = DevComponents.DotNetBar.eDotNetBarStyle.Office2007;
+ this.ppPnlRODb.Controls.Add(this.ppBtnTestSQL);
+ this.ppPnlRODb.Controls.Add(this.ppTxtSQL);
+ this.ppPnlRODb.Controls.Add(this.ppLblSQL);
this.ppPnlRODb.Controls.Add(this.ppTxtExt);
this.ppPnlRODb.Controls.Add(this.ppTxtPath);
this.ppPnlRODb.Controls.Add(this.ppLblGraphicFileExtLoc);
@@ -92,6 +98,33 @@ namespace VEPROMS
this.ppPnlRODb.Style.GradientAngle = 90;
this.ppPnlRODb.TabIndex = 3;
//
+ // ppBtnTestSQL
+ //
+ this.ppBtnTestSQL.Location = new System.Drawing.Point(542, 110);
+ this.ppBtnTestSQL.Name = "ppBtnTestSQL";
+ this.ppBtnTestSQL.Size = new System.Drawing.Size(82, 46);
+ this.ppBtnTestSQL.TabIndex = 44;
+ this.ppBtnTestSQL.Text = "Test Connect";
+ this.ppBtnTestSQL.UseVisualStyleBackColor = true;
+ this.ppBtnTestSQL.Click += new System.EventHandler(this.ppBtnTestSQL_Click);
+ //
+ // ppTxtSQL
+ //
+ this.ppTxtSQL.Location = new System.Drawing.Point(129, 156);
+ this.ppTxtSQL.Name = "ppTxtSQL";
+ this.ppTxtSQL.Size = new System.Drawing.Size(507, 22);
+ this.ppTxtSQL.TabIndex = 43;
+ this.ppTxtSQL.TextChanged += new System.EventHandler(this.ppTxtSQL_TextChanged);
+ //
+ // ppLblSQL
+ //
+ this.ppLblSQL.AutoSize = true;
+ this.ppLblSQL.Location = new System.Drawing.Point(30, 156);
+ this.ppLblSQL.Name = "ppLblSQL";
+ this.ppLblSQL.Size = new System.Drawing.Size(92, 17);
+ this.ppLblSQL.TabIndex = 42;
+ this.ppLblSQL.Text = "SQL Connect";
+ //
// ppTxtExt
//
this.ppTxtExt.Enabled = false;
@@ -203,5 +236,8 @@ namespace VEPROMS
private System.Windows.Forms.Label ppLblExt;
private System.Windows.Forms.TextBox ppTxtPath;
private System.Windows.Forms.TextBox ppTxtExt;
+ private System.Windows.Forms.Button ppBtnTestSQL;
+ private System.Windows.Forms.TextBox ppTxtSQL;
+ private System.Windows.Forms.Label ppLblSQL;
}
}
\ No newline at end of file
diff --git a/PROMS/VEPROMS User Interface/frmRODbProperties.cs b/PROMS/VEPROMS User Interface/frmRODbProperties.cs
index 77045d7e..aeae059e 100644
--- a/PROMS/VEPROMS User Interface/frmRODbProperties.cs
+++ b/PROMS/VEPROMS User Interface/frmRODbProperties.cs
@@ -2,6 +2,7 @@ using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
+using System.Data.SqlClient;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
@@ -58,6 +59,7 @@ namespace VEPROMS
private RODbInfo _roDbInfo;
private string _origROName;
private string _origFolderPath;
+ private string _origSQLConnect = null;
private DocVersion _docVersion;
public frmRODbProperties(DocVersion docVersion, RODbInfo roDbInfo)
{
@@ -66,6 +68,7 @@ namespace VEPROMS
InitializeComponent();
_origROName = (_roDbInfo == null) ? null : _roDbInfo.ROName;
_origFolderPath = (_roDbInfo == null) ? null : _roDbInfo.FolderPath;
+ _origSQLConnect = (_roDbInfo == null) ? null : (_roDbInfo.DBConnectionString == null || _roDbInfo.DBConnectionString == "" || _roDbInfo.DBConnectionString == "cstring") ? null : _roDbInfo.DBConnectionString;
// Disable the OK button when initialized. Enable it if the user makes changes
ppBtnOk.Enabled = false;
}
@@ -86,7 +89,8 @@ namespace VEPROMS
// check for modify. If the path to this rodb already exists, we've got to use that
// as the assocation. if it's a new path, i.e. a modify of the rodb record, just save current data.
// Then close & return.
- if (_origROName !=null && _origFolderPath !=null && (_origROName != ppRTxtName.Text || _origFolderPath != ppTxtPath.Text))
+ if ((_origROName !=null && _origFolderPath !=null && (_origROName != ppRTxtName.Text || _origFolderPath != ppTxtPath.Text)) ||
+ (_origSQLConnect != ppTxtSQL.Text || _origSQLConnect != ppTxtSQL.Text))
{
if (!Directory.Exists(ppTxtPath.Text))
{
@@ -100,6 +104,12 @@ namespace VEPROMS
}
RODb roDb = RODb.GetJustRoDb(_roDbInfo.RODbID);
if (_origROName != ppRTxtName.Text) roDb.ROName = ppRTxtName.Text;
+ if (!(_origSQLConnect == "cstring" && (ppTxtSQL.Text == null || ppTxtSQL.Text == "")) && _origSQLConnect != ppTxtSQL.Text)
+ {
+ // C2017-003: ro in sql. 'cstring' in connection string represents using MS Access database
+ // if connect string is null, set connect string to "cstring" otherwise, use what user typed in:
+ roDb.DBConnectionString = (ppTxtSQL.Text == null || ppTxtSQL.Text == "") ? "cstring" : ppTxtSQL.Text;
+ }
if (_origFolderPath != ppTxtPath.Text)
{
// see if an rodb already exists with this pathname.
@@ -184,7 +194,8 @@ namespace VEPROMS
MessageBox.Show("No existing ro.fst in path " + ppTxtPath.Text + ". Check for invalid path");
return;
}
- RODb newroDb = RODb.MakeRODb(ppRTxtName.Text, ppTxtPath.Text, "cstring", null);
+ string connectstr = ppTxtSQL.Text != null && ppTxtSQL.Text != "" ? ppTxtExt.Text : "cstring";
+ RODb newroDb = RODb.MakeRODb(ppRTxtName.Text, ppTxtPath.Text, connectstr, null);
RODbInfo newrdi = RODbInfo.Get(newroDb.RODbID);
newroDb.Save().Dispose();
ROFst rofst = ROFstInfo.AddRoFst(newrdi, _docVersion, DoProgressBarRefresh);
@@ -196,6 +207,7 @@ namespace VEPROMS
Location = ParentLocation;
ppRTxtName.Text = (_roDbInfo == null) ? null : _roDbInfo.ROName;
ppTxtPath.Text = (_roDbInfo == null) ? null : _roDbInfo.FolderPath;
+ ppTxtSQL.Text = (_roDbInfo == null) ? null : (_roDbInfo.DBConnectionString == "cstring") ? null : _roDbInfo.DBConnectionString;
RODbConfig cfg = (_roDbInfo == null) ? new RODbConfig() : new RODbConfig(_roDbInfo);
// Note that the Graphic Extension data is shown in a non-editable text box here because
// the data is either retrieved from the roapp.ini - and if there can only be editted from
@@ -235,5 +247,38 @@ namespace VEPROMS
//The OK button should only be enabled if the path has changed
ppBtnOk.Enabled = _origFolderPath != ppTxtPath.Text;
}
+ private void ppTxtSQL_TextChanged(object sender, EventArgs e)
+ {
+ //The OK button should only be enabled if the path has changed
+ ppBtnOk.Enabled = _origSQLConnect != ppTxtSQL.Text;
+ }
+ // C2017-003: test that the sql string entered can connect to the database:
+ private void ppBtnTestSQL_Click(object sender, EventArgs e)
+ {
+ try
+ {
+ using (SqlConnection connection = new SqlConnection(ppTxtSQL.Text))
+ {
+ try
+ {
+ connection.Open();
+ if (connection.State == ConnectionState.Open)
+ {
+ MessageBox.Show("You have been successfully connected to the database!");
+ }
+ else
+ {
+ MessageBox.Show("Connection failed.");
+ }
+ }
+ catch (SqlException) { }
+ }
+ }
+ catch (Exception ex)
+ {
+ MessageBox.Show("Connection failed: " + ex);
+ }
+
+ }
}
}
\ No newline at end of file
diff --git a/PROMS/VEPROMS User Interface/frmVersionsProperties.Designer.cs b/PROMS/VEPROMS User Interface/frmVersionsProperties.Designer.cs
index 12b71379..8c5820c3 100644
--- a/PROMS/VEPROMS User Interface/frmVersionsProperties.Designer.cs
+++ b/PROMS/VEPROMS User Interface/frmVersionsProperties.Designer.cs
@@ -98,6 +98,7 @@ namespace VEPROMS
this.tcpGeneral = new DevComponents.DotNetBar.TabControlPanel();
this.tiGeneral = new DevComponents.DotNetBar.TabItem(this.components);
this.tcpRefereceObjects = new DevComponents.DotNetBar.TabControlPanel();
+ this.ppBtnRoToSql = new System.Windows.Forms.Button();
this.tbRoDb = new System.Windows.Forms.TextBox();
this.ppBtnRoDbBrowse = new System.Windows.Forms.Button();
this.btnRoDbProperties = new DevComponents.DotNetBar.ButtonX();
@@ -1161,6 +1162,7 @@ namespace VEPROMS
//
// tcpRefereceObjects
//
+ this.tcpRefereceObjects.Controls.Add(this.ppBtnRoToSql);
this.tcpRefereceObjects.Controls.Add(this.tbRoDb);
this.tcpRefereceObjects.Controls.Add(this.ppBtnRoDbBrowse);
this.tcpRefereceObjects.Controls.Add(this.btnRoDbProperties);
@@ -1185,6 +1187,17 @@ namespace VEPROMS
this.tcpRefereceObjects.TabItem = this.tiRefObjs;
this.tcpRefereceObjects.Enter += new System.EventHandler(this.tabpage_Enter);
//
+ // ppBtnRoToSql
+ //
+ this.ppBtnRoToSql.Location = new System.Drawing.Point(337, 146);
+ this.ppBtnRoToSql.Name = "ppBtnRoToSql";
+ this.ppBtnRoToSql.Size = new System.Drawing.Size(163, 46);
+ this.ppBtnRoToSql.TabIndex = 48;
+ this.ppBtnRoToSql.Text = "Migrate Data to Sql";
+ this.ppBtnRoToSql.UseVisualStyleBackColor = true;
+ this.ppBtnRoToSql.Visible = false;
+ this.ppBtnRoToSql.Click += new System.EventHandler(this.ppBtnRoToSql_Click);
+ //
// tbRoDb
//
this.tbRoDb.Enabled = false;
@@ -2903,6 +2916,7 @@ namespace VEPROMS
private DevComponents.DotNetBar.Controls.ComboBoxEx ppCmbxMOSfontName;
private DevComponents.DotNetBar.ButtonX btnMergedOutputSettngs;
private DevComponents.DotNetBar.Controls.CheckBoxX ppChbxMOSview;
+ private System.Windows.Forms.Button ppBtnRoToSql;
private System.Windows.Forms.CheckBox ppChbxEnhancedAllowMods;
}
}
diff --git a/PROMS/VEPROMS User Interface/frmVersionsProperties.cs b/PROMS/VEPROMS User Interface/frmVersionsProperties.cs
index 5fe40aec..4f754f6b 100644
--- a/PROMS/VEPROMS User Interface/frmVersionsProperties.cs
+++ b/PROMS/VEPROMS User Interface/frmVersionsProperties.cs
@@ -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")]
diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/Database.cs b/PROMS/VEPROMS.CSLA.Library/Generated/Database.cs
index 732f20d8..7cc80a48 100644
--- a/PROMS/VEPROMS.CSLA.Library/Generated/Database.cs
+++ b/PROMS/VEPROMS.CSLA.Library/Generated/Database.cs
@@ -327,7 +327,7 @@ public static string DBServer
tsmi.Font = new System.Drawing.Font(tsmi.Font, System.Drawing.FontStyle.Bold);
foreach (DataRow dr in ds.Tables[0].Rows)
{
- if (dr["functionality"].ToString() == "Approval")
+ if (dr["functionality"].ToString() == "Approval" && !dr["name"].ToString().EndsWith("_RO")) // don't display sql ro databases in list
cms.Items.Add(dr["name"].ToString(), null, new EventHandler(Database_Click));
}
return cms;
diff --git a/PROMS/Volian.Controls.Library/DisplayRO.cs b/PROMS/Volian.Controls.Library/DisplayRO.cs
index 1c65ef62..cee48a70 100644
--- a/PROMS/Volian.Controls.Library/DisplayRO.cs
+++ b/PROMS/Volian.Controls.Library/DisplayRO.cs
@@ -882,6 +882,8 @@ namespace Volian.Controls.Library
ROFSTLookup.rochild roch = (ROFSTLookup.rochild)obj;
_SelectedRoidBeforeRoEditor = roch.roid;
string args = "\"" + _MyROFST.MyRODb.FolderPath + "\" " + roch.roid.ToLower();
+ // C2017-003: ro data in sql server, check for sql connection string
+ if (_MyROFST.MyRODb.DBConnectionString != "cstring") args = args + " \"" + _MyROFST.MyRODb.DBConnectionString + "\"";
System.Diagnostics.Process.Start(roapp, args);
}
}
@@ -922,6 +924,8 @@ namespace Volian.Controls.Library
FlexibleMessageBox.Show(string.Format("RO Database directory does not exist: {0}", _MyROFST.MyRODb.FolderPath));
return;
}
+ // C2017-003: ro data in sql server, check for sql connection string
+ if (_MyROFST.MyRODb.DBConnectionString != "cstring") args = args + " \"" + _MyROFST.MyRODb.DBConnectionString + "\"";
System.Diagnostics.Process.Start(roapp, args);
}
}
diff --git a/PROMS/Volian.Controls.Library/DisplayReports.cs b/PROMS/Volian.Controls.Library/DisplayReports.cs
index 378ec821..fae06977 100644
--- a/PROMS/Volian.Controls.Library/DisplayReports.cs
+++ b/PROMS/Volian.Controls.Library/DisplayReports.cs
@@ -936,9 +936,11 @@ namespace Volian.Controls.Library
sw.Close();
}
string roloc = "\"" + MyDVI.DocVersionAssociations[0].MyROFst.MyRODb.FolderPath + "\" \"/f=" + fname + "\"";
+ // C2017-003: ro data in sql server, check for sql connection string
+ if (MyDVI.DocVersionAssociations[0].MyROFst.MyRODb.DBConnectionString != "cstring") roloc = roloc + " \"/sql=" + MyDVI.DocVersionAssociations[0].MyROFst.MyRODb.DBConnectionString + "\"";
System.Diagnostics.Process p = System.Diagnostics.Process.Start(cmpRptExePath, roloc);
// need to wait, sometimes the Print.tmp file that is generated is not available
- p.WaitForExit(); // without arguments, this will wait indefinately
+ p.WaitForExit(); // without arguments, this will wait indefinitely
Application.DoEvents();
}
catch (Exception ex)
diff --git a/PROMS/Volian.Controls.Library/StepTabRibbon.cs b/PROMS/Volian.Controls.Library/StepTabRibbon.cs
index 3c85ac9c..a74dc7a1 100644
--- a/PROMS/Volian.Controls.Library/StepTabRibbon.cs
+++ b/PROMS/Volian.Controls.Library/StepTabRibbon.cs
@@ -2886,6 +2886,8 @@ namespace Volian.Controls.Library
FlexibleMessageBox.Show(string.Format("RO Database directory does not exist: {0}", myRODB.FolderPath));
return;
}
+ // C2017-003: ro data in sql server, check for sql connection string
+ if (myRODB.DBConnectionString != "cstring") args = args + " \"" + myRODB.DBConnectionString + "\"";
System.Diagnostics.Process.Start(roapp, args);
}
}
@@ -3031,6 +3033,8 @@ namespace Volian.Controls.Library
FlexibleMessageBox.Show(string.Format("RO Database directory does not exist: {0}", Mydvi.DocVersionAssociations[0].MyROFst.MyRODb.FolderPath));
return;
}
+ // C2017-003: ro data in sql server, check for sql connection string
+ if (Mydvi.DocVersionAssociations[0].MyROFst.MyRODb.DBConnectionString != "cstring") roloc = roloc + " \"" + Mydvi.DocVersionAssociations[0].MyROFst.MyRODb.DBConnectionString + "\"";
System.Diagnostics.Process.Start(roapp, roloc);
}
diff --git a/PROMS/Volian.Controls.Library/vlnTreeView.cs b/PROMS/Volian.Controls.Library/vlnTreeView.cs
index 711e6213..1e3c2e84 100644
--- a/PROMS/Volian.Controls.Library/vlnTreeView.cs
+++ b/PROMS/Volian.Controls.Library/vlnTreeView.cs
@@ -2045,6 +2045,8 @@ namespace Volian.Controls.Library
FlexibleMessageBox.Show(string.Format("RO Database directory does not exist: {0}", MyDVI.DocVersionAssociations[0].MyROFst.MyRODb.FolderPath));
return;
}
+ // C2017-003: ro data in sql server, check for sql connection string
+ if (MyDVI.DocVersionAssociations[0].MyROFst.MyRODb.DBConnectionString != "cstring") roloc = roloc + " \"" + MyDVI.DocVersionAssociations[0].MyROFst.MyRODb.DBConnectionString + "\"";
System.Diagnostics.Process.Start(roapp, roloc);
}