Gridview列的增减

Gridview一部分列固定, 另一部分根据所选月份增减, 实现统计的应用

 

 

 

                if ((howm < 12) && (howm >= 0))
                {

                    for (int i = GridView1.Columns.Count; i > 12; i--)
                    {
                        GridView1.Columns.RemoveAt(i-1);
                    }

 

                    int NewM = 0;
                    for (int k = 0; k <= howm; k++)
                    {
                        string hStr;
                        BoundField bc = new BoundField();

                        if ((Convert.ToInt16(m1)) + k <= 12)
                        {
                            hStr = Convert.ToString((Convert.ToInt16(m1)) + k);

                            if (Convert.ToInt16(hStr) < 10)
                            {
                                bc.HeaderText = y1 + "0" + hStr;
                            }
                            else
                            {
                                bc.HeaderText = y1 + hStr;
                            }

                            ym = bc.HeaderText.ToString();
                            dm = Convert.ToInt16(ym.Substring(4, 2));
                            bc.DataField = "tq" + dm.ToString().Trim();
                            GridView1.Columns.Add(bc);
                           
                            ExecSQL("update DataReport set m" + dm.ToString().Trim() + "_t = (Select Count(*) as recs From DataReptmp where styleNo = DataReport.styleNo and rectt=DataReport.rectt and ltrim(str(year(seldate)))+ (case when month(seldate)<10 then '0'+ltrim(str(month(seldate))) else ltrim(str(month(seldate))) end) ='" + ym + "' Group By styleNo,whouse Having Count(*) >=1 ) ");
                            ExecSQL("update DataReport set m" + dm.ToString().Trim() + "_q = (Select sum(quan) as quan From DataReptmp where styleNo = DataReport.styleNo and rectt=DataReport.rectt and ltrim(str(year(seldate)))+ (case when month(seldate)<10 then '0'+ltrim(str(month(seldate))) else ltrim(str(month(seldate))) end) ='" + ym + "' Group By styleNo,whouse)");

                        }
                        else
                        {
                            NewM++;
                            hStr = Convert.ToString(NewM);
                            if (Convert.ToInt16(hStr) < 10)
                            {
                                bc.HeaderText = y2 + "0" + hStr;
                            }
                            else
                            {
                                bc.HeaderText = y2 + hStr;
                            }


                            ym = bc.HeaderText.ToString();
                            dm = Convert.ToInt16(ym.Substring(4, 2));
                            bc.DataField = "tq" + dm.ToString().Trim();
                            GridView1.Columns.Add(bc);

 

                            ExecSQL("update DataReport set m" + dm.ToString().Trim() + "_t = (Select Count(*) as recs From DataReptmp where styleNo = DataReport.styleNo and rectt=DataReport.rectt and ltrim(str(year(seldate)))+ (case when month(seldate)<10 then '0'+ltrim(str(month(seldate))) else ltrim(str(month(seldate))) end) ='" + ym + "' Group By styleNo,whouse Having Count(*) >=1 ) ");


                            ExecSQL("update DataReport set m" + dm.ToString().Trim() + "_q = (Select sum(quan) as quan From DataReptmp where styleNo = DataReport.styleNo and rectt=DataReport.rectt and ltrim(str(year(seldate)))+ (case when month(seldate)<10 then '0'+ltrim(str(month(seldate))) else ltrim(str(month(seldate))) end) ='" + ym + "' Group By styleNo,whouse)");
                        }
                       


                    }

                    ExecSQL("update DataReport set ttl_t = isnull(m1_t,'0')+isnull(m2_t,'0')+isnull(m3_t,'0')+isnull(m4_t,'0')+isnull(m5_t,'0')+isnull(m6_t,'0')+isnull(m7_t,'0')+isnull(m8_t,'0')+isnull(m9_t,'0')+isnull(m10_t,'0')+isnull(m11_t,'0')+isnull(m12_t,'0') ");
                    ExecSQL("update DataReport set ttl_q = isnull(m1_q,'0')+isnull(m2_q,'0')+isnull(m3_q,'0')+isnull(m4_q,'0')+isnull(m5_q,'0')+isnull(m6_q,'0')+isnull(m7_q,'0')+isnull(m8_q,'0')+isnull(m9_q,'0')+isnull(m10_q,'0')+isnull(m11_q,'0')+isnull(m12_q,'0') ");

 

                    ExecSQL("delete DataReport where ttl_t = 0");// needs

 

                   

                }

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值