用委托(Delegate)来协调窗体中各用户控件之间的消息
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace Tobto.DJ.DJWebUI.JXKH
{
/// <summary>
/// CountGongZuoLiang 的摘要说明。
/// </summary>
public class CountGongZuoLiang : Tobto.DJ.DJWebUI.UIClass.DJPageBase
{
protected Tobto.DJ.DJWebUI.UserControls.UcJxkh.UcCountCondi UcCountCondi1;
protected Tobto.DJ.DJWebUI.UserControls.UcJxkh.UcGongZuoLiang UcGongZuoLiang1;
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
protected override void InitUserControls()
{
UcCountCondi1.EventCountData += new Tobto.DJ.DJWebUI.UserControls.UcJxkh.UcCountCondi.CountData(UcCountCondi1_EventCountData);
UcGongZuoLiang1.EventSetCountList += new Tobto.DJ.DJWebUI.UserControls.UcJxkh.UcGongZuoLiang.SetCountList(UcGongZuoLiang1_EventSetCountList);
base.InitUserControls ();
}
private void UcCountCondi1_EventCountData(string departmentID,string departmentName, DateTime beginDate, DateTime endDate)
{
UcGongZuoLiang1.Visible = true;
UcGongZuoLiang1.BindItem(departmentID,departmentName,beginDate,endDate);
UcCountCondi1.SetibtnToExcelStatus(true);
}
private void UcGongZuoLiang1_EventSetCountList(DataTable table)
{
UcCountCondi1.countList = table;
}
}
}
namespace Tobto.DJ.DJWebUI.UserControls.UcJxkh
{
using System;
using System.Data;
using System.IO;
using System.Drawing;
using System.Web;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
/// <summary>
/// UcCountCondi 的摘要说明。
/// </summary>
public class UcCountCondi :Tobto.DJ.DJWebUI.UIClass.DJUcListPageBase
{
protected System.Web.UI.WebControls.TextBox txtDepartmentName;
protected System.Web.UI.WebControls.TextBox txtEndDate;
protected System.Web.UI.WebControls.TextBox txtBeginDate;
protected System.Web.UI.WebControls.TextBox txtDepartmentID;
protected System.Web.UI.WebControls.ImageButton ibtnToExcel;
protected System.Web.UI.WebControls.ImageButton ibtnOk;
public delegate void CountData(string departmentID,string departmentName,DateTime beginDate,DateTime endDate);
public event CountData EventCountData;
public DataTable countList
{
get{return ViewState["countList"] == null ? null : ViewState["countList"] as DataTable;}
set{ViewState["countList"] = value;}
}
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
if (!IsPostBack)
BindItem();
}
private void BindItem()
{
txtBeginDate.Text = DateTime.Today.AddMonths(-1).ToShortDateString();
txtEndDate.Text = DateTime.Today.ToShortDateString();
txtDepartmentID.Text = CurrentLoginUserInfo.DepartMentID;
txtDepartmentName.Text = GetDepartmentNameByID(CurrentLoginUserInfo.DepartMentID);
}
public void SetibtnToExcelStatus(bool isShow)
{
ibtnToExcel.Visible = isShow;
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器
/// 修改此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.ibtnOk.Click += new System.Web.UI.ImageClickEventHandler(this.ibtnOk_Click);
this.ibtnToExcel.Click += new System.Web.UI.ImageClickEventHandler(this.ibtnToExcel_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void ibtnOk_Click(object sender, System.Web.UI.ImageClickEventArgs e)
{
if (EventCountData != null && txtBeginDate.Text != "" && txtEndDate.Text.Trim() != "" && txtDepartmentID.Text!="")
{
try
{
EventCountData(txtDepartmentID.Text.Trim(),txtDepartmentName.Text,Convert.ToDateTime(txtBeginDate.Text),Convert.ToDateTime(txtEndDate.Text));
}
catch (Exception err)
{
Tobto.FrameWork.Error2Log.To2LogFile(err);
ShowMessage(err.Message);
}
}
}
private void ibtnToExcel_Click(object sender, System.Web.UI.ImageClickEventArgs e)
{
System.IO.StringWriter sw = CreateCountTextStream(countList);
Tobto.FrameWork.IO.FileHelper.startDownLoad(Response,sw,"CountReport" + Tobto.FrameWork.DataAccessLayer.QueryFacadeBase.GetDBTime().ToString("yyMMdd") + ".csv");
}
public StringWriter CreateCountTextStream(DataTable resultList)
{
StringWriter oStringWriter = new StringWriter();
oStringWriter.WriteLine("序号,所在部门,姓名,路线数,区域数,设备数,额定测项数,完成测项数,停检数,漏检数,平均漏检率,平均工作强度");
int i = 0;
foreach (DataRow drr in resultList.Rows)
{
i++;
string seqStr = i.ToString();
if (i == resultList.Rows.Count)
seqStr = "合计";
oStringWriter.WriteLine(seqStr + "," + GetUserDepartmentName(drr["UserID"]) + "," + GetUserName(drr["UserID"]) + "," + drr["Tasks"] + "," + drr["TotalAreas"] + "," + drr["TotalDevice"] + "," + drr["totalitems"] + "," + drr["FinishItems"] + "," + drr["StopTotal"] + "," + drr["LouJian"] + "," + GetLouJianLv(drr["totalitems"],drr["StopTotal"],drr["LouJian"]) + "," + GetQianDu(drr["FinishItems"],drr["TotalTime"]));
}
return oStringWriter;
}
protected string GetLouJianLv(object total,object stopTotal,object louJian)
{
if ( louJian!= null && total!= null&& total != DBNull.Value && louJian != DBNull.Value && Convert.ToInt32(total) > 0)
{
int stopTot = 0;
if (stopTotal != null && stopTotal != DBNull.Value)
stopTot = Convert.ToInt32(stopTotal);
if (Convert.ToInt32(total)<=stopTot )
return "0";
double temp = (Convert.ToDouble(louJian) / (Convert.ToInt32(total)-stopTot))*100;
return temp.ToString("0.00") + "%";
}
else
return "0";
}
protected string GetQianDu(object FinishItems,object TotalTime)
{
if (TotalTime != null && FinishItems != null && TotalTime != DBNull.Value && FinishItems!= DBNull.Value && Convert.ToDouble( FinishItems) >0)
{
return Convert.ToInt32( Convert.ToDouble( TotalTime)/60 / Convert.ToInt32(FinishItems) ) + "分钟/测点";
}
return "";
}
}
}
namespace Tobto.DJ.DJWebUI.UserControls.UcJxkh
{
using System;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using Tobto.DJ.DataFacade;
/// <summary>
/// UcGongZuoLiang 的摘要说明。
/// </summary>
public class UcGongZuoLiang : Tobto.DJ.DJWebUI.UIClass.DJUcListPageBase
{
protected System.Web.UI.WebControls.Literal ltMarkTableDate;
protected System.Web.UI.WebControls.Literal ltMarkTableUser;
protected System.Web.UI.WebControls.DataGrid dgList;
protected System.Web.UI.WebControls.Literal ltEndDate;
protected System.Web.UI.WebControls.Literal ltBeginDate;
protected System.Web.UI.WebControls.Literal ltDepartment;
public delegate void SetCountList(DataTable list);
public event SetCountList EventSetCountList;
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器
/// 修改此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.dgList.ItemDataBound += new System.Web.UI.WebControls.DataGridItemEventHandler(this.dgList_ItemDataBound);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private int TotalRows;
public void BindItem(string departmentID,string departmentName,DateTime beginDate,DateTime endDate)
{
DataSet data = DJ2_TASKlISTFacade.CountGongZuoLiang(departmentID,beginDate,endDate);
DataSet sumData = DJ2_TASKlISTFacade.SumCountGongZuoLiang(departmentID,beginDate,endDate);
DataRow dr = data.Tables[0].NewRow();
for(int i=0; i<sumData.Tables[0].Columns.Count; i++)
{
dr[i] = sumData.Tables[0].Rows[0][i];
}
data.Tables[0].Rows.Add(dr);
TotalRows = data.Tables[0].Rows.Count;
dgList.DataSource = data.Tables[0].DefaultView;
dgList.DataBind();
if (EventSetCountList != null)
{
EventSetCountList(data.Tables[0]);
}
}
private void dgList_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
Label lblOrderNum = (Label)e.Item.FindControl("lblOrderNum");
if (lblOrderNum != null)
{
if (e.Item.ItemIndex == TotalRows -1)
lblOrderNum.Text = "合计:";
else
lblOrderNum.Text = Convert.ToString((e.Item.ItemIndex +1));
}
}
protected string GetLouJianLv(object total,object stopTotal,object louJian)
{
if ( louJian!= null && total!= null&& total != DBNull.Value && louJian != DBNull.Value && Convert.ToInt32(total) > 0)
{
int stopTot = 0;
if (stopTotal != null && stopTotal != DBNull.Value)
stopTot = Convert.ToInt32(stopTotal);
if (Convert.ToInt32(total)<=stopTot )
return "0";
double temp = (Convert.ToDouble(louJian) / (Convert.ToInt32(total)-stopTot))*100;
return temp.ToString("0.00") + "%";
}else
return "0";
}
protected string GetQianDu(object FinishItems,object TotalTime)
{
if (TotalTime != null && FinishItems != null && TotalTime != DBNull.Value && FinishItems!= DBNull.Value && Convert.ToDouble( FinishItems) >0)
{
return Convert.ToInt32( Convert.ToDouble( TotalTime)/60 / Convert.ToInt32(FinishItems) ) + "分钟/测点";
}
return "";
}
protected string GetTimeStr(object totalTime)
{
if (totalTime != null && totalTime!= DBNull.Value)
{
long totalSecond = Convert.ToInt64(totalTime);
int day = Convert.ToInt32( totalSecond/86400);
int hour = Convert.ToInt32( totalSecond - day * 86400)/3600;
int minut = Convert.ToInt32(totalSecond - day * 86400 - hour * 60)/60;
return string.Format("{0}天{1}小时{2}分",day,hour,minut);
}
return "";
}
}
}
浙公网安备 33010602011771号