数据交叉表的实现(2):通过组建Axes轴和Cell数组来建立数据交叉表模型

这篇距离上篇已经有些时日了,最近也比较忙,一直没有好好的整理

楼下有人要代码,我就发出来把。顺便做个简单的介绍
模型的建立
横轴:
竖轴:
因为两个轴是一样的,那么我们放在一起来讲
首先一个轴应该包含哪些信息呢?
1:轴名称
2:Positon集合(用于存放真正的维度信息)
每个轴都有若干个Position 一个Position代表一个维度,Position里面是Member的结合(也就是维度数据的集合)--如下图所示:
ClassDiagram1.gif

数据CellSet:
CellSet相对前面的概念来说就比较简单了,Cellset就是存放数据的容器了
其中一个单元格就是一个Cell

我们还是来看一下代码把
数据绑定的部分

 

  1 ContractedBlock.gif ExpandedBlockStart.gif          绑定数据 #region 绑定数据
  2InBlock.gif        private DataView _dataView;
  3InBlock.gif        public override void DataBind()
  4ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{  
  5InBlock.gif            // Load the data 其中dataSource是已经绑定的数据源
  6InBlock.gif            if (_dataSource != null)
  7ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
  8InBlock.gif                if (_dataSource is DataView || _dataSource is DataSet || _dataSource is DataTable)
  9ExpandedSubBlockStart.gifContractedSubBlock.gif                dot.gif{
 10InBlock.gif                    if (_dataSource is DataView)
 11ExpandedSubBlockStart.gifContractedSubBlock.gif                    dot.gif{
 12InBlock.gif                        _dataView = (DataView)_dataSource;
 13ExpandedSubBlockEnd.gif                    }

 14InBlock.gif                    else if (_dataSource is DataSet)
 15ExpandedSubBlockStart.gifContractedSubBlock.gif                    dot.gif{                       
 16InBlock.gif                       _dataView = ((DataSet)_dataSource).Tables[0].DefaultView;                       
 17ExpandedSubBlockEnd.gif                    }

 18InBlock.gif                    else // DataTable
 19ExpandedSubBlockStart.gifContractedSubBlock.gif                    dot.gif{
 20InBlock.gif                        _dataView = ((DataTable)_dataSource).DefaultView;
 21ExpandedSubBlockEnd.gif                    }

 22InBlock.gif
 23InBlock.gif                    this.DataBindToDataView(_dataView);
 24ExpandedSubBlockEnd.gif                }

 25InBlock.gif                else if (_dataSource is IEnumerable)
 26ExpandedSubBlockStart.gifContractedSubBlock.gif                dot.gif{
 27InBlock.gif                    this.DataBindToEnumerable((IEnumerable)_dataSource);
 28ExpandedSubBlockEnd.gif                }

 29InBlock.gif                else
 30ExpandedSubBlockStart.gifContractedSubBlock.gif                dot.gif{
 31InBlock.gif                    throw new Exception("Cannot bind to data source of type " + _dataSource.GetType().ToString());
 32ExpandedSubBlockEnd.gif                }

 33ExpandedSubBlockEnd.gif            }

 34InBlock.gif           
 35InBlock.gif            base.DataBind();
 36InBlock.gif
 37InBlock.gif            //_dataBound = true;
 38ExpandedSubBlockEnd.gif        }

 39InBlock.gif
 40InBlock.gif        private void DataBindToDataView(DataView oDataView)
 41ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
 42InBlock.gif            this.LoadGrid(oDataView);          
 43InBlock.gif            // Get some info about the dataset          
 44ExpandedSubBlockEnd.gif        }

 45InBlock.gif
 46InBlock.gif        private void DataBindToEnumerable(IEnumerable arList)
 47ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
 48InBlock.gif            throw new NotSupportedException("该方法未被支持,后面的版本也许会支持");          
 49ExpandedSubBlockEnd.gif        }

 50InBlock.gif
 51InBlock.gif        private void LoadGrid(DataView oDataView)
 52ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
 53InBlock.gif            DataTable oTable = oDataView.Table;
 54InBlock.gif            if (oTable == null || oTable.Rows.Count == 0return;
 55InBlock.gif            BuildFromDataTable(oTable);
 56ExpandedSubBlockEnd.gif        }

 57InBlock.gif
 58InBlock.gif       
 59InBlock.gif        private void BuildFromDataTable(DataTable table)
 60ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
 61InBlock.gif            if (this._measurefieldname == null || this._measurefieldname == "")
 62ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
 63InBlock.gif                throw new ArgumentNullException("MeasureFieldName""请设置数据列");
 64ExpandedSubBlockEnd.gif            }

 65InBlock.gif            if ((this._onColumnsAxesFieldName == null || this._onColumnsAxesFieldName == ""
 66InBlock.gif                && (this._onRowAxesFieldName == null || this._onRowAxesFieldName == "")                
 67InBlock.gif                )
 68ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
 69InBlock.gif                throw new ArgumentNullException("OnColumnsAxesFieldName OR OnRowAxesFieldName""横轴和纵轴不能同时为空");
 70InBlock.gif               
 71ExpandedSubBlockEnd.gif            }

 72InBlock.gif            else
 73ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
 74ContractedSubBlock.gifExpandedSubBlockStart.gif                构建横竖轴#region 构建横竖轴
 75InBlock.gif                string[] cols = (this.OnColumnsAxesFieldName != null && this.OnColumnsAxesFieldName != ""? this.OnColumnsAxesFieldName.Split(','): null;
 76InBlock.gif                string[] rows = (this.OnRowAxesFieldName != null && this.OnRowAxesFieldName != ""? this.OnRowAxesFieldName.Split(',') : null;
 77InBlock.gif                string[] colsvalue =(this.OnColumnsAxesValueFieldName != null && this.OnColumnsAxesValueFieldName != ""? this.OnColumnsAxesValueFieldName.Split(','): null;
 78InBlock.gif                string[] rowsvalue = (this.OnRowAxesValueFieldName != null && this.OnRowAxesValueFieldName != ""? this.OnRowAxesValueFieldName.Split(',') : null;
 79InBlock.gif                if (colsvalue != null && colsvalue.Length != cols.Length)
 80ExpandedSubBlockStart.gifContractedSubBlock.gif                dot.gif{                   
 81InBlock.gif                  throw new ArgumentNullException("OnColumnsAxesFieldName , OnColumnsAxesValueFieldName""轴名称列和轴值列必须一一对应");
 82ExpandedSubBlockEnd.gif                }

 83InBlock.gif                if (rowsvalue != null && rowsvalue.Length != rows.Length)
 84ExpandedSubBlockStart.gifContractedSubBlock.gif                dot.gif{
 85InBlock.gif                    throw new ArgumentNullException("OnRowAxesFieldName , OnRowAxesValueFieldName""轴名称列和轴值列必须一一对应");
 86ExpandedSubBlockEnd.gif                }

 87InBlock.gif
 88InBlock.gif                 // 声明需要用到的变量
 89InBlock.gif                PositionCollection pc;
 90InBlock.gif                Position ps;
 91InBlock.gif                MemberCollection mc;
 92InBlock.gif                Member mb;
 93InBlock.gif                int index ;
 94InBlock.gif                int valueindex =0;
 95InBlock.gif                DataRow[] arrdr;
 96InBlock.gif                string col;
 97InBlock.gif                string row;
 98InBlock.gif                string colvalue;
 99InBlock.gif                string rowvalue;
100InBlock.gif                if (cols != null)  //如果设置了维度列在竖轴上,则构建竖轴
101ExpandedSubBlockStart.gifContractedSubBlock.gif                dot.gif{
102InBlock.gif                    pc = new PositionCollection();
103InBlock.gif                    for (int k = 0; k < cols.Length; k++ )
104ExpandedSubBlockStart.gifContractedSubBlock.gif                    dot.gif{
105InBlock.gif                        col = cols[k];
106InBlock.gif                        if (colsvalue != null)
107ExpandedSubBlockStart.gifContractedSubBlock.gif                        dot.gif{
108InBlock.gif                            colvalue = colsvalue[k];
109InBlock.gif                            valueindex = table.Columns[colvalue].Ordinal;
110ExpandedSubBlockEnd.gif                        }

111InBlock.gif                        index = table.Columns[col].Ordinal;                      
112InBlock.gif                        ps = new Position();
113InBlock.gif                        ps.Name = col;
114InBlock.gif                        mc = new MemberCollection();
115InBlock.gif                        arrdr = table.Select("", col + " asc "); //过滤相同的维度信息做准备
116InBlock.gif                        for (int i = 0; i < arrdr.Length; i++)
117ExpandedSubBlockStart.gifContractedSubBlock.gif                        dot.gif{
118InBlock.gif                            if (arrdr[i][index].ToString() == "$#NULL#$"continue;  // 过滤空的维度值
119InBlock.gif                            if (i == 0 || arrdr[i][index].ToString() != arrdr[i - 1][index].ToString())
120ExpandedSubBlockStart.gifContractedSubBlock.gif                            dot.gif{
121InBlock.gif                                mb = new Member();
122InBlock.gif                                mb.Caption = (arrdr[i][index] != null && arrdr[i][index] != System.DBNull.Value) ? arrdr[i][index].ToString() : "";
123InBlock.gif                                if (colsvalue != null)
124ExpandedSubBlockStart.gifContractedSubBlock.gif                                dot.gif{
125InBlock.gif                                    mb.Value = (arrdr[i][valueindex] != null && arrdr[i][valueindex] != System.DBNull.Value) ? arrdr[i][valueindex].ToString() : "";
126ExpandedSubBlockEnd.gif                                }

127InBlock.gif                                ps.Members.Add(mb);
128ExpandedSubBlockEnd.gif                            }

129ExpandedSubBlockEnd.gif                        }

130InBlock.gif                        if (this.ShowColumnsSum)  //是否在竖轴上显示合计列
131ExpandedSubBlockStart.gifContractedSubBlock.gif                        dot.gif{
132InBlock.gif                            mb = new Member();
133InBlock.gif                            mb.Caption = this.SumText;
134InBlock.gif                            mb.IsSumTotal = true;
135InBlock.gif                            mb.Value = "$SUM$";
136InBlock.gif                            ps.Members.Add(mb);
137ExpandedSubBlockEnd.gif                        }

138InBlock.gif                        this.ColumnsAxes.Add(ps);
139ExpandedSubBlockEnd.gif                    }

140InBlock.gif                    
141InBlock.gif                    
142ExpandedSubBlockEnd.gif                }

143InBlock.gif                if (rows != null) //构建横轴,同上
144ExpandedSubBlockStart.gifContractedSubBlock.gif                dot.gif{
145InBlock.gif
146InBlock.gif                    for (int k = 0; k < rows.Length; k++)
147ExpandedSubBlockStart.gifContractedSubBlock.gif                    dot.gif{
148InBlock.gif                        row = rows[k];
149InBlock.gif                        if (rowsvalue != null)//
150ExpandedSubBlockStart.gifContractedSubBlock.gif                        dot.gif{
151InBlock.gif                            rowvalue = rowsvalue[k];
152InBlock.gif                            valueindex = table.Columns[rowvalue].Ordinal;
153ExpandedSubBlockEnd.gif                        }

154InBlock.gif                        index = table.Columns[row].Ordinal;
155InBlock.gif                        
156InBlock.gif                        ps = new Position();
157InBlock.gif                        ps.Name = row;
158InBlock.gif                        mc = new MemberCollection();
159InBlock.gif                        arrdr = table.Select("", row+" asc ");
160InBlock.gif                        for (int i = 0; i < arrdr.Length ; i++)
161ExpandedSubBlockStart.gifContractedSubBlock.gif                        dot.gif{
162InBlock.gif                            if (arrdr[i][index].ToString() == "$#NULL#$"continue;
163InBlock.gif
164InBlock.gif                            if (i == 0 || arrdr[i][index].ToString() != arrdr[i - 1][index].ToString())
165ExpandedSubBlockStart.gifContractedSubBlock.gif                            dot.gif{
166InBlock.gif                                mb = new Member();
167InBlock.gif                                mb.Caption = (arrdr[i][index] != null && arrdr[i][index] != System.DBNull.Value) ? arrdr[i][index].ToString() : "";
168InBlock.gif                                if (rowsvalue != null)
169ExpandedSubBlockStart.gifContractedSubBlock.gif                                dot.gif{
170InBlock.gif                                    mb.Value = (arrdr[i][valueindex] != null && arrdr[i][valueindex] != System.DBNull.Value) ? arrdr[i][valueindex].ToString() : "";
171ExpandedSubBlockEnd.gif                                }

172InBlock.gif                                ps.Members.Add(mb);
173ExpandedSubBlockEnd.gif                            }

174ExpandedSubBlockEnd.gif                        }

175InBlock.gif                        if (this.ShowRowsSum)
176ExpandedSubBlockStart.gifContractedSubBlock.gif                        dot.gif{
177InBlock.gif                            mb = new Member();
178InBlock.gif                            mb.Caption = this.SumText;
179InBlock.gif                            mb.IsSumTotal = true;
180InBlock.gif                            mb.Value = "$SUM$";
181InBlock.gif                            ps.Members.Add(mb);
182ExpandedSubBlockEnd.gif                        }

183InBlock.gif                        this.RowAxes.Add(ps);
184ExpandedSubBlockEnd.gif                    }

185InBlock.gif                   
186ExpandedSubBlockEnd.gif                }

187ExpandedSubBlockEnd.gif                #endregion

188InBlock.gif
189ContractedSubBlock.gifExpandedSubBlockStart.gif                获取数据#region 获取数据
190InBlock.gif                //开始获取数据拉
191InBlock.gif                int totalcols = 1;
192InBlock.gif                foreach (Position cps in this.ColumnsAxes)
193ExpandedSubBlockStart.gifContractedSubBlock.gif                dot.gif{
194InBlock.gif                    totalcols *= cps.Members.Count;
195ExpandedSubBlockEnd.gif                }

196InBlock.gif                this.dataCells.BreakIndex = totalcols ;
197InBlock.gif                int totalrows = 1;
198InBlock.gif                foreach (Position rps in this.RowAxes)
199ExpandedSubBlockStart.gifContractedSubBlock.gif                dot.gif{
200InBlock.gif                    totalrows *= rps.Members.Count;
201ExpandedSubBlockEnd.gif                }

202InBlock.gif
203InBlock.gif                int colscount = this.ColumnsAxes.Count;
204InBlock.gif                int rowscount = this.RowAxes.Count;
205InBlock.gif                string codition = "";
206InBlock.gif                string fun = "";
207InBlock.gif               
208InBlock.gif                int rowmindex = 0 ;
209InBlock.gif                int colmindex = 0;               
210InBlock.gif                Cell cell;
211InBlock.gif                forint i =0 ;i<totalrows ; i++)
212ExpandedSubBlockStart.gifContractedSubBlock.gif                dot.gif{
213InBlock.gif                    for (int j = 0; j < totalcols; j++)
214ExpandedSubBlockStart.gifContractedSubBlock.gif                    dot.gif{
215InBlock.gif                        codition = "";
216InBlock.gif                        fun = this._cellclientfunction;
217InBlock.gif                        for (int m = rowscount - 1; m >= 0; m--)
218ExpandedSubBlockStart.gifContractedSubBlock.gif                        dot.gif{
219InBlock.gif                            
220InBlock.gif                            rowmindex = RowMemberIndex(m, i);
221InBlock.gif                            if (!this.RowAxes[m].Members[rowmindex].IsSumTotal)
222ExpandedSubBlockStart.gifContractedSubBlock.gif                            dot.gif{
223InBlock.gif                                if (codition != "") codition += " and ";
224InBlock.gif                                codition += this.RowAxes[m].Name + "='" + this.RowAxes[m].Members[rowmindex].Caption + "'";
225ExpandedSubBlockEnd.gif                            }

226InBlock.gif                            if (fun != "")
227ExpandedSubBlockStart.gifContractedSubBlock.gif                            dot.gif{
228InBlock.gif                                fun = fun.Replace("{" + this.RowAxes[m].Name + "}""'"+this.RowAxes[m].Members[rowmindex].Value.Replace("'","")+"'");
229ExpandedSubBlockEnd.gif                            }

230ExpandedSubBlockEnd.gif                        }

231InBlock.gif                        for (int n = colscount - 1; n >= 0; n--)
232ExpandedSubBlockStart.gifContractedSubBlock.gif                        dot.gif{                            
233InBlock.gif                            colmindex = ColMemberIndex(n, j);
234InBlock.gif                            if (!this.ColumnsAxes[n].Members[colmindex].IsSumTotal)
235ExpandedSubBlockStart.gifContractedSubBlock.gif                            dot.gif{
236InBlock.gif                                if (codition != "") codition += " and ";
237InBlock.gif                                codition += this.ColumnsAxes[n].Name + "='" + this.ColumnsAxes[n].Members[colmindex].Caption + "'";
238ExpandedSubBlockEnd.gif                            }

239InBlock.gif                            if (fun != "")
240ExpandedSubBlockStart.gifContractedSubBlock.gif                            dot.gif{
241InBlock.gif                                fun = fun.Replace("{" + this.ColumnsAxes[n].Name + "}""'" + this.ColumnsAxes[n].Members[colmindex].Value.Replace("'"""+ "'");
242ExpandedSubBlockEnd.gif                            }

243ExpandedSubBlockEnd.gif                        }

244InBlock.gif                        object o =table.Compute("sum(" + this.MeasureFieldName + ")", codition);
245InBlock.gif                        cell = new Cell();
246InBlock.gif                        if (this._cellclientfunction != null && this._cellclientfunction != "")
247InBlock.gif                            cell.ClientClickFunction = fun;
248InBlock.gif
249InBlock.gif                        if (_formartstring != null && _formartstring != "")
250InBlock.gif                            cell.FormatString = _formartstring;
251InBlock.gif
252InBlock.gif                        cell.Value = Convert.ToDecimal(o!=null &&  o !=System.DBNull.Value ?o:0);
253InBlock.gif                        this.dataCells.Add(cell);
254InBlock.gif                        fun = "";
255ExpandedSubBlockEnd.gif                    }

256ExpandedSubBlockEnd.gif                }

257ExpandedSubBlockEnd.gif                #endregion

258ExpandedSubBlockEnd.gif            }

259ExpandedSubBlockEnd.gif        }

260ExpandedBlockEnd.gif        #endregion
  

绘制表格的部分
ContractedBlock.gif ExpandedBlockStart.gif          绘制表格 #region 绘制表格
InBlock.gif        
protected override void RenderContents(System.Web.UI.HtmlTextWriter output)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
InBlock.gif            
//base.RenderContents(writer);
InBlock.gif
            if (this.dataCells == null || this.dataCells.Count == 0return;
InBlock.gif
InBlock.gif            
int totalcols = 1;
InBlock.gif            
foreach (Position ps in this.ColumnsAxes)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                totalcols 
*= ps.Members.Count;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
int totalrows = 1;
InBlock.gif            
foreach (Position ps in this.RowAxes)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                totalrows 
*= ps.Members.Count;
ExpandedSubBlockEnd.gif            }

InBlock.gif           
InBlock.gif            
//开始绘制表格
InBlock.gif
            output.AddAttribute("ID"this.UniqueID);
InBlock.gif            
//output.AddAttribute("border", "0");
InBlock.gif
            output.AddAttribute("CellSpacing"this._cellspacing.ToString());
InBlock.gif            output.AddAttribute(
"CellPadding"this._cellpadding.ToString());
InBlock.gif            output.AddAttribute(
"Width"this._width.ToString());
InBlock.gif            output.AddAttribute(
"Height"this._height.ToString());
InBlock.gif            output.AddAttribute(HtmlTextWriterAttribute.Class, 
this.CssClass);
InBlock.gif            output.RenderBeginTag(HtmlTextWriterTag.Table);
InBlock.gif
InBlock.gif            
//绘制第一个行
InBlock.gif
            output.RenderBeginTag(HtmlTextWriterTag.Tr);
InBlock.gif
InBlock.gif            
//绘制第一个单元格   
InBlock.gif
            if (this.RowAxes.Count != 0 && this.ColumnsAxes.Count != 0)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                output.AddAttribute(
"Align""center");
InBlock.gif                output.AddAttribute(
"ColSpan"this.RowAxes.Count.ToString());
InBlock.gif                output.AddAttribute(
"RowSpan"this.ColumnsAxes.Count.ToString());
InBlock.gif                
if (this.CrossHeadClass != null && this.CrossHeadClass!="")
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    output.AddAttribute(HtmlTextWriterAttribute.Class, 
this.CrossHeadClass);
ExpandedSubBlockEnd.gif                }

InBlock.gif                
if (!this.CrossHeadBgColor.IsEmpty)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                   output.AddStyleAttribute(HtmlTextWriterStyle.BackgroundColor, ColorTranslator.ToHtml(
this.CrossHeadBgColor));
ExpandedSubBlockEnd.gif                }

InBlock.gif                
this.RenderStyle(TDClass.TdLTBR, output); //表格样式
InBlock.gif
                output.RenderBeginTag(HtmlTextWriterTag.Td);
InBlock.gif                output.Write(
"&nbsp;");
InBlock.gif                output.RenderEndTag();
ExpandedSubBlockEnd.gif            }

InBlock.gif
InBlock.gif            
int colscount;
InBlock.gif            
//绘制表头
InBlock.gif
            for (int i = 0; i < this.ColumnsAxes.Count; i++)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
if (i > 0)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    output.RenderBeginTag(HtmlTextWriterTag.Tr);
ExpandedSubBlockEnd.gif                }

