using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using Newtonsoft.Json; namespace FineUIPro.Web.Controls { public partial class ProgressBox : System.Web.UI.UserControl { #region 各种属性 /// 最大值 public int Max { get { return this.Session["_Max"] != null ? Convert.ToInt32(this.Session["_Max"]) : 100; } set { if (this.Session["_Max"] != null) { this.Session["_Max"] = value; } else { this.Session.Add("_Max", value); } } } private static int _value; /// 进度值 public int Value { get { return _value; } set { if (value < 0) { value = 0; } if (value > this.Max) { value = this.Max; } _value = value; } } /// ajax回调时的网址 public String PageUrl { get { return this.ViewState["_PageUrl"] == null ? this.Page.Request.Url.ToString() : this.ViewState["_PageUrl"].ToString(); } set { if (this.ViewState["_PageUrl"] != null) { this.ViewState.Add("_PageUrl", value); } else { this.ViewState["_PageUrl"] = value; } } } public delegate void ThreadStartFunciton(); public ThreadStartFunciton RunFunction { get { return this.Session[this.ID + "_runFunction"] as ThreadStartFunciton; } set { if (this.Session[this.ID + "_runFunction"] != null) { this.Session.Add(this.ID + "_runFunction", value); } else { this.Session[this.ID + "_runFunction"] = value; } } } #endregion #region 各种方法 /// 开始一个进程,运行this.RunFunction中指定的函数 public void StartThread() { this.StartThread(this.RunFunction); } /// 开始一个进程,运行指定的函数 /// <函数的名称/param> public void StartThread(ThreadStartFunciton runFunction) { System.Threading.Thread thread = new System.Threading.Thread(new System.Threading.ThreadStart(runFunction)); thread.Start(); } /// 获得客户端回调函数的字符串 /// STring public String GetPostBackFunctionNameReference() { return "returnResponse();"; } /// 向客户观返回取当前进度的值 public void ResponseValue() { Response.Write(this.Value.ToString() + "," + this.Max.ToString()); Response.Flush(); Response.Close(); } #endregion protected void Page_Load(object sender, EventArgs e) { } } }