B2017-135 Only open the Message Box once

B2017-137 Restore Previous valid version if the current version cannot be opened
This commit is contained in:
Rich 2017-07-10 15:43:14 +00:00
parent 537ab3c21c
commit ae4ca7df37

View File

@ -109,18 +109,14 @@ namespace Volian.Controls.Library
_MyDocumentInfo = documentInfo; _MyDocumentInfo = documentInfo;
SetupDSO(); SetupDSO();
_RefreshTimer = new Timer(); // Enabled is false and interval is 1/10th of second. _RefreshTimer = new Timer(); // Enabled is false and interval is 1/10th of second.
_RefreshTimer.Interval = 1000;// B2017-133 Edraw _RefreshTimer.Interval = 500;// B2017-133 Edraw
ClientSizeChanged += new EventHandler(DSOTabPanel_ClientSizeChanged); ClientSizeChanged += new EventHandler(DSOTabPanel_ClientSizeChanged);
_RefreshTimer.Tick += new EventHandler(_RefreshTimer_Tick); _RefreshTimer.Tick += new EventHandler(_RefreshTimer_Tick);
_MyEdWord.BeforeDocumentClosed += _MyEdWord_BeforeDocumentClosed;// B2017-133 Edraw
_MyEdWord.BeforeDocumentOpened += _MyEdWord_BeforeDocumentOpened;// B2017-133 Edraw
_MyEdWord.BeforeDocumentSaved += _MyEdWord_BeforeDocumentSaved;// B2017-133 Edraw _MyEdWord.BeforeDocumentSaved += _MyEdWord_BeforeDocumentSaved;// B2017-133 Edraw
//_frm = new frmPG(_MyDSOFramer);
//_frm.Show();
} }
void _MyEdWord_BeforeDocumentSaved(object sender, EventArgs e)// B2017-133 Edraw void _MyEdWord_BeforeDocumentSaved(object sender, EventArgs e)// B2017-133 Edraw
{ {
SaveDSO(); _MyEdWord.Save(); // B2017-135 Only open the Message Box once
} }
void DisableWordCommands()// B2017-133 Edraw void DisableWordCommands()// B2017-133 Edraw
{ {
@ -137,25 +133,6 @@ namespace Volian.Controls.Library
_MyEdWord.DisableSaveHotKey(true); _MyEdWord.DisableSaveHotKey(true);
_MyEdWord.DisablePrintHotKey(true); _MyEdWord.DisablePrintHotKey(true);
} }
void _MyEdWord_BeforeDocumentOpened(object sender, EventArgs e)// B2017-133 Edraw
{
//_MyEdWord.DisableFileCommand(EDWordLib.WdUIType.wdUIDisableClose, true);
//_MyEdWord.DisableFileCommand(EDWordLib.WdUIType.wdUIDisableNew, true);
//_MyEdWord.DisableFileCommand(EDWordLib.WdUIType.wdUIDisablePrint, true);
//_MyEdWord.DisableFileCommand(EDWordLib.WdUIType.wdUIDisablePrintPreview, true);
//_MyEdWord.DisableFileCommand(EDWordLib.WdUIType.wdUIDisablePrintQuick, true);
//_MyEdWord.DisableFileCommand(EDWordLib.WdUIType.wdUIDisableSave, true);
//_MyEdWord.DisableFileCommand(EDWordLib.WdUIType.wdUIDisableSaveAs, true);
//_MyEdWord.DisableStandardCommand(EDWordLib.CommandType.cmdTypeSave, true);
//_MyEdWord.DisableStandardCommand(EDWordLib.CommandType.cmdTypeClose, true);
//_MyEdWord.DisableStandardCommand(EDWordLib.CommandType.cmdTypePrint, true);
//_MyEdWord.DisableSaveHotKey(true);
//_MyEdWord.DisablePrintHotKey(true);
}
void _MyEdWord_BeforeDocumentClosed(object sender, EventArgs e)// B2017-133 Edraw
{
Console.WriteLine("B2017-133 Edraw Before Document Closed");
}
void _RefreshTimer_Tick(object sender, EventArgs e) void _RefreshTimer_Tick(object sender, EventArgs e)
{ {
_RefreshTimer.Enabled = false; _RefreshTimer.Enabled = false;
@ -166,6 +143,10 @@ namespace Volian.Controls.Library
//_MyEdWord.BringToFront(); //_MyEdWord.BringToFront();
//_MyEdWord.EndInit(); //_MyEdWord.EndInit();
} }
//else
//{
// _MyDisplayTabControl.CloseTabItem(_MyDisplayTabItem);
//}
} }
void DSOTabPanel_ClientSizeChanged(object sender, EventArgs e) void DSOTabPanel_ClientSizeChanged(object sender, EventArgs e)
{ {
@ -204,6 +185,7 @@ namespace Volian.Controls.Library
//System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(WordDSOTab)); //System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(WordDSOTab));
//this._DSOFramer.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("_FC.OcxState"))); //this._DSOFramer.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("_FC.OcxState")));
_MyEdWord.EndInit(); _MyEdWord.EndInit();
LBDocumentClass doc;
try try
{ {
try try
@ -212,10 +194,11 @@ namespace Volian.Controls.Library
this._MyEdWord.LicenseCode = "EDW8-5527-1201-AB8A";// B2017-133 Edraw this._MyEdWord.LicenseCode = "EDW8-5527-1201-AB8A";// B2017-133 Edraw
DisableWordCommands(); DisableWordCommands();
this._MyEdWord.Open(MyDSOFile.MyFile.FullName); this._MyEdWord.Open(MyDSOFile.MyFile.FullName);
doc = new LBDocumentClass(_MyEdWord.ActiveDocument());
} }
catch (Exception ex) catch (Exception ex)
{ {
System.IO.FileStream fs = MyDSOFile.MyFile.Create(); // B2017-137 Restore Previous valid version if the current version cannot be opened,
using (DocumentAuditInfoList dail = DocumentAuditInfoList.Get(MyDocumentInfo.DocID)) using (DocumentAuditInfoList dail = DocumentAuditInfoList.Get(MyDocumentInfo.DocID))
{ {
if (dail.Count > 0) if (dail.Count > 0)
@ -225,28 +208,40 @@ namespace Volian.Controls.Library
//{ //{
// if (tmpa.DTS > dai.DTS) dai = tmpa; // if (tmpa.DTS > dai.DTS) dai = tmpa;
//} //}
if(MessageBox.Show("Do you want to revert to a previous version?", "Error in MS Word section", if (MessageBox.Show("Do you want to revert to a previous version?", "Error in MS Word section",
MessageBoxButtons.YesNo, MessageBoxIcon.Question)==DialogResult.Yes) MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{ {
//fs.Write(dai.DocContent, 0, dai.DocContent.Length);
using (Document myDoc = Document.Get(MyDocumentInfo.DocID)) using (Document myDoc = Document.Get(MyDocumentInfo.DocID))
{ {
myDoc.RestoreWordDoc(_ItemInfo); myDoc.RestoreWordDoc(_ItemInfo);
_DSOFile = null; }
using (Document myDoc = Document.Get(MyDocumentInfo.DocID))
{
System.IO.FileStream fs = MyDSOFile.MyFile.Create();
fs.Write(myDoc.DocContent, 0, myDoc.DocContent.Length);
fs.Close();
_MyDocumentInfo = DocumentInfo.Get(MyDocumentInfo.DocID); _MyDocumentInfo = DocumentInfo.Get(MyDocumentInfo.DocID);
DocumentInfo.Refresh(myDoc);
//_DSOFile = null;
this._MyEdWord.Open(MyDSOFile.MyFile.FullName);
doc = new LBDocumentClass(_MyEdWord.ActiveDocument());
doc.Range(1, 1);
} }
} }
} }
else else
{
System.IO.FileStream fs = MyDSOFile.MyFile.Create();
fs.Close();
MessageBox.Show("Reverting to Blank Document", "Error in MS Word section", MessageBox.Show("Reverting to Blank Document", "Error in MS Word section",
MessageBoxButtons.OK, MessageBoxIcon.Exclamation); MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
} }
fs.Close(); }
this._MyEdWord.Open(MyDSOFile.MyFile.FullName);// B2017-133 Edraw this._MyEdWord.Open(MyDSOFile.MyFile.FullName);// B2017-133 Edraw
} }
LBDocumentClass doc = new LBDocumentClass(_MyEdWord.ActiveDocument()); doc = new LBDocumentClass(_MyEdWord.ActiveDocument());
Console.WriteLine("Version {0}", doc.Application.Version); //Console.WriteLine("Version {0}", doc.Application.Version);
float ver; float ver;
if (!float.TryParse(doc.Application.Version, out ver)) if (!float.TryParse(doc.Application.Version, out ver))
ver = 12.0F; ver = 12.0F;
@ -259,8 +254,8 @@ namespace Volian.Controls.Library
} }
catch (Exception ex) catch (Exception ex)
{ {
string message = ShowException(ex); //string message = ShowException(ex);
Console.WriteLine("\r\n-------------\r\n{0}{1}{2}\r\n-------------\r\n", MyDSOFile.MyFile.FullName, ex.GetType().Name, message); //Console.WriteLine("\r\n-------------\r\n{0}{1}{2}\r\n-------------\r\n", MyDSOFile.MyFile.FullName, ex.GetType().Name, message);
// TODO: Should output a message // TODO: Should output a message
// TODO: Should try to do a direct open using Word. // TODO: Should try to do a direct open using Word.
} }
@ -513,7 +508,7 @@ namespace Volian.Controls.Library
try try
{ {
bool stat = _MyEdWord.Save();// B2017-133 Edraw bool stat = _MyEdWord.Save();// B2017-133 Edraw
Console.WriteLine("Save = {0}", stat); //Console.WriteLine("Save = {0}", stat);
SaveDSO_Phase2(); SaveDSO_Phase2();
//_MyDSOFramer_OnSaveCompleted(this, null); //_MyDSOFramer_OnSaveCompleted(this, null);
// These are handled in the method above // These are handled in the method above