This commit is contained in:
253
PROMS/Volian.Controls.Library/DisplayLibDocs.cs
Normal file
253
PROMS/Volian.Controls.Library/DisplayLibDocs.cs
Normal file
@@ -0,0 +1,253 @@
|
||||
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<listBoxLibDocs.Items.Count; i++)
|
||||
{
|
||||
if (dil[i].DocID == done)
|
||||
{
|
||||
indx = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
listBoxLibDocs.SelectedIndex = indx;
|
||||
}
|
||||
}
|
||||
}
|
||||
private int SaveTheDoc(string temppath, string title)
|
||||
{
|
||||
try
|
||||
{
|
||||
FileStream fs = File.Open(temppath, FileMode.Open, FileAccess.Read, FileShare.None);
|
||||
long len = fs.Length + 1;
|
||||
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); //, 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 void listBoxUsages_SelectedValueChanged(object sender, EventArgs e)
|
||||
{
|
||||
if (!_InitializingLibDocList)
|
||||
{
|
||||
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;
|
||||
}
|
||||
MessageBox.Show("WARNING: All edits made to this Library Document will be applied to all uses of the Document");
|
||||
_DisplayTabControl.OpenItem(di.LibraryDocumentUsageList[listBoxUsages.SelectedIndex]);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user