datagirdview进行数据统计
因为BOSS需要查看销售单退货的情况,不只需要看到退货的明细,而且还要看到退货的总计,以及各个单据对应业务员的关系。因此需要对数据进行统计计算。
以下代码是自己根据自己项目开发中需要用到的地方。
/// <summary>
/// 对DATAGRIDVIEW设置汇总统计信息
/// </summary>
private void setSumInfo()
{
double RMBrealInit = 0;
double USDrealInit = 0;
double HKDrealInit = 0;
double EURrealInit = 0;
double totalQty = 0;//总消退数
double totalPcs = 0;//件数
object obj;
Object obj2;
object obj3;
for (int i = 0; i < dgvSummary.Rows.Count; i++)
{
obj = dgvSummary.Rows[i].Cells["N_totalBackMoneyQty"].Value;
//循环计算RMB的值
if (Convert.ToString(dgvSummary.Rows[i].Cells["N_TransactionMoneyTypeDetail"].Value) == "RMB")
{
if (obj == null)
{
RMBrealInit += 0;
}
else
{
RMBrealInit+= Convert.ToDouble(dgvSummary.Rows[i].Cells["N_totalBackMoneyQty"].Value);
}
}//循环计算港币
else if (Convert.ToString(dgvSummary.Rows[i].Cells["N_TransactionMoneyTypeDetail"].Value) == "HKD")
{
if (obj == null)
{
HKDrealInit += 0;
}
else
{
HKDrealInit+= Convert.ToDouble(dgvSummary.Rows[i].Cells["N_totalBackMoneyQty"].Value);
}
}//美金
else if (Convert.ToString(dgvSummary.Rows[i].Cells["N_TransactionMoneyTypeDetail"].Value) == "USD")
{
if (obj == null)
{
USDrealInit += 0;
}
else
{
USDrealInit+= Convert.ToDouble(dgvSummary.Rows[i].Cells["N_totalBackMoneyQty"].Value);
}
}//欧元
else if (Convert.ToString(dgvSummary.Rows[i].Cells["N_TransactionMoneyTypeDetail"].Value) == "EUR")
{
if (obj == null)
{
EURrealInit += 0;
}
else
{
EURrealInit+= Convert.ToDouble(dgvSummary.Rows[i].Cells["N_totalBackMoneyQty"].Value);
}
}
//计算总总量,若需考虑单位,请考虑兑换比例
obj2 = dgvSummary.Rows[i].Cells["N_TotalBackqty"].Value;
if (obj2 == null)
{
totalQty += 0;
}
else
{
totalQty+= Convert.ToDouble(dgvSummary.Rows[i].Cells["N_TotalBackqty"].Value);
}
//计算总件数
obj3 = dgvSummary.Rows[i].Cells["N_TotalBackPcs"].Value;
if (obj3 == null)
{
totalPcs += 0;
}
else
{
totalPcs+= Convert.ToDouble(dgvSummary.Rows[i].Cells["N_TotalBackPcs"].Value);
}
}
/*格式化数字为货币形式*/
System.Globalization.CultureInfo rmbCultureInfo= new System.Globalization.CultureInfo("zh-CN");//
System.Globalization.CultureInfo usdCultureInfo = new System.Globalization.CultureInfo("en-US");
System.Globalization.CultureInfo hkdCultureInfo = new System.Globalization.CultureInfo("zh-HK");
this.txtSumRMB.Text = RMBrealInit.ToString("C", rmbCultureInfo);
// this.txtSumHKD.Text = HKDrealInit.ToString("C", hkdCultureInfo);//此代码显示复数的时候,用括号表示,不知何因由
this.txtSumHKD.Text ="HK$"+ HKDrealInit.ToString("N2", hkdCultureInfo);
this.txtSumUSD.Text = USDrealInit.ToString("C", usdCultureInfo);
this.txtSumEUR.Text = "€" + EURrealInit.ToString("N3");
this.txtSumWeightQty.Text = totalQty.ToString("N0");
this.txtTotalPcs.Text = totalPcs.ToString("N0");
}