C2026-058 Check all Tables for if Acc Page Id Prefix is Used More than Once
This commit is contained in:
1 parent
ae9fb0eb67
commit
82f11fa696
10 files changed
+717
-133
No files matched your search
@@ -336,7 +336,8 @@ namespace RODBInterface
|
||||
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 IsDuplicateAccPagePrefix(VlnXmlElement ro, string pfix);
|
||||
public abstract VlnXmlElement RODB_ReadRO(string tbl, string recid);
|
||||
public abstract bool RODB_WriteRO(VlnXmlElement ro, bool movedRO = false);
|
||||
public abstract bool RODB_InsertRO(VlnXmlElement ro);
|
||||
public abstract ushort RODB_GetFieldType(VlnXmlElement elem, string TableName, string Fld);
|
||||
@@ -2026,23 +2027,23 @@ namespace RODBInterface
|
||||
return true;
|
||||
}
|
||||
|
||||
public override bool IsDuplicateAccPageID(VlnXmlElement ro, string newacc)
|
||||
{
|
||||
string strcheck, inacc = null;
|
||||
bool isdup = false;
|
||||
int indx = newacc.IndexOf("'");
|
||||
if (indx >= 0)
|
||||
inacc = newacc.Insert(indx, "'");
|
||||
else
|
||||
inacc = newacc;
|
||||
strcheck = "SELECT Count(RecID) AS CNT FROM " + ro.GetAttribute("Table") + " WHERE AccPageID = '" + inacc + "'";
|
||||
public override bool IsDuplicateAccPageID(VlnXmlElement ro, string newacc)
|
||||
{
|
||||
string strcheck, inacc = null;
|
||||
bool isdup = false;
|
||||
int indx = newacc.IndexOf("'");
|
||||
if (indx >= 0)
|
||||
inacc = newacc.Insert(indx, "'");
|
||||
else
|
||||
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") + "')";
|
||||
try
|
||||
{
|
||||
DBE.Command(strcheck);
|
||||
DBE.Reader();
|
||||
if (ro.HasAttribute("RecID")) // new ro's don't have recid defined yet before this test.
|
||||
strcheck = strcheck + " AND (NOT RecID = '" + ro.GetAttribute("RecID") + "')";
|
||||
try
|
||||
{
|
||||
DBE.Command(strcheck);
|
||||
DBE.Reader();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
@@ -2062,7 +2063,69 @@ namespace RODBInterface
|
||||
return isdup;
|
||||
}
|
||||
|
||||
public override VlnXmlElement RODB_ReadRO(string tbl, string recid)
|
||||
//C2026-058 Check all Tables for if Acc Page Id Prefix is Used More than Once
|
||||
public override bool IsDuplicateAccPagePrefix(VlnXmlElement ro, string pfix)
|
||||
{
|
||||
// Loop through and build sql
|
||||
StringBuilder strGetData = new StringBuilder();
|
||||
List<string> all_tables = RODB_GetAllTables();
|
||||
|
||||
if (all_tables.Count == 0) return false;
|
||||
|
||||
foreach (string table in all_tables)
|
||||
{
|
||||
//if not the first item, add a union all
|
||||
if (strGetData.Length > 0)
|
||||
{ strGetData.Append(" UNION ALL "); }
|
||||
|
||||
//All info's containing AccPageIDPrefix should be RecType 3 (Group)
|
||||
//Note if you use LIKE or ALIKE
|
||||
// WHERE Info ALIKE '%AccPageIDPrefix%'"
|
||||
// WHERE Info LIKE '*AccPageIDPrefix*'
|
||||
//Then it truncates Info only pulling back the 1st 255 characters
|
||||
strGetData.Append($"SELECT Info, '{table}' AS TBL FROM {table} WHERE RecType = 3");
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
DBE.Command(strGetData.ToString());
|
||||
DBE.Reader();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
MessageBox.Show(e.Message, "Error getting Acc Page ID Prefix Data");
|
||||
return true;
|
||||
}
|
||||
|
||||
while (DBE.Read())
|
||||
{
|
||||
string Info = DBE.GetString(0);
|
||||
string tbl = DBE.GetString(1);
|
||||
|
||||
using (XmlTextReader rdr = new XmlTextReader(Info, XmlNodeType.Element, null))
|
||||
{
|
||||
VlnXmlElement retele = null;
|
||||
try
|
||||
{
|
||||
XmlNode nd = ROXml.ReadNode(rdr);
|
||||
retele = (VlnXmlElement)nd;
|
||||
}
|
||||
catch
|
||||
{
|
||||
//do nothing not a valid item to check
|
||||
}
|
||||
|
||||
if (retele != null && tbl != ro.GetAttribute("Table") && retele.GetAttribute("AccPageIDPrefix").ToLower() == pfix.ToLower())
|
||||
{
|
||||
return true; //another table contains the prefix - return true
|
||||
}
|
||||
}
|
||||
}
|
||||
DBE.CommandDispose();
|
||||
DBE.ReaderClose();
|
||||
return false;
|
||||
}
|
||||
public override VlnXmlElement RODB_ReadRO(string tbl, string recid)
|
||||
{
|
||||
ShowCount.ReadRo++;
|
||||
VlnXmlElement retele = null;
|
||||
@@ -3104,6 +3167,33 @@ namespace RODBInterface
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//C2026-058 Check all Tables for if Acc Page Id Prefix is Used More than Once
|
||||
//Get all Tables in the MS Access DB
|
||||
public List<string> RODB_GetAllTables()
|
||||
{
|
||||
List<string> tables = new List<string>();
|
||||
|
||||
using (System.Data.OleDb.OleDbConnection connection = new System.Data.OleDb.OleDbConnection(strDatabaseConnectionCommand))
|
||||
{
|
||||
connection.Open();
|
||||
using (System.Data.OleDb.OleDbCommand command = connection.CreateCommand())
|
||||
{
|
||||
using (DataTable schema = connection.GetSchema("Tables"))
|
||||
{
|
||||
foreach (DataRow row in schema.Rows)
|
||||
{
|
||||
if (row["TABLE_TYPE"].ToString() == "TABLE")
|
||||
{
|
||||
tables.Add(row["TABLE_NAME"].ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return tables;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1357,13 +1357,13 @@ namespace RODBInterface
|
||||
{
|
||||
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"));
|
||||
command.Parameters.AddWithValue("@ROTable", ro.GetAttribute("Table"));
|
||||
|
||||
using (SqlDataReader reader = command.ExecuteReader())
|
||||
using (SqlDataReader reader = command.ExecuteReader())
|
||||
{
|
||||
if (reader.Read())
|
||||
{
|
||||
@@ -1383,7 +1383,38 @@ namespace RODBInterface
|
||||
}
|
||||
return isdup;
|
||||
}
|
||||
public override VlnXmlElement RODB_ReadRO(string tbl, string recid)
|
||||
public override bool IsDuplicateAccPagePrefix(VlnXmlElement ro, string pfix)
|
||||
{
|
||||
try
|
||||
{
|
||||
using (SqlConnection cn = ROAPP_SqlConnection)
|
||||
{
|
||||
SqlCommand command = new SqlCommand();
|
||||
command.Connection = cn;
|
||||
command.CommandType = CommandType.StoredProcedure;
|
||||
command.CommandText = "checkAccPagePrefixUsed";
|
||||
command.Parameters.AddWithValue("@Prefix", pfix);
|
||||
command.Parameters.AddWithValue("@ROTable", ro.GetAttribute("Table"));
|
||||
|
||||
using (SqlDataReader reader = command.ExecuteReader())
|
||||
{
|
||||
if (reader.Read())
|
||||
{
|
||||
int cnt = reader.GetInt32(0);
|
||||
if (cnt > 0)
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message, "Error on IsDuplicateAccPagePrefix");
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public override VlnXmlElement RODB_ReadRO(string tbl, string recid)
|
||||
{
|
||||
ShowCount.ReadRo++;
|
||||
VlnXmlElement retele = null;
|
||||
|
||||
Reference in new issue
Block a user