PageRenderTime 50ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/EQT_V2/EQT/EQT.DAL/DaTestItem.add.cs

http://sgsoft-las.googlecode.com/
C# | 278 lines | 210 code | 19 blank | 49 comment | 17 complexity | 0674ca1abc4ce21146be4ee12aaa719e MD5 | raw file
Possible License(s): LGPL-2.1
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Data;
  5. using System.Globalization;
  6. using System.Text;
  7. using System.Xml;
  8. using System.Data.Common;
  9. using Microsoft.Practices.EnterpriseLibrary.Data;
  10. using Microsoft.Practices.EnterpriseLibrary.Data.Sql;
  11. using EQT.Model;
  12. namespace EQT.Dal
  13. {
  14. public partial class DaTestItem //?????????,ITestItem
  15. {
  16. /// <summary>
  17. /// ??????,??.
  18. /// </summary>
  19. /// <param name="itemid"></param>
  20. /// <returns></returns>
  21. public bool DeleteTestItem(string itemid)
  22. {
  23. bool rc = false;
  24. using (DbConnection cnn = db.CreateConnection())
  25. {
  26. DbTransaction trans = null;
  27. try
  28. {
  29. cnn.Open();
  30. using (trans = cnn.BeginTransaction())
  31. {
  32. //??????
  33. this.DeleteByWhereClause(String.Format(" WHERE ITEM_CODE='{0}'",itemid), trans);
  34. //???????
  35. string strSQL = "DELETE FROM TEST_CATALOG WHERE TEST_CTG_ID='" + itemid + "'";
  36. db.ExecuteNonQuery(trans, CommandType.Text, strSQL);
  37. //????????????
  38. trans.Commit();
  39. }
  40. cnn.Close();
  41. rc = true;
  42. }
  43. catch (DbException ex)
  44. {
  45. if (trans != null) trans.Rollback();
  46. HandleDbException(ex);
  47. }
  48. }
  49. return rc;
  50. }
  51. /// <summary>
  52. /// ??????,??.
  53. /// </summary>
  54. /// <param name="modCatalog"></param>
  55. /// <param name="modItem"></param>
  56. /// <returns></returns>
  57. public bool AddTestItem(MoTestCatalog modCatalog,MoTestItem modItem)
  58. {
  59. bool rc = false;
  60. using (DbConnection cnn = db.CreateConnection())
  61. {
  62. DbTransaction trans = null;
  63. try
  64. {
  65. cnn.Open();
  66. using (trans = cnn.BeginTransaction())
  67. {
  68. //???????
  69. this.Add(modItem, trans);
  70. //??????
  71. DaTestCatalog dacatalog = new DaTestCatalog(db);
  72. dacatalog.Add(modCatalog, trans);
  73. trans.Commit();
  74. }
  75. cnn.Close();
  76. rc = true;
  77. }
  78. catch (DbException ex)
  79. {
  80. if (trans != null) trans.Rollback();
  81. HandleDbException(ex);
  82. }
  83. }
  84. return rc;
  85. }
  86. /// <summary>
  87. /// ??????,??.
  88. /// </summary>
  89. /// <param name="modCatalog"></param>
  90. /// <param name="modItem"></param>
  91. /// <returns></returns>
  92. public bool UpdateTestItem(MoTestCatalog modCatalog, MoTestItem modItem)
  93. {
  94. bool rc = false;
  95. using (DbConnection cnn = db.CreateConnection())
  96. {
  97. DbTransaction trans = null;
  98. try
  99. {
  100. cnn.Open();
  101. using (trans = cnn.BeginTransaction())
  102. {
  103. //???????
  104. this.Update(modItem, trans);
  105. //??????
  106. DaTestCatalog dacatalog = new DaTestCatalog(db);
  107. dacatalog.Update(modCatalog, trans);
  108. trans.Commit();
  109. }
  110. cnn.Close();
  111. rc = true;
  112. }
  113. catch (DbException ex)
  114. {
  115. if (trans != null) trans.Rollback();
  116. HandleDbException(ex);
  117. }
  118. }
  119. return rc;
  120. }
  121. /// <summary>
  122. /// ????????doc,xls???
  123. /// </summary>
  124. /// <param name="ItemID"></param>
  125. /// <returns></returns>
  126. public DataSet QueryFileTemplate(string ItemID)
  127. {
  128. DataSet ds=new DataSet();
  129. string strSQL = "SELECT m.*, (SELECT File_Name FROM TFiles WHERE File_ID = m.Doc_Url) AS docname,"+
  130. "(SELECT File_Name FROM TFiles WHERE File_ID = m.Xls_Url) AS xlsname"+
  131. " FROM File_Template m LEFT OUTER JOIN"+
  132. " Ref_File ref ON m.Item_Code = ref.EID LEFT OUTER JOIN"+
  133. " Test_Item i ON m.Item_Code = i.Item_Code where m.item_code='"+ItemID+"'";
  134. try
  135. {
  136. ds = db.ExecuteDataSet(CommandType.Text, strSQL);
  137. }
  138. catch (DbException ex)
  139. {
  140. HandleDbException(ex);
  141. }
  142. return ds;
  143. }
  144. /// <summary>
  145. /// ???????????
  146. /// </summary>
  147. /// <param name="templateid"></param>
  148. /// <returns></returns>
  149. public bool DeleteItemTemplate(string templateid)
  150. {
  151. bool rc = false;
  152. using (DbConnection cnn = db.CreateConnection())
  153. {
  154. DbTransaction trans = null;
  155. try
  156. {
  157. cnn.Open();
  158. using (trans = cnn.BeginTransaction())
  159. {
  160. DaFileTemplate daTemplate = new DaFileTemplate();
  161. DaRefFile daRef = new DaRefFile();
  162. DaTfiles daFile = new DaTfiles();
  163. //????
  164. string strDelRefFile = "delete from ref_file where eid='" + templateid + "'";
  165. db.ExecuteNonQuery(trans, CommandType.Text, strDelRefFile);
  166. MoFileTemplate modtemplate = new MoFileTemplate();
  167. modtemplate.FtId = templateid;
  168. //????
  169. if (daTemplate.GetEntityEx(ref modtemplate))
  170. {
  171. daFile.DeleteByWhereClause(String.Format(" WHERE FILE_ID='{0}'", modtemplate.DocUrl), trans);
  172. daFile.DeleteByWhereClause(String.Format(" WHERE FILE_ID='{0}'", modtemplate.XlsUrl),trans);
  173. }
  174. //????
  175. string strDelTemplate = "delete from File_Template where FT_ID='"+templateid+"'";
  176. db.ExecuteNonQuery(trans, CommandType.Text, strDelTemplate);
  177. trans.Commit();
  178. }
  179. cnn.Close();
  180. rc = true;
  181. }
  182. catch (DbException ex)
  183. {
  184. if (trans != null) trans.Rollback();
  185. HandleDbException(ex);
  186. }
  187. }
  188. return rc;
  189. }
  190. /// <summary>
  191. /// ??????Doc???
  192. /// </summary>
  193. /// <param name="motf"></param>
  194. /// <param name="morf"></param>
  195. /// <returns></returns>
  196. public int AddTemplateDoc(MoTfiles motf, MoRefFile morf)
  197. {
  198. if (motf == null || morf == null) return 0;
  199. int rc = 0;
  200. using (DbConnection conn = db.CreateConnection())
  201. {
  202. try
  203. {
  204. conn.Open();
  205. using (DbTransaction trans = conn.BeginTransaction())
  206. {
  207. DaRefFile darf = new DaRefFile(db);
  208. DaTfiles daf = new DaTfiles(db);
  209. rc += daf.Add(motf, trans);
  210. rc += darf.Add(morf, trans);
  211. string sql = "update File_Template set doc_url='" + motf.FileId + "' where FT_ID='" + morf.Eid + "'";
  212. db.ExecuteNonQuery(trans, CommandType.Text, sql);
  213. trans.Commit();
  214. }
  215. conn.Close();
  216. }
  217. catch (DbException de)
  218. {
  219. throw new DalException("??????????????" + motf.ToString() + "\r\n" + morf.ToString(), de);
  220. }
  221. }
  222. return rc;
  223. }
  224. /// <summary>
  225. /// ??????Xls???
  226. /// </summary>
  227. /// <param name="motf"></param>
  228. /// <param name="morf"></param>
  229. /// <returns></returns>
  230. public int AddTemplateXls(MoTfiles motf, MoRefFile morf)
  231. {
  232. if (motf == null || morf == null) return 0;
  233. int rc = 0;
  234. using (DbConnection conn = db.CreateConnection())
  235. {
  236. try
  237. {
  238. conn.Open();
  239. using (DbTransaction trans = conn.BeginTransaction())
  240. {
  241. DaRefFile darf = new DaRefFile(db);
  242. DaTfiles daf = new DaTfiles(db);
  243. rc += daf.Add(motf, trans);
  244. rc += darf.Add(morf, trans);
  245. string sql = "update File_Template set xls_url='" + motf.FileId + "' where FT_ID='"+morf.Eid+"'";
  246. db.ExecuteNonQuery(trans, CommandType.Text, sql);
  247. trans.Commit();
  248. }
  249. conn.Close();
  250. }
  251. catch (DbException de)
  252. {
  253. throw new DalException("??????????????" + motf.ToString() + "\r\n" + morf.ToString(), de);
  254. }
  255. }
  256. return rc;
  257. }
  258. }
  259. }