From bbcb6380247c8587ac70653d4c5ae5781d0a8f95 Mon Sep 17 00:00:00 2001 From: Kathy Date: Wed, 12 Dec 2018 15:34:25 +0000 Subject: [PATCH] =?UTF-8?q?C2018-039:=20Upgrade=20=E2=80=93=20User=20Contr?= =?UTF-8?q?ol=20of=20Format?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Extension/ContentExt.cs | 319 ++++- .../Extension/DisplayText.cs | 40 +- .../Extension/FormatExt.cs | 113 +- .../VEPROMS.CSLA.Library/Extension/ItemExt.cs | 27 +- .../VEPROMS.CSLA.Library/Format/Comparator.cs | 335 +++++ .../VEPROMS.CSLA.Library/Format/DocStyles.cs | 55 +- PROMS/VEPROMS.CSLA.Library/Format/ENums.cs | 8 + .../Format/PlantFormat.cs | 415 ++++-- .../VEPROMS.CSLA.Library/Format/vlnFormat.cs | 13 + .../VEPROMS.CSLA.Library/Generated/Format.cs | 53 +- .../Generated/FormatInfo.cs | 12 + .../Generated/FormatInfoList.cs | 1 + PROMS/Volian.Base.Library/FlagEnumEditor.cs | 277 ++++ .../Volian.Base.Library/PropGridCollEditor.cs | 300 +++++ PROMS/Volian.Base.Library/RTBAPI.cs | 1110 +++++++++++++++++ PROMS/Volian.Base.Library/RtfEditor.cs | 36 + .../frmRtfEdit.Designer.cs | 179 +++ PROMS/Volian.Base.Library/frmRtfEdit.cs | 199 +++ PROMS/Volian.Base.Library/frmRtfEdit.resx | 120 ++ PROMS/Volian.Controls.Library/DisplayTags.cs | 36 +- PROMS/Volian.Controls.Library/RtfRawItem.cs | 1 + .../RtfRawItem.designer.cs | 2 +- .../UCFDiffDetails.xsl | 198 +++ .../Volian.Controls.Library/UCFImpDetails.xsl | 189 +++ .../dlgUCFImportOptions.Designer.cs | 397 ++++++ .../dlgUCFImportOptions.cs | 184 +++ .../dlgUCFImportOptions.resx | 126 ++ .../Volian.Print.Library/VlnSvgPageHelper.cs | 34 +- PROMS/Volian.Print.Library/vlnParagraph.cs | 10 +- 29 files changed, 4656 insertions(+), 133 deletions(-) create mode 100644 PROMS/VEPROMS.CSLA.Library/Format/Comparator.cs create mode 100644 PROMS/Volian.Base.Library/FlagEnumEditor.cs create mode 100644 PROMS/Volian.Base.Library/PropGridCollEditor.cs create mode 100644 PROMS/Volian.Base.Library/RTBAPI.cs create mode 100644 PROMS/Volian.Base.Library/RtfEditor.cs create mode 100644 PROMS/Volian.Base.Library/frmRtfEdit.Designer.cs create mode 100644 PROMS/Volian.Base.Library/frmRtfEdit.cs create mode 100644 PROMS/Volian.Base.Library/frmRtfEdit.resx create mode 100644 PROMS/Volian.Controls.Library/UCFDiffDetails.xsl create mode 100644 PROMS/Volian.Controls.Library/UCFImpDetails.xsl create mode 100644 PROMS/Volian.Controls.Library/dlgUCFImportOptions.Designer.cs create mode 100644 PROMS/Volian.Controls.Library/dlgUCFImportOptions.cs create mode 100644 PROMS/Volian.Controls.Library/dlgUCFImportOptions.resx diff --git a/PROMS/VEPROMS.CSLA.Library/Extension/ContentExt.cs b/PROMS/VEPROMS.CSLA.Library/Extension/ContentExt.cs index 2d50e0af..b8d60507 100644 --- a/PROMS/VEPROMS.CSLA.Library/Extension/ContentExt.cs +++ b/PROMS/VEPROMS.CSLA.Library/Extension/ContentExt.cs @@ -1357,9 +1357,322 @@ namespace VEPROMS.CSLA.Library } } #endregion - #region Enhanced - #region Enhanced_UnlinkItems - [Serializable()] + #region UCF Fix FormatId After Import + private class FixFormatIDAfterImportCriteria + { + private string _DocVersionList; + public string DocVersionList + { + get { return _DocVersionList; } + set { _DocVersionList = value; } + } + private int _OldFormatID; + public int OldFormatID + { + get { return _OldFormatID; } + set { _OldFormatID = value; } + } + private int _NewFormatID; + public int NewFormatID + { + get { return _NewFormatID; } + set { _NewFormatID = value; } + } + public FixFormatIDAfterImportCriteria(string dvlst, int oldfid, int newfid) + { + _DocVersionList = dvlst; + _OldFormatID = oldfid; + _NewFormatID = newfid; + } + } + private void DataPortal_Fetch(FixFormatIDAfterImportCriteria criteria) + { + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "vesp_UpdateVersionFormatForUCF"; + cm.Parameters.AddWithValue("@VersionList", criteria.DocVersionList); + cm.Parameters.AddWithValue("@OldFormatID", criteria.OldFormatID); + cm.Parameters.AddWithValue("@NewFormatID", criteria.NewFormatID); + cm.CommandTimeout = Database.DefaultTimeout; + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + IsReadOnly = false; + while (dr.Read()) + { + ContentInfo contentInfo = new ContentInfo(dr); + this.Add(contentInfo); + } + IsReadOnly = true; + } + } + } + } + catch (Exception ex) + { + Database.LogException("FixFormatIDAfterImport.DataPortal_Fetch", ex); + throw new DbCslaException("FixFormatIDAfterImport.DataPortal_Fetch", ex); + } + } + public static ContentInfoList FixFormatIDAfterImport(string dvlst, int oldfid, int newfid) + { + try + { + ContentInfoList tmp = DataPortal.Fetch(new FixFormatIDAfterImportCriteria(dvlst, oldfid, newfid)); + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on ContentInfoList.FixFormatIDAfterImport", ex); + } + } + #endregion + #region UCF Clear Overwridden Formats + private class ClearOverrideFormatsByFolderCriteria + { + public ClearOverrideFormatsByFolderCriteria(int folderID, int? formatID, int? newformatID) + { + _FormatID = formatID; + _FolderID = folderID; + _NewFormatID = newformatID; + } + private int? _FormatID; + public int? FormatID + { + get { return _FormatID; } + set { _FormatID = value; } + } + private int? _NewFormatID; + public int? NewFormatID + { + get { return _NewFormatID; } + set { _NewFormatID = value; } + } + private int _FolderID; + public int FolderID + { + get { return _FolderID; } + set { _FolderID = value; } + } + } + private void DataPortal_Fetch(ClearOverrideFormatsByFolderCriteria criteria) + { + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "vesp_ClearOverrideFormatsByFolder"; + cm.Parameters.AddWithValue("@FolderID", criteria.FolderID); + if (criteria.FormatID == null) + cm.Parameters.AddWithValue("@FormatID", DBNull.Value); + else + cm.Parameters.AddWithValue("@FormatID", criteria.FormatID); + if (criteria.NewFormatID == null) + cm.Parameters.AddWithValue("@NewFormatID", DBNull.Value); + else + cm.Parameters.AddWithValue("@NewFormatID", criteria.NewFormatID); + cm.CommandTimeout = Database.DefaultTimeout; + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + IsReadOnly = false; + while (dr.Read()) + { + ContentInfo contentInfo = new ContentInfo(dr); + this.Add(contentInfo); + } + IsReadOnly = true; + } + } + } + } + catch (Exception ex) + { + Database.LogException("ClearOverrideFormatsByFolderCriteria.DataPortal_Fetch", ex); + throw new DbCslaException("ClearOverrideFormatsByFolderCriteria.DataPortal_Fetch", ex); + } + } + public static ContentInfoList ClearOverrideFormatsByFolder(int folderID, int? formatID, int? newformatID) + { + try + { + ContentInfoList tmp = DataPortal.Fetch(new ClearOverrideFormatsByFolderCriteria(folderID, formatID, newformatID)); + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on ContentInfoList.ClearOverrideFormatsByFolder", ex); + } + } + private class ClearOverrideFormatsByDocVersionCriteria + { + public ClearOverrideFormatsByDocVersionCriteria(string dvlist, int? formatID, int?newformatID) + { + _FormatID = formatID; + _DVList = dvlist; + _NewFormatID = newformatID; + } + private int? _FormatID; + public int? FormatID + { + get { return _FormatID; } + set { _FormatID = value; } + } + private int? _NewFormatID; + public int? NewFormatID + { + get { return _NewFormatID; } + set { _NewFormatID = value; } + } + private string _DVList; + public string DVList + { + get { return _DVList; } + set { _DVList = value; } + } + } + private void DataPortal_Fetch(ClearOverrideFormatsByDocVersionCriteria criteria) + { + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "vesp_ClearOverrideFormatsByDocVersion"; + cm.Parameters.AddWithValue("@DocVersionList", criteria.DVList); + if (criteria.FormatID == null) + cm.Parameters.AddWithValue("@FormatID", DBNull.Value); + else + cm.Parameters.AddWithValue("@FormatID", criteria.FormatID); + if (criteria.NewFormatID == null) + cm.Parameters.AddWithValue("@NewFormatID", DBNull.Value); + else + cm.Parameters.AddWithValue("@NewFormatID", criteria.NewFormatID); + cm.CommandTimeout = Database.DefaultTimeout; + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + IsReadOnly = false; + while (dr.Read()) + { + ContentInfo contentInfo = new ContentInfo(dr); + this.Add(contentInfo); + } + IsReadOnly = true; + } + } + } + } + catch (Exception ex) + { + Database.LogException("ClearOverrideFormatsByDocVersion.DataPortal_Fetch", ex); + throw new DbCslaException("ClearOverrideFormatsByDocVersion.DataPortal_Fetch", ex); + } + } + public static ContentInfoList ClearOverrideFormatsByDocVersion(string dvlist, int? formatID, int? newformatID) + { + try + { + ContentInfoList tmp = DataPortal.Fetch(new ClearOverrideFormatsByDocVersionCriteria(dvlist, formatID, newformatID)); + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on ContentInfoList.ClearOverrideFormatsByDocVersion", ex); + } + } + private class ClearOverrideFormatsByItemCriteria + { + public ClearOverrideFormatsByItemCriteria(int itemID, int? formatID, int? newformatID) + { + _FormatID = formatID; + _NewFormatID = newformatID; + _ItemID = itemID; + } + private int? _FormatID; + public int? FormatID + { + get { return _FormatID; } + set { _FormatID = value; } + } + private int? _NewFormatID; + public int? NewFormatID + { + get { return _NewFormatID; } + set { _NewFormatID = value; } + } + private int _ItemID; + public int ItemID + { + get { return _ItemID; } + set { _ItemID = value; } + } + } + private void DataPortal_Fetch(ClearOverrideFormatsByItemCriteria criteria) + { + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "vesp_ClearOverrideFormatsByItem"; + cm.Parameters.AddWithValue("@ItemID", criteria.ItemID); + if (criteria.FormatID == null) + cm.Parameters.AddWithValue("@FormatID", DBNull.Value); + else + cm.Parameters.AddWithValue("@FormatID", criteria.FormatID); + if (criteria.NewFormatID == null) + cm.Parameters.AddWithValue("@NewFormatID", DBNull.Value); + else + cm.Parameters.AddWithValue("@NewFormatID", criteria.NewFormatID); + cm.CommandTimeout = Database.DefaultTimeout; + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + IsReadOnly = false; + while (dr.Read()) + { + ContentInfo contentInfo = new ContentInfo(dr); + this.Add(contentInfo); + } + IsReadOnly = true; + } + } + } + } + catch (Exception ex) + { + Database.LogException("ClearOverrideFormatsByItem.DataPortal_Fetch", ex); + throw new DbCslaException("ClearOverrideFormatsByItem.DataPortal_Fetch", ex); + } + } + public static ContentInfoList ClearOverrideFormatsByItem(int itemID, int? formatID, int? newformatID) + { + try + { + ContentInfoList tmp = DataPortal.Fetch(new ClearOverrideFormatsByItemCriteria(itemID, formatID, newformatID)); + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on ContentInfoList.ClearOverrideFormatsByItem", ex); + } + } + + + + #endregion + #region Enhanced + #region Enhanced_UnlinkItems + [Serializable()] private class EnhancedUnlinkCriteria { public EnhancedUnlinkCriteria(int? enhancedID) diff --git a/PROMS/VEPROMS.CSLA.Library/Extension/DisplayText.cs b/PROMS/VEPROMS.CSLA.Library/Extension/DisplayText.cs index 45667407..c8cae76d 100644 --- a/PROMS/VEPROMS.CSLA.Library/Extension/DisplayText.cs +++ b/PROMS/VEPROMS.CSLA.Library/Extension/DisplayText.cs @@ -1936,7 +1936,7 @@ namespace VEPROMS.CSLA.Library // return Text; //} #endregion - private static Dictionary dicReplaceRegex = new Dictionary(); + private static Dictionary dicReplaceRegex = new Dictionary(); private static bool? _ProcessReplaceWords; public static bool ProcessReplaceWords { @@ -1961,33 +1961,33 @@ namespace VEPROMS.CSLA.Library if (_MyItemInfo.MyContent.Type < 20000) return Text; // for now only replace in steps. FoundMatches myMatches = new FoundMatches(Text,_MyItemInfo.FormatStepData.Font,_MyItemInfo); // Exclude Link Text from Replace Word process - myMatches.AddLink(regFindLink, _MyFormat.PlantFormat.FormatData.SectData.ReplaceWordsInROs, _MyItemInfo.MyProcedure.MyDocVersion); - ReplaceStrList rsl = _MyFormat.PlantFormat.FormatData.SectData.ReplaceStrList; - + myMatches.AddLink(regFindLink, _MyFormat.PlantFormat.FormatData.SectData.ReplaceWordsInROs, _MyItemInfo.MyProcedure.MyDocVersion); + FormatConfig.ReplaceStrData rsl = _MyFormat.PlantFormat.UCFandOrigReplaceStrData; + // ReplaceStrData xml node is empty, it does the inheritance and gets the 'base' format's list. if (rsl.Count==1 && (rsl[0].ReplaceWord == null || rsl[0].ReplaceWord == "")) return Text; // Loop through text looking for words to be replaced - Dictionary partialReplaceList = new Dictionary(); + Dictionary partialReplaceList = new Dictionary(); Dictionary shouldReplace = new Dictionary(); //int profileDepth = ProfileTimer.Push(">>>> DoReplaceWords2.ForLoop"); - foreach (ReplaceStr rs in rsl) + foreach (FormatConfig.ReplaceStr rs in rsl) { - bool dopartial = (rs.Flag & E_ReplaceFlags.Partials) == E_ReplaceFlags.Partials; + bool dopartial = (E_ReplaceFlags)(rs.Flag & FormatConfig.E_ReplaceFlagsUCF.Partials) == E_ReplaceFlags.Partials; // note that the order of this check is important. Check in this order... // background here - if (!shouldReplace.ContainsKey(rs.Flag)) + if (!shouldReplace.ContainsKey((E_ReplaceFlags)rs.Flag)) { //int profileDepth2 = ProfileTimer.Push(">>>> Before ShouldReplaceIt"); - shouldReplace.Add(rs.Flag, ShouldReplaceIt(rs.Flag)); + shouldReplace.Add((E_ReplaceFlags)rs.Flag, ShouldReplaceIt((E_ReplaceFlags)rs.Flag)); //ProfileTimer.Pop(profileDepth2); } - bool replaceit = shouldReplace[rs.Flag]; + bool replaceit = shouldReplace[(E_ReplaceFlags)rs.Flag]; if (replaceit) { if (!dicReplaceRegex.ContainsKey(rs)) { - RegexOptions myOptions = (rs.Flag & E_ReplaceFlags.CaseInsens) == E_ReplaceFlags.CaseInsens ? RegexOptions.IgnoreCase : RegexOptions.None; + RegexOptions myOptions = (E_ReplaceFlags)(rs.Flag & FormatConfig.E_ReplaceFlagsUCF.CaseInsens) == E_ReplaceFlags.CaseInsens ? RegexOptions.IgnoreCase : RegexOptions.None; if (dopartial) { dicReplaceRegex.Add(rs, new Regex(rs.ReplaceWord, myOptions)); @@ -2028,8 +2028,8 @@ namespace VEPROMS.CSLA.Library Text = Text.Replace(@"\xA0", @"\u160?"); //replace hard space try { - foreach (ReplaceStr prs in partialReplaceList.Keys) - Text = partialReplaceList[prs].Replace(Text, prs.ReplaceWith); + foreach (FormatConfig.ReplaceStr prs in partialReplaceList.Keys) + Text = partialReplaceList[prs].Replace(Text, prs.ReplaceWith); } catch (Exception ex) // Don't crash on a format issue. { @@ -2184,7 +2184,7 @@ namespace VEPROMS.CSLA.Library _Font = font; _MyItemInfo = myItemInfo; } - public void Add(Regex myRegEx, ReplaceStr myWord) + public void Add(Regex myRegEx, FormatConfig.ReplaceStr myWord) { MatchCollection myMatches = myRegEx.Matches(_Text); foreach (Match myMatch in myMatches) @@ -2227,7 +2227,7 @@ namespace VEPROMS.CSLA.Library } return false; } - public void Add(Match myMatch, ReplaceStr myWord) + public void Add(Match myMatch, FormatConfig.ReplaceStr myWord) { // If one already exists for this location, then don't add another. if (ContainsKey(myMatch.Index)) return; @@ -2262,9 +2262,9 @@ namespace VEPROMS.CSLA.Library { //if(offset != 0 || foundMatch.MyMatch.Index != 0 || !foundMatch.MyWord.ReplaceWith.StartsWith(@"{\par}")) //{ - if (((foundMatch.MyWord.Flag & E_ReplaceFlags.DiffUnit) == 0) || DiffUnit(foundMatch.MyWord.ReplaceWord,_MyItemInfo,"UNIT ")) + if (((foundMatch.MyWord.Flag & FormatConfig.E_ReplaceFlagsUCF.DiffUnit) == 0) || DiffUnit(foundMatch.MyWord.ReplaceWord,_MyItemInfo,"UNIT ")) { - string with = foundMatch.MyWord.ReplaceWith; + string with = foundMatch.MyWord.ReplaceWith; if (offset == 0 && with.StartsWith(@"{\par}")) if(StartsWith(text,foundMatch.MyMatch.Index,"",@"\ul ",@"\b ",@"* ",@"* \ul ",@"* \b ",@"*",@"*\ul ",@"*\b ")) with = with.Replace(@"{\par}", ""); @@ -2365,13 +2365,13 @@ namespace VEPROMS.CSLA.Library get { return _MyMatch; } set { _MyMatch = value; } } - private ReplaceStr _MyWord; - public ReplaceStr MyWord + private FormatConfig.ReplaceStr _MyWord; + public FormatConfig.ReplaceStr MyWord { get { return _MyWord; } set { _MyWord = value; } } - public FoundMatch(Match myMatch, ReplaceStr myWord) + public FoundMatch(Match myMatch, FormatConfig.ReplaceStr myWord) { _MyMatch = myMatch; _MyWord = myWord; diff --git a/PROMS/VEPROMS.CSLA.Library/Extension/FormatExt.cs b/PROMS/VEPROMS.CSLA.Library/Extension/FormatExt.cs index 3cf566f2..290dced9 100644 --- a/PROMS/VEPROMS.CSLA.Library/Extension/FormatExt.cs +++ b/PROMS/VEPROMS.CSLA.Library/Extension/FormatExt.cs @@ -140,7 +140,7 @@ namespace VEPROMS.CSLA.Library [NonSerialized] private PlantFormat _PlantFormat; public PlantFormat PlantFormat - { get { return (_PlantFormat != null ? _PlantFormat : _PlantFormat = new PlantFormat(this)); } } + { get { return (_PlantFormat != null ? _PlantFormat : _PlantFormat = new PlantFormat(this, Config)); } } #endregion public static event FormatEvent FormatLoaded; private static void OnFormatLoaded(object sender, FormatEventArgs args) @@ -517,11 +517,75 @@ namespace VEPROMS.CSLA.Library throw new DbCslaException("FormatInfo.DataPortal_Fetch", ex); } } + // Get format data, but do not resolve the 'Data' and 'Genmac' fields, i.e. keep empty if they are + // empty. + public static FormatInfo GetFormatNoUCFByFormatID(int formatID) + { + try + { + FormatInfo tmp = DataPortal.Fetch(new FormatIDNoUCFCriteria(formatID)); + if (tmp.ErrorMessage == "No Record Found") + { + tmp.Dispose(); // Clean-up FormatInfo + tmp = null; + } + return tmp; + } + catch (Exception ex) + { + throw new DbCslaException("Error on FormatInfo.GetFormatNoUCFByFormatID", ex); + } + } + protected class FormatIDNoUCFCriteria + { + private int _FormatID; + public int FormatID { get { return _FormatID; } } + public FormatIDNoUCFCriteria(int formatID) + { + _FormatID = formatID; + } + } + private void DataPortal_Fetch(FormatIDNoUCFCriteria criteria) + { + if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] FormatInfo.DataPortal_Fetch", GetHashCode()); + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + ApplicationContext.LocalContext["cn"] = cn; + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getFormatNoUCF"; + cm.Parameters.AddWithValue("@FormatID", criteria.FormatID); + cm.CommandTimeout = Database.DefaultTimeout; + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + if (!dr.Read()) + { + _ErrorMessage = "No Record Found"; + return; + } + ReadData(dr); + } + } + // removing of item only needed for local data portal + if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client) + ApplicationContext.LocalContext.Remove("cn"); + } + } + catch (Exception ex) + { + if (_MyLog.IsErrorEnabled) _MyLog.Error("FormatInfo.DataPortal_Fetch", ex); + _ErrorMessage = ex.Message; + throw new DbCslaException("FormatInfo.DataPortal_Fetch", ex); + } + } #region PlantFormat [NonSerialized] private PlantFormat _PlantFormat; public PlantFormat PlantFormat - { get { return (_PlantFormat != null ? _PlantFormat : _PlantFormat = new PlantFormat(this)); } } + { get { return (_PlantFormat != null ? _PlantFormat : _PlantFormat = new PlantFormat(this, Config)); } } #endregion public IFormatOrFormatInfo MyIParent { get { return MyParent; } } public override string ToString() @@ -608,6 +672,51 @@ namespace VEPROMS.CSLA.Library return _SortedFormatInfoList; } } + public static FormatInfoList GetFormatInfoListUsed() + { + try + { + FormatInfoList fvl = (FormatInfoList)DataPortal.Fetch(new FormatInfoListUsedCriteria()); + return fvl; + } + catch (Exception ex) + { + throw new DbCslaException("FormatVersionList.DataPortal_Fetch GetFormatVersions", ex); + } + } + protected class FormatInfoListUsedCriteria + { + } + private void DataPortal_Fetch(FormatInfoListUsedCriteria criteria) + { + try + { + using (SqlConnection cn = Database.VEPROMS_SqlConnection) + { + using (SqlCommand cm = cn.CreateCommand()) + { + cm.CommandType = CommandType.StoredProcedure; + cm.CommandText = "getFormatListUsed"; + cm.CommandTimeout = Database.DefaultTimeout; + using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader())) + { + while (dr.Read()) + { + FormatInfo formatInfo = new FormatInfo(dr); + IsReadOnly = false; + this.Add(formatInfo); + IsReadOnly = true; + } + } + } + } + } + catch (Exception ex) + { + Database.LogException("FormatInfoList.DataPortal_Fetch", ex); + throw new DbCslaException("FormatInfoList.DataPortal_Fetch", ex); + } + } } public class FormatVersion { diff --git a/PROMS/VEPROMS.CSLA.Library/Extension/ItemExt.cs b/PROMS/VEPROMS.CSLA.Library/Extension/ItemExt.cs index 8a494238..43bddd0b 100644 --- a/PROMS/VEPROMS.CSLA.Library/Extension/ItemExt.cs +++ b/PROMS/VEPROMS.CSLA.Library/Extension/ItemExt.cs @@ -5185,7 +5185,8 @@ namespace VEPROMS.CSLA.Library // To determine if the section has a checkoff... // Section won't have checkoffs if there is no checkofflist, or ProcData pd = ActiveFormat.PlantFormat.FormatData.ProcData; - if (pd.CheckOffData == null || pd.CheckOffData.CheckOffList == null || pd.CheckOffData.CheckOffList.MaxIndex <= 0) return false; + int maxindx = pd.CheckOffUCF ? pd.CheckOffData.CheckOffList.MaxIndex : pd.CheckOffData.CheckOffList.MaxIndexNoInherit; + if (pd.CheckOffData == null || pd.CheckOffData.CheckOffList == null || maxindx <= 0) return false; if (pd.CheckOffData.CheckOffHeaderList == null || pd.CheckOffData.CheckOffHeaderList.MaxIndex <= 1) return true; //if (pd.CheckOffData == null || pd.CheckOffData.CheckOffHeaderList == null || pd.CheckOffData.CheckOffHeaderList.Count <= 1) return false; @@ -5216,7 +5217,8 @@ namespace VEPROMS.CSLA.Library private int SectionDefaultCheckOffIndex() { ProcData pd = ActiveFormat.PlantFormat.FormatData.ProcData; - if (pd.CheckOffData != null && pd.CheckOffData.CheckOffList != null && pd.CheckOffData.CheckOffList.MaxIndex == 2) return 0; // if only two items, first is macro - use it. + int maxindx = pd.CheckOffUCF ? pd.CheckOffData.CheckOffList.MaxIndex : pd.CheckOffData.CheckOffList.MaxIndexNoInherit; + if (pd.CheckOffData != null && pd.CheckOffData.CheckOffList != null && maxindx == 2) return 0; // if only two items, first is macro - use it. SectionConfig sc = ActiveSection.MyConfig as SectionConfig; return sc.Section_CheckoffListSelection; } @@ -5227,7 +5229,23 @@ namespace VEPROMS.CSLA.Library if (!SectionHasCheckOffs()) return null; int stpCoIndx = CheckOffIndex(); // this step has a checkoff defined if (stpCoIndx == -1) return null; - if (stpCoIndx > 1) return ActiveFormat.PlantFormat.FormatData.ProcData.CheckOffData.CheckOffList[stpCoIndx]; + if (stpCoIndx > 1) + { + if (ActiveFormat.PlantFormat.FormatData.ProcData.CheckOffUCF && stpCoIndx >= 100) + { + // get index, if greater than 100, store that - otherwise store index down list. + // if this format does not have ucf signoffs, indx is just the selected index from the combo box. + foreach (CheckOff co in ActiveFormat.PlantFormat.FormatData.ProcData.CheckOffData.CheckOffList) + { + if (stpCoIndx == co.Index) + { + stpCoIndx = (int)co.Index; + break; + } + } + } + return ActiveFormat.PlantFormat.FormatData.ProcData.CheckOffData.CheckOffList[stpCoIndx]; // DO override of CheckOffList[] to get ucf + } int sectCoIndx = SectionDefaultCheckOffIndex(); // no checkoff on step, see if there is a section default. if (sectCoIndx == -1) return null; if ((ActiveFormat.PlantFormat.FormatData.ProcData.CheckOffData.CheckOffOnHLSOnly && IsHigh) @@ -5261,7 +5279,8 @@ namespace VEPROMS.CSLA.Library get { ProcData pd = ActiveFormat.PlantFormat.FormatData.ProcData; - if (pd.CheckOffData != null && pd.CheckOffData.CheckOffList != null && pd.CheckOffData.CheckOffList.MaxIndex == 2 && pd.CheckOffData.CheckOffList[0].MenuItem == "Enabled") + int maxindx = pd.CheckOffUCF ? pd.CheckOffData.CheckOffList.MaxIndex : pd.CheckOffData.CheckOffList.MaxIndexNoInherit; + if (pd.CheckOffData != null && pd.CheckOffData.CheckOffList != null && maxindx == 2 && pd.CheckOffData.CheckOffList[0].MenuItem == "Enabled") return true; // if only two items, first is macro - use it. return false; } diff --git a/PROMS/VEPROMS.CSLA.Library/Format/Comparator.cs b/PROMS/VEPROMS.CSLA.Library/Format/Comparator.cs new file mode 100644 index 00000000..14e7fc87 --- /dev/null +++ b/PROMS/VEPROMS.CSLA.Library/Format/Comparator.cs @@ -0,0 +1,335 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Xml; +using System.Windows.Forms; + +namespace VEPROMS.CSLA.Library +{ + public class Comparator + { + private XmlDocument _ResultsDoc; + public XmlDocument ResultsDoc + { + get { return _ResultsDoc; } + set { _ResultsDoc = value; } + } + private XmlDocument _XDoc1; + public XmlDocument XDoc1 + { + get { return _XDoc1; } + set { _XDoc1 = value; } + } + private XmlDocument _XDoc2; + public XmlDocument XDoc2 + { + get { return _XDoc2; } + set { _XDoc2 = value; } + } + public Comparator(XmlDocument xdoc1, XmlDocument xdoc2) + { + XDoc1 = xdoc1; + XDoc2 = xdoc2; + ResultsDoc = new XmlDocument(); + ResultsDoc.LoadXml(@""); + } + public Comparator(string existingFC, string importedFC) //string fName1, string fName2) + { + XDoc1 = new XmlDocument(); + XDoc1.LoadXml(existingFC); + XDoc2 = new XmlDocument(); + XDoc2.LoadXml(importedFC); + ResultsDoc = new XmlDocument(); + ResultsDoc.LoadXml(@""); + } + public XmlDocument Compare() + { + AllKeys = null; + Compare(XDoc1.DocumentElement, XDoc2.DocumentElement, ""); + Console.WriteLine("results xml = \r\n{0}", ResultsDoc.InnerXml); + return ResultsDoc; + } + public void Compare(XmlNode xn1, XmlNode xn2, string path) + { + if (xn1.OuterXml == xn2.OuterXml) return; + Compare(xn1.Attributes, xn2.Attributes , path, xn1, xn2); + xn1.Attributes.RemoveAll(); + xn2.Attributes.RemoveAll(); + + Dictionary xns1 = new Dictionary(); // child nodes, key = 'OuterXml', value = node itself + Dictionary xns2 = new Dictionary(); + // xns1 starts out with all child nodes of xn1 + foreach (XmlNode xc1 in xn1.ChildNodes) + xns1.Add(xc1.OuterXml + GetKey(xc1), xc1); + // xns1 - remove any matching child nodes from xns2 + // xns2 - has nodes that are not in xns1 + foreach (XmlNode xc2 in xn2.ChildNodes) + if (xns1.ContainsKey(xc2.OuterXml + GetKey(xc2))) + xns1.Remove(xc2.OuterXml + GetKey(xc2)); + else + xns2.Add(xc2.OuterXml+GetKey(xc2), xc2); + + // xnss1 & xnss2 are dictionaries based on a unique key + Dictionary xnss1 = new Dictionary(); + Dictionary xnss2 = new Dictionary(); + foreach (XmlNode xc1 in xns1.Values) + xnss1.Add(GetKey(xc1), xc1); + foreach (XmlNode xc2 in xns2.Values) + if (xnss1.ContainsKey(GetKey(xc2))) + Compare(xnss1[GetKey(xc2)], xc2, path + "/" + GetKey(xc2)); + else + xnss2.Add(GetKey(xc2), xc2); + // element differences, if counts are different. xns1 elements are not found in xns2 and xns2 elements are not found in xns1 + if (xns1.Count == 0 && xns2.Count == 0) return; + xns1 = new Dictionary(); // child nodes, key = 'OuterXml', value = node itself + xns2 = new Dictionary(); + // xns1 starts out with all child nodes of xn1 + foreach (XmlNode xc1 in xn1.ChildNodes) + { + xns1.Add(xc1.OuterXml+GetKey(xc1), xc1); + } + // xns1 - remove any matching child nodes from xns2 + // xns2 - has nodes that are not in xns1 + foreach (XmlNode xc2 in xn2.ChildNodes) + if (xns1.ContainsKey(xc2.OuterXml + GetKey(xc2))) + xns1.Remove(xc2.OuterXml + GetKey(xc2)); + else + xns2.Add(xc2.OuterXml + GetKey(xc2), xc2); + + // xnss1 & xnss2 are dictionaries based on a unique key + xnss1 = new Dictionary(); + xnss2 = new Dictionary(); + foreach (XmlNode xc1 in xns1.Values) + xnss1.Add(GetKey(xc1), xc1); + foreach (XmlNode xc2 in xns2.Values) + if (xnss1.ContainsKey(GetKey(xc2))) + Compare(xnss1[GetKey(xc2)], xc2, path + "/" + GetKey(xc2)); + else + xnss2.Add(GetKey(xc2), xc2); + // element differences, if counts are different. xns1 elements are not found in xns2 and xns2 elements are not found in xns1 + if (xns1.Count == 0 && xns2.Count == 0) return; + Console.WriteLine(" {0} {1} {2}", path + "/" + xn1.Name, xns1.Count, xns2.Count); + foreach (string key in xnss1.Keys) + { + if (xnss1[key].Attributes.Count > 0 || xnss1[key].ChildNodes.Count > 0) + { + XmlNode xnr = MakeXPathFormat(path); + if (xnr != null) + { + XmlNode cloned = xnss1[key].CloneNode(true); + XmlNode importNode = ResultsDoc.ImportNode(cloned, true); + XmlNode resnd = xnr.AppendChild(importNode); + XmlAttribute xKey = ResultsDoc.CreateAttribute("Mode"); + xKey.Value = "Deleted"; + resnd.Attributes.Append(xKey); + xKey = ResultsDoc.CreateAttribute("OldKey"); + xKey.Value = GetKey(xnss1[key]); + resnd.Attributes.Append(xKey); + xnr.AppendChild(resnd); + if (resnd.ChildNodes.Count > 0) + { + foreach (XmlNode cxn in resnd.ChildNodes) if (cxn.Name == "Layout") SuffixAttributes("Old", cxn); + } + } + } + xnss1[key].ParentNode.RemoveChild(xnss1[key]); + } + + foreach (string key in xnss2.Keys) + { + if (xnss2[key].Attributes.Count > 0 || xnss2[key].ChildNodes.Count > 0) + { + XmlNode xnr = MakeXPathFormat(path); + if (xnr != null) + { + XmlNode cloned = xnss2[key].CloneNode(true); + XmlNode importNode = ResultsDoc.ImportNode(cloned, true); + XmlNode resnd = xnr.AppendChild(importNode); + + // if this has subnodes, add the 'Inserted' mode on them, otherwise, out it on this level + if (resnd.ChildNodes.Count > 0) + { + foreach (XmlNode cxn in resnd.ChildNodes) + { + if (cxn.Name=="Layout") SuffixAttributes("New", cxn); + XmlAttribute xKey = ResultsDoc.CreateAttribute("Mode"); + xKey.Value = "Inserted"; + if (cxn is XmlText) + resnd.Attributes.Append(xKey); + else + cxn.Attributes.Append(xKey); // crashing here on a flag difference - trying to append this attribute to 'false'. + } + } + else + { + XmlAttribute xKey = ResultsDoc.CreateAttribute("Mode"); + xKey.Value = "Inserted"; + resnd.Attributes.Append(xKey); + } + XmlAttribute xKey1 = ResultsDoc.CreateAttribute("NewKey"); + xKey1.Value = GetKey(xnss2[key]); + resnd.Attributes.Append(xKey1); + xnr.AppendChild(resnd); + } + } + xnss2[key].ParentNode.RemoveChild(xnss2[key]); + } + } + + private void SuffixAttributes(string suffix, XmlNode resnd) + { + Dictionary renameList = new Dictionary(); + foreach (XmlAttribute xa in resnd.Attributes) renameList.Add(xa.Name, xa.Value); + foreach (string key in renameList.Keys) + { + resnd.Attributes.RemoveNamedItem(key); + XmlAttribute xKey1 = ResultsDoc.CreateAttribute(key+suffix); + xKey1.Value = renameList[key]; + resnd.Attributes.Append(xKey1); + } + } + private Dictionary _AllKeys; + public Dictionary AllKeys + { + get + { + if (_AllKeys == null) _AllKeys = new Dictionary(); + return _AllKeys; + } + set { _AllKeys = value; } + } + public string GetKey(XmlNode xn) + { + string key = GetKey1(xn); + if (AllKeys.ContainsKey(xn)) return AllKeys[xn]; + AllKeys.Add(xn, key); + return key; + } + // Get unique key, key is a string representing either the name itself or a combination of element name/attribute to make it unique + public string GetKey1(XmlNode xn) + { + if (xn.Attributes == null) return xn.Name; + XmlAttribute xi = xn.Attributes.GetNamedItem("Index") as XmlAttribute; + if (xi != null) + { + XmlAttribute xa = xn.Attributes.GetNamedItem("Name") as XmlAttribute; + if (xa != null) return string.Format("{0}[{1}]", xn.Name, xa.Value); + return string.Format("{0}[{1}]", xn.Name, xi.Value); + } + XmlAttribute xt = xn.Attributes.GetNamedItem("Token") as XmlAttribute; + if(xt != null) return string.Format("{0}[{1}]", xn.Name, xt.Value); + XmlAttribute xw = xn.Attributes.GetNamedItem("ReplaceWord") as XmlAttribute; + if(xw != null) return string.Format("{0}[{1}]", xn.Name, xw.Value); + return xn.Name; + } + static private XmlNode makeXPath(XmlDocument doc, string xpath) + { + xpath = xpath.Replace(@"DocStyle[", @"DocStyle[@Name='"); + xpath = xpath.Replace(@"]", "']"); + return makeXPath(doc, doc as XmlNode, xpath); + } + + static private XmlNode makeXPath(XmlDocument doc, XmlNode parent, string xpath) + { + if (xpath.Contains("DocStyle")) Console.WriteLine("here"); + // grab the next node name in the xpath; or return parent if empty + string[] partsOfXPath = xpath.Trim('/').Split('/'); + string nextNodeInXPath = partsOfXPath.First(); + if (string.IsNullOrEmpty(nextNodeInXPath)) + return parent; + + XmlNode node = parent.SelectSingleNode(nextNodeInXPath); + if (node == null) + { + if (nextNodeInXPath.Contains("@")) // element with an attribute, create both + { + // make element + string elename = nextNodeInXPath.Substring(0, nextNodeInXPath.IndexOf("@") - 1); + node = parent.AppendChild(doc.CreateElement(elename)); + // make attribute + int indx = nextNodeInXPath.IndexOf("@")+1; + string name = nextNodeInXPath.Substring(indx, nextNodeInXPath.IndexOf("=",indx)-indx); + XmlAttribute xKeyd = doc.CreateAttribute(name); + indx = nextNodeInXPath.IndexOf("='",indx)+2; + string value = nextNodeInXPath.Substring(indx,nextNodeInXPath.IndexOf("'", indx) - indx); + xKeyd.Value = nextNodeInXPath.Substring(indx,nextNodeInXPath.IndexOf("'",indx)-indx); + node.Attributes.Append(xKeyd); + } + else + node = parent.AppendChild(doc.CreateElement(nextNodeInXPath)); + } + + // rejoin the remainder of the array as an xpath expression and recurse + string rest = String.Join("/", partsOfXPath.Skip(1).ToArray()); + return makeXPath(doc, node, rest); + } + + private XmlNode MakeXPathFormat(string xpath) + { + // first find or make, if not found, the XmlElement within FormatData or DocStyles + Console.WriteLine("path = {0}", xpath); + return makeXPath(ResultsDoc, xpath); + } + #region Attributes + private void Compare(XmlAttributeCollection atts1, XmlAttributeCollection atts2, string path, XmlNode atts1Par, XmlNode atts2Par) + { + // go through attributes in first xml document, see if they exist in the 2nd xml document & are identical attribute + foreach (XmlAttribute xa1 in atts1) + { + XmlAttribute xa2 = atts2.GetNamedItem(xa1.Name) as XmlAttribute; + if (xa2 == null) + { + XmlNode xnr = MakeXPathFormat(path); + if (xnr != null) + { + XmlAttribute xKey = ResultsDoc.CreateAttribute(xa1.Name+"Old"); + xKey.Value = xa1.Value; + xnr.Attributes.Append(xKey); + xKey = ResultsDoc.CreateAttribute("OldKey"); + xKey.Value = GetKey(atts1Par); + if (xKey.Value != null) xnr.Attributes.Append(xKey); + } + } + else if (xa2.Value != xa1.Value) + { + XmlNode xnr = MakeXPathFormat(path); + if (xnr != null) + { + XmlAttribute xKey = ResultsDoc.CreateAttribute(xa1.Name + "Old"); + xKey.Value = xa1.Value; + xnr.Attributes.Append(xKey); + XmlAttribute xKey2 = ResultsDoc.CreateAttribute(xa2.Name + "New"); + xKey2.Value = xa2.Value; + xnr.Attributes.Append(xKey2); + xKey = ResultsDoc.CreateAttribute("OldKey"); + xKey.Value = GetKey(atts1Par); + if (xKey.Value != null) xnr.Attributes.Append(xKey); + xKey = ResultsDoc.CreateAttribute("NewKey"); + xKey.Value = GetKey(atts2Par); + if (xKey.Value != null) xnr.Attributes.Append(xKey); + } + } + } + // go through attributes in 2nd xml document to see if they exist in the first xml document & are identical + foreach (XmlAttribute xa2 in atts2) + { + XmlAttribute xa1 = atts1.GetNamedItem(xa2.Name) as XmlAttribute; + if (xa1 == null) + { + XmlNode xnr = MakeXPathFormat(path); + if (xnr != null) + { + XmlAttribute xKey = ResultsDoc.CreateAttribute(xa2.Name+"New"); + xKey.Value = xa2.Value; + xnr.Attributes.Append(xKey); + xKey = ResultsDoc.CreateAttribute("NewKey"); + xKey.Value = GetKey(atts2Par); + if (xKey.Value != null) xnr.Attributes.Append(xKey); + } + } + } + } + #endregion + } +} diff --git a/PROMS/VEPROMS.CSLA.Library/Format/DocStyles.cs b/PROMS/VEPROMS.CSLA.Library/Format/DocStyles.cs index 60a7ed60..748419e0 100644 --- a/PROMS/VEPROMS.CSLA.Library/Format/DocStyles.cs +++ b/PROMS/VEPROMS.CSLA.Library/Format/DocStyles.cs @@ -515,7 +515,29 @@ namespace VEPROMS.CSLA.Library { get { - return LazyLoad(ref _LeftMargin, "@LeftMargin"); + if (PlantFormat.IgnoreUCF) return LazyLoad(ref _LeftMargin, "@LeftMargin"); + if (MyFormat.PlantFormat.FormatConfig == null) return LazyLoad(ref _LeftMargin, "@LeftMargin"); + + // see if there is UCF data, need to match the index of the ucf data to that in the original format, and + // also need to check that LeftMargin is not null, since other docstyle data may exist in UCF but not PageLength: + XmlNode par = this.XmlNode.ParentNode; + string indx = null; + XmlElement ele = par as XmlElement; + if (ele.HasAttribute("Index")) indx = ele.GetAttribute("Index"); + if (indx == null) return LazyLoad(ref _PageLength, "@LeftMargin"); + if (MyFormat.PlantFormat.FormatConfig != null && this.MyFormat.PlantFormat.FormatConfig.PlantFormat.DocStyles != null && MyFormat.PlantFormat.FormatConfig.PlantFormat.DocStyles.Count > 0) + { + foreach (FormatConfig.DocStyle ds in MyFormat.PlantFormat.FormatConfig.PlantFormat.DocStyles) + { + if (indx == ds.Index) + { + float? test = ds.Layout.LeftMargin; + if (test != null) _LeftMargin = new LazyLoad(ds.Layout.LeftMargin); + break; + } + } + } + return LazyLoad(ref _LeftMargin, "@LeftMargin"); } } #endregion @@ -526,10 +548,33 @@ namespace VEPROMS.CSLA.Library [Description("Length of Page")] public float? PageLength { - get - { - return LazyLoad(ref _PageLength, "@PageLength"); - } + get + { + if (PlantFormat.IgnoreUCF) return LazyLoad(ref _PageLength, "@PageLength"); + if (MyFormat.PlantFormat.FormatConfig == null) return LazyLoad(ref _PageLength, "@PageLength"); + + // see if there is UCF data, need to match the index of the ucf data to that in the original format, and + // also need to check that PageLength is not null, since other docstyle data may exist in UCF but not PageLength: + XmlNode par = this.XmlNode.ParentNode; + string indx = null; + XmlElement ele = par as XmlElement; + if (ele.HasAttribute("Index")) indx = ele.GetAttribute("Index"); + if (indx == null) return LazyLoad(ref _PageLength, "@PageLength"); + if (MyFormat.PlantFormat.FormatConfig != null && this.MyFormat.PlantFormat.FormatConfig.PlantFormat.DocStyles != null && MyFormat.PlantFormat.FormatConfig.PlantFormat.DocStyles.Count > 0) + { + foreach (FormatConfig.DocStyle ds in MyFormat.PlantFormat.FormatConfig.PlantFormat.DocStyles) + { + if (indx == ds.Index) + { + float? test = ds.Layout.PageLength; + if (test != null) _PageLength = new LazyLoad(ds.Layout.PageLength); + break; + } + } + } + + return LazyLoad(ref _PageLength, "@PageLength"); + } } #endregion #region PageWidth diff --git a/PROMS/VEPROMS.CSLA.Library/Format/ENums.cs b/PROMS/VEPROMS.CSLA.Library/Format/ENums.cs index bd3c7f6d..0cc16b76 100644 --- a/PROMS/VEPROMS.CSLA.Library/Format/ENums.cs +++ b/PROMS/VEPROMS.CSLA.Library/Format/ENums.cs @@ -247,5 +247,13 @@ namespace VEPROMS.CSLA.Library SupInfoPdfPrint = 2, Merge = 3 } + public enum E_UCFImportOptions : uint + { + Ignore = 0, + LoadNotUsed = 1, + LoadOnlyImported = 2, + LoadUseAll = 3, + LoadForSetOnly = 4 + } #endregion } diff --git a/PROMS/VEPROMS.CSLA.Library/Format/PlantFormat.cs b/PROMS/VEPROMS.CSLA.Library/Format/PlantFormat.cs index 31bb2408..45a5eb9a 100644 --- a/PROMS/VEPROMS.CSLA.Library/Format/PlantFormat.cs +++ b/PROMS/VEPROMS.CSLA.Library/Format/PlantFormat.cs @@ -11,9 +11,56 @@ namespace VEPROMS.CSLA.Library [TypeConverter(typeof(ExpandableObjectConverter))] public class PlantFormat { - public PlantFormat(IFormatOrFormatInfo format) + public PlantFormat(IFormatOrFormatInfo format, string config) { _MyFormat = format; + string str = null; + if (format is Format) str = (format as Format).Config; + else if (format is FormatInfo) str = (format as FormatInfo).Config; + if (str != null && str != "") _FormatConfig = FormatConfig.Get(str); + } + private FormatConfig _FormatConfig; + public FormatConfig FormatConfig + { + get + { + if (_FormatConfig == null) + { + _FormatConfig = GetFormatConfig(_MyFormat); + } + return _FormatConfig; + } + set { _FormatConfig = value; } + } + // when IgnoreUCF is true, get the original data, i.e. don't apply any UCF changes to it + private static bool _IgnoreUCF = false; + public static bool IgnoreUCF + { + get { return PlantFormat._IgnoreUCF; } + set { PlantFormat._IgnoreUCF = value; } + } + // flags that the User Control of Format setting for using additional UCF checkoffs is active + private static bool _DoingUCFCheckOffs = false; + public static bool DoingUCFCheckOffs + { + get { return PlantFormat._DoingUCFCheckOffs; } + set { PlantFormat._DoingUCFCheckOffs = value; } + } + // flags the value that should be used (true/false) for using additional UCF checkoffs (used with DoingUCFCheckOffs) + private static bool _DoingUCFCheckOffsUse = false; + public static bool DoingUCFCheckOffsUse + { + get { return PlantFormat._DoingUCFCheckOffsUse; } + set { PlantFormat._DoingUCFCheckOffsUse = value; } + } + public static FormatConfig GetFormatConfig(IFormatOrFormatInfo format) + { + FormatConfig fc = null; + string str = null; + if (format is Format) str = (format as Format).Config; + else if (format is FormatInfo) str = (format as FormatInfo).Config; + if (str != null && str != "") fc = FormatConfig.Get(str); + return fc; } private IFormatOrFormatInfo _MyFormat; public IFormatOrFormatInfo MyFormat @@ -58,12 +105,76 @@ namespace VEPROMS.CSLA.Library return _DocStyles; } } - public bool HasPageListToken(string token) - {; - string xpath = string.Format("/PlantFormat/PageStyles/PageStyle/Item[@Token = '{0}']", token); - XmlNodeList nl = XmlDoc.SelectNodes(xpath); - return nl.Count > 0; - } + public bool HasPageListToken(string token) + { + string xpath = string.Format("/PlantFormat/PageStyles/PageStyle/Item[@Token = '{0}']", token); + XmlNodeList nl = XmlDoc.SelectNodes(xpath); + return nl.Count > 0; + } + private FormatConfig.ReplaceStrData _UCFandOrigReplaceStrData = null; + public FormatConfig.ReplaceStrData UCFandOrigReplaceStrData + { + get + { + if (_UCFandOrigReplaceStrData != null) return _UCFandOrigReplaceStrData; + _UCFandOrigReplaceStrData = GetMergedReplaceList(this); + return _UCFandOrigReplaceStrData; + } + } + private FormatConfig.ReplaceStrData GetMergedReplaceList(PlantFormat OriginalPlantFormat) + { + // need to compare the original format list with the list as it is stored for working with property grid. + FormatConfig.ReplaceStrData retlist = new FormatConfig.ReplaceStrData(); // merged list + List inoriglist = new List(); // use this list to find new items in formatconfig (see below) + foreach (ReplaceStr origrepstr in OriginalPlantFormat.FormatData.SectData.ReplaceStrList) + { + // In the format config list (UCF), find the 'ReplaceWord'. This is the 'key' for defining whether the + // replace word has been overwridden by UCF data. If it exists, use it: + FormatConfig.ReplaceStr usethisone = null; + bool deleted = false; + // States for replacewords: 0 = no change, -1 deleted, 1 added, 2 modified + if (FormatConfig != null) + { + foreach (FormatConfig.ReplaceStr ucfrepstr in FormatConfig.PlantFormat.FormatData.ReplaceStrData) + { + if (ucfrepstr.ReplaceWord == origrepstr.ReplaceWord) + { + if (ucfrepstr.State == -1) deleted = true; + else usethisone = ucfrepstr; + ucfrepstr.State = 2; + inoriglist.Add(origrepstr.ReplaceWord); + break; + } + } + } + if (!deleted && usethisone == null) + { + usethisone = new FormatConfig.ReplaceStr(); + usethisone.Flag = (FormatConfig.E_ReplaceFlagsUCF)origrepstr.Flag; + usethisone.State = 0; // no change + usethisone.ReplaceWith = origrepstr.ReplaceWith; + usethisone.ReplaceWord = origrepstr.ReplaceWord; + } + if (!deleted) retlist.Add(usethisone); + } + // now add in any ucf only replacements, any that are not in the inoriglist + if (FormatConfig != null) + { + foreach (FormatConfig.ReplaceStr ucfrepstr in FormatConfig.PlantFormat.FormatData.ReplaceStrData) + { + if (!inoriglist.Contains(ucfrepstr.ReplaceWord)) + { + FormatConfig.ReplaceStr newone = new FormatConfig.ReplaceStr(); + newone.Flag = (FormatConfig.E_ReplaceFlagsUCF)ucfrepstr.Flag; + newone.State = 1; + newone.ReplaceWith = ucfrepstr.ReplaceWith; + newone.ReplaceWord = ucfrepstr.ReplaceWord; + retlist.Add(newone); + } + } + } + return (retlist); + } } #endregion #region VE_Font @@ -71,12 +182,20 @@ namespace VEPROMS.CSLA.Library public class VE_Font : vlnFormatItem { public VE_Font(XmlNode xmlNode) : base(xmlNode) { } + private string _ffam = null; + private int _fsize = 0; + private E_Style _fstyle = E_Style.None; + private float _fcpi = 0; public VE_Font(string family, int size, E_Style style, float CPI) { _Family = new LazyLoad(family); _Size = new LazyLoad(size); _Style = new LazyLoad(style); _CPI = new LazyLoad(CPI); + _ffam = family; + _fsize = size; + _fstyle = style; + _fcpi = CPI; } private LazyLoad _Family; private static Dictionary _WinFontLookup = new Dictionary(); @@ -127,10 +246,15 @@ namespace VEPROMS.CSLA.Library style |= FontStyle.Underline; } // for now - check size to be 0 and set to 10 if so, error in fmtxml? - if (Family == null) // Need to get inherited font - _WindowsFont = GetFont("Arial", 10, FontStyle.Regular); - else - _WindowsFont = GetFont(Family, Size == 0 ? 10 : (float)Size, style); + if (Family == null) // Need to get inherited font + _WindowsFont = GetFont("Arial", 10, FontStyle.Regular); + else + { + //if (_ffam != null) + // _WindowsFont = GetFont(_ffam, (float)_fsize, style); // this needs work. + //else + _WindowsFont = GetFont(Family, Size == 0 ? 10 : (float)Size, style); + } } return _WindowsFont; } @@ -1107,13 +1231,13 @@ namespace VEPROMS.CSLA.Library [TypeConverter(typeof(ExpandableObjectConverter))] public class ProcData : vlnFormatItem { - public ProcData(XmlNode xmlNode): base(xmlNode) {} + public ProcData(XmlNode xmlNode) : base(xmlNode) { } private ProcedureSuffixList _ProcedureSuffixList; public ProcedureSuffixList ProcedureSuffixList { get { - return _ProcedureSuffixList == null? _ProcedureSuffixList = new ProcedureSuffixList(SelectNodes("ProcedureSuffix/string")): _ProcedureSuffixList; + return _ProcedureSuffixList == null ? _ProcedureSuffixList = new ProcedureSuffixList(SelectNodes("ProcedureSuffix/string")) : _ProcedureSuffixList; } set { _ProcedureSuffixList = value; } } @@ -1122,7 +1246,7 @@ namespace VEPROMS.CSLA.Library { get { - return _ChangeBarData == null? _ChangeBarData = new ChangeBarData(SelectSingleNode("ChangeBarData")):_ChangeBarData; + return _ChangeBarData == null ? _ChangeBarData = new ChangeBarData(SelectSingleNode("ChangeBarData")) : _ChangeBarData; } } private CheckOffData _CheckOffData; @@ -1130,7 +1254,7 @@ namespace VEPROMS.CSLA.Library { get { - return _CheckOffData == null? _CheckOffData = new CheckOffData(SelectSingleNode("CheckOffData")):_CheckOffData; + return _CheckOffData == null ? _CheckOffData = new CheckOffData(SelectSingleNode("CheckOffData")) : _CheckOffData; } } private PSI _PSI; @@ -1141,29 +1265,47 @@ namespace VEPROMS.CSLA.Library return _PSI == null ? _PSI = new PSI(SelectSingleNode("PSI")) : _PSI; } } + private LazyLoad _CheckOffUCF; + public bool CheckOffUCF + { + get + { + // The following line is used in UCF: this needs to be able to control a change in setting in UCF versus its use: + // This is a special case since the original format, using the value in BaseAll, is always 'false'. And the value + // should never be set in original volian plant format files, if the additional UCF checkoffs are to be used, this must + // be set in the UCF user interface. + if (PlantFormat.DoingUCFCheckOffs) return PlantFormat.DoingUCFCheckOffsUse; + + if (PlantFormat.IgnoreUCF) return LazyLoad(ref _CheckOffUCF, "@CheckOffUCF"); + bool? localvalue = null; // comes to here if in edit or print - use any UCF data before going to original format. + FormatConfig fc = PlantFormat.GetFormatConfig(MyFormat); + if (fc != null) localvalue = fc.PlantFormat.FormatData.Flags.CheckOffUCF; + return localvalue ?? LazyLoad(ref _CheckOffUCF, "@CheckOffUCF"); + } + } private LazyLoad _TitleLength; public int? TitleLength - { - get + { + get { return LazyLoad(ref _TitleLength, "@TitleLength"); - } + } } private LazyLoad _CoverTitleLength; public int? CoverTitleLength - { - get + { + get { return LazyLoad(ref _CoverTitleLength, "@CoverTitleLength"); - } + } } private LazyLoad _ProcedureSuffixFlags; public string ProcedureSuffixFlags - { - get + { + get { - return LazyLoad(ref _ProcedureSuffixFlags, "@ProcedureSuffixFlags"); - } + return LazyLoad(ref _ProcedureSuffixFlags, "@ProcedureSuffixFlags"); + } } private LazyLoad _CapitalizeTitle; public bool CapitalizeTitle @@ -1503,22 +1645,146 @@ namespace VEPROMS.CSLA.Library public class CheckOffData : vlnFormatItem { public CheckOffData(XmlNode xmlNode) : base(xmlNode) { } - private CheckOffList _CheckOffList; + private CheckOffList _CheckOffList = null; public CheckOffList CheckOffList { get { - return _CheckOffList == null? _CheckOffList = new CheckOffList(SelectNodes("CheckOffList/CheckOff"),MyFormat):_CheckOffList; + if (_CheckOffList != null) return _CheckOffList; + + // Get a list of checkoffs that should be included: + // if !UseCheckOffUCF (Baseall has it as false. User can change setting in UCF to true) + // if !IgnoreUCF, i.e. use UCF changes, return original lists with only active items (Inactive = false) + // if IgnoreUCF, return original lists with all items + // if UseCheckOffUCF is true use the merged lists from current format and baseall.xml and + // do the same processing for IgnoreUCF described above. + + // UseCheckOffUCF is false or there is no FormatConfig (UCF) data: + FormatConfig fc = PlantFormat.GetFormatConfig(MyFormat); + if (!MyFormat.PlantFormat.FormatData.ProcData.CheckOffUCF || fc==null) + { + _CheckOffList = new CheckOffList(SelectNodes("CheckOffList/CheckOff"), MyFormat); + // If Ignoring the UCF data, just return the entire list. Also, return entire list if there is no UCF data (fc == null) + if (!PlantFormat.IgnoreUCF || fc == null) return _CheckOffList; + // If not ignoring UCF settings, only return those that are active + foreach (FormatConfig.CheckOff co in fc.PlantFormat.FormatData.CheckOffList) + { + foreach (CheckOff coo in _CheckOffList) + { + if ((int)coo.Index == Convert.ToInt32(co.Index) && !(bool)co.Active) + { + _CheckOffList.Remove(coo); + break; + } + } + } + return _CheckOffList; + } + // UseCheckOfffUCF is true: + // merge the checkoff list from the current format and the checkoff list from the base format + _CheckOffList = new CheckOffList(SelectNodes("CheckOffList/CheckOff"), MyFormat); + CheckOffList retlist2 = new CheckOffList(SelectNodes("../CheckOffDataUCF/CheckOffList/CheckOff"), MyFormat); + if (retlist2 != null && retlist2.Count > 0) foreach (CheckOff co in retlist2) _CheckOffList.Add(co); + if (PlantFormat.IgnoreUCF) return _CheckOffList; + + // if applying UCF, then remove those that are inactive: + foreach (FormatConfig.CheckOff co in fc.PlantFormat.FormatData.CheckOffList) + { + foreach (CheckOff coo in _CheckOffList) + { + if ((int)coo.Index == Convert.ToInt32(co.Index) && !(bool)co.Active) + { + _CheckOffList.Remove(coo); + break; + } + } + } + return _CheckOffList; } } + public void ClearCheckOffAndHeaderLists() + { + _CheckOffList = null; + _CheckOffHeaderList = null; + } private CheckOffHeaderList _CheckOffHeaderList; public CheckOffHeaderList CheckOffHeaderList { get { - return _CheckOffHeaderList == null? _CheckOffHeaderList = new CheckOffHeaderList(SelectNodes("CheckOffHeaderList/CheckOffHeader"),MyFormat): _CheckOffHeaderList; + if (_CheckOffHeaderList != null) return _CheckOffHeaderList; + FormatConfig fc = PlantFormat.GetFormatConfig(MyFormat); + if (!MyFormat.PlantFormat.FormatData.ProcData.CheckOffUCF || fc == null) + { + _CheckOffHeaderList = new CheckOffHeaderList(SelectNodes("CheckOffHeaderList/CheckOffHeader"), MyFormat); + // Depending on the IgnoreUCF flag, either return this list with UCF Inactive flags set or return the + // list as is. + if (PlantFormat.IgnoreUCF || fc == null) return _CheckOffHeaderList; + // If not ignoring UCF settings, only return those that are active + foreach (FormatConfig.CheckOffHeader coh in fc.PlantFormat.FormatData.CheckOffHeaderList) + { + foreach (CheckOffHeader coo in _CheckOffHeaderList) + { + if ((int)coo.Index == Convert.ToInt32(coh.Index) && !(bool)coh.Active) + { + _CheckOffHeaderList.Remove(coo); + break; + } + } + } + return _CheckOffHeaderList; + } + // merge the checkoff header lists from the current format and the list from the base + _CheckOffHeaderList = new CheckOffHeaderList(SelectNodes("CheckOffHeaderList/CheckOffHeader"), MyFormat); + CheckOffHeaderList retlist2 = new CheckOffHeaderList(SelectNodes("../CheckOffDataUCF/CheckOffHeaderList/CheckOffHeader"), MyFormat); + if (retlist2 != null && retlist2.Count > 0) foreach (CheckOffHeader co in retlist2) _CheckOffHeaderList.Add(co); + if (PlantFormat.IgnoreUCF) return _CheckOffHeaderList; + + // if applying UCF, then remove those that are inactive. + foreach (FormatConfig.CheckOffHeader coh in fc.PlantFormat.FormatData.CheckOffHeaderList) + { + foreach (CheckOffHeader cooh in _CheckOffHeaderList) + { + if ((int)cooh.Index == Convert.ToInt32(coh.Index) && !(bool)coh.Active) + { + _CheckOffHeaderList.Remove(cooh); + break; + } + } + } + return _CheckOffHeaderList; } } + public void CheckOffHeaderListRefresh(bool CheckOffUCF) + { + if (!CheckOffUCF) + { + _CheckOffHeaderList = new CheckOffHeaderList(SelectNodes("CheckOffHeaderList/CheckOffHeader"), MyFormat); + // Depending on the IgnoreUCF flag, either return this list with UCF Inactive flags set or return the + // list as is. + FormatConfig fc = PlantFormat.GetFormatConfig(MyFormat); + if (PlantFormat.IgnoreUCF || fc == null) return; + // If not ignoring UCF settings, only return those that are active + foreach (FormatConfig.CheckOffHeader coh in fc.PlantFormat.FormatData.CheckOffHeaderList) + { + foreach (CheckOffHeader coo in _CheckOffHeaderList) + { + if ((int)coo.Index == Convert.ToInt32(coh.Index) && !(bool)coh.Active) + { + _CheckOffHeaderList.Remove(coo); + break; + } + } + } + return; + } + // if coming from the UCF dialog, then check for the 'ignoreUCF' this will flag whether to only + // merge the checkoff header lists from the current format and the list from the base + CheckOffHeaderList retlist = new CheckOffHeaderList(SelectNodes("CheckOffHeaderList/CheckOffHeader"), MyFormat); + CheckOffHeaderList retlist2 = new CheckOffHeaderList(SelectNodes("../CheckOffDataUCF/CheckOffHeaderList/CheckOffHeader"), MyFormat); + if (retlist2 != null && retlist2.Count > 0) foreach (CheckOffHeader co in retlist2) retlist.Add(co); + _CheckOffHeaderList = retlist; + } private LazyLoad _CheckOffHeaderInPagelist; public bool CheckOffHeaderInPagelist { @@ -1619,57 +1885,6 @@ namespace VEPROMS.CSLA.Library } } #endregion - //#region RightCheckOffBox - //[TypeConverter(typeof(ExpandableObjectConverter))] - //public class RightCheckOffBox : vlnFormatItem, IVlnIndexedFormatItem - //{ - // public RightCheckOffBox(XmlNode xmlNode) : base(xmlNode) { } - // public RightCheckOffBox() : base() { } - // private LazyLoad _Index; - // public int? Index - // { - // get - // { - // return LazyLoad(ref _Index, "@Index"); - // } - // } - // private LazyLoad _RightCheckOffBoxChar; - // public int? RightCheckOffBoxChar - // { - // get - // { - // return LazyLoad(ref _RightCheckOffBoxChar, "@RightCheckOffBoxChar"); - // } - // } - // public override string GetPDDisplayName() - // { return string.Format("[{0}]", Index); } - // public override string GetPDDescription() - // { return string.Format("[{0}] - {1}", Index, RightCheckOffBoxChar); } - // public override string GetPDCategory() - // { return "RightCheckOffBox Data"; } - // public override string ToString() - // { - // return RightCheckOffBoxChar.ToString(); - // } - //} - //#endregion - //#region RightCheckOffBoxList - //[TypeConverter(typeof(vlnIndexedListConverter))] - //public class RightCheckOffBoxList : vlnIndexedFormatList - //{ - // public RightCheckOffBoxList(XmlNodeList xmlNodeList,IFormatOrFormatInfo myFormat) : base(xmlNodeList,myFormat) { } - // public override vlnIndexedFormatList InheritedList - // { - // get - // { - // IFormatOrFormatInfo parentFormat = MyFormat.MyIParent; - // if (parentFormat != null) - // return parentFormat.PlantFormat.FormatData.ProcData.CheckOffData.RightCheckOffBoxList; - // return null; - // } - // } - //} - //#endregion #region CheckOff [TypeConverter(typeof(ExpandableObjectConverter))] public class CheckOff : vlnFormatItem,IVlnIndexedFormatItem @@ -3531,7 +3746,11 @@ namespace VEPROMS.CSLA.Library { get { - return LazyLoad(ref _CompressSteps, "@CompressSteps"); + if (PlantFormat.IgnoreUCF) return LazyLoad(ref _CompressSteps, "@CompressSteps"); + bool? localvalue = null; + FormatConfig fc = PlantFormat.GetFormatConfig(MyFormat); + if (fc != null) localvalue = fc.PlantFormat.FormatData.Flags.CompressSteps; + return localvalue ?? LazyLoad(ref _CompressSteps, "@CompressSteps"); } } private LazyLoad _DoSTExtraAtTop; @@ -3718,7 +3937,11 @@ namespace VEPROMS.CSLA.Library { get { - return LazyLoad(ref _PartialStepCompression, "@PartialStepCompression"); + if (PlantFormat.IgnoreUCF) return LazyLoad(ref _PartialStepCompression, "@PartialStepCompression"); + bool? localvalue = null; + FormatConfig fc = PlantFormat.GetFormatConfig(MyFormat); + if (fc != null) localvalue = fc.PlantFormat.FormatData.Flags.PartialStepCompression; + return localvalue ?? LazyLoad(ref _PartialStepCompression, "@PartialStepCompression"); } } private LazyLoad _VirtualDotInHLSTab; @@ -5072,11 +5295,41 @@ namespace VEPROMS.CSLA.Library return LazyLoad(ref _Quoted, "@Quoted"); } } + private VE_Font GetUCFFontAsVE_Font() + { + // if formatconfig & step list, then go through to see if index exists, if so and if there is a font, use it: + if (MyFormat.PlantFormat.FormatConfig != null && MyFormat.PlantFormat.FormatConfig.PlantFormat != null && MyFormat.PlantFormat.FormatConfig.PlantFormat.FormatData != null && MyFormat.PlantFormat.FormatConfig.PlantFormat.FormatData.StepData != null) + { + foreach (FormatConfig.Step stp in MyFormat.PlantFormat.FormatConfig.PlantFormat.FormatData.StepData) + { + if (Convert.ToInt32(stp.Index) == (int)Index && stp.FontDesc != null && stp.FontDesc.Font != null && stp.FontDesc.Font != "") + { + System.Drawing.FontConverter cvt = new System.Drawing.FontConverter(); + System.Drawing.Font windowsFont = cvt.ConvertFromString(stp.FontDesc.Font) as System.Drawing.Font; + + E_Style myStyle = E_Style.None; + if (windowsFont.Bold) myStyle |= E_Style.Bold; + if (windowsFont.Underline) myStyle |= E_Style.Underline; + if (windowsFont.Italic) myStyle |= E_Style.Italics; + return (new VE_Font(windowsFont.Name, (int)windowsFont.Size, myStyle, windowsFont.SizeInPoints)); + } + } + } + return null; + } private VE_Font _Font; public VE_Font Font { get { + if (PlantFormat.IgnoreUCF) return (_Font == null) ?_Font = new VE_Font(base.XmlNode): _Font; + if (_Font != null) return (_Font); + VE_Font vef = GetUCFFontAsVE_Font(); + if (vef != null) + { + _Font = vef; + return vef; + } return (_Font == null) ?_Font = new VE_Font(base.XmlNode): _Font; } } diff --git a/PROMS/VEPROMS.CSLA.Library/Format/vlnFormat.cs b/PROMS/VEPROMS.CSLA.Library/Format/vlnFormat.cs index 275b56f7..312582e8 100644 --- a/PROMS/VEPROMS.CSLA.Library/Format/vlnFormat.cs +++ b/PROMS/VEPROMS.CSLA.Library/Format/vlnFormat.cs @@ -642,6 +642,19 @@ namespace VEPROMS.CSLA.Library return max; } } + public int MaxIndexNoInherit + { + get + { + int max = base.Count; + foreach (T tmp in this) + { + if (tmp.Index >= max) + max = ((int)tmp.Index) + 1; + } + return max; + } + } #region ICustomTypeDescriptor public String GetClassName() { return TypeDescriptor.GetClassName(this, true); } diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/Format.cs b/PROMS/VEPROMS.CSLA.Library/Generated/Format.cs index 8f7fb81c..eaa37a07 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/Format.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/Format.cs @@ -262,6 +262,27 @@ namespace VEPROMS.CSLA.Library } } } + private string _Config = string.Empty; + public string Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("Config", true); + return _Config; + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + set + { + CanWriteProperty("Config", true); + if (value == null) value = string.Empty; + if (_Config != value) + { + _Config = value; + PropertyHasChanged(); + } + } + } private string _GenMac = string.Empty; public string GenMac { @@ -559,15 +580,18 @@ namespace VEPROMS.CSLA.Library Csla.Validation.CommonRules.StringRequired, "Name"); ValidationRules.AddRule( Csla.Validation.CommonRules.StringMaxLength, - new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 20)); + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100)); ValidationRules.AddRule( Csla.Validation.CommonRules.StringMaxLength, new Csla.Validation.CommonRules.MaxLengthRuleArgs("Description", 250)); - ValidationRules.AddRule( - Csla.Validation.CommonRules.StringRequired, "Data"); + //ValidationRules.AddRule( + // Csla.Validation.CommonRules.StringRequired, "Data"); ValidationRules.AddRule( Csla.Validation.CommonRules.StringMaxLength, new Csla.Validation.CommonRules.MaxLengthRuleArgs("Data", 1073741823)); + ValidationRules.AddRule( + Csla.Validation.CommonRules.StringMaxLength, + new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823)); ValidationRules.AddRule( Csla.Validation.CommonRules.StringMaxLength, new Csla.Validation.CommonRules.MaxLengthRuleArgs("GenMac", 1073741823)); @@ -747,13 +771,14 @@ namespace VEPROMS.CSLA.Library tmp.Data = data; return tmp; } - public static Format New(Format myParent, string name, string description, string data, string genMac, DateTime dts, string userID) + public static Format New(Format myParent, string name, string description, string data, string config, string genMac, DateTime dts, string userID) { Format tmp = Format.New(); tmp.MyParent = myParent; tmp.Name = name; tmp.Description = description; tmp.Data = data; + tmp.Config = config; tmp.GenMac = genMac; tmp.DTS = dts; tmp.UserID = userID; @@ -761,7 +786,7 @@ namespace VEPROMS.CSLA.Library } public static Format MakeFormat(Format myParent, string name, string description, string data, string genMac, DateTime dts, string userID) { - Format tmp = Format.New(myParent, name, description, data, genMac, dts, userID); + Format tmp = Format.New(myParent, name, description, data, null, genMac, dts, userID); if (tmp.IsSavable) tmp = tmp.Save(); else @@ -775,19 +800,20 @@ namespace VEPROMS.CSLA.Library } return tmp; } - public static Format New(Format myParent, string name, string description, string data, string genMac) + public static Format New(Format myParent, string name, string description, string data, string config, string genMac) { Format tmp = Format.New(); tmp.MyParent = myParent; tmp.Name = name; tmp.Description = description; tmp.Data = data; + tmp.Config = config; tmp.GenMac = genMac; return tmp; } public static Format MakeFormat(Format myParent, string name, string description, string data, string genMac) { - Format tmp = Format.New(myParent, name, description, data, genMac); + Format tmp = Format.New(myParent, name, description, data, null, genMac); if (tmp.IsSavable) tmp = tmp.Save(); else @@ -953,6 +979,7 @@ namespace VEPROMS.CSLA.Library _Name = dr.GetString("Name"); _Description = dr.GetString("Description"); _Data = dr.GetString("Data"); + _Config = dr.GetString("Config"); _GenMac = dr.GetString("GenMac"); _DTS = dr.GetDateTime("DTS"); _UserID = dr.GetString("UserID"); @@ -1094,6 +1121,7 @@ namespace VEPROMS.CSLA.Library cm.Parameters.AddWithValue("@Name", _Name); cm.Parameters.AddWithValue("@Description", _Description); cm.Parameters.AddWithValue("@Data", _Data); + cm.Parameters.AddWithValue("@Config", _Config); cm.Parameters.AddWithValue("@GenMac", _GenMac); if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS); cm.Parameters.AddWithValue("@UserID", _UserID); @@ -1126,7 +1154,7 @@ namespace VEPROMS.CSLA.Library } } [Transactional(TransactionalTypes.TransactionScope)] - public static byte[] Add(SqlConnection cn, ref int formatID, Format myParent, string name, string description, string data, string genMac, DateTime dts, string userID) + public static byte[] Add(SqlConnection cn, ref int formatID, Format myParent, string name, string description, string data, string config, string genMac, DateTime dts, string userID) { if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Format.Add", 0); try @@ -1141,6 +1169,7 @@ namespace VEPROMS.CSLA.Library cm.Parameters.AddWithValue("@Name", name); cm.Parameters.AddWithValue("@Description", description); cm.Parameters.AddWithValue("@Data", data); + cm.Parameters.AddWithValue("@Config", config); cm.Parameters.AddWithValue("@GenMac", genMac); if (dts.Year >= 1753 && dts.Year <= 9999) cm.Parameters.AddWithValue("@DTS", dts); cm.Parameters.AddWithValue("@UserID", userID); @@ -1208,6 +1237,7 @@ namespace VEPROMS.CSLA.Library cm.Parameters.AddWithValue("@Name", _Name); cm.Parameters.AddWithValue("@Description", _Description); cm.Parameters.AddWithValue("@Data", _Data); + cm.Parameters.AddWithValue("@Config", _Config); cm.Parameters.AddWithValue("@GenMac", _GenMac); if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS); cm.Parameters.AddWithValue("@UserID", _UserID); @@ -1243,9 +1273,9 @@ namespace VEPROMS.CSLA.Library { SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"]; if (IsNew) - _LastChanged = Format.Add(cn, ref _FormatID, _MyParent, _Name, _Description, _Data, _GenMac, _DTS, _UserID); + _LastChanged = Format.Add(cn, ref _FormatID, _MyParent, _Name, _Description, _Data, _Config, _GenMac, _DTS, _UserID); else - _LastChanged = Format.Update(cn, ref _FormatID, _ParentID, _Name, _Description, _Data, _GenMac, _DTS, _UserID, ref _LastChanged); + _LastChanged = Format.Update(cn, ref _FormatID, _ParentID, _Name, _Description, _Data, _Config, _GenMac, _DTS, _UserID, ref _LastChanged); MarkOld(); } if (_FormatFolders != null) _FormatFolders.Update(this); @@ -1264,7 +1294,7 @@ namespace VEPROMS.CSLA.Library MarkNew(); } [Transactional(TransactionalTypes.TransactionScope)] - public static byte[] Update(SqlConnection cn, ref int formatID, int parentID, string name, string description, string data, string genMac, DateTime dts, string userID, ref byte[] lastChanged) + public static byte[] Update(SqlConnection cn, ref int formatID, int parentID, string name, string description, string data, string config, string genMac, DateTime dts, string userID, ref byte[] lastChanged) { if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Format.Update", 0); try @@ -1280,6 +1310,7 @@ namespace VEPROMS.CSLA.Library cm.Parameters.AddWithValue("@Name", name); cm.Parameters.AddWithValue("@Description", description); cm.Parameters.AddWithValue("@Data", data); + cm.Parameters.AddWithValue("@Config", config); cm.Parameters.AddWithValue("@GenMac", genMac); if (dts.Year >= 1753 && dts.Year <= 9999) cm.Parameters.AddWithValue("@DTS", dts); cm.Parameters.AddWithValue("@UserID", userID); diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/FormatInfo.cs b/PROMS/VEPROMS.CSLA.Library/Generated/FormatInfo.cs index ee54e39a..d5679401 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/FormatInfo.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/FormatInfo.cs @@ -152,6 +152,16 @@ namespace VEPROMS.CSLA.Library return _Data; } } + private string _Config = string.Empty; + public string Config + { + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + get + { + CanReadProperty("Config", true); + return _Config; + } + } private string _GenMac = string.Empty; public string GenMac { @@ -417,6 +427,7 @@ namespace VEPROMS.CSLA.Library _Name = tmp.Name; _Description = tmp.Description; _Data = tmp.Data; + _Config = tmp.Config; _GenMac = tmp.GenMac; _DTS = tmp.DTS; _UserID = tmp.UserID; @@ -483,6 +494,7 @@ namespace VEPROMS.CSLA.Library _Name = dr.GetString("Name"); _Description = dr.GetString("Description"); _Data = dr.GetString("Data"); + _Config = dr.GetString("Config"); _GenMac = dr.GetString("GenMac"); _DTS = dr.GetDateTime("DTS"); _UserID = dr.GetString("UserID"); diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/FormatInfoList.cs b/PROMS/VEPROMS.CSLA.Library/Generated/FormatInfoList.cs index 00aaad07..cfe55f2f 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/FormatInfoList.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/FormatInfoList.cs @@ -103,6 +103,7 @@ namespace VEPROMS.CSLA.Library public static void Reset() { _FormatInfoList = null; + _SortedFormatInfoList = null; } // CSLATODO: Add alternative gets - //public static FormatInfoList Get() diff --git a/PROMS/Volian.Base.Library/FlagEnumEditor.cs b/PROMS/Volian.Base.Library/FlagEnumEditor.cs new file mode 100644 index 00000000..0caf5736 --- /dev/null +++ b/PROMS/Volian.Base.Library/FlagEnumEditor.cs @@ -0,0 +1,277 @@ +using System; +using System.Collections; +using System.ComponentModel; +using System.Drawing; +using System.Data; +using System.Windows.Forms; +using System.Drawing.Design; +using System.Windows.Forms.Design; + + +namespace Volian.Base.Library +{ + + public class FlagCheckedListBox : CheckedListBox + { + private System.ComponentModel.Container components = null; + + public FlagCheckedListBox() + { + // This call is required by the Windows.Forms Form Designer. + InitializeComponent(); + } + + protected override void Dispose(bool disposing) + { + if (disposing) + { + if (components != null) + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Component Designer generated code + private void InitializeComponent() + { + // + // FlaggedCheckedListBox + // + this.CheckOnClick = true; + + } + #endregion + + // Adds an integer value and its associated description + public FlagCheckedListBoxItem Add(uint v, string c) + { + FlagCheckedListBoxItem item = new FlagCheckedListBoxItem(v, c); + Items.Add(item); + return item; + } + + public FlagCheckedListBoxItem Add(FlagCheckedListBoxItem item) + { + Items.Add(item); + return item; + } + + protected override void OnItemCheck(ItemCheckEventArgs e) + { + base.OnItemCheck(e); + + if (isUpdatingCheckStates) + return; + + // Get the checked/unchecked item + FlagCheckedListBoxItem item = Items[e.Index] as FlagCheckedListBoxItem; + // Update other items + UpdateCheckedItems(item, e.NewValue); + } + + // Checks/Unchecks items depending on the give bitvalue + protected void UpdateCheckedItems(uint value) + { + + isUpdatingCheckStates = true; + + // Iterate over all items + for (int i = 0; i < Items.Count; i++) + { + FlagCheckedListBoxItem item = Items[i] as FlagCheckedListBoxItem; + + if (item.value == 0) + { + SetItemChecked(i, value == 0); + } + else + { + + // If the bit for the current item is on in the bitvalue, check it + if ((item.value & value) == item.value && item.value != 0) + SetItemChecked(i, true); + // Otherwise uncheck it + else + SetItemChecked(i, false); + } + } + + isUpdatingCheckStates = false; + + } + + // Updates items in the checklistbox + // composite = The item that was checked/unchecked + // cs = The check state of that item + protected void UpdateCheckedItems(FlagCheckedListBoxItem composite, CheckState cs) + { + + // If the value of the item is 0, call directly. + if (composite.value == 0) + UpdateCheckedItems(0); + + + // Get the total value of all checked items + uint sum = 0; + for (int i = 0; i < Items.Count; i++) + { + FlagCheckedListBoxItem item = Items[i] as FlagCheckedListBoxItem; + + // If item is checked, add its value to the sum. + if (GetItemChecked(i)) + sum |= item.value; + } + + // If the item has been unchecked, remove its bits from the sum + if (cs == CheckState.Unchecked) + sum = sum & (~composite.value); + // If the item has been checked, combine its bits with the sum + else + sum |= composite.value; + + // Update all items in the checklistbox based on the final bit value + UpdateCheckedItems(sum); + + } + + private bool isUpdatingCheckStates = false; + + // Gets the current bit value corresponding to all checked items + public uint GetCurrentValue() + { + uint sum = 0; + + for (int i = 0; i < Items.Count; i++) + { + FlagCheckedListBoxItem item = Items[i] as FlagCheckedListBoxItem; + + if (GetItemChecked(i)) + sum |= item.value; + } + + return sum; + } + + Type enumType; + Enum enumValue; + + // Adds items to the checklistbox based on the members of the enum + private void FillEnumMembers() + { + foreach (string name in Enum.GetNames(enumType)) + { + object val = Enum.Parse(enumType, name); + uint intVal = (uint)Convert.ChangeType(val, typeof(uint)); + + Add(intVal, name); + } + } + + // Checks/unchecks items based on the current value of the enum variable + private void ApplyEnumValue() + { + uint intVal = (uint)Convert.ChangeType(enumValue, typeof(uint)); + UpdateCheckedItems(intVal); + + } + + [DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Hidden)] + public Enum EnumValue + { + get + { + object e = Enum.ToObject(enumType, GetCurrentValue()); + return (Enum)e; + } + set + { + + Items.Clear(); + enumValue = value; // Store the current enum value + enumType = value.GetType(); // Store enum type + FillEnumMembers(); // Add items for enum members + ApplyEnumValue(); // Check/uncheck items depending on enum value + + } + } + + + } + + // Represents an item in the checklistbox + public class FlagCheckedListBoxItem + { + public FlagCheckedListBoxItem(uint v, string c) + { + value = v; + caption = c; + } + + public override string ToString() + { + return caption; + } + + // Returns true if the value corresponds to a single bit being set + public bool IsFlag + { + get + { + return ((value & (value - 1)) == 0); + } + } + + // Returns true if this value is a member of the composite bit value + public bool IsMemberFlag(FlagCheckedListBoxItem composite) + { + return (IsFlag && ((value & composite.value) == value)); + } + + public uint value; + public string caption; + } + + + // UITypeEditor for flag enums + public class FlagEnumUIEditor : UITypeEditor + { + // The checklistbox + private FlagCheckedListBox flagEnumCB; + + public FlagEnumUIEditor() + { + flagEnumCB = new FlagCheckedListBox(); + flagEnumCB.BorderStyle = BorderStyle.None; + } + + public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value) + { + if (context != null + && context.Instance != null + && provider != null) + { + + IWindowsFormsEditorService edSvc = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService)); + + if (edSvc != null) + { + + Enum e = (Enum)Convert.ChangeType(value, context.PropertyDescriptor.PropertyType); + flagEnumCB.EnumValue = e; + edSvc.DropDownControl(flagEnumCB); + return flagEnumCB.EnumValue; + + } + } + return null; + } + + public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context) + { + return UITypeEditorEditStyle.DropDown; + } + + + } + +} diff --git a/PROMS/Volian.Base.Library/PropGridCollEditor.cs b/PROMS/Volian.Base.Library/PropGridCollEditor.cs new file mode 100644 index 00000000..72b9209e --- /dev/null +++ b/PROMS/Volian.Base.Library/PropGridCollEditor.cs @@ -0,0 +1,300 @@ +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Text; +using System.ComponentModel; +using System.ComponentModel.Design; +using System.Windows.Forms; +using System.Reflection; + +namespace Volian.Base.Library +{ + // The PropGridCollEditor expands the functionality of the CollectionEditor (the collection editor comes up when in a + // property grid, and the current selected item is a collection, and the user selects the '...'. + public class PropGridCollEditor : CollectionEditor + { + // Define a static event to expose the inner PropertyGrid's + // PropertyValueChanged event args... + public delegate void MyPropertyValueChangedEventHandler(object sender, PropertyValueChangedEventArgs e); + public static event MyPropertyValueChangedEventHandler MyPropertyValueChanged; + private bool AllowAddDel = false; // flags whether the Add/Delete buttons should be displayed: + // Inherit the default constructor from the standard + // Collection Editor... + private Type _origType; + public PropGridCollEditor(Type type) + : base(type) + { + AllowAddDel = false; + _origType = type; + if (type.Name == "ReplaceStrData") AllowAddDel = true; // Defaults to not having the 'Add' & 'Remove' buttons. + } + + protected override Type CreateCollectionItemType() + { + return base.CreateCollectionItemType(); + } + private Button resetbtn = null; + // Override this method in order to access the containing user controls + // from the default Collection Editor form or to add new ones... + protected override CollectionForm CreateCollectionForm() + { + // Getting the default layout of the Collection Editor... + CollectionForm collectionForm = base.CreateCollectionForm(); + + Form frmCollectionEditorForm = collectionForm as Form; + + // The Add/Remove buttons are made invisible: + if (!AllowAddDel) HideAddRemoveButtons(0, frmCollectionEditorForm); + Button okbtn = FindOkButton(frmCollectionEditorForm); + + if (!AllowAddDel) + { + // add a reset button and put next to ok button: + resetbtn = new Button(); + resetbtn.Text = "Reset"; + resetbtn.Location = new System.Drawing.Point(okbtn.Location.X - 20, okbtn.Location.Y); + resetbtn.Width = 250; + resetbtn.Visible = true; + resetbtn.Enabled = false; // only enabled on data change + resetbtn.Click += resetbtn_Click; + okbtn.Parent.Controls.Add(resetbtn); + } + SetMembersLabel(collectionForm); + TableLayoutPanel tlpLayout = frmCollectionEditorForm.Controls[0] as TableLayoutPanel; + if (tlpLayout != null) + { + // Get a reference to the inner PropertyGrid and hook an event handler to it. + if (tlpLayout.Controls[5] is PropertyGrid) + { + propertyGrid = tlpLayout.Controls[5] as PropertyGrid; + propertyGrid.PropertyValueChanged += new PropertyValueChangedEventHandler(propertyGrid_PropertyValueChanged); + propertyGrid.SelectedGridItemChanged += PG_SelectedGridItemChanged; + } + } + + return collectionForm; + } + + // when the reset button is clicked the data will be reset to the data from the original format file. Note that if + // data is added to the UCF that is part of a collection, code will need to be added here to reset the value. + void resetbtn_Click(object sender, EventArgs e) + { + resetbtn.Text = "Reset"; + resetbtn.Enabled = false; + if (SelectedGridField.Contains("Left Margin")) + ResetValue(propertyGrid.SelectedGridItem.Parent.Value, "LeftMargin"); + else if (SelectedGridField.Contains("Page Length")) + ResetValue(propertyGrid.SelectedGridItem.Parent.Value, "PageLength"); + else if (SelectedGridField.Contains("WindowsFont")) + ResetValue(propertyGrid.SelectedGridItem.Parent.Value, "WindowsFont"); + else if (SelectedGridField.Contains("Inactive CheckOff Header")) + ResetValue(propertyGrid.SelectedGridItem.Parent.Value, "Inactive"); + else if (SelectedGridField.Contains("Inactive CheckOff")) + ResetValue(propertyGrid.SelectedGridItem.Parent.Parent.Value, "Inactive"); + } + private void ShowReflection(Object data) + { + if (data == null) return; + //Object data = new A(); + FieldInfo[] fields = data.GetType().GetFields(BindingFlags.Public | + BindingFlags.NonPublic | + BindingFlags.Instance); + String str = ""; + foreach (FieldInfo f in fields) + { + str += f.Name + " = " + f.GetValue(data) + "\r\n"; + } + Console.WriteLine("reflection = {0}", str); + } + PropertyGrid propertyGrid = null; + private string SelectedGridField = ""; + // The following method is used to enable and set text on the 'Reset' button. When a grid item is selected, if it has + // UCF data, then put the original value as part of the button text & enable it: + void PG_SelectedGridItemChanged(object sender, SelectedGridItemChangedEventArgs e) + { + if (resetbtn == null) return; + if (propertyGrid != null) Console.WriteLine(LabelPath(propertyGrid.SelectedGridItem)); // PG.SelectedGridItem.Label + " : " + PG.SelectedGridItem.Value; + // see if data has changed, and if so, enable the Reset button. + bool enabled = false; + resetbtn.Text = "Reset"; + SelectedGridField = LabelPath(propertyGrid.SelectedGridItem); + if (SelectedGridField.Contains("WindowsFont")) + { + string origForButton = OrigValue(propertyGrid.SelectedGridItem.Parent.Value, "WindowsFont"); + if (origForButton != null) + { + resetbtn.Text = "Reset to " + origForButton; + enabled = true; + } + } + else if (SelectedGridField.Contains("Left Margin")) + { + string origForButton = OrigValue(propertyGrid.SelectedGridItem.Parent.Value, "LeftMargin"); + if (origForButton != null) + { + resetbtn.Text = "Reset to " + origForButton; + enabled = true; + } + } + else if (SelectedGridField.Contains("Page Length")) + { + string origForButton = OrigValue(propertyGrid.SelectedGridItem.Parent.Value, "PageLength"); + if (origForButton != null) + { + resetbtn.Text = "Reset to " + origForButton; + enabled = true; + } + } + else if (SelectedGridField.Contains("Active CheckOff Header")) + { + string origForButton = OrigValue(propertyGrid.SelectedGridItem.Parent.Parent.Value, "Active"); + if (origForButton != null) + { + resetbtn.Text = "Reset to " + origForButton; + enabled = true; + } + } + else if (SelectedGridField.Contains("Active CheckOff")) + { + string origForButton = OrigValue(propertyGrid.SelectedGridItem.Parent.Parent.Value, "Active"); + if (origForButton != null) + { + resetbtn.Text = "Reset to " + origForButton; + enabled = true; + } + } + else enabled = false; + + resetbtn.Enabled = enabled; + } + // This code,using data reflection, will determine the if there is UCF (changed) data, and if so + // will return its value as a string for concatenation of Reset button text. + private string OrigValue(object data, string fieldName) + { + FieldInfo fldVal = null; + FieldInfo fldOrig = null; + if (data == null) return null; + FieldInfo[] fields = data.GetType().GetFields(BindingFlags.Public | + BindingFlags.NonPublic | + BindingFlags.Instance); + // Go through the fields in the data structure, looking to match that passed in. Also look for the original + // field to compare the 2 to see if a change was made, i.e. UCF data exists. + foreach (FieldInfo f in fields) + { + if (f.Name == "_" + fieldName) fldVal = f; + if (f.Name == "_Orig" + fieldName) fldOrig = f; + } + if (fldVal != null && fldOrig != null) + { + try + { + // see if values are different: + string orig = fldOrig.GetValue(data).ToString(); + string newv = fldVal.GetValue(data).ToString(); + string retval = fldOrig.GetValue(data).ToString(); + if (retval.StartsWith("[Font:")) + { + retval = retval.Replace("[Font: Name=", "").Replace(", Size=", ","); + } + if (orig != newv) return retval; + else return null; + } + catch (Exception ex) + { + return null; + } + } + return null; + } + // The following Resets the format variable's value from the original format (as stored in the 'OrigXXX' field in FormatConfig + private void ResetValue(object data, string fieldName) + { + FieldInfo fldVal = null; + FieldInfo fldOrig = null; + if (data == null) return; + FieldInfo[] fields = data.GetType().GetFields(BindingFlags.Public | + BindingFlags.NonPublic | + BindingFlags.Instance); + foreach (FieldInfo f in fields) + { + if (f.Name == "_" + fieldName) fldVal = f; + if (f.Name == "_Orig" + fieldName) fldOrig = f; + } + if (fldVal != null && fldOrig != null) + { + fldVal.SetValue(data, fldOrig.GetValue(data)); + propertyGrid.Refresh(); + } + } + // Remove this on release, and any uses of it. + private string LabelPath(GridItem gi) + { + return (gi.Parent == null ? "" : LabelPath(gi.Parent) + ":" + gi.Label); + } + + // set the 'members' label to better reflect what is displayed: + private bool SetMembersLabel(Control myControl) + { + if (myControl is Label && myControl.Text.ToUpper().Contains("MEMBER")) + { + string dt = myControl.TopLevelControl.Text; + if (dt.ToUpper().Contains("DOCSTYL")) myControl.Text = "Section Types"; + else if (dt.ToUpper().Contains("REPLACE")) myControl.Text = "Replace Words"; + else if (dt.ToUpper().Contains("CHECKOFFHEADER")) myControl.Text = "CheckOff Headers"; + else if (dt.ToUpper().Contains("CHECKOFF")) myControl.Text = "CheckOffs"; + else if (dt.ToUpper().Contains("STEP")) myControl.Text = "Steps"; + return true; + } + if (myControl.Controls != null && myControl.Controls.Count > 0) + { + foreach (Control con in myControl.Controls) + { + bool found = SetMembersLabel(con); + if (found == true) return true; + } + } + return false; + } + // This code looks for the 'OK' button, so that the 'Reset' button can be placed by it. + private Button FindOkButton(Control myControl) + { + if (myControl is Button && myControl.Text == "OK") + { + return myControl as Button; + } + if (myControl.Controls != null && myControl.Controls.Count > 0) + { + foreach (Control con in myControl.Controls) + { + Button found = FindOkButton(con); + if (found != null) return found; + } + } + return null; + } + + // Find the 'Add' & 'Remove' buttons based on their text, and then make invisible. + private void HideAddRemoveButtons(int level, Control myControl) + { + if (myControl.Text == "&Add" || myControl.Text == "&Remove") + { + myControl.Visible = false; + return; + } + if (myControl.Controls != null && myControl.Controls.Count > 0) + { + foreach (Control con in myControl.Controls) + HideAddRemoveButtons(level + 1, con); + } + } + + void propertyGrid_PropertyValueChanged(object sender, PropertyValueChangedEventArgs e) + { + // Fire our customized collection event... + if (PropGridCollEditor.MyPropertyValueChanged != null) + { + PropGridCollEditor.MyPropertyValueChanged(this, e); + } + } + } +} diff --git a/PROMS/Volian.Base.Library/RTBAPI.cs b/PROMS/Volian.Base.Library/RTBAPI.cs new file mode 100644 index 00000000..c88aecf9 --- /dev/null +++ b/PROMS/Volian.Base.Library/RTBAPI.cs @@ -0,0 +1,1110 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Windows.Forms; +using System.Drawing; +using System.Runtime.InteropServices; +using System.ComponentModel; +using Volian.Base.Library; + +namespace Volian.Base.Library +{ + public static class RTBAPI + { + #region SendMessage + [DllImport("user32.dll", SetLastError = true)] + private static extern int SendMessage(HandleRef hWndlock, Messages wMsg, Int32 wParam, ref Point pt); + [DllImport("user32.dll", SetLastError = true)] + private static extern int SendMessage(HandleRef hWndlock, Messages wMsg, Int32 wParam, int lParam); + [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)] + public static extern int SendMessage(HandleRef hWndlock, Messages wMsg, RTBSelection wParam, ref CharFormat2 cf2); + [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)] + public static extern int SendMessage(HandleRef hWndlock, Messages wMsg, int wParam, ref ParaFormat2 pf2); + [DllImport("user32.dll", SetLastError = true)] + private static extern int GetWindowLong (IntPtr hWin, int index); + #region RTB Messages + // EM_AUTOURLDETECT - An EM_AUTOURLDETECT message enables or disables automatic detection of URLs by a rich edit control. + // EM_CANPASTE - The EM_CANPASTE message determines whether a rich edit control can paste a specified clipboard format. + // EM_CANREDO - The EM_CANREDO message determines whether there are any actions in the control redo queue. + // EM_DISPLAYBAND - The EM_DISPLAYBAND message displays a portion of the contents of a rich edit control, as previously formatted for a device using the EM_FORMATRANGE message. + // EM_EXGETSEL - The EM_EXGETSEL message retrieves the starting and ending character positions of the selection in a rich edit control. + // EM_EXLIMITTEXT - The EM_EXLIMITTEXT message sets an upper limit to the amount of text the user can type or paste into a rich edit control. + // EM_EXLINEFROMCHAR - The EM_EXLINEFROMCHAR message determines which line contains the specified character in a rich edit control. + // EM_EXSETSEL - The EM_EXSETSEL message selects a range of characters or COM objects in a Rich Edit control. + // EM_FINDTEXT - The EM_FINDTEXT message finds text within a rich edit control. + // EM_FINDTEXTEX - The EM_FINDTEXTEX message finds text within a rich edit control. + // EM_FINDTEXTEXW - The EM_FINDTEXTEXW message finds Unicode text within a rich edit control. + // EM_FINDTEXTW - The EM_FINDTEXTW message finds Unicode text within a rich edit control. + // EM_FINDWORDBREAK - The EM_FINDWORDBREAK message finds the next word break before or after the specified character position or retrieves information about the character at that position. + // EM_FORMATRANGE - The EM_FORMATRANGE message formats a range of text in a rich edit control for a specific device. + // EM_GETAUTOURLDETECT - The EM_GETAUTOURLDETECT message indicates whether the auto URL detection is turned on in the rich edit control. + // EM_GETBIDIOPTIONS - The EM_GETBIDIOPTIONS message indicates the current state of the bidirectional options in the rich edit control. + // EM_GETCHARFORMAT - The EM_GETCHARFORMAT message determines the character formatting in a rich edit control. + // EM_GETCTFMODEBIAS - An application sends a EM_GETCTFMODEBIAS message to get the Text Services Framework mode bias values for a Rich Edit control. + // EM_GETCTFOPENSTATUS - An application sends an EM_GETCTFOPENSTATUS message to determine if the Text Services Framework (TSF) keyboard is open or closed. + // EM_GETEDITSTYLE - The EM_GETEDITSTYLE message retrieves the current edit style flags. + // EM_GETEVENTMASK - The EM_GETEVENTMASK message retrieves the event mask for a rich edit control. The event mask specifies which notification messages the control sends to its parent window. + // EM_GETHYPHENATEINFO - An application sends an EM_GETHYPHENATEINFO message to get information about hyphenation for a Rich Edit control. + // EM_GETIMECOLOR - The EM_GETIMECOLOR message retrieves the Input Method Editor (IME) composition color. This message is available only in Asian-language versions of the operating system. + // EM_GETIMECOMPMODE - An application sends an EM_GETIMECOMPMODE message to get the current IME mode for a rich edit control. + // EM_GETIMECOMPTEXT - An application sends an EM_GETIMECOMPTEXT message to get the IME composition text. + // EM_GETIMEMODEBIAS - An application sends an EM_GETIMEMODEBIAS message to get the IME mode bias for a Rich Edit control. + // EM_GETIMEOPTIONS - The EM_GETIMEOPTIONS message retrieves the current IME options. This message is available only in Asian-language versions of the operating system. + // EM_GETIMEPROPERTY - An application sends a EM_GETIMEPROPERTY message to get the property and capabilities of the IME associated with the current input locale. + // EM_GETLANGOPTIONS - An application sends an EM_GETLANGOPTIONS message to get a rich edit control's option settings for IME and Asian language support. + // EM_GETOLEINTERFACE - The EM_GETOLEINTERFACE message retrieves an IRichEditOle object that a client can use to access a rich edit control's COM functionality. + // EM_GETOPTIONS - The EM_GETOPTIONS message retrieves rich edit control options. + // EM_GETPAGEROTATE - Deprecated. An application sends an EM_GETPAGEROTATE message to get the text layout for a Rich Edit control. + // EM_GETPARAFORMAT - The EM_GETPARAFORMAT message retrieves the paragraph formatting of the current selection in a rich edit control. + // EM_GETPUNCTUATION - The EM_GETPUNCTUATION message gets the current punctuation characters for the rich edit control. This message is available only in Asian-language versions of the operating system. + // EM_GETREDONAME - An application sends an EM_GETREDONAME message to a rich edit control to retrieve the type of the next action, if any, in the control's redo queue. + // EM_GETSCROLLPOS - An application sends an EM_GETSCROLLPOS message to obtain the current scroll position of the edit control. + // EM_GETSELTEXT - The EM_GETSELTEXT message retrieves the currently selected text in a rich edit control. + // EM_GETTEXTEX - The EM_GETTEXTEX message allows you to get all of the text from the rich edit control in any particular code base you want. + // EM_GETTEXTLENGTHEX - The EM_GETTEXTLENGTHEX message calculates text length in various ways. It is usually called before creating a buffer to receive the text from the control. + // EM_GETTEXTMODE - An application sends an EM_GETTEXTMODE message to get the current text mode and undo level of a rich edit control. + // EM_GETTEXTRANGE - The EM_GETTEXTRANGE message retrieves a specified range of characters from a rich edit control. + // EM_GETTYPOGRAPHYOPTIONS - The EM_GETTYPOGRAPHYOPTIONS message returns the current state of the typography options of a rich edit control. + // EM_GETUNDONAME - Rich Edit 2.0 and later: An application sends an EM_GETUNDONAME message to a rich edit control to retrieve the type of the next undo action, if any. + // EM_GETWORDBREAKPROCEX - The EM_GETWORDBREAKPROCEX message retrieves the address of the currently registered extended word-break procedure. + // EM_GETWORDWRAPMODE - The EM_GETWORDWRAPMODE message gets the current word wrap and word-break options for the rich edit control. This message is available only in Asian-language versions of the operating system. + // EM_GETZOOM - The EM_GETZOOM message gets the current zoom ratio, which is always between 1/64 and 64. + // EM_HIDESELECTION - The EM_HIDESELECTION message hides or shows the selection in a rich edit control. + // EM_ISIME - An application sends a EM_ISIME message to determine if current input locale is an East Asian locale. + // EM_PASTESPECIAL - The EM_PASTESPECIAL message pastes a specific clipboard format in a rich edit control. + // EM_RECONVERSION - The EM_RECONVERSION message invokes the IME reconversion dialog box. + // EM_REDO - Send an EM_REDO message to a rich edit control to redo the next action in the control's redo queue. + // EM_REQUESTRESIZE - The EM_REQUESTRESIZE message forces a rich edit control to send an EN_REQUESTRESIZE notification message to its parent window. + // EM_SELECTIONTYPE - The EM_SELECTIONTYPE message determines the selection type for a rich edit control. + // EM_SETBIDIOPTIONS - The EM_SETBIDIOPTIONS message sets the current state of the bidirectional options in the rich edit control. + // EM_SETBKGNDCOLOR - The EM_SETBKGNDCOLOR message sets the background color for a rich edit control. + // EM_SETCHARFORMAT - The EM_SETCHARFORMAT message sets character formatting in a rich edit control. + // EM_SETCTFMODEBIAS - An application sends an EM_SETCTFMODEBIAS message to set the Text Services Framework (TSF) mode bias for a Rich Edit control. + // EM_SETCTFOPENSTATUS - An application sends an EM_SETCTFOPENSTATUS message to open or close the Text Services Framework (TSF) keyboard. + // EM_SETEDITSTYLE - The EM_SETEDITSTYLE message sets the current edit style flags. + // EM_SETEVENTMASK - The EM_SETEVENTMASK message sets the event mask for a rich edit control. The event mask specifies which notification messages the control sends to its parent window. + // EM_SETFONTSIZE - The EM_SETFONTSIZE message sets the font size for the selected text. + // EM_SETHYPHENATEINFO - An application sends an EM_SETHYPHENATEINFO message to set the way a Rich Edit control does hyphenation. + // EM_SETIMECOLOR - The EM_SETIMECOLOR message sets the IME composition color. This message is available only in Asian-language versions of the operating system. + // EM_SETIMEMODEBIAS - An application sends an EM_SETIMEMODEBIAS message to set the IME mode bias for a Rich Edit control. + // EM_SETIMEOPTIONS - The EM_SETIMEOPTIONS message sets the IME options. This message is available only in Asian-language versions of the operating system. + // EM_SETLANGOPTIONS - An application sends an EM_SETLANGOPTIONS message to set options for IME and Asian language support in a rich edit control. + // EM_SETOLECALLBACK - The EM_SETOLECALLBACK message gives a rich edit control an IRichEditOleCallback object that the control uses to get OLE-related resources and information from the client. + // EM_SETOPTIONS - The EM_SETOPTIONS message sets the options for a rich edit control. + // EM_SETPAGEROTATE - Deprecated. An application sends an EM_SETPAGEROTATE message to set the text layout for a Rich Edit control. + // EM_SETPALETTE - An application sends an EM_SETPALETTE message to change the palette that rich edit uses for its display window. + // EM_SETPARAFORMAT - The EM_SETPARAFORMAT message sets the paragraph formatting for the current selection in a rich edit control. + // EM_SETPUNCTUATION - The EM_SETPUNCTUATION message sets the punctuation characters for a rich edit control. This message is available only in Asian-language versions of the operating system. + // EM_SETSCROLLPOS - An application sends an EM_SETSCROLLPOS message to tell the rich edit control to scroll to a particular point. + // EM_SETTARGETDEVICE - The EM_SETTARGETDEVICE message sets the target device and line width used for "what you see is what you get" (WYSIWYG) formatting in a rich edit control. + // EM_SETTEXTEX - The EM_SETTEXTEX message combines the functionality of WM_SETTEXT and EM_REPLACESEL and adds the ability to set text using a code page and to use either rich text or plain text. + // EM_SETTEXTMODE - An application sends an EM_SETTEXTMODE message to set the text mode or undo level of a rich edit control. The message fails if the control contains any text. + // EM_SETTYPOGRAPHYOPTIONS - The EM_SETTYPOGRAPHYOPTIONS message sets the current state of the typography options of a rich edit control. + // EM_SETUNDOLIMIT - An application sends an EM_SETUNDOLIMIT message to a rich edit control to set the maximum number of actions that can stored in the undo queue. + // EM_SETWORDBREAKPROCEX - The EM_SETWORDBREAKPROCEX message sets the extended word-break procedure. + // EM_SETWORDWRAPMODE - The EM_SETWORDWRAPMODE message sets the word-wrapping and word-breaking options for the rich edit control. This message is available only in Asian-language versions of the operating system. + // EM_SETZOOM - The EM_SETZOOM message sets the zoom ratio anywhere between 1/64 and 64. + // EM_SHOWSCROLLBAR - The EM_SHOWSCROLLBAR message shows or hides one of the scroll bars in the Text Host window. + // EM_STOPGROUPTYPING - An application sends an EM_STOPGROUPTYPING message to a rich edit control to stop the control from collecting additional typing actions into the current undo action. The control stores the next typing action, if any, into a new action in the undo queue. + // EM_STREAMIN - The EM_STREAMIN message replaces the contents of a rich edit control with a stream of data provided by an application defined + // EM_STREAMOUT - The EM_STREAMOUT message causes a rich edit control to pass its contents to an application + #endregion + #endregion + #region Constants + //const int ECOOP_XOR = 0x0004; + + //const int ECO_AUTOWORDSELECTION = 0x00000001; + + + const int WM_USER = 0x0400; + const int GWL_STYLE = -16; + const int WS_HSCROLL = 0x100000; + const int WS_VSCROLL = 0x200000; + + #endregion + #region Enums + public enum Messages : int + { + EM_AUTOURLDETECT = WM_USER + 91, + EM_CANPASTE = WM_USER + 50, + EM_CANREDO = WM_USER + 85, + EM_DISPLAYBAND = WM_USER + 51, + EM_EXGETSEL = WM_USER + 52, + EM_EXLIMITTEXT = WM_USER + 53, + EM_EXLINEFROMCHAR = WM_USER + 54, + EM_EXSETSEL = WM_USER + 55, + EM_FINDTEXT = WM_USER + 56, + EM_FINDTEXTEX = WM_USER + 79, + EM_FINDTEXTEXW = WM_USER + 124, + EM_FINDTEXTW = WM_USER + 123, + EM_FINDWORDBREAK = WM_USER + 76, + EM_FORMATRANGE = WM_USER + 57, + EM_GETAUTOURLDETECT = WM_USER + 92, + EM_GETBIDIOPTIONS = WM_USER + 201, + EM_GETCHARFORMAT = WM_USER + 58, + EM_GETCTFMODEBIAS = WM_USER + 237, + EM_GETCTFOPENSTATUS = WM_USER + 240, + EM_GETEDITSTYLE = WM_USER + 205, + EM_GETEVENTMASK = WM_USER + 59, + EM_GETHYPHENATEINFO = WM_USER + 230, + EM_GETIMECOLOR = WM_USER + 105, + EM_GETIMECOMPMODE = WM_USER + 122, + EM_GETIMECOMPTEXT = WM_USER + 242, + EM_GETIMEMODEBIAS = WM_USER + 127, + EM_GETIMEOPTIONS = WM_USER + 107, + EM_GETIMEPROPERTY = WM_USER + 244, + EM_GETLANGOPTIONS = WM_USER + 121, + EM_GETOLEINTERFACE = WM_USER + 60, + EM_GETOPTIONS = WM_USER + 78, + EM_GETPAGEROTATE = WM_USER + 235, + EM_GETPARAFORMAT = WM_USER + 61, + EM_GETPUNCTUATION = WM_USER + 101, + EM_GETREDONAME = WM_USER + 87, + EM_GETSCROLLPOS = WM_USER + 221, + EM_GETSELTEXT = WM_USER + 62, + EM_GETTEXTEX = WM_USER + 94, + EM_GETTEXTLENGTHEX = WM_USER + 95, + EM_GETTEXTMODE = WM_USER + 90, + EM_GETTEXTRANGE = WM_USER + 75, + EM_GETTYPOGRAPHYOPTIONS = WM_USER + 203, + EM_GETUNDONAME = WM_USER + 86, + EM_GETWORDBREAKPROCEX = WM_USER + 80, + EM_GETWORDWRAPMODE = WM_USER + 103, + EM_GETZOOM = WM_USER + 224, + EM_HIDESELECTION = WM_USER + 63, + EM_ISIME = WM_USER + 243, + EM_PASTESPECIAL = WM_USER + 64, + EM_RECONVERSION = WM_USER + 125, + EM_REDO = WM_USER + 84, + EM_REQUESTRESIZE = WM_USER + 65, + EM_SELECTIONTYPE = WM_USER + 66, + EM_SETBIDIOPTIONS = WM_USER + 200, + EM_SETBKGNDCOLOR = WM_USER + 67, + EM_SETCHARFORMAT = WM_USER + 68, + EM_SETCTFMODEBIAS = WM_USER + 238, + EM_SETCTFOPENSTATUS = WM_USER + 241, + EM_SETEDITSTYLE = WM_USER + 204, + EM_SETEVENTMASK = WM_USER + 69, + EM_SETFONTSIZE = WM_USER + 223, + EM_SETHYPHENATEINFO = WM_USER + 231, + EM_SETIMECOLOR = WM_USER + 104, + EM_SETIMEMODEBIAS = WM_USER + 126, + EM_SETIMEOPTIONS = WM_USER + 106, + EM_SETLANGOPTIONS = WM_USER + 120, + EM_SETOLECALLBACK = WM_USER + 70, + EM_SETOPTIONS = WM_USER + 77, + EM_SETPAGEROTATE = WM_USER + 236, + EM_SETPALETTE = WM_USER + 93, + EM_SETPARAFORMAT = WM_USER + 71, + EM_SETPUNCTUATION = WM_USER + 100, + EM_SETSCROLLPOS = WM_USER + 222, + EM_SETTARGETDEVICE = WM_USER + 72, + EM_SETTEXTEX = WM_USER + 97, + EM_SETTEXTMODE = WM_USER + 89, + EM_SETTYPOGRAPHYOPTIONS = WM_USER + 202, + EM_SETUNDOLIMIT = WM_USER + 82, + EM_SETWORDBREAKPROCEX = WM_USER + 81, + EM_SETWORDWRAPMODE = WM_USER + 102, + EM_SETZOOM = WM_USER + 225, + EM_SHOWSCROLLBAR = WM_USER + 96, + EM_STOPGROUPTYPING = WM_USER + 88, + EM_STREAMIN = WM_USER + 73, + EM_STREAMOUT = WM_USER + 74 + }; + [Flags] + public enum LanguageOptions : int // Options for EM_SETLANGOPTIONS and EM_GETLANGOPTIONS + { + IMF_AUTOKEYBOARD = 0x0001, + IMF_AUTOFONT = 0x0002, + IMF_IMECANCELCOMPLETE = 0x0004, // high completes the comp string when aborting, low cancels. + IMF_IMEALWAYSSENDNOTIFY = 0x0008 + } + public enum TimeCompMode : int // Values for EM_GETIMECOMPMODE + { + ICM_NOTOPEN = 0x0000, + ICM_LEVEL3 = 0x0001, + ICM_LEVEL2 = 0x0002, + ICM_LEVEL2_5 = 0x0003, + ICM_LEVEL2_SUI = 0x0004 + } + [Flags] + public enum EditControlOptions : int // Edit control options + { + ECO_AUTOWORDSELECTION = 0x00000001, + ECO_AUTOVSCROLL = 0x00000040, + ECO_AUTOHSCROLL = 0x00000080, + ECO_NOHIDESEL = 0x00000100, + ECO_READONLY = 0x00000800, + ECO_WANTRETURN = 0x00001000, + ECO_SAVESEL = 0x00008000, + ECO_SELECTIONBAR = 0x01000000, + ECO_VERTICAL = 0x00400000, // FE specific + } + public enum EcoOperations : int // ECO operations + { + ECOOP_SET = 0x0001, + ECOOP_OR = 0x0002, + ECOOP_AND = 0x0003, + ECOOP_XOR = 0x0004 + } + public enum WordBreakFunctionActions : int // new word break function actions + { + WB_CLASSIFY = 3, + WB_MOVEWORDLEFT = 4, + WB_MOVEWORDRIGHT = 5, + WB_LEFTBREAK = 6, + WB_RIGHTBREAK = 7 + } + //#define PC_FOLLOWING 1 + //#define PC_LEADING 2 + //#define PC_OVERFLOW 3 + //#define PC_DELIMITER 4 + //#define WBF_WORDWRAP 0x010 + //#define WBF_WORDBREAK 0x020 + //#define WBF_OVERFLOW 0x040 + //#define WBF_LEVEL1 0x080 + //#define WBF_LEVEL2 0x100 + //#define WBF_CUSTOM 0x200 + /* Word break flags (used with WB_CLASSIFY) */ + //#define WBF_CLASS ((BYTE) 0x0F) + //#define WBF_ISWHITE ((BYTE) 0x10) + //#define WBF_BREAKLINE ((BYTE) 0x20) + //#define WBF_BREAKAFTER ((BYTE) 0x40) + ///* Far East specific flags */ + //#define IMF_FORCENONE 0x0001 + //#define IMF_FORCEENABLE 0x0002 + //#define IMF_FORCEDISABLE 0x0004 + //#define IMF_CLOSESTATUSWINDOW 0x0008 + //#define IMF_VERTICAL 0x0020 + //#define IMF_FORCEACTIVE 0x0040 + //#define IMF_FORCEINACTIVE 0x0080 + //#define IMF_FORCEREMEMBER 0x0100 + //#define IMF_MULTIPLEEDIT 0x0400 + public enum RTBSelection : int + { + SCF_DEFAULT = 0x0000, + SCF_SELECTION = 0x0001, + SCF_WORD = 0x0002, + SCF_ALL = 0x0004, + SCF_USEUIRULES = 0x0008 + } + [Flags] + public enum CharFormatMasks : uint + { + CFM_NONE = 0, + CFM_BOLD = 0x00000001, + CFM_ITALIC = 0x00000002, + CFM_UNDERLINE = 0x00000004, + CFM_STRIKEOUT = 0x00000008, + CFM_PROTECTED = 0x00000010, + CFM_LINK = 0x00000020, // Exchange hyperlink extension + CFM_SIZE = 0x80000000, + CFM_COLOR = 0x40000000, + CFM_FACE = 0x20000000, + CFM_OFFSET = 0x10000000, + CFM_CHARSET = 0x08000000, + CFM_SMALLCAPS = 0x0040, + CFM_ALLCAPS = 0x0080, + CFM_HIDDEN = 0x0100, + CFM_OUTLINE = 0x0200, + CFM_SHADOW = 0x0400, + CFM_EMBOSS = 0x0800, + CFM_IMPRINT = 0x1000, + CFM_DISABLED = 0x2000, + CFM_REVISED = 0x4000, + CFM_BACKCOLOR = 0x04000000, + CFM_LCID = 0x02000000, + CFM_UNDERLINETYPE = 0x00800000, + CFM_WEIGHT = 0x00400000, + CFM_SPACING = 0x00200000, + CFM_KERNING = 0x00100000, + CFM_STYLE = 0x00080000, + CFM_ANIMATION = 0x00040000, + CFM_REVAUTHOR = 0x00008000, + CFM_SUBSCRIPT = 0x00010000, + CFM_SUPERSCRIPT = 0x00020000 + // CFM_SUBorSUPERSCRIPT = 0x00030000 + } + [Flags] + public enum CharFormatEffects : uint + { + CFE_NONE = 0, + CFE_BOLD = 0x0001, + CFE_ITALIC = 0x0002, + CFE_UNDERLINE = 0x0004, + CFE_STRIKEOUT = 0x0008, + CFE_PROTECTED = 0x0010, + CFE_LINK = 0x0020, + CFE_AUTOBACKCOLOR = 0x04000000, // NOTE: this corresponds to CFM_BACKCOLOR, which controls it + CFE_AUTOCOLOR = 0x40000000, // NOTE: this corresponds to CFM_COLOR, which controls it + CFE_SUBSCRIPT = 0x00010000, // Superscript and subscript are + CFE_SUPERSCRIPT = 0x00020000, // mutually exclusive + CFE_SMALLCAPS = 0x0040, + CFE_ALLCAPS = 0x0080, + CFE_HIDDEN = 0x0100, + CFE_OUTLINE = 0x0200, + CFE_SHADOW = 0x0400, + CFE_EMBOSS = 0x0800, + CFE_IMPRINT = 0x1000, + CFE_DISABLED = 0x2000, + CFE_REVISED = 0x4000 + } + public enum CharUnderline : byte + { + CFU_UNDERLINENONE = 0, + CFU_UNDERLINE = 1, + CFU_UNDERLINEWORD = 2, // displayed as ordinary underline + CFU_UNDERLINEDOUBLE = 3, // displayed as ordinary underline + CFU_UNDERLINEDOTTED = 4, + CFU_UNDERLINEDASH = 5, + CFU_UNDERLINEDASHDOT = 6, + CFU_UNDERLINEDASHDOTDOT = 7, + CFU_UNDERLINEWAVE = 8, + CFU_UNDERLINETHICK = 9, + CFU_INVERT = 0xFE // For IME composition fake a selection. + } + [Flags] + public enum ParaFormatMasks : uint + { + PFM_NONE = 0, + PFM_STARTINDENT = 0x00000001, + PFM_RIGHTINDENT = 0x00000002, + PFM_OFFSET = 0x00000004, + PFM_ALIGNMENT = 0x00000008, + PFM_TABSTOPS = 0x00000010, + PFM_NUMBERING = 0x00000020, + PFM_SPACEBEFORE = 0x00000040, + PFM_SPACEAFTER = 0x00000080, + PFM_LINESPACING = 0x00000100, + PFM_RESERVED = 0x00000200, + PFM_STYLE = 0x00000400, + PFM_BORDER = 0x00000800, + PFM_SHADING = 0x00001000, + PFM_NUMBERINGSTYLE = 0x00002000, + PFM_NUMBERINGTAB = 0x00004000, + PFM_NUMBERINGSTART = 0x00008000, + // PFM_DIR = 0x00010000, + PFM_RTLPARA = 0x00010000, + PFM_KEEP = 0x00020000, + PFM_KEEPNEXT = 0x00040000, + PFM_PAGEBREAKBEFORE = 0x00080000, + PFM_NOLINENUMBER = 0x00100000, + PFM_NOWIDOWCONTROL = 0x00200000, + PFM_DONOTHYPHEN = 0x00400000, + PFM_SIDEBYSIDE = 0x00800000, + PFM_TABLEROWDELIMITER = 0x10000000, + PFM_TEXTWRAPPINGBREAK = 0x20000000, + PFM_TABLE = 0x40000000, + PFM_OFFSETINDENT = 0x80000000 + } + public enum ParaFormatEffects : ushort + { + PFE_RTLPARA = 0x0001, + PFE_KEEP = 0x0002, + PFE_KEEPNEXT = 0x0004, + PFE_PAGEBREAKBEFORE = 0x0008, + PFE_NOLINENUMBER = 0x0010, + PFE_NOWIDOWCONTROL = 0x0020, + PFE_DONOTHYPHEN = 0x0040, + PFE_SIDEBYSIDE = 0x0080, + PFE_TABLEROW = 0xc000, /* These 3 options are mutually */ + PFE_TABLECELLEND = 0x8000, /* exclusive and each imply */ + PFE_TABLECELL = 0x4000, /* that para is part of a table*/ + } + public enum ParaAlignment : ushort + { + PFA_LEFT = 1, + PFA_RIGHT = 2, + PFA_CENTER = 3, + PFA_JUSTIFY = 4, + PFA_FULL_INTERWORD = 5 + } + public enum ParaNumbering : ushort + { + PFN_NONE = 0, + PFN_BULLET = 1, + PFN_ARABIC = 2, + PFN_LOWER = 3, + PFN_UPPER = 4, + PFN_LOWERROMAN = 5, + PFN_UPPERROMAN = 6, + PFN_UNI = 7 + } + public enum ParaSpacing : byte + { + PFS_SINGLE = 0, + PFS_ONEANDONEHALF = 1, + PFS_DOUBLE = 2, + PFS_EXACTSINGLEMIN = 3, + PFS_EXACT = 4, + PFS_EXACT20 = 5 + } + [Flags] + public enum E_FontStyle : byte + { + FS_NONE = 0, + FS_BOLD = 0x01, + FS_UNDERLINE = 0x02, + FS_ITALIC = 0x04, + FS_SUPERSCRIPT = 0x08, + FS_SUBSCRIPT = 0x10 + } + #endregion + #region Structures + //struct CharRange + //{ + // public int cpMin; + // public int cpMax; + //} + [StructLayout(LayoutKind.Sequential, Pack = 4, CharSet = CharSet.Auto)] + public struct CharFormat2 + { + public int cbSize; + public uint dwMask; + public uint dwEffects; + public int yHeight; + public int yOffset; + public int crTextColor; + public byte bCharSet; + public byte bPitchAndFamily; + [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)] + public string szFaceName; + public short wWeight; + public short sSpacing; + public int crBackColor; + public int lcid; + public int dwReserved; + public short sStyle; + public short wKerning; + public byte bUnderlineType; + public byte bAnimation; + public byte bRevAuthor; + public byte bReserved1; + } + public class CharFormatTwo + { + public CharFormatTwo(CharFormat2 cf) + { + _CharFormat2 = cf; + } + private CharFormat2 _CharFormat2; + [Browsable(false)] + public CharFormat2 CharFormat2 + { + get { return _CharFormat2; } + } + [Browsable(false)] + public int cbSize + { + get { return _CharFormat2.cbSize; } + set { _CharFormat2.cbSize = value; } + } + [Editor(typeof(FlagEnumUIEditor), typeof(System.Drawing.Design.UITypeEditor))] + public CharFormatMasks dwMask + { + get { return (CharFormatMasks)_CharFormat2.dwMask; } + set { _CharFormat2.dwMask = (uint)value; } + } + [Editor(typeof(FlagEnumUIEditor), typeof(System.Drawing.Design.UITypeEditor))] + public CharFormatEffects dwEffects + { + get { return (CharFormatEffects)_CharFormat2.dwEffects; } + set { _CharFormat2.dwEffects = (uint)value; } + } + public int yHeight + { + get { return _CharFormat2.yHeight; } + set { _CharFormat2.yHeight = value; } + } + public int yOffset + { + get { return _CharFormat2.yOffset; } + set { _CharFormat2.yOffset = value; } + } + private Color Int2Color(int color) + { + return Color.FromArgb(color % 256, (color / 256) % 256, color / (256 * 256)); + } + private int Color2Int(Color color) + { + return color.R + (color.G * 256) + (color.B * 256 * 256); + } + public Color crTextColor + { + get { return Int2Color(_CharFormat2.crTextColor); } + set { _CharFormat2.crTextColor = Color2Int(value); } + } + public byte bCharSet + { + get { return _CharFormat2.bCharSet; } + set { _CharFormat2.bCharSet = value; } + } + public byte bPitchAndFamily + { + get { return _CharFormat2.bPitchAndFamily; } + set { _CharFormat2.bPitchAndFamily = value; } + } + public string szFaceName + { + get { return _CharFormat2.szFaceName; } + set { _CharFormat2.szFaceName = value; } + } + public short wWeight + { + get { return _CharFormat2.wWeight; } + set { _CharFormat2.wWeight = value; } + } + public short sSpacing + { + get { return _CharFormat2.sSpacing; } + set { _CharFormat2.sSpacing = value; } + } + public Color crBackColor + { + get { return Int2Color(_CharFormat2.crBackColor); } + set { _CharFormat2.crBackColor = Color2Int(value); } + } + public int lcid + { + get { return _CharFormat2.lcid; } + set { _CharFormat2.lcid = value; } + } + public int dwReserved + { + get { return _CharFormat2.dwReserved; } + set { _CharFormat2.dwReserved = value; } + } + public short sStyle + { + get { return _CharFormat2.sStyle; } + set { _CharFormat2.sStyle = value; } + } + public short wKerning + { + get { return _CharFormat2.wKerning; } + set { _CharFormat2.wKerning = value; } + } + public CharUnderline bUnderlineType + { + get { return (CharUnderline)_CharFormat2.bUnderlineType; } + set { _CharFormat2.bUnderlineType = (byte)value; } + } + public byte bAnimation + { + get { return _CharFormat2.bAnimation; } + set { _CharFormat2.bAnimation = value; } + } + public byte bRevAuthor + { + get { return _CharFormat2.bRevAuthor; } + set { _CharFormat2.bRevAuthor = value; } + } + public byte bReserved1 + { + get { return _CharFormat2.bReserved1; } + set { _CharFormat2.bReserved1 = value; } + } + } + [StructLayout(LayoutKind.Sequential, Pack = 4)] + public struct ParaFormat2 + { + public int cbSize; + public int dwMask; + public ushort wNumbering; + public short wEffects; + public int dxStartIndent; + public int dxRightIndent; + public int dxOffset; + public short wAlignment; + public short cTabCount; + [MarshalAs(UnmanagedType.ByValArray, SizeConst = 32)] + public int[] rgxTabs; + public int dySpaceBefore; + public int dySpaceAfter; + public int dyLineSpacing; + public short sStyle; + public byte bLineSpacingRule; + public byte bOutlineLevel; + public short wShadingWeight; + public short wShadingStyle; + public short wNumberingStart; + public short wNumberingStyle; + public short wNumberingTab; + public short wBorderSpace; + public short wBorderWidth; + public short wBorders; + } + public class ParaFormatTwo + { + private ParaFormat2 _ParaFormat2; + public ParaFormatTwo(ParaFormat2 pf) + { + _ParaFormat2 = pf; + } + public ParaFormat2 ParaFormat2 + { + get { return _ParaFormat2; } + } + public int cbSize + { + get { return _ParaFormat2.cbSize; } + set { _ParaFormat2.cbSize = value; } + } + [Editor(typeof(FlagEnumUIEditor), typeof(System.Drawing.Design.UITypeEditor))] + public ParaFormatMasks dwMask + { + get { return (ParaFormatMasks)_ParaFormat2.dwMask; } + set { _ParaFormat2.dwMask = (int)value; } + } + public ParaNumbering wNumbering + { + get { return (ParaNumbering)_ParaFormat2.wNumbering; } + set { _ParaFormat2.wNumbering = (ushort)value; } + } + public ParaFormatEffects wEffects + { + get { return (ParaFormatEffects)_ParaFormat2.wEffects; } + set { _ParaFormat2.wEffects = (short)value; } + } + public int dxStartIndent + { + get { return _ParaFormat2.dxStartIndent; } + set { _ParaFormat2.dxStartIndent = value; } + } + public int dxRightIndent + { + get { return _ParaFormat2.dxRightIndent; } + set { _ParaFormat2.dxRightIndent = value; } + } + public int dxOffset + { + get { return _ParaFormat2.dxOffset; } + set { _ParaFormat2.dxOffset = value; } + } + public ParaAlignment wAlignment + { + get { return (ParaAlignment)_ParaFormat2.wAlignment; } + set { _ParaFormat2.wAlignment = (short)value; } + } + public short cTabCount + { + get { return _ParaFormat2.cTabCount; } + set { _ParaFormat2.cTabCount = value; } + } + public int[] rgxTabs + { + get { return _ParaFormat2.rgxTabs; } + set { _ParaFormat2.rgxTabs = value; } + } + public int dySpaceBefore + { + get { return _ParaFormat2.dySpaceBefore; } + set { _ParaFormat2.dySpaceBefore = value; } + } + public int dySpaceAfter + { + get { return _ParaFormat2.dySpaceAfter; } + set { _ParaFormat2.dySpaceAfter = value; } + } + public int dyLineSpacing + { + get { return _ParaFormat2.dyLineSpacing; } + set { _ParaFormat2.dyLineSpacing = value; } + } + public short sStyle + { + get { return _ParaFormat2.sStyle; } + set { _ParaFormat2.sStyle = value; } + } + public ParaSpacing bLineSpacingRule + { + get { return (ParaSpacing)_ParaFormat2.bLineSpacingRule; } + set { _ParaFormat2.bLineSpacingRule = (byte)value; } + } + public byte bOutlineLevel + { + get { return _ParaFormat2.bOutlineLevel; } + set { _ParaFormat2.bOutlineLevel = value; } + } + public short wShadingWeight + { + get { return _ParaFormat2.wShadingWeight; } + set { _ParaFormat2.wShadingWeight = value; } + } + public short wShadingStyle + { + get { return _ParaFormat2.wShadingStyle; } + set { _ParaFormat2.wShadingStyle = value; } + } + public short wNumberingStart + { + get { return _ParaFormat2.wNumberingStart; } + set { _ParaFormat2.wNumberingStart = value; } + } + public short wNumberingStyle + { + get { return _ParaFormat2.wNumberingStyle; } + set { _ParaFormat2.wNumberingStyle = value; } + } + public short wNumberingTab + { + get { return _ParaFormat2.wNumberingTab; } + set { _ParaFormat2.wNumberingTab = value; } + } + public short wBorderSpace + { + get { return _ParaFormat2.wBorderSpace; } + set { _ParaFormat2.wBorderSpace = value; } + } + public short wBorderWidth + { + get { return _ParaFormat2.wBorderWidth; } + set { _ParaFormat2.wBorderWidth = value; } + } + public short wBorders + { + get { return _ParaFormat2.wBorders; } + set { _ParaFormat2.wBorders = value; } + } + } + #endregion + #region Static Methods + public static bool HasVertScroll(Control ctl) + { + int dwstyle = GetWindowLong(ctl.Handle, GWL_STYLE); + return (dwstyle & WS_VSCROLL) != 0; + } + public static bool HasHorzScroll(Control ctl) + { + int dwstyle = GetWindowLong(ctl.Handle, GWL_STYLE); + return (dwstyle & WS_HSCROLL) != 0; + } + public static void SetScrollLocation(RichTextBox richTextBox, Point point) + { + if (SendMessage(new HandleRef(richTextBox, richTextBox.Handle), Messages.EM_SETSCROLLPOS, 0, ref point) == 0) + throw new Win32Exception(); + } + public static Point GetScrollLocation(RichTextBox richTextBox) + { + Point pt = new Point(); + if (SendMessage(new HandleRef(richTextBox, richTextBox.Handle), Messages.EM_GETSCROLLPOS, 0, ref pt) == 0) + throw new Win32Exception(); + return pt; + } + public static void SetBackgroundColor(RichTextBox richTextBox, Color color) + { + int clr = color.R + (color.G * 256) + (color.B * 256 * 256); + if (SendMessage(new HandleRef(richTextBox, richTextBox.Handle), Messages.EM_SETBKGNDCOLOR, 0, clr) == 0) + throw new Win32Exception(); + } + public static void SetAuto(RichTextBox richTextBox) + { + if (SendMessage(new HandleRef(richTextBox, richTextBox.Handle), Messages.EM_SETOPTIONS, (int)EcoOperations.ECOOP_XOR, (int)EditControlOptions.ECO_AUTOWORDSELECTION) == 0) + throw new Win32Exception(); + } + public static ParaFormatTwo GetParaFormat(RichTextBox richTextBox) + { + ParaFormat2 pf = new ParaFormat2(); + pf.cbSize = Marshal.SizeOf(pf); + if (SendMessage(new HandleRef(richTextBox, richTextBox.Handle), Messages.EM_GETPARAFORMAT, 0, ref pf) == 0) + throw new Win32Exception(); + return new ParaFormatTwo(pf); + } + public static void SetParaFormat(RichTextBox richTextBox, ParaFormatTwo pft) + { + ParaFormat2 pf2 = pft.ParaFormat2; + if (SendMessage(new HandleRef(richTextBox, richTextBox.Handle), Messages.EM_SETPARAFORMAT, 0, ref pf2) == 0) + { + //if(Marshal.GetLastWin32Error()!=0) + throw new Win32Exception(); + } + } + public static CharFormatTwo GetCharFormat(RichTextBox richTextBox, RTBSelection selection) + { + CharFormat2 cf = new CharFormat2(); + cf.cbSize = Marshal.SizeOf(cf); + if (SendMessage(new HandleRef(richTextBox, richTextBox.Handle), Messages.EM_GETCHARFORMAT, selection, ref cf) == 0) + throw new Win32Exception(); + return new CharFormatTwo(cf); + } + public static void SetCharFormat(RichTextBox richTextBox, RTBSelection selection, CharFormatTwo cft) + { + try + { + CharFormat2 cf2 = cft.CharFormat2; + try + { + HandleRef hr = new HandleRef(richTextBox, richTextBox.Handle); + } + catch (Exception ex) + { + Console.WriteLine(ex.Message); + } + if (SendMessage(new HandleRef(richTextBox, richTextBox.Handle), Messages.EM_SETCHARFORMAT, selection, ref cf2) == 0) + throw new Win32Exception(); + } + catch (Exception ex) + { + Console.WriteLine("Error on SetCharFormat {0}", ex.Message); + } + + } + public static void SetHighlightColor(RichTextBox richTextBox, RTBSelection selection, Color color) + { + CharFormatTwo cft = GetCharFormat(richTextBox, selection); + cft.crBackColor = color; + cft.dwEffects = 0; + cft.dwMask = 0; + cft.dwMask |= CharFormatMasks.CFM_BACKCOLOR; + SetCharFormat(richTextBox, selection, cft); + } + public static void SetSpaceBefore(RichTextBox richTextBox, int spaceBefore) + { + ParaFormatTwo pft = GetParaFormat(richTextBox); + pft.dwMask = 0; + pft.dwMask |= ParaFormatMasks.PFM_SPACEBEFORE; + // get the monitor's resolution in DPI and use it to set the linespacing value for + // the richtextbox. Note that without this, the Arial Unicode font made the appearance of + // almost double linespacing. Using PFS_Exact makes it appear as regular single spacing. + Graphics g = richTextBox.CreateGraphics(); + int dpi = Convert.ToInt32((g.DpiX + g.DpiY) / 2); + g.Dispose(); + // dyLineSpacing is Spacing between lines. the PFS_EXACT sets line spacing as the spacing from one + //line to the next, in twips - thus the 1440. + + pft.dySpaceBefore = spaceBefore * 1440 / dpi; + SetParaFormat(richTextBox, pft); + } + //developed for equation editor interface work, but ended up not needing it. Kept it in + // case it is needed in the future. + //public static void SetSpaceAfter(RichTextBox richTextBox, int spaceAfter) + //{ + // ParaFormatTwo pft = GetParaFormat(richTextBox); + // pft.dwMask = 0; + // pft.dwMask |= ParaFormatMasks.PFM_SPACEAFTER; + // // get the monitor's resolution in DPI and use it to set the linespacing value for + // // the richtextbox. Note that without this, the Arial Unicode font made the appearance of + // // almost double linespacing. Using PFS_Exact makes it appear as regular single spacing. + // Graphics g = richTextBox.CreateGraphics(); + // int dpi = Convert.ToInt32((g.DpiX + g.DpiY) / 2); + // g.Dispose(); + // // dyLineSpacing is Spacing between lines. the PFS_EXACT sets line spacing as the spacing from one + // //line to the next, in twips - thus the 1440. + + // pft.dySpaceAfter = spaceAfter * 1440 / dpi; + // SetParaFormat(richTextBox, pft); + //} + public static void SetLineSpacing(RichTextBox richTextBox, ParaSpacing type) + { + ParaFormatTwo pft = GetParaFormat(richTextBox); + pft.bLineSpacingRule = type; + pft.dwMask = 0; + pft.dwMask |= ParaFormatMasks.PFM_LINESPACING; + pft.dwMask |= ParaFormatMasks.PFM_SPACEAFTER; + + // get the monitor's resolution in DPI and use it to set the linespacing value for + // the richtextbox. Note that without this, the Arial Unicode font made the appearance of + // almost double linespacing. Using PFS_Exact makes it appear as regular single spacing. + Graphics g = richTextBox.CreateGraphics(); + int dpi = Convert.ToInt32((g.DpiX + g.DpiY) / 2); + g.Dispose(); + // dyLineSpacing is Spacing between lines. the PFS_EXACT sets line spacing as the spacing from one + //line to the next, in twips - thus the 1440. + + pft.dyLineSpacing = Convert.ToInt32(.5 + richTextBox.Font.GetHeight(dpi)) * 1440 / dpi; + SetParaFormat(richTextBox, pft); + } + public static E_FontStyle GetFontStyle(RichTextBox richTextBox) + { + E_FontStyle fs = E_FontStyle.FS_NONE; + CharFormatTwo cft = GetCharFormat(richTextBox, RTBSelection.SCF_SELECTION); + if (((cft.dwMask & CharFormatMasks.CFM_BOLD) == CharFormatMasks.CFM_BOLD) && + ((cft.dwEffects & CharFormatEffects.CFE_BOLD) == CharFormatEffects.CFE_BOLD)) fs |= E_FontStyle.FS_BOLD; + if (((cft.dwMask & CharFormatMasks.CFM_UNDERLINE) == CharFormatMasks.CFM_UNDERLINE) && + ((cft.dwEffects & CharFormatEffects.CFE_UNDERLINE) == CharFormatEffects.CFE_UNDERLINE)) fs |= E_FontStyle.FS_UNDERLINE; + if (((cft.dwMask & CharFormatMasks.CFM_ITALIC) == CharFormatMasks.CFM_ITALIC) && + ((cft.dwEffects & CharFormatEffects.CFE_ITALIC) == CharFormatEffects.CFE_ITALIC)) fs |= E_FontStyle.FS_ITALIC; + if (richTextBox.SelectionCharOffset == -2) fs |= E_FontStyle.FS_SUBSCRIPT; + if (richTextBox.SelectionCharOffset == 2) fs |= E_FontStyle.FS_SUPERSCRIPT; + return fs; + } + public static void SetFontStyle(RichTextBox richTextBox, E_FontStyle fs) + { + CharFormatTwo cft = GetCharFormat(richTextBox, RTBSelection.SCF_SELECTION); + if ((fs & E_FontStyle.FS_BOLD) == E_FontStyle.FS_BOLD) + { + cft.dwEffects |= CharFormatEffects.CFE_BOLD; + cft.dwMask |= CharFormatMasks.CFM_BOLD; + } + if ((fs & E_FontStyle.FS_UNDERLINE) == E_FontStyle.FS_UNDERLINE) + { + cft.dwEffects |= CharFormatEffects.CFE_UNDERLINE; + cft.dwMask |= CharFormatMasks.CFM_UNDERLINE; + } + if ((fs & E_FontStyle.FS_ITALIC) == E_FontStyle.FS_ITALIC) + { + cft.dwEffects |= CharFormatEffects.CFE_ITALIC; + cft.dwMask |= CharFormatMasks.CFM_ITALIC; + } + if ((fs & E_FontStyle.FS_SUBSCRIPT) == E_FontStyle.FS_SUBSCRIPT) + { + richTextBox.SelectionCharOffset = -2; + } + if ((fs & E_FontStyle.FS_SUPERSCRIPT) == E_FontStyle.FS_SUPERSCRIPT) + { + richTextBox.SelectionCharOffset = 2; + } + SetCharFormat(richTextBox, RTBSelection.SCF_SELECTION, cft); + } + public static bool IsSuperScript(RichTextBox richTextBox) + { + return (richTextBox.SelectionCharOffset>0); + } + public static bool IsSubScript(RichTextBox richTextBox) + { + return (richTextBox.SelectionCharOffset < 0); + } + public static void ToggleSubscript(bool bSet, RichTextBox richTextBox, RTBSelection selection) + { + if (bSet) + richTextBox.SelectionCharOffset = -2; + else + richTextBox.SelectionCharOffset = 0; + } + public static void ToggleSuperscript(bool bSet, RichTextBox richTextBox, RTBSelection selection) + { + if (bSet) + richTextBox.SelectionCharOffset = 2; + else + richTextBox.SelectionCharOffset = 0; + } + public static bool IsBold(RichTextBox richTextBox) + { + CharFormatTwo cft = GetCharFormat(richTextBox, RTBSelection.SCF_SELECTION); + return (((cft.dwMask & CharFormatMasks.CFM_BOLD) == CharFormatMasks.CFM_BOLD) && + ((cft.dwEffects & CharFormatEffects.CFE_BOLD) == CharFormatEffects.CFE_BOLD)); + } + public static void ToggleBold(bool bSet, RichTextBox richTextBox, RTBSelection selection) + { + CharFormatTwo cft = GetCharFormat(richTextBox, selection); + if (bSet) + { + cft.dwEffects = CharFormatEffects.CFE_BOLD; + cft.dwMask = CharFormatMasks.CFM_BOLD; + } + else + { + cft.dwEffects = CharFormatEffects.CFE_NONE; + cft.dwMask = CharFormatMasks.CFM_BOLD; + } + SetCharFormat(richTextBox, selection, cft); + } + public static bool IsUnderline(RichTextBox richTextBox) + { + CharFormatTwo cft = GetCharFormat(richTextBox, RTBSelection.SCF_SELECTION); + return (((cft.dwMask & CharFormatMasks.CFM_UNDERLINE) == CharFormatMasks.CFM_UNDERLINE) && + ((cft.dwEffects & CharFormatEffects.CFE_UNDERLINE) == CharFormatEffects.CFE_UNDERLINE)); + } + public static void ToggleUnderline(bool bSet, RichTextBox richTextBox, RTBSelection selection) + { + CharFormatTwo cft = GetCharFormat(richTextBox, selection); + if (bSet) + { + cft.dwEffects = CharFormatEffects.CFE_UNDERLINE; + cft.dwMask = CharFormatMasks.CFM_UNDERLINE; + } + else + { + cft.dwEffects = CharFormatEffects.CFE_NONE; + cft.dwMask = CharFormatMasks.CFM_UNDERLINE; + } + SetCharFormat(richTextBox, selection, cft); + } + public static bool IsItalic(RichTextBox richTextBox) + { + CharFormatTwo cft = GetCharFormat(richTextBox, RTBSelection.SCF_SELECTION); + return (((cft.dwMask & CharFormatMasks.CFM_ITALIC) == CharFormatMasks.CFM_ITALIC) && + ((cft.dwEffects & CharFormatEffects.CFE_ITALIC) == CharFormatEffects.CFE_ITALIC)); + } + public static void ToggleItalic(bool bSet, RichTextBox richTextBox, RTBSelection selection) + { + CharFormatTwo cft = GetCharFormat(richTextBox, selection); + if (bSet) + { + cft.dwEffects = CharFormatEffects.CFE_ITALIC; + cft.dwMask = CharFormatMasks.CFM_ITALIC; + } + else + { + cft.dwEffects = CharFormatEffects.CFE_NONE; + cft.dwMask = CharFormatMasks.CFM_ITALIC; + } + SetCharFormat(richTextBox, selection, cft); + } + //public static bool IsLink(RichTextBox richTextBox) + //{ + // CharFormatTwo cft = GetCharFormat(richTextBox, RTBSelection.SCF_SELECTION); + // return ((cft.dwEffects & CharFormatEffects.CFE_PROTECTED) == CharFormatEffects.CFE_PROTECTED); + //} + //public static void ToggleLink(bool bSet, RichTextBox richTextBox, RTBSelection selection) + //{ + // CharFormatTwo cft = GetCharFormat(richTextBox, selection); + // if (bSet) + // { + // cft.dwEffects |= CharFormatEffects.CFE_LINK; + // cft.dwMask |= CharFormatMasks.CFM_LINK; + // } + // else + // { + // cft.dwEffects &= ~RTBAPI.CharFormatEffects.CFE_LINK; + // } + // SetCharFormat(richTextBox, selection, cft); + //} + //public static void UnProtect(RichTextBox richTextBox) //, string type, string text, string link) + //{ + // //richTextBox.DetectUrls = false; + // CharFormatTwo cft = GetCharFormat(richTextBox, RTBAPI.RTBSelection.SCF_SELECTION); ; + // //int position = richTextBox.SelectionStart = richTextBox.TextLength; + // //richTextBox.SelectionLength = 0; + // //richTextBox.SelectedRtf = @"{\rtf1\ansi " + text + @"\v #" + link + @"\v0}"; + // //richTextBox.SelectedRtf = "{" + string.Format(@"\rtf1\ansi\protect\v {0}\v0 {1}\v #{2}", type, text, link) + "}"; + // //richTextBox.Select(position, type.Length + text.Length + link.Length + 1); + // cft.dwMask = RTBAPI.CharFormatMasks.CFM_PROTECTED; + // cft.dwEffects = 0; + // // The lines below can be used to allow link text to be edited + // //charFormat.dwMask = RTBAPI.CharFormatMasks.CFM_LINK; + // //charFormat.dwEffects = RTBAPI.CharFormatEffects.CFE_LINK; + // SetCharFormat(richTextBox, RTBSelection.SCF_SELECTION, cft); + // //rtbRTF.SetSelectionLink(true); + // //richTextBox.SelectionStart = richTextBox.TextLength; + // //richTextBox.SelectionLength = 0; + //} + //public static void Protect(RichTextBox richTextBox) //, string type, string text, string link) + //{ + // CharFormatTwo cft = GetCharFormat(richTextBox, RTBAPI.RTBSelection.SCF_SELECTION); ; + // cft.dwMask = CharFormatMasks.CFM_PROTECTED; + // cft.dwEffects = CharFormatEffects.CFE_PROTECTED; + // SetCharFormat(richTextBox, RTBSelection.SCF_SELECTION, cft); + //} + //public static void SetLink(RichTextBox richTextBox, string type, string text, string link) + //{ + // richTextBox.DetectUrls = false; + // CharFormatTwo cft = GetCharFormat(richTextBox, RTBAPI.RTBSelection.SCF_SELECTION); ; + // int position = richTextBox.SelectionStart = richTextBox.TextLength; + // richTextBox.SelectionLength = 0; + // //richTextBox.SelectedRtf = @"{\rtf1\ansi " + text + @"\v #" + link + @"\v0}"; + // richTextBox.SelectedRtf = "{" + string.Format(@"\rtf1\ansi\protect\v {0}\v0 {1}\v #{2}", type, text, link) + "}"; + // richTextBox.Select(position, type.Length + text.Length + link.Length + 1); + // cft.dwMask = RTBAPI.CharFormatMasks.CFM_LINK | RTBAPI.CharFormatMasks.CFM_PROTECTED; + // cft.dwEffects = RTBAPI.CharFormatEffects.CFE_LINK | RTBAPI.CharFormatEffects.CFE_PROTECTED; + // // The lines below can be used to allow link text to be edited + // //charFormat.dwMask = RTBAPI.CharFormatMasks.CFM_LINK; + // //charFormat.dwEffects = RTBAPI.CharFormatEffects.CFE_LINK; + // SetCharFormat(richTextBox, RTBSelection.SCF_SELECTION, cft); + // //rtbRTF.SetSelectionLink(true); + // richTextBox.SelectionStart = richTextBox.TextLength; + // richTextBox.SelectionLength = 0; + //} + #endregion + } +} diff --git a/PROMS/Volian.Base.Library/RtfEditor.cs b/PROMS/Volian.Base.Library/RtfEditor.cs new file mode 100644 index 00000000..60e00494 --- /dev/null +++ b/PROMS/Volian.Base.Library/RtfEditor.cs @@ -0,0 +1,36 @@ +using System.ComponentModel; +using System.Drawing.Design; +using System.Windows.Forms; +using System.Windows.Forms.Design; +using System; + + +namespace Volian.Base.Library +{ + // The RtfEditor inherits from the UITypeEditor and is used to edit Rtf fields. This provides the interface for fields in FormatConfig + // and uses the frmRtfEdit to provide a mechanism to do basic editing of text with a subset of rtf command support. + public class RtfEditor : UITypeEditor + { + public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context) + { + return UITypeEditorEditStyle.Modal; + } + public override object EditValue(ITypeDescriptorContext context, System.IServiceProvider provider, object value) + { + IWindowsFormsEditorService svc = provider.GetService(typeof(IWindowsFormsEditorService)) as IWindowsFormsEditorService; + string rw = value as string; + if (svc != null && rw != null) + { + using (frmRtfEdit form = new frmRtfEdit()) + { + form.Value = rw; + if (svc.ShowDialog(form) == DialogResult.OK) + { + rw = form.Value; // update object + } + } + } + return rw; + } + } +} diff --git a/PROMS/Volian.Base.Library/frmRtfEdit.Designer.cs b/PROMS/Volian.Base.Library/frmRtfEdit.Designer.cs new file mode 100644 index 00000000..1743f71b --- /dev/null +++ b/PROMS/Volian.Base.Library/frmRtfEdit.Designer.cs @@ -0,0 +1,179 @@ +namespace Volian.Base.Library +{ + partial class frmRtfEdit + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.btnOK = new System.Windows.Forms.Button(); + this.btnCancel = new System.Windows.Forms.Button(); + this.rtfBox = new System.Windows.Forms.RichTextBox(); + this.btnBold = new DevComponents.DotNetBar.ButtonX(); + this.btnItalics = new DevComponents.DotNetBar.ButtonX(); + this.btnUnderline = new DevComponents.DotNetBar.ButtonX(); + this.btnSubscript = new DevComponents.DotNetBar.ButtonX(); + this.btnSuperscript = new DevComponents.DotNetBar.ButtonX(); + this.btnHardspace = new DevComponents.DotNetBar.ButtonX(); + this.SuspendLayout(); + // + // btnOK + // + this.btnOK.DialogResult = System.Windows.Forms.DialogResult.OK; + this.btnOK.Location = new System.Drawing.Point(38, 144); + this.btnOK.Name = "btnOK"; + this.btnOK.Size = new System.Drawing.Size(75, 23); + this.btnOK.TabIndex = 3; + this.btnOK.Text = "OK"; + this.btnOK.UseVisualStyleBackColor = true; + this.btnOK.Click += new System.EventHandler(this.btnOK_Click); + // + // btnCancel + // + this.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel; + this.btnCancel.Location = new System.Drawing.Point(143, 144); + this.btnCancel.Name = "btnCancel"; + this.btnCancel.Size = new System.Drawing.Size(75, 23); + this.btnCancel.TabIndex = 4; + this.btnCancel.Text = "Cancel"; + this.btnCancel.UseVisualStyleBackColor = true; + this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click); + // + // rtfBox + // + this.rtfBox.Location = new System.Drawing.Point(38, 73); + this.rtfBox.Name = "rtfBox"; + this.rtfBox.Size = new System.Drawing.Size(214, 50); + this.rtfBox.TabIndex = 5; + this.rtfBox.Text = ""; + this.rtfBox.SelectionChanged += new System.EventHandler(this.rtfBox_SelectionChanged); + // + // btnBold + // + this.btnBold.AccessibleRole = System.Windows.Forms.AccessibleRole.PushButton; + this.btnBold.ColorTable = DevComponents.DotNetBar.eButtonColor.OrangeWithBackground; + this.btnBold.Location = new System.Drawing.Point(12, 12); + this.btnBold.Name = "btnBold"; + this.btnBold.Size = new System.Drawing.Size(31, 24); + this.btnBold.Style = DevComponents.DotNetBar.eDotNetBarStyle.StyleManagerControlled; + this.btnBold.TabIndex = 6; + this.btnBold.Text = "B"; + this.btnBold.Click += new System.EventHandler(this.btnBold_Click); + // + // btnItalics + // + this.btnItalics.AccessibleRole = System.Windows.Forms.AccessibleRole.PushButton; + this.btnItalics.ColorTable = DevComponents.DotNetBar.eButtonColor.OrangeWithBackground; + this.btnItalics.Font = new System.Drawing.Font("Microsoft Sans Serif", 7.8F, System.Drawing.FontStyle.Italic, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.btnItalics.Location = new System.Drawing.Point(43, 12); + this.btnItalics.Name = "btnItalics"; + this.btnItalics.Size = new System.Drawing.Size(31, 24); + this.btnItalics.Style = DevComponents.DotNetBar.eDotNetBarStyle.StyleManagerControlled; + this.btnItalics.TabIndex = 7; + this.btnItalics.Text = "I"; + this.btnItalics.Click += new System.EventHandler(this.btnItalics_Click); + // + // btnUnderline + // + this.btnUnderline.AccessibleRole = System.Windows.Forms.AccessibleRole.PushButton; + this.btnUnderline.ColorTable = DevComponents.DotNetBar.eButtonColor.OrangeWithBackground; + this.btnUnderline.Location = new System.Drawing.Point(74, 12); + this.btnUnderline.Name = "btnUnderline"; + this.btnUnderline.Size = new System.Drawing.Size(31, 24); + this.btnUnderline.Style = DevComponents.DotNetBar.eDotNetBarStyle.StyleManagerControlled; + this.btnUnderline.TabIndex = 8; + this.btnUnderline.Text = "U"; + this.btnUnderline.Click += new System.EventHandler(this.btnUnderline_Click); + // + // btnSubscript + // + this.btnSubscript.AccessibleRole = System.Windows.Forms.AccessibleRole.PushButton; + this.btnSubscript.ColorTable = DevComponents.DotNetBar.eButtonColor.OrangeWithBackground; + this.btnSubscript.Location = new System.Drawing.Point(12, 42); + this.btnSubscript.Name = "btnSubscript"; + this.btnSubscript.Size = new System.Drawing.Size(75, 23); + this.btnSubscript.Style = DevComponents.DotNetBar.eDotNetBarStyle.StyleManagerControlled; + this.btnSubscript.TabIndex = 9; + this.btnSubscript.Text = "Subscript"; + this.btnSubscript.Click += new System.EventHandler(this.btnSubscript_Click); + // + // btnSuperscript + // + this.btnSuperscript.AccessibleRole = System.Windows.Forms.AccessibleRole.PushButton; + this.btnSuperscript.ColorTable = DevComponents.DotNetBar.eButtonColor.OrangeWithBackground; + this.btnSuperscript.Location = new System.Drawing.Point(90, 42); + this.btnSuperscript.Name = "btnSuperscript"; + this.btnSuperscript.Size = new System.Drawing.Size(75, 23); + this.btnSuperscript.Style = DevComponents.DotNetBar.eDotNetBarStyle.StyleManagerControlled; + this.btnSuperscript.TabIndex = 10; + this.btnSuperscript.Text = "Superscript"; + this.btnSuperscript.Click += new System.EventHandler(this.btnSuperscript_Click); + // + // btnHardspace + // + this.btnHardspace.AccessibleRole = System.Windows.Forms.AccessibleRole.PushButton; + this.btnHardspace.ColorTable = DevComponents.DotNetBar.eButtonColor.OrangeWithBackground; + this.btnHardspace.Location = new System.Drawing.Point(150, 10); + this.btnHardspace.Name = "btnHardspace"; + this.btnHardspace.Size = new System.Drawing.Size(37, 26); + this.btnHardspace.Style = DevComponents.DotNetBar.eDotNetBarStyle.StyleManagerControlled; + this.btnHardspace.TabIndex = 11; + this.btnHardspace.Text = "HS"; + this.btnHardspace.Click += new System.EventHandler(this.btnHardspace_Click); + // + // frmRtfEdit + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(282, 198); + this.Controls.Add(this.btnHardspace); + this.Controls.Add(this.btnSuperscript); + this.Controls.Add(this.btnSubscript); + this.Controls.Add(this.btnUnderline); + this.Controls.Add(this.btnItalics); + this.Controls.Add(this.btnBold); + this.Controls.Add(this.rtfBox); + this.Controls.Add(this.btnCancel); + this.Controls.Add(this.btnOK); + this.Name = "frmRtfEdit"; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; + this.Text = "Rich Text Edit"; + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.Button btnOK; + private System.Windows.Forms.Button btnCancel; + private System.Windows.Forms.RichTextBox rtfBox; + private DevComponents.DotNetBar.ButtonX btnBold; + private DevComponents.DotNetBar.ButtonX btnItalics; + private DevComponents.DotNetBar.ButtonX btnUnderline; + private DevComponents.DotNetBar.ButtonX btnSubscript; + private DevComponents.DotNetBar.ButtonX btnSuperscript; + private DevComponents.DotNetBar.ButtonX btnHardspace; + } +} \ No newline at end of file diff --git a/PROMS/Volian.Base.Library/frmRtfEdit.cs b/PROMS/Volian.Base.Library/frmRtfEdit.cs new file mode 100644 index 00000000..09aea923 --- /dev/null +++ b/PROMS/Volian.Base.Library/frmRtfEdit.cs @@ -0,0 +1,199 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Windows.Forms; +using System.Text.RegularExpressions; +using DevComponents.DotNetBar; + +namespace Volian.Base.Library +{ + // this is the form used in the UCF (User Control of Format) feature that displays text and allows the user to modify it to + // add/remove various text attributes: Underline, bold, italics, super/sub script & Hard space. + public partial class frmRtfEdit : Form + { + public frmRtfEdit() + { + InitializeComponent(); + } + private static Regex regHyphen = new Regex(@"(?", "\\\\"), @"\u8209?"); + int indx = rtbString.IndexOf('-'); + while (indx > -1) + { + if (indx > 2) + { + if (rtbString[indx - 1] != 'i' || rtbString[indx - 2] != 'f' || rtbString[indx - 3] != '\\') + { + rtbString = rtbString.Remove(indx, 1); + rtbString = rtbString.Insert(indx, @"\u8209?"); + } + if (indx + 1 > rtbString.Length) indx = -1; + else indx = rtbString.IndexOf('-', indx + 1); + } + } + return rtbString; + } + set + { + string makeRtf = @"{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fnil\fcharset0 Microsoft Sans Serif;}}\viewkind4\uc1\pard\f0\fs16 " + value + @"\par}"; + makeRtf = makeRtf.Replace(@"\xa0", "'"); + rtfBox.Rtf = makeRtf; + } + } + // when saving text, keep all of the necessary rtf commands that are used to define the text attributes. The rest are removed + public static string StaticReplaceRTFClause(Match m) + { + try + { + string token = m.Groups[1].Value; + switch (token[1]) + { + case '\\': + return token; + case 'u': + if (Regex.IsMatch(token, @"^\\u[0-9]+$")) + return token; // Special Charcaters + if (Regex.IsMatch(token, @"^\\ulnone ?$")) + return token; + if (Regex.IsMatch(token, @"^\\ul.*$")) + return token; // Underline + if (Regex.IsMatch(token, @"^\\up[0-9] ?$")) + return token; // shift up (superscript) + break; + case 'd': + if (Regex.IsMatch(token, @"^\\dn[0-9] ?$")) + return token; // shift down (subscript) + break; + case '\'': // Special Character + return token; + case 'b': // Bold + return token; + case 'i': // Italics + return token; + case '{': // look for escape for curly braces: + return token; + case '}': + return token; + case 'l': + if (Regex.IsMatch(token, @"^\\line ?$")) return token; + if (Regex.IsMatch(token, @"^\\li[-0-9]+ ?$")) return token; // line indent + break; + case 'f': + if (Regex.IsMatch(token, @"^\\fi[-0-9]+ ?$")) return token; // first line indent + break; + case 'p': + if (Regex.IsMatch(token, @"^\\par ?$")) return @"{\par}"; + break; + } + } + catch (Exception ex) + { + Console.WriteLine("StaticReplaceRTFClause {0} - {1}", ex.GetType().Name, ex.Message); + } + return "";//Strip All + } + // remove all of the rtf commands that are not needed to define the attributes of text that are supported: + private static Regex reg1 = new Regex(@"\\par\r\n(?!\\)"); + private static Regex reg2 = new Regex(@"[\r\n]", RegexOptions.Singleline); // Strip Carriage Returns and Newlines + private static Regex reg3 = new Regex(@"^\{(.*)\}$", RegexOptions.Singleline); // Strip Opening and Closing Braces + private static Regex reg4 = new Regex(@"\{[^{]*?\}", RegexOptions.Singleline); // Strip Clauses - remove anything from curly braces + private static Regex reg5 = new Regex(@"\{[^{]*?\}", RegexOptions.Singleline); // Strip Clauses - remove anything from curly braces + private static Regex reg6 = new Regex(@"(\\[^' \\?\r\n\t]+)(?=\\)"); // add space after token if followed by token + private static Regex reg7 = new Regex(@"(\\[^' \\?\r\n\t]+ )"); // take backslash xyz and evaluates them + private static Regex reg8 = new Regex(@"(\\[^' \\?\r\n\t]+) (?=\\)"); // remove space between tokens + private static Regex reg9 = new Regex(@"(\\[^' \\?\r\n\t]+) (?=\r\n)"); // remove space before /r/n + private static Regex reg10 = new Regex(@"(\\[0-9a-z]+)$"); // end of text attribute needs a 'space' + private string RtfToDbText(string rtf) + { + // replace \{ & \} with (![ & (!] respectively and then redo at end. The curly braces + // are rtf so were getting removed and/or not handled correctly. + string retval = rtf.Replace(@"\{", @" (!["); + retval = retval.Replace(@"\}", @" (!]"); + + // remove carriage return/newlines after \par commands (these are introduced by rtb + // for hard returns, goes into rtb as \par and comes out as \par\r\n): + retval = reg1.Replace(retval, "\\par "); + retval = retval.Replace("\\v0\r\n", "\\v0 "); // Replace Carriage Return and Newline after comment + retval = reg2.Replace(retval, ""); // Strip Carriage Returns and Newlines + retval = reg3.Replace(retval, "$1"); // Strip Opening and Closing Braces + retval = reg4.Replace(retval, ""); // Strip Clauses - remove anything from curly braces + retval = reg5.Replace(retval, ""); // Strip Clauses - remove anything from curly braces + retval = reg6.Replace(retval, "$1 "); // add space after token if followed by token + retval = reg7.Replace(retval, new MatchEvaluator(StaticReplaceRTFClause)); // take backslash xyz and evaluates them + retval = reg8.Replace(retval, "$1"); // remove space between tokens + retval = reg9.Replace(retval, "$1"); // remove space before /r/n + if (retval.EndsWith(@"{\par}")) retval = retval.Remove(retval.Length - 6, 6); + retval = reg10.Replace(retval, "$1 "); + // remove \r\n at end of string if the string has 2 or more characters + if (retval.EndsWith("\r\n")) retval = retval.Remove(retval.Length - 2, 2); + if (retval.Length == 0) return ""; + if (retval.EndsWith(@"\v")) retval = retval.Remove(retval.Length - 2, 2); + retval = retval.Replace(@" (![", @"\{"); + retval = retval.Replace(@" (!]", @"\}"); + retval = retval.Replace("`",@"\xA0"); + return retval; + } + private void btnBold_Click(object sender, EventArgs e) + { + RTBAPI.ToggleBold(!RTBAPI.IsBold(rtfBox), rtfBox, rtfBox.SelectionLength == 0 ? RTBAPI.RTBSelection.SCF_DEFAULT : RTBAPI.RTBSelection.SCF_SELECTION); + btnBold.Checked = RTBAPI.IsBold(rtfBox); + } + private void btnItalics_Click(object sender, EventArgs e) + { + RTBAPI.ToggleItalic(!RTBAPI.IsItalic(rtfBox), rtfBox, rtfBox.SelectionLength == 0 ? RTBAPI.RTBSelection.SCF_DEFAULT : RTBAPI.RTBSelection.SCF_SELECTION); + btnItalics.Checked = RTBAPI.IsItalic(rtfBox); + } + private void btnUnderline_Click(object sender, EventArgs e) + { + RTBAPI.ToggleUnderline(!RTBAPI.IsUnderline(rtfBox), rtfBox, rtfBox.SelectionLength == 0 ? RTBAPI.RTBSelection.SCF_DEFAULT : RTBAPI.RTBSelection.SCF_SELECTION); + btnUnderline.Checked = RTBAPI.IsUnderline(rtfBox); + } + private void btnSubscript_Click(object sender, EventArgs e) + { + RTBAPI.ToggleSubscript(!RTBAPI.IsSubScript(rtfBox), rtfBox, rtfBox.SelectionLength == 0 ? RTBAPI.RTBSelection.SCF_DEFAULT : RTBAPI.RTBSelection.SCF_SELECTION); + btnSubscript.Checked = RTBAPI.IsSubScript(rtfBox); + } + private void btnSuperscript_Click(object sender, EventArgs e) + { + RTBAPI.ToggleSuperscript(!RTBAPI.IsSuperScript(rtfBox), rtfBox, rtfBox.SelectionLength == 0 ? RTBAPI.RTBSelection.SCF_DEFAULT : RTBAPI.RTBSelection.SCF_SELECTION); + btnSuperscript.Checked = RTBAPI.IsSuperScript(rtfBox); + } + private void btnOK_Click(object sender, EventArgs e) + { + } + private void btnCancel_Click(object sender, EventArgs e) + { + } + private void rtfBox_SelectionChanged(object sender, EventArgs e) + { + btnBold.Checked = RTBAPI.IsBold(rtfBox); + btnItalics.Checked = RTBAPI.IsItalic(rtfBox); + btnUnderline.Checked = RTBAPI.IsUnderline(rtfBox); + } + private void btnHardspace_Click(object sender, EventArgs e) + { + AddText("`"); + } + private void AddText(string str) + { + // See comments in AddRtf(string str) to explain the font style setting + RTBAPI.E_FontStyle fs = RTBAPI.GetFontStyle(rtfBox); + int positionStart = rtfBox.SelectionStart; + rtfBox.SelectedText = str; + int positionAfter = rtfBox.SelectionStart; + rtfBox.Select(positionStart, positionAfter - positionStart); + RTBAPI.SetFontStyle(rtfBox, fs); + rtfBox.Select(positionAfter, 0); + } + } +} + diff --git a/PROMS/Volian.Base.Library/frmRtfEdit.resx b/PROMS/Volian.Base.Library/frmRtfEdit.resx new file mode 100644 index 00000000..7080a7d1 --- /dev/null +++ b/PROMS/Volian.Base.Library/frmRtfEdit.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/PROMS/Volian.Controls.Library/DisplayTags.cs b/PROMS/Volian.Controls.Library/DisplayTags.cs index 6c08cab4..2fce2ff8 100644 --- a/PROMS/Volian.Controls.Library/DisplayTags.cs +++ b/PROMS/Volian.Controls.Library/DisplayTags.cs @@ -270,7 +270,9 @@ namespace Volian.Controls.Library bool _checkoffsAllowed = true; if (fmtdata.ProcData.CheckOffData.CheckoffOnSubStepsOnly) _checkoffsAllowed = cmbCheckoff.Enabled = CurItemInfo.IsType("Substep"); - if (_checkoffsAllowed && !(fmtdata.ProcData.CheckOffData.CheckOffList == null) && !(fmtdata.ProcData.CheckOffData.CheckOffList.MaxIndex == 0)) + + int maxindx = fmtdata.ProcData.CheckOffUCF ? fmtdata.ProcData.CheckOffData.CheckOffList.MaxIndex : fmtdata.ProcData.CheckOffData.CheckOffList.MaxIndexNoInherit; + if (_checkoffsAllowed && !(fmtdata.ProcData.CheckOffData.CheckOffList == null) && !(maxindx == 0)) { cmbCheckoff.Items.Clear(); foreach (CheckOff co in fmtdata.ProcData.CheckOffData.CheckOffList) @@ -280,14 +282,27 @@ namespace Volian.Controls.Library // bug fix B2015-186 // the config had a really big number for the checkoff index. // if that config number is greater than the number of items in the checkoff list, default to an index of zero + // for the ucf, add possibility of index >= 100 which flags a UCF index. if (sc.Step_CheckOffIndex != -1) - cmbCheckoff.SelectedIndex = (sc.Step_CheckOffIndex <= cmbCheckoff.Items.Count - 1) ? sc.Step_CheckOffIndex : 0; + { + int cntindx = 0; + // find matching string & use its index: + foreach (CheckOff co in fmtdata.ProcData.CheckOffData.CheckOffList) + { + if (co.Index == sc.Step_CheckOffIndex) + { + cmbCheckoff.SelectedIndex = cntindx; + break; + } + cntindx++; + } + } } // if there are no checkoffs OR // if this is a sign-off, the checkoff list is not enabled either (matches 16bit functionality) At some point, we // may want to allow them to turn off the checkoff // Catawba and McGuire formats use this - if (_checkoffsAllowed && (fmtdata.ProcData.CheckOffData.CheckOffList == null || fmtdata.ProcData.CheckOffData.CheckOffList.MaxIndex == 0) || + if (_checkoffsAllowed && (fmtdata.ProcData.CheckOffData.CheckOffList == null || maxindx == 0) || fmtdata.ProcData.CheckOffData.Menu == "Signoff") { SectionConfig secf = CurItemInfo.ActiveSection.MyConfig as SectionConfig; @@ -638,6 +653,21 @@ namespace Volian.Controls.Library MyEditItem.SaveContents(); // set selected index in the step's config. int indx = cmbCheckoff.SelectedIndex; + // get index, if greater than 100, store that - otherwise store index down list. + // if this format does not have ucf signoffs, indx is just the selected index from the combo mobx. + if (CurItemInfo.ActiveFormat.PlantFormat.FormatData.ProcData.CheckOffUCF) + { + // get index, if greater than 100, store that - otherwise store index down list. + // if this format does not have ucf signoffs, indx is just the selected index from the combo mobx. + foreach (CheckOff co in CurItemInfo.ActiveFormat.PlantFormat.FormatData.ProcData.CheckOffData.CheckOffList) + { + if (cmbCheckoff.SelectedItem == co.MenuItem) + { + if ((int)co.Index >= 100) indx = (int)co.Index; + break; + } + } + } StepConfig sc = CurItemInfo.MyConfig as StepConfig; sc.Step_CheckOffIndex = indx; //using (Content cnt = Content.Get(CurItemInfo.MyContent.ContentID)) diff --git a/PROMS/Volian.Controls.Library/RtfRawItem.cs b/PROMS/Volian.Controls.Library/RtfRawItem.cs index ee3e91ee..d2e5e41e 100644 --- a/PROMS/Volian.Controls.Library/RtfRawItem.cs +++ b/PROMS/Volian.Controls.Library/RtfRawItem.cs @@ -6,6 +6,7 @@ using System.Data; using System.Text; using System.Windows.Forms; using VEPROMS.CSLA.Library; +using Volian.Base.Library; namespace Volian.Controls.Library { diff --git a/PROMS/Volian.Controls.Library/RtfRawItem.designer.cs b/PROMS/Volian.Controls.Library/RtfRawItem.designer.cs index 1160b6d3..c19953c3 100644 --- a/PROMS/Volian.Controls.Library/RtfRawItem.designer.cs +++ b/PROMS/Volian.Controls.Library/RtfRawItem.designer.cs @@ -52,7 +52,7 @@ //RTBAPI.SetLineSpacing(this._MyStepRTB, RTBAPI.ParaSpacing.PFS_DOUBLE); // RTBAPI.SetSpaceAfter(this._MyStepRTB, 200); - RTBAPI.SetSpaceBefore(this._MyStepRTB, 20); + Volian.Base.Library.RTBAPI.SetSpaceBefore(this._MyStepRTB, 20); // // _MyStepRTB // diff --git a/PROMS/Volian.Controls.Library/UCFDiffDetails.xsl b/PROMS/Volian.Controls.Library/UCFDiffDetails.xsl new file mode 100644 index 00000000..654713b0 --- /dev/null +++ b/PROMS/Volian.Controls.Library/UCFDiffDetails.xsl @@ -0,0 +1,198 @@ + + + + + + + + + + +

