PageBaseSetting
using System; using System.Collections.Generic; using System.Linq; using System.Text; using IDAL; using Model; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Xml.Linq; using System.IO; using System.Threading; using System.Collections.Specialized; using System.Collections; using System.Net; namespace Common { public class PageBaseSetting : Page { public IWeb_Cache Webcache = new IWeb_Cache(); public string WEBFileName = ""; public string WEBFilePath = ""; public string WEBURL = ""; public string WEBServerMapPath = ""; public string WebVPath = ""; public string AshxReturnStr = ""; private bool saveState = false; protected HttpSessionUser SessionUser; /********************************************************************* * * * COPY旧代码开始 * * * *********************************************************************/ protected virtual HttpSessionUser GetSessionUser() { return SessionManager.SessionUser; } /********************************************************************* * * * COPY旧代码结束 * * *********************************************************************/ protected override void OnLoad(EventArgs e) { WEBFileName = GetPageName(); WEBURL = GetUrl(); WEBServerMapPath = Server.MapPath("~/"); WebVPath = Request.ServerVariables["URL"].ToString().Trim(); HiddenField hfctrl = new HiddenField(); hfctrl.ID = "HdfTableInfo"; hfctrl.Value = GetTableName(); this.Page.Form.Controls.Add(hfctrl); Literal ltlctrl = new Literal(); ltlctrl.ID = "ltlScript"; ltlctrl.Text = ""; this.Page.Form.Controls.Add(ltlctrl); SolveRefresh("LOT_NO_KEYWORDS"); base.OnLoad(e); }
public void SetAshxReturnString(string keywords,Control controls_content ) { if (this.Page.FindControl(keywords) != null) { if(((TextBox)(this.Page.FindControl(keywords))).Text.ToString().ToString().Trim().Length>1){
AshxReturnStr = GetRequestJsonString("/Handler.ashx", "KeyWord=" + ((TextBox)(this.Page.FindControl(keywords))).Text.ToString().ToString() + "," + GetTableName().ToString()); string[] CtrlValueArr; string[] CtrlArr; CtrlValueArr = AshxReturnStr.Split(';'); for (int i = 0; i < CtrlValueArr.Length; i++) { CtrlArr = CtrlValueArr[i].Split(':'); string CtrlID = ""; if (CtrlArr.Length > 1) { foreach (Control ctrl in controls_content.Controls) { if (ctrl is TextBox) { String str = ctrl.ID.ToString();
String[] myarr; myarr = str.Split('_'); CtrlID = myarr[myarr.Length - 1].ToString();
if (CtrlID.ToUpper().ToString() == CtrlArr[0].ToString().ToUpper()) { if (CtrlArr[1].ToString().Trim().Length > 0) { ((TextBox)ctrl).Text = CtrlArr[1].ToString(); ((TextBox)ctrl).ReadOnly = true; } }
} }
} } } } } //重写Page OnPreInit事件 protected override void OnPreInit(EventArgs e) { SessionUser = GetSessionUser(); base.OnPreInit(e); }
///当前Request Url的文件名称 /// </summary> /// <returns>返回当前Request Url的文件名称</returns> public string GetRequestFilename() { return System.IO.Path.GetFileName(Request.Path); } public void MsgShow(String messageString) { base.RegisterStartupScript("", "<script>alert('" + messageString + "');</script>"); } /// <summary> /// 打开新的窗口 可以是模态可非模态 /// </summary> /// <param name="url">打开窗口URL地址</param> /// <param name="Wwidth">打开窗口宽度</param> /// <param name="Wheight">打开窗口高度</param> /// <param name="Wresizable">是否有滚动条 1为有滚动条,默认没有</param> /// <returns></returns> public string GetOpenWindowString(string url, string Wwidth, string Wheight, string Wresizable) { if (Wwidth.ToString().Trim().Length < 1) { Wwidth = "500"; } if (Wheight.ToString().Trim().Length < 1) { Wheight = "400"; } if (Wresizable.ToString().Trim().Length < 1) { Wresizable = "2"; } else { Wresizable = "1"; } string openstr = ""; openstr = "<script language='javascript'> window.showModalDialog('" + url.ToString() + "','dialogWidth:" + Wwidth.ToString() + "px;dialogHeight:" + Wheight.ToString() + "px;resizable=" + Wresizable.ToString() + ";');</script>";
return openstr; }
public string GetUrl() { return HttpContext.Current.Request.Url.ToString(); } /// <summary> /// 获得当前页面的名称 /// </summary> /// <returns>当前页面的名称</returns> public string GetPageName() { string[] urlArr = HttpContext.Current.Request.Url.AbsolutePath.Split('/'); return urlArr[urlArr.Length - 1].ToLower(); } /// <summary> /// 根据文件名称获取表名称;文件名称以_分开各部分,其中倒数第二个是相关表名 /// </summary> /// <returns>返回表名称</returns> public string GetTableName() { string webpagestr = ""; webpagestr = ((HiddenField)(this.Page.FindControl("TABLE_NAME"))).Value.ToString(); return webpagestr.ToUpper().ToString().Trim(); }
/// <summary> /// 弹出新的窗口 可以是模态可非模态 /// </summary> /// <param name="url">窗口URL</param> /// <param name="Wwidth">窗口宽度</param> /// <param name="Wheight">窗口高度</param> /// <param name="Wresizable">是否有滚动条 1为有滚动条,默认没有</param> public void PopUpNewWindow(string url, string Wwidth, string Wheight, string Wresizable) { if (Wwidth.ToString().Trim().Length < 1) { Wwidth = "500"; } if (Wheight.ToString().Trim().Length < 1) { Wheight = "400"; } if (Wresizable.ToString().Trim().Length < 1) { Wresizable = "2"; } else { Wresizable = "1"; } string openstr = ""; openstr = "<script language='javascript'> window.showModalDialog('" + url.ToString() + "','dialogWidth:" + Wwidth.ToString() + "px;dialogHeight:" + Wheight.ToString() + "px;resizable=" + Wresizable.ToString() + ";');</script>"; ((Literal)(this.Page.Form.FindControl("ltlScript"))).Text = openstr; } /// <summary> /// 加载css样式表 /// </summary> /// <param name="cssFilePath">样式文件地址参数</param> public void AddIncludeCssFile2Page(string cssFilePath) { HtmlGenericControl child = new HtmlGenericControl("link"); child.Attributes.Add("href", cssFilePath); child.Attributes.Add("rel", "stylesheet"); child.Attributes.Add("type", "text/css"); Page handler = (Page)HttpContext.Current.Handler; handler.Header.Controls.Add(child); } /// <summary> /// 向页面添加页面标题、关键字、描述 /// </summary> /// <param name="Title">标题参数</param> /// <param name="Keywords">关键字参数</param> /// <param name="Webdesc">描述参数</param> public void AddKeyWordsWebdescMeta(String Title, String Keywords, String Webdesc) { HtmlMeta keywords = new HtmlMeta(); HtmlMeta desription = new HtmlMeta(); keywords.Name = "keywords"; keywords.Content = Keywords.ToString().Trim(); desription.Name = "description"; desription.Content = Webdesc.ToString().Trim(); Page handler = (Page)HttpContext.Current.Handler;
handler.Header.Controls.Add(keywords); handler.Header.Controls.Add(desription); handler.Title = Title.Trim();
} /// <summary> /// 通过JS文件地址,动态加载JS文件 /// </summary> /// <param name="JS_SRC">JS文件地址参数</param> public void AddJs2Web(String Js_Src) { HtmlGenericControl JSControl = new HtmlGenericControl("script"); JSControl.Attributes.Add("type", "text/javascript"); JSControl.Attributes.Add("src", Js_Src); Page handler = (Page)HttpContext.Current.Handler;
handler.Header.Controls.Add(JSControl); } /// <summary> /// 获取ASHX文件返回值 /// </summary> /// <param name="relativePath">ASHX文件相对地址</param> /// <param name="data">ASHX接收参数</param> /// <returns>返回处理后的数据</returns> public string GetRequestJsonString(string relativePath, string data) { string requestUrl = GetRequestUrl(relativePath, data); //Response.Write(requestUrl); try { WebRequest request = WebRequest.Create(requestUrl); request.Method = "GET";
StreamReader jsonStream = new StreamReader(request.GetResponse().GetResponseStream()); string jsonObject = jsonStream.ReadToEnd();
return jsonObject; } catch { return string.Empty; } } public string GetRequestUrl(string relativePath, string data) { string absolutePath = HttpContext.Current.Request.Url.AbsoluteUri; string hostNameAndPort = HttpContext.Current.Request.Url.Authority; string applicationDir = HttpContext.Current.Request.ApplicationPath; StringBuilder sbRequestUrl = new StringBuilder();
sbRequestUrl.Append(absolutePath.Substring(0, absolutePath.IndexOf(hostNameAndPort))); sbRequestUrl.Append(hostNameAndPort); sbRequestUrl.Append(applicationDir); sbRequestUrl.Append(relativePath);
if (!string.IsNullOrEmpty(data)) { sbRequestUrl.Append("?"); sbRequestUrl.Append(data); }
return sbRequestUrl.ToString();
}
public void SolveRefresh(string LOT_NO_KEYWORDS) { if (this.Page.FindControl(LOT_NO_KEYWORDS) != null) { if (((TextBox)this.Page.FindControl(LOT_NO_KEYWORDS.ToString())).Text.ToString().Length > 2) { AshxReturnStr = GetControlIdValue(((TextBox)this.Page.FindControl(LOT_NO_KEYWORDS.ToString())).Text.ToString(), "");// GetRequestJsonString("/Handler.ashx", "KeyWord=" + ((TextBox)(this.Page.FindControl("LOT_NO_KEYWORDS"))).Text.ToString().ToString() + "," + GetTableName().ToString()); // Response.Write(AshxReturnStr);
string[] CtrlValueArr; string[] CtrlArr; CtrlValueArr = AshxReturnStr.Split(';'); for (int i = 0; i < CtrlValueArr.Length; i++) { CtrlArr = CtrlValueArr[i].Split(':'); string CtrlID = "txt_" + GetTableName().ToUpper() + "_" + CtrlArr[0].ToString().ToUpper(); if (CtrlArr.Length > 1) { if (this.Page.FindControl(CtrlID.ToString()) != null) { ((TextBox)this.Page.FindControl(CtrlID.ToString())).Text = CtrlArr[1].ToString();// ((TextBox)( this.Page.FindControl(CtrlID.ToString())).Text = CtrlArr[1].ToString(); ((TextBox)this.Page.FindControl(CtrlID.ToString())).ReadOnly = true; } }
} } } } public string GetControlIdValue(String LOTNO, String CO_CODE ) { if (CO_CODE.ToString().Length < 2) { CO_CODE = "L2300"; } String Str_Keywords = ""; System.Data.DataSet ds = new System.Data.DataSet(); String SQLSTR = ""; String AutoSqlStr = ""; String TABLENAME=""; TABLENAME=GetTableName().ToUpper(); if (LOTNO.ToString().Trim().Length < 5 || TABLENAME.ToString().Trim().Length < 3) { } else { String SELECT = "usr_lst.usr_id,usr_lst.usr_name,prod_lst.prod_pn,prod_lst.pn_desc,proc_opr.mc_id,proc_hist.flow_id,proc_hist.wip_seq,proc_hist.proc_id,proc_hisT.IN_TIME,PROC_HIST.OUT_TIME"; AutoSqlStr = @"SELECT $SELECT$ FROM proc_hist, proc_opr, lot_info, prod_lst,usr_lst WHERE lot_info.co_code = proc_hist.co_code and lot_info.prod_pn=prod_lst.prod_pn and lot_info.co_code=prod_lst.co_code and usr_lst.usr_id=proc_opr.proc_USR_ID and usr_lst.co_code=proc_opr.co_code AND lot_info.wip_id = proc_hist.wip_id AND proc_opr.co_code = proc_hist.co_code AND proc_opr.wip_id = proc_hist.wip_id AND proc_opr.proc_ref = proc_hist.proc_ref AND lot_info.co_code = '$COCODE$' AND lot_info.lot_no = '$LOTNO$' and proc_hist.proc_id = '$PROCID$';";
if (TABLENAME.ToString().ToLower() == "procexception") { SQLSTR = @"SELECT prod_lst.PROD_PN JDITNR,prod_lst.PN_DESC JDITDC FROM lot_info, prod_lst WHERE lot_info.prod_pn=prod_lst.prod_pn and lot_info.co_code=prod_lst.co_code AND lot_info.co_code = 'L2300' AND lot_info.lot_no = '$LOTNO$' limit 100;"; SQLSTR = SQLSTR.Replace("$LOTNO$", LOTNO); } SQLSTR = SQLSTR.ToUpper();
if (SQLSTR.ToString().Trim().Length > 30) { ds.Clear(); ds = MTS2.DBUtility.MySqlServerHelper.ExecuteDataSet(SQLSTR);
}
}
System.Data.DataTable table = new System.Data.DataTable(); Str_Keywords = "";
if (ds.Tables != null) { if (ds.Tables.Count > 0) { table = ds.Tables[0]; for (int j = 0; j < table.Rows.Count; j++) { for (int i = 0; i < table.Columns.Count; i++) { Str_Keywords = Str_Keywords + table.Columns[i].ColumnName.ToUpper() + ":" + table.Rows[j][i].ToString() + ";"; } } } } return Str_Keywords; } } }