Commit for development environment setup

This commit is contained in:
2023-06-19 16:12:33 -04:00
parent be72063a3c
commit bbce2ad0a6
2209 changed files with 1171775 additions and 625 deletions

View File

@@ -0,0 +1,55 @@
using System.Reflection;
using System.Runtime.CompilerServices;
//
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
//
[assembly: AssemblyTitle("")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("")]
[assembly: AssemblyCopyright("")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
//
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Revision and Build Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion("1.1.*")]
//
// In order to sign your assembly you must specify a key to use. Refer to the
// Microsoft .NET Framework documentation for more information on assembly signing.
//
// Use the attributes below to control which key is used for signing.
//
// Notes:
// (*) If no key is specified, the assembly is not signed.
// (*) KeyName refers to a key that has been installed in the Crypto Service
// Provider (CSP) on your machine. KeyFile refers to a file which contains
// a key.
// (*) If the KeyFile and the KeyName values are both specified, the
// following processing occurs:
// (1) If the KeyName can be found in the CSP, that key is used.
// (2) If the KeyName does not exist and the KeyFile does exist, the key
// in the KeyFile is installed into the CSP and used.
// (*) In order to create a KeyFile, you can use the sn.exe (Strong Name) utility.
// When specifying the KeyFile, the location of the KeyFile should be
// relative to the project output directory which is
// %Project Directory%\obj\<configuration>. For example, if your KeyFile is
// located in the project directory, you would specify the AssemblyKeyFile
// attribute as [assembly: AssemblyKeyFile("..\\..\\mykey.snk")]
// (*) Delay Signing is an advanced option - see the Microsoft .NET Framework
// documentation for more information on this.
//

View File

@@ -0,0 +1,58 @@
using System.Reflection;
using System.Runtime.CompilerServices;
//
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
//
[assembly: AssemblyTitle("")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("")]
[assembly: AssemblyCopyright("")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
//
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Revision and Build Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion("1.1.*")]
//
// In order to sign your assembly you must specify a key to use. Refer to the
// Microsoft .NET Framework documentation for more information on assembly signing.
//
// Use the attributes below to control which key is used for signing.
//
// Notes:
// (*) If no key is specified, the assembly is not signed.
// (*) KeyName refers to a key that has been installed in the Crypto Service
// Provider (CSP) on your machine. KeyFile refers to a file which contains
// a key.
// (*) If the KeyFile and the KeyName values are both specified, the
// following processing occurs:
// (1) If the KeyName can be found in the CSP, that key is used.
// (2) If the KeyName does not exist and the KeyFile does exist, the key
// in the KeyFile is installed into the CSP and used.
// (*) In order to create a KeyFile, you can use the sn.exe (Strong Name) utility.
// When specifying the KeyFile, the location of the KeyFile should be
// relative to the project output directory which is
// %Project Directory%\obj\<configuration>. For example, if your KeyFile is
// located in the project directory, you would specify the AssemblyKeyFile
// attribute as [assembly: AssemblyKeyFile("..\\..\\mykey.snk")]
// (*) Delay Signing is an advanced option - see the Microsoft .NET Framework
// documentation for more information on this.
//
[assembly: AssemblyDelaySign(false)]
[assembly: AssemblyKeyFile("E:\\proms.net\\Public Key\\vlnkey.snk")]
[assembly: AssemblyKeyName("")]

View File

@@ -0,0 +1,249 @@
/*********************************************************************************************
* Copyright 2003 - Volian Enterprises, Inc. All rights reserved.
* Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE
* ------------------------------------------------------------------------------
* $Workfile: EopToErgRelations.cs $ $Revision: 1 $
* $Author: Jsj $ $Date: 11/12/04 10:33a $
*
* $History: EopToErgRelations.cs $
*
* ***************** Version 1 *****************
* User: Jsj Date: 11/12/04 Time: 10:33a
* Created in $/LibSource/VDB
* Class to support translation table maintenance.
*********************************************************************************************/
using System;
using System.IO;
using System.Collections;
using VDB;
namespace VDB_Set
{
/// <summary>
/// Support for the maintenance of the EOP ot ERG translation table
/// (TRANSL.TBL) which holds the relationships between the EOPs and ERGs
/// </summary>
public class EopToErgRelations
{
static string RelationshipFile = "TRANSL.TBL";
private ArrayList _aryTransTable = null;
public ArrayList aryTransTable
{
get
{
return _aryTransTable;
}
set
{
_aryTransTable = value;
}
}
public EopToErgRelations()
{
_aryTransTable = new ArrayList();
ReadTranslationTableFile();
}
private void ReadTranslationTableFile()
{
string inbuf;
TransFileRecord TranTblRec;
if (!File.Exists(RelationshipFile))
return; // file not there to read
StreamReader sr = new StreamReader(RelationshipFile);
while ((inbuf = sr.ReadLine()) != null)
{
TranTblRec = new TransFileRecord(inbuf);
_aryTransTable.Add(TranTblRec);
}
sr.Close();
}
public void WriteTranslationTableFile()
{
StreamWriter sw = new StreamWriter(RelationshipFile,false);
foreach (TransFileRecord tfr in _aryTransTable)
{
sw.Write(tfr.StringForFile());
}
sw.Close();
}
// Add to the end of the passed in list either info from the read-in
// translation file (TRANSL.TBL) or a new (empty) record.
public void AddToTranslationList(SetRecordObj SetRecObj, ArrayList NewList)
{
bool found = false;
for (int i = 0; !found && i < _aryTransTable.Count; i++)
{
TransFileRecord tfr = (TransFileRecord)_aryTransTable[i];
string tfrUpper = tfr.EOPFile.ToUpper();
string NewUpper = SetRecObj.DatabaseTable.ToUpper();
if (tfrUpper.Equals(NewUpper))
{
NewList.Add(tfr);
found=true;
}
}
if (!found)
{
TransFileRecord newrec = new TransFileRecord();
newrec.EOPFile = SetRecObj.DatabaseTable;
NewList.Add(newrec);
}
}
// Assign the ERG information (passed in as RecObj) to the currently
// slected EOP
public bool ChangeTranslationListItem(int EOPidx, object RecObj)
{
bool changedFlag = false;
SetRecordObj SetRecObj = (SetRecordObj)RecObj;
TransFileRecord tfr = (TransFileRecord)_aryTransTable[EOPidx];
if (tfr.ERGFile == null ||
!tfr.ERGFile.Equals(SetRecObj.DatabaseTable) ||
!tfr.ERGProcNum.Equals(SetRecObj.ProcNumber))
{
changedFlag = true;
tfr.ERGFile = SetRecObj.DatabaseTable;
tfr.ERGProcNum = SetRecObj.ProcNumber;
_aryTransTable[EOPidx] = tfr;
}
return changedFlag;
}
// For a given procecure number, find the position in the translation
// table list.
public int FindEOPInList(String EopFileName)
{
bool found = false;
int rtval = -1;
int cnt = _aryTransTable.Count;
TransFileRecord tfr;
string uEopFileName = EopFileName.ToUpper();
for (int i = 0; !found && i < cnt; i++)
{
tfr = (TransFileRecord)_aryTransTable[i];
string uListEopName = tfr.EOPFile.ToString().ToUpper();
if (uListEopName.Equals(uEopFileName))
{
rtval = i;
found = true;
}
}
return rtval;
}
// For a given position in the Translation table, get the corresponding
// position in the ERGList array
public int FindInERGList(int idx, ArrayList ERGList)
{
int rtval = 0;
bool found = false;
TransFileRecord tfr = (TransFileRecord)_aryTransTable[idx];
if (tfr.ERGFile == null)
return 0; // return not selected
string uERGFileName = tfr.ERGFile.ToUpper();
SetRecordObj SetRec;
string uErgListFName;
int cnt = ERGList.Count;
for (int i=0; !found && i < cnt; i++)
{
SetRec = (SetRecordObj)ERGList[i];
uErgListFName = SetRec.DatabaseTable.ToUpper();
if (uErgListFName.Equals(uERGFileName))
{
rtval = i;
found = true;
}
}
return rtval;
}
}
// This class is used to hold the information of a record in the
// Translation table (TRANSL.TBL)
class TransFileRecord
{
private string _EOPFile;
private string _ERGFile;
private string _ERGProcNum;
public string EOPFile
{
get
{
return _EOPFile;
}
set
{
_EOPFile = value;
}
}
public string ERGFile
{
get
{
return _ERGFile;
}
set
{
_ERGFile = value;
}
}
public string ERGProcNum
{
get
{
return _ERGProcNum;
}
set
{
_ERGProcNum = value;
}
}
public TransFileRecord()
{
_EOPFile = null;
_ERGFile = null;
_ERGProcNum = null;
}
// "inbuf" is a line read from the TRANSL.TBL file.
// parse out the the EOP's database file name, the ERG's
// database file name, and the ERG's procedure number
public TransFileRecord(string inbuf)
{
int stidx, len;
stidx = 0;
len = inbuf.IndexOf(",");
_EOPFile = inbuf.Substring(stidx,len);
stidx = len+1;
len = inbuf.IndexOf(",",stidx) - stidx;
_ERGFile = inbuf.Substring(stidx,len);
stidx = stidx + len +1;
_ERGProcNum = inbuf.Substring(stidx);
}
// Create a string of the EOP database name, ERG database name, and
// ERG procedure number for saving in the TRANSL.TBL file
public string StringForFile()
{
string outbuf;
outbuf = _EOPFile + "," + _ERGFile + "," + _ERGProcNum + "\n";
return outbuf;
}
}
}

View File

@@ -0,0 +1,193 @@
/*********************************************************************************************
* Copyright 2004 - Volian Enterprises, Inc. All rights reserved.
* Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE
* ------------------------------------------------------------------------------
* $Workfile: ProcedureSelectionList.cs $ $Revision: 1 $
* $Author: Kathy $ $Date: 7/27/04 8:39a $
*
* $History: ProcedureSelectionList.cs $
*
* ***************** Version 1 *****************
* User: Kathy Date: 7/27/04 Time: 8:39a
* Created in $/LibSource/VDB
*********************************************************************************************/
using System;
using System.Data;
using System.Drawing;
using System.Collections;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Windows.Forms;
using System.Text;
using VDB;
namespace VDB_Set
{
/// <summary>
/// Summary description for ProcedureSelectionList.
/// </summary>
public class ProcedureSelectionList : System.Windows.Forms.Form
{
private System.Windows.Forms.CheckedListBox checkedListBox1;
private System.Windows.Forms.Button btnOK;
private System.Windows.Forms.Button btnCancel;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
public ProcedureSelectionList()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
// Changes the selection mode from double-click to single click.
checkedListBox1.CheckOnClick = true;
}
public void Add(DataRow rw)
{
SetRecordObj SetRec = new SetRecordObj(rw);
checkedListBox1.Items.Add(SetRec);
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.checkedListBox1 = new System.Windows.Forms.CheckedListBox();
this.btnOK = new System.Windows.Forms.Button();
this.btnCancel = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// checkedListBox1
//
this.checkedListBox1.Location = new System.Drawing.Point(16, 8);
this.checkedListBox1.Name = "checkedListBox1";
this.checkedListBox1.Size = new System.Drawing.Size(528, 274);
this.checkedListBox1.TabIndex = 0;
//
// btnOK
//
this.btnOK.Location = new System.Drawing.Point(136, 296);
this.btnOK.Name = "btnOK";
this.btnOK.Size = new System.Drawing.Size(80, 32);
this.btnOK.TabIndex = 1;
this.btnOK.Text = "OK";
this.btnOK.Click += new System.EventHandler(this.btnOK_Click);
//
// btnCancel
//
this.btnCancel.Location = new System.Drawing.Point(272, 296);
this.btnCancel.Name = "btnCancel";
this.btnCancel.Size = new System.Drawing.Size(96, 32);
this.btnCancel.TabIndex = 2;
this.btnCancel.Text = "Cancel";
this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click);
//
// ProcedureSelectionList
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(560, 342);
this.Controls.Add(this.btnCancel);
this.Controls.Add(this.btnOK);
this.Controls.Add(this.checkedListBox1);
this.Name = "ProcedureSelectionList";
this.Text = "Select Procedures";
this.Load += new System.EventHandler(this.ProcedureSelectionList_Load);
this.ResumeLayout(false);
}
#endregion
private void ProcedureSelectionList_Load(object sender, System.EventArgs e)
{
}
public StringCollection GetListOfSelectedProcs_Files()
{
StringCollection RtnStrings = new StringCollection();
for (int i=0; i< checkedListBox1.CheckedItems.Count; i++)
{
SetRecordObj tmpObj = (SetRecordObj)checkedListBox1.CheckedItems[i];
RtnStrings.Add(tmpObj.DatabaseTable);
}
return RtnStrings;
}
private void btnOK_Click(object sender, System.EventArgs e)
{
DialogResult=DialogResult.OK;
this.Close();
}
private void btnCancel_Click(object sender, System.EventArgs e)
{
DialogResult=DialogResult.Cancel;
this.Close();
}
}
public class SetRecordObj
{
public string ProcTitle;
public string ProcNumber;
public string RECID;
public string DatabaseTable;
public string Format;
public string ApprvDate;
public string ApprvTime;
public string Initials;
public DataRow ProcSetRow;
public SetRecordObj(DataRow Rw)
{
ProcSetRow = Rw;
ProcTitle = ProcSetRow.ItemArray[0].ToString();
ProcNumber = ProcSetRow.ItemArray[1].ToString();
Format = ProcSetRow.ItemArray[2].ToString();
DatabaseTable = ProcSetRow.ItemArray[4].ToString();
RECID = ProcSetRow.ItemArray[5].ToString();
ApprvDate = ProcSetRow.ItemArray[7].ToString();
ApprvTime = ProcSetRow.ItemArray[8].ToString();
Initials = ProcSetRow.ItemArray[9].ToString();
}
public override string ToString()
{
StringBuilder rtnStr = new StringBuilder();
rtnStr.Append(ProcNumber);
rtnStr.Append(" ");
rtnStr.Append(ProcTitle);
return rtnStr.ToString();
}
}
}

