Helper_SQLHelper_CommandInfo.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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.IO;
  14. using System.Collections.Generic;
  15. using System.Text;
  16. using System.Data.SqlClient;
  17. using System.Web;
  18. namespace iNethinkCMS.Helper
  19. {
  20. public enum EffentNextType
  21. {
  22. /// <summary>
  23. /// 对其他语句无任何影响
  24. /// </summary>
  25. None,
  26. /// <summary>
  27. /// 当前语句必须为"select count(1) from .."格式,如果存在则继续执行,不存在回滚事务
  28. /// </summary>
  29. WhenHaveContine,
  30. /// <summary>
  31. /// 当前语句必须为"select count(1) from .."格式,如果不存在则继续执行,存在回滚事务
  32. /// </summary>
  33. WhenNoHaveContine,
  34. /// <summary>
  35. /// 当前语句影响到的行数必须大于0,否则回滚事务
  36. /// </summary>
  37. ExcuteEffectRows,
  38. /// <summary>
  39. /// 引发事件-当前语句必须为"select count(1) from .."格式,如果不存在则继续执行,存在回滚事务
  40. /// </summary>
  41. SolicitationEvent
  42. }
  43. public class CommandInfo
  44. {
  45. public object ShareObject = null;
  46. public object OriginalData = null;
  47. event EventHandler _solicitationEvent;
  48. public event EventHandler SolicitationEvent
  49. {
  50. add
  51. {
  52. _solicitationEvent += value;
  53. }
  54. remove
  55. {
  56. _solicitationEvent -= value;
  57. }
  58. }
  59. public void OnSolicitationEvent()
  60. {
  61. if (_solicitationEvent != null)
  62. {
  63. _solicitationEvent(this, new EventArgs());
  64. }
  65. }
  66. public string CommandText;
  67. public System.Data.Common.DbParameter[] Parameters;
  68. public EffentNextType EffentNextType = EffentNextType.None;
  69. public CommandInfo()
  70. {
  71. }
  72. public CommandInfo(string sqlText, SqlParameter[] para)
  73. {
  74. this.CommandText = sqlText;
  75. this.Parameters = para;
  76. }
  77. public CommandInfo(string sqlText, SqlParameter[] para, EffentNextType type)
  78. {
  79. this.CommandText = sqlText;
  80. this.Parameters = para;
  81. this.EffentNextType = type;
  82. }
  83. }
  84. public class GetConnectionString
  85. {
  86. /// <summary>
  87. /// 得到conn.config里配置项的数据库连接字符串。
  88. /// </summary>
  89. public static string iGetConn
  90. {
  91. get
  92. {
  93. string strXmlFile = HttpContext.Current.Server.MapPath("~/config/conn.config");
  94. string vDataBaseServer = XMLHelper.GetXmlNodeByXpath(strXmlFile, "//conn_configuration//DataBaseServer").InnerText.Trim();
  95. string vDataBasePort = XMLHelper.GetXmlNodeByXpath(strXmlFile, "//conn_configuration//DataBasePort").InnerText.Trim();
  96. string vDataBaseUser = XMLHelper.GetXmlNodeByXpath(strXmlFile, "//conn_configuration//DataBaseUser").InnerText.Trim();
  97. string vDataBasePass = XMLHelper.GetXmlNodeByXpath(strXmlFile, "//conn_configuration//DataBasePass").InnerText.Trim();
  98. string vDataBaseName = XMLHelper.GetXmlNodeByXpath(strXmlFile, "//conn_configuration//DataBaseName").InnerText.Trim();
  99. string _connectionString;
  100. if (vDataBasePort != "0")
  101. {
  102. vDataBaseServer = vDataBaseServer + "," + vDataBasePort;
  103. }
  104. _connectionString = "Data Source=" + vDataBaseServer + ";Initial Catalog=" + vDataBaseName + ";User ID=" + vDataBaseUser + ";Password=" + vDataBasePass + "";
  105. return _connectionString;
  106. }
  107. }
  108. }
  109. }