62,243
社区成员




<asp:GridView ID="gdvIn" CellSpacing="0" CellPadding="0" BorderStyle="None"
CssClass="Contenttable" runat="server" AutoGenerateColumns="False"
ShowHeader="False" Width="100%" EnableTheming="false" GridLines="None">
<Columns>
<asp:BoundField DataField="categoryname" HeaderText="收支项目">
<ItemStyle CssClass="viewcateName"/></asp:BoundField>
<asp:TemplateField HeaderText="第1月">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("month1") %>' ForeColor='<%# returnColor(decimal.Parse(Eval("month1").ToString())) %>'></asp:Label>
</ItemTemplate>
<ItemStyle CssClass="gridwidth"/>
</asp:TemplateField>
<asp:TemplateField HeaderText="第2月">
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("month2") %>' ForeColor='<%# returnColor(decimal.Parse(Eval("month2").ToString())) %>'></asp:Label>
</ItemTemplate>
<ItemStyle CssClass="gridwidth"/>
</asp:TemplateField>
---------------------------------------------分割线--------gdvIn和gdvOut是分别独立而非嵌套的Gridview--------------------------------------------
<asp:GridView ID="gdvOut" CellSpacing="0" CssClass="Contenttable"
runat="server" AutoGenerateColumns="False"
ShowHeader="False" Width="100%" EnableTheming="false" GridLines="None">
<Columns>
<asp:BoundField DataField="categoryname" HeaderText="收支项目">
<ItemStyle CssClass="viewcateName"/></asp:BoundField>
<asp:TemplateField HeaderText="第1月">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("month1") %>' ForeColor='<%# returnColor(decimal.Parse(Eval("month1").ToString())) %>'></asp:Label>
</ItemTemplate>
<ItemStyle CssClass="gridwidth"/>
</asp:TemplateField>
<asp:TemplateField HeaderText="第2月">
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("month2") %>' ForeColor='<%# returnColor(decimal.Parse(Eval("month2").ToString())) %>'></asp:Label>
</ItemTemplate>
<ItemStyle CssClass="gridwidth"/>
</asp:TemplateField>
<asp:TemplateField HeaderText="第3月">
<ItemTemplate>
<asp:Label ID="Label3" runat="server" Text='<%# Bind("month3") %>' ForeColor='<%# returnColor(decimal.Parse(Eval("month3").ToString())) %>'></asp:Label>
</ItemTemplate>
//显示合计
int inCount = gdvIn.Rows.Count - 1;
int outCount = gdvOut.Rows.Count - 1;
for (int i = 1; i < gdvIn.Columns.Count;i++ )
{
Label lblIn = (Label)gdvIn.Rows[inCount].FindControl("Label"+i.ToString());
Label lblOut = (Label)gdvOut.Rows[outCount].FindControl("Label" + i.ToString());
Label lblSum = (Label)Page.FindControl("sum"+i.ToString());
decimal sum = decimal.Parse(lblIn.Text) - decimal.Parse(lblOut.Text);
lblSum.Text = sum.ToString("F2");
if(sum<0)
{
lblSum.ForeColor = System.Drawing.Color.Red;
}
public static DataTable intypeTable(string dateYear)
{
DataTable inDt = new DataTable();
DataColumn dc = new DataColumn("categoryname",typeof(string));
inDt.Columns.Add(dc);
DataColumn month1 = new DataColumn("month1", typeof(decimal));
inDt.Columns.Add(month1);
DataColumn month2 = new DataColumn("month2", typeof(decimal));
inDt.Columns.Add(month2);
DataColumn month3 = new DataColumn("month3", typeof(decimal));
inDt.Columns.Add(month3);
DataColumn month4 = new DataColumn("month4", typeof(decimal));
inDt.Columns.Add(month4);
DataColumn month5 = new DataColumn("month5", typeof(decimal));
inDt.Columns.Add(month5);
DataColumn month6 = new DataColumn("month6", typeof(decimal));
inDt.Columns.Add(month6);
DataColumn month7 = new DataColumn("month7", typeof(decimal));
inDt.Columns.Add(month7);
DataColumn month8 = new DataColumn("month8", typeof(decimal));
inDt.Columns.Add(month8);
DataColumn month9 = new DataColumn("month9", typeof(decimal));
inDt.Columns.Add(month9);
DataColumn month10 = new DataColumn("month10", typeof(decimal));
inDt.Columns.Add(month10);
DataColumn month11 = new DataColumn("month11", typeof(decimal));
inDt.Columns.Add(month11);
DataColumn month12 = new DataColumn("month12", typeof(decimal));
inDt.Columns.Add(month12);
//
PutopJxc.Entity.v_Wastebook_Type1[] type1 = PutopJxc.Da.M_Statistics.SelectType1("dtyear=" + dateYear);
DataRow dr;
decimal[] insum = new decimal[12];
for (int i = 0; i < type1.Length;i++ )
{
dr = inDt.NewRow();
if(i == 0)
{
dr[0] = type1[i].categoryname;
dr[type1[i].dtmonth] = type1[i].amount.ToString("n2");
inDt.Rows.Add(dr);
}
else
{
int index = -1;
for(int j =0;j<inDt.Rows.Count;j++)
{
if(type1[i].categoryname == inDt.Rows[j][0].ToString())
{
index = j;
break;
}
}
if (index != -1)
{
inDt.Rows[index][type1[i].dtmonth] = type1[i].amount.ToString("n2");
}
else
{
dr[0] = type1[i].categoryname;
dr[type1[i].dtmonth] = type1[i].amount.ToString("n2");
inDt.Rows.Add(dr);
}
}
insum[type1[i].dtmonth-1] += type1[i].amount;
}
//添加小计行
DataRow sumDr = inDt.NewRow();
sumDr[0] = "收入小计";
for (int i = 1; i < insum.Length;i++ )
{
sumDr[i] = insum[i - 1].ToString("n2");
}
inDt.Rows.Add(sumDr);
//
//填充空的单元格
for (int i = 0; i < inDt.Rows.Count;i++ )
{
for (int j = 1; j < inDt.Columns.Count;j++ )
{
if (String.IsNullOrEmpty(inDt.Rows[i][j].ToString()))
{
inDt.Rows[i][j] = "0.00";
}
}
}
return inDt;
}
public static DataTable outtypeTable(string dateYear)
{
DataTable outDt = new DataTable();
DataColumn dc = new DataColumn("categoryname", typeof(string));
outDt.Columns.Add(dc);
DataColumn month1 = new DataColumn("month1", typeof(decimal));
outDt.Columns.Add(month1);
DataColumn month2 = new DataColumn("month2", typeof(decimal));
outDt.Columns.Add(month2);
DataColumn month3 = new DataColumn("month3", typeof(decimal));
outDt.Columns.Add(month3);
DataColumn month4 = new DataColumn("month4", typeof(decimal));
outDt.Columns.Add(month4);
DataColumn month5 = new DataColumn("month5", typeof(decimal));
outDt.Columns.Add(month5);
DataColumn month6 = new DataColumn("month6", typeof(decimal));
outDt.Columns.Add(month6);
DataColumn month7 = new DataColumn("month7", typeof(decimal));
outDt.Columns.Add(month7);
DataColumn month8 = new DataColumn("month8", typeof(decimal));
outDt.Columns.Add(month8);
DataColumn month9 = new DataColumn("month9", typeof(decimal));
outDt.Columns.Add(month9);
DataColumn month10 = new DataColumn("month10", typeof(decimal));
outDt.Columns.Add(month10);
DataColumn month11 = new DataColumn("month11", typeof(decimal));
outDt.Columns.Add(month11);
DataColumn month12 = new DataColumn("month12", typeof(decimal));
outDt.Columns.Add(month12);
//
PutopJxc.Entity.v_Wastebook_Type2[] type2 = PutopJxc.Da.M_Statistics.SelectType2("dtyear=" + dateYear);
DataRow dr;
decimal[] outSum = new decimal[12];
for (int i = 0; i < type2.Length; i++)
{
dr = outDt.NewRow();
if(i==0)
{
dr[0] = type2[i].categoryname;
dr[type2[i].dtmonth] = type2[i].amount.ToString("n2");
outDt.Rows.Add(dr);
}
else
{
int index = -1;
for (int j = 0; j < outDt.Rows.Count;j++ )
{
if(type2[i].categoryname == outDt.Rows[j][0].ToString())
{
index = j;
break;
}
}
if (index != -1)
{
outDt.Rows[index][type2[i].dtmonth] = type2[i].amount.ToString("n2");
}
else
{
dr[0] = type2[i].categoryname;
dr[type2[i].dtmonth] = type2[i].amount.ToString("n2");
outDt.Rows.Add(dr);
}
}
outSum[type2[i].dtmonth - 1] += type2[i].amount;
}
//添加小计行
DataRow sumDr = outDt.NewRow();
sumDr[0] = "支出小计";
for (int i = 1; i < outSum.Length; i++)
{
sumDr[i] = outSum[i - 1].ToString("n2");
}
outDt.Rows.Add(sumDr);
//填充空的单元格
for (int i = 0; i < outDt.Rows.Count; i++)
{
for (int j = 1; j < outDt.Columns.Count; j++)
{
if (String.IsNullOrEmpty(outDt.Rows[i][j].ToString()))
{
outDt.Rows[i][j] = "0.00";
}
}
}
return outDt;
}