View File

@@ -0,0 +1,157 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 1.3
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">1.3</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1">this is my long string</data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
[base64 mime encoded serialized .NET Framework object]
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
[base64 mime encoded string representing a byte array form of the .NET Framework object]
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used forserialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>1.3</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="checkedListBox1.DefaultModifiers" type="System.CodeDom.MemberAttributes, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>Private</value>
</data>
<data name="checkedListBox1.Locked" type="System.Boolean, mscorlib, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>False</value>
</data>
<data name="checkedListBox1.Modifiers" type="System.CodeDom.MemberAttributes, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>Private</value>
</data>
<data name="btnOK.Locked" type="System.Boolean, mscorlib, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>False</value>
</data>
<data name="btnOK.DefaultModifiers" type="System.CodeDom.MemberAttributes, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>Private</value>
</data>
<data name="btnOK.Modifiers" type="System.CodeDom.MemberAttributes, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>Private</value>
</data>
<data name="btnCancel.Locked" type="System.Boolean, mscorlib, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>False</value>
</data>
<data name="btnCancel.DefaultModifiers" type="System.CodeDom.MemberAttributes, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>Private</value>
</data>
<data name="btnCancel.Modifiers" type="System.CodeDom.MemberAttributes, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>Private</value>
</data>
<data name="$this.Locked" type="System.Boolean, mscorlib, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>False</value>
</data>
<data name="$this.Language" type="System.Globalization.CultureInfo, mscorlib, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>(Default)</value>
</data>
<data name="$this.TrayLargeIcon" type="System.Boolean, mscorlib, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>False</value>
</data>
<data name="$this.Localizable" type="System.Boolean, mscorlib, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>False</value>
</data>
<data name="$this.GridSize" type="System.Drawing.Size, System.Drawing, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>8, 8</value>
</data>
<data name="$this.Name">
<value>ProcedureSelectionList</value>
</data>
<data name="$this.DrawGrid" type="System.Boolean, mscorlib, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</data>
<data name="$this.TrayHeight" type="System.Int32, mscorlib, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>80</value>
</data>
<data name="$this.SnapToGrid" type="System.Boolean, mscorlib, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</data>
<data name="$this.DefaultModifiers" type="System.CodeDom.MemberAttributes, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>Private</value>
</data>
</root>

View File

