diff --git a/PROMS/DataLoader/Applicability.cs b/PROMS/DataLoader/Applicability.cs new file mode 100644 index 00000000..ebdcf239 --- /dev/null +++ b/PROMS/DataLoader/Applicability.cs @@ -0,0 +1,65 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.IO; + +namespace DataLoader +{ + public partial class Loader + { + public bool BuildScopeApplicability() + { + bool rv = false; + //get scopes from proc.ini + rv |= CreateScopes(); + //end get scopes from proc.ini + //get apl dictionary + Dictionary> procAPLs = new Dictionary>(); + string[] procs = Directory.GetFiles(frmMain.MySettings.ProcedureSetPath, "PROC*.APL"); + foreach (string proc in procs) + { + Dictionary procAPL = new Dictionary(); + FileInfo myFile = new FileInfo(proc); + FileStream fs = myFile.OpenRead(); + BinaryReader br = new BinaryReader(fs); + byte[] myBuff = new byte[myFile.Length]; + br.Read(myBuff, 0, (int)myFile.Length); + br.Close(); + fs.Close(); + int offset = 0; + while (offset < myBuff.Length) + { + string recnum = Encoding.Default.GetString(myBuff, offset, 8); + int applicability = BitConverter.ToInt32(myBuff, offset + 8); + string applicabilityToStr = string.Format("{0:X8}", applicability); + //4294967296 + if (!procAPL.ContainsKey(recnum)) + procAPL.Add(recnum, applicabilityToStr); + else + if (procAPL[recnum] != applicabilityToStr) + procAPL[recnum] = applicabilityToStr; + offset += 12; + } + procAPLs.Add(proc, procAPL); + } + //end get apl dictionary + rv = true; + return rv; + } + + private bool CreateScopes() + { + string iniFile = string.Format(@"{0}\PROC.ini", frmMain.MySettings.ProcedureSetPath); + TextReader tr = File.OpenText(iniFile); + string line = string.Empty; + while (!line.StartsWith("Name=")) + line = tr.ReadLine(); + tr.Close(); + string[] parts = line.Split('='); + string[] scopes = parts[1].Split(','); + foreach (string scope in scopes) + Console.WriteLine(scope); + return true; + } + } +} diff --git a/PROMS/DataLoader/Approve.cs b/PROMS/DataLoader/Approve.cs new file mode 100644 index 00000000..a1e03b36 --- /dev/null +++ b/PROMS/DataLoader/Approve.cs @@ -0,0 +1,378 @@ +//using System; +using System.Collections.Generic; +using System.Text; +using VEPROMS.CSLA.Library; +using System.IO; +using System.Data.OleDb; +using System.Data; + +namespace DataLoader +{ + public partial class Loader + { + public bool BuildApprovedRevision() + { + frmMain.RunScript("PROMSApproveApprove.sql", frmMain.MySettings.DBName); + bool rv = false; + using (Stage myStage = GetApprovedStage()) + { + if (myStage == null) + return rv; + DocVersionInfoList dvil = DocVersionInfoList.Get(); + foreach (DocVersionInfo dvi in dvil) + { + if (dvi.Procedures.Count > 0) + { + string approvedFolder = dvi.MyFolder.Title + @"\APPROVED"; + if (Directory.Exists(approvedFolder)) + { + if (frmMain.MySettings.OnlyThisSet) + { + if (frmMain.MySettings.ProcedureSetPath.ToUpper() == dvi.MyFolder.Title.ToUpper()) + rv |= BuildApprovedRevision(myStage, approvedFolder, dvi); + } + else + rv |= BuildApprovedRevision(myStage, approvedFolder, dvi); + } + } + } + } + return rv; + } + + private static Stage GetApprovedStage() + { + StageInfoList sil = StageInfoList.Get(); + foreach (StageInfo si in sil) + { + if (si.Name.ToUpper() == "APPROVED") + return si.Get(); + } + return null; + } + private bool BuildApprovedRevision(Stage myStage, string approvedFolder, DocVersionInfo dvi) + { + bool rv = false; + ApprovedFolder af = new ApprovedFolder(approvedFolder); + foreach (ProcedureInfo pi in dvi.Procedures) + { + rv |= BuildApprovedRevision(myStage, af, pi); + } + return rv; + } + private bool BuildApprovedRevision(Stage myStage, ApprovedFolder af, ProcedureInfo pi) + { + bool rv = false; + frmMain.MyInfo = string.Format("Loading approved data for Procedure: {0}", pi.DisplayNumber); + using (Revision revision = CreateRevision(af, pi)) + { + System.DateTime dts = pi.DTS; + string userID = af.EntryFromProc[pi.DisplayNumber].UserID; + using (Version version = Version.MakeVersion(revision, myStage, GetPDF(af,pi), GetSummaryPDF(), dts, userID)) + { + using (Check check = Check.MakeCheck(revision, myStage, af.BuildConsistencyChecks(pi))) + { + rv |= true; + } + } + } + if(!rv) + frmMain.MyInfo = string.Format("Loading Procedure: {0} FAILED MISERABLY", pi.DisplayNumber); + return rv; + } + private byte[] GetSummaryPDF() + { + return null; + } + private byte[] GetPDF(ApprovedFolder af, ProcedureInfo pi) + { + string pdf = string.Format(@"{0}\PDFS\{1}.pdf", af.Path, pi.DisplayNumber); + FileInfo pdfFile = new FileInfo(pdf); + if (pdfFile.Exists) + { + FileStream fs = pdfFile.Open(FileMode.Open, FileAccess.Read, FileShare.ReadWrite); + byte[] pdfBuf = new byte[pdfFile.Length]; + fs.Read(pdfBuf, 0, pdfBuf.Length); + fs.Close(); + return pdfBuf; + } + return null; + } + private Revision CreateRevision(ApprovedFolder af, ProcedureInfo pi) + { + int typeID = 1; //revision not tempmod + ProcInfo pinf = af.EntryFromProc[pi.DisplayNumber]; + string revisionNumber = pinf.Rev; + System.DateTime revisionDate = System.DateTime.Parse(pinf.RevDate ?? "1/1/1980"); + string notes = "Migration Of Current Approved Revision"; + string config = string.Empty; + System.DateTime dts = pi.DTS; + string userID = pinf.UserID; + return Revision.MakeRevision(pi.ItemID, typeID, revisionNumber, revisionDate, notes, config, dts, userID); + } + } + public partial class ApprovedFolder + { + private OleDbConnection _Connection; + public OleDbConnection Connection + { + get + { + if(_Connection == null) + _Connection = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + _Path + ";Extended Properties=dBase III;Persist Security Info=False"); + return _Connection; + } + } + private string _Path; + public string Path + { + get { return _Path; } + set { _Path = value; } + } + private System.DateTime _ROFstDate = System.DateTime.MinValue; + public System.DateTime ROFstDate + { + get + { + if (_ROFstDate == System.DateTime.MinValue) + { + FileInfo fi = new FileInfo(string.Format(@"{0}\ro.fst",Path)); + if(fi.Exists) + _ROFstDate = fi.LastWriteTimeUtc; + } + return _ROFstDate; + } + } + + private Dictionary _ROValues = new Dictionary(); + private Dictionary _LibDocDates = new Dictionary(); + private Dictionary> _ProcROs = new Dictionary>(); + private Dictionary> _LibROs = new Dictionary>(); + private Dictionary> _LibDocs = new Dictionary>(); + + public string BuildConsistencyChecks(ProcedureInfo proc) + { + /* + + + + + + + + + */ + ConsistencyChecks cc = new ConsistencyChecks(); + cc.ItemID = proc.ItemID; + BuildROChecks(cc, proc); + BuildLibDocChecks(cc, proc); + return cc.ToString().Replace("OldDocDate=\"0001-01-01T00:00:00\"", ""); + } + + private void BuildLibDocChecks(ConsistencyChecks cc, ProcedureInfo proc) + { + if (_LibDocs.ContainsKey(proc.DisplayNumber)) + { + foreach (string libdoc in _LibDocs[proc.DisplayNumber]) + { + FileInfo fi = new FileInfo(string.Format(@"{0}\RTFFILES\{1}.LIB",Path,libdoc)); + if (fi.Exists) + { + //if (proc.MyDocVersion.VersionID > 1) + // System.Threading.Thread.Sleep(5000); + int docid = GetDocID(libdoc, proc.MyDocVersion.VersionID); + if (docid > 0) + cc.LibDocConsistency.AddLibDocCheck(docid, fi.LastWriteTimeUtc); + } + } + } + } + + private int GetDocID(string libdoc, int versionid) + { + DocumentInfo di = DocumentInfo.GetByLibDocName(libdoc, versionid); + return di.DocID; + } + + private void BuildROChecks(ConsistencyChecks cc, ProcedureInfo proc) + { + cc.ROConsistency.ROFstDate = ROFstDate; + if (_ProcROs.ContainsKey(proc.DisplayNumber)) + { + foreach (string roid in _ProcROs[proc.DisplayNumber]) + cc.ROConsistency.AddROCheck(FormatROID(roid), GetROValue(FormatROID(roid))); + } + //int cnt = cc.ROConsistency.MyROChecks.Length; + if (_LibDocs.ContainsKey(proc.DisplayNumber)) + { + foreach (string libdoc in _LibDocs[proc.DisplayNumber]) + { + if (_LibROs.ContainsKey(libdoc)) + { + foreach (string roid in _LibROs[libdoc]) + cc.ROConsistency.AddROCheck(FormatROID(roid), GetROValue(FormatROID(roid))); + } + } + } + } + + private string GetROValue(string roid) + { + if (!_ROValues.ContainsKey(roid)) + { + //if (roid.Contains("000128")) + // System.Console.WriteLine(); + //string ss = _Lookup.GetRoValue(roid); + //ss = ItemInfo.ConvertToDisplayText(ss); + //ss = ss.Replace('\n', ';'); + + _ROValues.Add(roid, ItemInfo.ConvertToDisplayText(_Lookup.GetRoValue(roid))); + } + return _ROValues[roid]; + } + private string FormatROID(string roid) + { + if (roid.Length == 16 && roid.EndsWith("0000")) + return roid.Substring(0, 12).ToUpper(); + return roid.ToUpper(); + } + + private Dictionary _EntryFromProc; + public Dictionary EntryFromProc + { + get + { + if (_EntryFromProc == null) + _EntryFromProc = FillEntryFromProc(); + return _EntryFromProc; + } + } + private Dictionary FillEntryFromProc() + { + Dictionary rv = new Dictionary(); + using (OleDbDataAdapter da = new OleDbDataAdapter("Select * from [set] where entry is not null", Connection)) + { + using (DataSet ds = new DataSet()) + { + da.Fill(ds); + foreach (DataRow dr in ds.Tables[0].Rows) + if (!rv.ContainsKey(dr["NUMBER"].ToString())) + rv.Add(dr["NUMBER"].ToString(), new ProcInfo(dr, Path)); + } + } + return rv; + } + private ROFSTLookup _Lookup; + public ApprovedFolder(string path) + { + _Path = path; + FillROs(); + FillLibDocs(); + _Lookup = new ROFSTLookup(string.Format(@"{0}\RO.FST", Path)); + } + + private void FillLibDocs() + { + using (OleDbDataAdapter da = new OleDbDataAdapter("Select distinct FROMNUMBER, TONUMBER from [tran] where tonumber like 'DOC%'", Connection)) + { + using (DataSet ds = new DataSet()) + { + da.Fill(ds); + foreach (DataRow dr in ds.Tables[0].Rows) + { + string number = dr["FROMNUMBER"].ToString(); + string libdoc = dr["TONUMBER"].ToString(); + if (!_LibDocs.ContainsKey(number)) + _LibDocs.Add(number, new List()); + if (!_LibDocs[number].Contains(libdoc)) + _LibDocs[number].Add(libdoc); + } + } + } + } + + private void FillROs() + { + using (OleDbDataAdapter da = new OleDbDataAdapter("Select distinct NUMBER, ROID from [usagero]", Connection)) + { + using (DataSet ds = new DataSet()) + { + da.Fill(ds); + foreach (DataRow dr in ds.Tables[0].Rows) + { + string number = dr["NUMBER"].ToString(); + string roid = dr["ROID"].ToString(); + if (number.StartsWith("DOC")) + { + if (!_LibROs.ContainsKey(number)) + _LibROs.Add(number, new List()); + if (!_LibROs[number].Contains(roid)) + _LibROs[number].Add(roid); + } + else + { + if (!_ProcROs.ContainsKey(number)) + _ProcROs.Add(number, new List()); + if (!_ProcROs[number].Contains(roid)) + _ProcROs[number].Add(roid); + } + } + } + } + } + } + public partial class ProcInfo + { + private string _Number; + public string Number + { + get { return _Number; } + set { _Number = value; } + } + private string _Entry; + public string Entry + { + get { return _Entry; } + set { _Entry = value; } + } + private string _UserID; + public string UserID + { + get { return _UserID; } + set { _UserID = value; } + } + private string _Rev; + public string Rev + { + get { return _Rev; } + set { _Rev = value; } + } + private string _RevDate; + public string RevDate + { + get { return _RevDate; } + set { _RevDate = value; } + } + private string _ReviewDate; + public string ReviewDate + { + get { return _ReviewDate; } + set { _ReviewDate = value; } + } + public ProcInfo(DataRow dr, string afpath) + { + Number = dr["NUMBER"].ToString(); + Entry = dr["ENTRY"].ToString(); + UserID = dr["INITIALS"].ToString(); + if (UserID == string.Empty) UserID = "UNKNOWN"; + FixItems fis = new FixItems(new FileInfo(string.Format(@"{0}\{1}.fix", afpath, Entry))); + if (fis.Count > 0) + { + Rev = fis[0].Rev; + RevDate = fis[0].RevDate; + ReviewDate = fis[0].ReviewDate; + } + } + } + +} diff --git a/PROMS/DataLoader/PROMSApproveApprove.sql b/PROMS/DataLoader/PROMSApproveApprove.sql new file mode 100644 index 00000000..bc0ad147 Binary files /dev/null and b/PROMS/DataLoader/PROMSApproveApprove.sql differ