InBlock.gif
InBlock.gif                colscount 
= ColMemberCount(i);
InBlock.gif                
for (int m = 0; m < colscount; m++)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    
for (int j = 0; j < this.ColumnsAxes[i].Members.Count; j++)
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
dot.gif{
InBlock.gif
InBlock.gif                        
if (i == 0)
ExpandedSubBlockStart.gifContractedSubBlock.gif                        
dot.gif
InBlock.gif                            
if(this.RowAxes.Count ==0 && j==0 )
InBlock.gif                                
this.RenderStyle(TDClass.TdLTBR, output);
InBlock.gif                            
else
InBlock.gif                                
this.RenderStyle(TDClass.TdTBR, output);
ExpandedSubBlockEnd.gif                        }

InBlock.gif                        
else
ExpandedSubBlockStart.gifContractedSubBlock.gif                        
dot.gif{
InBlock.gif                            
if (this.RowAxes.Count == 0 && j == 0 && m==0)
InBlock.gif                                
this.RenderStyle(TDClass.TdLBR, output);
InBlock.gif                            
else
InBlock.gif                                
this.RenderStyle(TDClass.TdBR, output);
ExpandedSubBlockEnd.gif                        }

InBlock.gif                        output.AddAttribute(
"Align""center");
InBlock.gif                        
if (this.AxisClass != null && this.AxisClass != "")
ExpandedSubBlockStart.gifContractedSubBlock.gif                        
dot.gif{
InBlock.gif                            output.AddAttribute(HtmlTextWriterAttribute.Class, 
this.AxisClass);
ExpandedSubBlockEnd.gif                        }