@@ -0,0 +1,868 @@
/*********************************************************************************************
* Copyright 2004 - Volian Enterprises, Inc. All rights reserved.
* Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE
* ------------------------------------------------------------------------------
* $Workfile: VDB.cs $ $Revision: 9 $
* $Author: Kathy $ $Date: 8/16/05 2:53p $
*
* $History: VDB.cs $
*
* ***************** Version 9 *****************
* User: Kathy Date: 8/16/05 Time: 2:53p
* Updated in $/LibSource/VDB
* B2005-030: error if missing ndx
*
* ***************** Version 8 *****************
* User: Kathy Date: 5/19/05 Time: 11:05a
* Updated in $/LibSource/VDB
* speed up approve
*
* ***************** Version 7 *****************
* User: Jsj Date: 5/17/05 Time: 11:54a
* Updated in $/LibSource/VDB
* cleanup
*
* ***************** Version 6 *****************
* User: Kathy Date: 5/11/05 Time: 9:28a
* Updated in $/LibSource/VDB
* add selectinto method
*
* ***************** Version 5 *****************
* User: Kathy Date: 4/21/05 Time: 10:18a
* Updated in $/LibSource/VDB
* if dbt is < 512, make it 512
*
* ***************** Version 4 *****************
* User: Kathy Date: 3/08/05 Time: 1:47p
* Updated in $/LibSource/VDB
* Approval
*
* ***************** Version 3 *****************
* User: Jsj Date: 8/20/04 Time: 4:44p
* Updated in $/LibSource/VDB
* backed out previous change
*
* ***************** Version 2 *****************
* User: Jsj Date: 8/20/04 Time: 1:14p
* Updated in $/LibSource/VDB
* Added logic to handle a single quote in a string that is in an SQL
* statement.
*
* ***************** Version 1 *****************
* User: Kathy Date: 7/27/04 Time: 8:40a
* Created in $/LibSource/VDB
*********************************************************************************************/
using System;
using System.Data;
using System.Data.OleDb;
using System.Collections.Specialized;
using System.IO;
using System.Windows.Forms;
using System.Text;
using VDB_ConnType;
namespace VDB
{
/// <summary>
/// This the base class for a VE-PROMS database (table)
/// The vdbDBConnType class allows us to setup a default database type (ex dBase)
/// and gives us a cential place to add logic that would allow the end user select
/// the type of database (engine) to use via a configuration file (for example).
/// The virtual functions requires the class, that inherits this base class,
/// to define the SQL statements needed for its database operations.
/// </summary>
public abstract class VDB_Base
{
private vdb_DBConnType databaseType;
// made this public so that abstract functions that define SQL statements
// can check the type of database (if needed).
public int databaseTypeValue;
private OleDbConnection dbConn;
private string strDBPath = ""; //database directory path
private string strDBFile = ""; // database file name with extension
private string strDBTable = ""; // database file name without extension
private string strSelectCommand;
private string[] DBExtensions={"DBF","DBT"};
public VDB_Base(string strPath)
{
ParsePathAndFile(strPath);
databaseType = new vdb_DBConnType(); // currently defaults to dBase
databaseTypeValue = databaseType.dbType;
// check if dbt is at least 512, if not append 508 bytes. This is to fix
// a problem where dbts were created with only 4 bytes in the 16-bit code.
if ( isdBaseFile() && File.Exists(strDBTable+".dbt") )
{
FileInfo fi = new FileInfo(strDBTable + ".dbt");
if (fi.Length<512)
{
FileStream fs = new FileStream(strDBTable+".dbt",FileMode.Open,FileAccess.Write,FileShare.ReadWrite);
BinaryWriter bw = new BinaryWriter(fs);
bw.Seek(0,SeekOrigin.End);
byte []wrBytes = new byte[512-fi.Length];
for (int i=0; i<512-fi.Length; i++) wrBytes[i]=0;
wrBytes[4]=0x02;
bw.Write(wrBytes);
bw.Close();
}
fi = null;
}
dbConn = new OleDbConnection(databaseType.ConnectionString(strDBPath,""));
// if needed, create an INF file with index file names listed or if
// index file(s) don't exist, create them (B2005-030)
if ( isdBaseFile() && File.Exists(strDBFile))
CheckIndxAndINF();
}
private void ParsePathAndFile(string strInPath)
{
// do we have a file name with the path?
if (File.Exists(strInPath))
{
// Get the Path
int lastSlash = strInPath.LastIndexOf("\\");
if (lastSlash > 0)
{
strDBPath = strInPath.Substring(0,lastSlash);
lastSlash++; // move past slash
}
else // current directory path
{
strDBPath = ".\\";
lastSlash=0;
}
// Get the file (with extension)
strDBFile = strInPath.Substring(lastSlash);
//Get the file (without extension)
strDBTable = strDBFile;
int lastDot = strDBFile.LastIndexOf(".");
if (lastDot >0 ) // trim off the extension
strDBTable = strDBFile.Substring(0,lastDot);
}
else // no file name, just a path to database directory
{
strDBPath = strInPath;
if (strDBPath.Length == 0) // empty string for path
strDBPath = ".\\"; // current directory path
strDBFile = "";
strDBTable = "";
}
}
public string DBPath //database directory path
{
get
{
return strDBPath;
}
set
{
strDBPath = value.ToString();
}
}
public string DBFile // database file name with extension
{
get
{
return strDBFile;
}
// I don't think was want to set the file name
// set
// {
// strDBFile = value.ToString();
// }
}
public string DBTable // also dBase file name without extension
{
get
{
return strDBTable;
}
set
{
string tmp = value.ToString();
// If a path was passed in inore it. The connection already
// has a path associated with it and we don't want to get it angry.
int j = tmp.LastIndexOf("\\");
if ((j>0) && tmp[j] == '\\')
tmp = tmp.Substring(j+1);
tmp = tmp.ToUpper();
// if there is a file extension, chop it off but save it to assign
// to the strDBFile property
j = tmp.LastIndexOf(".");
if ((j>0) && tmp[j] == '.') // got an extension
{
strDBFile = tmp;
strDBTable = tmp.Substring(0,j);
}
else // no extension, assign the table name
{
strDBTable = tmp;
// if we're connected to dBase, then Tables are Files,
// So create a strDBFile by added .DBF to the table name
if (isdBaseFile())
strDBFile = tmp + ".DBF";
}
// We assigned the strDBTable (DBTable property) with a table name.
// Now we need to make sure there is a corresponding INF file
// for dBase index file information.
CreateINF();
}
}
/***
// To have single quote in a sql command string, you need to
// represent it as '' (two single quotes)
private string FixSingleQuotes(string sqlcmd)
{
string tmpstr1 = "(,= ";
string tmpstr2 = "), ";
string rtnstr = "";
int idx = 0;
int st = 0;
bool twoquotes;
int len = sqlcmd.Length;
while ((idx = sqlcmd.IndexOf("'",st)) >= 0)
{
twoquotes = true;
// is there a "(", comma , "=", or a space before the quote?
// if so then we do not want to add another quote
// because it part of the sql command, not the string
if (idx > 0 && (tmpstr1.IndexOf(sqlcmd[idx-1]) >= 0))
twoquotes = false;
// is there a ")", comma, or a space after the quote?
// if so then we do not want to add another quote
// because it part of the sql command, not the string
if (twoquotes)
if (idx > 0 && (idx == len) || (tmpstr2.IndexOf(sqlcmd[idx+1]) >= 0))
twoquotes = false;
// If there is already a second quote, then increment idx past
// it and set twoqotes to false.
if (twoquotes)
{
if (sqlcmd[idx+1] == '\'')
{
idx++; // second quote already there
twoquotes = false;
}
}
rtnstr += sqlcmd.Substring(st,(idx-st)+1);
if (twoquotes)
{
rtnstr += "'"; // add a second quote
}
twoquotes = false;
idx++;
st = idx;
}
rtnstr += sqlcmd.Substring(st);
return rtnstr;
}
***/
// Process a list of SQL commands. If an error occures, return 1
private int ProcessSQLCommands (OleDbCommand cmdSQL,StringCollection strColl)
{
int errs =0;
foreach (string sqlcmd in strColl)
{
try
{
/***
string fixedSqlCmd = FixSingleQuotes(sqlcmd);
cmdSQL.CommandText = fixedSqlCmd; //sqlcmd;
***/
cmdSQL.CommandText = sqlcmd;
cmdSQL.ExecuteNonQuery();
}
catch (Exception err)
{
errs = 1;
MessageBox.Show(err.Message.ToString(),"ProcessSQLCommands Error");
}
}
return errs;
}
//memo strings of greater than 255 where getting truncated and needed a separate
// reader.
public string GetMemo(string RecId)
{
string retstr=null;
OleDbCommand cmd=null;
OleDbDataReader dr = null;
StringBuilder tmp = new StringBuilder();
tmp.Append("SELECT [TEXTM] FROM [");
tmp.Append(DBTable);
tmp.Append("] WHERE RECID = '");
tmp.Append(RecId);
tmp.Append("'");
try
{
dbConn.Open();
cmd = new OleDbCommand(tmp.ToString(),dbConn);
dr = cmd.ExecuteReader();
if (dr.Read())retstr = dr.GetString(0);
}
catch (Exception e)
{
MessageBox.Show(e.Message,"VDB Error");
retstr = null;
}
if (dr !=null) dr.Close();
if (cmd != null) cmd.Dispose();
dbConn.Close();
return retstr;
}
// The default SQL statement will get all of the records in a database
// This should be suitable for all of our database, but just in case
// it can be overloaded.
public virtual string DefaultSelectCommand()
{
StringBuilder tmp = new StringBuilder();
tmp.Append("SELECT * FROM [");
tmp.Append(strDBTable);
tmp.Append("]");
return tmp.ToString();
}
// return and set the SELECT statement used to get a DataSet (DB_Data)
public string SelectCmd
{
get
{
return strSelectCommand;
}
set
{
strSelectCommand = value.ToString();
}
}
public System.Data.DataSet DB_Data
{
// return a DataSet containing the database (table) records
get
{
dbConn.Open();
// if a select command was not created, then use the default
// select all command
if (strSelectCommand == null || strSelectCommand.Equals(""))
strSelectCommand = DefaultSelectCommand();
OleDbDataAdapter da =new OleDbDataAdapter(strSelectCommand,dbConn);
DataSet ds = new DataSet();
try
{
da.Fill(ds);
}
catch (Exception err)
{
MessageBox.Show(err.Message.ToString(),"VDB Error");
ds = null; // return null if error getting dataset
}
dbConn.Close();
return ds;
}
// update the database (table) with the changes made to the DataSet
set
{
// pass in a dataset, update the changed/added/deleted records
int err = 0;
StringCollection CommandList = new StringCollection();
// Open a database connection
dbConn.Open();
// Setup for a series of database transactions
System.Data.OleDb.OleDbCommand cmdSQL = new OleDbCommand();
System.Data.OleDb.OleDbTransaction dbTransAct;
// dbTransAct = dbConn.BeginTransaction(IsolationLevel.Serializable);
dbTransAct = dbConn.BeginTransaction();
cmdSQL.Connection = dbConn;
cmdSQL.Transaction = dbTransAct;
// Get only the new, modified, and deleted dataset rows
DataSet dsChanges = value.GetChanges();
// Get the database Table (the database file in dBase terms)
DataTable tbl = dsChanges.Tables[0];
// Spin through the changed rows (in the DataSet) and add
// the proper SQL command to the list of commands
foreach (DataRow row in tbl.Rows)
{
switch (row.RowState)
{
case DataRowState.Modified:
CommandList.Add(GetRecUpdateStr(tbl,row));
break;
case DataRowState.Added:
CommandList.Add(GetRecInsertStr(tbl,row));
break;
case DataRowState.Deleted:
CommandList.Add(RecDeleteStr(tbl,row));
break;
default:
// Ignore the DataRowState.Detached
// and the DataRowState.Unchanged
break;
}
}
// Process the list of SQL commands
err = ProcessSQLCommands(cmdSQL,CommandList);
// If no errors in the database transactions,
// commit the changes in both the database
// and the dataset.
if (err == 0)
{
dbTransAct.Commit();
value.AcceptChanges();
}
else
{
// If there was an error then roll back the changes
dbTransAct.Rollback();
}
dbConn.Close();
}
}
public bool ProcessACommand(string cmd)
{
// open a connection and setup for the database command
dbConn.Open();
System.Data.OleDb.OleDbCommand cmdSQL = new OleDbCommand();
System.Data.OleDb.OleDbTransaction dbTransAct;
dbTransAct = dbConn.BeginTransaction();
try
{
cmdSQL.Connection = dbConn;
cmdSQL.Transaction = dbTransAct;
cmdSQL.CommandText = cmd;
cmdSQL.ExecuteNonQuery();
dbTransAct.Commit();
dbConn.Close();
}
catch (Exception e)
{
dbTransAct.Rollback();
dbConn.Close();
MessageBox.Show(e.Message,"Error writing to database");
return false;
}
return true;
}
// Create a function that returns an SQL statement to use for updating
// existing records in a database
public abstract string GetRecUpdateStr(DataTable tbl,DataRow row);
// Create a function that returns an SQL statement to use for inserting
// records in a database
public abstract string GetRecInsertStr(DataTable tbl,DataRow row);
// Create a function that returns an SQL statement to use for deleting
// existing records in a database
public abstract string RecDeleteStr(DataTable tbl,DataRow row);
// Create a function that returns a list of SQL commands that will create
// a new table
public abstract StringCollection CreateTableStatements(string strTblName);
// Create a function that returns a list of SQL commands that selects from
// given table into another table. (Used for copying to approved/tmpchg).
public virtual StringCollection SelectIntoStatements(string destdb){return null;}
// Create a function that returns a list of SQL commands that will create
// the index files needed for this database file.
public virtual StringCollection CreateIndexFilesStatements(){return null;}
// Create a function that returns a list of SQL commands that will create
// the first (empty) record.
public virtual StringCollection CreateFirstRecordStatement(string strTblName)
{
StringCollection rtnStrColl = new StringCollection();
// Default to no "first record" (a.k.a record zero)
// Return an empty set of SQL commands
return rtnStrColl;
}
// Override this function if post processing is needed after creating
// a table.
public virtual int PostCreateTableFunction()
{
return 0;
}
public int CreateTable(string strTlbName)
{
int errs =0;
dbConn.Open();
// Setup for a series of database transactions
System.Data.OleDb.OleDbCommand cmdSQL = new OleDbCommand();
System.Data.OleDb.OleDbTransaction dbTransAct;
// dbTransAct = dbConn.BeginTransaction(IsolationLevel.Serializable);
dbTransAct = dbConn.BeginTransaction();
cmdSQL.Connection = dbConn;
cmdSQL.Transaction = dbTransAct;
// Process the list of SQL commands
// NOTE: if you create an associated INF file (for dBase indexes)
// before calling ProcessSQLCommands(), the INF file will be
// deleted (by the database engine) when the Create Table
// SQL command is run.
errs = ProcessSQLCommands(cmdSQL,CreateTableStatements(strTlbName));
// The PostCreateTableFunction() function should:
// - call CreateINF()if using dBase files with indexes
// - create the first "blank" record if required
if (errs == 0)
errs = PostCreateTableFunction();
// Create the first record
if (errs == 0)
errs = ProcessSQLCommands(cmdSQL,CreateFirstRecordStatement(strTlbName));
dbConn.Close();
return errs;
}
// Just a pass through, update string is passed in.
public bool UpdateUsing(string updstr)
{
return (ProcessACommand(updstr));
}
// Select data from the current table into a new table, where the new table
// is the parameter destfile which includes the pathname to the database
// file.
public int SelectIntoNewTable(string destfile)
{
int errs=0;
dbConn.Open();
// Setup for a series of database transactions
System.Data.OleDb.OleDbCommand cmdSQL = new OleDbCommand();
System.Data.OleDb.OleDbTransaction dbTransAct;
dbTransAct = dbConn.BeginTransaction();
cmdSQL.Connection = dbConn;
cmdSQL.Transaction = dbTransAct;
// Process the list of SQL commands, selectinto has no where clause.
// It only requires that the destination database file be included.
errs = ProcessSQLCommands(cmdSQL,SelectIntoStatements(destfile));
dbConn.Close();
return errs;
}
// make statement to insert into (an existing table). If table specific
// commands are needed, move this to the specific table code.
public StringCollection InsertIntoStatements(string destdb, string WhereStr)
{
StringCollection rtnStrColl = new StringCollection();
StringBuilder str = new StringBuilder();
str.Append("INSERT INTO ");
str.Append(DBTable);
str.Append(" IN '");
str.Append(destdb.Substring(0,destdb.LastIndexOf('\\')));
str.Append("' 'dBase III;' SELECT * FROM ");
str.Append(DBTable);
if (WhereStr.Length > 0) // Was a WHERE clause passed in?
{
// Add " WHERE " to the beginning if it is not already there
string tmpstr = WhereStr.ToUpper();
if (tmpstr[0] != ' ')
{
str.Append(" ");
if (!tmpstr.StartsWith("WHERE "))
str.Append("WHERE ");
}
else if (!tmpstr.StartsWith(" WHERE "))
str.Append(" WHERE");
// add the passed in WHERE clause
str.Append(WhereStr);
}
rtnStrColl.Add(str.ToString());
return rtnStrColl;
}
public int InsertInto(string destfile, string WhereStr)
{
int errs=0;
dbConn.Open();
// Setup for a series of database transactions
System.Data.OleDb.OleDbCommand cmdSQL = new OleDbCommand();
System.Data.OleDb.OleDbTransaction dbTransAct;
dbTransAct = dbConn.BeginTransaction();
cmdSQL.Connection = dbConn;
cmdSQL.Transaction = dbTransAct;
// Process the list of SQL commands, selectinto has no where clause, but
// requires that the index file be created ("",true arguments)
errs = ProcessSQLCommands(cmdSQL,InsertIntoStatements(destfile,WhereStr));
dbConn.Close();
return errs;
}
// make statement to delete records based on input criteria. If table specific
// commands are needed, move this to the specific table code.
public StringCollection DeleteSelectedStr(string whereclause)
{
StringCollection rtnStrColl = new StringCollection();
StringBuilder deleteStr = new StringBuilder();
deleteStr.Append("DELETE FROM [");
deleteStr.Append(DBTable);
deleteStr.Append("]");
// Add the WHERE clause
deleteStr.Append(" WHERE ");
deleteStr.Append(whereclause);
rtnStrColl.Add(deleteStr.ToString());
return rtnStrColl;
}
// Delete selected records based on criteria from WhereStr parameter.
public int DeleteSelected(string WhereStr)
{
int errs=0;
dbConn.Open();
System.Data.OleDb.OleDbCommand cmdSQL = new OleDbCommand();
System.Data.OleDb.OleDbTransaction dbTransAct;
dbTransAct = dbConn.BeginTransaction();
cmdSQL.Connection = dbConn;
cmdSQL.Transaction = dbTransAct;
// Process the list of SQL commands
errs = ProcessSQLCommands(cmdSQL,DeleteSelectedStr(WhereStr));
dbConn.Close();
return errs;
}
public abstract StringCollection DeleteTableStatements(string strTblName);
// Override this function if post processing is needed after removing
// a table.
public int PostDeleteTableFunction()
{
return 0;
}
public virtual int DeleteTable(string strTblName)
{
int errs =0;
dbConn.Open();
// Setup for a series of database transactions
System.Data.OleDb.OleDbCommand cmdSQL = new OleDbCommand();
System.Data.OleDb.OleDbTransaction dbTransAct;
// dbTransAct = dbConn.BeginTransaction(IsolationLevel.Serializable);
dbTransAct = dbConn.BeginTransaction();
cmdSQL.Connection = dbConn;
cmdSQL.Transaction = dbTransAct;
// Process the list of SQL commands
errs = ProcessSQLCommands(cmdSQL,DeleteTableStatements(strTblName));
// do any needed post processing
if (errs == 0)
errs = PostDeleteTableFunction();
if (errs == 0) // no errors
{
strDBTable = "";
if (databaseTypeValue.Equals(vdb_DBConnType.DBTypes.DBaseIII))
{
strDBFile = "";
}
}
dbConn.Close();
return errs;
}
// Override this function to create a text file with the same name as the
// dBase file, except give it an extension of INF instead of DBF.
// Inside this text file should be the index file names associated
// with the dBasefile. (each file name should be on its own line)
// Example, for USAGERO.DBF you should create a USAGERO.INF and inside
// the INF file should be:
// NDX1=USAGERO.NDX
// NDX2=USAGROID.NDX
//
// If the dBase does not use an index file, then there is no need to
// override this virtual funtion.
public virtual int CreateINF()
{
return 0;
}
public bool isdBaseFile()
{
return databaseTypeValue == (int)vdb_DBConnType.DBTypes.DBaseIII;
}
public virtual string GetCreateIndx1String()
{
return null;
}
public virtual string GetCreateIndx2String()
{
return null;
}
public virtual bool IndexFilesExist()
{
return true;
}
public virtual void DeleteIndexFiles()
{
}
// use this to clean up/create index & INF Files. The INF files are used to
// define which index files are used for the given database file. However, if file
// names are listed in the INF file and the NDX file does not exist, an error was
// given - so be sure that the index files exist too. Note that the INF file
// must be created after the NDX file, because an error occurs if creating an NDX
// file when an INF file exists. This was done to fix B2005-030.
public bool CheckIndxAndINF()
{
try
{
if (!IndexFilesExist())
{
string cwd = Directory.GetCurrentDirectory();
Directory.SetCurrentDirectory(DBPath);
// if more than one index file exists for a dbf, then delete (in case
// one of them did exist)
DeleteIndexFiles();
// CreateIndexFiles creates the NDX and also INF.
CreateIndexFiles();
Directory.SetCurrentDirectory(cwd);
}
else
CreateINF(); // CreateINF creates a new copy (overwrites any existing)
}
catch (Exception e)
{
MessageBox.Show("Could not set up index files " + e.Message,"Check For Indexes");
return false;
}
return true;
}
public virtual int CreateIndexFiles()
{
int errs =0;
dbConn.Open();
// Setup for a series of database transactions
System.Data.OleDb.OleDbCommand cmdSQL = new OleDbCommand();
System.Data.OleDb.OleDbTransaction dbTransAct;
dbTransAct = dbConn.BeginTransaction();
cmdSQL.Connection = dbConn;
cmdSQL.Transaction = dbTransAct;
// if dbase, delete the inf file. If it exists, an error occurs when
// creating the index.
if (File.Exists(strDBTable+".INF")) File.Delete(strDBTable+".INF");
// Process the list of SQL commands
errs = ProcessSQLCommands(cmdSQL,CreateIndexFilesStatements());
dbConn.Close();
if (errs==0 && isdBaseFile()) CreateINF();
return errs;
}
public void Pack()
{
// the database was not getting 'packed' on a delete, i.e. the deleted
// records were still visible in the 16-bit codes. We'll pack here by
// selecting into a temp db & renaming files.
// first see if there is an index, i.e. GetCreateIndxString will return
// a string if an index file is needed. If so, we know that we'll have
// to create the index(es) & also create an INF file.
string createindx = GetCreateIndx1String();
string origname = this.DBTable;
string newtbname=null;
try
{
if (this.DBTable.Length==8)
newtbname = "z" + this.DBTable.Substring(1,7);
else
newtbname = "z" + this.DBTable;
string sqlcmd = "select * into [" + newtbname + "] from [" + origname + "];";
// Setup for a series of database transactions
dbConn = new OleDbConnection(databaseType.ConnectionString(strDBPath,""));
dbConn.Open();
System.Data.OleDb.OleDbCommand cmdSQL = new OleDbCommand(sqlcmd,dbConn);
cmdSQL.ExecuteNonQuery();
dbConn.Close();
// delete original & rename (dbf, dbt), then make new index file & INF
// file, if they exist.
foreach(string str in DBExtensions)
{
string orig = strDBPath+"\\"+origname + "." + str;
if (File.Exists(orig))
{
File.Delete(orig);
string newnm = strDBPath + "\\" + newtbname + "." + str;
File.Move(newnm,orig);
}
}
if (createindx!=null)
{
// delete the index files...
DeleteIndexFiles();
dbConn.Open();
cmdSQL = new OleDbCommand(createindx,dbConn);
cmdSQL.ExecuteNonQuery();
createindx = GetCreateIndx2String();
if (createindx!=null)
{
cmdSQL.CommandText = createindx;
cmdSQL.ExecuteNonQuery();
}
dbConn.Close();
CreateINF();
}
}
catch (Exception e)
{
MessageBox.Show(e.Message,"Could not pack database, use data integrity checker on procedure");
}
}
}
}

View File

