UIHelper.cs 47 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294
  1. using System;
  2. using System.Data;
  3. using System.Configuration;
  4. using System.Collections;
  5. using System.Collections.Specialized;
  6. using System.IO;
  7. using System.Web;
  8. using System.Web.Security;
  9. using System.Web.UI;
  10. using System.Web.UI.WebControls;
  11. using System.Web.UI.WebControls.WebParts;
  12. using System.Web.UI.HtmlControls;
  13. using com.cloudsoft.utils;
  14. using System.Text;
  15. using System.Collections.Generic;
  16. /// <summary>
  17. /// Delegate defining the interface for BizRule
  18. /// </summary>
  19. public delegate String BizRule(string zRequest);
  20. /// <summary>
  21. /// Delegate defining the interface for BizRule
  22. /// </summary>
  23. public delegate XMLHelper XMLBizRule(XMLHelper oRequest);
  24. /// <summary>
  25. /// Delegate defining the interface for BizRule
  26. /// </summary>
  27. public delegate StringBuilder CSVBizRule(XMLHelper oRequest);
  28. namespace com.cloudsoft.utils
  29. {
  30. /// <summary>
  31. /// UI Helper class. Extends System.Web.UI.Page
  32. /// Should be used as the extention class in a aspx cs class.
  33. /// </summary>
  34. public class UIHelper : System.Web.UI.Page
  35. {
  36. /// <summary>
  37. /// Gets or sets the gprev page Global variable.
  38. /// </summary>
  39. /// <value>The gprev page.</value>
  40. public String gPrevPage
  41. {
  42. get { return getSyncKey("gPrevPage"); }
  43. set { setSyncKey("gPrevPage", value); }
  44. }
  45. /// <summary>
  46. /// Gets or sets the Global method variable.
  47. /// </summary>
  48. /// <value>The method.</value>
  49. public String zgMethod
  50. {
  51. get { return getSyncKey("gMethod"); }
  52. set { setSyncKey("gMethod", value); }
  53. }
  54. /// <summary>
  55. /// Gets or sets the Global current tab variable.
  56. /// </summary>
  57. /// <value>The current tab.</value>
  58. public String gCurrentTab
  59. {
  60. get { return getSyncKey("gCurrentTab"); }
  61. set { setSyncKey("gCurrentTab", value); }
  62. }
  63. /// <summary>
  64. /// Gets or sets the type of the Global page variable usied for paging.
  65. /// </summary>
  66. /// <value>The Page number for paging</value>
  67. public String zgPageType
  68. {
  69. get { return getSyncKey("zgPageType"); }
  70. set { setSyncKey("zgPageType", value); }
  71. }
  72. /// <summary>
  73. /// Gets or sets the Global user id (MUD ID).
  74. /// </summary>
  75. /// <value>The MUD ID.</value>
  76. public virtual String zgUser
  77. {
  78. get { return getSyncKey("gUserID"); }
  79. set { setSyncKey("gUserID", value); }
  80. }
  81. /// <summary>
  82. /// The Root Directory for the web
  83. /// </summary>
  84. public String zgRootDirectory = "";
  85. /// <summary>
  86. /// The page title
  87. /// </summary>
  88. public String zgPageTitle = "";
  89. /// <summary>
  90. /// The Full root web directory (eg. http://bresawn0123/cims)
  91. /// </summary>
  92. public String zgFullRootWeb = "";
  93. /// <summary>
  94. /// The Root of the web (eg. /cims)
  95. /// </summary>
  96. public String zgRootWeb = "";
  97. /// <summary>
  98. /// Array of Months
  99. /// </summary>
  100. public String[] arygMonths = new String[] {"January","February","March","April","May","June","July","August","September","October","November","December"};
  101. /// <summary>
  102. /// An Array of slow business rules to be executed
  103. /// </summary>
  104. public String[] aSlowRules = new String[] {};
  105. /// <summary>
  106. /// Array of returned XML from slow business rules
  107. /// </summary>
  108. public String[] aSlowXML = new String[] {};
  109. /// <summary>
  110. /// The Global system (eg. cims). Should be overridden
  111. /// </summary>
  112. public String zgSystem = "cims";
  113. /// <summary>
  114. /// Branding XML
  115. /// </summary>
  116. public XMLHelper oBranding = null;
  117. /// <summary>
  118. /// Current page
  119. /// </summary>
  120. public String gCurrentPage = "";
  121. /// <summary>
  122. /// The Name displayed in the title for branding
  123. /// </summary>
  124. public String zgGlobalName = "";
  125. /// <summary>
  126. /// The Object which raised an error
  127. /// </summary>
  128. public String zgErr_Object = "";
  129. /// <summary>
  130. /// The Method which raised an error
  131. /// </summary>
  132. public String zgErr_Method = "";
  133. /// <summary>
  134. /// Determins whether the user is a superuser
  135. /// </summary>
  136. public Boolean gbSuperUser = false;
  137. /// <summary>
  138. /// Determines whether menu security should be used
  139. /// </summary>
  140. public String zgSecurity = "ON";
  141. /// <summary>
  142. /// Determines whether tasks should be shown
  143. /// </summary>
  144. public Boolean zbShowTasks = false;
  145. /// <summary>
  146. /// Default rows per page
  147. /// </summary>
  148. public int zgRowsPerPage = 20;
  149. /// <summary>
  150. /// Location of the Framework web
  151. /// </summary>
  152. public String zgFrameworkWeb = "/WI3/";
  153. /// <summary>
  154. /// Full location of the framework web (eg. http://bresawnv0123/wi3)
  155. /// </summary>
  156. public String zgFullFrameworkWeb = "";
  157. private DateTime gdStart;
  158. public Boolean bTopCalled = false;
  159. private Hashtable oSyncKeys = new Hashtable();
  160. private Boolean bInLoad = false;
  161. /// <summary>
  162. /// Raises the System.Web.UI.Control.Init event to initialize the page.
  163. /// </summary>
  164. /// <param name="e">An System.EventArgs that contains the event data.</param>
  165. override protected void OnInit(EventArgs e)
  166. {
  167. // Load SyncKeys from the Application Definition
  168. loadSyncKeys();
  169. zgRootDirectory = Request.MapPath("~");
  170. zgRootWeb = Request.ApplicationPath + "/";
  171. zgUser = RequestP("zgUser");
  172. //WADS: Secure connections...
  173. string protocolPrepend = "http://";
  174. if (HttpContext.Current.Request.IsSecureConnection)
  175. protocolPrepend = "https://";
  176. zgFullRootWeb = protocolPrepend + Request.ServerVariables["HTTP_HOST"].ToString() + zgRootWeb;
  177. zgFullFrameworkWeb = protocolPrepend + Request.ServerVariables["SERVER_NAME"].ToString() + zgFrameworkWeb;
  178. if (Session["MudID"] != null)
  179. {
  180. if (zgUser == "")
  181. zgUser = (String) Session["MudID"];
  182. }
  183. else
  184. {
  185. if (zgUser == "")
  186. {
  187. zgUser = Request.ServerVariables["LOGON_USER"];
  188. zgUser = zgUser.Substring(zgUser.IndexOf('\\')+1).ToUpper();
  189. }
  190. }
  191. Session["MudID"] = zgUser;
  192. gdStart = DateTime.Now;
  193. //zgFrameworkDirectory = Request.MapPath(zgFrameworkWeb) + "\\";
  194. gPrevPage = RequestP("gPrevPage");
  195. gCurrentPage = Request.ServerVariables["PATH_INFO"].ToUpper();
  196. if (gCurrentPage == gPrevPage)
  197. gCurrentTab = RequestP("gCurrentTab");
  198. zgMethod = RequestP("gMethod");
  199. // ----------------------------
  200. // Page Type Setting
  201. // ----------------------------
  202. // MENU: Menu Navigation Page
  203. // Full branding, Top Menu & Side Menu
  204. // TABSET: Tab Control Set Navigation Page
  205. // Full branding, Top Menu, Side Menu or Side TabControl
  206. // CONTENT: Content only (tab)
  207. // No Branding, no top menu, no side menu or side tab control
  208. //
  209. if (zgPageType == "")
  210. {
  211. zgPageType = RequestF("zgPageType");
  212. switch (zgPageType)
  213. {
  214. case "MENU":
  215. case "CONTENT":
  216. case "TABSET":
  217. break;
  218. default:
  219. zgPageType = "MENU";
  220. break;
  221. }
  222. }
  223. base.OnInit(e);
  224. }
  225. /// <summary>
  226. /// Determines whether an error is a UI error
  227. /// </summary>
  228. /// <param name="err">The Exception</param>
  229. /// <returns>
  230. /// <c>true</c> if is UI error; otherwise, <c>false</c>.
  231. /// </returns>
  232. public Boolean isUIError(Exception err)
  233. {
  234. Boolean boolIsError = false;
  235. //switch (err.number)
  236. //{
  237. // case -2147221005:
  238. // boolIsError = true;
  239. // break;
  240. // default:
  241. // boolIsError = false;
  242. // break;
  243. //}
  244. return boolIsError;
  245. }
  246. // ============================================================================
  247. // Business Rule Execution (Logic Functions)
  248. // ============================================================================
  249. /// <summary>
  250. /// Bubbles an event up to the loadorder if required
  251. /// </summary>
  252. public void LoadOrderBubble()
  253. {
  254. String zLoadOrder = RequestQS("loadorder");
  255. if (!(zLoadOrder == "None" || zLoadOrder == null) && (zgPageType == "CONTENT"))
  256. {
  257. Response.Write("<script language=\"JavaScript\">");
  258. //WADS: Cross site scripting...
  259. Response.Write("parent.fnLoad" + zLoadOrder + "(frameElement.id);");
  260. Response.Write("</script>");
  261. }
  262. }
  263. // ============================================================================
  264. // TabControl Functions
  265. // ============================================================================
  266. /// <summary>
  267. /// Writes the html for the chosen tabcontrol
  268. /// </summary>
  269. /// <param name="zMenu">Name of the Menu (in this case, a page of tabcontrols) to write (will filter on security if set on)</param>
  270. /// <param name="zTabControl">Name of the TabControl to write</param>
  271. public void writeTabControl(String zMenu, String zTabControl)
  272. {
  273. XMLHelper oXML = getMenuDOM(zMenu);
  274. if (oXML != null)
  275. {
  276. oXML.getNode("/toplevel/navigation/menu[@id='" + zTabControl + "']").transform(zgFullFrameworkWeb + "xsl/UN_TabControl_SC.xsl", Response.Output);
  277. }
  278. }
  279. // ============================================================================
  280. // Sync Key Functions
  281. // ============================================================================
  282. /// <summary>
  283. /// write SyncKeys to Hidden Fields Should be overriden to include another systems sync keys
  284. /// </summary>
  285. public virtual void loadSyncKeys()
  286. {
  287. // Add your SyncKeys Here
  288. SyncKey("gPrevPage");
  289. SyncKey("gMethod");
  290. SyncKey("gCurrentTab");
  291. SyncKey("zgPageType");
  292. SyncKey("gUserID");
  293. SyncKey("gdeleteID");
  294. }
  295. /// <summary>
  296. /// Sets a Sync key.
  297. /// </summary>
  298. /// <param name="zName">Name of the Sync Key</param>
  299. public void SyncKey(String zName)
  300. {
  301. String zValue = Server.HtmlEncode(Request.Params[zName]);
  302. if (zValue == null)
  303. zValue = "";
  304. if (!oSyncKeys.ContainsKey(zName))
  305. oSyncKeys.Add(zName, zValue);
  306. else
  307. oSyncKeys[zName] = zValue;
  308. }
  309. /// <summary>
  310. /// Gets a sync key.
  311. /// </summary>
  312. /// <param name="zName">Name of Sync Key</param>
  313. /// <returns>The value of the Sync Key</returns>
  314. public String getSyncKey(String zName)
  315. {
  316. return (String) oSyncKeys[zName];
  317. }
  318. /// <summary>
  319. /// Sets the sync key.
  320. /// </summary>
  321. /// <param name="zName">Name of the Sync Key</param>
  322. /// <param name="zValue">The value to set the Sync Key to.</param>
  323. public void setSyncKey(String zName, String zValue)
  324. {
  325. oSyncKeys[zName] = zValue;
  326. }
  327. /// <summary>
  328. /// Write / update syncKeys on the client
  329. /// </summary>
  330. public void writeSyncKeys()
  331. {
  332. foreach (String zSyncKey in oSyncKeys.Keys)
  333. {
  334. Response.Write("\t setSyncKey(\"" + zSyncKey + "\", \"" + oSyncKeys[zSyncKey] + "\");\n");
  335. }
  336. }
  337. /// <summary>
  338. /// Write syncKeys as hidden fields on the client.
  339. /// </summary>
  340. /// <param name="zPageType">The Page Type</param>
  341. public void writeSyncKeysToInput(String zPageType)
  342. {
  343. setSyncKey("zgPageType", zPageType);
  344. foreach (String zSyncKey in oSyncKeys.Keys)
  345. {
  346. Response.Write("<input type=\"hidden\" name=\"" + zSyncKey + "\" value=\"" + oSyncKeys[zSyncKey] + "\" />\n");
  347. }
  348. }
  349. // ============================================================================
  350. // Paging
  351. // ============================================================================
  352. // --------------------------------------------------------------
  353. // Function: createPaging
  354. // Purpose: Create a DB paged response (list)
  355. // Outputs:
  356. //
  357. // --------------------------------------------------------------
  358. /// <summary>
  359. /// Creates paging HTML.
  360. /// </summary>
  361. /// <param name="lCurrentPage">The current page.</param>
  362. /// <param name="lRows">The total number of rows.</param>
  363. /// <param name="lRowsPerPage">The rows per page.</param>
  364. public string createPaging(int lCurrentPage, int lRows, int lRowsPerPage)
  365. {
  366. StringBuilder sb = new StringBuilder();
  367. int i;
  368. int lPageSet;
  369. int lFirst;
  370. int lLast;
  371. int lPages = 0;
  372. if (lRows > 0)
  373. lPages = ((lRows-1) / lRowsPerPage)+1;
  374. if ((lCurrentPage == 0) || (lPages == 0))
  375. return "";
  376. lPageSet = ((lCurrentPage-1) / 10) + 1;
  377. lFirst = ((lPageSet-1) * 10) + 1;
  378. lLast = lPageSet * 10;
  379. if (lLast > lPages)
  380. lLast = lPages;
  381. sb.Append("<table width='100%'>\r\n");
  382. sb.Append("<tr>\r\n");
  383. sb.Append("<td align=\"left\"><font face=\"Verdana,Arial\" size=\"1\">Currently viewing page ");
  384. sb.Append(lCurrentPage + " out of ");
  385. sb.Append((lPages == 200) ? "at least 200" : lPages + " pages.</font></td>\r\n");
  386. sb.Append("<td alight=\"right\">Total found : " + lRows);
  387. if (lPages==200)
  388. sb.Append("+");
  389. sb.Append("</td></tr>\r\n");
  390. sb.Append("<tr><td colspan=\"2\">\r\n");
  391. sb.Append("<table><tr>\r\n");
  392. if (lPageSet > 1)
  393. {
  394. sb.Append("<td class=\"nextprev\"><a HREF=\"Javascript: document.forms[0].Page.value=" + (lFirst - 10) + ";document.forms[0].Button_clicked.value=true;document.forms[0].submit()\"><font face=\"marlett\">33</font>prev 10</a> </td>\r\n");
  395. }
  396. for (i=lFirst; i < lLast+1; i++)
  397. {
  398. if (i > 0 && i <= lPages)
  399. {
  400. if (i == lCurrentPage)
  401. {
  402. sb.Append("<td class=\"pageno\">[" + i + "]</td>\r\n");
  403. }
  404. else
  405. {
  406. sb.Append("<td class=\"pageno\"><a HREF=\"Javascript: document.forms[0].Page.value=" + i + ";document.forms[0].Button_clicked.value=true;document.forms[0].submit()\">" + i + "</a></td>\r\n");
  407. }
  408. }
  409. }
  410. if (lLast < lPages)
  411. {
  412. sb.Append("<td class=\"nextprev\"><a HREF=\"Javascript: document.forms[0].Page.value=" + (lLast + 1) + ";document.forms[0].Button_clicked.value=true;document.forms[0].submit()\">next 10<font face=\"marlett\">44</font></a></td>\r\n");
  413. }
  414. sb.Append("</tr></table>\r\n");
  415. sb.Append("</td></tr>\r\n");
  416. sb.Append("</table>\r\n");
  417. return sb.ToString();
  418. }
  419. // ============================================================================
  420. // Select Dropdown Utilities
  421. // ============================================================================
  422. public String generateSelectionMonth(String name)
  423. {
  424. return generateSelectionMonth(name, null);
  425. }
  426. /// <summary>
  427. /// Build a month select dropdown
  428. /// </summary>
  429. /// <param name="name">Name of the Select Tag</param>
  430. /// <param name="selected">Month to be preselected </param>
  431. /// <returns>HTML for select Month</returns>
  432. public String generateSelectionMonth(String name, String selected)
  433. {
  434. DateTime now = DateTime.Now;
  435. String arg = selected;
  436. String output = "";
  437. int pos = 0;
  438. int current = 0;
  439. // Need to determine the current month - number ie Oct is 9 in the array
  440. if (arg != "" && arg != null)
  441. {
  442. String aArg1 = arg.Split(new Char[] { ' ' })[0];
  443. String[] aArg = aArg1.Split(new Char[] { '-' });
  444. if (arg.Length == 2)
  445. current = Convert.ToInt32(arg) - 1;
  446. else
  447. {
  448. for (pos = 0; pos < arygMonths.Length; pos++)
  449. {
  450. if (aArg[1].Substring(0, 3).ToUpper() == arygMonths[pos].Substring(0, 3).ToUpper())
  451. break;
  452. }
  453. current = pos;
  454. }
  455. }
  456. else
  457. current = now.Month - 1;
  458. // Write the Select tag
  459. output = "<select name=\'" + name + "\'>";
  460. // Now add the options for each month
  461. for (int i = 0; i < arygMonths.Length; i++)
  462. {
  463. output += "<option value=\'";
  464. output += i < 9 ? "0" + Convert.ToString(i + 1) : Convert.ToString(i + 1);
  465. output += "\'";
  466. output += (current == i) ? " selected='true'" : "";
  467. output += ">" + arygMonths[i] + "</option>";
  468. }
  469. //Now close the select
  470. output += "</select>";
  471. return output;
  472. }
  473. public String generateSelectionYear(String name, int yearsForward, int yearsBack)
  474. {
  475. return generateSelectionYear(name, yearsForward, yearsBack, null);
  476. }
  477. /// <summary>
  478. /// Build a year select dropdown
  479. /// </summary>
  480. /// <param name="name">Name of the Select Tag</param>
  481. /// <param name="yearsForward">Number of years in the future to include</param>
  482. /// <param name="yearsBack">Number of years in the past to include</param>
  483. /// <param name="selected">Year to be preselected</param>
  484. /// <returns>HTML for select Month</returns>
  485. public String generateSelectionYear(String name, int yearsForward, int yearsBack, String selected)
  486. {
  487. DateTime now = DateTime.Now;
  488. String arg = selected;
  489. int current = now.Year;
  490. int start = current - yearsBack;
  491. int end = current + yearsForward;
  492. String output = "";
  493. //Check to see if a year is already selected, also check if the selected year is
  494. //greater than the end if if so make the end the selected year
  495. if (arg != null)
  496. {
  497. String aArg1 = arg.Split(new Char[] { ' ' })[0];
  498. String[] aArg = aArg1.Split(new Char[] { '-' });
  499. if (aArg.Length > 0 && aArg[0] != "")
  500. {
  501. if (arg.Length == 4)
  502. {
  503. current = Convert.ToInt32(arg);
  504. }
  505. else
  506. {
  507. current = Convert.ToInt32(aArg[2]);
  508. }
  509. }
  510. }
  511. if (current > end)
  512. end = current;
  513. // Write the Select tag
  514. output = "<select name=\'" + name + "\'>";
  515. // Now add the options for each month
  516. for (start = start + 0; start <= end; start++)
  517. {
  518. output += "<option value=\'" + start + "\'";
  519. output += current == start ? " selected='true'" : "";
  520. output += ">" + start + "</option>";
  521. }
  522. //Now close the select
  523. output += "</select>";
  524. return output;
  525. }
  526. /// <summary>
  527. /// Generates the select value= tag for a select box setting selected=true if the value = previous
  528. /// </summary>
  529. /// <param name="zValue">The value of the select option.</param>
  530. /// <param name="zPrevious">The value to compare.</param>
  531. /// <returns>Option attributes</returns>
  532. public String getOption(String zValue, String zPrevious)
  533. {
  534. String sReturn = "value=\"" + zValue + "\"";
  535. if (zValue == zPrevious)
  536. sReturn += " selected=\"true\"";
  537. return sReturn;
  538. }
  539. /// <summary>
  540. /// Standard look and field header.
  541. /// Should be called between a head html section of a web page
  542. /// </summary>
  543. /// <param name="zpPageTitle">The Page Title.</param>
  544. /// <param name="zDep1">Dummy parameter for backward compatibility</param>
  545. /// <param name="zDep2">Dummy parameter for backward compatibility</param>
  546. public void Brand_Head(String zpPageTitle, String zDep1, String zDep2)
  547. {
  548. Brand_Head(zpPageTitle);
  549. }
  550. /// <summary>
  551. /// Standard look and field header.
  552. /// Should be called between a head html section of a web page
  553. /// </summary>
  554. /// <param name="zpPageTitle">The Page Title.</param>
  555. /// <param name="zDep1">Dummy parameter for backward compatibility</param>
  556. public virtual void Brand_Head(String zpPageTitle, String zDep1)
  557. {
  558. Brand_Head(zpPageTitle);
  559. }
  560. /// <summary>
  561. /// Standard look and field header.
  562. /// Should be called between a head html section of a web page
  563. /// </summary>
  564. /// <param name="zpPageTitle">The Page Title.</param>
  565. public void Brand_Head(String zpPageTitle)
  566. {
  567. Response.Write(Brand_Head(zpPageTitle, true));
  568. }
  569. /// <summary>
  570. /// Standard look and field header.
  571. /// Should be inserted between a head html section of a web page
  572. /// </summary>
  573. /// <param name="zpPageTitle">The Page Title.</param>
  574. public string Brand_Head(String zpPageTitle, Boolean ReturnMode)
  575. {
  576. try
  577. {
  578. zgPageTitle = zpPageTitle;
  579. StringBuilder sb = new StringBuilder();
  580. //WADS REQUIREMENT: 5.1.1
  581. sb.Append("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">");
  582. sb.Append("<link href=\"" + zgFullFrameworkWeb + "Styles/style.css\" rel=\"stylesheet\" type=\"text/css\" />");
  583. sb.Append("<title>" + zgSystem + "_" + zpPageTitle + "</title>");
  584. sb.Append("<script>");
  585. sb.Append(" zgRootWeb = \"" + zgRootWeb + "\";");
  586. sb.Append("</script>");
  587. sb.Append("<script language=\"Javascript\" src=\"" + zgFullFrameworkWeb + "Javascript/CommonUtils.js\"></script>");
  588. return sb.ToString();
  589. }
  590. catch
  591. {
  592. return "";
  593. }
  594. }
  595. /// <summary>
  596. /// Standard Look and field body
  597. /// Should be called between a body html section of a web page
  598. /// </summary>
  599. /// <param name="zMenu">The side menu to display</param>
  600. /// <param name="zDep">Dummy parameter for backward compatibility</param>
  601. public void Brand_BodyTop(String zMenu, String zDep)
  602. {
  603. Brand_BodyTop(zMenu);
  604. }
  605. /// <summary>
  606. /// Standard Look and field body
  607. /// Should be called between a body html section of a web page
  608. /// </summary>
  609. /// <param name="zMenu">The side menu to display</param>
  610. /// <param name="zSearch">Dummy parameter for backward compatibility</param>
  611. /// <param name="bRenderTabCtrl">Dummy parameter for backward compatibility</param>
  612. public void Brand_BodyTop(String zMenu, String zSearch, Boolean bRenderTabCtrl)
  613. {
  614. Brand_BodyTop(zMenu);
  615. }
  616. /// <summary>
  617. /// Gets the menu DOM.
  618. /// </summary>
  619. /// <param name="zMenu">The menu name to obrain the DOM for</param>
  620. /// <returns>An XMLHelper DOM with the menu in it</returns>
  621. public XMLHelper getMenuDOM(String zMenu)
  622. {
  623. XMLHelper oMenu = null;
  624. if (Session["MenuXML"] == null)
  625. {
  626. String zFile = Request.MapPath("~/" + "menu/" + zgSystem + "Menu.xml");
  627. oMenu = new XMLHelper();
  628. oMenu.load(zFile);
  629. if (zgSecurity == "ON")
  630. {
  631. XMLHelper oRequest = newRequest("BuildUIMenu");
  632. //Security_nTX oSec = new Security_nTX();
  633. //String zResponse = oSec.GetUserResources(oRequest.getRootXML());
  634. //XMLHelper oResponse = new XMLHelper();
  635. //oResponse.load(zResponse);
  636. //Session.Add("UserResources", oResponse);
  637. //oResponse.appendNode(oMenu.getNode("/toplevel"));
  638. ////oMenu = oResponse.transform(zgFullFrameworkWeb + "xsl/FilterSideMenu.xsl");
  639. ////WADS: Secure connections (can't establish secure connection from app)...
  640. //oMenu = oResponse.transform("http://localhost/wi3/xsl/FilterSideMenu.xsl");
  641. }
  642. Session.Add("MenuXML", oMenu);
  643. }
  644. else
  645. {
  646. oMenu = (XMLHelper)Session["MenuXML"];
  647. }
  648. return oMenu;
  649. }
  650. /// <summary>
  651. /// Standard Look and field body
  652. /// Should be called between a body html section of a web page
  653. /// </summary>
  654. /// <param name="zMenu">The side menu to display</param>
  655. public virtual void Brand_BodyTop(String zMenu)
  656. {
  657. try
  658. {
  659. bTopCalled = true;
  660. XMLHelper oMenu = getMenuDOM(zMenu);
  661. String zXSL = Request.MapPath("~/" + "menu/" + zgSystem + "Branding.xsl");
  662. Dictionary<string, string> aParams = new Dictionary<string, string>();
  663. aParams.Add("param1", zgSystem);
  664. aParams.Add("param2", zMenu);
  665. aParams.Add("param3", zgRootWeb);
  666. aParams.Add("param4", zgFullFrameworkWeb);
  667. aParams.Add("param5", zgPageTitle);
  668. oBranding = oMenu.transform(zXSL, aParams);
  669. XMLHelper oHead = oBranding.getNode("head");
  670. Response.Write(oHead.getInnerXML());
  671. Response.Write("<table width=\"100%\" xxbgcolor=\"#FFFFFF\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" style=\"margin-top: 1px\">");
  672. Response.Write("<tr>");
  673. // Get the left menu XML
  674. if (!zMenu.Equals(""))
  675. {
  676. XMLHelper oSide = oBranding.getNode("side");
  677. Response.Write(oSide.getInnerXML());
  678. }
  679. Response.Write("<td width=\"100%\" align=\"left\" valign=\"top\">");
  680. Response.Write("<table width=\"100%\" align=\"left\" border=\"0\" cellpadding=\"2\" cellspacing=\"0\">");
  681. XMLHelper oTitle = oBranding.getNode("title");
  682. Response.Write(oTitle.getInnerXML());
  683. Response.Write("<tr>\r\n");
  684. Response.Write("<td colspan=\"" + oTitle.nodeCount("tr/td") + "\" valign=\"Top\">\r\n");
  685. Response.Write("<div style=\"padding-bottom: 8px; padding-top: 10px; padding-left:8px; padding-right:8px; width:100%; \">\r\n");
  686. }
  687. catch {}
  688. }
  689. /// <summary>
  690. /// Standard Look and field Footer
  691. /// Should be called between at just before the closing body html section of a web page
  692. /// </summary>
  693. public virtual void Brand_BodyBottom()
  694. {
  695. try
  696. {
  697. // ------------------------
  698. // Write Sync Keys to
  699. // hidden input fields
  700. // ------------------------
  701. gPrevPage = gCurrentPage;
  702. writeSyncKeysToInput(zgPageType);
  703. // ------------------------
  704. // Bubble to load order
  705. // if required
  706. // ------------------------
  707. LoadOrderBubble();
  708. if (bTopCalled)
  709. {
  710. Response.Write(" </div>\r\n");
  711. Response.Write(" </td>\r\n");
  712. Response.Write(" </tr>\r\n");
  713. Response.Write("</table>\r\n");
  714. Response.Write("</td>\r\n");
  715. Response.Write("</tr>\r\n");
  716. Response.Write("</table>\r\n");
  717. XMLHelper oBottom = oBranding.getNode("bottom");
  718. Response.Write(oBottom.getInnerXML());
  719. }
  720. Response.Write("<script language = \"javascript\">");
  721. if (bTopCalled)
  722. {
  723. Response.Write("try { divGlobalName.innerHTML = \"" + zgGlobalName + "\"; } catch (ex) {} \r\n");
  724. DateTime dEnd = DateTime.Now;
  725. TimeSpan tDiff = dEnd.Subtract(gdStart);
  726. String zDiff = "";
  727. if (tDiff.Seconds < 1)
  728. zDiff = tDiff.Milliseconds + " milliseconds";
  729. else
  730. zDiff = tDiff.TotalSeconds + " seconds";
  731. Response.Write("try { document.getElementById(\"idCopyright\").title = \"Render Time : " + zDiff + "\"; } catch (ex) {} ");
  732. }
  733. //write sync key information to page
  734. writeSyncKeys();
  735. Response.Write("</script>");
  736. }
  737. catch {}
  738. }
  739. /// <summary>
  740. /// Transforms the XML with the given XSL file.
  741. /// </summary>
  742. /// <param name="xmlFile">The XML file or XML String.</param>
  743. /// <param name="xslFile">The XSL file.</param>
  744. /// <returns>The Transformed XML String</returns>
  745. public String transformXML(String xmlFile, String xslFile)
  746. {
  747. return transformXML(xmlFile, xslFile, new Dictionary<string, string>());
  748. }
  749. /// <summary>
  750. /// Transforms the XML with the given XSL file.
  751. /// </summary>
  752. /// <param name="xmlFile">The XML file or XML String.</param>
  753. /// <param name="xslFile">The XSL file.</param>
  754. /// <param name="aParams">An array of Parameters to pass to the XSL stylesheet.</param>
  755. /// <returns>The Transformed XML String</returns>
  756. public String transformXML(String xmlFile, String xslFile, Dictionary<string, string> aParams)
  757. {
  758. StringWriter oString = new StringWriter();
  759. XMLHelper oDOM = new XMLHelper();
  760. if (xmlFile.StartsWith("<"))
  761. oDOM.load(xmlFile);
  762. else
  763. oDOM.load(Request.MapPath("~/" + xmlFile));
  764. if (xslFile.Substring(0,5).Contains(":"))
  765. oDOM.transform(xslFile, aParams, oString);
  766. else
  767. oDOM.transform(Request.MapPath("~/" + xslFile), aParams, oString);
  768. return oString.ToString();
  769. }
  770. /// <summary>
  771. /// Transforms the DOM with the given XSL file.
  772. /// </summary>
  773. /// <param name="oDOM">An XMLHelper document</param>
  774. /// <param name="xslFile">The XSL file.</param>
  775. public void transformXML(XMLHelper oDOM, String xslFile)
  776. {
  777. oDOM.transform(Request.MapPath("~/" + xslFile), Response.Output);
  778. }
  779. /// <summary>
  780. /// Transforms the DOM with the given XSL file.
  781. /// </summary>
  782. /// <param name="oDOM">An XMLHelper document</param>
  783. /// <param name="xslFile">The XSL file.</param>
  784. /// <param name="aParams">An array of Parameters to pass to the XSL stylesheet.</param>
  785. public void transformXML(XMLHelper oDOM, String xslFile, Dictionary<string, string> aParams)
  786. {
  787. oDOM.transform(Request.MapPath("~/" + xslFile), aParams, Response.Output);
  788. }
  789. /// <summary>
  790. /// Creates a standard request DOM with the resource, system and user (MUD ID).
  791. /// </summary>
  792. /// <param name="zResource">The resource (method) of the request.</param>
  793. /// <returns>A standard request DOM with the resource, system and user</returns>
  794. public XMLHelper newRequest(String zResource)
  795. {
  796. XMLHelper oXML = new XMLHelper();
  797. oXML.createStandardRequest(zResource, zgUser, zgSystem.ToUpper());
  798. if (zgSecurity == "OFF")
  799. oXML.appendAttribute("sec", "off");
  800. return oXML;
  801. }
  802. /// <summary>
  803. /// Loads a DOM with the XML file or XML String.
  804. /// </summary>
  805. /// <param name="zXML">The XML string or file.</param>
  806. /// <returns>An XML helper DOM</returns>
  807. public XMLHelper loadDOM(String zXML)
  808. {
  809. XMLHelper oDOM = new XMLHelper();
  810. oDOM.load(zXML);
  811. return oDOM;
  812. }
  813. /// <summary>
  814. /// Gets a standard request DOM using the Request.Form and Request.QueryString parameters.
  815. /// </summary>
  816. /// <param name="zResource">The resource (method) for the request.</param>
  817. /// <returns>An XMLHelper DOM containing the Request.Form and Request.QueryString parameters.</returns>
  818. public XMLHelper getRequestDOM(String zResource)
  819. {
  820. XMLHelper oDOM = newRequest(zResource);
  821. oDOM.appendNode(Request.Form);
  822. oDOM.appendNode(Request.QueryString);
  823. return oDOM;
  824. }
  825. /// <summary>
  826. /// Gets a request DOM using the Request.Form and Request.QueryString parameters.
  827. /// </summary>
  828. /// <returns>An XMLHelper DOM containing the Request.Form and Request.QueryString parameters.</returns>
  829. public XMLHelper getRequestDOM()
  830. {
  831. XMLHelper oDOM = new XMLHelper("request");
  832. oDOM.appendNode(Request.Form);
  833. oDOM.appendNode(Request.QueryString);
  834. return oDOM;
  835. }
  836. /// <summary>
  837. /// Gets the request DOM with Request.QueryString parameters.
  838. /// </summary>
  839. /// <returns>An XMLHelper DOM containing Request.QueryString parameters.</returns>
  840. public XMLHelper getRequestQueryDOM()
  841. {
  842. XMLHelper oDOM = new XMLHelper("request");
  843. oDOM.appendNode(Request.QueryString);
  844. return oDOM;
  845. }
  846. /// <summary>
  847. /// Gets the request DOM with Request.Form parameters.
  848. /// </summary>
  849. /// <returns>An XMLHelper DOM containing Request.Form parameters</returns>
  850. public XMLHelper getRequestFormDOM()
  851. {
  852. XMLHelper oDOM = new XMLHelper("request");
  853. oDOM.appendNode(Request.Form);
  854. return oDOM;
  855. }
  856. /// <summary>
  857. /// Executes a business method returning a DOM.
  858. /// </summary>
  859. /// <param name="oMethod">The Bizrule method.</param>
  860. /// <param name="oRequest">The Request DOM.</param>
  861. /// <returns>An XMLHelper response DOM</returns>
  862. public XMLHelper executeBizMethodDOM(BizRule oMethod, XMLHelper oRequest)
  863. {
  864. return executeBizMethodDOM(oMethod, oRequest.getRootXML(), true);
  865. }
  866. /// <summary>
  867. /// Executes a business method returning a DOM.
  868. /// </summary>
  869. /// <param name="oMethod">The Bizrule method.</param>
  870. /// <param name="zRequestXML">The request XML.</param>
  871. /// <returns>An XMLHelper response DOM</returns>
  872. public XMLHelper executeBizMethodDOM(BizRule oMethod, String zRequestXML)
  873. {
  874. return executeBizMethodDOM(oMethod, zRequestXML, true);
  875. }
  876. /// <summary>
  877. /// Executes a business method returning a DOM.
  878. /// </summary>
  879. /// <param name="oMethod">The Bizrule method.</param>
  880. /// <param name="zRequestXML">The request XML.</param>
  881. /// <param name="bDisplayErrors">if set to <c>true</c> [automatically display errors].</param>
  882. /// <returns>An XMLHelper response DOM</returns>
  883. public XMLHelper executeBizMethodDOM(BizRule oMethod, String zRequestXML, Boolean bDisplayErrors)
  884. {
  885. XMLHelper oDOM = new XMLHelper();
  886. oDOM.load(executeBizMethod(oMethod, zRequestXML, bDisplayErrors));
  887. return oDOM;
  888. }
  889. /// <summary>
  890. /// Executes a business method returning an XML String.
  891. /// </summary>
  892. /// <param name="oMethod">The Bizrule method.</param>
  893. /// <param name="oRequest">The Request DOM.</param>
  894. /// <returns>The response dom as a string</returns>
  895. public String executeBizMethod(BizRule oMethod, XMLHelper oRequest)
  896. {
  897. return executeBizMethod(oMethod, oRequest.getRootXML(), true);
  898. }
  899. /// <summary>
  900. /// Executes a business method returning an XML String.
  901. /// </summary>
  902. /// <param name="oMethod">The Bizrule method.</param>
  903. /// <param name="zRequestXML">The request XML.</param>
  904. /// <returns>The response dom as a string</returns>
  905. public String executeBizMethod(BizRule oMethod, String zRequestXML)
  906. {
  907. return executeBizMethod(oMethod, zRequestXML, true);
  908. }
  909. /// <summary>
  910. /// Executes a business method returning an XML String.
  911. /// </summary>
  912. /// <param name="oMethod">The Bizrule method.</param>
  913. /// <param name="zRequestXML">The request XML.</param>
  914. /// <param name="bDisplayErrors">if set to <c>true</c> [automatically display errors].</param>
  915. /// <returns></returns>
  916. public String executeBizMethod(BizRule oMethod, String zRequestXML, Boolean bDisplayErrors)
  917. {
  918. try
  919. {
  920. return oMethod(zRequestXML);
  921. }
  922. catch (Exception ex)
  923. {
  924. if (bDisplayErrors != false)
  925. {
  926. //WADS: Detailed exception info no longer given to the user...
  927. throw new Exception("You cannot give detailed exception info to the user");
  928. }
  929. else
  930. {
  931. throw ex;
  932. }
  933. }
  934. }
  935. /// <summary>
  936. /// Executes a business method returning an XML String.
  937. /// </summary>
  938. /// <param name="oMethod">The XMLBizrule method.</param>
  939. /// <param name="zRequestXML">The request XML.</param>
  940. /// <param name="bDisplayErrors">if set to <c>true</c> [automatically display errors].</param>
  941. /// <returns></returns>
  942. public XMLHelper executeBizMethod(XMLBizRule oMethod, XMLHelper oRequest, Boolean bDisplayErrors)
  943. {
  944. if (bDisplayErrors == true)
  945. {
  946. try
  947. {
  948. return oMethod(oRequest);
  949. }
  950. catch (Exception ex)
  951. {
  952. if (bDisplayErrors != false)
  953. {
  954. if (ex.Message.Substring(0,9) == "ORA-20000")
  955. {
  956. throw ex;
  957. }
  958. else
  959. {
  960. //WADS: Detailed exception info no longer given to the user...
  961. throw new Exception("You cannot give detailed exception info to the user");
  962. }
  963. }
  964. else
  965. {
  966. throw ex;
  967. }
  968. }
  969. }
  970. else
  971. {
  972. return oMethod(oRequest);
  973. }
  974. }
  975. public StringBuilder executeBizMethod(CSVBizRule oMethod, XMLHelper oRequest)
  976. {
  977. return oMethod(oRequest);
  978. }
  979. /// <summary>
  980. /// Displays an error message
  981. /// </summary>
  982. /// <param name="ex">The Exception to handle.</param>
  983. public void handleError(Exception ex)
  984. {
  985. handleError(ex, null);
  986. }
  987. /// <summary>
  988. /// Displays an error message
  989. /// </summary>
  990. /// <param name="ex">The Exception to handle.</param>
  991. /// <param name="zRequestXML">The Exception to handle.</param>
  992. public void handleError(Exception ex, String zRequestXML)
  993. {
  994. //WADS: Detailed exception info no longer given to the user...
  995. throw new Exception("You cannot give detailed exception info to the user");
  996. }
  997. /// <summary>
  998. /// Validates the number.
  999. /// </summary>
  1000. /// <param name="zInput">The Number to check.</param>
  1001. /// <returns>Converted number as a string</returns>
  1002. public String validNumber(String zInput)
  1003. {
  1004. try
  1005. {
  1006. return Convert.ToDouble(zInput).ToString();
  1007. }
  1008. catch
  1009. {
  1010. return "";
  1011. }
  1012. }
  1013. /// <summary>
  1014. /// Returns a default of the checked value is null otherwise it returns a the value to check
  1015. /// </summary>
  1016. /// <param name="oCheck">Value to check.</param>
  1017. /// <param name="zDefault">The default.</param>
  1018. /// <returns>Either the Checked value or the default depending on whether the checked value is null</returns>
  1019. public String ifNull(Object oCheck, String zDefault)
  1020. {
  1021. if (oCheck == null)
  1022. return zDefault;
  1023. else
  1024. return oCheck.ToString();
  1025. }
  1026. /// <summary>
  1027. /// Returns a default of the checked value is null otherwise it returns a the value to check
  1028. /// </summary>
  1029. /// <param name="oCheck">Value to check.</param>
  1030. /// <param name="iDefault">The default.</param>
  1031. /// <returns>Either the Checked value or the default depending on whether the checked value is null</returns>
  1032. public int ifNull(Object oCheck, int iDefault)
  1033. {
  1034. if (oCheck == null)
  1035. return iDefault;
  1036. else
  1037. return Convert.ToInt32(oCheck);
  1038. }
  1039. /// <summary>
  1040. /// Determines whether the user has a given resource.
  1041. /// </summary>
  1042. /// <param name="zResourceName">Name of the resource to check.</param>
  1043. /// <returns>
  1044. /// <c>true</c> if the user has the given resource; otherwise, <c>false</c>.
  1045. /// </returns>
  1046. public Boolean hasSecurityResource(String zResourceName)
  1047. {
  1048. XMLHelper oDOM = (XMLHelper)Session["UserResources"];
  1049. if (oDOM == null)
  1050. return false;
  1051. if (oDOM.nodeCount("//resource[@name='" + zResourceName.ToUpper() + "']") == 0)
  1052. return false;
  1053. else
  1054. return true;
  1055. }
  1056. //========================================================================================
  1057. // W A D S
  1058. //========================================================================================
  1059. public String RequestQS(String input)
  1060. {
  1061. String strCheck = ifNull(Request.QueryString[input], "");
  1062. return Server.HtmlEncode(strCheck);
  1063. }
  1064. public int RequestQS(String input, int intDefault)
  1065. {
  1066. return ifNull(Request.QueryString[input], 0);
  1067. }
  1068. public String RequestF(String input)
  1069. {
  1070. String strCheck = ifNull(Request.Form[input], "");
  1071. return Server.HtmlEncode(strCheck);
  1072. }
  1073. public int RequestF(String input, int intDefault)
  1074. {
  1075. return ifNull(Request.Form[input], 0);
  1076. }
  1077. public String RequestFGet(String input)
  1078. {
  1079. String strCheck = ifNull(Request.Form.Get(input), "");
  1080. return Server.HtmlEncode(strCheck);
  1081. }
  1082. public String RequestP(String input)
  1083. {
  1084. String strCheck = ifNull(Request.Params[input], "");
  1085. return Server.HtmlEncode(strCheck);
  1086. }
  1087. public String RequestWADS(String input, String strDefault)
  1088. {
  1089. String strCheck = ifNull(Request[input], strDefault);
  1090. return Server.HtmlEncode(strCheck);
  1091. }
  1092. public String RequestWADS(String input)
  1093. {
  1094. String strCheck = ifNull(Request[input], "");
  1095. return Server.HtmlEncode(strCheck);
  1096. }
  1097. public int RequestWADS(String input, int intDefault)
  1098. {
  1099. return ifNull(Request[input], 0);
  1100. }
  1101. public String RequestCookies(String section, String input)
  1102. {
  1103. String strCookie = "";
  1104. try
  1105. {
  1106. strCookie = Request.Cookies[section][input];
  1107. }
  1108. catch (Exception ex)
  1109. {
  1110. strCookie = "";
  1111. }
  1112. return Server.HtmlEncode(strCookie);
  1113. }
  1114. public String RequestXML(String input)
  1115. // for xml strings do nothing for now; Server.HtmlEncode corrupts xml stings
  1116. {
  1117. String strCheck = ifNull(Request[input], "");
  1118. return strCheck;
  1119. }
  1120. public XMLHelper serialisePost()
  1121. {
  1122. XMLHelper oRequest = new XMLHelper("request");
  1123. oRequest.appendNode("system", zgSystem);
  1124. if (zgSecurity == "OFF") oRequest.appendAttribute("sec", "off");
  1125. foreach (String s in Request.Form)
  1126. {
  1127. if (s != null)
  1128. {
  1129. if (s[0] == '_')
  1130. {
  1131. if (s.Length > 1)
  1132. {
  1133. oRequest.appendAttribute(s.Substring(1), Request.Form[s]);
  1134. }
  1135. }
  1136. else
  1137. {
  1138. //Sync Key
  1139. if (s.StartsWith("g_"))
  1140. {
  1141. String zField = s.Substring(2);
  1142. if (ifNull(Request.Form[zField], "") == "")
  1143. oRequest.setNode(zField, Request.Form[s]);
  1144. }
  1145. else
  1146. {
  1147. oRequest.setNode(s, Request.Form[s]);
  1148. }
  1149. }
  1150. }
  1151. }
  1152. return oRequest;
  1153. }
  1154. }
  1155. }