using System; using System.Collections; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; using System.Data; using System.Text; using System.Windows.Forms; using System.Text.RegularExpressions; using System.IO; using AT.STO.UI.Win; using VEPROMS.CSLA.Library; 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; } } #endregion #region Constructors public DisplayLibDocs() { InitializeComponent(); btnOpenLibDoc.Enabled = false; btnDelLibDoc.Enabled = false; } DisplayTabControl _DisplayTabControl; #endregion #region LoadControlData private bool _InitializingLibDocList; // used? see if selectionchanged event (still coding) public void LibDocListFillIn(DisplayTabControl tc) { _InitializingLibDocList = true; listBoxLibDocs.Items.Clear(); 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; } #endregion #region Events private void listBoxLibDocs_Click(object sender, EventArgs e) { if (listBoxLibDocs.SelectedIndex == _SelectedLibDoc) return; _SelectedLibDoc = listBoxLibDocs.SelectedIndex; listBoxUsages.Items.Clear(); tbComment.Clear(); tbName.Clear(); btnSave.Enabled = false; btnCancel.Enabled = false; _InitializingLibDocList = true; // need this so textchanged code doesn't turn save/cancel buttons on. tbName.Text = LibDocList[_SelectedLibDoc].LibTitle; DocumentConfig dc = new DocumentConfig(LibDocList[_SelectedLibDoc]); tbComment.Text = dc.LibDoc_Comment; _InitializingLibDocList = false; // If there are no usages, then enable delete & open button (open for docs with usages occurs // from usage list), otherwise disable buttons & list usages DocumentInfo dicnt = LibDocList[_SelectedLibDoc]; ItemInfoList iil = dicnt.LibraryDocumentUsageList; if (iil == null) { btnDelLibDoc.Enabled = true; btnOpenLibDoc.Enabled = true; return; } // Put the usages in the usage list for the selected library document. btnDelLibDoc.Enabled = false; btnOpenLibDoc.Enabled = false; DocumentInfo di = LibDocList[_SelectedLibDoc]; foreach (ItemInfo ii in di.LibraryDocumentUsageList) { listBoxUsages.Items.Add(ii.MyProcedure.ToString() + " - " + ii.MyContent.Number + " " + ii.MyContent.Text); } } 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); } 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(); LibDocListFillIn(_DisplayTabControl); } } 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 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 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; 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