我有没有面板的母版页。我想在用户单击内容占位符页面的链接按钮时使用外观模式来查看适当的面板或一组面板。
在第一个帐户加载(初始状态)时,第一个面板将可见,其他面板关闭,而用户单击登录页面的链接按钮,第二个面板可见,其他面板关闭。
我如何创建这个基类newManageClass:
public class newManageClass : System.Web.UI.Page
{
public Panel Panel_User_Photo { get; set; }
public Panel Panel_Search { get; set; }
public Panel Panel_notification { get; set; }
public Panel Panel_companymanagement { get; set; }
public Panel Panel_omwealthmanagement { get; set; }
public Panel Panel_newsletter { get; set; }
public newManageClass()
{
Panel_User_Photo = new Panel();
Panel_Search = new Panel();
Panel_notification = new Panel();
Panel_companymanagement = new Panel();
Panel_omwealthmanagement = new Panel();
Panel_newsletter = new Panel();
}
public void OnPageLoad()
{
Panel_User_Photo.Visible = true;
Panel_Search.Visible = true;
Panel_notification.Visible = true;
Panel_companymanagement.Visible = false;
Panel_omwealthmanagement.Visible = false;
Panel_newsletter.Visible = false;
}
public void CompanyManagementClick()
{
Panel_User_Photo.Visible = false;
Panel_Search.Visible = true;
Panel_companymanagement.Visible = true;
Panel_notification.Visible = false;
Panel_omwealthmanagement.Visible = false;
Panel_newsletter.Visible = false;
}
public void OmWealthManagementClick()
{
Panel_User_Photo.Visible = false;
Panel_Search.Visible = true;
Panel_notification.Visible = false;
Panel_companymanagement.Visible = false;
Panel_omwealthmanagement.Visible = true;
Panel_newsletter.Visible = false;
}
public void NewsLetterManagementClick()
{
Panel_User_Photo.Visible = false;
Panel_Search.Visible = false;
Panel_notification.Visible = false;
Panel_companymanagement.Visible = false;
Panel_omwealthmanagement.Visible = false;
Panel_newsletter.Visible = true;
}
public void UserManagementClick()
{
Panel_User_Photo.Visible = false;
Panel_Search.Visible = true;
Panel_notification.Visible = false;
Panel_companymanagement.Visible = false;
Panel_omwealthmanagement.Visible = false;
Panel_newsletter.Visible = false;
}
protected override void OnPreInit(EventArgs e)
{
base.OnPreInit(e);
if (Session["MyTheme"] == null)
{
Session.Add("MyTheme", "blue");
Page.Theme = ((string)Session["MyTheme"]);
}
else
{
Page.Theme = ((string)Session["MyTheme"]);
}
}
}
毕竟我将这个类实现为母版页的辅助类:
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 System.Data.SqlClient;
using System.Globalization;
using System.Collections.Generic;
using System.Net;
using System.Text;
using System.Collections.ObjectModel;
using System.IO;
using System.Xml;
public partial class Admin_MasterPage : System.Web.UI.MasterPage
{
newManageClass manage_panels = new newManageClass();
DateTime LastCheck = DateTime.MinValue;
struct UnreadMails
{
//public string From { get; set; }
private string _From;
public string From
{
get { return _From; }
set { _From = value; }
}
//public string Subject { get; set; }
private string _Subject;
public string Subject
{
get { return _Subject; }
set { _Subject = value; }
}
//public DateTime MailModify { get; set; }
private DateTime _MailModify;
public DateTime MailModify
{
get { return _MailModify; }
set { _MailModify = value; }
}
}
Collection<UnreadMails> GetNewMails()
{
WebRequest webGmailRequest = WebRequest.Create(@"https://mail.google.com/mail/feed/atom");
webGmailRequest.PreAuthenticate = true;
NetworkCredential loginCredentials = new NetworkCredential("XXXXXXXXXX", "XXXXX");
webGmailRequest.Credentials = loginCredentials;
WebResponse webGmailResponse = webGmailRequest.GetResponse();
Stream strmUnreadMailInfo = webGmailResponse.GetResponseStream();
StringBuilder sbUnreadMailInfo = new StringBuilder(); byte[] buffer = new byte[8192]; int byteCount = 0;
while ((byteCount = strmUnreadMailInfo.Read(buffer, 0, buffer.Length)) > 0)
sbUnreadMailInfo.Append(System.Text.Encoding.ASCII.GetString(buffer, 0, byteCount));
XmlDocument UnreadMailXmlDoc = new XmlDocument();
UnreadMailXmlDoc.LoadXml(sbUnreadMailInfo.ToString());
XmlNodeList UnreadMailEntries = UnreadMailXmlDoc.GetElementsByTagName("entry");
UnreadMails oUnreadMails = new UnreadMails();
Collection<UnreadMails> clUnreadMails = new Collection<UnreadMails>();
for (int _i = 0; _i < UnreadMailEntries.Count; ++_i)
{
oUnreadMails.Subject = (UnreadMailEntries[_i]["title"]).InnerText;
oUnreadMails.From = (UnreadMailEntries[_i]["author"])["name"].InnerText + " <" + (UnreadMailEntries[_i]["author"])["email"].InnerText + ">";
oUnreadMails.MailModify = DateTime.Parse((UnreadMailEntries[_i]["modified"]).InnerText);
clUnreadMails.Add(oUnreadMails);
}
return clUnreadMails;
}
protected void Page_Load(object sender, EventArgs e)
{
manage_panels.Panel_User_Photo = (Panel)this.Page.Master.FindControl("Panel_User_Photo");
manage_panels.Panel_Search = (Panel)this.Page.Master.FindControl("Panel_Search");
manage_panels.Panel_notification = (Panel)this.Page.Master.FindControl("Panel_notification");
manage_panels.Panel_companymanagement = (Panel)this.Page.Master.FindControl("Panel_companymanagement");
manage_panels.Panel_omwealthmanagement = (Panel)this.Page.Master.FindControl("Panel_omwealthmanagement");
manage_panels.Panel_newsletter = (Panel)this.Page.Master.FindControl("Panel_newsletter");
string fullPath = Request.Url.AbsolutePath;
string fileName = System.IO.Path.GetFileName(fullPath);
switch (fileName)
{
case "Inquiry_history.aspx":
manage_panels.OnPageLoad();
break;
case "manage_companies.aspx":
manage_panels.CompanyManagementClick();
break;
case "service_manage.aspx":
manage_panels.OmWealthManagementClick();
break;
case "subscriber_manage.aspx":
manage_panels.NewsLetterManagementClick();
break;
case "user_manage.aspx":
manage_panels.UserManagementClick();
break;
default:
manage_panels.OnPageLoad();
break;
}
if (Session["username"] == null)
{
Response.Redirect("../Default.aspx");
}
else
{
if (!Page.IsPostBack)
{
manage_panels.OnPageLoad();
using (SqlConnection conn = Util.GetConnection())
{
conn.Open();
string select = "SELECT COUNT(*) FROM tbl_FreeTrial_History WHERE ((MONTH(Created_date)=DATEPART(month,GETDATE()) AND DAY(Created_date)= DATEPART(day,GETDATE()) AND YEAR(Created_date)= DATEPART(year,GETDATE())))";
SqlCommand cmd = new SqlCommand(select, conn);
int nResult;
nResult = int.Parse(cmd.ExecuteScalar().ToString());
lbl_free_count.Text = nResult.ToString();
string select1 = "SELECT COUNT(*) FROM tbl_Inquiry_History WHERE IsRead='False'";
SqlCommand cmd1 = new SqlCommand(select1, conn);
int nResult1;
nResult1 = int.Parse(cmd1.ExecuteScalar().ToString());
lbl_service_count.Text = nResult1.ToString();
}
string name, email, birth_date, phone_no, address, occuption, password, city_name, pin, counry_id, state_id;
int profile_id;
DatabaseHelper.GetUserProfile(Session["username"].ToString(), out name, out profile_id, out password, out email, out phone_no, out address, out birth_date, out occuption, out counry_id, out state_id, out city_name, out pin);
lbldisplayname.Text = name;
int NewUnreadMail = 0;
DateTime LastUnreadMailDate = DateTime.MinValue;
Collection<UnreadMails> clUnreadMails = GetNewMails();
for (int i = 0; i < clUnreadMails.Count; i++)
{
if (clUnreadMails[i].MailModify > LastCheck)
{
NewUnreadMail++;
}
if (clUnreadMails[i].MailModify > LastUnreadMailDate)
LastUnreadMailDate = clUnreadMails[i].MailModify;
}
LastCheck = LastUnreadMailDate;
lblnewunreadmail.Text = NewUnreadMail.ToString();
}
}
protected void SiteMapPath1_ItemCreated(object sender, SiteMapNodeItemEventArgs e)
{
if (e.Item.ItemType == SiteMapNodeItemType.Root || (e.Item.ItemType == SiteMapNodeItemType.PathSeparator && e.Item.ItemIndex == 1))
{
e.Item.Visible = false;
}
}
protected void lbtnlogout_Click(object sender, EventArgs e)
{
Session.Clear();
Response.Redirect("../Default.aspx");
}
protected void hplhome_Click(object sender, EventArgs e)
{
Response.Redirect("Admin_Landing_page.aspx");
manage_panels.OnPageLoad();
}
}
这是 admin_landing_page.aspx 代码:
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;
public partial class Admin_Admin_Landing_page : newManageClass
{
protected void Page_Load(object sender, EventArgs e)
{
if (Session["username"] == null)
{
Response.Redirect("../Default.aspx");
}
else
{
OnPageLoad();
}
}
protected void lbut_manage_inquiry_Click(object sender, EventArgs e)
{
Response.Redirect("Inquiry_history.aspx");
OnPageLoad();
}
protected void lbut_company_management_Click(object sender, EventArgs e)
{
Response.Redirect("manage_companies.aspx");
CompanyManagementClick();
}
protected void lbut_stocksmanagement_Click(object sender, EventArgs e)
{
Response.Redirect("service_manage.aspx");
OmWealthManagementClick();
}
protected void lbut_newslettermanagement_Click(object sender, EventArgs e)
{
Response.Redirect("subscriber_manage.aspx");
NewsLetterManagementClick();
}
protected void lbut_usermanagement_Click(object sender, EventArgs e)
{
Response.Redirect("user_manage.aspx");
UserManagementClick();
}
}