InBlock.gif                        
if (!this.AxisColor.IsEmpty)
ExpandedSubBlockStart.gifContractedSubBlock.gif                        
dot.gif{
InBlock.gif                            output.AddStyleAttribute(HtmlTextWriterStyle.BackgroundColor, ColorTranslator.ToHtml(
this.AxisColor));
ExpandedSubBlockEnd.gif                        }

InBlock.gif                        
if (!this.AxisTextColor.IsEmpty)
ExpandedSubBlockStart.gifContractedSubBlock.gif                        
dot.gif{
InBlock.gif                            output.AddStyleAttribute(
"Color", ColorTranslator.ToHtml(this.AxisTextColor));
ExpandedSubBlockEnd.gif                        }

InBlock.gif
InBlock.gif                        output.AddAttribute(
"ColSpan", ColPostionClildCount(i).ToString());                       
InBlock.gif                        output.RenderBeginTag(HtmlTextWriterTag.Td);                     
InBlock.gif                       
InBlock.gif                        
if (this.ColumnsAxes[i].Members[j].Caption != null && this.ColumnsAxes[i].Members[j].Caption !="")
InBlock.gif                            output.Write(
this.ColumnsAxes[i].Members[j].Caption);
InBlock.gif                        
else
InBlock.gif                            output.Write(
"&nbsp;");                       
InBlock.gif
InBlock.gif                        output.RenderEndTag();
ExpandedSubBlockEnd.gif                    }

