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.

373 lines
13 KiB

4 years ago
  1. using Common.Helper;
  2. using Repository.DAO;
  3. using Repository.DAO.SwiftDao;
  4. using System;
  5. using System.Collections;
  6. using System.Collections.Generic;
  7. using System.Data;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Web;
  11. using System.Web.UI.WebControls;
  12. namespace JMEAgentSystem.Library
  13. {
  14. public class SwiftLibrary : SwiftDao
  15. {
  16. public string CreateDynamicDropDownBox(string name, string sql, string valueField, string textField, string defaultValue)
  17. {
  18. var html = new StringBuilder("");
  19. var width = "";
  20. var dt = ExecuteDataSet(sql).Tables[0];
  21. html.Append("<select " + width + " name=\"" + name + "\" id =\"" + name + "\" class = \"formText\">");
  22. foreach (DataRow row in dt.Rows)
  23. {
  24. html.Append("<option value=\"" + row[valueField].ToString() + "\"" + AutoSelect(row[valueField].ToString(), defaultValue) + ">" + row[textField].ToString() + "</option>");
  25. }
  26. html.Append("</select>");
  27. return html.ToString();
  28. }
  29. public void SetDefaultDdl(ref DropDownList ddl, string label, bool isClearItem)
  30. {
  31. if (isClearItem)
  32. ddl.Items.Clear();
  33. var item = new ListItem(label, "");
  34. ddl.Items.Add(item);
  35. }
  36. public void SetDDL(ref DropDownList ddl, string sql, string valueField, string textField, string valueToBeSelected, string label)
  37. {
  38. var ds = ExecuteDataSet(sql);
  39. ListItem item = null;
  40. if (ds.Tables.Count == 0)
  41. {
  42. if (label != "")
  43. {
  44. item = new ListItem(label, "");
  45. ddl.Items.Add(item);
  46. }
  47. return;
  48. }
  49. var dt = ds.Tables[0];
  50. ddl.Items.Clear();
  51. if (label != "")
  52. {
  53. item = new ListItem(label, "");
  54. ddl.Items.Add(item);
  55. }
  56. foreach (DataRow row in dt.Rows)
  57. {
  58. item = new ListItem();
  59. item.Value = row[valueField].ToString();
  60. item.Text = row[textField].ToString();
  61. if (row[valueField].ToString().ToUpper() == valueToBeSelected.ToUpper())
  62. item.Selected = true;
  63. ddl.Items.Add(item);
  64. }
  65. }
  66. public void SetDDL2(ref DropDownList ddl, string sql, string textField, string valueToBeSelected, string label)
  67. {
  68. var dt = ExecuteDataSet(sql).Tables[0];
  69. ListItem item = null;
  70. ddl.Items.Clear();
  71. if (label != "")
  72. {
  73. item = new ListItem(label, "");
  74. ddl.Items.Add(item);
  75. }
  76. foreach (DataRow row in dt.Rows)
  77. {
  78. item = new ListItem();
  79. item.Value = row[textField].ToString();
  80. item.Text = row[textField].ToString();
  81. if (row[textField].ToString().ToUpper() == valueToBeSelected.ToUpper())
  82. item.Selected = true;
  83. ddl.Items.Add(item);
  84. }
  85. }
  86. public void SetDDLFromDT(ref DropDownList ddl, DataTable dataTable, string valueField, string textField, string valueToBeSelected, string label)
  87. {
  88. ListItem item = null;
  89. if (dataTable == null)
  90. return;
  91. if (dataTable.Rows.Count == 0)
  92. {
  93. if (label != "")
  94. {
  95. item = new ListItem(label, "");
  96. ddl.Items.Add(item);
  97. }
  98. return;
  99. }
  100. var dt = dataTable;
  101. ddl.Items.Clear();
  102. if (label != "")
  103. {
  104. item = new ListItem(label, "");
  105. ddl.Items.Add(item);
  106. }
  107. foreach (DataRow row in dt.Rows)
  108. {
  109. item = new ListItem();
  110. item.Value = row[valueField].ToString();
  111. item.Text = row[textField].ToString();
  112. if (row[valueField].ToString().ToUpper() == valueToBeSelected.ToUpper())
  113. item.Selected = true;
  114. ddl.Items.Add(item);
  115. }
  116. }
  117. public void SetDDL3(ref DropDownList ddl, string sql, string valueField, string textField, string valueToBeSelected, string label)
  118. {
  119. var dt = ExecuteDataSet(sql).Tables[0];
  120. ListItem item = null;
  121. ddl.Items.Clear();
  122. if (label != "")
  123. {
  124. item = new ListItem(label, "");
  125. ddl.Items.Add(item);
  126. }
  127. foreach (DataRow row in dt.Rows)
  128. {
  129. item = new ListItem();
  130. item.Value = row[valueField].ToString();
  131. item.Text = row[textField].ToString();
  132. if (row[textField].ToString().ToUpper() == valueToBeSelected.ToUpper())
  133. item.Selected = true;
  134. ddl.Items.Add(item);
  135. }
  136. }
  137. public void BeginForm(string formCaption)
  138. {
  139. var htmlCode = new StringBuilder("");
  140. htmlCode.AppendLine("<table class=\"container\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"40%\">");
  141. htmlCode.AppendLine("<tbody>");
  142. htmlCode.AppendLine("<tr>");
  143. htmlCode.AppendLine("<td width=\"1%\" class=\"container_tl\"><div></div></td>");
  144. htmlCode.AppendLine("<td width=\"91%\" class=\"container_tmid\"><div>" + formCaption + "</div></td>");
  145. htmlCode.AppendLine("<td width=\"8%\" class=\"container_tr\"><div></div></td>");
  146. htmlCode.AppendLine("</tr>");
  147. htmlCode.AppendLine("<tr>");
  148. htmlCode.AppendLine("<td class=\"container_l\"></td>");
  149. htmlCode.AppendLine("<td class=\"container_content\">");
  150. HttpContext.Current.Response.Write(htmlCode.ToString());
  151. htmlCode.Clear();
  152. }
  153. public void EndForm()
  154. {
  155. var htmlCode = new StringBuilder("");
  156. htmlCode.AppendLine("</td>");
  157. htmlCode.AppendLine("<td class=\"container_r\"></td>");
  158. htmlCode.AppendLine("</tr>");
  159. htmlCode.AppendLine("<tr>");
  160. htmlCode.AppendLine("<td class=\"container_bl\"></td>");
  161. htmlCode.AppendLine("<td class=\"container_bmid\"></td>");
  162. htmlCode.AppendLine("<td class=\"container_br\"></td>");
  163. htmlCode.AppendLine("</tr>");
  164. htmlCode.AppendLine("</tbody>");
  165. htmlCode.AppendLine("</table>");
  166. HttpContext.Current.Response.Write(htmlCode.ToString());
  167. htmlCode.Clear();
  168. }
  169. public void BeginHeaderForGrid(string headerCaption, string childAlign)
  170. {
  171. var htmlCode = new StringBuilder("");
  172. htmlCode.AppendLine("<table width=\"100%\" border=\"0\">");
  173. htmlCode.AppendLine("<tr>");
  174. htmlCode.AppendLine("<td valign=\"bottom\" class=\"\" valign=\"buttom\">");
  175. htmlCode.AppendLine("<div class=\"BredCurm\">" + headerCaption + "</div>");
  176. htmlCode.AppendLine("</td>");
  177. htmlCode.AppendLine("</tr>");
  178. htmlCode.AppendLine("<tr>");
  179. htmlCode.AppendLine("<td valign=\"top\" align=\"" + childAlign + "\">");
  180. HttpContext.Current.Response.Write(htmlCode.ToString());
  181. htmlCode.Clear();
  182. }
  183. public void BeginHeaderForGrid(string headerCaption)
  184. {
  185. BeginHeaderForGrid(headerCaption, "center");
  186. }
  187. public void EndHeaderForGrid()
  188. {
  189. var htmlCode = new StringBuilder("");
  190. htmlCode.AppendLine("</td>");
  191. htmlCode.AppendLine("</tr>");
  192. htmlCode.AppendLine("</table>");
  193. HttpContext.Current.Response.Write(htmlCode.ToString());
  194. htmlCode.Clear();
  195. }
  196. public void SetYearDdl(ref DropDownList ddl, int low, int high, string label)
  197. {
  198. ListItem item = null;
  199. if (!string.IsNullOrWhiteSpace(label))
  200. {
  201. item = new ListItem { Value = "", Text = label };
  202. ddl.Items.Add(item);
  203. }
  204. for (int i = low; i <= high; i++)
  205. {
  206. item = new ListItem { Value = i.ToString(), Text = i.ToString() };
  207. ddl.Items.Add(item);
  208. }
  209. }
  210. public void SetMonthDdl(ref DropDownList ddl, string label)
  211. {
  212. ListItem item = null;
  213. if (!string.IsNullOrWhiteSpace(label))
  214. {
  215. item = new ListItem { Value = "", Text = label };
  216. ddl.Items.Add(item);
  217. }
  218. DateTime mnth = Convert.ToDateTime("1/1/2000");
  219. for (int i = 0; i < 12; i++)
  220. {
  221. DateTime nextMnth = mnth.AddMonths(i);
  222. item = new ListItem { Text = nextMnth.ToString("MMMM"), Value = nextMnth.ToString("MM") };
  223. ddl.Items.Add(item);
  224. }
  225. }
  226. public void SetDay(ref DropDownList ddl, string label)
  227. {
  228. ListItem item = null;
  229. if (!string.IsNullOrWhiteSpace(label))
  230. {
  231. item = new ListItem { Value = "", Text = label };
  232. ddl.Items.Add(item);
  233. }
  234. for (int i = 1; i <= 31; i++)
  235. {
  236. item = new ListItem { Text = i.ToString(), Value = i.ToString() };
  237. ddl.Items.Add(item);
  238. }
  239. }
  240. #region Grid
  241. public string CreateGrid(string gridName, string gridWidth, string sql, string rowIdField, bool showCheckBox, bool multiSelect, string columns, string cssClass, string callBackFunction)//, string editPage, bool allowEdit, bool allowDelete, bool allowApprove, string customLink, string customVariableList)
  242. {
  243. if (string.IsNullOrEmpty(cssClass))
  244. cssClass = "TBLReport";
  245. var html = new StringBuilder();
  246. var dt = ExecuteDataSet(sql).Tables[0];
  247. var columnList = columns.Split(',');
  248. html.AppendLine(
  249. "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" align=\"left\" class=\"" + cssClass + "\" width = \"" +
  250. gridWidth + "px\" id =\"" + gridName + "_body\">");
  251. if (showCheckBox)
  252. {
  253. var headerFuntion = "SelectAll(this, '" + gridName + "'," + (multiSelect ? "true" : "false") + ");" + callBackFunction;
  254. html.AppendLine("<th Class=\"" + cssClass + "\" nowrap style = \"cursor:pointer;text-align: center\" onclick =\"" + headerFuntion + "\">" + (multiSelect ? "√" : "×") + "</th>");
  255. }
  256. var columnIndexArray = new ArrayList();
  257. foreach (var str in columnList)
  258. {
  259. columnIndexArray.Add(str);
  260. }
  261. var columnArray = new ArrayList();
  262. foreach (DataColumn col in dt.Columns)
  263. {
  264. columnArray.Add(col);
  265. }
  266. for (var i = 0; i < columnArray.Count; i++)
  267. {
  268. if (columns.Trim().Equals(""))
  269. {
  270. html.AppendLine("<th align=\"left\" nowrap >" + columnArray[i] + "</th>");
  271. }
  272. else
  273. {
  274. if (columnIndexArray.Contains(i.ToString()))
  275. {
  276. html.AppendLine("<th align=\"left\" nowrap >" + columnArray[i] + "</th>");
  277. }
  278. }
  279. }
  280. html.AppendLine("</tr>");
  281. var checkBoxFunction = "";
  282. if (showCheckBox)
  283. {
  284. checkBoxFunction = "ManageSelection(this, '" + gridName + "'," + (multiSelect ? "true" : "false") + ");" +
  285. callBackFunction;
  286. }
  287. foreach (DataRow row in dt.Rows)
  288. {
  289. html.AppendLine("<tr>");
  290. if (showCheckBox)
  291. {
  292. html.AppendLine("<td align=\"center\"><input type = \"checkbox\" value = \"" +
  293. row[rowIdField.ToLower()] + "\" name =\"" + gridName + "_rowId\" onclick = \"" +
  294. checkBoxFunction + "\"></td>");
  295. }
  296. for (var i = 0; i < dt.Columns.Count; i++)
  297. {
  298. var data = row[i].ToString();
  299. if (columns.Trim().Equals(""))
  300. {
  301. html.AppendLine("<td align=\"left\">" + GetStatic.FormatData(data, "") + "</td>");
  302. }
  303. else
  304. {
  305. if (columnIndexArray.Contains(i.ToString()))
  306. {
  307. html.AppendLine("<td align=\"left\">" + GetStatic.FormatData(data, "") + "</td>");
  308. }
  309. }
  310. }
  311. html.AppendLine("</tr>");
  312. }
  313. html.AppendLine("</table>");
  314. return html.ToString();
  315. }
  316. #endregion
  317. }
  318. }