页小计
栏尾 + Data项里要有 数据源绑定。
大写人民
private void Cell47_AfterData(object sender, EventArgs e)
{
TableCell nCell= sender as TableCell;
nCell.Text=ToRMB(nCell.Text.ToString());
}
public static string ToRMB(string e)
{
if (String.IsNullOrEmpty(e))
return ToRMB(0);
else
return ToRMB(decimal.Parse(e));
}
public static string ToRMB(decimal e)
{
string eString;//数字的格式化字符串
string eNum;//单数字
int eLen;//格式化字符串长度
System.Text.StringBuilder rmb = new System.Text.StringBuilder();//人民币大写
string yuan;//圆
bool seriesZero;//连续0标志
bool minus = false;//负数标志
if (e == 0m)
{
return "零圆整";
}
if (e < 0)
{
minus = true;
e = System.Math.Abs(e);
}
if (e > (decimal)999999999999.99)
{
throw new Exception("超过最大范围");
}
eString = e.ToString("0.00");
eLen = eString.Length;
yuan = (eString.Substring(0, 1) == "0" ? "" : "圆");
eNum = eString.Substring(eLen - 1, 1);//分位
if (eNum == "0")
{
rmb.Append("整");
seriesZero = true;
}
else
{
rmb.Append(stringNum(eNum) + "分");
seriesZero = false;
}
eNum = eString.Substring(eLen - 2, 1);//角位
if (eNum == "0")
{
if (!seriesZero)
{
if (!(eLen == 4 && eString.Substring(0, 1) == "0"))
{
rmb.Insert(0, "零");
}
}
}
else
{
rmb.Insert(0, stringNum(eNum) + "角");
seriesZero = false;
}
if (eLen <= 7)
{
rmb.Insert(0, stringNum4(eString.Substring(0, eLen - 3)) + yuan);
}
else if (eLen <= 11)
{
rmb.Insert(0, stringNum4(eString.Substring(eLen - 7, 4)) + yuan);
rmb.Insert(0, stringNum4(eString.Substring(0, eLen - 7)) + "万");
}
else if (eLen <= 15)
{
rmb.Insert(0, stringNum4(eString.Substring(eLen - 7, 4)) + yuan);
rmb.Insert(0, stringNum4(eString.Substring(eLen - 11, 4)) + (eString.Substring(eLen - 11, 4) == "0000" ? "" : "万"));
rmb.Insert(0, stringNum4(eString.Substring(0, eLen - 11)) + "亿");
}
if (minus) rmb.Insert(0, "负");
return rmb.ToString();
}
private static string stringNum4(string eNum4)
{
string eNum;
bool seriesZero = false;
System.Text.StringBuilder rmb4 = new System.Text.StringBuilder();
int eLen = eNum4.Length;
eNum = eNum4.Substring(eLen - 1, 1);//个位
if (eNum == "0")
{
seriesZero = true;
}
else
{
rmb4.Append(stringNum(eNum));
}
if (eLen >= 2)//十位
{
eNum = eNum4.Substring(eLen - 2, 1);
if (eNum == "0")
{
if (!seriesZero)
{
rmb4.Insert(0, "零");
seriesZero = true;
}
}
else
{
rmb4.Insert(0, stringNum(eNum) + "拾");
seriesZero = false;
}
}
if (eLen >= 3)//百位
{
eNum = eNum4.Substring(eLen - 3, 1);
if (eNum == "0")
{
if (!seriesZero)
{
rmb4.Insert(0, "零");
seriesZero = true;
}
}
else
{
rmb4.Insert(0, stringNum(eNum) + "佰");
seriesZero = false;
}
}
if (eLen == 4)//千位
{
eNum = eNum4.Substring(0, 1);
if (eNum == "0")
{
if (!seriesZero)
{
rmb4.Insert(0, "零");
seriesZero = true;
}
}
else
{
rmb4.Insert(0, stringNum(eNum) + "仟");
seriesZero = false;
}
}
return rmb4.ToString();
}
private static string stringNum(string eNum)
{
switch (eNum)
{
case "1":
return "壹";
case "2":
return "贰";
case "3":
return "叁";
case "4":
return "肆";
case "5":
return "伍";
case "6":
return "陆";
case "7":
return "柒";
case "8":
return "捌";
case "9":
return "玖";
default:
return "";
}
}