@@ -0,0 +1,155 @@
<VisualStudioProject>
<CSHARP
ProjectType = "Local"
ProductVersion = "7.10.3077"
SchemaVersion = "2.0"
ProjectGuid = "{F6AB1684-FC39-47E8-BEF1-A71EE4082206}"
>
<Build>
<Settings
ApplicationIcon = ""
AssemblyKeyContainerName = ""
AssemblyName = "VDB"
AssemblyOriginatorKeyFile = ""
DefaultClientScript = "JScript"
DefaultHTMLPageLayout = "Grid"
DefaultTargetSchema = "IE50"
DelaySign = "false"
OutputType = "Library"
PreBuildEvent = ""
PostBuildEvent = ""
RootNamespace = "VDB"
RunPostBuildEvent = "OnBuildSuccess"
StartupObject = ""
>
<Config
Name = "Debug"
AllowUnsafeBlocks = "false"
BaseAddress = "285212672"
CheckForOverflowUnderflow = "false"
ConfigurationOverrideFile = ""
DefineConstants = "DEBUG;TRACE;Upgrade2005;"
DocumentationFile = ""
DebugSymbols = "true"
FileAlignment = "4096"
IncrementalBuild = "true"
NoStdLib = "false"
NoWarn = ""
Optimize = "false"
OutputPath = "..\..\..\Ve-proms.net\BIN\"
RegisterForComInterop = "false"
RemoveIntegerChecks = "false"
TreatWarningsAsErrors = "false"
WarningLevel = "4"
/>
<Config
Name = "Release"
AllowUnsafeBlocks = "false"
BaseAddress = "285212672"
CheckForOverflowUnderflow = "false"
ConfigurationOverrideFile = ""
DefineConstants = "TRACE"
DocumentationFile = ""
DebugSymbols = "true"
FileAlignment = "4096"
IncrementalBuild = "false"
NoStdLib = "false"
NoWarn = ""
Optimize = "true"
OutputPath = "..\..\..\Ve-proms.net\BIN\"
RegisterForComInterop = "false"
RemoveIntegerChecks = "false"
TreatWarningsAsErrors = "false"
WarningLevel = "4"
/>
</Settings>
<References>
<Reference
Name = "System"
AssemblyName = "System"
HintPath = "C:\WINDOWS\Microsoft.NET\Framework\v1.0.3705\System.dll"
/>
<Reference
Name = "System.Data"
AssemblyName = "System.Data"
HintPath = "C:\WINDOWS\Microsoft.NET\Framework\v1.0.3705\System.Data.dll"
/>
<Reference
Name = "System.XML"
AssemblyName = "System.Xml"
HintPath = "C:\WINDOWS\Microsoft.NET\Framework\v1.0.3705\System.XML.dll"
/>
<Reference
Name = "System.Windows.Forms"
AssemblyName = "System.Windows.Forms"
HintPath = "C:\WINDOWS\Microsoft.NET\Framework\v1.0.3705\System.Windows.Forms.dll"
/>
<Reference
Name = "System.Drawing"
AssemblyName = "System.Drawing"
HintPath = "C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\System.Drawing.dll"
/>
</References>
</Build>
<Files>
<Include>
<File
RelPath = "AssemblyInfo.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "EopToErgRelations.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "ProcedureSelectionList.cs"
SubType = "Form"
BuildAction = "Compile"
/>
<File
RelPath = "ProcedureSelectionList.resx"
DependentUpon = "ProcedureSelectionList.cs"
BuildAction = "EmbeddedResource"
/>
<File
RelPath = "VDB.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "vdb_Proc.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "vdb_ROUsage.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "vdb_Set.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "vdb_SetExt.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "vdb_TransUsage.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "vdbConnType.cs"
SubType = "Code"
BuildAction = "Compile"
/>
</Include>
</Files>
</CSHARP>
</VisualStudioProject>

View File

@@ -0,0 +1,21 @@
Microsoft Visual Studio Solution File, Format Version 8.00
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VDB", "VDB.csproj", "{F6AB1684-FC39-47E8-BEF1-A71EE4082206}"
ProjectSection(ProjectDependencies) = postProject
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfiguration) = preSolution
Debug = Debug
Release = Release
EndGlobalSection
GlobalSection(ProjectConfiguration) = postSolution
{F6AB1684-FC39-47E8-BEF1-A71EE4082206}.Debug.ActiveCfg = Debug|.NET
{F6AB1684-FC39-47E8-BEF1-A71EE4082206}.Debug.Build.0 = Debug|.NET
{F6AB1684-FC39-47E8-BEF1-A71EE4082206}.Release.ActiveCfg = Release|.NET
{F6AB1684-FC39-47E8-BEF1-A71EE4082206}.Release.Build.0 = Release|.NET
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
EndGlobalSection
GlobalSection(ExtensibilityAddIns) = postSolution
EndGlobalSection
EndGlobal

View File

@@ -0,0 +1,66 @@
/*********************************************************************************************
* Copyright 2004 - Volian Enterprises, Inc. All rights reserved.
* Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE
* ------------------------------------------------------------------------------
* $Workfile: vdbConnType.cs $ $Revision: 1 $
* $Author: Kathy $ $Date: 7/27/04 8:40a $
*
* $History: vdbConnType.cs $
*
* ***************** Version 1 *****************
* User: Kathy Date: 7/27/04 Time: 8:40a
* Created in $/LibSource/VDB
*********************************************************************************************/
using System;
using System.Text;
namespace VDB_ConnType
{
/// <summary>
/// This currently defaults to dBase, but logic can be added to
/// select other database types.
/// </summary>
public class vdb_DBConnType
{
public enum DBTypes {DBaseIII, Access}; // list of database types
private int CurrentDbType; // current database type
public vdb_DBConnType()
{
CurrentDbType = (int)DBTypes.DBaseIII;
}
public int dbType
{
get
{
return CurrentDbType;
}
}
// The "database" parameter is here for future use of Access (part of the
// Data Source string) and for Sequel (the Initial Catalog) settings.
// for a dBase connection, we only need the "dbpath" parameter.
public string ConnectionString(string dbpath, string database)
{
StringBuilder tmp = new StringBuilder();
switch (CurrentDbType)
{
case (int)DBTypes.DBaseIII:
tmp.Append("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=");
tmp.Append(dbpath);
tmp.Append(";Extended Properties=dBase III;Persist Security Info=False");
break;
case (int)DBTypes.Access:
// build the connect string for an Access database
break;
default:
break;
}
return tmp.ToString();
}
}
}

View File

