![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
.aspx.cs
1
using System;
2
using System.Collections;
3
using System.ComponentModel;
4
using System.Data;
5
using System.Data.SqlClient;
6
using System.Drawing;
7
using System.Web;
8
using System.Web.SessionState;
9
using System.Web.UI;
10
using System.Web.UI.WebControls;
11
using System.Web.UI.HtmlControls;
12![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
13
using Test1.ItemplateTest;
14![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
15
namespace Test1
16![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
{
17![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
18
/// ScoreTable 的摘要说明。
19
/// </summary>
20
public class ScoreTable : System.Web.UI.Page
21![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
22
protected System.Web.UI.WebControls.Button Button1;
23
protected System.Web.UI.WebControls.DataGrid grdTextAnserScore;
24
25
private void Page_Load(object sender, System.EventArgs e)
26![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
27
DataSet demand = getData();//得到数据源
28![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
29
//为Datagrid添加列
30
addColumsForDataGrid(grdTextAnserScore,demand);
31
//创建虚拟数据表,用做数据源
32
DataTable dt = createDataTable(demand);
33
//得到包下所有供应商信息
34
DataTable dtProv = getProvsInPack("bfee693b-25c0-4080-8edb-ece782f09ad8");
35
//为虚拟表添加数据
36
DataTable dtFilled = FillDataTable(dtProv,dt,demand);
37
//绑定DataGrid
38
grdTextAnserScore.DataSource = dtFilled;
39
grdTextAnserScore.DataBind();
40
}
41![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
42![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
43
/// 描述:得到分类、要求信息
44
/// 作者:南守拥
45
/// 时间:2006年12月26日
46
/// </summary>
47
/// <returns></returns>
48
private DataSet getData()
49![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
50
//DataGrid表头
51
//包下有那些供应商
52
SqlConnection con = new SqlConnection("Persist Security Info=false;Data Source=192.168.0.9;Initial Catalog=TjgpE;User ID=sa;Password=;");
53
SqlDataAdapter da = new SqlDataAdapter("",con);
54
//包文本应答项
55
//要求分类信息
56
da.SelectCommand.CommandText = "select distinct PK_DemandKindID,DemandKindName from V_StockItem_StockPack_Demand_BidValue_Resp where FK_StockPackID = 'bfee693b-25c0-4080-8edb-ece782f09ad8'and FK_ResponseID = '0'";
57
DataSet demand = new DataSet();
58
da.Fill(demand,"Kind");
59
//要求信息
60
da.SelectCommand.CommandText = "select distinct PK_DemandKindID,DemandName,PK_StockPack_DemandID,FK_DemandInfoID from V_StockItem_StockPack_Demand_BidValue_Resp where FK_StockPackID = 'bfee693b-25c0-4080-8edb-ece782f09ad8' and FK_ResponseID = '0'";
61
da.Fill(demand,"Info");
62
//加要求分类与要求关系
63
demand.Relations.Add("KindAndInfo",demand.Tables["Kind"].Columns["PK_DemandKindID"],demand.Tables["Info"].Columns["PK_DemandKindID"]);
64
65
return demand;
66
}
67![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
68![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
69![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
70
/// 描述:为DataGrid添加列
71
/// 作者:南守拥
72
/// 时间:2006年12月16日
73
/// </summary>
74
/// <param name="myGrid">要添加列的DataGrid</param>
75
/// <param name="demand">数据源</param>
76
private void addColumsForDataGrid(DataGrid myGrid,DataSet demand)
77![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
78
foreach(DataRow rowKind in demand.Tables["Kind"].Rows)//分类
79![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
80
foreach(DataRow rowInfo in rowKind.GetChildRows("KindAndInfo")) //要求
81![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
82
//Datagrid添加应答列
83
TemplateColumn tc1 = new TemplateColumn();
84
string columName = "Anser" + rowInfo["DemandName"].ToString();
85
tc1.ItemTemplate = new CTemplateColLabel(columName);
86
tc1.ItemStyle.Wrap = false;
87
grdTextAnserScore.Columns.Add(tc1);
88
//Datagrid添加打分列
89
TemplateColumn tc2 = new TemplateColumn();
90
string columNamePoint = "Point" + rowInfo["DemandName"].ToString();
91
tc2.ItemTemplate = new CTemplateCol(columNamePoint);
92
tc2.ItemStyle.Wrap = false;
93
grdTextAnserScore.Columns.Add(tc2);
94![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
95
}
96
}
97
}
98![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
99![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
100![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
101
/// 描述:创建虚拟表
102
/// 作者:南守拥
103
/// 时间:2006年12月26日
104
/// </summary>
105
/// <param name="demand">数据源</param>
106
/// <returns>虚拟DataTable</returns>
107
private DataTable createDataTable(DataSet demand)
108![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
109
DataTable myTable = new DataTable();
110![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
111
DataColumn columProvID = new DataColumn();
112
columProvID.ColumnName = "ProvID";
113
myTable.Columns.Add(columProvID);//添加供应商ID列
114![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
115
DataColumn columProvName = new DataColumn();
116
columProvName.ColumnName = "ProvName";
117
myTable.Columns.Add(columProvName);//添加供应商名称列
118![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
119
foreach(DataRow rowKind in demand.Tables["Kind"].Rows)//分类
120![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
121
foreach(DataRow rowInfo in rowKind.GetChildRows("KindAndInfo")) //要求
122![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
123
DataColumn colum = new DataColumn();
124
colum.ColumnName = "Anser" + rowInfo["DemandName"].ToString();
125
myTable.Columns.Add(colum);
126
}
127
}
128
return myTable;
129
}
130![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
131![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
132![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
133
/// 描述:得到包下的所有供应商
134
/// 作者:南守拥
135
/// 时间:2006年12月26日
136
/// </summary>
137
/// <param name="packid">包ID</param>
138
/// <returns></returns>
139
private DataTable getProvsInPack(string packid)
140![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
141
SqlConnection con = new SqlConnection("Persist Security Info=false;Data Source=192.168.0.9;Initial Catalog=TjgpE;User ID=sa;Password=;");
142
SqlDataAdapter da = new SqlDataAdapter("select distinct Txt_ProvID,txt_name_ch from V_StockItem_StockPack_Demand_BidValue_Resp where FK_StockPackID = 'bfee693b-25c0-4080-8edb-ece782f09ad8' and FK_ResponseID = '0'",con);
143
DataTable dt = new DataTable();
144
da.Fill(dt);
145
return dt;
146
}
147![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
148![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
149![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
150
/// 描述:为虚拟表添加数据
151
/// 作者:南守拥
152
/// 时间:2006年12月26日
153
/// </summary>
154
/// <param name="provs"></param>
155
/// <param name="myTable"></param>
156
/// <returns></returns>
157
private DataTable FillDataTable(DataTable provs,DataTable myTable,DataSet source)
158![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
159
foreach(DataRow row in provs.Rows)
160![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
161
DataRow newRow = myTable.NewRow();//创建新行
162
//添加供应商ID
163
newRow["ProvID"] = row["Txt_ProvID"];
164
//添加供应商名称
165
newRow["ProvName"] = row["txt_name_ch"];
166
foreach(DataRow rowKind in source.Tables["Kind"].Rows)//分类
167![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
168
foreach(DataRow rowInfo in rowKind.GetChildRows("KindAndInfo")) //要求
169![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
170
newRow["Anser" + rowInfo["DemandName"].ToString()] = GetResponseInfo("bfee693b-25c0-4080-8edb-ece782f09ad8",row["Txt_ProvID"].ToString(),rowInfo["FK_DemandInfoID"].ToString());
171
}
172
}
173
myTable.Rows.Add(newRow);
174
}
175
return myTable;
176
}
177![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
178![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
179
/// 描述:查询包下特定供应商的特定要求的应答内容
180
/// 作者:南守拥
181
/// 时间:2006年12月26日
182
/// </summary>
183
/// <param name="packid">包ID</param>
184
/// <param name="provid">供应商ID</param>
185
/// <param name="demandid">要求ID</param>
186
/// <returns></returns>
187
private string GetResponseInfo(string packid,string provid,string demandid)
188![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
189
SqlConnection con = new SqlConnection("Persist Security Info=false;Data Source=192.168.0.9;Initial Catalog=TjgpE;User ID=sa;Password=;");
190
SqlDataAdapter da = new SqlDataAdapter("select distinct ResponseContent from V_StockItem_StockPack_Demand_BidValue_Resp where FK_StockPackID='"+packid+"'and FK_ResponseID='0'and Txt_ProvID='"+provid+"'and FK_DemandInfoID='"+demandid+"'",con);
191
DataTable dt = new DataTable();
192
da.Fill(dt);
193
return dt.Rows[0][0].ToString();
194
}
195![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
196![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
197![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif)
Web 窗体设计器生成的代码#region Web 窗体设计器生成的代码
198
override protected void OnInit(EventArgs e)
199![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
200
//
201
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
202
//
203
InitializeComponent();
204
base.OnInit(e);
205
}
206
207![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
208
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
209
/// 此方法的内容。
210
/// </summary>
211
private void InitializeComponent()
212![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
213
this.grdTextAnserScore.ItemCreated += new System.Web.UI.WebControls.DataGridItemEventHandler(this.grdTextAnserScore_ItemCreated);
214
this.grdTextAnserScore.ItemDataBound += new System.Web.UI.WebControls.DataGridItemEventHandler(this.grdTextAnserScore_ItemDataBound);
215
this.Button1.Click += new System.EventHandler(this.Button1_Click);
216
this.Load += new System.EventHandler(this.Page_Load);
217![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
218
}
219
#endregion
220![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
221
private void grdTextAnserScore_ItemCreated(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
222![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
223
if(e.Item.ItemType == ListItemType.Header)
224![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
225
e.Item.SetRenderMethodDelegate(new RenderMethod(NewRenderMothodItem));//输出流重定向(按项目)
226
}
227
}
228![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
229
/// 描述:自定义表头输出
230
/// 作者:南守拥
231
/// 时间:2006年12月27日
232
/// </summary>
233
/// <param name="writer"></param>
234
/// <param name="ctl"></param>
235
private void NewRenderMothodItem(HtmlTextWriter writer,Control ctl)
236![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
237
//输出供应商ID
238
writer.AddAttribute(HtmlTextWriterAttribute.Rowspan,"2");
239
writer.AddAttribute(HtmlTextWriterAttribute.Class,"locked");
240
writer.AddAttribute(HtmlTextWriterAttribute.Wrap,"false");
241
writer.RenderBeginTag(HtmlTextWriterTag.Th);
242
Label lbl0 = new Label();
243
lbl0.Text = "供应商ID";
244
lbl0.RenderControl(writer);
245
writer.RenderEndTag();
246
//输出供应商名称
247
writer.AddAttribute(HtmlTextWriterAttribute.Rowspan,"2");
248
writer.AddAttribute(HtmlTextWriterAttribute.Class,"locked");
249
writer.AddAttribute(HtmlTextWriterAttribute.Wrap,"false");
250
writer.RenderBeginTag(HtmlTextWriterTag.Th);
251
Label lbl1 = new Label();
252
lbl1.Text = "供应商名称";
253
lbl1.RenderControl(writer);
254
writer.RenderEndTag();
255
//输出表头的第一行(分类名称部分)
256
DataSet demand = getData();
257
RenderTitleFirstRow(writer,demand);//输出第一行
258
//强制结束换行
259
writer.Write("</tr>");
260
//输出表头的第二行(要求名称部分)
261
RenderTitleSecondRow(writer,demand);//输出第二行
262
}
263![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
264
/// 描述:输出表头的第一行
265
/// 作者:南守拥
266
/// 时间:2006年12月27日
267
/// </summary>
268
/// <param name="demand">分类其要求</param>
269
private void RenderTitleFirstRow(HtmlTextWriter writer, DataSet demand)
270![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
271
foreach(DataRow rowKind in demand.Tables["Kind"].Rows) //循环所有的分类
272![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
273
int colspan = GetCagegoryColspan(rowKind); //得到其Colspan属性值
274
writer.AddAttribute(HtmlTextWriterAttribute.Colspan,colspan.ToString());//添加相应的Colspan属性
275
writer.RenderBeginTag(HtmlTextWriterTag.Th);//输出表头单元格标记<th>
276
Label lbl = new Label();
277
lbl.Text = rowKind["DemandKindName"].ToString();//分类名称
278
lbl.RenderControl(writer);//输出
279
writer.RenderEndTag();//输出表头单元格结束标记</th>
280
}
281
}
282![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
283
/// 描述:得到特定分类的Colspan
284
/// 作者:南守拥
285
/// 时间:2006年12月27日
286
/// </summary>
287
/// <param name="row">分类行</param>
288
/// <returns>特定分类的Colspan值</returns>
289
private int GetCagegoryColspan(DataRow row)
290![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
291
int demaindCount = 0;
292
for(int i = 0;i< row.GetChildRows("KindAndInfo").Length;i++) //循环要求个数
293![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
294
demaindCount ++;
295
}
296
if(demaindCount == 0)
297![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
298
return 1;
299
}
300
return demaindCount*2;//因为表头的第二行有固定的Colspan数2(应答内容列、打分列)
301
}
302![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
303
/// 描述:输出表头的第二行
304
/// 作者:南守拥
305
/// 时间:2006年12月27日
306
/// </summary>
307
/// <param name="writer">Html流</param>
308
/// <param name="demand">分类和要求</param>
309
private void RenderTitleSecondRow(HtmlTextWriter writer,DataSet demand)
310![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
311
//添加行<tr>
312
writer.RenderBeginTag(HtmlTextWriterTag.Tr);
313
//输出表头第二行
314
foreach(DataRow rowKind in demand.Tables["Kind"].Rows)//分类
315![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
316
foreach(DataRow rowInfo in rowKind.GetChildRows("KindAndInfo"))//要求
317![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
318
writer.AddAttribute(HtmlTextWriterAttribute.Colspan,"2");//固定的跨二列(应答内容列、打分列)
319
writer.RenderBeginTag(HtmlTextWriterTag.Th);//表头单元格<th>
320
Label lbl = new Label();
321
lbl.Text = rowInfo["DemandName"].ToString();//名称
322
lbl.RenderControl(writer);
323
writer.RenderEndTag();//表头单元格结束</th>
324
}
325
}
326
//结束添加的行</tr>
327
writer.RenderEndTag();
328
}
329![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
330![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
331![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
332
/// 描述:打分表的行数据绑定事件
333
/// 作者:南守拥
334
/// 时间:2006年12月27日
335
/// </summary>
336
/// <param name="sender"></param>
337
/// <param name="e"></param>
338
private void grdTextAnserScore_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
339![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
340
if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
341![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
342
e.Item.Cells[0].CssClass = "locked";//让第一列固定
343
e.Item.Cells[1].CssClass = "locked";//让第二列固定
344
}
345
}
346![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
347![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
348![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
349
/// 事件测试,读打分值
350
/// </summary>
351
/// <param name="sender"></param>
352
/// <param name="e"></param>
353
private void Button1_Click(object sender, System.EventArgs e)
354![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
355
foreach(DataGridItem item in grdTextAnserScore.Items)
356![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
357
TextBox txt = (TextBox)item.FindControl("Point资信要求3");
358
if(txt != null)
359![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
360
Response.Write(txt.Text.Trim());
361
}
362
}
363
}
364
}
365
}
这里面还有许多需要重构的,没有时间做了,项目太紧。