PageRenderTime 28ms CodeModel.GetById 25ms RepoModel.GetById 1ms app.codeStats 0ms

/AKDOA28/ZX.SPL/Factory/Dialect/Access.cs

#
C# | 221 lines | 184 code | 19 blank | 18 comment | 21 complexity | 1cb56a1137ad499427e82d9f32f10229 MD5 | raw file
Possible License(s): LGPL-2.1, LGPL-3.0, Apache-2.0, GPL-2.0, BSD-3-Clause, LGPL-2.0, MIT, GPL-3.0
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Text;
  5. using ZX.Common;
  6. //using ZX.DBModule;
  7. namespace ZX.SPL.Factory.Dialect
  8. {
  9. /// <summary>
  10. /// MsSqlServer 的摘要说明。
  11. /// </summary>
  12. public class Access : ZX.SPL.Factory.DialectFactory
  13. {
  14. public Access(object entitys)
  15. : base(entitys)
  16. {
  17. //
  18. // TODO: 在此处添加构造函数逻辑
  19. //
  20. }
  21. public override string BuildInsertCom()
  22. {
  23. System.Text.StringBuilder _InsStrIns = new StringBuilder("insert into " + this.GetTableName());
  24. System.Text.StringBuilder _InsStrFields = new StringBuilder();
  25. System.Text.StringBuilder _InsStr = new StringBuilder();
  26. System.Text.StringBuilder _InsStrValues = new StringBuilder();
  27. System.Collections.Generic.SortedDictionary<string, ClassField> ht = ReaderSqliteAutoMapper();
  28. if (ht == null)
  29. {
  30. //log
  31. return null;
  32. }
  33. ht.Remove(this.GetGuid()); // 去掉自增字段的信息
  34. int i = 0;
  35. IDictionaryEnumerator myEnumerator = ht.GetEnumerator();
  36. try
  37. {
  38. while (myEnumerator.MoveNext())
  39. {
  40. ClassField cf = myEnumerator as ClassField;
  41. if (i == 0)
  42. {
  43. _InsStrFields.Append("[" + myEnumerator.Key.ToString() + "]");
  44. if (cf.cType == "DT")
  45. {
  46. _InsStrValues.Append("'" + ((DateTime)cf.Field).ToString("s") + "'");
  47. }
  48. else
  49. {
  50. _InsStrValues.Append("'" + cf.Field + "'");
  51. }
  52. }
  53. else
  54. {
  55. _InsStrFields.Append(",[" + myEnumerator.Key.ToString() + "]");
  56. if (cf.Field == null)
  57. { _InsStrValues.Append(",null"); }
  58. else
  59. {
  60. if (cf.cType == "DT")
  61. {
  62. DateTime dt = ((DateTime)cf.Field);
  63. _InsStrValues.Append(",'" + dt.ToString("s") + "'");
  64. //_InsStrValues.Append(",'" + string.Format(dt.ToString("yyyy-MM-dd {0}:MM:SS") + "'"),dt.Hour>10?dt.Hour.ToString():"0"+dt.Hour.ToString());
  65. }
  66. else
  67. {
  68. _InsStrValues.Append(",'" + cf.Field + "'");
  69. }
  70. }
  71. }
  72. i++;
  73. }
  74. _InsStr.AppendFormat("{0} ({1}) values ({2}) ", _InsStrIns, _InsStrFields, _InsStrValues);
  75. return _InsStr.ToString();
  76. }
  77. catch (System.Exception e)
  78. {
  79. // log to log
  80. throw e;
  81. }
  82. }
  83. public override string BuildUpdateCom()
  84. {
  85. System.Text.StringBuilder _strUpdate = new StringBuilder();
  86. System.Text.StringBuilder _strWhere = new StringBuilder();
  87. System.Text.StringBuilder _strFieldValue = new StringBuilder();
  88. SortedDictionary<string, object> ht = ReaderAutoMapper();
  89. if (ht == null)
  90. {
  91. return null;
  92. }
  93. ht.Remove(this.GetGuid()); // 去掉自增字段的信息
  94. int i = 0;
  95. _strWhere.Append(this.GetGuid() + "= " + Globals.GetPropertyValue(this.Entitys, this.GetGuid()) + " ");
  96. IDictionaryEnumerator myEnumerator = ht.GetEnumerator();
  97. try
  98. {
  99. while (myEnumerator.MoveNext())
  100. {
  101. if (i == 0)
  102. {
  103. _strFieldValue.Append("[" + myEnumerator.Key.ToString() + "]");
  104. }
  105. else
  106. {
  107. _strFieldValue.Append(",[" + myEnumerator.Key.ToString() + "]");
  108. //_strFieldValue.Append("='" + myEnumerator.Value+"'");
  109. }
  110. if (myEnumerator.Value == null)
  111. {
  112. _strFieldValue.Append(" = null");
  113. }
  114. else
  115. {
  116. _strFieldValue.Append(" = '" + myEnumerator.Value + "'");
  117. }
  118. i++;
  119. }
  120. _strUpdate.AppendFormat("update {0} Set {1} where {2}", this.GetTableName(), _strFieldValue, _strWhere);
  121. return _strUpdate.ToString();
  122. }
  123. catch (System.Exception e)
  124. {
  125. throw e;
  126. }
  127. }
  128. /// <summary>
  129. /// 更新语句 //add sundexiang
  130. /// </summary>
  131. /// <param name="FieldValue">更新的Colums</param>
  132. /// <param name="condition">更新的条件</param>
  133. /// <returns></returns>
  134. public override string BuildUpdateCom(string FieldValue, string condition)
  135. {
  136. System.Text.StringBuilder _strUpdate = new StringBuilder();
  137. try
  138. {
  139. _strUpdate.AppendFormat("update [{0}] Set {1} where {2}", this.GetTableName(), FieldValue, condition);
  140. return _strUpdate.ToString();
  141. }
  142. catch (System.Exception e)
  143. {
  144. throw e;
  145. }
  146. }
  147. //public string
  148. public override string BuildDeleteCom()
  149. {
  150. System.Text.StringBuilder _strDelete = new StringBuilder();
  151. _strDelete.Append("delete from ");
  152. _strDelete.Append(this.GetTableName());
  153. _strDelete.Append(" where ");
  154. _strDelete.Append(this.GetGuid());
  155. _strDelete.Append(" = '");
  156. _strDelete.Append(Globals.GetPropertyValue(this.Entitys, this.GetGuid()));
  157. _strDelete.Append("'");
  158. return _strDelete.ToString();
  159. }
  160. public override string BuildDeleteCom(string condition)
  161. {
  162. System.Text.StringBuilder _strDelete = new StringBuilder();
  163. _strDelete.Append("delete from ");
  164. _strDelete.Append(this.GetTableName());
  165. _strDelete.Append(" where ");
  166. _strDelete.Append(condition);
  167. return _strDelete.ToString();
  168. }
  169. public override string SelectCommand(IList list)
  170. {
  171. StringBuilder _SelStr = new StringBuilder(this.SelectAllCommand());
  172. if (list == null)
  173. {
  174. return _SelStr.ToString();
  175. }
  176. IEnumerator myEnumerator = list.GetEnumerator();
  177. try
  178. {
  179. while (myEnumerator.MoveNext())
  180. {
  181. myEnumerator.Current.ToString();
  182. }
  183. return _SelStr.ToString(); ;
  184. }
  185. catch (System.Exception e)
  186. {
  187. throw e;
  188. }
  189. }
  190. public override string SelectCommand(string id)
  191. {
  192. System.Text.StringBuilder sb = new StringBuilder("");
  193. string _strSel = base.SelectAllCommand();
  194. sb.Append(_strSel + " ");
  195. sb.Append(" where ");
  196. sb.Append(this.GetGuid());
  197. sb.Append("=");
  198. sb.Append(id);
  199. return sb.ToString();
  200. }
  201. }
  202. }