comparison Demo/Asp.Net/Web/Controls/BreadCrumbControl.ascx.cs @ 0:f990fcb411a9

Копия текущей версии из github
author cin
date Thu, 27 Mar 2014 21:46:09 +0400
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:f990fcb411a9
1 using System;
2 using System.Web.UI.WebControls;
3 using System.Web.UI.HtmlControls;
4
5 using PetShop.BusinessLogic;
6
7 namespace PetShop.Web
8 {
9 public partial class BreadCrumbControl : System.Web.UI.UserControl
10 {
11 protected void Page_Load(object sender, EventArgs e)
12 {
13 string categoryId = Request.QueryString["categoryId"];
14
15 if (!string.IsNullOrEmpty(categoryId))
16 {
17 ProcessHomePageLink();
18
19 // Process Product page link
20 //
21 HtmlAnchor lnkProducts = new HtmlAnchor();
22
23 lnkProducts.InnerText = new ProductManager().GetCategory(categoryId).Name;
24 lnkProducts.HRef = string.Format("~/Products.aspx?page=0&categoryId={0}", categoryId);
25
26 plhControl.Controls.Add(lnkProducts);
27
28 string productId = Request.QueryString["productId"];
29
30 if (!string.IsNullOrEmpty(productId))
31 {
32 // Process Item page link
33 //
34 plhControl.Controls.Add(GetDivider());
35
36 HtmlAnchor lnkItemDetails = new HtmlAnchor();
37
38 lnkItemDetails.InnerText = new ProductManager().GetProduct(productId).Name;
39 lnkItemDetails.HRef = string.Format("~/Items.aspx?categoryId={0}&productId={1}", categoryId, productId);
40
41 plhControl.Controls.Add(lnkItemDetails);
42 }
43 }
44 else
45 {
46 int len = Request.Url.Segments.Length;
47
48 if (len >= 2 && Request.Url.Segments[len-2].TrimEnd('/', '\\').ToLower() == "admin")
49 {
50 ProcessHomePageLink();
51
52 HtmlAnchor a = new HtmlAnchor();
53
54 a.InnerText = Request.Url.Segments[len - 1].Split('.')[0];
55 a.HRef = Request.Url.PathAndQuery;
56
57 plhControl.Controls.Add(a);
58 }
59 }
60 }
61
62 private void ProcessHomePageLink()
63 {
64 HtmlAnchor lnkHome = new HtmlAnchor();
65
66 lnkHome.InnerText = "Home";
67 lnkHome.HRef = "~/Default.aspx";
68
69 plhControl.Controls.Add(lnkHome);
70 plhControl.Controls.Add(GetDivider());
71 }
72
73 /// <summary>
74 /// Create a breadcrumb nodes divider
75 /// </summary>
76 /// <returns>Literal control containing formatted divider</returns>
77 private Literal GetDivider()
78 {
79 Literal ltlDivider = new Literal();
80
81 ltlDivider.Text = "&nbsp;&#062;&nbsp;";
82
83 return ltlDivider;
84 }
85 }
86 }