@@ -0,0 +1,553 @@
/*********************************************************************************************
* Copyright 2004 - Volian Enterprises, Inc. All rights reserved.
* Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE
* ------------------------------------------------------------------------------
* $Workfile: vdb_Proc.cs $ $Revision: 11 $
* $Author: Kathy $ $Date: 9/23/05 8:33a $
*
* $History: vdb_Proc.cs $
*
* ***************** Version 11 *****************
* User: Kathy Date: 9/23/05 Time: 8:33a
* Updated in $/LibSource/VDB
* Fix B2005-043 - cannot select into for files with a '-' (dash).
*
* ***************** Version 10 *****************
* User: Jsj Date: 9/16/05 Time: 9:54a
* Updated in $/LibSource/VDB
* handle dbase NDX file names that begin with a number. SQL statement
* could not create a NDX file that begins with a number.
*
* ***************** Version 9 *****************
* User: Kathy Date: 8/16/05 Time: 2:53p
* Updated in $/LibSource/VDB
* B2005-030: error if missing ndx
*
* ***************** Version 8 *****************
* User: Kathy Date: 7/28/05 Time: 2:06p
* Updated in $/LibSource/VDB
* for mod proc number, select into correct destination file
*
* ***************** Version 7 *****************
* User: Kathy Date: 5/19/05 Time: 11:05a
* Updated in $/LibSource/VDB
* speed up approve
*
* ***************** Version 6 *****************
* User: Jsj Date: 5/17/05 Time: 9:39a
* Updated in $/LibSource/VDB
*
* ***************** Version 5 *****************
* User: Kathy Date: 5/11/05 Time: 9:28a
* Updated in $/LibSource/VDB
* add selectinto support
*
* ***************** Version 4 *****************
* User: Kathy Date: 4/21/05 Time: 10:19a
* Updated in $/LibSource/VDB
* always write inf file
*
* ***************** Version 3 *****************
* User: Kathy Date: 3/08/05 Time: 1:47p
* Updated in $/LibSource/VDB
* Approval
*
* ***************** Version 2 *****************
* User: Jsj Date: 8/23/04 Time: 10:12a
* Updated in $/LibSource/VDB
* Fixed replace of single quote
*
* ***************** Version 1 *****************
* User: Kathy Date: 7/27/04 Time: 8:40a
* Created in $/LibSource/VDB
*********************************************************************************************/
using System;
using System.Data;
using System.Text;
using System.Collections.Specialized;
using System.IO;
using System.Windows.Forms;
using VDB;
namespace VDB_Proc
{
/// <summary>
/// Summary description for vdb_Proc.
/// </summary>
public class vdb_Proc:VDB_Base
{
public enum SortTypes {NotSorted,StepSeqTypeSort,RECIDsort}; // list of sorting types
public string ProcNDX = "";
public string TmpNDXFileName = "";
public vdb_Proc(String strPath):base(strPath)
{
}
public string ProcGetTextFromMemo(string RecId)
{
return GetMemo(RecId);
}
// Build a SQL statement. Optionally sort and filter the select statement.
private void BuildSelectCommand(int SortingType,string WhereStr)
{
StringBuilder tmp = new StringBuilder();
tmp.Append("SELECT [STEP], [SEQUENCE], [TEXT], [TEXTM], [TYPE], [DATE], [TIME], [INITIALS], [RECID] FROM [");
tmp.Append(DBTable);
tmp.Append("]");
if (WhereStr.Length > 0) // Was a WHERE clause passed in?
{
// Add " WHERE " to the beginning if it is not already there
string tmpstr = WhereStr.ToUpper();
if (tmpstr[0] != ' ')
{
tmp.Append(" ");
if (!tmpstr.StartsWith("WHERE "))
tmp.Append("WHERE ");
}
else if (!tmpstr.StartsWith(" WHERE "))
tmp.Append(" WHERE");
// add the passed in WHERE clause
tmp.Append(tmpstr);
}
switch (SortingType)
{
case 0: //NotSorted
break;
case 1: // StepSeqTypeSort - sorted by STEP+SEQUENCE+TYPE
tmp.Append(" GROUP BY [STEP],[SEQUENCE],[TYPE],[TEXT],[TEXTM],[DATE],[TIME],[INITIALS],[RECID]");
break;
case 2: // RECIDsort - sorted by RECID
tmp.Append(" GROUP BY [RECID],[STEP],[SEQUENCE],[TYPE],[TEXT],[TEXTM],[DATE],[TIME],[INITIALS]");
break;
}
SelectCmd = tmp.ToString();
}
#if Upgrade2005_Print
// Build a SQL statement for record count on select.
private void BuildCountCommand(string WhereStr)
{
StringBuilder tmp = new StringBuilder();
tmp.Append("SELECT COUNT(*) FROM [");
tmp.Append(DBTable);
tmp.Append("]");
if (WhereStr.Length > 0) // Was a WHERE clause passed in?
{
// Add " WHERE " to the beginning if it is not already there
string tmpstr = WhereStr.ToUpper();
if (tmpstr[0] != ' ')
{
tmp.Append(" ");
if (!tmpstr.StartsWith("WHERE "))
tmp.Append("WHERE ");
}
else if (!tmpstr.StartsWith(" WHERE "))
tmp.Append(" WHERE");
// add the passed in WHERE clause
tmp.Append(tmpstr);
}
SelectCmd = tmp.ToString();
}
#endif
private void BuildNDXFileNames()
{
ProcNDX = DBTable;
}
// Build the SQL command needed to update a row in the Procedure file
public override string GetRecUpdateStr(DataTable tbl,DataRow row)
{
int j = 0;
bool FirstOne = true;
StringBuilder updateStr = new StringBuilder();
StringBuilder LikeRecID = new StringBuilder();
bool NullEntry = false;
updateStr.Append("UPDATE [");
updateStr.Append(DBTable);
updateStr.Append("] SET");
foreach (DataColumn col in tbl.Columns)
{
bool isString = (col.DataType == Type.GetType("System.String"));
if (col.ColumnName.Equals("STEP") && row.ItemArray[j].ToString().Equals(""))
{
NullEntry = true;
j++;
continue;
}
if (col.ColumnName.Equals("RECID"))
{
LikeRecID.Append("___"); // ignore the first 3 positions
LikeRecID.Append(row.ItemArray[j].ToString(),3,5);
}
if (FirstOne)
{
updateStr.Append(" [");
FirstOne = false;
}
else
updateStr.Append(", [");
updateStr.Append(col.ColumnName);
updateStr.Append("]=");
if (row.ItemArray[j].ToString().Equals(""))
{
updateStr.Append("NULL");
}
else if (isString)
{
String tmpstr = row.ItemArray[j].ToString();
updateStr.Append("'");
tmpstr = tmpstr.Replace("'","''");
updateStr.Append(tmpstr);
updateStr.Append("'");
}
else if (col.DataType == Type.GetType("System.DateTime"))
{
int jj;
String tmpstr = row.ItemArray[j].ToString();
updateStr.Append("'");
jj=tmpstr.IndexOf(" ");
if (jj<0) jj = tmpstr.Length;
updateStr.Append(tmpstr.Substring(0,jj));
updateStr.Append("'");
}
j++;
}
if (NullEntry)
{
// So that we can change the RECID number on the first entry
updateStr.Append(" WHERE [STEP] IS NULL");
}
else
{
updateStr.Append(" WHERE [RECID] LIKE '");
updateStr.Append(LikeRecID.ToString());
updateStr.Append("'");
}
return updateStr.ToString();
}
// Build the SQL command needed to insert a row in the Procedure file
public override string GetRecInsertStr(DataTable tbl,DataRow row)
{
int j = 0;
StringBuilder insrtStr = new StringBuilder();
StringBuilder valueStr = new StringBuilder();
insrtStr.Append("INSERT INTO [");
insrtStr.Append(DBTable);
insrtStr.Append("] (");
valueStr.Append(" VALUES (");
foreach (DataColumn col in tbl.Columns)
{
bool isString = (col.DataType == Type.GetType("System.String"));
insrtStr.Append("[");
insrtStr.Append(col.ColumnName);
insrtStr.Append("],");
if (row.ItemArray[j].ToString().Equals(""))
{
valueStr.Append("NULL");
}
else if (isString)
{
String tmpstr = row.ItemArray[j].ToString();
tmpstr = tmpstr.Replace("'","''");
valueStr.Append("'");
valueStr.Append(tmpstr);
valueStr.Append("'");
}
else if (col.DataType == Type.GetType("System.DateTime"))
{
int jj;
String tmpstr = row.ItemArray[j].ToString();
valueStr.Append("'");
jj = tmpstr.IndexOf(" ");
if (jj<0) jj=tmpstr.Length;
valueStr.Append(tmpstr.Substring(0,jj));
valueStr.Append("'");
}
else
{
valueStr.Append(row.ItemArray[j].ToString());
}
valueStr.Append(",");
j++;
}
insrtStr = insrtStr.Replace(',',')',insrtStr.Length-1,1);
valueStr = valueStr.Replace(',',')',valueStr.Length-1,1);
insrtStr.Append(valueStr.ToString());
return insrtStr.ToString();
}
// Build the SQL command needed to delete a row in the Procedure file
public override string RecDeleteStr(DataTable tbl,DataRow row)
{
int j = 0;
String RecIDStr = "";
String StepStr = "";
String SeqStr = "";
StringBuilder deleteStr = new StringBuilder();
deleteStr.Append("DELETE FROM [");
deleteStr.Append(DBTable);
deleteStr.Append("] WHERE ");
row.RejectChanges();
foreach (DataColumn col in tbl.Columns)
{
if (col.ColumnName.Equals("STEP"))
{
StepStr = row.ItemArray[j].ToString();
}
else if (col.ColumnName.Equals("SEQUENCE"))
{
SeqStr = row.ItemArray[j].ToString();
}
else if (col.ColumnName.Equals("RECID"))
{
RecIDStr = row.ItemArray[j].ToString();
}
j++;
}
// we might want to change this to delete via only the RECID
// but that could be risky if we have duplicate RECIDs
deleteStr.Append("[STEP] = '");
deleteStr.Append(StepStr);
deleteStr.Append("' AND [SEQUENCE] = '");
deleteStr.Append(SeqStr);
deleteStr.Append("' AND [RECID] = '");
deleteStr.Append(RecIDStr);
deleteStr.Append("'");
return deleteStr.ToString();
}
public override string GetCreateIndx1String()
{
StringBuilder index1Str = new StringBuilder();
// Make a temporary index file name if dBase filename
// for any procedure. (those that start with a number
// or had a dash were having a problem here - see
// B2005-040 & 043).
TmpNDXFileName = "ndxtmp";
index1Str.Append("CREATE INDEX [");
index1Str.Append(TmpNDXFileName);
index1Str.Append("] ON [");
index1Str.Append(DBTable);
index1Str.Append("] ([STEP],[SEQUENCE],[TYPE])");
return (index1Str.ToString());
}
public override bool IndexFilesExist()
{
if (ProcNDX == "") BuildNDXFileNames();
if(File.Exists(DBPath+"\\"+ProcNDX+".NDX")) return true;
return false;
}
public override void DeleteIndexFiles()
{
if(File.Exists(DBPath+"\\"+ProcNDX+".NDX")) File.Delete(DBPath+"\\"+ProcNDX+".NDX");
}
// Build a list of SQL commands needed to create a new Procedure table (file)
// and add the first row
public override StringCollection CreateTableStatements(string strTblName)
{
StringCollection rtnStrColl = new StringCollection();
StringBuilder createStr = new StringBuilder();
if (strTblName.Length > 0) // was a table name passd in?
{
DBTable = strTblName; // this will create the INI file for dBase
}
if (DBTable.Equals(""))
{
MessageBox.Show("Trying to Create a new Table without a Name","Create Table Error");
return rtnStrColl;
}
// Build the command that creates a new SET table (file)
createStr.Append("CREATE TABLE [");
createStr.Append(DBTable);
createStr.Append("] ");
createStr.Append("([STEP] Char(2), [SEQUENCE] Char(10), [TEXT] Char(100), ");
createStr.Append("[TEXTM] TEXT, [TYPE] Char(2), [DATE] Date, [TIME] Char(5), ");
createStr.Append("INITIALS Char(5), [RECID] Char(8))");
rtnStrColl.Add(createStr.ToString()); // add create table
// If we are using dBase files, create the index files too
if (isdBaseFile())
{
// Build the command that creates the index file
rtnStrColl.Add(GetCreateIndx1String()); // add create index
}
return rtnStrColl;
}
// Build a list of SQL commands needed to create the first row (a.k.a record zero)
public override StringCollection CreateFirstRecordStatement(string strTblName)
{
StringCollection rtnStrColl = new StringCollection();
StringBuilder firstRecStr = new StringBuilder();
// Build the command that adds the first (blank) record
// with the RECID initialize to 00000001
firstRecStr.Append("INSERT INTO [");
firstRecStr.Append(DBTable);
firstRecStr.Append("] ([RECID]) VALUES ('00000001')");
rtnStrColl.Add(firstRecStr.ToString()); // add insert first record
return rtnStrColl;
}
// make statement to select into a new table. Table must not exist and
// can include a path to the table.
public override StringCollection SelectIntoStatements(string destdb)
{
StringCollection rtnStrColl = new StringCollection();
StringBuilder str = new StringBuilder();
str.Append("SELECT * INTO [");
str.Append(destdb.Substring(destdb.LastIndexOf('\\')+1,destdb.Length-destdb.LastIndexOf('\\')-1));
str.Append("] IN '");
str.Append(destdb.Substring(0,destdb.LastIndexOf('\\')));
str.Append("' 'dBase III;' from [");
str.Append(DBTable);
str.Append("]");
rtnStrColl.Add(str.ToString());
return rtnStrColl;
}
// After the table is created, create the associated INF file
public override int PostCreateTableFunction()
{
CreateINF(); // should already be created
return 0;
}
// This will be called from CreateTableStatements()
// and this is called if the table name is assigned to the DBTable property
public override int CreateINF()
{
// if we are using dBase files, create an INF file containing
// a list of the associated NDX files.
if (isdBaseFile())
{
StreamWriter infFile;
string infFileStr;
StringBuilder tmp = new StringBuilder();
// build the ndx file names (w/o extensions)
BuildNDXFileNames();
//build INF file name
tmp.Append(DBPath);
tmp.Append("\\");
tmp.Append(DBTable);
tmp.Append(".INF");
infFileStr = tmp.ToString();
// always recreate it. Some plants' data had invalid files
// and it was felt that it would be quicker to recreate always
// rather than read and check.
infFile = new StreamWriter(infFileStr,false);
infFile.Write("NDX1=");
infFile.Write(ProcNDX);
infFile.Write(".NDX\r\n");
infFile.Close();
// a temp index file name was always used to create the index
// because unusual file names, such as those beginning with
// a number or those with a '-' caused an error to occur
// during ndx file creation. This fixes, B2005-040 & B2005-043.
if (TmpNDXFileName.Length > 0)
{
File.Copy(TmpNDXFileName+".NDX",ProcNDX+".NDX");
File.Delete(TmpNDXFileName+".NDX");
TmpNDXFileName = "";
}
}
return 0;
}
public override StringCollection CreateIndexFilesStatements()
{
if (isdBaseFile())
{
StringCollection rtnStrColl = new StringCollection();
string indx1 = GetCreateIndx1String();
rtnStrColl.Add(indx1);
return rtnStrColl;
}
return null;
}
// return a list of SQL commands that will drop (delete) a database table (file)
public override StringCollection DeleteTableStatements(string strTblName)
{
StringCollection rtnStrColl = new StringCollection();
StringBuilder DropTableStr = new StringBuilder();
DropTableStr.Append("Drop Table [");
DropTableStr.Append(DBTable);
DropTableStr.Append("]");
rtnStrColl.Add(DropTableStr.ToString());
return rtnStrColl;
}
// return a dataset of procedure records, not sorted
public System.Data.DataSet GetNotSorted(string WhereStr)
{
BuildSelectCommand((int)SortTypes.NotSorted,WhereStr);
return DB_Data;
}
// return a dataset of procedure records, sorted by the [STEP] field
public System.Data.DataSet GetSortedByStepSeqType(string WhereStr)
{
BuildSelectCommand((int)SortTypes.StepSeqTypeSort,WhereStr);
return DB_Data;
}
// return a dataset of procedure records, sorted by the [RECID] field
public System.Data.DataSet GetSortedByRECID(string WhereStr)
{
BuildSelectCommand((int)SortTypes.RECIDsort,WhereStr);
return DB_Data;
}
#if Upgrade2005_Print
// return integer count of selected records only
public int GetCount(string WhereStr)
{
BuildCountCommand(WhereStr);
DataSet ds = DB_Data;
return ds.Tables[0].Rows.Count;
}
#endif
}
}

View File

