/// 显示图象
/// </summary>
/// <param name="strContent">相关主题下的内容</param>
/// <param name="decNumAll">所有的票数</param>
/// <returns></returns>
public string GetResult(string strContent, decimal decNumAll)
{
string[] arrContent = strContent.Split('|');
string strBody = "<table width=100% border=1>\n";
foreach (string strContentIN in arrContent)
{
string strItemName = strContentIN.Split(',')[1].ToString();//得到选项名称
decimal decItemNum = Convert.ToDecimal(strContentIN.Split(',')[0]);//得到选项的投票数
decimal decPercent = GetPercent(decItemNum, decNumAll) * 100;//得到百分比
string strPercent = decPercent.ToString();//将百分比转为字符型
if (strPercent.Length > 5)//如果百分比结果长度超过5位
{
strPercent = strPercent.Substring(0, 5);//将百分比的余数截短为“00.00”
}
strBody += "<tr><td width=100>" + strItemName + "</td><td width=50>" + decItemNum.ToString() + "票</td><td><img src=Images/bar1.gif height=10 width=" + strPercent + "%>" + strPercent + "%</td></tr>\n";
}
strBody += "</table>";
return strBody;
}
/// <summary>
/// 票数求和
/// </summary>
/// <param name="strNum">当前所要操作的字串</param>
/// <returns></returns>
public decimal GetNumAll(string strNum)
{
decimal decNumAll = 0;
string[] arrNum = strNum.Split('|');
foreach (string strNumIN in arrNum)
{
decNumAll += Convert.ToInt32(strNumIN.Split(',')[0].ToString());//截取第零位
}
return decNumAll;
}
/// <summary>
/// 百分比
/// </summary>
/// <param name="decItem">当前选项本身的票数</param>
/// <param name="decNumAll">所有的票数</param>
/// <returns></returns>
public decimal GetPercent(decimal decItem, decimal decNumAll)
{
if (decNumAll == 0)//如果总票数是零
{
decNumAll++;//加一,避免除0出错
}
decimal decPercent = decItem / decNumAll;
return decPercent;
}