B2019-108 -Disable/enable buttons
Replace special characters Use word font size when copying table text Corrected button high click Corrected button current click Show special characters while importing
This commit is contained in:
parent
8471cfb899
commit
cd0072e103
@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
@ -29,15 +29,20 @@ namespace Volian.Controls.Library
|
||||
txbWordFile.Text = Properties.Settings.Default.ImportWordFilePath;
|
||||
disableButtons();
|
||||
_initializing = false;
|
||||
btnOpen.Enabled = (txbWordFile.Text.Length > 0);
|
||||
// B2019-108 Enable/disable buttons
|
||||
btnOpen.Enabled = File.Exists(txbWordFile.Text) && _WordApp==null;
|
||||
}
|
||||
|
||||
private void disableButtons()
|
||||
{
|
||||
btnOpen.Enabled = false;
|
||||
// B2019-108 Enable/disable buttons
|
||||
btnOpen.Enabled = File.Exists(txbWordFile.Text) && _WordApp == null; ;
|
||||
btnNext.Enabled = false;
|
||||
btnPage.Enabled = false;
|
||||
btnPrev.Enabled = false;
|
||||
btnCurrent.Enabled = false;
|
||||
btnInsertNext.Enabled = false;
|
||||
btnReplaceNext.Enabled = false;
|
||||
}
|
||||
private void ofd_FileOk(object sender, CancelEventArgs e)
|
||||
{
|
||||
@ -66,9 +71,7 @@ namespace Volian.Controls.Library
|
||||
{
|
||||
btnOpen_Click(sender, e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void btnOpen_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (!File.Exists(txbWordFile.Text))
|
||||
@ -80,11 +83,20 @@ namespace Volian.Controls.Library
|
||||
_WordApp = new LBApplicationClass();
|
||||
_WordApp.Documents.Open(txbWordFile.Text);
|
||||
_WordApp.Visible = true;
|
||||
// B2019-108 Enable/disable buttons
|
||||
EnableButtons();
|
||||
Properties.Settings.Default.ImportWordFilePath = txbWordFile.Text;
|
||||
Properties.Settings.Default.Save();
|
||||
}
|
||||
private void EnableButtons()
|
||||
{
|
||||
btnOpen.Enabled = File.Exists(txbWordFile.Text) && _WordApp == null; ;
|
||||
btnNext.Enabled = true;
|
||||
btnPage.Enabled = true;
|
||||
btnPrev.Enabled = true;
|
||||
Properties.Settings.Default.ImportWordFilePath = txbWordFile.Text;
|
||||
Properties.Settings.Default.Save();
|
||||
btnCurrent.Enabled = true;
|
||||
btnInsertNext.Enabled = true;
|
||||
btnReplaceNext.Enabled = true;
|
||||
}
|
||||
private void btnPage_Click(object sender, EventArgs e)
|
||||
{
|
||||
@ -188,6 +200,8 @@ namespace Volian.Controls.Library
|
||||
// C2019-021 Generic CopyWordText (Copy Text, Style and Number to fields on form)
|
||||
private void CopyWordText()
|
||||
{
|
||||
// B2019-108 Display Font Size
|
||||
lblFS.Text = _WordApp.Selection.Font.Size.ToString() + "Pts";
|
||||
txvStyle.Text = _WordApp.Selection.Style.NameLocal;
|
||||
txbLevel.Text = _WordApp.Selection.Style.ListLevelNumber.ToString();
|
||||
tbxNumber.Text = _WordApp.Selection.Range.ListFormat.ListString;
|
||||
@ -203,7 +217,21 @@ namespace Volian.Controls.Library
|
||||
lblTable.Text = "Not Table";
|
||||
lblTable.FontBold = false;
|
||||
}
|
||||
txbWrdText.Text = ShowText(_WordApp.Selection.Text.TrimEnd("\r\a".ToCharArray()));
|
||||
// B2019-108 Replace Special Characters
|
||||
string txt = ShowText(_WordApp.Selection.Text.TrimEnd("\r\a".ToCharArray())
|
||||
.Replace("\x1D", "-")// Hyphen
|
||||
.Replace("\x1E", "-")// Hyphen
|
||||
.Replace("\x2013", "-")// Hyphen
|
||||
.Replace("\xa0", " ")// Space
|
||||
.Replace("\x0b", " ")// Space Soft Return
|
||||
.Replace("\x201C", "\"")// Space
|
||||
.Replace("\x201D", "\"")// Space
|
||||
.Replace("\x09INITIAL", "")// Space
|
||||
);
|
||||
if (txt.Contains("\x09_____")) // Tab Signoff
|
||||
txt = txt.Substring(0, txt.IndexOf("\x09_____")).TrimEnd(" \x09".ToCharArray());// Trim spaces and Tabs
|
||||
txbWrdText.Text = txt;
|
||||
|
||||
_WordApp.Activate();
|
||||
}
|
||||
// C2019-021 RHM 5/15/2019 Added newe methods and properties for Import Word Content
|
||||
@ -221,7 +249,8 @@ namespace Volian.Controls.Library
|
||||
}
|
||||
private void txbWordFile_TextChanged(object sender, EventArgs e)
|
||||
{
|
||||
btnOpen.Enabled = !_initializing;
|
||||
// B2019-108 Enable/disable buttons
|
||||
btnOpen.Enabled = File.Exists(txbWordFile.Text) && _WordApp == null;
|
||||
}
|
||||
private void frmImportWordContents_FormClosing(object sender, FormClosingEventArgs e)
|
||||
{
|
||||
@ -229,6 +258,8 @@ namespace Volian.Controls.Library
|
||||
{
|
||||
if (_WordApp != null)
|
||||
_WordApp.Quit();
|
||||
// B2019-108 Reset WordApp when closed.
|
||||
_WordApp = null;
|
||||
}
|
||||
catch
|
||||
{
|
||||
@ -273,6 +304,13 @@ namespace Volian.Controls.Library
|
||||
VlnFlexGrid vg = MyStepRTB.Parent as VlnFlexGrid;
|
||||
vg.StartEditing();
|
||||
MyStepRTB.Text = txbWrdText.Text;
|
||||
// B2019-108 Set font for table cell
|
||||
if (MyStepRTB.Parent is VlnFlexGrid && lblFS.Text !="FS")
|
||||
{
|
||||
Font fs = MyStepRTB.Font;
|
||||
fs = new Font(fs.FontFamily, float.Parse(lblFS.Text.Replace("Pts", "")), fs.Style);
|
||||
MyStepRTB.Font = fs;
|
||||
}
|
||||
vg[vg.Row, vg.Col] = MyStepRTB.Rtf;
|
||||
vg.FinishEditing(false);
|
||||
}
|
||||
@ -357,8 +395,8 @@ namespace Volian.Controls.Library
|
||||
{
|
||||
if (MyStepRTB != null)
|
||||
{
|
||||
EditItem ei = MyStepRTB.Parent as EditItem;
|
||||
if (ei.MyItemInfo.IsSection)
|
||||
EditItem ei = GetEditItem(MyStepRTB);
|
||||
if (ei != null && ei.MyItemInfo.IsSection)
|
||||
{
|
||||
ei.AddChild(VEPROMS.CSLA.Library.E_FromType.Step, 20002);
|
||||
return;
|
||||
@ -374,6 +412,15 @@ namespace Volian.Controls.Library
|
||||
}
|
||||
}
|
||||
}
|
||||
private EditItem GetEditItem(Control Ctrl)
|
||||
{
|
||||
while (Ctrl != null)
|
||||
{
|
||||
Ctrl = Ctrl.Parent;
|
||||
if (Ctrl is EditItem) return Ctrl as EditItem;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
// C2019-021 New Function Add a new sequential substep
|
||||
private void btnSEQ_Click(object sender, EventArgs e)
|
||||
{
|
||||
@ -422,9 +469,18 @@ namespace Volian.Controls.Library
|
||||
// C2019-021 RHM 5/15/2019 Added new methods and properties for Import Word Content
|
||||
private void btnCurrent_Click(object sender, EventArgs e)
|
||||
{
|
||||
_WordApp.Selection.MoveUp(LBWdUnits.wdParagraph, 1, 0); // Select paragraph
|
||||
_WordApp.Selection.MoveDown(LBWdUnits.wdParagraph, 1, 1); // Select paragraph
|
||||
_WordApp.Selection.MoveEnd(LBWdUnits.wdCharacter, -1); // Exclude the last character
|
||||
// B2019-108 Corrected curent button code
|
||||
//_WordApp.Selection.MoveUp(LBWdUnits.wdParagraph, 1, 0); // Select paragraph
|
||||
//_WordApp.Selection.MoveDown(LBWdUnits.wdParagraph, 1, 1); // Select paragraph
|
||||
//_WordApp.Selection.MoveEnd(LBWdUnits.wdCharacter, -1); // Exclude the last character
|
||||
try
|
||||
{
|
||||
_WordApp.Selection.Cells[1].Range.Select();
|
||||
}
|
||||
catch
|
||||
{
|
||||
_WordApp.Selection.Paragraphs[1].Range.Select();
|
||||
}
|
||||
try
|
||||
{
|
||||
// C2019-021 Use Generic CopyWordText
|
||||
@ -438,15 +494,53 @@ namespace Volian.Controls.Library
|
||||
catch
|
||||
{ }
|
||||
}
|
||||
private void btnTest_Click(object sender, EventArgs e)
|
||||
//private void btnTest_Click(object sender, EventArgs e)
|
||||
//{
|
||||
// if (!MoveToNextCell())
|
||||
// {
|
||||
// _WordApp.Selection.MoveDown(LBWdUnits.wdParagraph, 2, 0);
|
||||
// _WordApp.Selection.MoveDown(LBWdUnits.wdParagraph, 1, 1);
|
||||
// }
|
||||
// _WordApp.Activate();
|
||||
// //int cols = _WordApp.Selection.Tables[1].Columns.Count;
|
||||
//}
|
||||
|
||||
// B2019-108 Show special Characters
|
||||
private void txbWrdText_TextChanged(object sender, EventArgs e)
|
||||
{
|
||||
if (!MoveToNextCell())
|
||||
txbImport.Text = fixText(txbWrdText.Text);
|
||||
}
|
||||
|
||||
private string fixText(string txt)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
foreach (char c in txt)
|
||||
{
|
||||
_WordApp.Selection.MoveDown(LBWdUnits.wdParagraph, 2, 0);
|
||||
_WordApp.Selection.MoveDown(LBWdUnits.wdParagraph, 1, 1);
|
||||
int ic = (int)c;
|
||||
if (ic < 32 || ic > '\x7F')
|
||||
{
|
||||
sb.Append(string.Format("[x{0:x2}]", ic));
|
||||
//MessageBox.Show(string.Format("[x{0:x2} - {1}]", ic, txt), "Special Character");
|
||||
}
|
||||
else
|
||||
sb.Append(c);
|
||||
}
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
// B2019-108 Handle WordApp status
|
||||
private void frmImportWordContents_Activated(object sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (_WordApp != null || _WordApp.WindowState == LBWdWindowState.wdWindowStateMinimize)
|
||||
_WordApp.WindowState = LBWdWindowState.wdWindowStateNormal;
|
||||
}
|
||||
catch
|
||||
{
|
||||
_WordApp=null;
|
||||
disableButtons();
|
||||
}
|
||||
_WordApp.Activate();
|
||||
//int cols = _WordApp.Selection.Tables[1].Columns.Count;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user