DataLoader changes during development

This commit is contained in:
2007-11-14 14:49:18 +00:00
parent da9b899424
commit ef81207dbe
28 changed files with 2118 additions and 962 deletions

View File

@@ -13,7 +13,7 @@ using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.OleDb;
using System.Data.OleDb;
using System.Collections.Specialized;
using System.Collections.Generic;
using System.Xml;
@@ -22,64 +22,49 @@ using System.Text;
using Volian.MSWord;
using vlnObjectLibrary;
using vlnServerLibrary;
using Volian.CSLA.Library;
using VEPROMS.CSLA.Library;
using Config;
[assembly: log4net.Config.XmlConfigurator(Watch = true)]
namespace DataLoader
{
public partial class frmLoader : Form
{
private bool _Loading = true;
private FolderTreeNode _topnode;
private bool UseVeTree = false;
#region Log4Net
public static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion
#region ClassProperties
private int wms = 500;
private static int EDDATA = 0x01;
private static int PH = 0x02;
private static int TOC = 0x04;
private static int AUTOIND = 0x08;
private static int AUTOGEN = 0x40;
private static int STP_COMMENT = 0;
private static int STP_MULT_CHGID = 1;
private static int STP_LNK_SEQ = 2;
private static int STP_OVR_TAB = 3;
private string ProcFileName;
private string ProcNumber;
private ROFST rofst;
private int EditSectId;
private Dictionary<string, int> dicLibDocRef;
// have a few variables for storing the database id record & the system record.
private Connection dbConn;
private Folder sysFolder;
FolderTreeNode _topnode;
private Loader ldr;
public bool cbSaveDocChecked { get { return cbSaveDoc.Checked; } }
public bool cbSaveRTFChecked { get { return cbSaveRTF.Checked; } }
public TreeView TV { get { return tv; } }
public int pbProcMaximum { get { return pbProc.Maximum; } set { pbProc.Maximum = value; } }
public int pbSectMaximum { get { return pbSect.Maximum; } set { pbSect.Maximum = value; } }
public int pbSectValue { get { return pbSect.Value; } set { pbSect.Value = value; } }
public int pbStepMaximum { get { return pbStep.Maximum; } set { pbStep.Maximum = value; } }
public int pbStepValue { get { return pbStep.Value; } set { pbStep.Value = value; } }
public int pbProcValue { get { return pbProc.Value; } set { pbProc.Value = value; } }
// the following two dictionaries are used to handle migration of the
// transitions... dicTrans_StrDone gets an entry for procnumber, sequence
// number and the new structure id as a step or section is created (transitions
// can go to steps or sections). When a transition is encountered, check this
// dictionary to see if the step or section was migrated & use the structureid
// for the step or section if it was migrated. When a transition is migrated where
// the 'to' has not been migrated yet, check if an entry exists in dicTrans_StrIds,
// if so, use the id listed here. If no entry exists in dicTrans_StrIds, create
// a structure table record and use the id as part of the 'to', and add an entry to
// dicTrans_StpIds to flag that the record was already created. As migrating sections
// and steps, check this dicTrans_StrIds to see if the structure record has already
// been create, if so use it and remove it from the dicTrans_StrIds dictionary,
// otherwise, create a new structure record.
private Dictionary<string, int> dicTrans_StrDone;
private Dictionary<string, int> dicTrans_StrIds;
private Dictionary<object, string> dicOldStepSequence;
private Dictionary<TreeNode, TreeNode> dicNeedToLoad;
private bool UseVeTree = false;
#endregion
public frmLoader()
public string Status
{
get { return toolStripStatusLabel1.Text; }
set
{
toolStripStatusLabel1.Text = value;
Application.DoEvents();
}
}
public string tbSourceText { get { return tbSource.Text; } set { tbSource.Text = value; } }
public frmLoader()
{
ldr = new Loader(log, this);
InitializeComponent();
lblTime.Tag = DateTime.Now;
switch (SystemInformation.ComputerName.ToUpper())
@@ -88,7 +73,7 @@ namespace DataLoader
//tbSource.Text = "G:\\VEIP2\\PROCS"; // basic data
//tbSource.Text = "G:\\VEFNP\\AOP1.PRC"; // test subsections, checkoffs, comments & continuous action flag
//tbSource.Text = "G:\\vecal\\eops.bck"; // test link seq STP_LNK_SEQ
tbSource.Text = "G:\\vehlp\\procs";// multiple change ids.
tbSource.Text = "G:\\vewcnckl\\ckl.prc";// multiple change ids.
break;
case "RHMDESKTOP":
//tbSource.Text = @"I:\UNZIPPED ACTIVE BASELINE DATA\vehlp\Procs"; // Sub-sections
@@ -97,7 +82,6 @@ namespace DataLoader
default:
throw new Exception("Not configured for " + SystemInformation.ComputerName);
}
dicNeedToLoad = new Dictionary<TreeNode, TreeNode>();
}
private void btnConvertSelected_Click(object sender, EventArgs e)
{
@@ -110,23 +94,18 @@ namespace DataLoader
return;
}
object o = tn.VEObject;
//object o = tn.Tag;
if (o.GetType() != typeof(DocVersionInfo))
{
MessageBox.Show("Must select a version node (working draft, approved, etc)", "No Node Selected");
return;
}
DocVersion v = ((DocVersionInfo)o).Get();
int istr = MigrateDocVersion(v.Title);
if (istr > 0)
Item itm = ldr.MigrateDocVersion(v);
if (itm != null)
{
v.StructureID = istr;
v.Title = "";
v.Save(true); // true forces save.
tn.Checked = true;
//TODO: Walk up structure and set check boxes appropriately.
tn.Checked = true;
}
}
else
{
@@ -143,15 +122,10 @@ namespace DataLoader
return;
}
DocVersion v = (DocVersion)o;
int istr = MigrateDocVersion(v.Title);
if (istr > 0)
Item itm = ldr.MigrateDocVersion(v);
if (itm != null)
{
v.StructureID = istr;
v.Title = "";
v.Save(true); // true forces save.
tn.Checked = true;
//TODO: Walk up structure and set check boxes appropriately.
}
}
}
@@ -169,8 +143,8 @@ namespace DataLoader
{
case "Volian.CSLA.Library.FolderInfo":
FolderInfo fld = (FolderInfo)o;
if (fld.DocVersionCount>0)
tn.Checked = LoadChildren(fld, tn); // load docversions.
if (fld.ChildFolderCount>0)
tn.Checked = ldr.LoadChildren(fld, tn); // load docversions.
break;
default:
break;
@@ -186,61 +160,44 @@ namespace DataLoader
if (o.GetType() == typeof(DocVersion)) tbSource.Text = ((DocVersion)o).Title;
}
private bool LoadFolders()
{
try
{
// make the initial database connection record
dbConn = Connection.MakeConnection("Default", "Default", "Data Source=.\\SQLEXPRESS;Initial Catalog=VEPROMS;Integrated Security=True", 1, null);
ConfigFile cfg = new ConfigFile();
XmlDocument d = cfg.LoadSystemIni();
sysFolder = Folder.MakeFolder(0, dbConn.DBID, "system", "system", d.InnerXml);
// This is to test the vln Libraries
List<Folder> lfldr = vlnDataPathFolders();
List<vlnObject> dp2 = new List<vlnObject>();
foreach (Folder fldr in lfldr)
{
TreeNode tn = tv.Nodes.Add(fldr.Name);
tn.Tag = fldr;
vlnObject vb = new vlnObject(null, "datapath", fldr.Name, fldr.Title);
dp2.Add(vb);
vlnServer vs = new vlnServer();
MigrateChildren(vb, vs, fldr.DBID, fldr.FolderID, tn);
tn.Expand();
}
}
catch (Exception ex)
{
log.ErrorFormat("Could not load data, error = {0}", ex.Message);
return false;
}
return true;
}
private void btnLoadTreeDB_Click(object sender, EventArgs e)
{
// When loading folders, i.e. the tree from dBase (old 16-bit)
// always clear the data
ClearData();
bool suc = LoadFolders();
ldr.ClearData();
bool suc = ldr.LoadFolders();
}
private void btnConvert_Click(object sender, System.EventArgs e)
{
Database.LoggingInfo = false;
bool success = true;
// if purge data, purge it all & reload folders & security.
if (cbPurgeData.Checked)
{
ClearData();
success=LoadFolders();
if (success)success=LoadSecurity();
ldr.ClearData();
success=ldr.LoadFolders();
if (success) success = ldr.LoadSecurity(tbVesamPath.Text);
}
if (success)
{
DateTime tstart = DateTime.Now;
DocVersionInfoList vl = DocVersionInfoList.Get();
DocVersion v = null;
foreach (DocVersionInfo vi in vl)
{
if (vi.Title.ToUpper() == tbSource.Text.ToUpper())
{
v = DocVersion.Get(vi.VersionID);
Database.LogInfoFormat("Before MigrateDocVersion");
Item itm = ldr.MigrateDocVersion(v);
}
}
MessageBox.Show(string.Format("{0} seconds",TimeSpan.FromTicks(DateTime.Now.Ticks-tstart.Ticks).TotalSeconds));
}
if (success) MigrateDocVersion(tbSource.Text);
}
private void UpdateLabels(int incPrc, int incSec, int incStp)
public void UpdateLabels(int incPrc, int incSec, int incStp)
{
if (incPrc == 0 && incSec == 0 && incStp == 0)//Reset
{
@@ -262,6 +219,7 @@ namespace DataLoader
log.ErrorFormat("{0}\r\n\r\n{1}", ex.Message, ex.InnerException);
}
}
//Database.LoggingInfo = (pbProc.Value > 153 && pbSect.Value > 11 && pbStep.Value > 61);
lblProc.Text = string.Format("{0} Procedures", pbProc.Value);
lblSection.Text = string.Format("{0} Sections", pbSect.Value);
lblStep.Text = string.Format("{0} Steps", pbStep.Value);
@@ -286,89 +244,8 @@ namespace DataLoader
{
if (cbSaveDoc.Checked) cbSaveRTF.Checked = false;
}
private void Wait(int n)
{
DateTime dtw = DateTime.Now.AddSeconds(n);
while (DateTime.Now < dtw)
{
Application.DoEvents();
}
}
private void WaitMS(int n)
{
DateTime dtw = DateTime.Now.AddMilliseconds(n);
while (DateTime.Now < dtw)
{
Application.DoEvents();
}
}
private void ClearData()
{
Database.PurgeData();
}
public static string MakeDate(string src)
{
if (src.Trim() == "") return null;
int[] DateOffset ={ 4, 5, 47, 6, 7, 47, 0, 1, 2, 3 }; // 47 = '/'
StringBuilder datebuff = new StringBuilder(10);
for (int i = 0; i < DateOffset.Length; i++)
{
if (DateOffset[i] < 9)
datebuff.Append(src[DateOffset[i]]);
else
datebuff.Append(System.Convert.ToChar(DateOffset[i]));
}
return datebuff.ToString();
}
private DateTime GetDTS(string date, string time)
{
// Set the date/time stamp. If there is no 'date', set the date
// to 1/1/2000 (this can be changed!). If there is not 'time',
// set the time to 0:0:0 (midnight).
DateTime dts = DateTime.Now;
string month = "01";
string day = "01";
string year = "2000";
string hour = "";
string minute = "";
try
{
if (date != null && date != "")
{
int indx1 = date.IndexOf("/");
month = date.Substring(0, indx1);
int indx2 = date.IndexOf("/", indx1 + 1);
day = date.Substring(indx1 + 1, indx2 - indx1 - 1);
year = date.Substring(indx2 + 1, 4);
}
if (time == null || time == "")
{
hour = "0";
minute = "0";
}
else
{
hour = time.Substring(0, 2);
int indxc = time.IndexOfAny(":A-".ToCharArray());
if (indxc == time.Length - 1)
minute = time.Substring(2, 2);
else
minute = time.Substring(indxc + 1, time.Length - indxc - 1);
}
dts = new DateTime(System.Convert.ToInt32(year), System.Convert.ToInt32(month), System.Convert.ToInt32(day),
System.Convert.ToInt32(hour), System.Convert.ToInt32(minute), 0);
}
catch (Exception ex)
{
log.ErrorFormat("DATE/TIME {0} {1}", date, time);
log.ErrorFormat("{0}\r\n\r\n{1}", ex.Message, ex.InnerException);
log.ErrorFormat(ex.StackTrace);
return dts;
}
return dts;
}
private void btnLoadTreeCSLA_Click(object sender, EventArgs e)
{
_topnode = FolderTreeNode.BuildTreeList();
@@ -384,26 +261,21 @@ namespace DataLoader
tbVesamPath.Text = fbd.SelectedPath;
}
private bool LoadSecurity()
{
Security sec = new Security(tbVesamPath.Text);
return sec.Migrate();
}
private void btnVesam_Click(object sender, EventArgs e)
{
// if purge data, purge it all & reload folders.
if (cbPurgeData.Checked)
{
ClearData();
LoadFolders();
ldr.ClearData();
ldr.LoadFolders();
}
bool sec = LoadSecurity();
bool sec = ldr.LoadSecurity(tbVesamPath.Text);
}
private void btnVETree_CSLA_Click(object sender, EventArgs e)
{
tv.Nodes.Add(VEFolder.LoadTree());
tv.Nodes.Add(VETreeNode.GetFolder(1));
UseVeTree = true;
}
@@ -412,5 +284,69 @@ namespace DataLoader
GroupProp f = new GroupProp();
f.ShowDialog();
}
private void tbSource_TextChanged(object sender, EventArgs e)
{
}
private void btnCtTok_Click(object sender, EventArgs e)
{
frmCntTkn frm = new frmCntTkn();
frm.ShowDialog();
}
public void UpdateLabelsSetProc(int prc)
{
pbProc.Maximum = prc;
}
public void UpdateLabelsSetSect(int sec)
{
pbSect.Maximum = sec;
}
public void UpdateLabelsLibDocs(int incLib, int incUsages)
{
if (incLib == 0 && incUsages == 0)//Reset
{
lblTime.Tag = DateTime.Now;
pbProc.Value = 0;
pbSect.Value = 0;
}
else
{
pbProc.Value += incLib;
pbSect.Value += incUsages;
}
lblProc.Text = string.Format("{0} Lib Docs", pbProc.Value);
lblSection.Text = string.Format("{0} Usages", pbSect.Value);
lblStep.Text = "";
TimeSpan ts = new TimeSpan(DateTime.Now.Ticks - ((DateTime)lblTime.Tag).Ticks);
lblTime.Text = string.Format("{0:D2}:{1:D2}:{2:D2} Elapsed", ts.Hours, ts.Minutes, ts.Seconds);
Application.DoEvents();
}
private void frmLoader_Load(object sender, EventArgs e)
{
if (Properties.Settings.Default["VeSamFilename"] != null)
this.tbVesamPath.Text = Properties.Settings.Default.VeSamFilename;
if (Properties.Settings.Default["DbfPathname"] != null)
this.tbSource.Text = Properties.Settings.Default.DbfPathname;
if (Properties.Settings.Default["LoadWordDoc"] != null)
this.cbSaveDoc.CheckState = Properties.Settings.Default.LoadWordDoc;
if (Properties.Settings.Default["PurgeData"] != null)
this.cbPurgeData.CheckState = Properties.Settings.Default.PurgeData;
if (Properties.Settings.Default["LoadRTFDoc"] != null)
this.cbSaveRTF.CheckState = Properties.Settings.Default.LoadRTFDoc;
_Loading = false;
}
private void frmLoader_FormClosing(object sender, FormClosingEventArgs e)
{
Properties.Settings.Default.VeSamFilename = tbVesamPath.Text;
Properties.Settings.Default.DbfPathname = tbSource.Text;
Properties.Settings.Default.LoadWordDoc = cbSaveDoc.CheckState;
Properties.Settings.Default.LoadRTFDoc = cbSaveRTF.CheckState;
Properties.Settings.Default.PurgeData = cbPurgeData.CheckState;
Properties.Settings.Default.Save();
}
}
}