root/trunk/eCard/eCardMVC/Platnosci/Helpers/helper.cs @ 870

Wersja 867, 6.2 KB (wprowadzona przez alina, 16 years temu)

re #215 zmiany Site.master

Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Web;
5using System.Web.Mvc;
6using System.Web.Routing;
7using System.Configuration;
8
9namespace Platnosci.Helpers
10{
11    public static class helper
12    {
13        public static string ImageTag(this HtmlHelper helper, string src, string alt)
14        {
15            TagBuilder tb = new TagBuilder("img");
16            tb.Attributes.Add("src", helper.Encode(src));
17            tb.Attributes.Add("alt", helper.Encode(alt));
18            return tb.ToString(TagRenderMode.SelfClosing);
19        }
20        public static string ImageLink(this HtmlHelper htmlHelper, string filename, string alt, string querystring)
21        {
22           
23            var action = htmlHelper.CurrentAction();
24            var controller = htmlHelper.CurrentController();
25                                   
26            UrlHelper urlHelper = ((Controller)htmlHelper.ViewContext.Controller).Url;
27            string src = urlHelper.UrlImage(filename);
28            string imgtag = htmlHelper.ImageTag(src, alt);
29           
30            RouteValueDictionary tab = new RouteValueDictionary();
31            string id = htmlHelper.ViewContext.RouteData.Values["id"].ToString();
32            tab.Add("language", alt);
33            tab.Add("id", id);
34
35            string url = urlHelper.Action(action, controller, tab);
36
37            string[] param = querystring.ToString().Split(("&").ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
38            for (int i = 0; i < param.Length; i++ )
39            {
40                if (i == 0) url += "?" + param[i];
41                else url += "&" + param[i];
42            }
43
44            TagBuilder link = new TagBuilder("a");
45            link.Attributes.Add("href", url);
46            link.InnerHtml = imgtag;
47            return link.ToString();
48        }
49        public static string CurrentController(this HtmlHelper htmlHelper)
50        {
51            return htmlHelper.ViewContext.RouteData.Values["controller"].ToString();
52        }
53        public static string CurrentAction(this HtmlHelper htmlHelper)
54        {
55            return htmlHelper.ViewContext.RouteData.Values["action"].ToString();
56        } 
57        public static string Home(this UrlHelper urlHelper)
58        {
59            return urlHelper.Content("~/");
60        }
61        public static string Css(this UrlHelper urlHelper, string fileName)
62        {
63            string url = urlHelper.Home() + "Content/" + fileName;
64            return urlHelper.Content(url);
65        }
66        public static string UrlImage(this UrlHelper urlHelper, string fileName)
67        {
68            string url = urlHelper.Home() + "Images/" + fileName;           
69            return urlHelper.Content(url);
70        }
71        public static string FileUrl(this UrlHelper urlHelper, string fileName)
72        {
73            string url = urlHelper.Home() + "Images/";
74            if (ConfigurationManager.AppSettings["Css"] == "truck") url += "truck/";
75                else if(ConfigurationManager.AppSettings["Css"] == "admoto") url += "admoto/";
76            url += fileName;
77            return urlHelper.Content(url);
78        }
79        public static string MainCss(this HtmlHelper htmlHelper, string filename)
80        {
81            UrlHelper urlHelper = new UrlHelper(htmlHelper.ViewContext.RequestContext);
82            string url = urlHelper.Css(filename);
83            string strCss = htmlHelper.LinkTag(url, "stylesheet", "text/css");
84            return strCss;
85        }
86        public static string LinkTag(this HtmlHelper htmlHelper, string url, string rel, string type)
87        {
88            TagBuilder linkcss = new TagBuilder("link");
89            linkcss.Attributes.Add("href", url);
90            linkcss.Attributes.Add("rel", rel);
91            if (type != "" ) linkcss.Attributes.Add("type", type);
92            return linkcss.ToString(TagRenderMode.SelfClosing);
93        }
94        public static string AddCssToPortal(this HtmlHelper htmlHelper)
95        {
96            string filename = "";
97            if (ConfigurationManager.AppSettings["Css"] == "truck") filename = "truck.css" ;   
98                else if(ConfigurationManager.AppSettings["Css"] == "admoto") filename = "admoto.css";
99           
100            string css = htmlHelper.MainCss(filename);
101            return css;
102        }
103        public static string Favicon(this HtmlHelper htmlHelper){
104            string url = "";
105            string str = "";
106            if (ConfigurationManager.AppSettings["Css"] == "admoto"){
107                UrlHelper urlHelper = new UrlHelper(htmlHelper.ViewContext.RequestContext);
108                url = urlHelper.FileUrl("favicon.ico");
109                str = htmlHelper.LinkTag(url,"shortcut icon","");
110            }
111            return str;
112        }
113        public static string Logo(this HtmlHelper htmlHelper)
114        {
115            string rowspan = "";
116            if (ConfigurationManager.AppSettings["Css"] == "truck") rowspan = "";
117                else if (ConfigurationManager.AppSettings["Css"] == "admoto") rowspan = "2";
118            string str = htmlHelper.TdTag("logo", rowspan);
119            return str;
120        }
121        public static string TdTag(this HtmlHelper helper, string tdClass, string tdRowspan)
122        {
123            UrlHelper urlHelper = new UrlHelper(helper.ViewContext.RequestContext);
124            string url = urlHelper.FileUrl("logo.gif");
125            string logotag = helper.ImageTag(url, "logo");
126            string labeltag = "";
127
128            TagBuilder tb = new TagBuilder("td");
129            tb.Attributes.Add("class", tdClass);
130            if (tdRowspan != "") tb.Attributes.Add("rowspan", tdRowspan);
131       
132            if (ConfigurationManager.AppSettings["Css"] == "admoto")
133            {
134                TagBuilder lab = new TagBuilder("asp:Label");
135                lab.Attributes.Add("ID", "Label1");
136                lab.Attributes.Add("runat", "server");
137                string txt = HttpContext.GetGlobalResourceObject("tlumaczenia", "tytul").ToString();
138                lab.Attributes.Add("Text", txt);
139                labeltag = lab.ToString();               
140            }
141            tb.InnerHtml = logotag + labeltag;
142            return tb.ToString();
143        }
144    }   
145}
Notatka: Zobacz TracBrowser aby uzyskać więcej informacji.