ExpandedSubBlockEnd.gif                }

InBlock.gif                output.RenderEndTag();  
ExpandedSubBlockEnd.gif            }

InBlock.gif            
//表头绘制完毕 
InBlock.gif
            for (int i = 0; i < totalrows; i++)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                output.RenderBeginTag(HtmlTextWriterTag.Tr);
InBlock.gif                
//绘制竖轴
InBlock.gif
                for (int j = 0; j < this.RowAxes.Count; j++)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    
if (this.IsRenderTD(j, i))
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
dot.gif{
InBlock.gif                        
if (j == 0)
ExpandedSubBlockStart.gifContractedSubBlock.gif                        
dot.gif
InBlock.gif                             
if(this.ColumnsAxes.Count ==0 && i==0)
InBlock.gif                                
this.RenderStyle(TDClass.TdLTBR, output);
InBlock.gif                              
else
InBlock.gif                                
this.RenderStyle(TDClass.TdLBR, output);
ExpandedSubBlockEnd.gif                        }

InBlock.gif                        
else
ExpandedSubBlockStart.gifContractedSubBlock.gif                        
dot.gif{
InBlock.gif                            
if (this.ColumnsAxes.Count == 0 && i == 0)
InBlock.gif                                
this.RenderStyle(TDClass.TdTBR, output);
InBlock.gif                            
else
InBlock.gif                                 
this.RenderStyle(TDClass.TdBR, output);
ExpandedSubBlockEnd.gif                        }

