250 lines
5.9 KiB
C#
250 lines
5.9 KiB
C#
/*********************************************************************************************
|
|
* 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;
|
|
}
|
|
}
|
|
|
|
}
|