You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

423 lines
16 KiB

  1. using System.Data;
  2. using System.Text;
  3. using System.Web;
  4. namespace Swift.web.Library
  5. {
  6. public static class Misc
  7. {
  8. #region Methods
  9. public static string GetMessageForNoRecords()
  10. {
  11. return "<span class =\"no-record\">No records</span>";
  12. }
  13. public static string DataTableToHtmlTable(ref DataTable dt)
  14. {
  15. var str = new StringBuilder("<table width=\"100%\" border=\"0\" class=\"table table-responsive table-bordered table-striped\" cellpadding=\"5\" cellspacing=\"5\" align=\"center\">");
  16. str.Append("<tr>");
  17. var cols = dt.Columns.Count;
  18. for (var i = 0; i < cols; i++)
  19. {
  20. str.Append("<th align=\"left\">" + dt.Columns[i].ColumnName + "</th>");
  21. }
  22. str.Append("</tr>");
  23. foreach (DataRow dr in dt.Rows)
  24. {
  25. str.Append("<tr>");
  26. for (var i = 0; i < cols; i++)
  27. {
  28. str.Append("<td align=\"left\">" + dr[i] + "</td>");
  29. }
  30. str.Append("</tr>");
  31. }
  32. str.Append("</table>");
  33. return str.ToString();
  34. }
  35. public static void BeginForm(string formCaption)
  36. {
  37. var htmlCode = new StringBuilder("");
  38. htmlCode.AppendLine("<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" class=\"fromTable\" align=\"left\">");
  39. htmlCode.AppendLine("<tr>");
  40. htmlCode.AppendLine("<th colspan=\"4\" class=\"frmTitle\">" + formCaption + " </th>");
  41. htmlCode.AppendLine("</tr>");
  42. htmlCode.AppendLine("<tr>");
  43. htmlCode.AppendLine("<td>");
  44. HttpContext.Current.Response.Write(htmlCode.ToString());
  45. htmlCode.Clear();
  46. }
  47. public static void EndForm()
  48. {
  49. var htmlCode = new StringBuilder("");
  50. htmlCode.AppendLine("</td>");
  51. htmlCode.AppendLine("</tr>");
  52. htmlCode.AppendLine("</table>");
  53. HttpContext.Current.Response.Write(htmlCode.ToString());
  54. htmlCode.Clear();
  55. }
  56. public static void CreateBredCrom(string headerCaption)
  57. {
  58. var htmlCode = new StringBuilder("");
  59. htmlCode.AppendLine("<table width=\"700px\" border=\"0\" align=\"left\" cellpadding=\"0\" cellspacing=\"0\">");
  60. htmlCode.AppendLine("<tr>");
  61. htmlCode.AppendLine("<td align=\"left\" valign=\"top\" class=\"bredCrom\">" + headerCaption + "</td>");
  62. htmlCode.AppendLine("</tr>");
  63. htmlCode.AppendLine("<tr>");
  64. htmlCode.AppendLine("<td height=\"10\" class=\"shadowBG\"></td>");
  65. htmlCode.AppendLine("</tr>");
  66. htmlCode.AppendLine("</table>");
  67. htmlCode.AppendLine("<div style =\"clear:both\"></div>");
  68. HttpContext.Current.Response.Write(htmlCode.ToString());
  69. htmlCode.Clear();
  70. }
  71. public static void BeginHeaderForGrid(string headerCaption, string childAlign)
  72. {
  73. var htmlCode = new StringBuilder("");
  74. htmlCode.AppendLine("<table width=\"100%\" border=\"0\">");
  75. htmlCode.AppendLine("<tr>");
  76. htmlCode.AppendLine("<td valign=\"bottom\" class=\"\" valign=\"buttom\">");
  77. htmlCode.AppendLine("<div class=\"BredCurm\">" + headerCaption + "</div>");
  78. htmlCode.AppendLine("</td>");
  79. htmlCode.AppendLine("</tr>");
  80. htmlCode.AppendLine("<tr>");
  81. htmlCode.AppendLine("<td valign=\"top\" align=\"" + childAlign + "\">");
  82. HttpContext.Current.Response.Write(htmlCode.ToString());
  83. htmlCode.Clear();
  84. }
  85. public static void BeginHeaderForGrid(string headerCaption)
  86. {
  87. BeginHeaderForGrid(headerCaption, "center");
  88. }
  89. public static void EndHeaderForGrid()
  90. {
  91. var htmlCode = new StringBuilder("");
  92. htmlCode.AppendLine("</td>");
  93. htmlCode.AppendLine("</tr>");
  94. htmlCode.AppendLine("</table>");
  95. HttpContext.Current.Response.Write(htmlCode.ToString());
  96. htmlCode.Clear();
  97. }
  98. #region TrackChanges
  99. public static void EnableTrackChanges(ref System.Web.UI.WebControls.TextBox tb, string hddField)
  100. {
  101. tb.Attributes.Add("onkeyup", "return TrackChanges('" + hddField + "');");
  102. tb.Attributes.Add("onpaste", "return TrackChanges('" + hddField + "');");
  103. }
  104. public static void EnableTrackChanges(ref System.Web.UI.WebControls.DropDownList ddl, string hddField)
  105. {
  106. ddl.Attributes.Add("onchange", "return TrackChanges('" + hddField + "');");
  107. ddl.Attributes.Add("onclick", "return TrackChanges('" + hddField + "');");
  108. }
  109. #endregion TrackChanges
  110. #region MakeNumericTextbox
  111. public static void MakeAmountTextBox(ref System.Web.UI.WebControls.TextBox tb)
  112. {
  113. tb.Attributes.Add("onblur", "UpdateComma(this);");
  114. }
  115. public static void MakeDisabledTextbox(ref System.Web.UI.WebControls.TextBox tb)
  116. {
  117. tb.Enabled = false;
  118. //tb.BackColor = System.Drawing.Color.Gray;
  119. }
  120. public static void MakeNumericTextbox(ref System.Web.UI.WebControls.TextBox tb)
  121. {
  122. tb.Attributes.Add("onfocus", "resetInput(this, '0', 1, true);");
  123. tb.Attributes.Add("onblur", "resetInput(this, '0', 2, true);");
  124. tb.Attributes.Add("onkeydown", "return numericOnly(this, (event?event:evt), true);");
  125. tb.Attributes.Add("onpaste", "return manageOnPaste(this);");
  126. }
  127. public static void MakeNumericTextbox(ref System.Web.UI.WebControls.TextBox tb, bool allowBlank)
  128. {
  129. MakeNumericTextbox(ref tb, allowBlank, false);
  130. }
  131. public static void MakeNumericTextbox(ref System.Web.UI.WebControls.TextBox tb, bool allowBlank, bool donotSupportNegative)
  132. {
  133. tb.Attributes.Add("onfocus", "resetInput(this, '0', 1, true);");
  134. tb.Attributes.Add("onblur", "resetInput(this, '0', 2, true, " + (allowBlank ? "true" : "false") + ");");
  135. tb.Attributes.Add("onkeydown", "return numericOnly(this, (event?event:evt), true, " + (donotSupportNegative ? "true" : "false") + ");");
  136. tb.Attributes.Add("onpaste", "return manageOnPaste(this);");
  137. }
  138. public static void DisableInput(ref System.Web.UI.WebControls.TextBox tb)
  139. {
  140. tb.Attributes.Add("onkeydown", "return false;");
  141. tb.Attributes.Add("onpaste", "return false;");
  142. }
  143. public static string MakeNumericTextbox()
  144. {
  145. return MakeNumericTextbox("");
  146. }
  147. public static string MakeNumericTextbox(string id)
  148. {
  149. return MakeNumericTextbox(id, id);
  150. }
  151. public static string MakeNumericTextbox(object value)
  152. {
  153. return MakeNumericTextbox("", value);
  154. }
  155. public static string MakeNumericTextbox(string id, string name)
  156. {
  157. return MakeNumericTextbox(id, name, "");
  158. }
  159. public static string MakeNumericTextbox(string id, object value)
  160. {
  161. return MakeNumericTextbox(id, "", value);
  162. }
  163. public static string MakeNumericTextbox(string id, string name, object value)
  164. {
  165. return MakeNumericTextbox(id, name, value, "", "");
  166. }
  167. public static string MakeNumericTextbox(string id, string name, object value, string attributes, string callBackFunction)
  168. {
  169. if (string.IsNullOrEmpty(name))
  170. name = id;
  171. var html = new StringBuilder("");
  172. html.Append("<input type = \"text\"");
  173. if (!string.IsNullOrEmpty(id))
  174. html.Append(" id=\"" + id + "\"");
  175. if (!string.IsNullOrEmpty(name))
  176. html.Append(" name=\"" + name + "\"");
  177. if (!string.IsNullOrEmpty((value ?? "").ToString()))
  178. html.Append(" value=\"" + value + "\"");
  179. if (!string.IsNullOrEmpty(attributes))
  180. html.Append(" " + attributes);
  181. html.Append(" onfocus = \"resetInput(this, '0', 1);" + callBackFunction + "\"");
  182. html.Append("onblur = \"resetInput(this, '0', 2);" + callBackFunction + "\"");
  183. html.Append("onkeydown =\"return numericOnly(this, (event?event:evt), true);" + callBackFunction + "\"");
  184. html.Append("onpaste = \"return false;" + callBackFunction + "\"");
  185. html.Append(" />");
  186. return html.ToString();
  187. }
  188. public static void MakeIntegerTextbox(ref System.Web.UI.WebControls.TextBox tb, bool allowBlank, bool donotSupportNegative)
  189. {
  190. tb.Attributes.Add("onfocus", "resetInput(this, '0', 1, true);");
  191. tb.Attributes.Add("onblur", "resetInput(this, '0', 2, true, " + (allowBlank ? "true" : "false") + ");");
  192. tb.Attributes.Add("onkeydown", "return numericOnly(this, (event?event:evt), false, " + (donotSupportNegative ? "true" : "false") + ");");
  193. tb.Attributes.Add("onpaste", "return false;");
  194. }
  195. public static string MakeIntegerTextbox(string id, string name, object value, string attributes, string callBackFunction)
  196. {
  197. if (string.IsNullOrEmpty(name))
  198. name = id;
  199. var html = new StringBuilder("");
  200. html.Append("<input type = \"text\"");
  201. if (!string.IsNullOrEmpty(id))
  202. html.Append(" id=\"" + id + "\"");
  203. if (!string.IsNullOrEmpty(name))
  204. html.Append(" name=\"" + name + "\"");
  205. if (!string.IsNullOrEmpty((value ?? "").ToString()))
  206. html.Append(" value=\"" + value + "\"");
  207. if (!string.IsNullOrEmpty(attributes))
  208. html.Append(" " + attributes);
  209. html.Append(" onfocus = \"resetInput(this, '0', 1);" + callBackFunction + "\""); ;
  210. html.Append(" onblur = \"IntegerOnly(this);" + callBackFunction + "\"");
  211. html.Append(" />");
  212. return html.ToString();
  213. }
  214. public static string MakeFloatTextbox(string id, string name, object value, string attributes, string callBackFunction)
  215. {
  216. if (string.IsNullOrEmpty(name))
  217. name = id;
  218. var html = new StringBuilder("");
  219. html.Append("<input type = \"text\"");
  220. if (!string.IsNullOrEmpty(id))
  221. html.Append(" id=\"" + id + "\"");
  222. if (!string.IsNullOrEmpty(name))
  223. html.Append(" name=\"" + name + "\"");
  224. if (!string.IsNullOrEmpty((value ?? "").ToString()))
  225. html.Append(" value=\"" + value + "\"");
  226. if (!string.IsNullOrEmpty(attributes))
  227. html.Append(" " + attributes);
  228. html.Append(" onfocus = \"resetInput(this, '0', 1);" + callBackFunction + "\""); ;
  229. html.Append(" onblur = \"FloatOnly(this);" + callBackFunction + "\"");
  230. html.Append(" />");
  231. return html.ToString();
  232. }
  233. #endregion MakeNumericTextbox
  234. #region SwiftCloseButton
  235. public static void SwiftCloseButton()
  236. {
  237. SwiftCloseButton((object)null);
  238. }
  239. public static void SwiftCloseButton(object id)
  240. {
  241. SwiftCloseButton(id, "Close");
  242. }
  243. public static void SwiftCloseButton(string text)
  244. {
  245. SwiftCloseButton(null, text);
  246. }
  247. public static void SwiftCloseButton(object id, string text)
  248. {
  249. var html = "";
  250. if (id != null)
  251. {
  252. html += "<input class=\"button\" id =\"" + id + "\" type = \"button\" value = \"" + text + "\" onclick = \"CloseDialog(null);\">";
  253. }
  254. else
  255. {
  256. html += "<input class=\"button\" type = \"button\" value = \"" + text + "\" onclick = \"CloseDialog(null);\">";
  257. }
  258. HttpContext.Current.Response.Write(html);
  259. }
  260. #endregion SwiftCloseButton
  261. #region SwiftBackButton
  262. public static void SwiftBackButton()
  263. {
  264. SwiftBackButton((object)null);
  265. }
  266. public static void SwiftBackButton(object id)
  267. {
  268. SwiftBackButton(id, "Back");
  269. }
  270. public static void SwiftBackButton(string text)
  271. {
  272. SwiftBackButton(null, text);
  273. }
  274. public static void SwiftBackButton(object id, string text)
  275. {
  276. var html = "";
  277. if (id != null)
  278. {
  279. html += "<input class=\"button\" id =\"" + id + "\" type = \"button\" value = \"" + text + "\" onclick = \"GoBack();\">";
  280. }
  281. else
  282. {
  283. html += "<input class=\"button\" type = \"button\" value = \"" + text + "\" onclick = \"GoBack();\">";
  284. }
  285. HttpContext.Current.Response.Write(html);
  286. }
  287. #endregion SwiftBackButton
  288. #endregion Methods
  289. public static string GetIcon(string iconType)
  290. {
  291. switch (iconType.ToLower())
  292. {
  293. case "edit":
  294. return "<img class = \"showHand\" border = \"0\" title = \"Edit\" alt=\"Edit\" src=\"" + GetStatic.GetUrlRoot() + "/images/edit.gif\" />";
  295. case "ba":
  296. return "<img class = \"showHand\" border = \"0\" title = \"Show Bank Account List\" alt=\"Edit\" src=\"" + GetStatic.GetUrlRoot() + "/images/ba.gif\" />";
  297. case "delete":
  298. return "<img class = \"showHand\" border = \"0\" title = \"Delete\" alt=\"Delete\" src=\"" + GetStatic.GetUrlRoot() + "/images/delete.gif\" />";
  299. case "add":
  300. return "<img class = \"showHand\" border = \"0\" title = \"Add\" alt=\"Add\" src=\"" + GetStatic.GetUrlRoot() + "/images/add.gif\"/>";
  301. case "wait":
  302. return "<img class = \"showHand\" border = \"0\" title = \"Waiting for approval\" alt=\"Waiting for approval\" src=\"" + GetStatic.GetUrlRoot() + "/images/wait-icon.png\"/>";
  303. case "viewchanges":
  304. return "<img class = \"showHand\" border = \"0\" title = \"View Changes\" alt=\"View Changes\" src=\"" + GetStatic.GetUrlRoot() + "/images/view-changes.jpg\"/>";
  305. case "vd":
  306. return "<img class = \"showHand\" border = \"0\" title = \"View Details\" alt=\"View Details\" src=\"" + GetStatic.GetUrlRoot() + "/images/view-detail-icon.png\"/>";
  307. case "file-format":
  308. return "<img class = \"showHand\" border = \"0\" title = \"File Format\" alt=\"File Format\" src=\"" + GetStatic.GetUrlRoot() + "/images/file-format.png\"/>";
  309. case "info":
  310. return "<img class = \"showHand\" border = \"0\" title = \"More Info\" alt=\"More Info\" src=\"" + GetStatic.GetUrlRoot() + "/images/info.gif\"/>";
  311. default:
  312. return iconType;
  313. }
  314. }
  315. public static void DisableInput(ref System.Web.UI.WebControls.TextBox tb, string defVal)
  316. {
  317. tb.Attributes.Add("onkeydown", "return DisableInput(this, (event?event:evt));");
  318. if (defVal != null)
  319. {
  320. tb.Attributes.Add("value", defVal);
  321. }
  322. tb.Attributes.Add("onpaste", "return false;");
  323. }
  324. public static string GetIcon(string iconType, string onClickFunction)
  325. {
  326. var html = new StringBuilder("<a href=\"#\" onclick = \"" + onClickFunction + "\" >");
  327. html.Append(GetIcon(iconType));
  328. html.Append("</a>");
  329. return html.ToString();
  330. }
  331. public static string JQueryCalUtil()
  332. {
  333. return @"
  334. <script type='text/javascript' language='javascript'>
  335. Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequest);
  336. function EndRequest(sender, args) {
  337. if (args.get_error() == undefined) {
  338. LoadAllCal();
  339. }
  340. }
  341. LoadAllCal();
  342. </script> ";
  343. }
  344. }
  345. }