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#region property
private float _sum = 0;
public float Sum
...{
get...{return _sum;}
set...{_sum=value;}
}
private int _level = 1;
/**//// <summary>
/// from 1 to end
/// </summary>
public int Level
...{
get...{return _level;}
set...{_level=value;}
}
private int _levelCount = 1;
/**//// <summary>
/// level number, including itself
/// </summary>
public int LevelCount
...{
get...{return _levelCount;}
set...{_levelCount=value;}
}
private int _rowSpan = 0;
public int RowSpan
...{
get...{return _rowSpan;}
set...{_rowSpan=value;}
}
private int _colSpan = 1;
public int ColSpan
...{
get...{return _colSpan;}
set...{_colSpan=value;}
}
private bool _isLastList = false;
public bool IsLastList
...{
get...{return _isLastList;}
set...{_isLastList=value;}
}
private NestedList _parent = null;
public NestedList Parent
...{
get...{return _parent;}
set...{_parent=value;}
}
#endregion
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;
}
}
}
... {
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#region property
private float _sum = 0;
public float Sum
...{
get...{return _sum;}
set...{_sum=value;}
}
private int _level = 1;
/**//// <summary>
/// from 1 to end
/// </summary>
public int Level
...{
get...{return _level;}
set...{_level=value;}
}
private int _levelCount = 1;
/**//// <summary>
/// level number, including itself
/// </summary>
public int LevelCount
...{
get...{return _levelCount;}
set...{_levelCount=value;}
}
private int _rowSpan = 0;
public int RowSpan
...{
get...{return _rowSpan;}
set...{_rowSpan=value;}
}
private int _colSpan = 1;
public int ColSpan
...{
get...{return _colSpan;}
set...{_colSpan=value;}
}
private bool _isLastList = false;
public bool IsLastList
...{
get...{return _isLastList;}
set...{_isLastList=value;}
}
private NestedList _parent = null;
public NestedList Parent
...{
get...{return _parent;}
set...{_parent=value;}
}
#endregion
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;
}
}
}