using System;namespace dyemp.Components
{
public class CAccount
{
public event StringToDecimal AccountString; public decimal ReMoveBracket(string strFormulary)
{
string strValue = strFormulary; int iLeftIndex = 0,iRightIndex = 0; while (iLeftIndex != -1)
{
iLeftIndex = strValue.LastIndexOf('('); if (iLeftIndex != -1)
{
iRightIndex =strValue.Substring(iLeftIndex + 1).IndexOf(')'); strValue = strValue.Substring (0,iLeftIndex) +
"#" +
Account(strValue.Substring(iLeftIndex + 1,iRightIndex)).ToString("F") +
strValue.Substring(iLeftIndex + iRightIndex + 2);
}
} return Account(strValue);
} private decimal Account(string strFormulary)
{
decimal deValue = 0; int iIndex = 0; iIndex = strFormulary.LastIndexOf("+"); if (iIndex != -1)
{
deValue = Account(strFormulary.Substring (0, iIndex))
+ Account(strFormulary.Substring (iIndex + 1)); return deValue;
}

iIndex = strFormulary.Length - 1; while (true)
{
iIndex = strFormulary.LastIndexOf('-', iIndex - 1); if (iIndex != -1)
{
if (strFormulary.Substring(iIndex - 1 , 1) != "#")
{
deValue = Account(strFormulary.Substring (0, iIndex))
- Account(strFormulary.Substring (iIndex + 1));

return deValue;
}
}
else
{
break;
}
} iIndex = strFormulary.LastIndexOf('*'); if (iIndex != -1)
{
deValue = Account(strFormulary.Substring (0, iIndex))
* Account(strFormulary.Substring (iIndex + 1)); return deValue;
}

iIndex = strFormulary.LastIndexOf('/'); if (iIndex != -1)
{
deValue = Account(strFormulary.Substring (0, iIndex))
/ Account(strFormulary.Substring (iIndex + 1)); return deValue;
} if (strFormulary.Substring(0,1) == "#")
{
return Convert.ToDecimal(strFormulary.Substring(1));
} return AccountString (strFormulary);
}
} public delegate decimal StringToDecimal(string strItem);
}