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
}