-
Notifications
You must be signed in to change notification settings - Fork 55
/
Copy pathLinkControl.cs
204 lines (174 loc) · 6.46 KB
/
LinkControl.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml;
using DigitalPlatform.Xml;
using DigitalPlatform.OPAC.Server;
namespace DigitalPlatform.OPAC.Web
{
/// <summary>
/// 用于构造HTML页面中<link>局部
/// </summary>
[DefaultProperty("Text")]
[ToolboxData("<{0}:LinkControl runat=server></{0}:LinkControl>")]
public class LinkControl : WebControl
{
// 取消最外面的tag
public override void RenderBeginTag(HtmlTextWriter writer)
{
}
public override void RenderEndTag(HtmlTextWriter writer)
{
}
protected override void RenderContents(HtmlTextWriter output)
{
string strHref = this.Attributes["href"];
string strStyleDirName = GetStyleDirName();
if (this.IsNewStyle == true)
output.Write("<LINK href='"
+ "./stylenew/" + strStyleDirName + "/"
+ strHref
+ "' type='text/css' rel='stylesheet' />");
else
output.Write("<LINK href='"
+ "./style/" + strStyleDirName + "/"
+ strHref
+ "' type='text/css' rel='stylesheet' />");
#if NO
string strStyle = "";
string strLibraryCode = "";
GetStyleDirName(out strStyle,
out strLibraryCode);
output.Write("<LINK href='./css.aspx?style="
+ HttpUtility.UrlEncode(strStyle)
+ "&librarycode="
+ HttpUtility.UrlEncode(strLibraryCode)
+ "&name="
+ HttpUtility.UrlEncode(strHref)
+ "' type='text/css' rel='stylesheet' />");
#endif
}
public bool IsNewStyle
{
get
{
OpacApplication app = (OpacApplication)this.Page.Application["app"];
if (app == null)
return false;
#if NO
string strValue = app.WebUiDom.DocumentElement.GetAttribute("newStyle");
if (string.IsNullOrEmpty(strValue) == true)
return false;
return DomUtil.IsBooleanTrue(strValue);
#endif
return app.IsNewStyle;
}
}
public static string MakeDir(string strLibraryDirName,
string strDirName)
{
if (string.IsNullOrEmpty(strDirName) == true)
strDirName = "0";
if (string.IsNullOrEmpty(strLibraryDirName) == true)
return strDirName;
return strLibraryDirName + "/" + strDirName;
}
#if NO
void GetStyleDirName(out string strStyle,
out string strLibraryCode)
{
strStyle = "";
strLibraryCode = "";
// 面板上选择的馆代码
strLibraryCode = (string)this.Page.Session["librarycode"];
}
#endif
string GetStyleDirName()
{
string strError = "";
OpacApplication app = (OpacApplication)this.Page.Application["app"];
if (app == null)
{
strError = "app == null";
goto ERROR1;
}
SessionInfo sessioninfo = (SessionInfo)this.Page.Session["sessioninfo"];
if (sessioninfo == null)
{
strError = "sessioninfo == null";
goto ERROR1;
}
string strLibraryCodeList = ""; // 当前用户管辖的馆代码列表
#if NO
if (sessioninfo.Channel != null)
strLibraryCodeList = sessioninfo.Channel.LibraryCodeList;
#endif
strLibraryCodeList = sessioninfo.LibraryCodeList;
// 面板上选择的馆代码
string strSelectedLibraryCode = (string)this.Page.Session["librarycode"];
string strLibraryStyleDir = ""; // 分馆的风格目录
if (string.IsNullOrEmpty(strSelectedLibraryCode) == false)
{
XmlNode nodeLibrary = app.WebUiDom.DocumentElement.SelectSingleNode("libraries/library[@code='" + strSelectedLibraryCode + "']");
if (nodeLibrary != null)
{
strLibraryStyleDir = DomUtil.GetAttr(nodeLibrary, "style");
if (string.IsNullOrEmpty(strLibraryStyleDir) == true)
strLibraryStyleDir = DomUtil.GetAttr(nodeLibrary, "code");
}
}
// 2007/7/11
LoginState loginstate = GlobalUtil.GetLoginState(this.Page);
XmlNode nodeUserType = null;
if (loginstate == LoginState.NotLogin)
{
nodeUserType = app.WebUiDom.DocumentElement.SelectSingleNode(
"titleBarControl/userType[@type='notlogin']");
}
else if (loginstate == LoginState.Public)
{
nodeUserType = app.WebUiDom.DocumentElement.SelectSingleNode(
"titleBarControl/userType[@type='public']");
}
else if (loginstate == LoginState.Librarian)
{
nodeUserType = app.WebUiDom.DocumentElement.SelectSingleNode(
"titleBarControl/userType[@type='librarian']");
}
if (nodeUserType != null)
{
string strStyleDirName = DomUtil.GetAttr(nodeUserType, "style");
return MakeDir(strLibraryStyleDir, strStyleDirName);
#if NO
if (String.IsNullOrEmpty(strStyleDirName) == true)
return "0"; // 缺省值
return strStyleDirName;
#endif
}
XmlDocument readerdom = null;
// 获得当前session中已经登录的读者记录DOM
// return:
// -2 当前登录的用户不是reader类型
// -1 出错
// 0 尚未登录
// 1 成功
int nRet = sessioninfo.GetLoginReaderDom(
out readerdom,
out strError);
if (nRet == -1 || nRet == -2)
goto ERROR1;
if (nRet == 0)
{
goto ERROR1;
}
// return PreferenceControl.GetReaderSelectedStyleDir(readerdom);
return MakeDir(strLibraryStyleDir, PreferenceControl.GetReaderSelectedStyleDir(readerdom));
ERROR1:
return "0";
}
}
}