PageRenderTime 84ms CodeModel.GetById 7ms RepoModel.GetById 0ms app.codeStats 0ms

/ZXFramework_2/source/Tool/HF.Forms.Data/MainChildForm.cs

#
C# | 392 lines | 303 code | 18 blank | 71 comment | 7 complexity | a3f40435948dbf520e048152ffe8b3b8 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.Data;
  3. using System.Text;
  4. using System.Collections.Generic;
  5. using HF.Framework.DataClientDBAgent;
  6. using HF.WorkFlow.DataContract;
  7. using HF.Framework.SqlDataContract;
  8. namespace HF.Forms.Data
  9. {
  10. /// <summary>
  11. /// 数据访问类MainChildForm。
  12. /// </summary>
  13. public class MainChildForm
  14. {
  15. #region 私有字段
  16. private SqlDataItem sqlDataItem = new SqlDataItem();
  17. private string[] fieldList = { "MainChildId", "ChildFormId", "MainFormId", "FormOrder", "FormState" };
  18. private string tableName = "HF_MainChildForm";
  19. private string keyField = "MainChildId";
  20. private string sqlString = "";
  21. #endregion
  22. #region 私有方法
  23. private void setParameter(MainChildFormEntity entity)
  24. {
  25. sqlDataItem.ParameterList.Clear();
  26. sqlDataItem.AppendParameter("@MainChildId", entity.MainChildId, typeof(string));
  27. sqlDataItem.AppendParameter("@ChildFormId", entity.ChildFormId, typeof(string));
  28. sqlDataItem.AppendParameter("@MainFormId", entity.MainFormId, typeof(string));
  29. sqlDataItem.AppendParameter("@FormOrder", entity.FormOrder, typeof(int));
  30. sqlDataItem.AppendParameter("@FormState", entity.FormState, typeof(string));
  31. }
  32. private void setInsertSql()
  33. {
  34. string tmpValueList = "";
  35. string tmpFieldName = "";
  36. sqlString = "insert into " + tableName + "(";
  37. int tmpInt = this.fieldList.Length;
  38. for (int i = 0; i < tmpInt - 1; i++)
  39. {
  40. tmpFieldName = fieldList[i].ToString();
  41. sqlString = sqlString + tmpFieldName + ", ";
  42. tmpValueList = tmpValueList + "@" + tmpFieldName + ",";
  43. }
  44. tmpFieldName = this.fieldList[tmpInt - 1].ToString();
  45. sqlString = sqlString + tmpFieldName;
  46. tmpValueList = tmpValueList + "@" + tmpFieldName;
  47. this.sqlString = sqlString + ")values(" + tmpValueList + ")";
  48. sqlDataItem.CommandText = sqlString;
  49. }
  50. private void setUpdateSql()
  51. {
  52. string tmpFieldName = "";
  53. int tmpInt = this.fieldList.Length;
  54. sqlString = "update " + tableName + " set ";
  55. for (int i = 0; i < tmpInt - 1; i++)
  56. {
  57. tmpFieldName = fieldList[i].ToString();
  58. sqlString = sqlString + tmpFieldName + " = @" + tmpFieldName + ", ";
  59. }
  60. tmpFieldName = this.fieldList[tmpInt - 1].ToString();
  61. sqlString = sqlString + tmpFieldName + " = @" + tmpFieldName;
  62. sqlString = sqlString + " where " + keyField + "=@" + this.keyField;
  63. sqlDataItem.CommandText = sqlString;
  64. }
  65. public MainChildFormEntity GetMainChildFormEntity(DataRow dr)
  66. {
  67. MainChildFormEntity entity = new MainChildFormEntity();
  68. string value = "";
  69. entity.MainChildId = dr["MainChildId"].ToString();
  70. entity.ChildFormId = dr["ChildFormId"].ToString();
  71. entity.MainFormId = dr["MainFormId"].ToString();
  72. value = dr["FormOrder"].ToString();
  73. if (string.IsNullOrEmpty(value) == false)
  74. {
  75. entity.FormOrder = Convert.ToInt32(value);
  76. }
  77. entity.FormState = dr["FormState"].ToString();
  78. return entity;
  79. }
  80. #endregion
  81. #region 构造函数
  82. public MainChildForm()
  83. { }
  84. public static MainChildForm GetInstance()
  85. {
  86. return new MainChildForm();
  87. }
  88. #endregion
  89. #region 公有方法
  90. #region 基本方法
  91. /// <summary>
  92. /// 增加
  93. /// </summary>
  94. /// <param name="entity">数据实体</param>
  95. /// <returns>影响的记录条数</returns>
  96. public int Insert(MainChildFormEntity entity)
  97. {
  98. try
  99. {
  100. setInsertSql();//设定insert语句
  101. setParameter(entity);//设定参数
  102. ClientDBAgent agent = new ClientDBAgent();
  103. return agent.ExecuteNonQuery(sqlDataItem);
  104. }
  105. catch (Exception ex)
  106. {
  107. throw ex;
  108. }
  109. }
  110. /// <summary>
  111. /// 修改
  112. /// </summary>
  113. /// <param name="entity">数据实体</param>
  114. /// <returns>影响的记录条数</returns>
  115. public int Update(MainChildFormEntity entity)
  116. {
  117. try
  118. {
  119. setUpdateSql();//设定insert语句
  120. setParameter(entity);//设定参数
  121. ClientDBAgent agent = new ClientDBAgent();
  122. return agent.ExecuteNonQuery(sqlDataItem);
  123. }
  124. catch (Exception ex)
  125. {
  126. throw ex;
  127. }
  128. }
  129. /// <summary>
  130. /// 是否存在该记录
  131. /// </summary>
  132. public bool Exists(string mainChildId)
  133. {
  134. string tmpSql = "select * from " + tableName + " where " + keyField + "=@" + keyField;
  135. SqlDataItem sqlItem = new SqlDataItem();
  136. sqlItem.CommandText = tmpSql;
  137. sqlItem.AppendParameter("@" + keyField, mainChildId);
  138. ClientDBAgent agent = new ClientDBAgent();
  139. return agent.RecordExists(sqlItem);
  140. }
  141. /// <summary>
  142. /// 删除
  143. /// </summary>
  144. /// <param name="mainChildId">主键Id</param>
  145. /// <returns>影响的记录条数</returns>
  146. public void Delete(string mainChildId)
  147. {
  148. try
  149. {
  150. string tmpSql = "delete from " + tableName + " where " + keyField + "=@" + keyField;
  151. SqlDataItem sqlItem = new SqlDataItem();
  152. sqlItem.CommandText = tmpSql;
  153. sqlItem.AppendParameter("@" + keyField, mainChildId);
  154. ClientDBAgent agent = new ClientDBAgent();
  155. agent.ExecuteNonQuery(sqlItem);
  156. }
  157. catch (Exception ex)
  158. {
  159. throw ex;
  160. }
  161. }
  162. /// <summary>
  163. /// 获取一条数据记录
  164. /// </summary>
  165. /// <param name="MainChildId">主键Id</param>
  166. /// <returns>DataTable</returns>
  167. public DataTable GetMainChildFormTable(string mainChildId)
  168. {
  169. string tmpSql = "select * from " + tableName + " where " + keyField + "=@" + keyField;
  170. try
  171. {
  172. SqlDataItem sqlItem = new SqlDataItem();
  173. sqlItem.CommandText = tmpSql;
  174. sqlItem.AppendParameter("@" + keyField, mainChildId);
  175. ClientDBAgent agent = new ClientDBAgent();
  176. return agent.ExecuteDataTable(sqlItem);
  177. }
  178. catch (Exception ex)
  179. {
  180. throw ex;
  181. }
  182. }
  183. /// <summary>
  184. /// 获取一个数据实体
  185. /// </summary>
  186. /// <param name="mainChildId">主键Id</param>
  187. /// <returns>DataTable</returns>
  188. public MainChildFormEntity GetMainChildFormEntity(string mainChildId)
  189. {
  190. DataTable dt = GetMainChildFormTable(mainChildId);
  191. if (dt != null && dt.Rows.Count > 0)
  192. {
  193. return GetMainChildFormEntity(dt.Rows[0]);
  194. }
  195. return null;
  196. }
  197. #endregion
  198. #region 扩展方法
  199. //此处添加扩展方法
  200. /// <summary>
  201. /// 把子表单移动到主表单中
  202. /// </summary>
  203. /// <param name="mainFormId">主表单id</param>
  204. /// <param name="childFormId">子表单id</param>
  205. /// <param name="formOrder">顺序号,以此排序</param>
  206. /// <param name="formState">表单读写状态</param>
  207. /// <returns>是否成功</returns>
  208. public bool MoveChildToMain(string mainFormId, string childFormId, int formOrder, string formState)
  209. {
  210. MainChildFormEntity entity = new MainChildFormEntity();
  211. try
  212. {
  213. entity.MainChildId = Guid.NewGuid().ToString();
  214. entity.MainFormId = mainFormId;
  215. entity.ChildFormId = childFormId;
  216. entity.FormOrder = formOrder;
  217. entity.FormState = formState;
  218. MainChildForm.GetInstance().Insert(entity);
  219. return true;
  220. }
  221. catch (Exception ex)
  222. {
  223. throw ex;
  224. }
  225. }
  226. /// <summary>
  227. /// 把子表单从主表单中移除
  228. /// </summary>
  229. /// <param name="mainFormId">主表单id</param>
  230. /// <param name="childFormId">子表单id</param>
  231. /// <returns>是否成功</returns>
  232. public bool RemoveChildFromMain(string mainFormId, string childFormId)
  233. {
  234. try
  235. {
  236. string tmpSql = "delete HF_MainChildForm where mainFormId=@mainFormId and childFormId=@childFormId";
  237. SqlDataItem sqlItem = new SqlDataItem();
  238. sqlItem.CommandText = tmpSql;
  239. sqlItem.AppendParameter("@mainFormId", mainFormId);
  240. sqlItem.AppendParameter("@childFormId", childFormId);
  241. ClientDBAgent agent = new ClientDBAgent();
  242. agent.ExecuteNonQuery(sqlItem);
  243. return true;
  244. }
  245. catch (Exception ex)
  246. {
  247. throw ex;
  248. }
  249. }
  250. /// <summary>
  251. /// 移除主表单中所有子表单
  252. /// </summary>
  253. /// <param name="mainUserCtrlId">主表单id</param>
  254. /// <returns>是否成功</returns>
  255. public bool RemoveAllChildFromMain(string mainFormId)
  256. {
  257. try
  258. {
  259. string tmpSql = "delete HF_MainChildForm where mainFormId=@mainFormId";
  260. SqlDataItem sqlItem = new SqlDataItem();
  261. sqlItem.CommandText = tmpSql;
  262. sqlItem.AppendParameter("@mainFormId", mainFormId);
  263. ClientDBAgent agent = new ClientDBAgent();
  264. agent.ExecuteNonQuery(sqlItem);
  265. return true;
  266. }
  267. catch (Exception ex)
  268. {
  269. throw ex;
  270. }
  271. }
  272. /// <summary>
  273. /// 获得流程的所有表单配置关系信息
  274. /// </summary>
  275. /// <param name="workFlowId"></param>
  276. /// <returns></returns>
  277. public DataTable GetMainChildFormsOfWorkFlow(string workFlowId)
  278. {
  279. try
  280. {
  281. string tmpStr = "select distinct wcf.* from HF_WorkTaskForm wtf left join HF_MainChildForm wcf on wtf.MainFormId=wcf.MainFormId "+
  282. " where wtf.workflowid=@workFlowId";
  283. SqlDataItem sqlItem = new SqlDataItem();
  284. sqlItem.CommandText = tmpStr;
  285. sqlItem.AppendParameter("@workFlowId", workFlowId);
  286. ClientDBAgent agent = new ClientDBAgent();
  287. return agent.ExecuteDataTable(sqlItem);
  288. }
  289. catch (Exception ex)
  290. {
  291. throw ex;
  292. }
  293. }
  294. /// <summary>
  295. /// 获得主表单与子表单的视图信息
  296. /// </summary>
  297. /// <param name="mainFormId"></param>
  298. /// <returns>DataTable</returns>
  299. public DataTable GetMainChildFormView(string mainFormId)
  300. {
  301. try
  302. {
  303. string tmpStr = @"SELECT * from HF_MainChildFormsView
  304. where MainFormId=@mainFormId order by FormOrder ";
  305. SqlDataItem sqlItem = new SqlDataItem();
  306. sqlItem.CommandText = tmpStr;
  307. sqlItem.AppendParameter("@mainFormId", mainFormId);
  308. ClientDBAgent agent = new ClientDBAgent();
  309. return agent.ExecuteDataTable(sqlItem);
  310. }
  311. catch (Exception ex)
  312. {
  313. throw ex;
  314. }
  315. }
  316. /// <summary>
  317. /// 获得主表单与子表单的视图信息
  318. /// </summary>
  319. /// <param name="mainFormId"></param>
  320. /// <returns>Entitys</returns>
  321. public List<MainChildFormViewEntity> GetMainChildFormViewEntitys(string mainFormId)
  322. {
  323. List<MainChildFormViewEntity> result = new List<MainChildFormViewEntity>();
  324. DataTable dt = GetMainChildFormView(mainFormId);
  325. try
  326. {
  327. foreach (DataRow dr in dt.Rows)
  328. {
  329. MainChildFormViewEntity entity = new MainChildFormViewEntity();
  330. entity.MainChildId = dr["MainChildId"].ToString();
  331. entity.MainFormId = dr["MainFormId"].ToString();
  332. entity.ChildFormId = dr["ChildFormId"].ToString();
  333. entity.MainCaption = dr["MainCaption"].ToString();
  334. entity.ChildCaption = dr["ChildCaption"].ToString();
  335. entity.FileName = dr["FileName"].ToString();
  336. entity.FilePath= dr["FilePath"].ToString();
  337. entity.FormOrder =Convert.ToInt16(dr["FormOrder"]);
  338. entity.FormState = dr["FormState"].ToString();
  339. entity.Description = dr["Description"].ToString();
  340. result.Add(entity);
  341. }
  342. return result;
  343. }
  344. catch (Exception ex)
  345. {
  346. throw ex;
  347. }
  348. }
  349. /// <summary>
  350. /// 获得任务节点与表单的视图信息
  351. /// </summary>
  352. /// <param name="workTaskId">任务模板Id</param>
  353. /// <returns>DataTable</returns>
  354. public DataTable GetWorkTaskFormsView(string workTaskId)
  355. {
  356. try
  357. {
  358. string tmpStr = @"SELECT * from HF_WorkTaskFormsView
  359. where workTaskId=@workTaskId order by FormOrder ";
  360. SqlDataItem sqlItem = new SqlDataItem();
  361. sqlItem.CommandText = tmpStr;
  362. sqlItem.AppendParameter("@workTaskId", workTaskId);
  363. ClientDBAgent agent = new ClientDBAgent();
  364. return agent.ExecuteDataTable(sqlItem);
  365. }
  366. catch (Exception ex)
  367. {
  368. throw ex;
  369. }
  370. }
  371. #endregion
  372. #endregion
  373. }
  374. }