416 lines
14 KiB
C#
416 lines
14 KiB
C#
// ========================================================================
|
|
// Copyright 2006 - Volian Enterprises, Inc. All rights reserved.
|
|
// Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE
|
|
// ------------------------------------------------------------------------
|
|
// $Workfile: $ $Revision: $
|
|
// $Author: $ $Date: $
|
|
//
|
|
// $History: $
|
|
// ========================================================================
|
|
using System;
|
|
using System.Drawing;
|
|
using System.Collections;
|
|
using System.ComponentModel;
|
|
using System.Windows.Forms;
|
|
using System.Data;
|
|
using System.Data.OleDb;
|
|
using System.Collections.Specialized;
|
|
using System.Collections.Generic;
|
|
using System.Xml;
|
|
using System.IO;
|
|
using System.Text;
|
|
using Volian.MSWord;
|
|
using vlnObjectLibrary;
|
|
using vlnServerLibrary;
|
|
using Volian.CSLA.Library;
|
|
using Config;
|
|
|
|
[assembly: log4net.Config.XmlConfigurator(Watch = true)]
|
|
|
|
namespace DataLoader
|
|
{
|
|
public partial class frmLoader : Form
|
|
{
|
|
|
|
#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;
|
|
|
|
// 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()
|
|
{
|
|
InitializeComponent();
|
|
lblTime.Tag = DateTime.Now;
|
|
switch (SystemInformation.ComputerName.ToUpper())
|
|
{
|
|
case "KATHYXP":
|
|
//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.
|
|
break;
|
|
case "RHMDESKTOP":
|
|
//tbSource.Text = @"I:\UNZIPPED ACTIVE BASELINE DATA\vehlp\Procs"; // Sub-sections
|
|
tbSource.Text = @"I:\veDATA\vehlp\Procs"; // Sub-sections
|
|
break;
|
|
default:
|
|
throw new Exception("Not configured for " + SystemInformation.ComputerName);
|
|
}
|
|
dicNeedToLoad = new Dictionary<TreeNode, TreeNode>();
|
|
}
|
|
private void btnConvertSelected_Click(object sender, EventArgs e)
|
|
{
|
|
if (UseVeTree)
|
|
{
|
|
VETreeNode tn = (VETreeNode)tv.SelectedNode;
|
|
if (tn == null)
|
|
{
|
|
MessageBox.Show("Must select a version node (working draft, approved, etc)", "No Node Selected");
|
|
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)
|
|
{
|
|
|
|
v.StructureID = istr;
|
|
v.Title = "";
|
|
v.Save(true); // true forces save.
|
|
tn.Checked = true;
|
|
//TODO: Walk up structure and set check boxes appropriately.
|
|
}
|
|
}
|
|
else
|
|
{
|
|
TreeNode tn = tv.SelectedNode;
|
|
if (tn == null)
|
|
{
|
|
MessageBox.Show("Must select a version node (working draft, approved, etc)", "No Node Selected");
|
|
return;
|
|
}
|
|
object o = tn.Tag;
|
|
if (o.GetType() != typeof(DocVersion))
|
|
{
|
|
MessageBox.Show("Must select a version node (working draft, approved, etc)", "No Node Selected");
|
|
return;
|
|
}
|
|
DocVersion v = (DocVersion)o;
|
|
int istr = MigrateDocVersion(v.Title);
|
|
if (istr > 0)
|
|
{
|
|
|
|
v.StructureID = istr;
|
|
v.Title = "";
|
|
v.Save(true); // true forces save.
|
|
tn.Checked = true;
|
|
//TODO: Walk up structure and set check boxes appropriately.
|
|
}
|
|
}
|
|
}
|
|
private void tv_BeforeExpand(object sender, TreeViewCancelEventArgs e)
|
|
{
|
|
if (UseVeTree)
|
|
{
|
|
((VETreeNode)e.Node).LoadChildren();
|
|
return;
|
|
}
|
|
|
|
TreeNode tn = e.Node;
|
|
object o = tn.Tag;
|
|
switch (o.GetType().ToString())
|
|
{
|
|
case "Volian.CSLA.Library.FolderInfo":
|
|
FolderInfo fld = (FolderInfo)o;
|
|
if (fld.DocVersionCount>0)
|
|
tn.Checked = LoadChildren(fld, tn); // load docversions.
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
private void tv_AfterSelect(object sender, TreeViewEventArgs e)
|
|
{
|
|
if (UseVeTree) return;
|
|
|
|
TreeNode tn = e.Node;
|
|
object o = tn.Tag;
|
|
tn.Expand();
|
|
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();
|
|
}
|
|
|
|
private void btnConvert_Click(object sender, System.EventArgs e)
|
|
{
|
|
bool success = true;
|
|
// if purge data, purge it all & reload folders & security.
|
|
if (cbPurgeData.Checked)
|
|
{
|
|
ClearData();
|
|
success=LoadFolders();
|
|
if (success)success=LoadSecurity();
|
|
}
|
|
if (success) MigrateDocVersion(tbSource.Text);
|
|
}
|
|
private void UpdateLabels(int incPrc, int incSec, int incStp)
|
|
{
|
|
if (incPrc == 0 && incSec == 0 && incStp == 0)//Reset
|
|
{
|
|
lblTime.Tag = DateTime.Now;
|
|
pbProc.Value = 0;
|
|
pbSect.Value = 0;
|
|
pbStep.Value = 0;
|
|
}
|
|
else
|
|
{
|
|
try
|
|
{
|
|
pbProc.Value += incPrc;
|
|
pbSect.Value += incSec;
|
|
pbStep.Value += incStp;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
log.ErrorFormat("{0}\r\n\r\n{1}", ex.Message, ex.InnerException);
|
|
}
|
|
}
|
|
lblProc.Text = string.Format("{0} Procedures", pbProc.Value);
|
|
lblSection.Text = string.Format("{0} Sections", pbSect.Value);
|
|
lblStep.Text = string.Format("{0} Steps", pbStep.Value);
|
|
//pbProc.Value = iPrc;
|
|
//pbSect.Value = iSec;
|
|
//pbStep.Value = iStp;
|
|
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 btnBrowse_Click(object sender, EventArgs e)
|
|
{
|
|
fbd.SelectedPath = tbSource.Text;
|
|
if (fbd.ShowDialog() == DialogResult.OK)
|
|
tbSource.Text = fbd.SelectedPath;
|
|
}
|
|
private void cbSaveRTF_Click(object sender, EventArgs e)
|
|
{
|
|
if (cbSaveRTF.Checked) cbSaveDoc.Checked = false;
|
|
}
|
|
private void cbSaveDoc_Click(object sender, EventArgs e)
|
|
{
|
|
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();
|
|
tv.Nodes.Add(_topnode);
|
|
tv.Nodes[0].Expand();
|
|
UseVeTree = false;
|
|
}
|
|
|
|
private void btnBrowseVesam_Click(object sender, EventArgs e)
|
|
{
|
|
fbd.SelectedPath = tbVesamPath.Text;
|
|
if (fbd.ShowDialog() == DialogResult.OK)
|
|
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();
|
|
}
|
|
bool sec = LoadSecurity();
|
|
}
|
|
|
|
private void btnVETree_CSLA_Click(object sender, EventArgs e)
|
|
{
|
|
tv.Nodes.Add(VEFolder.LoadTree());
|
|
UseVeTree = true;
|
|
}
|
|
|
|
private void btnGroup_Click(object sender, EventArgs e)
|
|
{
|
|
GroupProp f = new GroupProp();
|
|
f.ShowDialog();
|
|
}
|
|
}
|
|
} |