您目前尚未登陆,请选择【登陆】或【注册
首页->全站代码->MyWebPages51aspx汉化最终版>>Administration/Navigation.aspx.cs>>源码在线查看
温馨提示:代码在线浏览功能只能做为源码浏览参考,如果想更进一步了解该代码请下载:MyWebPages51aspx汉化最终版
当前文件:文件类型 MyWebPagesStarterKit/Administration/Navigation.aspx.cs打开代码结构图
普通视图
		            
1//=============================================================================================== 2// 3// (c) Copyright Microsoft Corporation. 4// This source is subject to the Microsoft Permissive License. 5// See http://www.microsoft.com/resources/sharedsource/licensingbasics/sharedsourcelicenses.mspx. 6// All other rights reserved. 7// 8//=============================================================================================== 9 10using System; 11using System.Data; 12using System.Configuration; 13using System.Collections; 14using System.Web; 15using System.Web.Security; 16using System.Web.UI; 17using System.Web.UI.WebControls; 18using System.Web.UI.WebControls.WebParts; 19using System.Web.UI.HtmlControls; 20using MyWebPagesStarterKit; 21using MyWebPagesStarterKit.Controls; 22using MyWebPagesStarterKit.Providers; 23using System.Xml; 24using System.IO; 25 26public partial class Administration_Navigation : PageBaseClass 27{ 28 private SitemapEditor editor = null; 29 protected string lang; 30 31 protected void Page_Load(object sender, EventArgs e) 32 { 33 //define language for the documentation path 34 lang = System.Threading.Thread.CurrentThread.CurrentCulture.TwoLetterISOLanguageName; 35 if (!File.Exists(HttpContext.Current.Server.MapPath(string.Format("~/Documentation/" + lang + "/quick_guide.html")))) 36 { 37 lang = "en"; 38 } 39 40 if (!User.IsInRole(RoleNames.Administrators.ToString())) 41 Response.Redirect("Login.aspx"); 42 43 Response.Expires = 0; 44 Response.ExpiresAbsolute = DateTime.Now.AddMinutes(-1.0); 45 Response.CacheControl = "private"; 46 Response.Cache.SetCacheability(HttpCacheability.NoCache); 47 48 if (!IsPostBack) 49 { 50 btnDelete.OnClientClick = "if (!confirm('" + Resources.StringsRes.adm_Navigation_PageDeletionWarning + "')) return false;"; 51 populateList(SiteMap.RootNode, 0); 52 if (Request.QueryString["sel"] != null) 53 { 54 lstPages.SelectedValue = Request.QueryString["sel"]; 55 showPageDetails(lstPages.SelectedValue); 56 } 57 } 58 } 59 60 protected void valVirtualPath_ServerValidate(object source, ServerValidateEventArgs args) 61 { 62 string virtualPath = txtVirtualPath.Text.Trim(); 63 if (virtualPath != string.Empty) 64 { 65 if (editor == null) 66 editor = new SitemapEditor(); 67 68 if (!virtualPath.StartsWith("~/")) 69 { 70 if (virtualPath.StartsWith("/")) 71 virtualPath = virtualPath.Substring(1); 72 virtualPath = "~/" + virtualPath; 73 } 74 if (!virtualPath.EndsWith(".aspx")) 75 { 76 virtualPath += ".aspx"; 77 } 78 virtualPath = virtualPath.Replace(' ', '_'); 79 txtVirtualPath.Text = virtualPath; 80 81 XmlNode node = editor.FindNodeByVirtualPath(virtualPath.ToLower()); 82 if ( 83 (node != null) 84 && 85 ( 86 (node.Attributes["pageId"] == null) 87 || 88 (node.Attributes["pageId"].Value != lstPages.SelectedValue) 89 ) 90 ) 91 args.IsValid = false; 92 else 93 args.IsValid = true; 94 } 95 else 96 { 97 args.IsValid = true; 98 } 99 } 100 101 private void populateList(SiteMapNode parentNode, int level) 102 { 103 foreach (SiteMapNode node in parentNode.ChildNodes) 104 { 105 if (node["pageId"] != null) 106 { 107 string title = node.Title; 108 for (int i = 0; i < level; i++) 109 title = "..." + title; 110 if (node["visible"] == false.ToString()) 111 title += " (invisible)"; 112 if (node["pageId"] == _website.HomepageId) 113 title += " (Homepage)"; 114 lstPages.Items.Add(new ListItem(title, node["pageId"])); 115 populateList(node, level + 1); 116 } 117 } 118 } 119 120 protected void btnSave_Click(object sender, EventArgs e) 121 { 122 Validate(); 123 if (IsValid) 124 { 125 WebPage page = new WebPage(lstPages.SelectedValue); 126 127 page.Title = txtTitle.Text.Trim(); 128 page.NavigationName = txtNavigation.Text.Trim(); 129 page.Visible = chkVisible.Checked; 130 page.AllowAnonymousAccess = chkAnonymousAccess.Checked; 131 132 string virtualPath = txtVirtualPath.Text.Trim().ToLower(); 133 if (virtualPath != string.Empty) 134 { 135 if (!virtualPath.StartsWith("~/")) 136 { 137 if (virtualPath.StartsWith("/")) 138 virtualPath = virtualPath.Substring(1); 139 virtualPath = "~/" + virtualPath; 140 } 141 if (!virtualPath.EndsWith(".aspx")) 142 { 143 virtualPath += ".aspx"; 144 } 145 146 virtualPath = virtualPath.Replace(' ', '_'); 147 } 148 page.VirtualPath = virtualPath; 149 txtVirtualPath.Text = virtualPath; 150 page.SaveData(); 151 152 if (editor == null) 153 editor = new SitemapEditor(); 154 editor.UpdatePage(page); 155 editor.Save(); 156 157 Response.Redirect(string.Format("{0}?sel={1}", Request.Url.AbsolutePath, lstPages.SelectedValue)); 158 } 159 } 160 161 protected void btnSetHomepage_Click(object sender, EventArgs e) 162 { 163 WebPage page = new WebPage(lstPages.SelectedValue); 164 165 page.AllowAnonymousAccess = true; 166 page.Visible = true; 167 page.SaveData(); 168 _website.HomepageId = lstPages.SelectedValue; 169 _website.SaveData(); 170 171 Response.Redirect(Request.RawUrl); 172 } 173 174 protected void btnDelete_Click(object sender, EventArgs e) 175 { 176 Sidebar.GetInstance().RemoveSection(lstPages.SelectedValue); 177 WebPage page = new WebPage(lstPages.SelectedValue); 178 page.Delete(); 179 SitemapEditor editor = new SitemapEditor(); 180 editor.DeletePage(lstPages.SelectedValue); 181 editor.Save(); 182 183 184 Response.Redirect(Request.Url.AbsolutePath); 185 } 186 187 protected void movePage_Command(object sender, CommandEventArgs e) 188 { 189 SitemapEditor editor = new SitemapEditor(); 190 switch (e.CommandName) 191 { 192 case "up": 193 editor.MoveUp(lstPages.SelectedValue); 194 break; 195 case "down": 196 editor.MoveDown(lstPages.SelectedValue); 197 break; 198 case "left": 199 editor.MoveLevelUp(lstPages.SelectedValue); 200 break; 201 case "right": 202 editor.MoveLevelDown(lstPages.SelectedValue); 203 break; 204 } 205 editor.Save(); 206 207 Response.Redirect(string.Format("{0}?sel={1}", Request.Url.AbsolutePath, lstPages.SelectedValue)); 208 } 209 210 protected void btnNewPage_Click(object sender, EventArgs e) 211 { 212 string PageId = lstPages.SelectedValue; 213 214 WebPage page = new WebPage(); 215 page.NavigationName = Resources.StringsRes.adm_Navigation_NewPageDefaultName; 216 page.AllowAnonymousAccess = true; 217 page.Visible = true; 218 page.SaveData(); 219 220 SitemapEditor editor = new SitemapEditor(); 221 editor.InsertPage(page, PageId); 222 editor.Save(); 223 224 Response.Redirect(string.Format("{0}?sel={1}", Request.Url.AbsolutePath, page.PageId)); 225 } 226 227 protected void lstPages_SelectedIndexChanged(object sender, EventArgs e) 228 { 229 showPageDetails(lstPages.SelectedValue); 230 } 231 232 private void showPageDetails(string pageId) 233 { 234 WebPage page = new WebPage(pageId); 235 txtTitle.Text = page.Title; 236 txtNavigation.Text = page.NavigationName; 237 txtVirtualPath.Text = page.VirtualPath; 238 chkVisible.Checked = page.Visible; 239 chkAnonymousAccess.Checked = page.AllowAnonymousAccess; 240 241 bool isHomepage = (pageId == _website.HomepageId); 242 chkVisible.Enabled = !isHomepage; 243 chkAnonymousAccess.Enabled = !isHomepage; 244 btnSetHomepage.Visible = !isHomepage; 245 246 SitemapEditor editor = new SitemapEditor(); 247 btnDelete.Visible = 248 ( 249 (lstPages.Items.Count > 1) 250 && 251 (pageId != _website.HomepageId) 252 && 253 (!editor.HasChildNodes(pageId)) 254 ); 255 256 tblPageDetails.Visible = true; 257 tblMoveIcons.Visible = true; 258 LocalizeMoveTitle.Visible = true; 259 } 260} 261
还没有找到您心仪的内容?请用.net源码大搜捕
代码片断 打包下载该项目完整源码:MyWebPages51aspx汉化最终版