@@ -0,0 +1,478 @@
/*********************************************************************************************
* Copyright 2004 - Volian Enterprises, Inc. All rights reserved.
* Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE
* ------------------------------------------------------------------------------
* $Workfile: vdb_ROUsage.cs $ $Revision: 6 $
* $Author: Kathy $ $Date: 5/01/06 11:17a $
*
* $History: vdb_ROUsage.cs $
*
* ***************** Version 6 *****************
* User: Kathy Date: 5/01/06 Time: 11:17a
* Updated in $/LibSource/VDB
* Fix B2006-018: single quote in proc number causes problem on data
* request
*
* ***************** Version 5 *****************
* User: Kathy Date: 8/16/05 Time: 2:54p
* Updated in $/LibSource/VDB
* B2005-030: error if missing ndx
*
* ***************** Version 4 *****************
* User: Kathy Date: 4/21/05 Time: 10:19a
* Updated in $/LibSource/VDB
* always write inf file & remove upgrade2005 define
*
* ***************** Version 3 *****************
* User: Kathy Date: 3/08/05 Time: 1:48p
* Updated in $/LibSource/VDB
* Approval
*
* ***************** Version 2 *****************
* User: Jsj Date: 8/23/04 Time: 10:12a
* Updated in $/LibSource/VDB
* Fixed replace of single quote
*
* ***************** Version 1 *****************
* User: Kathy Date: 7/27/04 Time: 8:40a
* Created in $/LibSource/VDB
*********************************************************************************************/
using System;
using System.Data;
using System.Text;
using System.Collections.Specialized;
using System.IO;
using System.Windows.Forms;
using VDB;
using VDB_ConnType;
namespace VDB_ROUsage
{
/// <summary>
/// Open, Create, Delete, Update functions for RO Usage files (tables)
/// </summary>
public class vdb_ROUsage:VDB_Base
{
public enum SortTypes {NotSorted,ProcSort,ROIDsort}; // list of sorting types
public string UsageROndx = "";
public string UsagROIDndx = "";
public vdb_ROUsage(String strPath):base(strPath)
{
// if no table (file name) specified, then default to USAGERO (USAGERO.DBF)
if (DBTable.Equals(""))
DBTable = "USAGERO";
}
// Build a SQL statement. Optionally sort and filter the select statement.
private void BuildSelectCommand(int SortingType,string WhereStr)
{
StringBuilder tmp = new StringBuilder();
tmp.Append("SELECT [NUMBER], [SEQUENCE], [INSTANCE], [ROID] FROM [");
tmp.Append(DBTable);
tmp.Append("]");
if (WhereStr.Length > 0) // Was a WHERE clause passed in?
{
// Add " WHERE " to the beginning if it is not already there
string tmpstr = WhereStr; //.ToUpper();
if (tmpstr[0] != ' ')
{
tmp.Append(" ");
if (!tmpstr.StartsWith("WHERE "))
tmp.Append("WHERE ");
}
else if (!tmpstr.StartsWith(" WHERE "))
tmp.Append(" WHERE");
// add the passed in WHERE clause
tmp.Append(tmpstr);
}
switch (SortingType)
{
case 0: //NotSorted
break;
case 1: // ProcSort - sorted by procedure number
tmp.Append(" GROUP BY [NUMBER],[SEQUENCE],[INSTANCE],[ROID]");
break;
case 2: // ROIDsort - sorted by ROID
tmp.Append(" GROUP BY [ROID],[NUMBER],[SEQUENCE],[INSTANCE]");
break;
}
SelectCmd = tmp.ToString();
}
private void BuildNDXFileNames()
{
UsageROndx = DBTable;
UsagROIDndx = DBTable.Substring(0,4)+"ROID";
}
// Build the SQL command needed to update a row in the USAGERO file
public override string GetRecUpdateStr(DataTable tbl,DataRow row)
{
int j = 0;
bool FirstOne = true;
StringBuilder updateStr = new StringBuilder();
string strNumber = "";
string strSequence = "";
string strInstance = "";
updateStr.Append("UPDATE [");
updateStr.Append(DBTable);
updateStr.Append("] SET");
foreach (DataColumn col in tbl.Columns)
{
bool isString = (col.DataType == Type.GetType("System.String"));
if (col.ColumnName.Equals("NUMBER"))
{
strNumber = row.ItemArray[j].ToString();
strNumber = strNumber.Replace("'","''");
}
else if (col.ColumnName.Equals("SEQUENCE"))
{
strSequence = row.ItemArray[j].ToString();
strSequence = strSequence.Replace("'","''");
}
else if (col.ColumnName.Equals("INSTANCE"))
{
strInstance = row.ItemArray[j].ToString();
strInstance = strInstance.Replace("'","''");
}
if (FirstOne)
{
updateStr.Append(" [");
FirstOne = false;
}
else
updateStr.Append(", [");
updateStr.Append(col.ColumnName);
updateStr.Append("]=");
if (row.ItemArray[j].ToString().Equals(""))
{
updateStr.Append("NULL");
}
else if (isString)
{
String tmpstr = row.ItemArray[j].ToString();
updateStr.Append("'");
tmpstr = tmpstr.Replace("'","''");
updateStr.Append(tmpstr);
updateStr.Append("'");
}
j++;
}
// Add the WHERE clause
updateStr.Append(" WHERE [NUMBER] = '");
updateStr.Append(strNumber.ToString());
updateStr.Append("' AND [SEQUENCE] = '");
updateStr.Append(strSequence.ToString());
updateStr.Append("' AND [INSTANCE] = '");
updateStr.Append(strInstance.ToString());
updateStr.Append("'");
return updateStr.ToString();
}
// Build the SQL command needed to insert a row in the USAGERO file
public override string GetRecInsertStr(DataTable tbl,DataRow row)
{
int j = 0;
StringBuilder insrtStr = new StringBuilder();
StringBuilder valueStr = new StringBuilder();
insrtStr.Append("INSERT INTO [");
insrtStr.Append(DBTable);
insrtStr.Append("] (");
valueStr.Append(" VALUES (");
foreach (DataColumn col in tbl.Columns)
{
bool isString = (col.DataType == Type.GetType("System.String"));
insrtStr.Append("[");
insrtStr.Append(col.ColumnName);
insrtStr.Append("],");
if (row.ItemArray[j].ToString().Equals(""))
{
valueStr.Append("NULL");
}
else if (isString)
{
String tmpstr = row.ItemArray[j].ToString();
tmpstr = tmpstr.Replace("'","''");
valueStr.Append("'");
valueStr.Append(tmpstr);
valueStr.Append("'");
}
else
{
valueStr.Append(row.ItemArray[j].ToString());
}
valueStr.Append(",");
j++;
}
insrtStr = insrtStr.Replace(',',')',insrtStr.Length-1,1);
valueStr = valueStr.Replace(',',')',valueStr.Length-1,1);
insrtStr.Append(valueStr.ToString());
return insrtStr.ToString();
}
// Build the SQL command needed to delete a row in the USAGERO file
public override string RecDeleteStr(DataTable tbl,DataRow row)
{
int j = 0;
string strNumber = "";
string strSequence = "";
string strInstance = "";
StringBuilder deleteStr = new StringBuilder();
deleteStr.Append("DELETE FROM [");
deleteStr.Append(DBTable);
deleteStr.Append("]");
row.RejectChanges();
foreach (DataColumn col in tbl.Columns)
{
if (col.ColumnName.Equals("NUMBER"))
{
strNumber = row.ItemArray[j].ToString();
strNumber = strNumber.Replace("'","''");
}
else if (col.ColumnName.Equals("SEQUENCE"))
{
strSequence = row.ItemArray[j].ToString();
strSequence = strSequence.Replace("'","''");
}
else if (col.ColumnName.Equals("INSTANCE"))
{
strInstance = row.ItemArray[j].ToString();
strInstance = strInstance.Replace("'","''");
}
j++;
}
// Add the WHERE clause
deleteStr.Append(" WHERE [NUMBER] = '");
deleteStr.Append(strNumber.ToString());
deleteStr.Append("' AND [SEQUENCE] = '");
deleteStr.Append(strSequence.ToString());
deleteStr.Append("' AND [INSTANCE] = '");
deleteStr.Append(strInstance.ToString());
deleteStr.Append("'");
return deleteStr.ToString();
}
public override string GetCreateIndx1String()
{
StringBuilder index1Str = new StringBuilder();
index1Str.Append("CREATE INDEX [");
index1Str.Append(UsageROndx);
index1Str.Append("] ON ");
index1Str.Append(DBTable);
index1Str.Append(".DBF ([NUMBER],[SEQUENCE],[INSTANCE])");
return (index1Str.ToString());
}
public override string GetCreateIndx2String()
{
StringBuilder index2Str = new StringBuilder();
index2Str.Append("CREATE INDEX [");
index2Str.Append(UsagROIDndx);
index2Str.Append("] ON ");
index2Str.Append(DBTable);
index2Str.Append(".DBF ([ROID])");
return (index2Str.ToString());
}
public override bool IndexFilesExist()
{
if (UsageROndx==""||UsagROIDndx=="") BuildNDXFileNames();
if(!File.Exists(DBPath+"\\"+UsageROndx+".NDX") || !File.Exists(DBPath+"\\"+UsagROIDndx+".NDX")) return false;
return true;
}
public override void DeleteIndexFiles()
{
if(File.Exists(DBPath+"\\"+UsageROndx+".NDX")) File.Delete(DBPath+"\\"+UsageROndx+".NDX");
if(File.Exists(DBPath+"\\"+UsagROIDndx+".NDX")) File.Delete(DBPath+"\\"+UsagROIDndx+".NDX");
if(File.Exists(DBPath+"\\"+DBTable+".INF")) File.Delete(DBPath+"\\"+DBTable+".INF");
}
public override StringCollection CreateIndexFilesStatements()
{
if (isdBaseFile())
{
StringCollection rtnStrColl = new StringCollection();
string indx1 = GetCreateIndx1String();
rtnStrColl.Add(indx1);
string indx2 = GetCreateIndx2String();
rtnStrColl.Add(indx2);
return rtnStrColl;
}
return null;
}
// Build a list of SQL commands needed to create a new USAGERO table (file)
// and add the first row
public override StringCollection CreateTableStatements(string strTblName)
{
StringCollection rtnStrColl = new StringCollection();
StringBuilder createStr = new StringBuilder();
//StringBuilder index1Str = new StringBuilder();
//StringBuilder index2Str = new StringBuilder();
if (strTblName.Length > 0) // was a table name passd in?
{
DBTable = strTblName;
}
if (DBTable.Equals(""))
{
MessageBox.Show("Trying to Create a new Table without a Name","Create Table Error");
return rtnStrColl;
}
// Build the command that creates a new SET table (file)
createStr.Append("CREATE TABLE [");
createStr.Append(DBTable);
createStr.Append("] ");
createStr.Append("([NUMBER] Char(20), [SEQUENCE] Char(12), ");
createStr.Append("[INSTANCE] Char(1), [ROID] Char(16))");
rtnStrColl.Add(createStr.ToString()); // add create table
if (isdBaseFile())
{
// build the ndx file names (w/o extensions)
// BuildNDXFileNames();
// Build the command that creates the first index file
rtnStrColl.Add(GetCreateIndx1String()); // add create 1st index
// Build the commmand that creates the second index file
string tmp = DBTable;
rtnStrColl.Add(GetCreateIndx2String()); // add create 2nd index
}
return rtnStrColl;
}
// After the table is created, create the associated INF file
public override int PostCreateTableFunction()
{
CreateINF(); // should already be created
return 0;
}
// This is called in the class constructor and
// if the table name is assigned to the DBTable property
public override int CreateINF()
{
// if we are using dBase files, create an INF file containing
// a list of the associated NDX files.
if (isdBaseFile())
{
StreamWriter infFile;
string infFileStr;
StringBuilder tmp = new StringBuilder();
// build the ndx file names (w/o extensions)
BuildNDXFileNames();
//build INF file name
tmp.Append(DBPath);
tmp.Append("\\");
tmp.Append(DBTable);
tmp.Append(".INF");
infFileStr = tmp.ToString();
// if the INF file does not already exist create it
//if (!File.Exists(infFileStr))
//{
// always recreate it. Some plants' data had invalid files
// and it was felt that it would be quicker to recreate always
// rather than
infFile = new StreamWriter(infFileStr,false);
infFile.Write("NDX1=");
infFile.Write(UsageROndx); // USAGERO.NDX
infFile.Write(".NDX\r\n");
infFile.Write("NDX2=");
infFile.Write(UsagROIDndx); //USAGROID.NDX
infFile.Write(".NDX\r\n");
infFile.Close();
//}
}
return 0;
}
// return a list of SQL commands that will drop (delete) a database table (file)
public override StringCollection DeleteTableStatements(string strTblName)
{
StringCollection rtnStrColl = new StringCollection();
StringBuilder DropTableStr = new StringBuilder();
DropTableStr.Append("Drop Table [");
DropTableStr.Append(DBTable);
DropTableStr.Append("]");
rtnStrColl.Add(DropTableStr.ToString());
return rtnStrColl;
}
// return a dataset of RO Usage records, not sorted
public System.Data.DataSet GetNotSorted(string WhereStr)
{
BuildSelectCommand((int)SortTypes.NotSorted,WhereStr);
return DB_Data;
}
// return a dataset of RO Usage records, sorted by the [NUMBER] field
public System.Data.DataSet GetSortedByProc(string WhereStr)
{
BuildSelectCommand((int)SortTypes.ProcSort,WhereStr);
return DB_Data;
}
// return a dataset of RO Usage records, sorted by the [ROID] field
public System.Data.DataSet GetSortedByROID(string WhereStr)
{
BuildSelectCommand((int)SortTypes.ROIDsort,WhereStr);
return DB_Data;
}
public void UpdateProcNumber(string oldnum, string newnum)
{
// Change fromnumber first, then tonumber
StringBuilder updateStr = new StringBuilder();
updateStr.Append("UPDATE [");
updateStr.Append(DBTable);
updateStr.Append("] SET [NUMBER] = '");
updateStr.Append(newnum.Replace("'","''"));
updateStr.Append("' WHERE [NUMBER] = '");
updateStr.Append(oldnum.Replace("'","''"));
updateStr.Append("'");
ProcessACommand(updateStr.ToString());
}
}
}

View File

@@ -0,0 +1,283 @@
/*********************************************************************************************
* Copyright 2004 - Volian Enterprises, Inc. All rights reserved.
* Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE
* ------------------------------------------------------------------------------
* $Workfile: vdb_Set.cs $ $Revision: 2 $
* $Author: Jsj $ $Date: 8/23/04 10:12a $
*
* $History: vdb_Set.cs $
*
* ***************** Version 2 *****************
* User: Jsj Date: 8/23/04 Time: 10:12a
* Updated in $/LibSource/VDB
* Fixed replace of single quote
*
* ***************** Version 1 *****************
* User: Kathy Date: 7/27/04 Time: 8:40a
* Created in $/LibSource/VDB
*********************************************************************************************/
using System;
using System.Data;
using System.Text;
using System.Collections.Specialized;
using System.Windows.Forms;
using VDB;
namespace VDB_Set
{
/// <summary>
/// Open, Create, Delete, Update functions for SET files (tables)
/// </summary>
public class vdb_Set:VDB_Base
{
public vdb_Set(String strPath):base(strPath)
{
// if no table (file name) specified, then default to SET (SET.DBF)
if (DBTable.Equals(""))
DBTable = "SET";
}
// Build the SQL command needed to update a row in the SET file
public override string GetRecUpdateStr(DataTable tbl,DataRow row)
{
int j = 0;
bool FirstOne = true;
StringBuilder updateStr = new StringBuilder();
StringBuilder LikeRecID = new StringBuilder();
bool NullEntry = false;
updateStr.Append("UPDATE [");
updateStr.Append(DBTable);
updateStr.Append("] SET");
foreach (DataColumn col in tbl.Columns)
{
bool isString = (col.DataType == Type.GetType("System.String"));
if (col.ColumnName.Equals("ENTRY") && row.ItemArray[j].ToString().Equals(""))
{
NullEntry = true;
j++;
continue;
}
if (col.ColumnName.Equals("RECID"))
{
LikeRecID.Append("___"); // ignore the first 3 positions
LikeRecID.Append(row.ItemArray[j].ToString(),3,5);
}
if (FirstOne)
{
updateStr.Append(" [");
FirstOne = false;
}
else
updateStr.Append(", [");
updateStr.Append(col.ColumnName);
updateStr.Append("]=");
if (row.ItemArray[j].ToString().Equals(""))
{
updateStr.Append("NULL");
}
else if (isString)
{
String tmpstr = row.ItemArray[j].ToString();
updateStr.Append("'");
tmpstr = tmpstr.Replace("'","''");
updateStr.Append(tmpstr);
updateStr.Append("'");
}
else if (col.DataType == Type.GetType("System.DateTime"))
{
int jj;
String tmpstr = row.ItemArray[j].ToString();
updateStr.Append("'");
jj=tmpstr.IndexOf(" ");
if (jj<0) jj = tmpstr.Length;
updateStr.Append(tmpstr.Substring(0,jj));
updateStr.Append("'");
}
j++;
}
if (NullEntry)
{
// So that we can change the RECID number on the first entry
updateStr.Append(" WHERE [ENTRY] IS NULL");
}
else
{
updateStr.Append(" WHERE [RECID] LIKE '");
updateStr.Append(LikeRecID.ToString());
updateStr.Append("' AND [ENTRY] IS NOT NULL");
}
return updateStr.ToString();
}
// Build the SQL command needed to insert a row in the SET file
public override string GetRecInsertStr(DataTable tbl,DataRow row)
{
int j = 0;
StringBuilder insrtStr = new StringBuilder();
StringBuilder valueStr = new StringBuilder();
insrtStr.Append("INSERT INTO [");
insrtStr.Append(DBTable);
insrtStr.Append("] (");
valueStr.Append(" VALUES (");
foreach (DataColumn col in tbl.Columns)
{
bool isString = (col.DataType == Type.GetType("System.String"));
insrtStr.Append("[");
insrtStr.Append(col.ColumnName);
insrtStr.Append("],");
if (row.ItemArray[j].ToString().Equals(""))
{
valueStr.Append("NULL");
}
else if (isString)
{
String tmpstr = row.ItemArray[j].ToString();
tmpstr = tmpstr.Replace("'","''");
valueStr.Append("'");
valueStr.Append(tmpstr);
valueStr.Append("'");
}
else if (col.DataType == Type.GetType("System.DateTime"))
{
int jj;
String tmpstr = row.ItemArray[j].ToString();
valueStr.Append("'");
jj = tmpstr.IndexOf(" ");
if (jj<0) jj=tmpstr.Length;
valueStr.Append(tmpstr.Substring(0,jj));
valueStr.Append("'");
}
else
{
valueStr.Append(row.ItemArray[j].ToString());
}
valueStr.Append(",");
j++;
}
insrtStr = insrtStr.Replace(',',')',insrtStr.Length-1,1);
valueStr = valueStr.Replace(',',')',valueStr.Length-1,1);
insrtStr.Append(valueStr.ToString());
return insrtStr.ToString();
}
// Build the SQL command needed to delete a row in the SET file
public override string RecDeleteStr(DataTable tbl,DataRow row)
{
int j = 0;
String RecIDStr = "";
String NumberStr = "";
StringBuilder deleteStr = new StringBuilder();
deleteStr.Append("DELETE FROM [");
deleteStr.Append(DBTable);
deleteStr.Append("] WHERE ");
row.RejectChanges();
foreach (DataColumn col in tbl.Columns)
{
if (col.ColumnName.Equals("NUMBER"))
{
NumberStr = row.ItemArray[j].ToString();
NumberStr = NumberStr.Replace("'","''");
}
else if (col.ColumnName.Equals("RECID"))
{
RecIDStr = row.ItemArray[j].ToString();
}
j++;
}
deleteStr.Append("[NUMBER] = '");
deleteStr.Append(NumberStr);
deleteStr.Append("' AND [RECID] = '");
deleteStr.Append(RecIDStr);
deleteStr.Append("' AND [ENTRY] IS NOT NULL");
return deleteStr.ToString();
}
// Build a list of SQL commands needed to create a new SET table (file)
// and add the first row
public override StringCollection CreateTableStatements(string strTblName)
{
StringCollection rtnStrColl = new StringCollection();
StringBuilder createStr = new StringBuilder();
// StringBuilder firstRecStr = new StringBuilder();
if (strTblName.Length > 0) // was a table name passd in?
{
DBTable = strTblName;
}
if (DBTable.Equals(""))
{
MessageBox.Show("Trying to Create a new Table without a Name","Create Table Error");
return rtnStrColl;
}
// Build the command that creates a new SET table (file)
createStr.Append("CREATE TABLE [");
createStr.Append(DBTable);
createStr.Append("] ");
createStr.Append("([TITLE] Char(250), [NUMBER] Char(20), [FORMAT] Char(1), ");
createStr.Append("[SUBDIR] Char(1), [ENTRY] Char(30), [RECID] Char(8), ");
createStr.Append("[PROCCODE] Char(1), [DATE] Date, [TIME] Char(5), ");
createStr.Append("INITIALS Char(5), SERIES Char(100))");
// // Build the command that adds the first (blank) record
// // with the RECID initialize to 00000001
// firstRecStr.Append("INSERT INTO [");
// firstRecStr.Append(DBTable);
// firstRecStr.Append("] ([RECID]) VALUES ('00000001')");
rtnStrColl.Add(createStr.ToString()); // add create table
// rtnStrColl.Add(firstRecStr.ToString()); // add inserst first record
return rtnStrColl;
}
// Build a list of SQL commands needed to create the first data row
public override StringCollection CreateFirstRecordStatement(string strTblName)
{
StringCollection rtnStrColl = new StringCollection();
StringBuilder firstRecStr = new StringBuilder();
// Build the command that adds the first (blank) record
// with the RECID initialize to 00000001
firstRecStr.Append("INSERT INTO [");
firstRecStr.Append(DBTable);
firstRecStr.Append("] ([RECID]) VALUES ('00000001')");
rtnStrColl.Add(firstRecStr.ToString()); // add inserst first record
return rtnStrColl;
}
// return a list of SQL commands that will drop (delete) a database table (file)
public override StringCollection DeleteTableStatements(string strTblName)
{
StringCollection rtnStrColl = new StringCollection();
StringBuilder DropTableStr = new StringBuilder();
DropTableStr.Append("Drop Table [");
DropTableStr.Append(DBTable);
DropTableStr.Append("]");
rtnStrColl.Add(DropTableStr.ToString());
return rtnStrColl;
}
}
}

