当前位置:编程学习 > C#/ASP.NET >>

菜鸟的问题:在VS2003下无法将下面的CS文件编译成DLL文件,在线急等!!!

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.IO;
using System.Reflection;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using WebAppraisementApp.Business;
using WebAppraisementApp.Business.AssessAdminCustoms;


namespace WebAppraisementApp.Pages.AssessAdminCustoms
{
public class ReverserClass : IComparer
{
private Type type = null;
private string name = string.Empty;
private string direction = "ASC";

public ReverserClass(Type type, string name, string direction)
{
this.type = type;
this.name = name;
this.direction = direction;
}

#region IComparer 成员

public int Compare(object x, object y)
{
object x1 = this.type.InvokeMember(this.name, BindingFlags.Public | BindingFlags.Instance | BindingFlags.GetProperty, null, x, null);
object y1 = this.type.InvokeMember(this.name, BindingFlags.Public | BindingFlags.Instance | BindingFlags.GetProperty, null, y, null);
if (this.direction.Equals("DESC")) Swap(ref x1, ref y1);
return (new CaseInsensitiveComparer()).Compare(x1, y1);
}
#endregion

private void Swap(ref object x, ref object y)
{
object temp = null;
temp = x;
x = y;
y = temp;
}
}

internal class IndexingAndOrder
{
private int indexOfRow;
private int sortOrder;
private decimal totalScore;

public IndexingAndOrder(int indexOfRow, int sortOrder, decimal totalScore)
{
this.indexOfRow = indexOfRow;
this.sortOrder = sortOrder;
this.totalScore = totalScore;
}

public int IndexOfRow
{
get
{
return indexOfRow;
}
set
{
indexOfRow = value;
}
}

public int SortOrder
{
get
{
return sortOrder;
}
set
{
sortOrder = value;
}
}

public decimal TotalScore
{
get
{
return totalScore;
}
set
{
totalScore = value;
}
}
}

public class AppraisementStatisticPage : BaseWebForm
{
private int classType;
protected System.Web.UI.WebControls.DropDownList ddlCheckYears;
protected System.Web.UI.WebControls.Button btnOK;
protected System.Web.UI.HtmlControls.HtmlGenericControl divResult;
protected HtmlGenericControl ttlCurrentPage;

// protected override int AssessYear
// {
// get 
// {
// object assessYear = ViewState["AssessYear"];
// if (CommonHelper.IsNullOrEmpty(assessYear)) assessYear = ddlCheckYears.SelectedValue;
// if (CommonHelper.IsNullOrEmpty(assessYear)) assessYear = Request.QueryString["assessYear"];
// if (CommonHelper.IsNullOrEmpty(assessYear)) assessYear = ApplicationSettings.CheckYear.ToString();
// return (int)ViewState["AssessYear"];
// }
// set
// {
// ViewState["AssessYear"] = value;
// }
// }

protected override int AssessYear
{
get
{
return int.Parse(ddlCheckYears.SelectedValue);
}
set
{
base.AssessYear = value;
}
}

protected override string[] AuthorizationExpression
{
get
{
return new string[] {"AA_QUERYRESULT"};
}
}

