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.

217 lines
5.7 KiB

  1. using System;
  2. using System.Configuration;
  3. using System.Data;
  4. using System.IO;
  5. namespace Swift.DAL.BL.System.Utility
  6. {
  7. public class Utility : XMLDataTableUtility
  8. {
  9. public static string BlankIfNull(string val)
  10. {
  11. if (!string.IsNullOrWhiteSpace(val))
  12. {
  13. return val;
  14. }
  15. return "";
  16. }
  17. public static string GetDateInCEReconsileFormat(string strDate)
  18. {
  19. var date = DateTime.Parse(strDate);
  20. return date.ToString("dd-MMM-yyyy");
  21. }
  22. public static string GetDateInCEFormat(string strDate)
  23. {
  24. var date = DateTime.Parse(strDate);
  25. return date.ToString("dd/MM/yyyy");
  26. }
  27. public static string GetDateInICFormat(string strDate)
  28. {
  29. var date = DateTime.Parse(strDate);
  30. return date.ToString("yyyyMMdd");
  31. }
  32. public static string GetDateToShortString(string strDate)
  33. {
  34. var date = DateTime.Parse(strDate);
  35. return date.ToShortDateString();
  36. }
  37. public static string ReadWebConfig(string key, string defValue)
  38. {
  39. return (ConfigurationSettings.AppSettings[key] ?? defValue);
  40. }
  41. #region GIBL API
  42. public static string GetgblCertName()
  43. {
  44. return ReadWebConfig("gblCertName", "");
  45. }
  46. public static string GetgblUserid()
  47. {
  48. return ReadWebConfig("gbluserid", "");
  49. }
  50. public static string GetgblPassword()
  51. {
  52. return ReadWebConfig("gblpassword", "");
  53. }
  54. public static string GetgblAgentId()
  55. {
  56. return ReadWebConfig("gblAgentID", "");
  57. }
  58. public static string GetgblCertPath()
  59. {
  60. return ReadWebConfig("gblCertPath", "");
  61. }
  62. public static string GetgblCertPwd()
  63. {
  64. return ReadWebConfig("gblCertPwd", "");
  65. }
  66. public static string GetGIBLISOBC()
  67. {
  68. return ReadWebConfig("GIBL_ISO_BC", "");
  69. }
  70. public static string GetgblAgentIDPay()
  71. {
  72. return ReadWebConfig("gblAgentIDPay", "");
  73. }
  74. //
  75. #endregion
  76. #region CashExpress API
  77. public static string GetCEAgentId()
  78. {
  79. return ReadWebConfig("CEAgentId", "");
  80. }
  81. #endregion
  82. public static string GetxmAgentID()
  83. {
  84. return ReadWebConfig("xmAgentID", "");
  85. }
  86. #region Email CRedentials
  87. public static string GetSMTP()
  88. {
  89. return ReadWebConfig("smtp", "");
  90. }
  91. public static string GetMailFrom()
  92. {
  93. return ReadWebConfig("mailFrom", "");
  94. }
  95. public static string GetPSW()
  96. {
  97. return ReadWebConfig("mailPwd", "");
  98. }
  99. public static string GetEnableSSL()
  100. {
  101. return ReadWebConfig("enableSSL", "");
  102. }
  103. public static string GetPort()
  104. {
  105. return ReadWebConfig("port", "");
  106. }
  107. #endregion
  108. public static string GetmgAgentId()
  109. {
  110. return ReadWebConfig("mgAgentID", "");
  111. }
  112. public static string GetkumariAgentId()
  113. {
  114. return ReadWebConfig("kumariBranchMapCode", "");
  115. }
  116. internal static string GetkumariPassword()
  117. {
  118. return ReadWebConfig("kumaripassword", "");
  119. }
  120. internal static string GetkumariUserid()
  121. {
  122. return ReadWebConfig("kumariuserid", "");
  123. }
  124. internal static string GetkumariAccessCode()
  125. {
  126. return ReadWebConfig("kumariAccessCode", "");
  127. }
  128. internal static string GetComplienceAmount()
  129. {
  130. return ReadWebConfig("kumariComplienceAmt", "");
  131. }
  132. public static string GetMaxMoneyAgentId()
  133. {
  134. return ReadWebConfig("maxMoneyBranchMapCode", "");
  135. }
  136. }
  137. public class XMLDataTableUtility
  138. {
  139. public static DataTable ParseXMLToDataTable(string xml)
  140. {
  141. if (string.IsNullOrWhiteSpace(xml))
  142. {
  143. return null;
  144. }
  145. DataSet ds = ParseXMLToDataSet(xml);
  146. if (ds == null || ds.Tables.Count == 0)
  147. return null;
  148. return ds.Tables[0];
  149. }
  150. public static DataSet ParseXMLToDataSet(string xml)
  151. {
  152. if (string.IsNullOrWhiteSpace(xml))
  153. {
  154. return null;
  155. }
  156. DataSet ds = new DataSet(); ;
  157. using (StringReader r = new StringReader(xml))
  158. {
  159. ds.ReadXml(r);
  160. }
  161. return ds;
  162. }
  163. public static DataRow ParseXMLToDataRow(string xml)
  164. {
  165. DataTable dt = ParseXMLToDataTable(xml);
  166. if (dt == null || dt.Rows.Count == 0)
  167. return null;
  168. return dt.Rows[0];
  169. }
  170. public static string GetDataRowData(ref DataRow dr, string colName, string defVal)
  171. {
  172. if (ColumnExists(ref dr, colName))
  173. {
  174. return (dr[colName] ?? defVal).ToString();
  175. }
  176. return "";
  177. }
  178. public static string GetDataRowData(ref DataRow dr, string colName)
  179. {
  180. return GetDataRowData(ref dr, colName, "");
  181. }
  182. protected static bool ColumnExists(ref DataRow dr, string colName)
  183. {
  184. foreach (DataColumn dc in dr.Table.Columns)
  185. {
  186. if (dc.ColumnName.ToUpper().Equals(colName.ToUpper()))
  187. {
  188. return true;
  189. }
  190. }
  191. return false;
  192. }
  193. }
  194. }