View File

@@ -0,0 +1,255 @@
/*********************************************************************************************
* Copyright 2004 - Volian Enterprises, Inc. All rights reserved.
* Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE
* ------------------------------------------------------------------------------
* $Workfile: vdb_SetExt.cs $ $Revision: 2 $
* $Author: Jsj $ $Date: 8/23/04 10:12a $
*
* $History: vdb_SetExt.cs $
*
* ***************** Version 2 *****************
* User: Jsj Date: 8/23/04 Time: 10:12a
* Updated in $/LibSource/VDB
* Fixed replace of single quote
*
* ***************** Version 1 *****************
* User: Kathy Date: 7/27/04 Time: 8:40a
* Created in $/LibSource/VDB
*********************************************************************************************/
using System;
using System.Data;
using System.Text;
using System.Collections.Specialized;
using System.Windows.Forms;
using VDB;
namespace VDB_SetExt
{
/// <summary>
/// Open, Create, Delete, Update functions for SETEXT files (tables)
/// (set extension)
/// </summary>
public class vdb_SetExt:VDB_Base
{
public vdb_SetExt(String strPath):base(strPath)
{
// if no table (file name) specified, then default to SETEXT (SET.DBF)
if (DBTable.Equals(""))
DBTable = "SETEXT";
}
// Build a SQL statement for selecting the data. The select for the set extension
// datta is much more involved because the date field for the approved date needs
// calculated/formatted.
public override string DefaultSelectCommand()
{
StringBuilder tmp = new StringBuilder();
tmp.Append("select t3.COMMENT, t3.REV, t3.PC, t3.RECID,format(ApprovedDate,'m/d/yyyy hh:nn:ss') ");
tmp.Append(" as ApprovedDate from(select COMMENT, REV, PC, RECID,iif(MyDate=DateValue('1/1/1970'),null,MyDate) ");
tmp.Append(" as ApprovedDate from (select COMMENT, REV, PC, RECID, dateadd(\"S\",(((asc(mid(tdstamp,4,1))*256)+asc(mid(tdstamp,3,1)) )");
tmp.Append("*256+asc(mid(tdstamp,2,1)) )*256+asc(mid(tdstamp,1,1)),datevalue('1/1/1970')) as MyDate ");
tmp.Append(" from (select COMMENT, REV, PC, RECID,iif(isnull(tdstamp),chr(0)+chr(0)+chr(0)+chr(0),left(tdstamp+chr(0)+chr(0)+chr(0)+chr(0),4)) as tdstamp from setext)t1)t2)t3 ");
SelectCmd = tmp.ToString();
return SelectCmd;
}
// Build the SQL command needed to update a row in the SETEXT file
public override string GetRecUpdateStr(DataTable tbl,DataRow row)
{
int j = 0;
StringBuilder updateStr = new StringBuilder();
StringBuilder LikeRecID = new StringBuilder();
updateStr.Append("UPDATE [");
updateStr.Append(DBTable);
updateStr.Append("] SET");
foreach (DataColumn col in tbl.Columns)
{
bool isString = (col.DataType == Type.GetType("System.String"));
if (col.ColumnName.ToUpper().Equals("RECID"))
{
LikeRecID.Append("___"); // ignore the first 3 positions
LikeRecID.Append(row.ItemArray[j].ToString(),3,5);
}
//only comment is updated (at least for initial 32bit veproms
// browser. This may need modified if it is used later
if (col.ColumnName.ToUpper().Equals("COMMENT"))
{
updateStr.Append(" [");
updateStr.Append(col.ColumnName);
updateStr.Append("]=");
if (row.ItemArray[j].ToString().Equals(""))
{
updateStr.Append("NULL");
}
else if (isString)
{
String tmpstr = row.ItemArray[j].ToString();
updateStr.Append("'");
tmpstr = tmpstr.Replace("'","''");
updateStr.Append(tmpstr);
updateStr.Append("'");
}
else
{
updateStr.Append(row.ItemArray[j].ToString());
}
}
j++;
}
updateStr.Append(" WHERE [RECID] LIKE '");
updateStr.Append(LikeRecID.ToString());
updateStr.Append("'");
return updateStr.ToString();
}
// Build the SQL command needed to insert a row in the SET file
public override string GetRecInsertStr(DataTable tbl,DataRow row)
{
int j = 0;
StringBuilder insrtStr = new StringBuilder();
StringBuilder valueStr = new StringBuilder();
insrtStr.Append("INSERT INTO [");
insrtStr.Append(DBTable);
insrtStr.Append("] (");
valueStr.Append(" VALUES (");
foreach (DataColumn col in tbl.Columns)
{
// the select statement was modified to handle the tdstamp field (which
// is a calculated date). This needs to be handled on insert, i.e. the
// fieldname.
bool isString = (col.DataType == Type.GetType("System.String"));
bool isApprovedDate = col.ColumnName.ToUpper().Equals("APPROVEDDATE");
insrtStr.Append("[");
if(!isApprovedDate)
insrtStr.Append(col.ColumnName);
else
insrtStr.Append("TDSTAMP");
insrtStr.Append("],");
if (row.ItemArray[j].ToString().Equals(""))
{
valueStr.Append("NULL");
}
else if (isString)
{
String tmpstr = row.ItemArray[j].ToString();
tmpstr = tmpstr.Replace("'","''");
valueStr.Append("'");
valueStr.Append(tmpstr);
valueStr.Append("'");
}
else
{
valueStr.Append(row.ItemArray[j].ToString());
}
valueStr.Append(",");
j++;
}
insrtStr = insrtStr.Replace(',',')',insrtStr.Length-1,1);
valueStr = valueStr.Replace(',',')',valueStr.Length-1,1);
insrtStr.Append(valueStr.ToString());
return insrtStr.ToString();
}
// Build the SQL command needed to delete a row in the SET file
public override string RecDeleteStr(DataTable tbl,DataRow row)
{
int j = 0;
String RecIDStr = "";
StringBuilder deleteStr = new StringBuilder();
deleteStr.Append("DELETE FROM [");
deleteStr.Append(DBTable);
deleteStr.Append("] WHERE ");
row.RejectChanges();
foreach (DataColumn col in tbl.Columns)
{
if (col.ColumnName.Equals("RECID"))
{
RecIDStr = row.ItemArray[j].ToString();
}
j++;
}
deleteStr.Append("[RECID] = '");
deleteStr.Append(RecIDStr);
deleteStr.Append("'");
return deleteStr.ToString();
}
// Build a list of SQL commands needed to create a new SET table (file)
// and add the first row
public override StringCollection CreateTableStatements(string strTblName)
{
StringCollection rtnStrColl = new StringCollection();
StringBuilder createStr = new StringBuilder();
if (strTblName.Length > 0) // was a table name passd in?
{
DBTable = strTblName;
}
if (DBTable.Equals(""))
{
MessageBox.Show("Trying to Create a new Table without a Name","Create Table Error");
return rtnStrColl;
}
// Build the command that creates a new SET table (file)
createStr.Append("CREATE TABLE [");
createStr.Append(DBTable);
createStr.Append("] ");
createStr.Append("([COMMENT] Char(250), [REV] Char(30), [PC] Char(10), ");
createStr.Append("[RECID] Char(8), [TDSTAMP] Int)");
rtnStrColl.Add(createStr.ToString()); // add create table
return rtnStrColl;
}
// Build a list of SQL commands needed to create the first data row
public override StringCollection CreateFirstRecordStatement(string strTblName)
{
StringCollection rtnStrColl = new StringCollection();
StringBuilder firstRecStr = new StringBuilder();
// Build the command that adds the first (blank) record
// with the RECID initialize to 00000001
firstRecStr.Append("INSERT INTO [");
firstRecStr.Append(DBTable);
firstRecStr.Append("] ([RECID]) VALUES ('00000001')");
rtnStrColl.Add(firstRecStr.ToString()); // add inserst first record
return rtnStrColl;
}
// return a list of SQL commands that will drop (delete) a database table (file)
public override StringCollection DeleteTableStatements(string strTblName)
{
StringCollection rtnStrColl = new StringCollection();
StringBuilder DropTableStr = new StringBuilder();
DropTableStr.Append("Drop Table [");
DropTableStr.Append(DBTable);
DropTableStr.Append("]");
rtnStrColl.Add(DropTableStr.ToString());
return rtnStrColl;
}
}
}

View File

