遍历输出嵌套报表

public   class  OTTimeReportListBuilder
    
{
        ReportArg _reportArg 
= null;
        
        
public OTTimeReportListBuilder(ReportArg reportArg)
        
{
            _reportArg 
= reportArg;
            Query();
        }


        
private void Query()
        
{
            Planing.OTTimeReport report 
= new Achievo.PMS.Planing.OTTimeReport();
            
this._items = report.GetItems(this._reportArg);
        }


        
/// <summary>
        
/// user name(lower case)/user id
        
/// </summary>
        
/// <param name="filterList"></param>

        public void Filter(SortedList listForFilter)
        
{
            ArrayList filteredList 
= new ArrayList();
            
if(this._items!=null)
            
{
                
foreach(Planing.OTTimeReportItem tempItem in this._items)
                
{
                    
string key = tempItem.EngineerName.ToLower();
                    
if(listForFilter.Contains(key))
                        filteredList.Add(tempItem);
                }

                
this._items = (Planing.OTTimeReportItem[])filteredList.ToArray(typeof(Planing.OTTimeReportItem));
                
if(this._items.Length==0)
                    
this._items=null;
            }

        }


        
public bool HasRecords
        
{
            
get{return (this._items!=null && this._items.Length>0);}
        }


        Planing.OTTimeReportItem[] _items 
= null;
        
public Planing.OTTimeReportItem[] GetDetailItems()
        
{
            
return _items;
        }


        
public string GetMonthLyReportString()
        
{
            
if(this._items==null || this._items.Length==0)
                
return "";
            
//
            StringBuilder resultBuilder = new StringBuilder();
            NestedList linkList 
= new NestedList();
            
foreach(Planing.OTTimeReportItem tempItem in this._items)
            
{
                
string[] names = new string[]{tempItem.ProductName
                                                 ,tempItem.ProjectName
                                                 ,tempItem.WeekEnd.ToString(
"MM/dd/yyyy")
                                                 ,tempItem.EngineerName
                                                 }
;
                linkList.AddOrUpdate(names ,tempItem.OTHours);
            }

            
string htmlString = linkList.ToHTMLString();
            
return htmlString;
        }


        
class NestedList : SortedList
        
{
            
property

            
public bool AddOrUpdate(string[] keys ,float value)
            
{
                
if(keys==null || keys.Length==0)
                    
return false;
                NestedList actionList 
= this;
                
for(int i=0;i<keys.Length;i++)
                
{
                    actionList.Sum 
+= value;
                    actionList.Level  
= i+1;
                    actionList.LevelCount  
= keys.Length-i;
                    actionList.ColSpan 
= keys.Length-i+1;
                    actionList.IsLastList 
= (i==(keys.Length-1));
                    
string key = keys[i];
                    
if(actionList.Contains(key))
                    
{
                        
if(actionList[key] is NestedList)
                            actionList 
= (NestedList)actionList[key];
                        
else
                            actionList[key] 
= float.Parse(actionList[key].ToString()) + value;
                    }

                    
else
                    
{
                        NestedList addingList 
= new NestedList();
                        
if(actionList.IsLastList)
                            actionList.Add(key ,value);
                        
else
                            actionList.Add(key ,addingList);
                        addingList.Parent 
= actionList;
                        actionList 
= addingList;
                        UpdateStatistics(addingList);
                    }

                }

                
return true;
            }


            
private void UpdateStatistics(NestedList actionList)
            
{
                NestedList parent 
= actionList.Parent;
                
while(parent!=null)
                
{
                    parent.RowSpan
++;
                    parent 
= parent.Parent;
                }

            }


            
public string ToHTMLString()
            
{
                StringBuilder htmlBuilder 
= new StringBuilder();
                
bool isFirstNode = true;
                
for(int i=0;i<this.Keys.Count;i++)
                
{
                    isFirstNode 
= (i==0);
                    
string key = this.GetKey(i).ToString();
                    NestedList tempList 
= this[key] as NestedList;
                    
if(tempList==null)
                    
{
                        
float tempValue = float.Parse(this[key].ToString());
                        
if(isFirstNode)
                            htmlBuilder.Append(
string.Format("<td>{0}</td><td>{1}</td></tr> " ,key ,tempValue));
                        
else
                            htmlBuilder.Append(
string.Format("<tr class="DataGridItemStyleForList"><td>{0}</td><td>{1}</td></tr> " ,key ,tempValue));
                    }

                    
else
                    
{
                        
string showName = key.Trim()=="" ? "(No Name)" : key;
                        
string rowLeftPart = ((!isFirstNode || this.Level==1)) ? "<tr class="DataGridItemStyleForList">" : "";
                        
string rowMiddlePart = string.Format(@"<td rowSpan=""{0}"">{1}</td>" ,tempList.RowSpan ,showName);
                        
string rowRightPart = tempList.ToHTMLString();
                        
string rowTemplate = @"<tr class=""DataGridItemStyleForList""><td colSpan=""{0}"">{1} {2}</td><td>{3}</td></tr>" + " ";
                        
string rowTotal = string.Format(rowTemplate ,tempList.ColSpan ,showName ,Global.UserLan.GetItem("OTTimeReport_searchCondition_list_header_SubTotal") ,tempList.Sum);
                        htmlBuilder.Append(rowLeftPart 
+ rowMiddlePart + rowRightPart + rowTotal);
                    }

                }

                
if(this.Level==1 && this.Keys.Count>1)
                
{
                    
string rowTemplate = @"<tr class=""DataGridItemStyleForList""><td colSpan=""{0}"">{1}</td><td>{2}</td></tr>" + " ";
                    
string rowTotal = string.Format(rowTemplate ,this.ColSpan-1 ,Global.UserLan.GetItem("OTTimeReport_searchCondition_list_header_Total") ,this.Sum);
                    htmlBuilder.Append(rowTotal);
                }

                
string returnString = htmlBuilder.ToString();
                
return returnString;
            }

        }

    }
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值