User Control of Format Differences

+ + + + + + + + + +
+ + + + + + + + + + + + + + + + +
FlagModeValue
+

+ + + + + + + + + + + + + + + + + +
Check Off Header TypeActiveMode
+

+ + + + + + + + + + + + + + + +
Check Off TypeActiveMode
+

+ + + + + + + + + + + + + +
Check Off X Offset Adjust (In)Mode
+ + + +
+

+ + + + + + + + + + + + + + + + + + +
Replace WordReplace WithStateFlag
+ + + Add + + + Modify + + + Delete + +
+

+ + + + + + + + + + + + + + + + +
Step TypeFont
+

+ + + + + + + + + + + + + + + + + + + + +
Document StyleOriginal Page LengthNew Page LengthOriginal Left MarginNew Left Margin
+
+ + \ No newline at end of file diff --git a/PROMS/Volian.Controls.Library/UCFImpDetails.xsl b/PROMS/Volian.Controls.Library/UCFImpDetails.xsl new file mode 100644 index 00000000..e3568414 --- /dev/null +++ b/PROMS/Volian.Controls.Library/UCFImpDetails.xsl @@ -0,0 +1,189 @@ + + + + + + + + + + +

+ + + + + + + + + +
+ + + + + + + + + + + + + + +
FlagValue
+

