统计表

统计表基类:

 

代码
/// <summary>
/// 统计表基类
/// </summary>
public abstract class StatsBase
{
/// <summary>
/// 统计参数
/// </summary>
public StatsParams Params
{
get;
set;
}

/// <summary>
/// 工作台
/// </summary>
public Table Worktable
{
get;
set;
}

/// <summary>
/// 统计表标题
/// </summary>
public string Caption
{
get;
set;
}

/// <summary>
/// 统计表基类构造函数
/// </summary>
/// <param name="table"></param>
/// <param name="param"></param>
public StatsBase(Table table, StatsParams param)
{
this.Params = param;
this.Worktable = table;
}

/// <summary>
/// 构建报表
/// </summary>
public virtual void BuildTable()
{
CreateData();
CreateHeader();
CreateContent();
}

/// <summary>
/// 获得数据
/// </summary>
protected abstract void CreateData();

/// <summary>
/// 创建表头 -必须实现此方法
/// </summary>
protected abstract void CreateHeader();

/// <summary>
/// 创建内容 -必须实现此方法
/// </summary>
protected abstract void CreateContent();

/// <summary>
/// 创建链接
/// </summary>
/// <param name="fieldName"></param>
/// <param name="id"></param>
/// <param name="count"></param>
/// <param name="condition"></param>
/// <returns></returns>
protected virtual string GetUrlString(string fieldName, string id, string count, string condition)
{
return string.Format("<A href=\"StatisticsDetailEnterpriseList.aspx?parm={0}\" target='_blank'>{1}</A>",
System.Web.HttpContext.Current.Server.UrlEncode(fieldName
+ "=" + id + " AND " + condition), count);
}

 

企业类型统计表

 

代码
/// <summary>
/// 具体页面的链接
/// </summary>
private const string NumberLink = "<a href=\"Statistic-SampleShowDetailList.aspx?StaType={0}&EntType={1}&drugCategory={2}&condition={3}\" target=\"_blank\">{4}</a>";

/// <summary>
/// 基于企业类型的统计表的构造函数
/// </summary>
/// <param name="table"></param>
/// <param name="param"></param>
public StatsByEntType(Table table, StatsParams param) : base(table,param)
{
this.Caption = "药品抽验情况统计表<br/>(监督抽验)";
}

/// <summary>
/// 统计列表企业类型和药品分类数据
/// </summary>
protected override void CreateData()
{

}

/// <summary>
/// 表头
/// </summary>
protected override void CreateHeader()
{
TableRow row
= new TableRow();
TableCell cell
= new TableCell();
cell.ColumnSpan
= 3;
cell.Text
= "抽验渠道";
SetHeaderCellStyle(cell);
row.Cells.Add(cell);

KeyInfo info;
for (int j = 0; j < this.Params.DrugCategoryList.Count; j++)
{
info
= this.Params.DrugCategoryList[j] as KeyInfo;
cell
= new TableCell();
SetHeaderCellStyle(cell);
cell.Text
= info.Text;
row.Cells.Add(cell);
}

cell
= new TableCell();
SetHeaderCellStyle(cell);
cell.Text
= "合计";
row.Cells.Add(cell);

this.Worktable.Rows.Add(row);
}

/// <summary>
/// 内容
/// </summary>
protected override void CreateContent()
{
SampleCheckStats bll
= new SampleCheckStats();
TableRow row1, row2, row4, row5, row7, row8, row3, row6,row9;
TableCell cell;
KeyInfo info, key;
LeechdomTestStatisticInfo staInfo;

int enterpriseTotal, enterpriseTotalForDisqualify, leechdomCategoryTotal, leechdomCategoryTotalForDisqualify, batchNumTotal, batchNumTotalForDisqualify;

for (int i = 0; i <this.Params.EntTypeList.Count; i++)
{
//左边第一列:企业类别行
info = this.Params.EntTypeList[i] as KeyInfo;
row1
= new TableRow();
cell
= new TableCell();
cell.Text
= info.Text;
SetLeftCellStyle(cell);
cell.RowSpan
= 9;
row1.Cells.Add(cell);

//------------------------
//左边第二列
cell = new TableCell();
cell.Text
= "单位数";
SetLeftCellStyle(cell);
cell.RowSpan
= 3;
row1.Cells.Add(cell);

row4
= new TableRow();
cell
= new TableCell();
cell.Text
= "品种数";
SetLeftCellStyle(cell);
cell.RowSpan
= 3;
row4.Cells.Add(cell);

row7
= new TableRow();
cell
= new TableCell();
cell.Text
= "批数";
SetLeftCellStyle(cell);
cell.RowSpan
= 3;
row7.Cells.Add(cell);
//-------------------------
//左边第三列:具体统计项目列
cell = new TableCell();
SetLeftItemCellStyle(cell);
cell.Text
= "总数";
row1.Cells.Add(cell);

row2
= new TableRow();
cell
= new TableCell();
SetLeftItemCellStyle(cell);
cell.Text
= "不合格数";
row2.Cells.Add(cell);

row3
= new TableRow();
cell
= new TableCell();
SetLeftItemCellStyle(cell);
cell.Text
= "不合格率";
row3.Cells.Add(cell);


cell
= new TableCell();
SetLeftItemCellStyle(cell);
cell.Text
= "抽验总数";
row4.Cells.Add(cell);

row5
= new TableRow();
cell
= new TableCell();
SetLeftItemCellStyle(cell);
cell.Text
= "不合格数";
row5.Cells.Add(cell);

row6
= new TableRow();
cell
= new TableCell();
SetLeftItemCellStyle(cell);
cell.Text
= "不合格率";
row6.Cells.Add(cell);

cell
= new TableCell();
SetLeftItemCellStyle(cell);
cell.Text
= "抽验总数";
row7.Cells.Add(cell);

row8
= new TableRow();
cell
= new TableCell();
SetLeftItemCellStyle(cell);
cell.Text
= "不合格数";
row8.Cells.Add(cell);

row9
= new TableRow();
cell
= new TableCell();
SetLeftItemCellStyle(cell);
cell.Text
= "不合格率";
row9.Cells.Add(cell);

enterpriseTotal
= enterpriseTotalForDisqualify = leechdomCategoryTotal = leechdomCategoryTotalForDisqualify = 0;
batchNumTotal
= batchNumTotalForDisqualify = 0;

//统计数据
for (int j = 0; j <this.Params.DrugCategoryList.Count; j++)
{
key
= this.Params.DrugCategoryList[j] as KeyInfo;
staInfo
= bll.GetStatisticInfo(info.Value, key.Value,this.Params.ConditionExpress);
cell
= new TableCell();
if (staInfo.EnterpriseCount != 0)
{
cell.Text
= String.Format(NumberLink, (int)ShowDetailInfoType.EnterpriseCount, info.Value, key.Value, this.Params.ConditionExpress, staInfo.EnterpriseCount.ToString());
SetContentCellStyle(cell);
}
enterpriseTotal
+= staInfo.EnterpriseCount;
row1.Cells.Add(cell);

cell
= new TableCell();
if (staInfo.EnterpriseCountForDisqualify != 0)
{
cell.Text
= String.Format(NumberLink, (int)ShowDetailInfoType.EnterpriseDisqualifyCount, info.Value, key.Value, this.Params.ConditionExpress, staInfo.EnterpriseCountForDisqualify.ToString());
SetContentCellStyle(cell);
}
enterpriseTotalForDisqualify
+= staInfo.EnterpriseCountForDisqualify;
row2.Cells.Add(cell);

// 不合格率
cell = new TableCell();
if (staInfo.EnterpriseCount != 0)
{
string failureRate = (Math.Round(staInfo.EnterpriseCountForDisqualify / (staInfo.EnterpriseCount * 1.0), 4) * 100.0).ToString();
cell.Text
= failureRate.Equals("0") ? failureRate : failureRate + "%";//(staInfo.EnterpriseCountForDisqualify/ (staInfo.EnterpriseCount*1.0)).ToString();
SetContentCellStyle(cell);
}
row3.Cells.Add(cell);

cell
= new TableCell();
if (staInfo.LeechdomCategoryCount != 0)
{
cell.Text
= String.Format(NumberLink, (int)ShowDetailInfoType.DrugSampleCount, info.Value, key.Value, this.Params.ConditionExpress, staInfo.LeechdomCategoryCount.ToString());
SetContentCellStyle(cell);
}
leechdomCategoryTotal
+= staInfo.LeechdomCategoryCount;
row4.Cells.Add(cell);

cell
= new TableCell();
if (staInfo.LeechdomCategoryCountForDisqualify != 0)
{
cell.Text
= String.Format(NumberLink, (int)ShowDetailInfoType.DrugSampleDisqualifyCount, info.Value, key.Value, this.Params.ConditionExpress, staInfo.LeechdomCategoryCountForDisqualify.ToString());
SetContentCellStyle(cell);
}
leechdomCategoryTotalForDisqualify
+= staInfo.LeechdomCategoryCountForDisqualify;
row5.Cells.Add(cell);

// 不合格率
cell = new TableCell();
if (staInfo.LeechdomCategoryCount != 0)
{
string failureRate = ( Math.Round(staInfo.LeechdomCategoryCountForDisqualify / (staInfo.LeechdomCategoryCount * 1.0), 4)*100.0).ToString();
cell.Text
= failureRate.Equals("0") ? failureRate : failureRate + "%";
SetContentCellStyle(cell);
}
row6.Cells.Add(cell);

cell
= new TableCell();
if (staInfo.BatchNumCount != 0)
{
cell.Text
= String.Format(NumberLink, (int)ShowDetailInfoType.BatchCount, info.Value, key.Value, this.Params.ConditionExpress, staInfo.BatchNumCount.ToString());
SetContentCellStyle(cell);
}
batchNumTotal
+= staInfo.BatchNumCount;
row7.Cells.Add(cell);

cell
= new TableCell();
if (staInfo.BatchNumCountForDisqualify != 0)
{
cell.Text
= String.Format(NumberLink, (int)ShowDetailInfoType.BatchDisqualifyCount, info.Value, key.Value, this.Params.ConditionExpress, staInfo.BatchNumCountForDisqualify.ToString());
SetContentCellStyle(cell);
}
batchNumTotalForDisqualify
+= staInfo.BatchNumCountForDisqualify;
row8.Cells.Add(cell);

// 不合格率
cell = new TableCell();
if (staInfo.BatchNumCount != 0)
{
string failureRate = (Math.Round(staInfo.BatchNumCountForDisqualify / (staInfo.BatchNumCount * 1.0), 4) * 100.0).ToString();
cell.Text
= failureRate.Equals("0") ? failureRate : failureRate + "%";
SetContentCellStyle(cell);
}
row9.Cells.Add(cell);
}

//合计
cell = new TableCell();
cell.Text
= enterpriseTotal.ToString();
SetContentCellStyle(cell);
row1.Cells.Add(cell);

cell
= new TableCell();
cell.Text
= enterpriseTotalForDisqualify.ToString();
SetContentCellStyle(cell);
row2.Cells.Add(cell);

cell
= new TableCell();
if (enterpriseTotal>0)
{
string failureRate = (Math.Round(enterpriseTotalForDisqualify / (enterpriseTotal * 1.0), 4) * 100.0).ToString();
cell.Text
= failureRate.Equals("0") ? failureRate : failureRate + "%";
SetContentCellStyle(cell);
}
row3.Cells.Add(cell);

cell
= new TableCell();
cell.Text
= leechdomCategoryTotal.ToString();
SetContentCellStyle(cell);
row4.Cells.Add(cell);

cell
= new TableCell();
cell.Text
= leechdomCategoryTotalForDisqualify.ToString();
SetContentCellStyle(cell);
row5.Cells.Add(cell);

cell
= new TableCell();
if (leechdomCategoryTotal > 0)
{
string failureRate = (Math.Round(leechdomCategoryTotalForDisqualify / (leechdomCategoryTotal * 1.0), 4) * 100.0).ToString();
cell.Text
= failureRate.Equals("0") ? failureRate : failureRate + "%";
SetContentCellStyle(cell);
}
row6.Cells.Add(cell);

cell
= new TableCell();
cell.Text
= batchNumTotal.ToString();
SetContentCellStyle(cell);
row7.Cells.Add(cell);

cell
= new TableCell();
cell.Text
= batchNumTotalForDisqualify.ToString();
SetContentCellStyle(cell);
row8.Cells.Add(cell);

cell
= new TableCell();
if (batchNumTotal > 0)
{
string failureRate = (Math.Round(batchNumTotalForDisqualify / (batchNumTotal * 1.0), 4) * 100.0).ToString();
cell.Text
= failureRate.Equals("0") ? failureRate : failureRate + "%";
SetContentCellStyle(cell);
}
row9.Cells.Add(cell);


this.Worktable.Rows.Add(row1);
this.Worktable.Rows.Add(row2);
this.Worktable.Rows.Add(row3);
this.Worktable.Rows.Add(row4);
this.Worktable.Rows.Add(row5);
this.Worktable.Rows.Add(row6);
this.Worktable.Rows.Add(row7);
this.Worktable.Rows.Add(row8);
this.Worktable.Rows.Add(row9);
}
}


private void SetHeaderCellStyle(TableCell cell)
{
cell.HorizontalAlign
= HorizontalAlign.Center;
cell.Font.Bold
= true;
//cell.Font.Size = FontUnit.XSmall;
//cell.Height = Unit.Pixel(35);
}

private void SetLeftCellStyle(TableCell cell)
{
cell.HorizontalAlign
= HorizontalAlign.Center;
cell.Font.Bold
= true;
//cell.Font.Size = FontUnit.XSmall;
}

private void SetLeftItemCellStyle(TableCell cell)
{
cell.HorizontalAlign
= HorizontalAlign.Center;
cell.Font.Bold
= true;
}

private void SetContentCellStyle(TableCell cell)
{
if (cell.Text == "0")
cell.Text
= "";
else
cell.HorizontalAlign
= HorizontalAlign.Center;
}

 

统计表生成工厂

 

代码
/// <summary>
/// 统计表生成工厂
/// </summary>
public class StatsFactory
{
private StatsBase m_Stats;
private StatsParams m_Params;

/// <summary>
/// 构建报表
/// </summary>
public void BuildStatistics(Table table, StatsParams param)
{
m_Params
= param;
switch (m_Params.ResultCategory )
{
case StatsCategory.StatsByEntType:
m_Stats
= new StatsByEntType(table, m_Params);
break;
case StatsCategory.StatsByFDAIdType:
m_Stats
= new StatsByFDAIdType(table,m_Params);
break;
}
if (m_Stats != null)
{
m_Stats.BuildTable();
}
}

/// <summary>
/// 获得标题
/// </summary>
/// <returns></returns>
public string GetCaption()
{
return m_Stats.Caption;
}
}

 

调用方法: factory.BuildStatistics(Table1, conditionStruct); 传入table控件和查询条件

运行效果图:

posted @ 2010-11-11 14:48  marr  阅读(608)  评论(0编辑  收藏  举报