using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using LIMS.MessageBox; using CY.Model; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls; using CY.Model.Inquiry; using CY.Infrastructure.Common; using CY.BLL; using CY.Infrastructure.Logging; using CY.Infrastructure.Configuration; using CY.BLL.Inquiry; using CY.BLL.Sys; namespace CY.WebForm { /// /// 基础页面类 /// public class MainPage : Page { EC_MemberBasicBLL bll_EC_MemberBasicBLL = new EC_MemberBasicBLL(); Pay_PaymentAccountBLL bll_Pay_PaymentAccountBLL = new Pay_PaymentAccountBLL(); #region 构造 /// /// 构建一个新的Page /// public MainPage() { Load += new EventHandler(LimsPage_Load); } public void LimsPage_Load(object sender, EventArgs e) { base.OnPreLoad(e); this.Response.Cache.SetNoStore(); try { this.Header.Title = this.Header.Title + " - 印刷行业在线交易平台"; } catch { LoggingFactory.GetLogger().Log(this.Request.Url.AbsolutePath); } //SendToRealUrl(); HtmlMeta meta = new HtmlMeta(); meta.HttpEquiv = "X-UA-Compatible"; meta.Content = "IE=EmulateIE7"; string customerId = string.Empty; //表示厂商设置 if (Request["SetFirm"] != null) { Utils.WriteCookie("SetCustomerId", string.Empty, -1); } //表示客户设置 if (Request["CustomerId"] != null) { customerId = Request["CustomerId"].ToString(); Utils.WriteCookie("SetCustomerId", customerId); } } protected void SendToRealUrl() { //if (!CY.Config.WebInfo.Instance.WebStatus.ToBoolean2()) //{ // Server.Transfer("Http://" + CY.Config.WebInfo.Instance.WebDomain + "/Close.html"); //} HttpContext httpCurrent = HttpContext.Current; HttpRequest req = httpCurrent.Request; string oUrl = req.Url.AbsoluteUri; string oHome = req.Url.Host; string endStr = string.Empty; string realDomain = oHome.Replace(".cyin.cn", ""); int bid = bll_EC_MemberBasicBLL.GetBid(realDomain); if (bid == -1 || bid == 0) { return; } else { string realHome = "Http://" + CY.Config.WebInfo.Instance.WebDomain + "/Pages/Templet/Default"; endStr = GetEndStr(oHome, oUrl); if (string.IsNullOrEmpty(endStr)) { endStr = "CompanyIndex.aspx"; } realHome = realHome + "/" + endStr + "?i=" + bid; Server.Transfer(realHome); } } private string GetEndStr(string oHome, string oUrl) { string endStr = string.Empty; int i = oUrl.IndexOf(oHome); int k = oUrl.IndexOf('/', i); if (k >= 0) { endStr = oUrl.Substring(k + 1, oUrl.Length - k - 1); } return endStr; } protected override void OnPreLoad(EventArgs e) { //try //{ // this.Header.Controls.Add(meta); //} //catch(Exception ex) //{ // LoggingFactory.GetLogger().Log(this.Request.Url.AbsolutePath); //} } #endregion #region 提供输出javascript到当前页面的方法 /// /// 提供输出javascript到当前页面的方法 /// public class JavaScript { #region 显示IE浏览器端的对话框 /// /// 显示IE浏览器端的对话框 /// /// 信息 /// 源页面 /// 是否关闭窗口 public static void MessageBox(string Message, System.Web.UI.Page page, bool IsClose) { Type cstype = page.GetType(); string guid = Guid.NewGuid().ToString(); try { LIMS.MessageBox.MessageBox tmp_box = new LIMS.MessageBox.MessageBox(); tmp_box.ID = "__LIMSBox_" + guid; tmp_box.CssClass = "LIMSMessageBox"; tmp_box.Visible = false; page.Form.Controls.Add(tmp_box); } catch { } MessageBox box = (MessageBox)page.FindControl("__LIMSBox_" + guid); if (box == null) { Message = Message.Replace("\r\n", "\\r\\n").Replace("'", "\""); if (IsClose) { page.ClientScript.RegisterStartupScript(cstype, "MessageBox", string.Format("", Message)); } else { page.ClientScript.RegisterStartupScript(cstype, "MessageBox", string.Format("", Message)); } } else { Message = Message.Replace("\r\n", "\\r\\n").Replace("\\r\\n", "
").Replace("\\n", "
").Replace("\\\\", "\\").Replace("'", "\""); box.Show("温馨提示", Message, page, IsClose); } } #endregion #region 显示IE浏览器端的对话框并且跳转页面 /// /// 显示IE浏览器端的对话框并且跳转页面 /// /// 消息 /// 源页面 public static void MessageBox(string Message, System.Web.UI.Page page) { string script = "alertMsg('" + Message + "')"; JavaScript.ExecuteClientScript("key", script, page); } /// /// 显示IE浏览器端的对话框并且跳转页面 /// /// 消息 /// 源页面 public static void MessageBoxandhideLoadingIndicator(string Message, System.Web.UI.Page page) { string script = "alertMsg('" + Message + "');hideLoadingIndicator();"; JavaScript.ExecuteClientScript("key", script, page); } /// /// 显示对话框 /// /// 消息 /// /// 是否关闭 /// 是否刷新父窗口 public static void MessageBox(string Message, System.Web.UI.Page page, bool IsClose, bool IsRefreshParent) { string jsfn = ""; if (IsClose && IsRefreshParent) jsfn = "top.frmright.ReLoad();top.Dialog.close();"; else if (IsClose) jsfn = "top.Dialog.close();"; else if (IsRefreshParent) jsfn = "top.frmright.ReLoad();"; string script = string.Format("alertMsg('{0}');{1}", Message, jsfn); JavaScript.ExecuteClientScript("key", script, page); } /// /// 显示对话框 /// /// 消息 /// /// 是否关闭 /// 是否刷新父窗口 public static void MessageBoxsssss(string Message, System.Web.UI.Page page, bool IsClose, bool IsRefreshParent) { string jsfn = ""; if (IsClose && IsRefreshParent) jsfn = "top.frmright.document.getElementById('btn_Search').click();top.Dialog.close();"; else if (IsClose) jsfn = "top.Dialog.close();"; else if (IsRefreshParent) jsfn = "top.frmright.document.getElementById('btn_Search').click();"; string script = string.Format("alertMsg('{0}');{1}", Message, jsfn); JavaScript.ExecuteClientScript("key", script, page); } /// /// 显示对话框,给父页面控件赋值 /// /// 消息 /// /// 是否关闭 /// 是否刷新父窗口 public static void MessageBoxfuzhi(string Message, System.Web.UI.Page page, bool IsClose, string kongjian,string fileUrl) { string jsfn = ""; if (IsClose && !string.IsNullOrEmpty(kongjian)) jsfn = "top.frmright.document.getElementById('" + kongjian + "').src = '"+ fileUrl + "';top.frmright.document.getElementById('view" + kongjian + "').href = '" + fileUrl + "';top.frmright.document.getElementById('hide" + kongjian + "').value = '" + fileUrl + "';top.Dialog.close();"; else if (IsClose) jsfn = "top.Dialog.close();"; else if (!string.IsNullOrEmpty(kongjian)) jsfn = "top.frmright.document.getElementById('" + kongjian + "').src = '" + fileUrl + "';top.frmright.document.getElementById('view" + kongjian + "').href = '" + fileUrl + "';top.frmright.document.getElementById('hide" + kongjian + "').value = '" + fileUrl + "';"; string script = string.Format("alertMsg('{0}');{1}", Message, jsfn); JavaScript.ExecuteClientScript("key", script, page); } /// /// 显示对话框 /// /// 消息 /// /// 是否关闭 /// 是否刷新父窗口 public static void MessageBoxs(string Message, System.Web.UI.Page page, bool IsClose, bool IsRefreshParent) { string jsfn = ""; if (IsClose && IsRefreshParent) jsfn = "parent.ReLoad();parent.Dialog.close();"; else if (IsClose) jsfn = "parent.Dialog.close();"; else if (IsRefreshParent) jsfn = "parent.ReLoad();"; string script = string.Format("alertMsg('{0}');{1}", Message, jsfn); JavaScript.ExecuteClientScript("key", script, page); } /// /// 显示对话框,刷新第一个窗体和父窗体 /// /// 消息 /// public static void MessageBoxCloseAndRefreshparent(string Message, System.Web.UI.Page page) { string jsfn = "top.document.getElementById('_DialogFrame_0').contentWindow.ReWindowSelf();top.Dialog.close();"; string script = string.Format("alertMsg('{0}');{1}", Message, jsfn); JavaScript.ExecuteClientScript("key", script, page); } /// /// 显示对话框,刷新第一个窗体和父窗体 /// /// 消息 /// public static void MessageBoxCloseAndRefreshFirst(string Message, System.Web.UI.Page page) { string jsfn = "top.document.getElementById('_DialogFrame_0').contentWindow.ReWindowSelf();top.frmright.ReLoad();top.Dialog.close();"; string script = string.Format("alertMsg('{0}');{1}", Message, jsfn); JavaScript.ExecuteClientScript("key", script, page); } /// /// 显示对话框,刷新第一个窗体和父窗体 /// /// 消息 /// public static void MessageBoxCloseAndRefreshFirsts(string Message, System.Web.UI.Page page) { string jsfn = "top.document.getElementById('_DialogFrame_0').contentWindow.ReWindowSelf();top.Dialog.close();"; string script = string.Format("alertMsg('{0}');{1}", Message, jsfn); JavaScript.ExecuteClientScript("key", script, page); } /// /// 显示对话框,刷新第一个窗体和父窗体(父窗体为切换框) /// /// 消息 /// public static void MessageBoxAndFirstRefresh(string Message, System.Web.UI.Page page, bool IsClose) { string jsfn = ""; if (IsClose) jsfn = "top.frmright.frmrightChild.ReLoad();top.Dialog.close();"; else jsfn = "top.document.getElementById('_DialogFrame_0').contentWindow.ReWindowSelf();top.frmright.frmrightChild.ReLoad();"; string script = string.Format("alertMsg('{0}');{1}", Message, jsfn); JavaScript.ExecuteClientScript("key", script, page); } /// /// 提示信息并附加后续操作 /// /// 消息 /// 源页面 /// 后续操作 public static void MessageBox(string Message, System.Web.UI.Page page, string jsfn) { string script = string.Format("alertMsg('{0}');{1}", Message, jsfn); JavaScript.ExecuteClientScript("key", script, page); } /// /// 提示信息并刷新 /// /// 消息 /// 源页面 /// 是否刷新(默认刷新) public static void MessageBox(string Message, System.Web.UI.Page page, Int16 isRefresh = 1) { MessageBox(Message, page, 1 == isRefresh ? "global.delayrefresh();" : ""); } #endregion #region 执行IE浏览器端的脚本 /// /// 执行IE浏览器端的脚本 /// /// 脚本功能函数名或函数 /// 脚本语句 /// 源页面 public static void ExecuteClientScript(string key, string script, Page page) { Type cstype = page.GetType(); page.ClientScript.RegisterStartupScript(cstype, key, string.Format("", script)); } public static void RegisterStartupScript(string key, string script, Page page) { if (!page.ClientScript.IsStartupScriptRegistered(page.GetType(), key)) page.ClientScript.RegisterStartupScript(page.GetType(), key, string.Format("", script)); } #endregion #region 显示错误信息 /// /// 显示错误信息 /// /// 当前页 /// 弹出警告信息 /// 错误页面信息 public static void ShowError(Page page, string msg, string detail) { if (!string.IsNullOrEmpty(msg)) { ResponseMsg(page, msg); } if (!string.IsNullOrEmpty(detail)) { // page.Response.Write(string.Format("", LimsConfiguration.LimsWebURL, detail)); page.Response.Write(string.Format("", WebSiteSetting.HomepageURL, detail)); } } #endregion #region 超时//todo /// /// 超时 /// public static void ShowTimeOut(Page page) { ResponseMsg(page, "连接超时,请重新登录!"); page.Response.Write(""); } #endregion #region 后退 /// /// 后退 /// public static void GoBack(Page page) { page.Response.Write(""); } #endregion #region 刷新父窗口 /// /// 刷新父窗口 /// public static void RefreshParent(Page page) { RegisterStartupScript("key", "top.frmright.ReLoad();", page); } #endregion #region 刷新弹出窗口 /// /// 刷新弹出窗口 /// public static void RefreshOpener(Page page) { page.Response.Write(""); } #endregion #region 关闭当前窗口并刷新父页面 /// /// 关闭当前窗口并刷新父页面 /// public static void RefreshDIVOpener(Page page) { //page.Response.Write(""); //page.Response.Write(""); //ExecuteClientScript("key", "RefreshDIVOpener()", page); //ExecuteClientScript("key", "RefreshDIVOpener();", page); RegisterStartupScript("clientScript", "top.frmright.ReLoad();top.Dialog.close();", page); } /// /// 关闭当前弹出窗口 /// public static void CloseDIVOpener(Page page) { //page.Response.Write(""); page.Response.Write(""); //ExecuteClientScript("key", "RefreshDIVOpener()", page); } public void RefreshOpener(Page page, string location) { page.Response.Write(string.Format("", location)); } #endregion #region 刷新窗口 /// /// 刷新窗口 /// public static void RefreshSelf(Page page) { page.Response.Write(""); } #endregion #region 刷新本页面 /// /// 刷新窗口 /// public static void RefreshThis(Page page) { page.Response.Write(""); } #endregion #region 关闭窗口 /// /// 关闭窗口 /// public static void CloseWindow(Page page) { page.Response.Write(""); } #endregion #region 信息格式化 /// /// 信息格式化 /// /// 信息 public static void ResponseMsg(Page page, string alertMessage) { if (alertMessage.IndexOf("\'") != -1) { alertMessage = alertMessage.Replace("\'", "\\'"); } if (alertMessage.IndexOf("\n") != -1) { alertMessage = alertMessage.Replace("\n", "\\n"); } if (alertMessage.IndexOf("\r") != -1) { alertMessage = alertMessage.Replace("\r", "\\r"); } if (alertMessage.IndexOf("\t") != -1) { alertMessage = alertMessage.Replace("\t", "\\t"); } page.Response.Write(""); } #endregion } #endregion #region 当前登录用户 /// /// 当前登录用户 /// public EC_MemberBasic CurrentUser { get { EC_MemberBasic m_EC_MemberBasic = Session["nowMemberLogin"] as EC_MemberBasic; //登录帐号 //EC_MemberBasic m_EC_MemberBasic = bll_EC_MemberBasicBLL.GetMemberByLogin("15012345678", "123456+");//厂商测试帐号 //EC_MemberBasic m_EC_MemberBasic = bll_EC_MemberBasicBLL.GetMemberByLogin("a1a45s1d4a", "123456+");//个人网店帐号 //EC_MemberBasic m_EC_MemberBasic = bll_EC_MemberBasicBLL.GetMemberByLogin("buyer", "123456+"); //管理员帐号 //EC_MemberBasic m_EC_MemberBasic = bll_EC_MemberBasicBLL.GetMemberByLogin("admin", "123456+"); //管理员帐号 return m_EC_MemberBasic; } set { Session["nowMemberLogin"] = value; } } /// /// 判断用户是否登录 /// public string IsLogin { get { if (CurrentUser != null) return "true"; else return "false"; } } /// /// 当前登录用户的账户 /// public Pay_PaymentAccount CurrentPayAccount { get { if (CurrentUser == null) { return new Pay_PaymentAccount(); } else { Pay_PaymentAccount m_Pay_PaymentAccount = bll_Pay_PaymentAccountBLL.GetModel(CurrentUser.MemberId); return m_Pay_PaymentAccount; } } } /// /// 当前登录用户的资料表 /// public EC_MemberExtend CurrentMemberExtend { get { if (CurrentUser == null) { return new EC_MemberExtend(); } else { EC_MemberExtend m_EC_MemberExtend = bll_EC_MemberBasicBLL.GetMemberExtendByMemberId(CurrentUser.MemberId); return m_EC_MemberExtend; } } } /// /// 管理员的账户 /// public Pay_PaymentAccount AdminAccount { get { Pay_PaymentAccount m_Pay_PaymentAccount = bll_Pay_PaymentAccountBLL.GetModel(Guid.Parse("11111111-1111-1111-1111-111111111111")); return m_Pay_PaymentAccount; } } #endregion #region 权限判断 #endregion #region 错误处理 protected void Page_Error(object sender, EventArgs e) { var ex = Server.GetLastError(); HandleException(ex); Server.ClearError(); } protected void HandleException(Exception ex) { bool rethrow = false; //var exManager = EnterpriseLibraryContainer.Current.GetInstance(); //rethrow = exManager.HandleException(ex, policy); //if (rethrow) //{ // this.RedirectPermanent("~/error.aspx"); //} LoggingFactory.InitializeLogFactory(new Log4NetAdapter()); CY.Infrastructure.Logging.ILogger logger = LoggingFactory.GetLogger(); logger.Log(ex); this.RedirectPermanent("/error.html"); } protected void PAGEHandleException(Exception ex) { bool rethrow = false; LoggingFactory.InitializeLogFactory(new Log4NetAdapter()); CY.Infrastructure.Logging.ILogger logger = LoggingFactory.GetLogger(); logger.Log(ex); } #endregion #region 重定向 /// /// 永久重定向 /// /// protected void RedirectPermanent(string url) { // JavaScript.ExecuteClientScript("key", "hideWaitDiv();window.location.href=" + url, this); Response.Redirect(url); } #endregion #region 方法 /// /// 设置控件为只读 /// /// Web控件 protected void SetControlReadOnly(Control _Control) { if (_Control is WebControl) { WebControl __Control = (WebControl)_Control; __Control.Attributes.Add("readonly", "readonly"); __Control.CssClass = "readonly"; } else if (_Control is HtmlControl) { HtmlControl __Control = (HtmlControl)_Control; __Control.Attributes.Add("readonly", "readonly"); __Control.Attributes.Add("class", "readonly"); } } /// /// 批量操作,让控件只读:GOFI XIAO 2007-08-09 /// /// protected void SetControlReadOnly(params Control[] arr) { foreach (Control c in arr) { SetControlReadOnly(c); } } /// /// 获取URL传入参数并赋值给对应控件 /// /// 控件 /// URL参数名 /// 是否成功 protected bool SetURLParameter(Control control, string QueryStringName) { if (!string.IsNullOrEmpty(Request.QueryString[QueryStringName])) { string QueryStringValue = Request.QueryString[QueryStringName].ToString().Trim(); if (control is TextBox) { ((TextBox)control).Text = QueryStringValue; return true; } else if (control is HiddenField) { ((HiddenField)control).Value = QueryStringValue; return true; } else if (control is DropDownList) { ((DropDownList)control).SelectedValue = QueryStringValue; return true; } return false; } return true; } #endregion #region 询价及其设置使用的公共参数 /// /// 获取询价公共条件类实例 /// public InquiryCondition InquiryConditionObj { get { InquiryCondition obj = new InquiryCondition(); if (CurrentUser.MemberType == "印刷厂商" || CurrentUser.MemberType == "个人网店") { obj.FirmId = CurrentUser.MemberId; } else { obj.FirmId = Guid.Parse(UtilConst.AdminFirmId); } if (SetCustomerId != Guid.Empty) { obj.CustomerId = SetCustomerId; obj.ActualFirmId = obj.CustomerId; } else { obj.CustomerId = Guid.Empty; obj.ActualFirmId = obj.FirmId; } if (obj.CustomerId == Guid.Empty) { if (CurrentUser.MemberType == "印刷厂商" || CurrentUser.MemberType == "个人网店") { EC_MemberBasicBLL memberBasic = new EC_MemberBasicBLL(); obj.InquiryId = memberBasic.GetMemberByMemberId(CurrentUser.MemberId).InquiryId; } else { obj.InquiryId = Guid.Parse(UtilConst.AdminFirmId); } } else { OA_CorporateClientsBLL _oA_CorporateClientsBLL = new OA_CorporateClientsBLL(); obj.InquiryId = _oA_CorporateClientsBLL.GetModel(obj.CustomerId).InquiryId; } return obj; } } /// /// 要设置询价参数的客户编号 /// public Guid SetCustomerId { get { string customerId = string.Empty; customerId = Utils.GetCookie("SetCustomerId"); if (!string.IsNullOrEmpty(customerId)) { return Guid.Parse(customerId); } else { return Guid.Empty; } } } /// /// 印刷类型 /// public int PrintingTypeId { get { if (Session["Operate"] != null) { if (Request["Operate"] != null) { if (Session["Operate"].ToString() == Request["Operate"].ToString()) { if (Request["PrintingTypeId"] != null) { Session["PrintingTypeId"] = Request["PrintingTypeId"].ToString(); } } else { Session["PrintingTypeId"] = null; Session["Operate"] = Request["Operate"].ToString(); } } } else { if (Request["Operate"] != null) { Session["Operate"] = Request["Operate"].ToString(); Session["PrintingTypeId"] = null; } } if (Session["PrintingTypeId"] != null) { return int.Parse(Session["PrintingTypeId"].ToString()); } else { return -1; } } } /// /// 根据印刷类型获取快速设价提示信息 /// /// /// public string GetFastSetMsg(int printTypeId) { string fastSetMsg = string.Empty; ///只有用户没有自己保存过询价价格时快速设价才起作用(管理员除外) if (InquiryConditionObj.FirmId != Guid.Parse(UtilConst.AdminFirmId)) { if (InquiryConditionObj.InquiryId == Guid.Parse(UtilConst.AdminFirmId)) { FastSetByFirmBLL fastSetByFirmBLL = new FastSetByFirmBLL(); if (fastSetByFirmBLL.IsExits(InquiryConditionObj.FirmId, InquiryConditionObj.CustomerId, printTypeId)) { Inquiry_FastSetByFirm model = fastSetByFirmBLL.GetModel(InquiryConditionObj.FirmId, InquiryConditionObj.CustomerId, printTypeId); if (model != null) { if (model.FastValue != 100) { SysInquiry_PrintingTypeBLL _printingTypeBLL = new SysInquiry_PrintingTypeBLL(); SysInquiry_PrintingType printTypeModel = _printingTypeBLL.GetModelById(printTypeId); fastSetMsg = printTypeModel.PrintName + "已设置快速价格为系统初始价格的" + model.FastValue + "%,以下价格都是系统初始价格"; } } } } } return fastSetMsg; } /// /// 返回Decimal样式 /// /// /// public string GetDecimalStr(object obj) { if (obj == null) { return "0"; } decimal num = (decimal)obj; string str = num.ToString(); int index = str.IndexOf('.'); if (index == -1) { return str; } else { string str1 = str.Substring(0, index); string str2 = str.Substring(index + 1, str.Length - index - 1); str2 = str2.TrimEnd('0'); if (string.IsNullOrEmpty(str2)) { return str1; } else { return str1 + "." + str2; } } } #endregion } }