+ + + + + + + + + + + + + + + +
Check Off HeadingActive
+ + + +
+

+ + + + + + + + + + + + + + +
Check Off TypeActive
+

+ + + + + + + + + + + +
Check Off X Offset Adjust (Inches)
+ +
+

+ + + + + + + + + + + + + + + + + + +
Replace WordReplace WithStateFlag
+ + + Add + + + Modify + + + Delete + +
+

+ + + + + + + + + + + + + + + + +
Step TypeFont
+

+ + + + + + + + + + + + + + + + +
Document StylePage LengthLeft Margin
+
+ + \ No newline at end of file diff --git a/PROMS/Volian.Controls.Library/dlgUCFImportOptions.Designer.cs b/PROMS/Volian.Controls.Library/dlgUCFImportOptions.Designer.cs new file mode 100644 index 00000000..9a850948 --- /dev/null +++ b/PROMS/Volian.Controls.Library/dlgUCFImportOptions.Designer.cs @@ -0,0 +1,397 @@ +namespace Volian.Controls.Library +{ + partial class dlgUCFImportOptions + { + ///

+ /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.btnOk = new System.Windows.Forms.Button(); + this.btnCancel = new System.Windows.Forms.Button(); + this.pnlOptions = new System.Windows.Forms.Panel(); + this.pnlChoices = new System.Windows.Forms.Panel(); + this.cmbFNames = new DevComponents.DotNetBar.Controls.ComboBoxEx(); + this.grPnlLoad = new DevComponents.DotNetBar.Controls.GroupPanel(); + this.grPnlUse = new DevComponents.DotNetBar.Controls.GroupPanel(); + this.rbOnlyImported = new System.Windows.Forms.RadioButton(); + this.rbAll = new System.Windows.Forms.RadioButton(); + this.rbSetOnly = new System.Windows.Forms.RadioButton(); + this.cbUse = new DevComponents.DotNetBar.Controls.CheckBoxX(); + this.lblLoadFormat = new DevComponents.DotNetBar.LabelX(); + this.sBtnLoad = new DevComponents.DotNetBar.Controls.SwitchButton(); + this.lblFmt = new System.Windows.Forms.Label(); + this.pnlXmlDiff = new System.Windows.Forms.Panel(); + this.wbBrwsExisting = new System.Windows.Forms.WebBrowser(); + this.splitterWebBrowsers = new System.Windows.Forms.Splitter(); + this.pnlWbBrwsImp = new System.Windows.Forms.Panel(); + this.wbBrwsImporting = new System.Windows.Forms.WebBrowser(); + this.superTooltip1 = new DevComponents.DotNetBar.SuperTooltip(); + this.pnlChoices.SuspendLayout(); + this.grPnlLoad.SuspendLayout(); + this.grPnlUse.SuspendLayout(); + this.pnlXmlDiff.SuspendLayout(); + this.pnlWbBrwsImp.SuspendLayout(); + this.SuspendLayout(); + // + // btnOk + // + this.btnOk.DialogResult = System.Windows.Forms.DialogResult.OK; + this.btnOk.Location = new System.Drawing.Point(31, 356); + this.btnOk.Name = "btnOk"; + this.btnOk.Size = new System.Drawing.Size(65, 23); + this.btnOk.TabIndex = 5; + this.btnOk.Text = "OK"; + this.btnOk.UseVisualStyleBackColor = true; + this.btnOk.Click += new System.EventHandler(this.btnOk_Click); + // + // btnCancel + // + this.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel; + this.btnCancel.Location = new System.Drawing.Point(121, 356); + this.btnCancel.Name = "btnCancel"; + this.btnCancel.Size = new System.Drawing.Size(65, 23); + this.btnCancel.TabIndex = 6; + this.btnCancel.Text = "Cancel"; + this.btnCancel.UseVisualStyleBackColor = true; + // + // pnlOptions + // + this.pnlOptions.Location = new System.Drawing.Point(0, 0); + this.pnlOptions.Name = "pnlOptions"; + this.pnlOptions.Size = new System.Drawing.Size(200, 100); + this.pnlOptions.TabIndex = 0; + // + // pnlChoices + // + this.pnlChoices.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left))); + this.pnlChoices.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.pnlChoices.Controls.Add(this.cmbFNames); + this.pnlChoices.Controls.Add(this.grPnlLoad); + this.pnlChoices.Controls.Add(this.lblLoadFormat); + this.pnlChoices.Controls.Add(this.sBtnLoad); + this.pnlChoices.Controls.Add(this.lblFmt); + this.pnlChoices.Controls.Add(this.btnCancel); + this.pnlChoices.Controls.Add(this.btnOk); + this.pnlChoices.Location = new System.Drawing.Point(0, 0); + this.pnlChoices.Name = "pnlChoices"; + this.pnlChoices.Size = new System.Drawing.Size(250, 606); + this.pnlChoices.TabIndex = 7; + // + // cmbFNames + // + this.cmbFNames.DisplayMember = "Text"; + this.cmbFNames.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawFixed; + this.cmbFNames.FormattingEnabled = true; + this.cmbFNames.ItemHeight = 16; + this.cmbFNames.Location = new System.Drawing.Point(26, 48); + this.cmbFNames.Name = "cmbFNames"; + this.cmbFNames.Size = new System.Drawing.Size(191, 22); + this.cmbFNames.Style = DevComponents.DotNetBar.eDotNetBarStyle.StyleManagerControlled; + this.cmbFNames.TabIndex = 15; + this.cmbFNames.SelectedIndexChanged += new System.EventHandler(this.cmbFNames_SelectedIndexChanged); + // + // grPnlLoad + // + this.grPnlLoad.CanvasColor = System.Drawing.SystemColors.Control; + this.grPnlLoad.ColorSchemeStyle = DevComponents.DotNetBar.eDotNetBarStyle.Office2007; + this.grPnlLoad.Controls.Add(this.grPnlUse); + this.grPnlLoad.Controls.Add(this.cbUse); + this.grPnlLoad.DisabledBackColor = System.Drawing.Color.Empty; + this.grPnlLoad.Location = new System.Drawing.Point(11, 130); + this.grPnlLoad.Name = "grPnlLoad"; + this.grPnlLoad.Size = new System.Drawing.Size(224, 184); + // + // + // + this.grPnlLoad.Style.BackColor2SchemePart = DevComponents.DotNetBar.eColorSchemePart.PanelBackground2; + this.grPnlLoad.Style.BackColorGradientAngle = 90; + this.grPnlLoad.Style.BackColorSchemePart = DevComponents.DotNetBar.eColorSchemePart.PanelBackground; + this.grPnlLoad.Style.BorderBottom = DevComponents.DotNetBar.eStyleBorderType.Solid; + this.grPnlLoad.Style.BorderBottomWidth = 1; + this.grPnlLoad.Style.BorderColorSchemePart = DevComponents.DotNetBar.eColorSchemePart.PanelBorder; + this.grPnlLoad.Style.BorderLeft = DevComponents.DotNetBar.eStyleBorderType.Solid; + this.grPnlLoad.Style.BorderLeftWidth = 1; + this.grPnlLoad.Style.BorderRight = DevComponents.DotNetBar.eStyleBorderType.Solid; + this.grPnlLoad.Style.BorderRightWidth = 1; + this.grPnlLoad.Style.BorderTop = DevComponents.DotNetBar.eStyleBorderType.Solid; + this.grPnlLoad.Style.BorderTopWidth = 1; + this.grPnlLoad.Style.CornerDiameter = 4; + this.grPnlLoad.Style.CornerType = DevComponents.DotNetBar.eCornerType.Rounded; + this.grPnlLoad.Style.TextAlignment = DevComponents.DotNetBar.eStyleTextAlignment.Center; + this.grPnlLoad.Style.TextColorSchemePart = DevComponents.DotNetBar.eColorSchemePart.PanelText; + this.grPnlLoad.Style.TextLineAlignment = DevComponents.DotNetBar.eStyleTextAlignment.Near; + // + // + // + this.grPnlLoad.StyleMouseDown.CornerType = DevComponents.DotNetBar.eCornerType.Square; + // + // + // + this.grPnlLoad.StyleMouseOver.CornerType = DevComponents.DotNetBar.eCornerType.Square; + this.grPnlLoad.TabIndex = 14; + this.grPnlLoad.Text = "Load Options"; + // + // grPnlUse + // + this.grPnlUse.BackColor = System.Drawing.Color.Transparent; + this.grPnlUse.CanvasColor = System.Drawing.SystemColors.Control; + this.grPnlUse.ColorSchemeStyle = DevComponents.DotNetBar.eDotNetBarStyle.Office2007; + this.grPnlUse.Controls.Add(this.rbOnlyImported); + this.grPnlUse.Controls.Add(this.rbAll); + this.grPnlUse.Controls.Add(this.rbSetOnly); + this.grPnlUse.DisabledBackColor = System.Drawing.Color.Empty; + this.grPnlUse.Location = new System.Drawing.Point(15, 39); + this.grPnlUse.Name = "grPnlUse"; + this.grPnlUse.Size = new System.Drawing.Size(181, 119); + // + // + // + this.grPnlUse.Style.BackColor2SchemePart = DevComponents.DotNetBar.eColorSchemePart.PanelBackground2; + this.grPnlUse.Style.BackColorGradientAngle = 90; + this.grPnlUse.Style.BackColorSchemePart = DevComponents.DotNetBar.eColorSchemePart.PanelBackground; + this.grPnlUse.Style.BorderBottom = DevComponents.DotNetBar.eStyleBorderType.Solid; + this.grPnlUse.Style.BorderBottomWidth = 1; + this.grPnlUse.Style.BorderColorSchemePart = DevComponents.DotNetBar.eColorSchemePart.PanelBorder; + this.grPnlUse.Style.BorderLeft = DevComponents.DotNetBar.eStyleBorderType.Solid; + this.grPnlUse.Style.BorderLeftWidth = 1; + this.grPnlUse.Style.BorderRight = DevComponents.DotNetBar.eStyleBorderType.Solid; + this.grPnlUse.Style.BorderRightWidth = 1; + this.grPnlUse.Style.BorderTop = DevComponents.DotNetBar.eStyleBorderType.Solid; + this.grPnlUse.Style.BorderTopWidth = 1; + this.grPnlUse.Style.CornerDiameter = 4; + this.grPnlUse.Style.CornerType = DevComponents.DotNetBar.eCornerType.Rounded; + this.grPnlUse.Style.TextAlignment = DevComponents.DotNetBar.eStyleTextAlignment.Center; + this.grPnlUse.Style.TextColorSchemePart = DevComponents.DotNetBar.eColorSchemePart.PanelText; + this.grPnlUse.Style.TextLineAlignment = DevComponents.DotNetBar.eStyleTextAlignment.Near; + // + // + // + this.grPnlUse.StyleMouseDown.CornerType = DevComponents.DotNetBar.eCornerType.Square; + // + // + // + this.grPnlUse.StyleMouseOver.CornerType = DevComponents.DotNetBar.eCornerType.Square; + this.grPnlUse.TabIndex = 1; + this.grPnlUse.Text = "In Procedure(s)"; + // + // rbOnlyImported + // + this.rbOnlyImported.AutoSize = true; + this.rbOnlyImported.BackColor = System.Drawing.Color.Transparent; + this.rbOnlyImported.Location = new System.Drawing.Point(12, 6); + this.rbOnlyImported.Name = "rbOnlyImported"; + this.rbOnlyImported.Size = new System.Drawing.Size(142, 21); + this.superTooltip1.SetSuperTooltip(this.rbOnlyImported, new DevComponents.DotNetBar.SuperTooltipInfo("For Imported Only", "", "The changed UCF will only be used by the procedure(s) that are being imported.", null, null, DevComponents.DotNetBar.eTooltipColor.Gray)); + this.rbOnlyImported.TabIndex = 5; + this.rbOnlyImported.TabStop = true; + this.rbOnlyImported.Text = "For Imported Only"; + this.rbOnlyImported.UseVisualStyleBackColor = false; + // + // rbAll + // + this.rbAll.AutoSize = true; + this.rbAll.BackColor = System.Drawing.Color.Transparent; + this.rbAll.Location = new System.Drawing.Point(12, 33); + this.rbAll.Name = "rbAll"; + this.rbAll.RightToLeft = System.Windows.Forms.RightToLeft.No; + this.rbAll.Size = new System.Drawing.Size(69, 21); + this.superTooltip1.SetSuperTooltip(this.rbAll, new DevComponents.DotNetBar.SuperTooltipInfo("For All ", "", "The changed UCF will be used in all procedure(s) and section(s) within the databa" + + "se that referenced this UCF. The one that existed in the database will be renam" + + "ed to \'Old N of UCFname\'.", null, null, DevComponents.DotNetBar.eTooltipColor.Gray)); + this.rbAll.TabIndex = 6; + this.rbAll.TabStop = true; + this.rbAll.Text = "For All"; + this.rbAll.UseVisualStyleBackColor = false; + // + // rbSetOnly + // + this.rbSetOnly.AutoSize = true; + this.rbSetOnly.BackColor = System.Drawing.Color.Transparent; + this.rbSetOnly.Location = new System.Drawing.Point(12, 60); + this.rbSetOnly.Name = "rbSetOnly"; + this.rbSetOnly.RightToLeft = System.Windows.Forms.RightToLeft.No; + this.rbSetOnly.Size = new System.Drawing.Size(108, 21); + this.superTooltip1.SetSuperTooltip(this.rbSetOnly, new DevComponents.DotNetBar.SuperTooltipInfo("For Set Only", "", "The changed UCF will only be used by the procedure(s)/sections(s) within the proc" + + "edure set that this procedure belongs.", null, null, DevComponents.DotNetBar.eTooltipColor.Gray)); + this.rbSetOnly.TabIndex = 7; + this.rbSetOnly.TabStop = true; + this.rbSetOnly.Text = "For Set Only"; + this.rbSetOnly.UseVisualStyleBackColor = false; + // + // cbUse + // + this.cbUse.BackColor = System.Drawing.Color.Transparent; + // + // + // + this.cbUse.BackgroundStyle.CornerType = DevComponents.DotNetBar.eCornerType.Square; + this.cbUse.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.cbUse.Location = new System.Drawing.Point(17, 5); + this.cbUse.Name = "cbUse"; + this.cbUse.Size = new System.Drawing.Size(125, 28); + this.cbUse.Style = DevComponents.DotNetBar.eDotNetBarStyle.StyleManagerControlled; + this.superTooltip1.SetSuperTooltip(this.cbUse, new DevComponents.DotNetBar.SuperTooltipInfo("Use", "", "If checked, the changes will be used as defined In Procedure(s) below. Otherwise," + + " the format is loaded but not used. ", null, null, DevComponents.DotNetBar.eTooltipColor.Gray)); + this.cbUse.TabIndex = 0; + this.cbUse.Text = "Use"; + this.cbUse.CheckedChanged += new System.EventHandler(this.cbUse_CheckedChanged); + // + // lblLoadFormat + // + // + // + // + this.lblLoadFormat.BackgroundStyle.CornerType = DevComponents.DotNetBar.eCornerType.Square; + this.lblLoadFormat.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.lblLoadFormat.Location = new System.Drawing.Point(124, 89); + this.lblLoadFormat.Name = "lblLoadFormat"; + this.lblLoadFormat.Size = new System.Drawing.Size(94, 24); + this.superTooltip1.SetSuperTooltip(this.lblLoadFormat, new DevComponents.DotNetBar.SuperTooltipInfo("Load Format", "", "The User Control of Format changes will be loaded (imported) into the database. O" + + "therwise it will be ignored and the existing User Control of Format will be used" + + ".", null, null, DevComponents.DotNetBar.eTooltipColor.Gray)); + this.lblLoadFormat.TabIndex = 13; + this.lblLoadFormat.Text = "Load Format"; + // + // sBtnLoad + // + this.sBtnLoad.BackgroundStyle.CornerType = DevComponents.DotNetBar.eCornerType.Square; + this.sBtnLoad.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.sBtnLoad.Location = new System.Drawing.Point(13, 88); + this.sBtnLoad.Name = "sBtnLoad"; + this.sBtnLoad.Size = new System.Drawing.Size(102, 26); + this.sBtnLoad.Style = DevComponents.DotNetBar.eDotNetBarStyle.StyleManagerControlled; + this.sBtnLoad.TabIndex = 12; + this.sBtnLoad.ValueChanged += new System.EventHandler(this.sBtnLoad_ValueChanged); + // + // lblFmt + // + this.lblFmt.AutoSize = true; + this.lblFmt.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.lblFmt.Location = new System.Drawing.Point(16, 19); + this.lblFmt.Name = "lblFmt"; + this.lblFmt.Size = new System.Drawing.Size(140, 18); + this.lblFmt.TabIndex = 8; + this.lblFmt.Text = "Changes to Format:"; + // + // pnlXmlDiff + // + this.pnlXmlDiff.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.pnlXmlDiff.Controls.Add(this.wbBrwsExisting); + this.pnlXmlDiff.Controls.Add(this.splitterWebBrowsers); + this.pnlXmlDiff.Controls.Add(this.pnlWbBrwsImp); + this.pnlXmlDiff.Location = new System.Drawing.Point(255, 0); + this.pnlXmlDiff.Name = "pnlXmlDiff"; + this.pnlXmlDiff.Size = new System.Drawing.Size(548, 601); + this.pnlXmlDiff.TabIndex = 8; + // + // wbBrwsExisting + // + this.wbBrwsExisting.Dock = System.Windows.Forms.DockStyle.Fill; + this.wbBrwsExisting.Location = new System.Drawing.Point(0, 0); + this.wbBrwsExisting.MinimumSize = new System.Drawing.Size(20, 20); + this.wbBrwsExisting.Name = "wbBrwsExisting"; + this.wbBrwsExisting.Size = new System.Drawing.Size(548, 298); + this.wbBrwsExisting.TabIndex = 0; + // + // splitterWebBrowsers + // + this.splitterWebBrowsers.Dock = System.Windows.Forms.DockStyle.Bottom; + this.splitterWebBrowsers.Location = new System.Drawing.Point(0, 298); + this.splitterWebBrowsers.Name = "splitterWebBrowsers"; + this.splitterWebBrowsers.Size = new System.Drawing.Size(548, 3); + this.splitterWebBrowsers.TabIndex = 2; + this.splitterWebBrowsers.TabStop = false; + // + // pnlWbBrwsImp + // + this.pnlWbBrwsImp.Controls.Add(this.wbBrwsImporting); + this.pnlWbBrwsImp.Dock = System.Windows.Forms.DockStyle.Bottom; + this.pnlWbBrwsImp.Location = new System.Drawing.Point(0, 301); + this.pnlWbBrwsImp.Name = "panel1"; + this.pnlWbBrwsImp.Size = new System.Drawing.Size(548, 300); + this.pnlWbBrwsImp.TabIndex = 3; + // + // wbBrwsImporting + // + this.wbBrwsImporting.Dock = System.Windows.Forms.DockStyle.Fill; + this.wbBrwsImporting.Location = new System.Drawing.Point(0, 0); + this.wbBrwsImporting.MinimumSize = new System.Drawing.Size(20, 20); + this.wbBrwsImporting.Name = "wbBrwsImporting"; + this.wbBrwsImporting.Size = new System.Drawing.Size(548, 300); + this.wbBrwsImporting.TabIndex = 0; + // + // superTooltip1 + // + this.superTooltip1.DefaultTooltipSettings = new DevComponents.DotNetBar.SuperTooltipInfo("", "", "", null, null, DevComponents.DotNetBar.eTooltipColor.Gray); + this.superTooltip1.LicenseKey = "F962CEC7-CD8F-4911-A9E9-CAB39962FC1F"; + // + // dlgUCFImportOptions + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(803, 606); + this.Controls.Add(this.pnlXmlDiff); + this.Controls.Add(this.pnlChoices); + this.Name = "dlgUCFImportOptions"; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; + this.Text = "User Control Of Format - Import Options"; + this.pnlChoices.ResumeLayout(false); + this.pnlChoices.PerformLayout(); + this.grPnlLoad.ResumeLayout(false); + this.grPnlUse.ResumeLayout(false); + this.grPnlUse.PerformLayout(); + this.pnlXmlDiff.ResumeLayout(false); + this.pnlWbBrwsImp.ResumeLayout(false); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.Button btnOk; + private System.Windows.Forms.Button btnCancel; + private System.Windows.Forms.Panel pnlOptions; + private System.Windows.Forms.Panel pnlXmlDiff; + private System.Windows.Forms.WebBrowser wbBrwsExisting; + private System.Windows.Forms.Panel pnlChoices; + private System.Windows.Forms.Label lblFmt; + private DevComponents.DotNetBar.LabelX lblLoadFormat; + private DevComponents.DotNetBar.Controls.SwitchButton sBtnLoad; + private DevComponents.DotNetBar.Controls.GroupPanel grPnlLoad; + private DevComponents.DotNetBar.Controls.GroupPanel grPnlUse; + private DevComponents.DotNetBar.Controls.CheckBoxX cbUse; + private System.Windows.Forms.RadioButton rbOnlyImported; + private System.Windows.Forms.RadioButton rbAll; + private System.Windows.Forms.RadioButton rbSetOnly; + private DevComponents.DotNetBar.SuperTooltip superTooltip1; + private DevComponents.DotNetBar.Controls.ComboBoxEx cmbFNames; + private System.Windows.Forms.Splitter splitterWebBrowsers; + private System.Windows.Forms.Panel pnlWbBrwsImp; + private System.Windows.Forms.WebBrowser wbBrwsImporting; + } +} \ No newline at end of file diff --git a/PROMS/Volian.Controls.Library/dlgUCFImportOptions.cs b/PROMS/Volian.Controls.Library/dlgUCFImportOptions.cs new file mode 100644 index 00000000..65bf47bc --- /dev/null +++ b/PROMS/Volian.Controls.Library/dlgUCFImportOptions.cs @@ -0,0 +1,184 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Windows.Forms; +using System.Xml; +using System.Xml.Linq; +using System.Xml.Xsl; +using System.IO; +using Microsoft.XmlDiffPatch; +using VEPROMS.CSLA.Library; + +namespace Volian.Controls.Library +{ + // This dialog is used when the imported UCF is different than one existing in the database. It allows the user to + // select whether to overwrite, copy, etc. See the user interface project/dlgExportImport.cs for the options. + public partial class dlgUCFImportOptions : Form + { + ListExistingFC; + ListImportedFC; + private bool _Initializing = false; + public E_UCFImportOptions UCFImportOptionsCase = E_UCFImportOptions.LoadOnlyImported; + public dlgUCFImportOptions(List name, List existingFC, List importedFC, E_UCFImportOptions defImpOpt, string xmlpath) + { + _Initializing = true; + InitializeComponent(); + InitializeFNamesCombo(name); + ExistingFC = existingFC; + ImportedFC = importedFC; + cmbFNames.SelectedIndex = 0; // this displays the web browser differences for first name in the combo box. + + // initialize the import of UCF option radio buttons: + UCFImportOptionsCase = defImpOpt; + rbSetOnly.Visible = !xmlpath.ToLower().Contains("folder"); + if (defImpOpt == E_UCFImportOptions.Ignore) + { + sBtnLoad.Value = false; + grPnlLoad.Enabled = false; + grPnlUse.Enabled = false; + } + else if (defImpOpt == E_UCFImportOptions.LoadNotUsed) + { + sBtnLoad.Value = true; + grPnlLoad.Enabled = true; + cbUse.Checked = false; + grPnlUse.Enabled = false; + } + else if (defImpOpt == E_UCFImportOptions.LoadOnlyImported) + { + sBtnLoad.Value = true; + grPnlLoad.Enabled = true; + cbUse.Checked = true; + grPnlUse.Enabled = true; + rbOnlyImported.Checked = true; + } + else if (defImpOpt == E_UCFImportOptions.LoadUseAll) + { + sBtnLoad.Value = true; + grPnlLoad.Enabled = true; + cbUse.Checked = true; + grPnlUse.Enabled = true; + rbAll.Checked = true; + } + else if (defImpOpt == E_UCFImportOptions.LoadForSetOnly) + { + sBtnLoad.Value = true; + grPnlLoad.Enabled = true; + cbUse.Checked = true; + grPnlUse.Enabled = true; + rbSetOnly.Checked = true; + } + _Initializing = false; + return; + } + + private void InitializeFNamesCombo(List name) + { + foreach (string str in name) + cmbFNames.Items.Add(str); + } + + private void DisplayXmlDiff(string existingFC, string importedFC) + { + XmlDocument xd = new XmlDocument(); + xd.LoadXml(existingFC); + XmlNodeList xnl = xd.GetElementsByTagName("FormatConfig"); + if (xnl != null && xnl.Count > 0) AddAttribute(xnl[0], "Version", "Existing"); + string sXSLSummary = System.IO.File.ReadAllText(Application.StartupPath + "\\" + "UCFImpDetails.xsl"); + StringWriter sw = new StringWriter(); + StringWriter xsw = new StringWriter(); + using (XmlReader xrt = XmlReader.Create(new StringReader(sXSLSummary))) + { + XmlTextWriter tx = new XmlTextWriter(xsw); + xd.WriteTo(tx); + string tmp = sw.ToString(); + tmp = xd.InnerXml; + using (XmlReader xri = XmlReader.Create(new StringReader(tmp))) + { + using (XmlWriter xwo = XmlWriter.Create(sw)) + { + XslCompiledTransform xsl = new XslCompiledTransform(); + xsl.Load(xrt); + xsl.Transform(xri, xwo); // Perform Transform + } + wbBrwsExisting.DocumentText = sw.ToString(); + } + } + StringWriter sw1 = new StringWriter(); + StringWriter xsw1 = new StringWriter(); + XmlDocument xd1 = new XmlDocument(); + xd1.LoadXml(importedFC); + xnl = xd1.GetElementsByTagName("FormatConfig"); + if (xnl != null && xnl.Count > 0) AddAttribute(xnl[0], "Version", "Importing"); + using (XmlReader xrt = XmlReader.Create(new StringReader(sXSLSummary))) + { + XmlTextWriter tx = new XmlTextWriter(xsw1); + xd1.WriteTo(tx); + string tmp = xd1.InnerXml; + using (XmlReader xri = XmlReader.Create(new StringReader(tmp))) + { + using (XmlWriter xwo = XmlWriter.Create(sw1)) + { + XslCompiledTransform xsl = new XslCompiledTransform(); + xsl.Load(xrt); + xsl.Transform(xri, xwo); // Perform Transform + } + wbBrwsImporting.DocumentText = sw1.ToString(); + } + } + } + + private void AddAttribute(XmlNode xn, string name, string value) + { + XmlAttribute xa = xn.OwnerDocument.CreateAttribute(name); + xa.Value = value.ToString(); + xn.Attributes.Append(xa); + } + private void btnOk_Click(object sender, EventArgs e) + { + if (!sBtnLoad.Value) UCFImportOptionsCase = E_UCFImportOptions.Ignore; + else if (!cbUse.Checked) UCFImportOptionsCase = E_UCFImportOptions.LoadNotUsed; + else if (rbOnlyImported.Checked) UCFImportOptionsCase = E_UCFImportOptions.LoadOnlyImported; + else if (rbAll.Checked) UCFImportOptionsCase = E_UCFImportOptions.LoadUseAll; + else if (rbSetOnly.Checked) UCFImportOptionsCase = E_UCFImportOptions.LoadForSetOnly; + this.Close(); + } + + private void sBtnLoad_ValueChanged(object sender, EventArgs e) // Import options for UCF Change: Load switch button + { + if (_Initializing) return; + if (sBtnLoad.Value) + { + grPnlLoad.Enabled = true; // Import the ucf change. let user select whether to use it. + grPnlUse.Enabled = false; + cbUse.Checked = false; + } + else + { + grPnlLoad.Enabled = false; // Don't import the ucf change. + grPnlUse.Enabled = false; + } + } + + private void cbUse_CheckedChanged(object sender, EventArgs e) // Import options for UCF Change: use checkbox + { + if (_Initializing) return; + if (cbUse.Checked) + grPnlUse.Enabled = true; // Use the change. enable the load group & select for imported only + else + grPnlUse.Enabled = false; // Don't use the change. + } + + private void cmbFNames_SelectedIndexChanged(object sender, EventArgs e) + { + int indx = cmbFNames.SelectedIndex; + string existingFC = ExistingFC[indx]; + string importedFC = ImportedFC[indx]; + DisplayXmlDiff(existingFC, importedFC); + } + } +} diff --git a/PROMS/Volian.Controls.Library/dlgUCFImportOptions.resx b/PROMS/Volian.Controls.Library/dlgUCFImportOptions.resx new file mode 100644 index 00000000..2e5faf21 --- /dev/null +++ b/PROMS/Volian.Controls.Library/dlgUCFImportOptions.resx @@ -0,0 +1,126 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + + + True + + \ No newline at end of file diff --git a/PROMS/Volian.Print.Library/VlnSvgPageHelper.cs b/PROMS/Volian.Print.Library/VlnSvgPageHelper.cs index d6206065..06956b84 100644 --- a/PROMS/Volian.Print.Library/VlnSvgPageHelper.cs +++ b/PROMS/Volian.Print.Library/VlnSvgPageHelper.cs @@ -1027,7 +1027,8 @@ i = 0; //} VEPROMS.CSLA.Library.FormatInfo activeFormat = mySection.ActiveFormat; VEPROMS.CSLA.Library.DocStyle docStyle = mySection.MyDocStyle; - Volian.Svg.Library.Svg mySvg = null; + Volian.Svg.Library.Svg mySvg = null; + // the following line fills in the svg/svggroup/svgparts for all that is defined in the genmac definition (svg for plant) mySvg = SvgSerializer.StringDeserialize(BuildMyText(activeFormat)); mySvg.ViewBox.Height = 1100; mySvg.ViewBox.Width = 850; @@ -1209,6 +1210,31 @@ i = 0; private string BuildMyText(VEPROMS.CSLA.Library.FormatInfo activeFormat) { string sGenMac = activeFormat.GenMac; + FormatInfo fibase = activeFormat; + // If this format has checkoffs (go through docstyles to see if any sections 'usecheckoffs'), then see if the ucf checkoffs are + // defined in the format's genmac: + string sGenMacBase = null; + foreach (DocStyle ds in activeFormat.PlantFormat.DocStyles.DocStyleList) + { + if (ds.Inactive == false && ds.UseCheckOffs && !sGenMac.ToUpper().Contains("C100")) + { + while (fibase.FormatID != fibase.ParentID) fibase = fibase.MyParent; + sGenMacBase = fibase.GenMac; + if (sGenMacBase != null && sGenMacBase != "") + { + XmlDocument xDocGenMacBase = new XmlDocument(); + xDocGenMacBase.LoadXml(sGenMacBase); + sGenMacBase = xDocGenMacBase.DocumentElement.InnerXml; + sGenMacBase = sGenMacBase.Replace("xmlns=\"http://www.w3.org/2000/svg\"", ""); + // replace fonts with hls fontname & size + string bsfontfamily = activeFormat.PlantFormat.FormatData.StepDataList[0].Font.Family; + string bsfontsize = activeFormat.PlantFormat.FormatData.StepDataList[0].Font.Size.ToString(); + sGenMacBase = sGenMacBase.Replace("{family}", bsfontfamily); + sGenMacBase = sGenMacBase.Replace("{size}", bsfontsize); + break; + } + } + } if (sGenMac == null || sGenMac == "") { // If subformat and does not have its own genmac, find an inherited genmac. @@ -1219,7 +1245,11 @@ i = 0; tmpf = FormatInfo.Get(tmpf.ParentID); } if (sGenMac == null || sGenMac == "") - sGenMac = "";// return ""; + sGenMac = ""; + } + if (sGenMacBase != null && sGenMacBase != "") + { + sGenMac = sGenMac.Replace("", sGenMacBase + ""); } if (!sGenMac.Contains("xmlns")) sGenMac = sGenMac.Replace(" 0 ? Width : 0) + relX; } } + // if there is ucf value for adjusting the alignment for checkoffs, use it: + FormatConfig fc = PlantFormat.GetFormatConfig(formatInfo); + if (fc != null && fc.PlantFormat.FormatData.CheckOffXOffAdj != null) + { + if (co.Index > 99) xloc_co += ((float)fc.PlantFormat.FormatData.CheckOffXOffAdj * 72); + } + // CheckOffXtraLines was introduced for the additional lines needed for the longer signoffs // for VCBA (&WST1), for F2016-061. float checkOffNumberOfLines = (co.CheckOffNumberOfLines ?? 0); @@ -4823,7 +4830,8 @@ namespace Volian.Print.Library // First see if there is any checkoff data in the format file and that there // is a pagelist item for the checkoff header. - if (itemInfo.ActiveFormat.PlantFormat.FormatData.ProcData.CheckOffData.CheckOffList.MaxIndex <= 0) return; + int maxindx = itemInfo.ActiveFormat.PlantFormat.FormatData.ProcData.CheckOffUCF ? itemInfo.ActiveFormat.PlantFormat.FormatData.ProcData.CheckOffData.CheckOffList.MaxIndex : itemInfo.ActiveFormat.PlantFormat.FormatData.ProcData.CheckOffData.CheckOffList.MaxIndexNoInherit; + if (maxindx <= 0) return; if (MyPageHelper.PageListCheckOffHeader == null) return; VE_Font font = null;