InBlock.gif                        output.AddAttribute(
"Align""center");
InBlock.gif                        
if (this.AxisClass != null && this.AxisClass != "")
ExpandedSubBlockStart.gifContractedSubBlock.gif                        
dot.gif{
InBlock.gif                            output.AddAttribute(HtmlTextWriterAttribute.Class, 
this.AxisClass);
ExpandedSubBlockEnd.gif                        }

InBlock.gif                        
if (!this.AxisColor.IsEmpty)
ExpandedSubBlockStart.gifContractedSubBlock.gif                        
dot.gif{
InBlock.gif                            output.AddStyleAttribute(HtmlTextWriterStyle.BackgroundColor, ColorTranslator.ToHtml(
this.AxisColor));
ExpandedSubBlockEnd.gif                        }

InBlock.gif                        
if (!this.AxisTextColor.IsEmpty)
ExpandedSubBlockStart.gifContractedSubBlock.gif                        
dot.gif{
InBlock.gif                            output.AddStyleAttribute(
"Color", ColorTranslator.ToHtml(this.AxisTextColor));
ExpandedSubBlockEnd.gif                        }

InBlock.gif                        output.AddAttribute(
"Rowspan", RowPostionClildCount(j).ToString());
InBlock.gif                        output.RenderBeginTag(HtmlTextWriterTag.Td);
InBlock.gif
InBlock.gif                      
InBlock.gif                        
int m = RowMemberIndex(j, i);
InBlock.gif                      
InBlock.gif                        
if (this.RowAxes[j].Members[m].Caption != null && this.RowAxes[j].Members[m].Caption !="")
InBlock.gif                            output.Write(
this.RowAxes[j].Members[m].Caption);
InBlock.gif                        
else
InBlock.gif                            output.Write(
"&nbsp;");
InBlock.gif                       
InBlock.gif                        output.RenderEndTag();
ExpandedSubBlockEnd.gif                    }

