diff --git a/PROMS/Volian.Controls.Library/DSOTabPanel.cs b/PROMS/Volian.Controls.Library/DSOTabPanel.cs index a0a4cd82..e3872666 100644 --- a/PROMS/Volian.Controls.Library/DSOTabPanel.cs +++ b/PROMS/Volian.Controls.Library/DSOTabPanel.cs @@ -272,20 +272,20 @@ namespace Volian.Controls.Library private void InitializeWordDocument(LBDocumentClass doc) { - if (MyDocumentInfo.Config == null || MyDocumentInfo.Config == "") + if (MyDocumentInfo.Config == null || MyDocumentInfo.Config == "" && MyDocumentInfo.DocumentEntryCount > 0) { - DocStyle ds = MyDocumentInfo.DocumentEntries[0].MyContent.ContentItems[0].MyDocStyle; - // this will cause an error and goto the Catch if the family or size is null, - // Westinghouse needs it to to this - at least for now - //if (ds.Font.Family != null) doc.Application.Selection.Font.Name = ds.Font.Family; - //if (ds.Font.Size != null) doc.Application.Selection.Font.Size = (float)ds.Font.Size; - doc.Application.Selection.Font.Name = ds.Font.Family; - doc.Application.Selection.Font.Size = (float)ds.Font.Size; - doc.Application.Selection.ParagraphFormat.SpaceBefore = 0; - doc.Application.Selection.ParagraphFormat.SpaceAfter = 0; - doc.Application.Selection.ParagraphFormat.LineSpacingRule = LBWdLineSpacing.wdLineSpaceExactly; - doc.Application.Selection.ParagraphFormat.LineSpacing = 72 / 6; // for 6 LPI - MSWordToPDF.AdjustMargins(ds, doc, false); + DocStyle ds = MyDocumentInfo.DocumentEntries[0].MyContent.ContentItems[0].MyDocStyle; + // this will cause an error and goto the Catch if the family or size is null, + // Westinghouse needs it to to this - at least for now + //if (ds.Font.Family != null) doc.Application.Selection.Font.Name = ds.Font.Family; + //if (ds.Font.Size != null) doc.Application.Selection.Font.Size = (float)ds.Font.Size; + doc.Application.Selection.Font.Name = ds.Font.Family; + doc.Application.Selection.Font.Size = (float)ds.Font.Size; + doc.Application.Selection.ParagraphFormat.SpaceBefore = 0; + doc.Application.Selection.ParagraphFormat.SpaceAfter = 0; + doc.Application.Selection.ParagraphFormat.LineSpacingRule = LBWdLineSpacing.wdLineSpaceExactly; + doc.Application.Selection.ParagraphFormat.LineSpacing = 72 / 6; // for 6 LPI + MSWordToPDF.AdjustMargins(ds, doc, false); } if (doc.ActiveWindow.ActivePane.View.Zoom.Percentage < 40) doc.ActiveWindow.ActivePane.View.Zoom.Percentage = 100; diff --git a/PROMS/Volian.Controls.Library/DisplayLibDocs.Designer.cs b/PROMS/Volian.Controls.Library/DisplayLibDocs.Designer.cs index 8c7cb50e..76bba6a0 100644 --- a/PROMS/Volian.Controls.Library/DisplayLibDocs.Designer.cs +++ b/PROMS/Volian.Controls.Library/DisplayLibDocs.Designer.cs @@ -186,7 +186,7 @@ namespace Volian.Controls.Library this.btnPrint.Name = "btnPrint"; this.btnPrint.Size = new System.Drawing.Size(75, 30); this.btnPrint.TabIndex = 15; - this.btnPrint.Text = "Print"; + this.btnPrint.Text = "Report"; this.btnPrint.UseVisualStyleBackColor = true; this.btnPrint.Click += new System.EventHandler(this.btnPrint_Click); // diff --git a/PROMS/Volian.Controls.Library/DisplayLibDocs.cs b/PROMS/Volian.Controls.Library/DisplayLibDocs.cs index fdb48184..d329ee57 100644 --- a/PROMS/Volian.Controls.Library/DisplayLibDocs.cs +++ b/PROMS/Volian.Controls.Library/DisplayLibDocs.cs @@ -16,50 +16,51 @@ namespace Volian.Controls.Library public partial class DisplayLibDocs : UserControl { #region Properties - private DocumentInfo _CurLibDoc; - public DocumentInfo CurLibDoc - { - get { return _CurLibDoc; } - set { _CurLibDoc = value; } - } - // selected index into listBoxLibDocs... - private int _SelectedLibDoc = -1; - private DocumentInfoList _LibDocList; - public DocumentInfoList LibDocList - { - get { return _LibDocList; } - set { _LibDocList = value; } - } + private DocumentInfo _CurLibDoc; + public DocumentInfo CurLibDoc + { + get { return _CurLibDoc; } + set { _CurLibDoc = value; } + } + // selected index into listBoxLibDocs... + private int _SelectedLibDoc = -1; + private DocumentInfoList _LibDocList; + public DocumentInfoList LibDocList + { + get { return _LibDocList; } + set { _LibDocList = value; } + } private Color saveGroupPanelUsages; #endregion #region Constructors public DisplayLibDocs() { InitializeComponent(); - btnOpenLibDoc.Enabled = false; - btnDelLibDoc.Enabled = false; - btnPrint.Enabled = false; + btnOpenLibDoc.Enabled = false; + btnDelLibDoc.Enabled = false; + btnPrint.Enabled = listBoxLibDocs.Items.Count > 0; saveGroupPanelUsages = groupPanelUsages.Style.BackColor; } - DisplayTabControl _DisplayTabControl; + DisplayTabControl _DisplayTabControl; #endregion - #region LoadControlData + #region LoadControlData private bool _InitializingLibDocList; // used? see if selectionchanged event (still coding) - public void LibDocListFillIn(DisplayTabControl tc) + public void LibDocListFillIn(DisplayTabControl tc) { - _InitializingLibDocList = true; - listBoxLibDocs.Items.Clear(); + _InitializingLibDocList = true; + listBoxLibDocs.Items.Clear(); tbComment.Clear(); tbName.Clear(); groupPanelLibDocs.Style.BackColor = Color.Yellow; - btnSave.Enabled = false; - btnCancel.Enabled = false; - LibDocList = DocumentInfoList.GetLibraries(true); - for (int i = 0; i < LibDocList.Count; i++) - listBoxLibDocs.Items.Add(((LibDocList[i].DocumentEntries == null || LibDocList[i].DocumentEntries.Count == 0) ? "0 " : LibDocList[i].DocumentEntries.Count.ToString() + " ") + LibDocList[i].DocumentTitle); // + LibDocList[i].DocumentEntries.Count); - _DisplayTabControl = tc; + btnSave.Enabled = false; + btnCancel.Enabled = false; + LibDocList = DocumentInfoList.GetLibraries(true); + for (int i = 0; i < LibDocList.Count; i++) + listBoxLibDocs.Items.Add(((LibDocList[i].DocumentEntries == null || LibDocList[i].DocumentEntries.Count == 0) ? "0 " : LibDocList[i].DocumentEntries.Count.ToString() + " ") + LibDocList[i].DocumentTitle); // + LibDocList[i].DocumentEntries.Count); + _DisplayTabControl = tc; listBoxUsages.Items.Clear(); - _InitializingLibDocList = false; + _InitializingLibDocList = false; + btnPrint.Enabled = listBoxLibDocs.Items.Count > 0; } public void SetSelectedLibDoc() { @@ -122,225 +123,226 @@ namespace Volian.Controls.Library btnOpenLibDoc.Enabled = false; foreach (ItemInfo ii in dicnt.LibraryDocumentUsageList) { - if(ii.MyDocVersion!=null) + if (ii.MyDocVersion != null) listBoxUsages.Items.Add(ii.MyProcedure.ToString() + " - " + ii.MyContent.Number + " " + ii.MyContent.Text); } - btnPrint.Enabled = listBoxUsages.Items.Count > 0 ? true : false; + btnPrint.Enabled = listBoxLibDocs.Items.Count > 0 ? true : false; } private void btnDelLibDoc_Click(object sender, EventArgs e) { - DocumentInfo di = LibDocList[_SelectedLibDoc]; - - try - { - Document.Delete(di.DocID); - } - catch (Exception ex) - { - Console.WriteLine("error deleting doc = " + ex.Message); - } - LibDocListFillIn(_DisplayTabControl); + DocumentInfo di = LibDocList[_SelectedLibDoc]; + + try + { + Document.Delete(di.DocID); + } + catch (Exception ex) + { + Console.WriteLine("error deleting doc = " + ex.Message); + } + LibDocListFillIn(_DisplayTabControl); } - private void btnSave_Click(object sender, EventArgs e) - { - bool chg = false; - DocumentInfo di = LibDocList[_SelectedLibDoc]; - Document doc = Document.Get(di.DocID); - if (tbName.Text != LibDocList[_SelectedLibDoc].LibTitle) - { - chg = true; - doc.LibTitle = tbName.Text; - } - DocumentConfig dc = new DocumentConfig(LibDocList[_SelectedLibDoc]); - if (tbComment.Text != dc.LibDoc_Comment) - { - chg = true; - dc.LibDoc_Comment = tbComment.Text; - doc.Config = dc.ToString(); - } - if (chg == true) - { - doc.Save(); + private void btnSave_Click(object sender, EventArgs e) + { + bool chg = false; + DocumentInfo di = LibDocList[_SelectedLibDoc]; + Document doc = Document.Get(di.DocID); + if (tbName.Text != LibDocList[_SelectedLibDoc].LibTitle) + { + chg = true; + doc.LibTitle = tbName.Text; + } + DocumentConfig dc = new DocumentConfig(LibDocList[_SelectedLibDoc]); + if (tbComment.Text != dc.LibDoc_Comment) + { + chg = true; + dc.LibDoc_Comment = tbComment.Text; + doc.Config = dc.ToString(); + } + if (chg == true) + { + doc.Save(); int cursel = _SelectedLibDoc; - LibDocListFillIn(_DisplayTabControl); + LibDocListFillIn(_DisplayTabControl); listBoxLibDocs.SelectedIndex = cursel; UpdateUsageList(); - } - } - private void btnCancel_Click(object sender, EventArgs e) - { - DocumentInfo di = LibDocList[_SelectedLibDoc]; - Document doc = Document.Get(di.DocID); - tbName.Text = doc.LibTitle; - DocumentConfig dc = new DocumentConfig(LibDocList[_SelectedLibDoc]); - tbComment.Text = dc.LibDoc_Comment; - btnSave.Enabled = false; - btnCancel.Enabled = false; - } + } + } + private void btnCancel_Click(object sender, EventArgs e) + { + DocumentInfo di = LibDocList[_SelectedLibDoc]; + Document doc = Document.Get(di.DocID); + tbName.Text = doc.LibTitle; + DocumentConfig dc = new DocumentConfig(LibDocList[_SelectedLibDoc]); + tbComment.Text = dc.LibDoc_Comment; + btnSave.Enabled = false; + btnCancel.Enabled = false; + } - private void btnOpenLibDoc_Click(object sender, EventArgs e) - { - DocumentInfo di = LibDocList[_SelectedLibDoc]; - _DisplayTabControl.OpenDSOTabPage(di); - } + private void btnOpenLibDoc_Click(object sender, EventArgs e) + { + DocumentInfo di = LibDocList[_SelectedLibDoc]; + _DisplayTabControl.OpenDSOTabPage(di); + } - private void tbName_TextChanged(object sender, EventArgs e) - { - if (_InitializingLibDocList) return; - btnSave.Enabled = true; - btnCancel.Enabled = true; - } + private void tbName_TextChanged(object sender, EventArgs e) + { + if (_InitializingLibDocList) return; + btnSave.Enabled = true; + btnCancel.Enabled = true; + } - private void tbComment_TextChanged(object sender, EventArgs e) - { - if (_InitializingLibDocList) return; - btnSave.Enabled = true; - btnCancel.Enabled = true; - } - + private void tbComment_TextChanged(object sender, EventArgs e) + { + if (_InitializingLibDocList) return; + btnSave.Enabled = true; + btnCancel.Enabled = true; + } - private void btnImpLibDoc_Click(object sender, EventArgs e) - { - OpenFileDialog openFileDialog1 = new OpenFileDialog(); - openFileDialog1.InitialDirectory = "c:\\"; - openFileDialog1.Filter = "Word files (*.doc;*.rtf)|*.doc;*.rtf|All files (*.*)|*.*"; - openFileDialog1.FilterIndex = 0; - openFileDialog1.RestoreDirectory = true; + private void btnImpLibDoc_Click(object sender, EventArgs e) + { + OpenFileDialog openFileDialog1 = new OpenFileDialog(); - if (openFileDialog1.ShowDialog() == DialogResult.OK) - { - int done = 0; - int ntry = 0; - while (done == 0 && ntry < 4) - { - ntry++; - done = SaveTheDoc(openFileDialog1.FileName, openFileDialog1.SafeFileName.Substring(0,openFileDialog1.SafeFileName.LastIndexOf("."))); - } - if (done > 0) - { - LibDocListFillIn(_DisplayTabControl); - // set selectedindex to the imported doc... - int indx = 0; - DocumentInfoList dil = DocumentInfoList.GetLibraries(true); - for(int i = 0; i= 0) - { - ItemInfo ii = di.LibraryDocumentUsageList[listBoxUsages.SelectedIndex]; - if (ii.MyDocVersion == null) - MessageBox.Show("This usage is not connected properly", "Disconnected Data", MessageBoxButtons.OK, MessageBoxIcon.Warning); - else - _DisplayTabControl.OpenItem(ii); - } - _ProcessingSelectedValueChanged = false; - } + ntry++; + done = SaveTheDoc(openFileDialog1.FileName, openFileDialog1.SafeFileName.Substring(0, openFileDialog1.SafeFileName.LastIndexOf("."))); } - #endregion + if (done > 0) + { + LibDocListFillIn(_DisplayTabControl); + // set selectedindex to the imported doc... + int indx = 0; + DocumentInfoList dil = DocumentInfoList.GetLibraries(true); + for (int i = 0; i < listBoxLibDocs.Items.Count; i++) + { + if (dil[i].DocID == done) + { + indx = i; + break; + } + } + listBoxLibDocs.SelectedIndex = indx; + } + } + } + private int SaveTheDoc(string temppath, string title) + { + try + { + FileInfo fi = new FileInfo(temppath); + FileStream fs = File.Open(temppath, FileMode.Open, FileAccess.Read, FileShare.None); + long len = fs.Length; + byte[] ByteArray = new byte[len]; + int nBytesRead = fs.Read(ByteArray, 0, (int)len); + fs.Close(); + string t1 = (title == null || title == "") ? null : title; + Document doc = Document.MakeDocument(t1, ByteArray, null, null, fi.Extension); //, DateTime.Now, "Migration"); + return doc.DocID; + } + // for an io exception, keep trying + catch (IOException) + { + Wait(2); + return 0; + } + catch (Exception ex) + { + MessageBox.Show(string.Format("Could not save the document, {0}, {1}", ex.Message, ex.InnerException)); + return -1; + } + + } + private void Wait(int n) + { + DateTime dtw = DateTime.Now.AddSeconds(n); + while (DateTime.Now < dtw) + { + Application.DoEvents(); + } + } + private bool _ProcessingSelectedValueChanged = false; + private void listBoxUsages_SelectedValueChanged(object sender, EventArgs e) + { + if (!_InitializingLibDocList) + { + if (_ProcessingSelectedValueChanged) return; + _ProcessingSelectedValueChanged = true; + if (listBoxUsages.SelectedIndex == -1) return; + DocumentInfo di = LibDocList[listBoxLibDocs.SelectedIndex]; + // see if the library document actually has data - data migration may have created a 'null' content within the + // record for missing library documents. + if (di.DocContent == null) + { + MessageBox.Show("No Content in this document"); + return; + } + if (listBoxUsages.SelectedIndex < di.LibraryDocumentUsageList.Count && listBoxUsages.SelectedIndex >= 0) + { + ItemInfo ii = di.LibraryDocumentUsageList[listBoxUsages.SelectedIndex]; + if (ii.MyDocVersion == null) + MessageBox.Show("This usage is not connected properly", "Disconnected Data", MessageBoxButtons.OK, MessageBoxIcon.Warning); + else + _DisplayTabControl.OpenItem(ii); + } + _ProcessingSelectedValueChanged = false; + } + } + #endregion private void btnPrint_Click(object sender, EventArgs e) { - OnPrintRequest(new DisplayLibDocEventArgs("Library Document Usage",LibDocList)); + OnPrintRequest(new DisplayLibDocEventArgs("Library Document Usage", LibDocList)); } - } - public class DisplayLibDocEventArgs - { - private string _ReportTitle; - public string ReportTitle - { - get { return _ReportTitle; } - set { _ReportTitle = value; } - } - private DocumentInfoList _libDocList; + } + public class DisplayLibDocEventArgs + { + private string _ReportTitle; + public string ReportTitle + { + get { return _ReportTitle; } + set { _ReportTitle = value; } + } + private DocumentInfoList _libDocList; - public DocumentInfoList LibDocList - { - get { return _libDocList; } - set { _libDocList = value; } - } - //private string _SearchString = null; - //public string SearchString - //{ - // get { return _SearchString; } - // set { _SearchString = value; } - //} - //private string _TypesSelected; - //public string TypesSelected - //{ - // get { return _TypesSelected; } - // set { _TypesSelected = value; } - //} - //private ICollection _MyItemInfoList; - //public ICollection MyItemInfoList - //{ - // get { return _MyItemInfoList; } - // set { _MyItemInfoList = value; } - //} - public DisplayLibDocEventArgs(string reportTitle, DocumentInfoList libDocList) - { - _ReportTitle = reportTitle; - _libDocList = libDocList; - } - } - public delegate void DisplayLibDocEvent(object sender, DisplayLibDocEventArgs args); + public DocumentInfoList LibDocList + { + get { return _libDocList; } + set { _libDocList = value; } + } + //private string _SearchString = null; + //public string SearchString + //{ + // get { return _SearchString; } + // set { _SearchString = value; } + //} + //private string _TypesSelected; + //public string TypesSelected + //{ + // get { return _TypesSelected; } + // set { _TypesSelected = value; } + //} + //private ICollection _MyItemInfoList; + //public ICollection MyItemInfoList + //{ + // get { return _MyItemInfoList; } + // set { _MyItemInfoList = value; } + //} + public DisplayLibDocEventArgs(string reportTitle, DocumentInfoList libDocList) + { + _ReportTitle = reportTitle; + _libDocList = libDocList; + } + } + public delegate void DisplayLibDocEvent(object sender, DisplayLibDocEventArgs args); }