☆用心生活☆-wonder-{改变自己才能让自己过上不一样的日子。为自己加油!}

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"
);
        }

posted @ 2011-08-20 15:52  ☆用心生活☆  阅读(939)  评论(0编辑  收藏  举报
本作者写的任何文章均属原创,若要转载,请注明出处;若
进行与文章有关的商业行为,本作者保留拥有诉诸法律追究
侵权的任何行为。文章只代表本人某一学习时间段内对某一
技术的说明,不代表具有绝对的正确性,若要学习,请与各
位高手编程人员讨论学习。本文章也不代表自己某一时期某
一公司的任何专著和机密文件。仅仅提供自我学习和他人学
习的文章参考,以及自我知识记录。wanzegui325#163.com