ExpandedSubBlockEnd.gif                }

InBlock.gif                
// 绘制数据单元格
InBlock.gif
                for (int j = 0; j < totalcols; j++)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    
if (i == 0 && j==0 && this.ColumnsAxes.Count ==0)
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
dot.gif{
InBlock.gif                        
this.RenderStyle(TDClass.TdTBR, output);
ExpandedSubBlockEnd.gif                    }

InBlock.gif                    
else if (i == 0 && j == 0 && this.RowAxes.Count == 0)
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
dot.gif{
InBlock.gif                        
this.RenderStyle(TDClass.TdLBR, output);
ExpandedSubBlockEnd.gif                    }

InBlock.gif                    
else
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
dot.gif{
InBlock.gif                        
this.RenderStyle(TDClass.TdBR, output);
ExpandedSubBlockEnd.gif                    }
                  
InBlock.gif                    
if (this._cellclientfunction != null && this._cellclientfunction != "")
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
dot.gif{
InBlock.gif                        output.AddStyleAttribute(HtmlTextWriterStyle.Cursor, 
"pointer");
InBlock.gif                        output.AddAttribute(HtmlTextWriterAttribute.Onclick, dataCells[i, j].ClientClickFunction);
ExpandedSubBlockEnd.gif                    }

InBlock.gif                    
if (this.CellCssClass !=null && this.CellCssClass !="")
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
dot.gif{
InBlock.gif                        output.AddAttribute(HtmlTextWriterAttribute.Class, 
this.CellCssClass);
ExpandedSubBlockEnd.gif                    }

