-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUniHR.Styles.cs
81 lines (67 loc) · 2.96 KB
/
UniHR.Styles.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
using System;
using System.IO;
using System.Web;
using System.Configuration;
namespace UniHR {
/// <summary>
/// Class used to load CSS files
/// </summary>
public class Style {
/// <summary>
/// Registrate a CSS file
/// </summary>
/// <param name="PsFileName">Name of the file that must be loaded</param>
public static void RegisterFile(string PsFileName) {
try {
if (PsFileName != "") {
// Get the page object
System.Web.UI.Page oPage = (System.Web.UI.Page)HttpContext.Current.Handler;
// TODO: Add debug control
//// Add the style
string sSessionName = "UNIHRSTYLE_" + oPage.Request.CurrentExecutionFilePath.ToUpper();
if (HttpContext.Current.Session[sSessionName] == null || !HttpContext.Current.Session[sSessionName].ToString().Contains(PsFileName + ",")) {
HttpContext.Current.Session[sSessionName] = (HttpContext.Current.Session[sSessionName] != null ? HttpContext.Current.Session[sSessionName].ToString() : string.Empty) + PsFileName + ",";
}
}
} catch (Exception ex) {
throw ex;
}
}
/// <summary>
/// Load the combined file to the page
/// </summary>
public static void Load() {
try {
if (HasFiles()) {
// TODO: Add debug control
// Get the page object
System.Web.UI.Page oPage = (System.Web.UI.Page)HttpContext.Current.Handler;
// Tag to add the combined styles
string sCombinedFileTag = "\r\n<link href=\"UniHR.ashx?t=text/css&f={0}\" rel=\"stylesheet\" type=\"text/css\" />";
sCombinedFileTag = string.Format(sCombinedFileTag, oPage.Request.CurrentExecutionFilePath);
// Add the file to the page
oPage.Header.Controls.AddAt(0, new System.Web.UI.LiteralControl(sCombinedFileTag));
}
} catch (Exception ex) {
throw ex;
}
}
/// <summary>
/// Verify if there are files to be loaded
/// </summary>
public static bool HasFiles() {
bool bResult = false;
try {
// Get the page object
System.Web.UI.Page oPage = (System.Web.UI.Page)HttpContext.Current.Handler;
string sSessionName = "UNIHRSTYLE_" + oPage.Request.CurrentExecutionFilePath.ToUpper();
if (!string.IsNullOrEmpty(HttpContext.Current.Session[sSessionName].ToString())) {
bResult = true;
}
} catch (Exception ex) {
throw ex;
}
return bResult;
}
}
}