501 lines
19 KiB
C#
501 lines
19 KiB
C#
|
|
using System;
|
|||
|
|
using System.Data;
|
|||
|
|
using System.Configuration;
|
|||
|
|
using System.Collections;
|
|||
|
|
using System.Web;
|
|||
|
|
using System.Web.Security;
|
|||
|
|
using System.Web.UI;
|
|||
|
|
using System.Web.UI.WebControls;
|
|||
|
|
using System.Web.UI.WebControls.WebParts;
|
|||
|
|
using System.Web.UI.HtmlControls;
|
|||
|
|
using Song.Extend;
|
|||
|
|
using System.Text.RegularExpressions;
|
|||
|
|
using System.Reflection;
|
|||
|
|
using System.ComponentModel;
|
|||
|
|
using Song.ServiceInterfaces;
|
|||
|
|
using WeiSha.Common;
|
|||
|
|
|
|||
|
|
namespace Song.Extend
|
|||
|
|
{
|
|||
|
|
public class CustomPage : System.Web.UI.Page
|
|||
|
|
{
|
|||
|
|
/// <summary>
|
|||
|
|
/// ϵͳ<CFB5>汾<EFBFBD><E6B1BE>
|
|||
|
|
/// </summary>
|
|||
|
|
protected static string version = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20><><EFBFBD>ýű<C3BD>,<2C><>alert<72><74>
|
|||
|
|
/// </summary>
|
|||
|
|
public Extend.Scripts Scripts
|
|||
|
|
{
|
|||
|
|
get
|
|||
|
|
{
|
|||
|
|
return new Scripts(this);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20><>ȡ<EFBFBD><C8A1>ǰҳ<C7B0><D2B3><EFBFBD><EFBFBD>Ψһid
|
|||
|
|
/// </summary>
|
|||
|
|
/// <returns></returns>
|
|||
|
|
public string getUID()
|
|||
|
|
{
|
|||
|
|
if (ViewState["UID"] != null)
|
|||
|
|
{
|
|||
|
|
return ViewState["UID"].ToString();
|
|||
|
|
}
|
|||
|
|
ViewState["UID"] = WeiSha.Common.Request.UniqueID();
|
|||
|
|
return ViewState["UID"].ToString();
|
|||
|
|
}
|
|||
|
|
protected override void OnInitComplete(EventArgs e)
|
|||
|
|
{
|
|||
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD><D3A6>Javascript<70>ű<EFBFBD><C5B1><EFBFBD>
|
|||
|
|
string scriptPath = "~/Manage/CoreScripts/";
|
|||
|
|
scriptPath = this.ResolveUrl(scriptPath);
|
|||
|
|
//<2F>ű<EFBFBD><C5B1><EFBFBD>
|
|||
|
|
string[] scriptFile = new string[] {
|
|||
|
|
"jquery.js",
|
|||
|
|
"GridView.js",
|
|||
|
|
"Extend.js",
|
|||
|
|
"PageExt.js",
|
|||
|
|
"Verify.js",
|
|||
|
|
"HoldMode.js"
|
|||
|
|
};
|
|||
|
|
Page.Header.Controls.Add(new System.Web.UI.LiteralControl("\r\n"));
|
|||
|
|
foreach (string file in scriptFile)
|
|||
|
|
{
|
|||
|
|
Page.Header.Controls.Add(new System.Web.UI.LiteralControl("<script type=\"text/javascript\" src=\""+scriptPath+file+"?ver=" + version + "\"></script>\r\n"));
|
|||
|
|
}
|
|||
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD><D3A6>css<73>ļ<EFBFBD><C4BC><EFBFBD>js<6A>ļ<EFBFBD>
|
|||
|
|
string name = WeiSha.Common.Request.Page.Name;
|
|||
|
|
if (System.IO.File.Exists(WeiSha.Common.Request.Page.PhysicsPath + "styles/public.css"))
|
|||
|
|
Page.Header.Controls.Add(new System.Web.UI.LiteralControl("<link href=\"styles/public.css?ver=" + version + "\" type=\"text/css\" rel=\"stylesheet\" />\r\n"));
|
|||
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
Page.Header.Controls.Add(new System.Web.UI.LiteralControl("<link href=\"/Utility/iconfont/iconfont.css?ver=" + version + "\" type=\"text/css\" rel=\"stylesheet\" />\r\n"));
|
|||
|
|
if (System.IO.File.Exists(WeiSha.Common.Request.Page.PhysicsPath + "styles/"+ name+".css" ))
|
|||
|
|
Page.Header.Controls.Add(new System.Web.UI.LiteralControl("<link href=\"styles/" + name + ".css?ver=" + version + "\" type=\"text/css\" rel=\"stylesheet\" />\r\n"));
|
|||
|
|
if (System.IO.File.Exists(WeiSha.Common.Request.Page.PhysicsPath + "scripts/" + name + ".js"))
|
|||
|
|
{
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
Page.Controls.Add(new System.Web.UI.LiteralControl("<script type=\"text/javascript\" src=\"scripts/" + name + ".js?ver=" + version + "\"></script>\r\n"));
|
|||
|
|
}
|
|||
|
|
catch
|
|||
|
|
{
|
|||
|
|
Page.Header.Controls.Add(new System.Web.UI.LiteralControl("<script type=\"text/javascript\" src=\"scripts/" + name + ".js?ver=" + version + "\"></script>\r\n"));
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
//Response.Write(Extend.ManageSession.Session.Name);
|
|||
|
|
#region <EFBFBD><EFBFBD>֤<EFBFBD>Ƿ<EFBFBD><EFBFBD><EFBFBD>¼
|
|||
|
|
|
|||
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڹ<EFBFBD><DAB9><EFBFBD><EFBFBD><EFBFBD>¼״̬
|
|||
|
|
if (LoginState.Admin.IsLogin)
|
|||
|
|
{
|
|||
|
|
//<2F><><EFBFBD><EFBFBD>д<EFBFBD><D0B4>session
|
|||
|
|
LoginState.Admin.Write();
|
|||
|
|
//<2F>ж<EFBFBD>Ȩ<EFBFBD><C8A8>
|
|||
|
|
LoginState.Admin.VerifyPurview();
|
|||
|
|
//<2F><>¼<EFBFBD><C2BC><EFBFBD><EFBFBD>
|
|||
|
|
if (!this.IsPostBack)
|
|||
|
|
{
|
|||
|
|
bool isWorkLogs = Business.Do<ISystemPara>()["SysIsWorkLogs"].Boolean ?? true;
|
|||
|
|
if (Extend.LoginState.Admin.isForRoot)
|
|||
|
|
if (isWorkLogs) Business.Do<ILogs>().AddOperateLogs();
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѧԱ<D1A7><D4B1>¼״̬
|
|||
|
|
if (LoginState.Accounts.IsLogin)
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
//<2F><>ǰҳ<C7B0><D2B3><EFBFBD><EFBFBD><EFBFBD>ڵĹ<DAB5><C4B9><EFBFBD>ģ<EFBFBD><C4A3><EFBFBD><EFBFBD><EFBFBD>ƣ<EFBFBD><C6A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>/Manage<67>ļ<EFBFBD><C4BC>е<EFBFBD>·<EFBFBD><C2B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊÿһ<C3BF><D2BB>ģ<EFBFBD><C4A3><EFBFBD><EFBFBD>ManageĿ¼<C4BF><C2BC><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŀ¼
|
|||
|
|
string module = WeiSha.Common.Request.Page.Module;
|
|||
|
|
if (module.ToLower() != "student")
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
Song.Entities.Teacher th = LoginState.Accounts.Teacher;
|
|||
|
|
if (th == null)
|
|||
|
|
{
|
|||
|
|
Response.Write("δ<><CEB4>¼<EFBFBD><C2BC><EFBFBD><EFBFBD><F2B2BBBE>в<EFBFBD><D0B2><EFBFBD>Ȩ<EFBFBD>ޡ<EFBFBD>");
|
|||
|
|
Response.End();
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
Response.Write("δ<><CEB4>¼<EFBFBD><C2BC><EFBFBD><EFBFBD>ͬһ<CDAC>˺<EFBFBD><CBBA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ص<EFBFBD>¼<EFBFBD><C2BC><EFBFBD><EFBFBD>ǰ<EFBFBD><C7B0>¼״̬<D7B4><CCAC>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>");
|
|||
|
|
Response.End();
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
//catch (System.Data.DataException ex)
|
|||
|
|
//{
|
|||
|
|
// Message.ExceptionShow(ex);
|
|||
|
|
//}
|
|||
|
|
//catch (NBear.Common.ExceptionForNoLogin ex)
|
|||
|
|
//{
|
|||
|
|
// Message.ExceptionShow(ex);
|
|||
|
|
//}
|
|||
|
|
//catch (NBear.Common.ExceptionForLicense ex)
|
|||
|
|
//{
|
|||
|
|
// Message.License(ex.Message);
|
|||
|
|
//}
|
|||
|
|
//catch (Exception ex)
|
|||
|
|
//{
|
|||
|
|
// Message.ExceptionShow(ex);
|
|||
|
|
//}
|
|||
|
|
#endregion
|
|||
|
|
//this.Form.Attributes.Add("onsubmit", "this.action=document.location.href");
|
|||
|
|
|
|||
|
|
base.OnInitComplete(e);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20><><EFBFBD>¼<EFBFBD><C2BC>ص<EFBFBD>ǰҳ<C7B0><D2B3>
|
|||
|
|
/// </summary>
|
|||
|
|
protected void Reload()
|
|||
|
|
{
|
|||
|
|
string url = Request.Path;
|
|||
|
|
this.Response.Redirect(url);
|
|||
|
|
}
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20><>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD>
|
|||
|
|
/// </summary>
|
|||
|
|
public Message Message
|
|||
|
|
{
|
|||
|
|
get { return new Message(this); }
|
|||
|
|
}
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="alert"></param>
|
|||
|
|
public void Alert(string alert)
|
|||
|
|
{
|
|||
|
|
alert = alert.Replace("\r","");
|
|||
|
|
alert = alert.Replace("\n", "");
|
|||
|
|
new Extend.Scripts(this).Alert(alert);
|
|||
|
|
}
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20><><EFBFBD><EFBFBD>JavaScript<70><74>ʾ<EFBFBD><CABE>ʾ,<2C><>ʾ<EFBFBD>꣬<EFBFBD>رմ<D8B1><D5B4>ڣ<EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD>ڵ<EFBFBD><DAB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɺ<EFBFBD><C9BA><EFBFBD><EFBFBD><EFBFBD>ʾ
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="say"></param>
|
|||
|
|
public void AlertAndClose(string say)
|
|||
|
|
{
|
|||
|
|
if (!string.IsNullOrWhiteSpace(say) && say.Trim() != "")
|
|||
|
|
{
|
|||
|
|
say = say.Replace("\r", "\n");
|
|||
|
|
say = "<script type=\"text/javascript\">alert(\"" + say + "\");new top.PageBox().Close();</script>";
|
|||
|
|
//ScriptManager.RegisterClientScriptBlock(this.Page, typeof(UpdatePanel), "Alert", say, true);
|
|||
|
|
Page.ClientScript.RegisterStartupScript(typeof(string), "alert", say);
|
|||
|
|
//Page.ClientScript.RegisterClientScriptBlock(typeof(string), "alert", say);
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
this.Close();
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20><><EFBFBD><EFBFBD>JavaScript<70><74>ʾ<EFBFBD><CABE>ʾ,<2C><>ʾ<EFBFBD>꣬<EFBFBD>رմ<D8B1><D5B4>ڣ<EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD>ڵ<EFBFBD><DAB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɺ<EFBFBD><C9BA><EFBFBD><EFBFBD><EFBFBD>ʾ
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="say"></param>
|
|||
|
|
public void AlertCloseAndRefresh(string say)
|
|||
|
|
{
|
|||
|
|
if (!string.IsNullOrWhiteSpace(say) && say.Trim() != "")
|
|||
|
|
{
|
|||
|
|
say = say.Replace("\r", "\n");
|
|||
|
|
say = "<script type=\"text/javascript\">alert(\"" + say + "\"); window.top.PageBox.CloseAndRefresh(window.name);</script>";
|
|||
|
|
//ScriptManager.RegisterClientScriptBlock(this.Page, typeof(UpdatePanel), "Alert", say, true);
|
|||
|
|
Page.ClientScript.RegisterStartupScript(typeof(string), "alert", say);
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
this.Close();
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20><><EFBFBD><EFBFBD>JavaScript<70><74>ʾ<EFBFBD><CABE>ʾ,<2C><>ʾ<EFBFBD>꣬<EFBFBD>رմ<D8B1><D5B4>ڣ<EFBFBD>
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="say"></param>
|
|||
|
|
public void Close(string say)
|
|||
|
|
{
|
|||
|
|
if (!string.IsNullOrWhiteSpace(say) && say.Trim() != "")
|
|||
|
|
{
|
|||
|
|
say = say.Replace("\r", "\n");
|
|||
|
|
say = "<script type=\"text/javascript\">alert(\"" + say + "\");new top.PageBox().CloseAndRefresh();</script>";
|
|||
|
|
//ScriptManager.RegisterClientScriptBlock(this.Page, typeof(UpdatePanel), "Alert", say, true);
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
say = "<script type=\"text/javascript\">new top.PageBox().CloseAndRefresh();</script>";
|
|||
|
|
//ScriptManager.RegisterClientScriptBlock(this.Page, typeof(UpdatePanel), "Alert", say, true);
|
|||
|
|
}
|
|||
|
|
Page.ClientScript.RegisterStartupScript(typeof(string), "close", say);
|
|||
|
|
}
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20>رմ<D8B1><D5B4>ڣ<EFBFBD>
|
|||
|
|
/// </summary>
|
|||
|
|
public void Close()
|
|||
|
|
{
|
|||
|
|
string say = "";
|
|||
|
|
say = "<script type=\"text/javascript\">new top.PageBox().Close();</script>";
|
|||
|
|
//ScriptManager.RegisterClientScriptBlock(this.Page, typeof(UpdatePanel), "Alert", say, true);
|
|||
|
|
Page.ClientScript.RegisterStartupScript(typeof(string), "close", say);
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
/// <summary>
|
|||
|
|
/// ִ<><D6B4>js<6A>ű<EFBFBD><C5B1><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="func"></param>
|
|||
|
|
/// <param name="values"></param>
|
|||
|
|
public void JsFunction(string func, params string[] values)
|
|||
|
|
{
|
|||
|
|
string script = "<script language='JavaScript' type='text/javascript'>{js}</script>";
|
|||
|
|
string para = "";
|
|||
|
|
for (int i = 0; i < values.Length; i++)
|
|||
|
|
{
|
|||
|
|
para += "\"" + values[i] + "\"";
|
|||
|
|
if (i < values.Length-1) para += ",";
|
|||
|
|
}
|
|||
|
|
string js = func + "(" + para + ");";
|
|||
|
|
script = script.Replace("{js}", js);
|
|||
|
|
if (this == null) return;
|
|||
|
|
if (!ClientScript.IsStartupScriptRegistered(this.GetType(), "JsFunction"))
|
|||
|
|
{
|
|||
|
|
ClientScript.RegisterStartupScript(this.GetType(), "JsFunction", script);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
#region <EFBFBD><EFBFBD>ѯ<EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20><><EFBFBD><EFBFBD>ѯ<EFBFBD><D1AF><EFBFBD><EFBFBD><EFBFBD>Ŀؼ<C4BF>ת<EFBFBD><D7AA><EFBFBD><EFBFBD>query<72>ַ<EFBFBD><D6B7><EFBFBD>
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="panel"></param>
|
|||
|
|
/// <returns></returns>
|
|||
|
|
protected string SearchQuery(System.Web.UI.WebControls.Panel panel)
|
|||
|
|
{
|
|||
|
|
return new SearchQuery(panel).QueryString();
|
|||
|
|
}
|
|||
|
|
protected string SearchQuery()
|
|||
|
|
{
|
|||
|
|
return new SearchQuery(this).QueryString();
|
|||
|
|
}
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20><><EFBFBD>ӵ<EFBFBD>ַ<EFBFBD>IJ<EFBFBD><C4B2><EFBFBD>
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="url"></param>
|
|||
|
|
/// <param name="key"></param>
|
|||
|
|
/// <param name="value"></param>
|
|||
|
|
/// <returns></returns>
|
|||
|
|
protected string AddPara(string url, string key, object value)
|
|||
|
|
{
|
|||
|
|
string query = string.Empty;
|
|||
|
|
if (url.IndexOf('?') > -1)
|
|||
|
|
{
|
|||
|
|
query = url.Substring(url.IndexOf('?') + 1);
|
|||
|
|
url = url.Substring(0, url.IndexOf('?'));
|
|||
|
|
}
|
|||
|
|
if (string.IsNullOrWhiteSpace(query)) return string.Format("{0}?{1}={2}", url, key, value.ToString());
|
|||
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
string[] arr = query.Split('&');
|
|||
|
|
string tmQuery = string.Empty;
|
|||
|
|
bool isExist = false;
|
|||
|
|
for (int i = 0; i < arr.Length;i++ )
|
|||
|
|
{
|
|||
|
|
string[] t = arr[i].Split('=');
|
|||
|
|
if (t.Length < 2) continue;
|
|||
|
|
if (key.ToLower() == t[0].ToLower())
|
|||
|
|
{
|
|||
|
|
t[1] = value.ToString();
|
|||
|
|
isExist = true;
|
|||
|
|
}
|
|||
|
|
tmQuery += string.Format("{0}={1}&", t[0], t[1]);
|
|||
|
|
}
|
|||
|
|
if (!isExist) tmQuery += string.Format("{0}={1}&", key, value.ToString());
|
|||
|
|
if (tmQuery.EndsWith("&")) tmQuery = tmQuery.Substring(0, tmQuery.Length - 1);
|
|||
|
|
return url + "?" + tmQuery;
|
|||
|
|
}
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20><><EFBFBD><EFBFBD>ƴ<EFBFBD><C6B4>ҳ<EFBFBD><D2B3><EFBFBD>IJ<EFBFBD>ѯ<EFBFBD>ִ<EFBFBD>
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="key"></param>
|
|||
|
|
/// <param name="value"></param>
|
|||
|
|
/// <returns></returns>
|
|||
|
|
protected string AddPara(string key, object value)
|
|||
|
|
{
|
|||
|
|
return this.AddPara(this.Page.Request.RawUrl, key, value);
|
|||
|
|
}
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20><><EFBFBD><EFBFBD>ѯ<EFBFBD>ִ<EFBFBD><D6B4><EFBFBD><F3B6A8B5><EFBFBD>ѯ<EFBFBD>ؼ<EFBFBD><D8BC><EFBFBD>
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="panel"></param>
|
|||
|
|
/// <returns></returns>
|
|||
|
|
protected void SearchBind(System.Web.UI.WebControls.Panel panel)
|
|||
|
|
{
|
|||
|
|
new SearchQuery(panel).SearchBind();
|
|||
|
|
}
|
|||
|
|
protected void SearchBind()
|
|||
|
|
{
|
|||
|
|
new SearchQuery(this).SearchBind();
|
|||
|
|
}
|
|||
|
|
#endregion
|
|||
|
|
|
|||
|
|
#region <EFBFBD><EFBFBD>ʵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD>ؼ<EFBFBD>
|
|||
|
|
protected void EntityBind(WeiSha.Data.Entity entity)
|
|||
|
|
{
|
|||
|
|
if (entity == null) return;
|
|||
|
|
_entityBind(this, entity);
|
|||
|
|
}
|
|||
|
|
protected void EntityBind(System.Web.UI.WebControls.Panel panel,WeiSha.Data.Entity entity)
|
|||
|
|
{
|
|||
|
|
if (entity == null) return;
|
|||
|
|
_entityBind(panel, entity);
|
|||
|
|
}
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20>ݹ<EFBFBD><DDB9><EFBFBD><EFBFBD>ÿؼ<C3BF><D8BC><EFBFBD>ֵ
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="control"></param>
|
|||
|
|
/// <returns></returns>
|
|||
|
|
protected void _entityBind(System.Web.UI.Control control, WeiSha.Data.Entity entity)
|
|||
|
|
{
|
|||
|
|
foreach (Control c in control.Controls)
|
|||
|
|
{
|
|||
|
|
if (string.IsNullOrWhiteSpace(c.ID)) continue;
|
|||
|
|
_entityBindSingle(c, entity);
|
|||
|
|
}
|
|||
|
|
foreach (Control c in control.Controls)
|
|||
|
|
_entityBind(c,entity);
|
|||
|
|
}
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20><EFBFBD><F2B5A5B8>ؼ<EFBFBD><D8BC><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="control"></param>
|
|||
|
|
/// <param name="entity"></param>
|
|||
|
|
private void _entityBindSingle(System.Web.UI.Control c, WeiSha.Data.Entity entity)
|
|||
|
|
{
|
|||
|
|
//<2F><><EFBFBD><EFBFBD>ʵ<EFBFBD><CAB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
Type info = entity.GetType();
|
|||
|
|
PropertyInfo[] properties = info.GetProperties();
|
|||
|
|
for (int j = 0; j < properties.Length; j++)
|
|||
|
|
{
|
|||
|
|
PropertyInfo pi = properties[j];
|
|||
|
|
if (c.ID.Equals(pi.Name, StringComparison.CurrentCultureIgnoreCase))
|
|||
|
|
{
|
|||
|
|
//<2F><>ǰ<EFBFBD><C7B0><EFBFBD>Ե<EFBFBD>ֵ
|
|||
|
|
object obj = info.GetProperty(pi.Name).GetValue(entity, null);
|
|||
|
|
if (obj != null) _controlBindFunc(c, obj);
|
|||
|
|
break;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20><><EFBFBD>ؼ<EFBFBD><D8BC><EFBFBD>ֵ
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="control"></param>
|
|||
|
|
/// <param name="value"></param>
|
|||
|
|
private void _controlBindFunc(System.Web.UI.Control c, object value)
|
|||
|
|
{
|
|||
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD><CBB5><EFBFBD><EFBFBD><EFBFBD>ѡ<EFBFBD>б<EFBFBD><D0B1><EFBFBD><EFBFBD><EFBFBD>ѡ<EFBFBD>б<EFBFBD>
|
|||
|
|
if (c is DropDownList || c is CheckBoxList || c is RadioButtonList)
|
|||
|
|
{
|
|||
|
|
ListControl ddl = c as ListControl;
|
|||
|
|
ddl.SelectedIndex = ddl.Items.IndexOf(ddl.Items.FindByValue(value.ToString()));
|
|||
|
|
}
|
|||
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
if (c is TextBox || c is Label || c is Literal)
|
|||
|
|
{
|
|||
|
|
ITextControl txt = c as ITextControl;
|
|||
|
|
if (value == null) return;
|
|||
|
|
if (c is Literal)
|
|||
|
|
{
|
|||
|
|
txt.Text = value.ToString();
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
WebControl wc = c as WebControl;
|
|||
|
|
//<2F><>ʽ<EFBFBD><CABD><EFBFBD>ַ<EFBFBD>
|
|||
|
|
string fmt = wc.Attributes["Format"] == null ? null : wc.Attributes["Format"];
|
|||
|
|
if (fmt == null)
|
|||
|
|
{
|
|||
|
|
txt.Text = value.ToString();
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
if (value is System.DateTime)
|
|||
|
|
txt.Text = System.Convert.ToDateTime(value).ToString(fmt);
|
|||
|
|
if (value is int)
|
|||
|
|
txt.Text = System.Convert.ToInt32(value).ToString(fmt);
|
|||
|
|
if (value is float)
|
|||
|
|
txt.Text = System.Convert.ToSingle(value).ToString(fmt);
|
|||
|
|
if (value is double)
|
|||
|
|
txt.Text = System.Convert.ToDouble(value).ToString(fmt);
|
|||
|
|
if(value is decimal)
|
|||
|
|
txt.Text = System.Convert.ToDecimal(value).ToString(fmt);
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
//<2F><>ѡ<EFBFBD><D1A1><EFBFBD><EFBFBD>ѡ
|
|||
|
|
if (c is CheckBox || c is RadioButton)
|
|||
|
|
(c as CheckBox).Checked = Convert.ToBoolean(value);
|
|||
|
|
}
|
|||
|
|
#endregion
|
|||
|
|
|
|||
|
|
#region <EFBFBD><EFBFBD>ʵ<EFBFBD><EFBFBD><EFBFBD>ӽ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ؼ<EFBFBD><EFBFBD><EFBFBD>ȡֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20><>ָ<EFBFBD><D6B8>ʵ<EFBFBD><CAB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="entity"></param>
|
|||
|
|
protected WeiSha.Data.Entity EntityFill(WeiSha.Data.Entity entity)
|
|||
|
|
{
|
|||
|
|
return _entityFill(this, entity);
|
|||
|
|
}
|
|||
|
|
private WeiSha.Data.Entity _entityFill(System.Web.UI.Control control, WeiSha.Data.Entity entity)
|
|||
|
|
{
|
|||
|
|
foreach (Control c in control.Controls)
|
|||
|
|
{
|
|||
|
|
if (string.IsNullOrWhiteSpace(c.ID)) continue;
|
|||
|
|
//<2F><><EFBFBD><EFBFBD>ʵ<EFBFBD><CAB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
Type info = entity.GetType();
|
|||
|
|
PropertyInfo[] properties = info.GetProperties();
|
|||
|
|
for (int j = 0; j < properties.Length; j++)
|
|||
|
|
{
|
|||
|
|
PropertyInfo pi = properties[j];
|
|||
|
|
if (pi.Name == c.ID)
|
|||
|
|
{
|
|||
|
|
entity = _entityFillSingle(c, entity, pi.Name);
|
|||
|
|
break;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
foreach (Control c in control.Controls)
|
|||
|
|
entity = _entityFill(c, entity);
|
|||
|
|
return entity;
|
|||
|
|
}
|
|||
|
|
private WeiSha.Data.Entity _entityFillSingle(System.Web.UI.Control c, WeiSha.Data.Entity entity, string piName)
|
|||
|
|
{
|
|||
|
|
string value = "";
|
|||
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD><CBB5><EFBFBD><EFBFBD><EFBFBD>ѡ<EFBFBD>б<EFBFBD><D0B1><EFBFBD><EFBFBD><EFBFBD>ѡ<EFBFBD>б<EFBFBD>
|
|||
|
|
if (c is DropDownList || c is CheckBoxList || c is RadioButtonList)
|
|||
|
|
{
|
|||
|
|
ListControl ddl = c as ListControl;
|
|||
|
|
value = ddl.SelectedValue;
|
|||
|
|
}
|
|||
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
if (c is TextBox)
|
|||
|
|
{
|
|||
|
|
TextBox tb = c as TextBox;
|
|||
|
|
value = tb.Text;
|
|||
|
|
}
|
|||
|
|
//<2F><>ѡ<EFBFBD><D1A1><EFBFBD><EFBFBD>ѡ
|
|||
|
|
if (c is CheckBox || c is RadioButton)
|
|||
|
|
{
|
|||
|
|
CheckBox cb = c as CheckBox;
|
|||
|
|
value = cb.Checked.ToString();
|
|||
|
|
}
|
|||
|
|
//<2F><>ȡֵ<C8A1><D6B5>ת<EFBFBD>ij<EFBFBD><C4B3><EFBFBD><EFBFBD>Ե<EFBFBD><D4B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͣ<EFBFBD><CDA3><EFBFBD><EFBFBD><EFBFBD>ֵ
|
|||
|
|
var property = entity.GetType().GetProperty(piName);
|
|||
|
|
object tm = string.IsNullOrEmpty(value) ? null : WeiSha.Common.DataConvert.ChangeType(value, property.PropertyType);
|
|||
|
|
property.SetValue(entity,tm , null);
|
|||
|
|
return entity;
|
|||
|
|
}
|
|||
|
|
#endregion
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
}
|