InBlock.gif
InBlock.gif                    
if (!this.CellBgColor.IsEmpty)
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
dot.gif{
InBlock.gif                        output.AddStyleAttribute(HtmlTextWriterStyle.BackgroundColor, ColorTranslator.ToHtml(
this.CellBgColor));
ExpandedSubBlockEnd.gif                    }

InBlock.gif                    
if (!this.CellTextColor.IsEmpty)
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
dot.gif{
InBlock.gif                        output.AddStyleAttribute(HtmlTextWriterStyle.Color, ColorTranslator.ToHtml(
this.CellTextColor));
ExpandedSubBlockEnd.gif                    }

InBlock.gif                    
if (!this.CellHeight.IsEmpty)
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
dot.gif{
InBlock.gif                        output.AddAttribute(HtmlTextWriterAttribute.Height, 
this.CellHeight.ToString());
ExpandedSubBlockEnd.gif                    }

InBlock.gif                    
if (!this.CellWidth.IsEmpty)
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
dot.gif{
InBlock.gif                        output.AddAttribute(HtmlTextWriterAttribute.Width, 
this.CellWidth.ToString());
ExpandedSubBlockEnd.gif                    }

InBlock.gif                    output.RenderBeginTag(HtmlTextWriterTag.Td);
InBlock.gif                    output.Write(dataCells[i, j].Text);
InBlock.gif                    output.RenderEndTag();
ExpandedSubBlockEnd.gif                }

InBlock.gif                output.RenderEndTag();
ExpandedSubBlockEnd.gif            }

InBlock.gif            output.RenderEndTag();
ExpandedSubBlockEnd.gif        }

ExpandedBlockEnd.gif        
#endregion


其他一些辅助函数
ContractedBlock.gif ExpandedBlockStart.gif    私有辅助函数 #region 私有辅助函数
InBlock.gif        
private int RowMemberIndex(int pindex, int cindex)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
int total = 1;
InBlock.gif
InBlock.gif            
for (int i = pindex + 1; i < this.RowAxes.Count; i++)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                total 
*= this.RowAxes[i].Members.Count;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
int mcount = this.RowAxes[pindex].Members.Count;
InBlock.gif            
return ((int)(cindex / total)) % (mcount);
InBlock.gif
InBlock.gif            
//int m = this.RowAxes[pindex].Members.Count;
InBlock.gif            
//return (cindex % m);
ExpandedSubBlockEnd.gif
        }

InBlock.gif        
private int ColMemberIndex(int pindex, int cindex)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
int total = 1;
InBlock.gif
InBlock.gif            
for (int i = pindex + 1; i < this.ColumnsAxes.Count; i++)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                total 
*= this.ColumnsAxes[i].Members.Count;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
int mcount = this.ColumnsAxes[pindex].Members.Count;
InBlock.gif
InBlock.gif            
return ((int)(cindex / total)) % (mcount);
InBlock.gif            
//int m = this.ColumnsAxes[pindex].Members.Count;
InBlock.gif            
//return (cindex % m);
ExpandedSubBlockEnd.gif
        }