@@ -0,0 +1,495 @@
/*********************************************************************************************
* Copyright 2004 - Volian Enterprises, Inc. All rights reserved.
* Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE
* ------------------------------------------------------------------------------
* $Workfile: vdb_TransUsage.cs $ $Revision: 7 $
* $Author: Kathy $ $Date: 5/01/06 11:17a $
*
* $History: vdb_TransUsage.cs $
*
* ***************** Version 7 *****************
* User: Kathy Date: 5/01/06 Time: 11:17a
* Updated in $/LibSource/VDB
* Fix B2006-018: single quote in proc number causes problem on data
* request
*
* ***************** Version 6 *****************
* User: Kathy Date: 8/16/05 Time: 2:54p
* Updated in $/LibSource/VDB
* B2005-030: error if missing ndx
*
* ***************** Version 5 *****************
* User: Kathy Date: 4/21/05 Time: 10:20a
* Updated in $/LibSource/VDB
* always write inf file
*
* ***************** Version 4 *****************
* User: Kathy Date: 3/08/05 Time: 1:48p
* Updated in $/LibSource/VDB
* Approval
*
* ***************** Version 3 *****************
* User: Jsj Date: 8/30/04 Time: 12:16p
* Updated in $/LibSource/VDB
* upper cased WHERE string did not find mixed cased database items, now
* use the WHERE string as it is passed in.
*
* ***************** Version 2 *****************
* User: Jsj Date: 8/23/04 Time: 10:13a
* Updated in $/LibSource/VDB
* Fixed replace of single quote
*
* ***************** Version 1 *****************
* User: Kathy Date: 7/27/04 Time: 8:40a
* Created in $/LibSource/VDB
*********************************************************************************************/
using System;
using System.Data;
using System.Text;
using System.Collections.Specialized;
using System.IO;
using System.Windows.Forms;
using VDB;
using VDB_ConnType;
namespace VDB_TransUsage
{
/// <summary>
/// Open, Create, Delete, Update functions for Transition Usage files (tables)
/// </summary>
public class vdb_TransUsage:VDB_Base
{
public enum SortTypes {NotSorted,FromSort,ToSort}; // list of sorting types
public string TransFromNDX = "";
public string TransToNDX = "";
public vdb_TransUsage(String strPath):base(strPath)
{
// if no table (file name) specified, then default to TRAN (TRAN.DBF)
if (DBTable.Equals(""))
DBTable = "TRAN";
}
// Build a SQL statement. Optionally sort and filter the select statement.
private void BuildSelectCommand(int SortingType,string WhereStr)
{
StringBuilder tmp = new StringBuilder();
tmp.Append("SELECT [FROMNUMBER],[FROMSEQUEN],[FROMINSTAN],[TYPE],");
tmp.Append("[TONUMBER],[TOSEQUENCE],[TOINSTANCE],[DTI],[OLDTO] FROM [");
tmp.Append(DBTable);
tmp.Append("]");
if (WhereStr.Length > 0) // Was a WHERE clause passed in?
{
// Add " WHERE " to the beginning if it is not already there
string tmpstr = WhereStr.ToUpper();
if (tmpstr[0] != ' ')
{
tmp.Append(" ");
if (!tmpstr.StartsWith("WHERE "))
tmp.Append("WHERE ");
}
else if (!tmpstr.StartsWith(" WHERE "))
tmp.Append(" WHERE");
// add the passed in WHERE clause
// When the WhereStr was upper cased, procedure numbers with mixed and/or lower
// cased letters would not be found. Therefore, use the WhereStr exactly as it
// was sent in.
// tmp.Append(tmpstr);
tmp.Append(WhereStr);
}
switch (SortingType)
{
case 0: //NotSorted
break;
case 1: // FromSort - sorted by FROMNUMBER
tmp.Append(" GROUP BY [FROMNUMBER],[FROMSEQUEN],[FROMINSTAN],[TYPE],");
tmp.Append("[TONUMBER],[TOSEQUENCE],[TOINSTANCE],[DTI],[OLDTO]");
break;
case 2: // Tosort - sorted by TONUMBER
tmp.Append(" GROUP BY [TONUMBER],[TOSEQUENCE],[TOINSTANCE],");
tmp.Append("[FROMNUMBER],[FROMSEQUEN],[FROMINSTAN],[TYPE],[DTI],[OLDTO]");
break;
}
SelectCmd = tmp.ToString();
}
private void BuildNDXFileNames()
{
TransFromNDX = DBTable +"FROM";
TransToNDX = DBTable + "TO";
}
// Build the SQL command needed to update a row in the TRAN file
public override string GetRecUpdateStr(DataTable tbl,DataRow row)
{
int j = 0;
bool FirstOne = true;
StringBuilder updateStr = new StringBuilder();
string strNumber = "";
string strSequence = "";
string strInstance = "";
updateStr.Append("UPDATE [");
updateStr.Append(DBTable);
updateStr.Append("] SET");
foreach (DataColumn col in tbl.Columns)
{
bool isString = (col.DataType == Type.GetType("System.String"));
if (col.ColumnName.Equals("FROMNUMBER"))
{
strNumber = row.ItemArray[j].ToString();
strNumber = strNumber.Replace("'","''");
}
else if (col.ColumnName.Equals("FROMSEQUEN"))
{
strSequence = row.ItemArray[j].ToString();
strSequence = strSequence.Replace("'","''");
}
else if (col.ColumnName.Equals("FROMINSTAN"))
{
strInstance = row.ItemArray[j].ToString();
strInstance = strInstance.Replace("'","''");
}
if (FirstOne)
{
updateStr.Append(" [");
FirstOne = false;
}
else
updateStr.Append(", [");
updateStr.Append(col.ColumnName);
updateStr.Append("]=");
if (row.ItemArray[j].ToString().Equals(""))
{
updateStr.Append("NULL");
}
else if (isString)
{
String tmpstr = row.ItemArray[j].ToString();
updateStr.Append("'");
tmpstr = tmpstr.Replace("'","''");
updateStr.Append(tmpstr);
updateStr.Append("'");
}
j++;
}
// Add the WHERE clause
updateStr.Append(" WHERE [FROMNUMBER] = '");
updateStr.Append(strNumber.ToString());
updateStr.Append("' AND [FROMSEQUEN] = '");
updateStr.Append(strSequence.ToString());
updateStr.Append("' AND [FROMINSTAN] = '");
updateStr.Append(strInstance.ToString());
updateStr.Append("'");
return updateStr.ToString();
}
// Build the SQL command needed to insert a row in the TRAN file
public override string GetRecInsertStr(DataTable tbl,DataRow row)
{
int j = 0;
StringBuilder insrtStr = new StringBuilder();
StringBuilder valueStr = new StringBuilder();
insrtStr.Append("INSERT INTO [");
insrtStr.Append(DBTable);
insrtStr.Append("] (");
valueStr.Append(" VALUES (");
foreach (DataColumn col in tbl.Columns)
{
bool isString = (col.DataType == Type.GetType("System.String"));
insrtStr.Append("[");
insrtStr.Append(col.ColumnName);
insrtStr.Append("],");
if (row.ItemArray[j].ToString().Equals(""))
{
valueStr.Append("NULL");
}
else if (isString)
{
String tmpstr = row.ItemArray[j].ToString();
tmpstr = tmpstr.Replace("'","''");
valueStr.Append("'");
valueStr.Append(tmpstr);
valueStr.Append("'");
}
else
{
valueStr.Append(row.ItemArray[j].ToString());
}
valueStr.Append(",");
j++;
}
insrtStr = insrtStr.Replace(',',')',insrtStr.Length-1,1);
valueStr = valueStr.Replace(',',')',valueStr.Length-1,1);
insrtStr.Append(valueStr.ToString());
return insrtStr.ToString();
}
// Build the SQL command needed to delete a row in the TRAN file
public override string RecDeleteStr(DataTable tbl,DataRow row)
{
int j = 0;
string strNumber = "";
string strSequence = "";
string strInstance = "";
StringBuilder deleteStr = new StringBuilder();
deleteStr.Append("DELETE FROM [");
deleteStr.Append(DBTable);
deleteStr.Append("]");
row.RejectChanges();
foreach (DataColumn col in tbl.Columns)
{
if (col.ColumnName.Equals("FROMNUMBER"))
{
strNumber = row.ItemArray[j].ToString();
strNumber = strNumber.Replace("'","''");
}
else if (col.ColumnName.Equals("FROMSEQUEN"))
{
strSequence = row.ItemArray[j].ToString();
strSequence = strSequence.Replace("'","''");
}
else if (col.ColumnName.Equals("FROMINSTAN"))
{
strInstance = row.ItemArray[j].ToString();
strInstance = strInstance.Replace("'","''");
}
j++;
}
// Add the WHERE clause
deleteStr.Append(" WHERE [FROMNUMBER] = '");
deleteStr.Append(strNumber.ToString());
deleteStr.Append("' AND [FROMSEQUEN] = '");
deleteStr.Append(strSequence.ToString());
deleteStr.Append("' AND [FROMINSTAN] = '");
deleteStr.Append(strInstance.ToString());
deleteStr.Append("'");
return deleteStr.ToString();
}
public override string GetCreateIndx1String()
{
StringBuilder index1Str = new StringBuilder();
index1Str.Append("CREATE INDEX [");
index1Str.Append(TransFromNDX);
index1Str.Append("] ON ");
index1Str.Append(DBTable);
index1Str.Append(".DBF ([FROMNUMBER],[FROMSEQUEN],[FROMINSTAN])");
return (index1Str.ToString());
}
public override string GetCreateIndx2String()
{
StringBuilder index2Str = new StringBuilder();
index2Str.Append("CREATE INDEX [");
index2Str.Append(TransToNDX);
index2Str.Append("] ON ");
index2Str.Append(DBTable);
index2Str.Append(".DBF ([TONUMBER], [TOSEQUENCE])");
return (index2Str.ToString());
}
public override bool IndexFilesExist()
{
if (TransFromNDX==""||TransToNDX=="")BuildNDXFileNames();
if(!File.Exists(DBPath+"\\"+TransFromNDX+".NDX") || !File.Exists(DBPath+"\\"+TransToNDX+".NDX")) return false;
return true;
}
public override void DeleteIndexFiles()
{
if(File.Exists(DBPath+"\\"+TransFromNDX+".NDX")) File.Delete(DBPath+"\\"+TransFromNDX+".NDX");
if(File.Exists(DBPath+"\\"+TransToNDX+".NDX")) File.Delete(DBPath+"\\"+TransToNDX+".NDX");
if(File.Exists(DBPath+"\\"+DBTable+".INF")) File.Delete(DBPath+"\\"+DBTable+".INF");
}
public override StringCollection CreateIndexFilesStatements()
{
if (isdBaseFile())
{
StringCollection rtnStrColl = new StringCollection();
string indx1 = GetCreateIndx1String();
rtnStrColl.Add(indx1);
string indx2 = GetCreateIndx2String();
rtnStrColl.Add(indx2);
return rtnStrColl;
}
return null;
}
// Build a list of SQL commands needed to create a new TRAN table (file)
// and add the first row
public override StringCollection CreateTableStatements(string strTblName)
{
StringCollection rtnStrColl = new StringCollection();
StringBuilder createStr = new StringBuilder();
//StringBuilder index1Str = new StringBuilder();
//StringBuilder index2Str = new StringBuilder();
if (strTblName.Length > 0) // was a table name passd in?
{
DBTable = strTblName;
}
if (DBTable.Equals(""))
{
MessageBox.Show("Trying to Create a new Table without a Name","Create Table Error");
return rtnStrColl;
}
// Build the command that creates a new SET table (file)
createStr.Append("CREATE TABLE [");
createStr.Append(DBTable);
createStr.Append("] ");
createStr.Append("([FROMNUMBER] Char(20), [FROMSEQUEN] Char(12), ");
createStr.Append("[FROMINSTAN] Char(1), [TYPE] Char(1),");
createStr.Append("[TONUMBER] Char(20), [TOSEQUENCE] Char(12), ");
createStr.Append("[TOINSTANCE] Char(2), [DTI] Char(18), [OLDTO] Char(32))");
rtnStrColl.Add(createStr.ToString()); // add create table
if (isdBaseFile())
{
// Build the command that creates the first index file
rtnStrColl.Add(GetCreateIndx1String()); // add create 1st index
// Build the commmand that creates the second index file
//string tmp = DBTable;
rtnStrColl.Add(GetCreateIndx2String()); // add create 2nd index
}
return rtnStrColl;
}
// After the table is created, create the associated INF file
public override int PostCreateTableFunction()
{
CreateINF(); // should already be created
return 0;
}
// This will be called from CreateTableStatements()
// and this is called if the table name is assigned to the DBTable property
public override int CreateINF()
{
// if we are using dBase files, create an INF file containing
// a list of the associated NDX files.
if (isdBaseFile())
{
StreamWriter infFile;
string infFileStr;
StringBuilder tmp = new StringBuilder();
// build the ndx file names (w/o extensions)
BuildNDXFileNames();
//build INF file name
tmp.Append(DBPath);
tmp.Append("\\");
tmp.Append(DBTable);
tmp.Append(".INF");
infFileStr = tmp.ToString();
// if the INF file does not already exist create it
//if (!File.Exists(infFileStr))
//{
// always recreate it. Some plants' data had invalid files
// and it was felt that it would be quicker to recreate always
// rather than
infFile = new StreamWriter(infFileStr,false);
infFile.Write("NDX1=");
infFile.Write(TransFromNDX); // TRANFROM.NDX
infFile.Write(".NDX\r\n");
infFile.Write("NDX2=");
infFile.Write(TransToNDX); //TRANTO.NDX
infFile.Write(".NDX\r\n");
infFile.Close();
//}
}
return 0;
}
// return a list of SQL commands that will drop (delete) a database table (file)
public override StringCollection DeleteTableStatements(string strTblName)
{
StringCollection rtnStrColl = new StringCollection();
StringBuilder DropTableStr = new StringBuilder();
DropTableStr.Append("Drop Table [");
DropTableStr.Append(DBTable);
DropTableStr.Append("]");
rtnStrColl.Add(DropTableStr.ToString());
return rtnStrColl;
}
// return a dataset of Transition Usage records, not sorted
public System.Data.DataSet GetNotSorted(string WhereStr)
{
BuildSelectCommand((int)SortTypes.NotSorted,WhereStr);
return DB_Data;
}
// return a dataset or Transition Usage records, sorted by the [FROMNUMBER] field
public System.Data.DataSet GetSortedByFromTrans(string WhereStr)
{
BuildSelectCommand((int)SortTypes.FromSort,WhereStr);
return DB_Data;
}
// return a dataset or Transition Usage records, sorted by the [TONUMBER] field
public System.Data.DataSet GetSortedByToTrans(string WhereStr)
{
BuildSelectCommand((int)SortTypes.ToSort,WhereStr);
return DB_Data;
}
public void UpdateProcNumber(string oldnum, string newnum)
{
// Change fromnumber first, then tonumber
StringBuilder updateStr = new StringBuilder();
updateStr.Append("UPDATE [");
updateStr.Append(DBTable);
updateStr.Append("] SET [FROMNUMBER] = '");
updateStr.Append(newnum.Replace("'","''"));
updateStr.Append("' WHERE [FROMNUMBER] = '");
updateStr.Append(oldnum.Replace("'","''"));
updateStr.Append("'");
ProcessACommand(updateStr.ToString());
// now to...
updateStr.Remove(0,updateStr.Length);
updateStr.Append("UPDATE [");
updateStr.Append(DBTable);
updateStr.Append("] SET [TONUMBER] = '");
updateStr.Append(newnum.Replace("'","''"));
updateStr.Append("' WHERE [TONUMBER] = '");
updateStr.Append(oldnum.Replace("'","''"));
updateStr.Append("'");
ProcessACommand(updateStr.ToString());
}
}
}