Command_Configuration.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /*******************************************************************************
  2. * iNethinkCMS - 网站内容管理系统
  3. * Copyright (C) 2012-2013 inethink.com
  4. *
  5. * @author jackyang <69991000@qq.com>
  6. * @website http://cms.inethink.com
  7. * @version 1.3.6.0 (2013-08-14)
  8. *
  9. * This is licensed under the GNU LGPL, version 3.0 or later.
  10. * For details, see: http://www.gnu.org/licenses/gpl-3.0.html
  11. *******************************************************************************/
  12. using System;
  13. using System.Configuration;
  14. namespace iNethinkCMS.Command
  15. {
  16. public class Command_Configuration
  17. {
  18. static string strXmlFile = System.Web.HttpContext.Current.Server.MapPath("~/config/sys.config");
  19. /// <summary>
  20. /// string
  21. /// </summary>
  22. /// <param name="key"></param>
  23. /// <returns></returns>
  24. public static string GetConfigString(string byKey)
  25. {
  26. string rInfo = iNethinkCMS.Helper.XMLHelper.GetXmlNodeByXpath(strXmlFile, "//sys_configuration//" + byKey).InnerText.Trim();
  27. return rInfo;
  28. }
  29. /// <summary>
  30. /// string
  31. /// </summary>
  32. /// <param name="key"></param>
  33. /// <returns></returns>
  34. public static string GetVersionsString(string byKey)
  35. {
  36. string rInfo = iNethinkCMS.Helper.XMLHelper.GetXmlNodeByXpath(strXmlFile, "//sys_versions//" + byKey).InnerText.Trim();
  37. return rInfo;
  38. }
  39. /// <summary>
  40. /// Bool
  41. /// </summary>
  42. /// <param name="key"></param>
  43. /// <returns></returns>
  44. public static bool GetConfigBool(string byKey)
  45. {
  46. bool result = false;
  47. string cfgVal = iNethinkCMS.Helper.XMLHelper.GetXmlNodeByXpath(strXmlFile, "//sys_configuration//" + byKey).InnerText.Trim();
  48. if (null != cfgVal && string.Empty != cfgVal)
  49. {
  50. try
  51. {
  52. result = bool.Parse(cfgVal);
  53. }
  54. catch (FormatException)
  55. {
  56. }
  57. }
  58. return result;
  59. }
  60. /// <summary>
  61. /// Decimal
  62. /// </summary>
  63. /// <param name="key"></param>
  64. /// <returns></returns>
  65. public static decimal GetConfigDecimal(string byKey)
  66. {
  67. decimal result = 0;
  68. string cfgVal = iNethinkCMS.Helper.XMLHelper.GetXmlNodeByXpath(strXmlFile, "//sys_configuration//" + byKey).InnerText.Trim();
  69. if (null != cfgVal && string.Empty != cfgVal)
  70. {
  71. try
  72. {
  73. result = decimal.Parse(cfgVal);
  74. }
  75. catch (FormatException)
  76. {
  77. }
  78. }
  79. return result;
  80. }
  81. /// <summary>
  82. /// int
  83. /// </summary>
  84. /// <param name="key"></param>
  85. /// <returns></returns>
  86. public static int GetConfigInt(string byKey)
  87. {
  88. int result = 0;
  89. string cfgVal = iNethinkCMS.Helper.XMLHelper.GetXmlNodeByXpath(strXmlFile, "//sys_configuration//" + byKey).InnerText.Trim();
  90. if (null != cfgVal && string.Empty != cfgVal)
  91. {
  92. try
  93. {
  94. result = int.Parse(cfgVal);
  95. }
  96. catch (FormatException)
  97. {
  98. }
  99. }
  100. return result;
  101. }
  102. }
  103. }