InBlock.gif        
private int RowPostionClildCount(int pindex)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
int total = 1;          
InBlock.gif            
for (int i = pindex+1; i < this.RowAxes.Count; i++)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                total 
*= this.RowAxes[i].Members.Count;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
return total;
ExpandedSubBlockEnd.gif        }

InBlock.gif        
private int ColPostionClildCount(int pindex)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
int total = 1;           
InBlock.gif            
for (int i = pindex+1; i < this.ColumnsAxes.Count; i++)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                total 
*= this.ColumnsAxes[i].Members.Count;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
return total;
ExpandedSubBlockEnd.gif        }

InBlock.gif        
private int ColMemberCount(int pindex)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
int total = 1;
InBlock.gif            
for (int i =0; i < pindex; i++)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                total 
*= this.ColumnsAxes[i].Members.Count;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
return total;
ExpandedSubBlockEnd.gif        }

InBlock.gif        
private bool IsRenderTD(int pindex,int cindex)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
int total = 1;
InBlock.gif           
InBlock.gif            
for (int i = pindex+1; i < this.RowAxes.Count; i++)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                total 
*= this.RowAxes[i].Members.Count;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
return (cindex % total) == 0;
ExpandedSubBlockEnd.gif        }

ExpandedBlockEnd.gif        
#endregion

None.gif
ContractedBlock.gifExpandedBlockStart.gif        
添加单元格边框样式 #region 添加单元格边框样式
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 添加单元格边框样式
InBlock.gif        
/// </summary>
InBlock.gif        
/// <param name="tdc"></param>
ExpandedSubBlockEnd.gif        
/// <param name="output"></param>

InBlock.gif        protected virtual void RenderStyle(TDClass tdc, HtmlTextWriter output)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
int tdclasscode = (int)tdc;
InBlock.gif
InBlock.gif            
if ((tdclasscode & 1!= 0//
ExpandedSubBlockStart.gifContractedSubBlock.gif
            dot.gif{
InBlock.gif                output.AddStyleAttribute(
"border-top""" + ColorTranslator.ToHtml(this._bordercolor) + " " + this._borderwidth.ToString() + " solid");
ExpandedSubBlockEnd.gif            }

InBlock.gif            
else
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                output.AddStyleAttribute(
"border-top""" + ColorTranslator.ToHtml(this._bordercolor) + " 0px solid");
ExpandedSubBlockEnd.gif            }

InBlock.gif            
if ((tdclasscode & 2!= 0)//
ExpandedSubBlockStart.gifContractedSubBlock.gif
            dot.gif{
InBlock.gif                output.AddStyleAttribute(
"border-bottom""" + ColorTranslator.ToHtml(this._bordercolor) + " " + this._borderwidth.ToString() + " solid");
ExpandedSubBlockEnd.gif            }

InBlock.gif            
else
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                output.AddStyleAttribute(
"border-bottom""" + ColorTranslator.ToHtml(this._bordercolor) + " 0px solid");
ExpandedSubBlockEnd.gif            }

InBlock.gif            
if ((tdclasscode & 4!= 0)//
ExpandedSubBlockStart.gifContractedSubBlock.gif
            dot.gif{
InBlock.gif                output.AddStyleAttribute(
"border-left""" + ColorTranslator.ToHtml(this._bordercolor) + " " + this._borderwidth.ToString() + " solid");
ExpandedSubBlockEnd.gif            }

InBlock.gif            
else
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                output.AddStyleAttribute(
"border-left""" + ColorTranslator.ToHtml(this._bordercolor) + " 0px solid");
ExpandedSubBlockEnd.gif            }

InBlock.gif            
if ((tdclasscode & 8!= 0)//
ExpandedSubBlockStart.gifContractedSubBlock.gif
            dot.gif{
InBlock.gif                output.AddStyleAttribute(
"border-right""" + ColorTranslator.ToHtml(this._bordercolor) + " " + this._borderwidth.ToString() + " solid");
ExpandedSubBlockEnd.gif            }

InBlock.gif            
else
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                output.AddStyleAttribute(
"border-right""" + ColorTranslator.ToHtml(this._bordercolor) + " 0px solid");
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

ExpandedBlockEnd.gif        
#endregion

ExpandedBlockStart.gif ContractedBlock.gif   /**/ /// <summary>
InBlock.gif    
/// TD单元格的边框样式
InBlock.gif    
/// </summary>
ExpandedBlockEnd.gif    
/// 1111分别代表,右左下上

None.gif      public   enum  TDClass
ExpandedBlockStart.gifContractedBlock.gif    
dot.gif {
InBlock.gif        TdLTBR 
= 15,  //1111
InBlock.gif
        TdTBR = 11,  //1011
InBlock.gif
        TdLBR = 14,   //1110
InBlock.gif
        TdBR = 10,    //1010
ExpandedBlockEnd.gif
    }

  代码下载
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值