        private void Page_Load(object sender, System.EventArgs e)
        {

            classType = int.Parse(Request.QueryString["classType"]);

            if (!IsPostBack)
            {

                ttlCurrentPage.InnerText = GetAppraisementTableTitle();

                ControlHelper.InitializeCheckYears(ddlCheckYears);

                BindResult(divResult);

            }

        }

private void BindResult(Control parent)
{
parent.Controls.Add(CreateDepartmentScoreTable());
}

private void Bind2006Result(Control parent)
{
classType = int.Parse(Request.QueryString["classType"]);
HtmlGenericControl ctrl = new HtmlGenericControl("div");

string sourceFile = string.Empty;
// 2006年度没有
if (classType == 0)
{
ctrl.InnerHtml = string.Empty;
return;
}
else if (classType == 1)
{
sourceFile = Server.MapPath("Huping_2006.txt");
}
else if (classType == 2)
{
sourceFile = Server.MapPath("Pingyi_2006.txt");
}

FileInfo fi = new FileInfo(sourceFile);
StreamReader fileReader = fi.OpenText();;
string fileContent = fileReader.ReadToEnd();
fileReader.Close();
ctrl.InnerHtml = fileContent;

parent.Controls.Add(ctrl);
}

private HtmlTable CreateScoreTable(string tableID)
{
HtmlTable table = TableGenerator.CreateTableWithAttributes(
new string[] {"ID", tableID},
new string[] {"Width", "100%"},
new string[] {"Border", "1"});

table = TableGenerator.AttachStylesOnTable(table,
new string[] {"border-style", "solid"},
new string[] {"border-width", "1"});

return table;
}

private HtmlTable CreateDepartmentScoreTable()
{
DataTable scoreTable = AppraisementScoreAdapter.GetStatisticScores(AssessYear, classType);
if (scoreTable.Rows.Count == 0)
{
Response.Redirect(string.Format("../../portal/ShowError.htm?message={0}", Server.UrlPathEncode("目前尚无测评数据")), true);
}

HtmlTable table = CreateScoreTable("tblScoreTable");
// HtmlTableRow[] titleRows = CreateTitleRows();
HtmlTableRow[] titleRows = CreateTitleRowsEx();
HtmlTableRow[] bodyRows = CreateBodyRows(scoreTable);
FillOrders(ref bodyRows, 1);
// 2008-12-16,不再显示总平均分,去掉
//HtmlTableRow summaryRow = CreateSummaryRow(bodyRows);

for (int i = 0; i < titleRows.Length; i ++) 
{
if (titleRows[i].Cells != null && titleRows[i].Cells.Count > 0)
table.Rows.Add(titleRows[i]);
}
// table.Rows.Add(summaryRow);
for (int i = 0; i < bodyRows.Length; i ++) table.Rows.Add(bodyRows[i]);

return table;
}

private HtmlTableRow[] CreateTitleRows()
{
DataTable criteriaTable = AppraisementScoreAdapter.GetCriteria(classType);

HtmlTableRow classRow = TableGenerator.CreateRowWithAttributes(
new string[] {"Height", "30"},
new string[] {"Class", "contentHeader"});

classRow.Cells.Add(TableGenerator.CreateTextCellWithAttributes(@"考核单位\考核内容",
new string[] {"RowSpan", "2"}, new string[] {"Align", "center"}));

HtmlTableRow criteriaRow = TableGenerator.CreateRowWithAttributes(
new string[] {"Height", "30"},
new string[] {"Class", "contentHeader"});

classRow.Cells.Add(TableGenerator.CreateTextCellWithAttributes("总分",
new string[] {"Align", "center"}, new string[] {"RowSpan", "2"}));

int[] classIDs = GetClassIDs(criteriaTable);
for (int i = 0; i < classIDs.Length; i ++)
{
int classID = classIDs[i];
DataRow[] rows = criteriaTable.Select(string.Format("ClassID={0}", classID));
string className = string.Empty;
if (rows.Length == 1)
{
decimal classWeight = (decimal)rows[0]["Ratio"];
className = string.Format("{0}({1:0.0}%)", rows[0]["ClassName"].ToString(), classWeight * 10);
}
else
{
className = rows[0]["ClassName"].ToString();
}
classRow.Cells.Add(TableGenerator.CreateTextCellWithAttributes(
className,
new string[] {"Align", "center"},
new string[] {"ColSpan", rows.Length.ToString()},
new string[] {"RowSpan", rows.Length == 1 ? "2" : "1"}
));

if (rows.Length > 1)
{
for (int j = 0; j < rows.Length; j ++)
{
decimal criterionWeight = (decimal)rows[j]["Ratio"];
criteriaRow.Cells.Add(TableGenerator.CreateTextCellWithAttributes(
string.Format("{0}({1:0.0}%)", rows[j]["CriterionName"].ToString(), criterionWeight * 10),
new string[] {"Align", "center"}
));
}
}
}

HtmlTableRow titleRow = new HtmlTableRow();
titleRow.Cells.Add(TableGenerator.CreateTextCellWithAttributes(
GetAppraisementTableTitle(),
new string[] {"Height", "30"},
new string[] {"Align", "center"},
new string[] {"Class", "title"},
new string[] {"ColSpan", (criteriaTable.Rows.Count + 2).ToString()}
));

return new HtmlTableRow[] {titleRow, classRow, criteriaRow};
} --------------------编程问答--------------------
/// <summary>
/// 生成测评票标题栏
/// </summary>
/// <param name="classType"></param>
/// <returns></returns>
/// <remarks>因测评票指标较多,将权重独立展示,不再合并到指标名称中</remarks>
private HtmlTableRow[] CreateTitleRowsEx()
{
int numOfTitleRows = HowManyTitleRows;
DataTable criteriaTable = AppraisementScoreAdapter.GetCriteria(classType);

HtmlTableRow classRow = TableGenerator.CreateRowWithAttributes(
new string[] {"Height", "30"},
new string[] {"Class", "contentHeader"});

HtmlTableRow criteriaRow = TableGenerator.CreateRowWithAttributes(
new string[] {"Height", "30"},
new string[] {"Class", "contentHeader"});

HtmlTableRow weightRow = TableGenerator.CreateRowWithAttributes(
new string[] {"Height", "30"},
new string[] {"Class", "contentHeader"});

classRow.Cells.Add(TableGenerator.CreateTextCellWithAttributes(@"考核单位\考核内容",
new string[] {"RowSpan", numOfTitleRows.ToString()}, new string[] {"Align", "center"}));

classRow.Cells.Add(TableGenerator.CreateTextCellWithAttributes("排名",
new string[] {"Align", "center"}, new string[] {"RowSpan", numOfTitleRows.ToString()}));

classRow.Cells.Add(TableGenerator.CreateTextCellWithAttributes("总分",
new string[] {"Align", "center"}, new string[] {"RowSpan", numOfTitleRows.ToString()}));

int[] classIDs = GetClassIDs(criteriaTable);
for (int i = 0; i < classIDs.Length; i ++)
{
int classID = classIDs[i];
DataRow[] rows = criteriaTable.Select(string.Format("ClassID={0}", classID));

string className = rows[0]["ClassName"].ToString();
classRow.Cells.Add(TableGenerator.CreateTextCellWithAttributes(
className,
new string[] {"Align", "center"},
new string[] {"ColSpan", rows.Length.ToString()}));

if (rows.Length > 1)
{
for (int j = 0; j < rows.Length; j ++)
{
decimal criterionWeight = (decimal)rows[j]["Ratio"];
criteriaRow.Cells.Add(TableGenerator.CreateTextCellWithAttributes(
string.Format("{0}", rows[j]["CriterionName"].ToString()),
new string[] {"Align", "center"}));
weightRow.Cells.Add(TableGenerator.CreateTextCellWithAttributes(
string.Format("{0:0.0}%", criterionWeight * 10),
new string[] {"Align", "center"}));
}
}
else
{
decimal criterionWeight = (decimal)rows[0]["Ratio"];
weightRow.Cells.Add(TableGenerator.CreateTextCellWithAttributes(
string.Format("{0:0.0}%", criterionWeight * 10),
new string[] {"Align", "center"}));
}
}

HtmlTableRow titleRow = new HtmlTableRow();
titleRow.Cells.Add(TableGenerator.CreateTextCellWithAttributes(
GetAppraisementTableTitle(),
new string[] {"Height", "30"},
new string[] {"Align", "center"},
new string[] {"Class", "title"},
new string[] {"ColSpan", (criteriaTable.Rows.Count + 3).ToString()}
));

return new HtmlTableRow[] {titleRow, classRow, criteriaRow, weightRow};
}

private int[] GetClassIDs(DataTable criteriaTable)
{
ArrayList al = new ArrayList();
for (int i = 0; i < criteriaTable.Rows.Count; i ++)
{
int classID = (int)criteriaTable.Rows[i]["ClassID"];
if (!al.Contains(classID)) al.Add(classID);
}

int[] classIDs = new int[al.Count];
al.CopyTo(classIDs);
return classIDs;

}

private int GetDepartmentCount(DataTable scoreTable)
{
ArrayList al = new ArrayList();
for (int i = 0; i < scoreTable.Rows.Count; i ++)
{
string departmentID = scoreTable.Rows[i]["DepartmentID"].ToString().ToUpper();
if (!al.Contains(departmentID)) al.Add(departmentID);
}
return al.Count;
}

private HtmlTableRow[] CreateBodyRows(DataTable scoreTable)
{
int departmentCount = GetDepartmentCount(scoreTable);
HtmlTableRow[] rows = new HtmlTableRow[departmentCount];
int pos = 0, numOfFields = scoreTable.Rows.Count / departmentCount;
for (int i = 0; i < rows.Length; i ++)
{
HtmlTableRow row = rows[i] = TableGenerator.CreateRowWithAttributes(new string[] {"Height", "25"});
row.Cells.Add(TableGenerator.CreateTextCellWithAttributes(
scoreTable.Rows[pos]["DepartmentName"].ToString(),
new string[] {"Width", "100px"}));

decimal totalScore = Decimal.Zero;
for (int j = pos; j < (i + 1) * numOfFields; j ++)
{
if (j >= scoreTable.Rows.Count) break;
decimal avgScore = (decimal)scoreTable.Rows[pos]["AvgScore"];
totalScore += avgScore * (decimal)scoreTable.Rows[pos]["Ratio"];
row.Cells.Add(TableGenerator.CreateTextCellWithAttributes(
avgScore.ToString("0.000"),
new string[] {"Align", "center"}));
pos ++;
}

HtmlTableCell totalScoreCell = TableGenerator.CreateTextCellWithAttributes(
totalScore == Decimal.Zero ? "" : totalScore.ToString("0.00"),
new string[] {"Align", "center"});

row.Cells.Insert(1, totalScoreCell);
}

return rows;
}

private void FillOrders(ref HtmlTableRow[] bodyRows, int cellIndexOfTotalScore)
{
ArrayList indexingAndOrders = new ArrayList();
for (int i = 0; i < bodyRows.Length; i ++)
{
HtmlTableRow currentRow = bodyRows[i];
indexingAndOrders.Add(new IndexingAndOrder(i, -1, decimal.Parse(currentRow.Cells[cellIndexOfTotalScore].InnerText)));
}

ReverserClass reverser = new ReverserClass(typeof(IndexingAndOrder), "TotalScore", "DESC");
indexingAndOrders.Sort(reverser);
AssignSortOrders(ref indexingAndOrders);

for (int i = 0; i < indexingAndOrders.Count; i ++)
{
IndexingAndOrder current = indexingAndOrders[i] as IndexingAndOrder;
HtmlTableCell orderCell = new HtmlTableCell();
orderCell.Align = "center";
orderCell.InnerText = current.SortOrder.ToString();
bodyRows[current.IndexOfRow].Cells.Insert(cellIndexOfTotalScore, orderCell);
}
// for (int i = 0; i < bodyRows.Length; i ++)
// {
// HtmlTableRow currentRow = bodyRows[i];
// HtmlTableCell orderCell = new HtmlTableCell();
// orderCell.Align = "center";
// orderCell.InnerText = (indexingAndOrders[i] as IndexingAndOrder).SortOrder.ToString();
// currentRow.Cells.Insert(cellIndexOfTotalScore, orderCell);
// }
}

private void AssignSortOrders(ref ArrayList indexingAndOrders)
{
int lastOrder = 1;
decimal maxScore = decimal.MaxValue;
for (int i = 0; i < indexingAndOrders.Count; i ++)
{
IndexingAndOrder current = indexingAndOrders[i] as IndexingAndOrder;
decimal currentScore = current.TotalScore;
if (currentScore < maxScore)
{
lastOrder = current.SortOrder = i + 1;
}
else
{
current.SortOrder = lastOrder;
}

maxScore = currentScore;
}
}

// private HtmlTableRow CreateSummaryRow(HtmlTableRow[] bodyRows)
// {
// HtmlTableRow summaryRow = TableGenerator.CreateRowWithAttributes(new string[] {"Height", "25"});
// summaryRow.Cells.Add(TableGenerator.CreateTextCellWithAttributes("总平均分"));
// for (int i = 1; i < bodyRows[0].Cells.Count; i ++)
// {
// decimal averageScore = CalculateAverageScore(bodyRows, i);
// summaryRow.Cells.Add(TableGenerator.CreateTextCellWithAttributes(
// (i == 1) ? averageScore.ToString("0.00") : averageScore.ToString("0.000"),
// new string[] {"Align", "center"}));
// }
//
// return summaryRow;
// }
//
// private decimal CalculateAverageScore(HtmlTableRow[] bodyRows, int cellIndex)
// {
// decimal totalScore = 0.00M;
// for (int i = 0; i < bodyRows.Length; i ++)
// {
// HtmlTableCell cell = bodyRows[i].Cells[cellIndex];
// decimal score = decimal.Parse(cell.InnerText);
// totalScore += score;
// }
//
// return totalScore / bodyRows.Length;
// }

private string GetAppraisementTableTitle()
{
if (classType == 0) return "总表1";
if (classType == 1) return "总表2";
if (classType == 2) return "总表3";
throw new ApplicationException("未知类型");
}

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{    
this.btnOK.Click += new System.EventHandler(this.btnOK_Click);
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion

private void btnOK_Click(object sender, System.EventArgs e)
{
// AssessYear = int.Parse(ddlCheckYears.SelectedValue);
if (AssessYear != 2006)
{
BindResult(divResult);
}
else
{
Bind2006Result(divResult);
}
}

/// <summary>
/// 计算标题栏行数
/// </summary>
/// <remarks>
/// 应该按照参数表动态计算出标题栏行数
/// 暂时按照不同测评票进行简化处理
/// </remarks>
private int HowManyTitleRows
{
get
{
int classType = int.Parse(Request.QueryString["classType"]);
if (classType == 0 || classType == 1) return 2;
return 3;
}
}

}
}
补充:.NET技术 ,  ASP.NET
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,