/// <summary>
///
/// </summary>
/// <param name="dtFormatedData"></param>
/// <param name="ReplaceColumn"></param>
/// <returns></returns>
private DataTable ReplaceCloumnString(DataTable dtFormatedData, List< string > ReplaceColumn)
{
Dictionary< string , string > newfirstReplaces = new Dictionary< string , string >();
newfirstReplaces = needfirstReplaces;
foreach (KeyValuePair< string , string > newitem in firstReplaces)
{
if (!newfirstReplaces.ContainsKey(newitem.Key))
{
newfirstReplaces.Add(newitem.Key, newitem.Value);
}
}
DataTable dtFormatedDataCopy = dtFormatedData.Clone();
foreach (DataRow dr in dtFormatedData.Rows)
{
foreach (KeyValuePair< string , string > item in newfirstReplaces)
{
foreach ( string needColumn in ReplaceColumn)
{
if (dr[needColumn].ToString().Contains(item.Key))
{
string ContentStr = dr[needColumn].ToString();
dr[needColumn] = ReplaceStr(ContentStr, item.Key, item.Value);
}
}
}
DataRow drNewRow = dtFormatedDataCopy.NewRow();
drNewRow.ItemArray = dr.ItemArray;
dtFormatedDataCopy.Rows.Add(drNewRow);
}
return dtFormatedDataCopy;
}
///修改为
/// <summary>
///
/// </summary>
/// <param name="dtFormatedData"></param>
/// <param name="ReplaceColumn"></param>
/// <returns></returns>
private DataTable ReplaceCloumnString(DataTable dtFormatedData, List< string > ReplaceColumn)
{
Dictionary< string , string > newfirstReplaces = GetReplaceDictionary();
DataTable dtFormatedDataCopy = dtFormatedData.Clone();
foreach (DataRow dr in dtFormatedData.Rows)
{
foreach (KeyValuePair< string , string > item in newfirstReplaces)
{
foreach ( string needColumn in ReplaceColumn)
{
if (dr[needColumn].ToString().Contains(item.Key))
{
string ContentStr = dr[needColumn].ToString();
dr[needColumn] = ReplaceStr(ContentStr, item.Key, item.Value);
}
}
}
DataRow drNewRow = dtFormatedDataCopy.NewRow();
drNewRow.ItemArray = dr.ItemArray;
dtFormatedDataCopy.Rows.Add(drNewRow);
}
return dtFormatedDataCopy;
}
private Dictionary< string , string > GetReplaceDictionary()
{
Dictionary< string , string > newfirstReplaces = new Dictionary< string , string >();
newfirstReplaces = needfirstReplaces;
foreach (KeyValuePair< string , string > newitem in firstReplaces)
{
if (!newfirstReplaces.ContainsKey(newitem.Key))
{
newfirstReplaces.Add(newitem.Key, newitem.Value);
}
}
return newfirstReplaces;
}
|