This commit is contained in:
2009-01-27 15:36:38 +00:00
parent 20783cc178
commit 4dbbcf0478
7 changed files with 872 additions and 319 deletions

View File

@@ -9,6 +9,7 @@ using System.Data;
using System.Data.SqlClient;
using System.Xml;
using System.Drawing;
using System.Text.RegularExpressions;
namespace VEPROMS.CSLA.Library
{
@@ -800,6 +801,88 @@ namespace VEPROMS.CSLA.Library
{
return (str == null ? def : str);
}
internal string _SearchDVPath;
public string SearchDVPath
{
get { return _SearchDVPath; }
}
internal string _SearchPath;
public string SearchPath
{
get { return _SearchPath; }
}
internal int _SearchAnnotationID;
public int SearchAnnotationID
{
get { return _SearchAnnotationID; }
}
internal string _SearchAnnotationText;
public string SearchAnnotationText
{
get { return _SearchAnnotationText; }
}
internal string _SearchAnnotationType;
public string SearchAnnotationType
{
get { return _SearchAnnotationType; }
}
public string DisplayText
{
get { return ConvertToDisplayText(MyContent.Text); }
}
private string ConvertToDisplayText(string txt)
{
string retval = txt;
retval = StripRtfFormatting(retval);
retval = StripLinks(retval);
retval = ReplaceSpecialCharacters(retval);
return retval;
}
private static string StripRtfFormatting(string rtf)
{
string retval = rtf;
retval = Regex.Replace(retval, @"\\b0 ?", "");
retval = Regex.Replace(retval, @"\\b ?", "");
retval = Regex.Replace(retval, @"\\ul0 ?", "");
retval = Regex.Replace(retval, @"\\ul ?", "");
retval = Regex.Replace(retval, @"\\i0 ?", "");
retval = Regex.Replace(retval, @"\\i ?", "");
retval = Regex.Replace(retval, @"\\super ?", "");
retval = Regex.Replace(retval, @"\\sub ?", "");
retval = Regex.Replace(retval, @"\\nosupersub ?", "");
return retval;
}
private static string StripLinks(string rtf)
{
string retval = rtf;
retval = Regex.Replace(retval, @"\\v.*?\\v0", "");
retval = retval.Replace("\u252C", "");// Unicode 9516 Transition
retval = retval.Replace("\u2566", "");// Unicode 9574 Transition
retval = retval.Replace("\u0015", "");// Unicode 21 RO
return retval;
}
private static string ReplaceSpecialCharacter(Match m)
{
StringBuilder sb = new StringBuilder();
int i = int.Parse(m.ToString().Substring(2,m.ToString().Length-3));
sb.Append((char)i);
return sb.ToString();
}
private static string ReplaceSpecialHexCharacter(Match m)
{
StringBuilder sb = new StringBuilder();
int i = int.Parse(m.ToString().Substring(2), System.Globalization.NumberStyles.HexNumber);
sb.Append((char)i);
return sb.ToString();
}
private static string ReplaceSpecialCharacters(string rtf)
{
string retval = rtf;
retval = retval.Replace("`", "\u00BA");// Degree
retval = Regex.Replace(retval, @"\\u[0-9]+[?]", new MatchEvaluator(ReplaceSpecialCharacter));
retval = Regex.Replace(retval, @"\\'[0-9A-Fa-f][0-9A-Fa-f]", new MatchEvaluator(ReplaceSpecialHexCharacter));
return retval;
}
public string Path
{
get
@@ -1140,7 +1223,7 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("ItemInfo.Constructor", ex);
}
}
private void AddContent(SafeDataReader dr)
internal void AddContent(SafeDataReader dr)
{
_MyContent = new ContentInfo(dr, true);
}
@@ -1252,6 +1335,340 @@ namespace VEPROMS.CSLA.Library
this.Add(itemInfo);
IsReadOnly = true;
}
#region Text Search
public static ItemInfoList GetListFromTextSearch(string docVersionList, string stepTypeList, string searchString, bool caseSensitive, ItemSearchIncludeLinks includeLinks, bool includeRtfFormatting, bool includeSpecialCharacters)
{
try
{
ItemInfoList tmp = DataPortal.Fetch<ItemInfoList>(new ItemListSearchCriteria(docVersionList, stepTypeList, searchString, caseSensitive, includeLinks, includeRtfFormatting, includeSpecialCharacters));
ItemInfo.AddList(tmp);
tmp.AddEvents();
return tmp;
}
catch (Exception ex)
{
throw new DbCslaException("Error on ItemInfoList.GetChildren", ex);
}
}
[Serializable()]
private class ItemListSearchCriteria
{
private string _DocVersionList;
public string DocVersionList
{
get { return _DocVersionList; }
set { _DocVersionList = value; }
}
private string _StepTypeList;
public string StepTypeList
{
get { return _StepTypeList; }
set { _StepTypeList = value; }
}
private string _SearchString;
public string SearchString
{
get { return _SearchString; }
set { _SearchString = value; }
}
private bool _CaseSensitive;
public bool CaseSensitive
{
get { return _CaseSensitive; }
set { _CaseSensitive = value; }
}
private ItemSearchIncludeLinks _IncludeLinks;
public ItemSearchIncludeLinks IncludeLinks
{
get { return _IncludeLinks; }
set { _IncludeLinks = value; }
}
private bool _IncludeRtfFormatting;
public bool IncludeRtfFormatting
{
get { return _IncludeRtfFormatting; }
set { _IncludeRtfFormatting = value; }
}
private bool _IncludeSpecialCharacters;
public bool IncludeSpecialCharacters
{
get { return _IncludeSpecialCharacters; }
set { _IncludeSpecialCharacters = value; }
}
public ItemListSearchCriteria(string docVersionList, string stepTypeList, string searchString,
bool caseSensitive, ItemSearchIncludeLinks includeLinks, bool includeRtfFormatting, bool includeSpecialCharacters)
{
_DocVersionList = docVersionList;
_StepTypeList = stepTypeList;
_SearchString = searchString;
_CaseSensitive = caseSensitive;
_IncludeLinks = includeLinks;
_IncludeRtfFormatting = includeRtfFormatting;
_IncludeSpecialCharacters = includeSpecialCharacters;
}
}
private void DataPortal_Fetch(ItemListSearchCriteria criteria)
{
this.RaiseListChangedEvents = false;
try
{
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
using (SqlCommand cm = cn.CreateCommand())
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandText = "vesp_SearchItemAndChildren";
cm.Parameters.AddWithValue("@DocVersionList", criteria.DocVersionList);
cm.Parameters.AddWithValue("@StepTypeList", criteria.StepTypeList);
cm.Parameters.AddWithValue("@SearchString", criteria.SearchString);
cm.Parameters.AddWithValue("@CaseSensitive", criteria.CaseSensitive ? 1 : 0);
cm.Parameters.AddWithValue("@IncludeLinks", (int) criteria.IncludeLinks);
cm.Parameters.AddWithValue("@IncludeRtfFormatting", criteria.IncludeRtfFormatting ? 1 : 0);
cm.Parameters.AddWithValue("@IncludeSpecialCharacters", criteria.IncludeSpecialCharacters ? 1 : 0);
using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader()))
{
while (dr.Read())
{
ItemInfo itemInfo = null;
int itemType = dr.GetInt32("Type") / 10000;
switch (itemType)
{
case 0:
itemInfo = new ProcedureInfo(dr);
break;
case 1:
itemInfo = new SectionInfo(dr);
break;
default:
itemInfo = new StepInfo(dr);
break;
}
itemInfo.AddContent(dr);
itemInfo._SearchDVPath = dr.GetString("DVPath");
itemInfo._SearchPath = dr.GetString("Path");
IsReadOnly = false;
this.Add(itemInfo);
IsReadOnly = true;
}
}
}
}
}
catch (Exception ex)
{
Database.LogException("ItemInfoList.DataPortal_Fetch", ex);
throw new DbCslaException("ItemInfoList.DataPortal_Fetch", ex);
}
this.RaiseListChangedEvents = true;
}
#endregion
#region RO Search
public static ItemInfoList GetListFromROSearch(string docVersionList, string stepTypeList, string roSearchString)
{
try
{
ItemInfoList tmp = DataPortal.Fetch<ItemInfoList>(new ItemListROSearchCriteria(docVersionList, stepTypeList, roSearchString));
ItemInfo.AddList(tmp);
tmp.AddEvents();
return tmp;
}
catch (Exception ex)
{
throw new DbCslaException("Error on ItemInfoList.GetChildren", ex);
}
}
[Serializable()]
private class ItemListROSearchCriteria
{
private string _DocVersionList;
public string DocVersionList
{
get { return _DocVersionList; }
set { _DocVersionList = value; }
}
private string _StepTypeList;
public string StepTypeList
{
get { return _StepTypeList; }
set { _StepTypeList = value; }
}
private string _ROSearchString;
public string ROSearchString
{
get { return _ROSearchString; }
set { _ROSearchString = value; }
}
public ItemListROSearchCriteria(string docVersionList, string stepTypeList, string roSearchString)
{
_DocVersionList = docVersionList;
_StepTypeList = stepTypeList;
_ROSearchString = roSearchString;
}
}
private void DataPortal_Fetch(ItemListROSearchCriteria criteria)
{
this.RaiseListChangedEvents = false;
try
{
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
using (SqlCommand cm = cn.CreateCommand())
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandText = "vesp_SearchROItemAndChildren";
cm.Parameters.AddWithValue("@DocVersionList", criteria.DocVersionList);
cm.Parameters.AddWithValue("@StepTypeList", criteria.StepTypeList);
cm.Parameters.AddWithValue("@ROSearchString", criteria.ROSearchString);
using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader()))
{
while (dr.Read())
{
ItemInfo itemInfo = null;
int itemType = dr.GetInt32("Type") / 10000;
switch (itemType)
{
case 0:
itemInfo = new ProcedureInfo(dr);
break;
case 1:
itemInfo = new SectionInfo(dr);
break;
default:
itemInfo = new StepInfo(dr);
break;
}
itemInfo.AddContent(dr);
itemInfo._SearchDVPath = dr.GetString("DVPath");
itemInfo._SearchPath = dr.GetString("Path");
IsReadOnly = false;
this.Add(itemInfo);
IsReadOnly = true;
}
}
}
}
}
catch (Exception ex)
{
Database.LogException("ItemInfoList.DataPortal_Fetch", ex);
throw new DbCslaException("ItemInfoList.DataPortal_Fetch", ex);
}
this.RaiseListChangedEvents = true;
}
#endregion
#region Annotation Search
public static ItemInfoList GetListFromAnnotationSearch(string docVersionList, string stepTypeList, string annotationTypeList, string searchString, bool caseSensitive)
{
try
{
ItemInfoList tmp = DataPortal.Fetch<ItemInfoList>(new ItemListAnnotationSearchCriteria(docVersionList, stepTypeList, annotationTypeList, searchString, caseSensitive));
ItemInfo.AddList(tmp);
tmp.AddEvents();
return tmp;
}
catch (Exception ex)
{
throw new DbCslaException("Error on ItemInfoList.GetChildren", ex);
}
}
[Serializable()]
private class ItemListAnnotationSearchCriteria
{
private string _DocVersionList;
public string DocVersionList
{
get { return _DocVersionList; }
set { _DocVersionList = value; }
}
private string _StepTypeList;
public string StepTypeList
{
get { return _StepTypeList; }
set { _StepTypeList = value; }
}
private string _AnnotationTypeList;
public string AnnotationTypeList
{
get { return _AnnotationTypeList; }
set { _AnnotationTypeList = value; }
}
private string _SearchString;
public string SearchString
{
get { return _SearchString; }
set { _SearchString = value; }
}
private bool _CaseSensitive;
public bool CaseSensitive
{
get { return _CaseSensitive; }
set { _CaseSensitive = value; }
}
public ItemListAnnotationSearchCriteria(string docVersionList, string stepTypeList, string annotationTypeList, string searchString, bool caseSensitive)
{
_DocVersionList = docVersionList;
_StepTypeList = stepTypeList;
_AnnotationTypeList = annotationTypeList;
_SearchString = searchString;
_CaseSensitive = caseSensitive;
}
}
private void DataPortal_Fetch(ItemListAnnotationSearchCriteria criteria)
{
this.RaiseListChangedEvents = false;
try
{
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
using (SqlCommand cm = cn.CreateCommand())
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandText = "vesp_SearchAnnotationItemAndChildren";
cm.Parameters.AddWithValue("@DocVersionList", criteria.DocVersionList);
cm.Parameters.AddWithValue("@StepTypeList", criteria.StepTypeList);
cm.Parameters.AddWithValue("@AnnotationTypeList", criteria.StepTypeList);
cm.Parameters.AddWithValue("@SearchString", criteria.SearchString);
cm.Parameters.AddWithValue("@CaseSensitive", criteria.CaseSensitive ? 1 : 0);
using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader()))
{
while (dr.Read())
{
ItemInfo itemInfo = null;
int itemType = dr.GetInt32("Type") / 10000;
switch (itemType)
{
case 0:
itemInfo = new ProcedureInfo(dr);
break;
case 1:
itemInfo = new SectionInfo(dr);
break;
default:
itemInfo = new StepInfo(dr);
break;
}
itemInfo.AddContent(dr);
itemInfo._SearchDVPath = dr.GetString("DVPath");
itemInfo._SearchPath = dr.GetString("Path");
itemInfo._SearchAnnotationID = dr.GetInt32("SearchAnnotationID");
itemInfo._SearchAnnotationText = dr.GetString("SearchText");
itemInfo._SearchAnnotationType = dr.GetString("AnnotationType");
IsReadOnly = false;
this.Add(itemInfo);
IsReadOnly = true;
}
}
}
}
}
catch (Exception ex)
{
Database.LogException("ItemInfoList.DataPortal_Fetch", ex);
throw new DbCslaException("ItemInfoList.DataPortal_Fetch", ex);
}
this.RaiseListChangedEvents = true;
}
#endregion
}
#endregion
#region ProcedureInfo
@@ -1596,4 +2013,10 @@ namespace VEPROMS.CSLA.Library
//#endregion
}
#endregion
public enum ItemSearchIncludeLinks
{
Nothing = 0,
Value = 1,
Everything =2
}
}