Department.cs
上传用户:simon2hong
上传日期:2021-11-18
资源大小:16746k
文件大小:8k
源码类别:

OA系统

开发平台:

C#

  1. //------------------------------------------------------------------------------
  2. // 创建标识: Copyright (C) 2009 Socansoft.com 版权所有
  3. // 创建描述: SocanCode代码生成器 V4.3.2.3 自动创建于 2009-11-15 20:10:34
  4. //
  5. // 功能描述: 
  6. //
  7. // 修改标识: 
  8. // 修改描述: 
  9. //------------------------------------------------------------------------------
  10. using System;
  11. using System.Data;
  12. using System.Data.Common;
  13. using System.Text;
  14. using System.Collections;
  15. using System.Collections.Generic;
  16. namespace SqlServerDAL
  17. {
  18. /// <summary>
  19. /// 数据访问类 Department
  20. /// </summary>
  21. public class Department : DALHelper
  22. {
  23. /// <summary>
  24. /// 增加一条数据
  25. /// </summary>
  26. public int Add(Model.Department model)
  27. {
  28. StringBuilder strSql = new StringBuilder();
  29. strSql.Append("INSERT INTO Department(");
  30.             strSql.Append("DeptId,ParentDept,DeptName,DeptNo,TelNo,FaxNo,Manager,Leader1,Leader2,DeptFunc)");
  31. strSql.Append(" VALUES (");
  32.             strSql.Append("@in_DeptId,@in_ParentDept,@in_DeptName,@in_DeptNo,@in_TelNo,@in_FaxNo,@in_Manager,@in_Leader1,@in_Leader2,@in_DeptFunc)");
  33. DbParameter[] cmdParms = {
  34. DataBaseOAHelper.CreateInDbParameter("@in_DeptId", DbType.Int32, model.DeptId),
  35. DataBaseOAHelper.CreateInDbParameter("@in_ParentDept", DbType.Int32, model.ParentDept),
  36. DataBaseOAHelper.CreateInDbParameter("@in_DeptName", DbType.String, model.DeptName),
  37. DataBaseOAHelper.CreateInDbParameter("@in_DeptNo", DbType.Int32, model.DeptNo),
  38. DataBaseOAHelper.CreateInDbParameter("@in_TelNo", DbType.String, model.TelNo),
  39. DataBaseOAHelper.CreateInDbParameter("@in_FaxNo", DbType.String, model.FaxNo),
  40. DataBaseOAHelper.CreateInDbParameter("@in_Manager", DbType.String, model.Manager),
  41. DataBaseOAHelper.CreateInDbParameter("@in_Leader1", DbType.String, model.Leader1),
  42. DataBaseOAHelper.CreateInDbParameter("@in_Leader2", DbType.String, model.Leader2),
  43. DataBaseOAHelper.CreateInDbParameter("@in_DeptFunc", DbType.String, model.DeptFunc)};
  44. return DataBaseOAHelper.ExecuteNonQuery(CommandType.Text, strSql.ToString(), cmdParms);
  45. }
  46. /// <summary>
  47. /// 更新一条数据
  48. /// </summary>
  49. public int Update(Model.Department model)
  50. {
  51. StringBuilder strSql = new StringBuilder();
  52. strSql.Append("UPDATE Department SET ");
  53. strSql.Append("DeptId=@in_DeptId,");
  54. strSql.Append("ParentDept=@in_ParentDept,");
  55. strSql.Append("DeptName=@in_DeptName,");
  56. strSql.Append("DeptNo=@in_DeptNo,");
  57. strSql.Append("TelNo=@in_TelNo,");
  58. strSql.Append("FaxNo=@in_FaxNo,");
  59. strSql.Append("Manager=@in_Manager,");
  60. strSql.Append("Leader1=@in_Leader1,");
  61. strSql.Append("Leader2=@in_Leader2,");
  62. strSql.Append("DeptFunc=@in_DeptFunc");
  63. strSql.Append(" WHERE ID=@in_ID");
  64. DbParameter[] cmdParms = {
  65. DataBaseOAHelper.CreateInDbParameter("@in_DeptId", DbType.Int32, model.DeptId),
  66. DataBaseOAHelper.CreateInDbParameter("@in_ParentDept", DbType.Int32, model.ParentDept),
  67. DataBaseOAHelper.CreateInDbParameter("@in_DeptName", DbType.String, model.DeptName),
  68. DataBaseOAHelper.CreateInDbParameter("@in_DeptNo", DbType.Int32, model.DeptNo),
  69. DataBaseOAHelper.CreateInDbParameter("@in_TelNo", DbType.String, model.TelNo),
  70. DataBaseOAHelper.CreateInDbParameter("@in_FaxNo", DbType.String, model.FaxNo),
  71. DataBaseOAHelper.CreateInDbParameter("@in_Manager", DbType.String, model.Manager),
  72. DataBaseOAHelper.CreateInDbParameter("@in_Leader1", DbType.String, model.Leader1),
  73. DataBaseOAHelper.CreateInDbParameter("@in_Leader2", DbType.String, model.Leader2),
  74. DataBaseOAHelper.CreateInDbParameter("@in_DeptFunc", DbType.String, model.DeptFunc),
  75. DataBaseOAHelper.CreateInDbParameter("@in_ID", DbType.Int32, model.ID)};
  76. return DataBaseOAHelper.ExecuteNonQuery(CommandType.Text, strSql.ToString(), cmdParms);
  77. }
  78. /// <summary>
  79. /// 删除一条数据
  80. /// </summary>
  81. public int Delete(int ID)
  82. {
  83. StringBuilder strSql = new StringBuilder();
  84. strSql.Append("DELETE FROM Department ");
  85. strSql.Append(" WHERE ID=@in_ID");
  86. DbParameter[] cmdParms = {
  87. DataBaseOAHelper.CreateInDbParameter("@in_ID", DbType.Int32, ID)};
  88. return DataBaseOAHelper.ExecuteNonQuery(CommandType.Text, strSql.ToString(), cmdParms);
  89. }
  90. /// <summary>
  91. /// 得到最大ID
  92. /// </summary>
  93. public int GetMaxId()
  94. {
  95. object obj = DataBaseOAHelper.ExecuteScalar(CommandType.Text, "SELECT MAX(ID) FROM Department", null);
  96. return DataBaseOAHelper.GetInt(obj);
  97. }
  98. /// <summary>
  99. /// 是否存在该记录
  100. /// </summary>
  101. public bool Exists(int ID)
  102. {
  103. StringBuilder strSql = new StringBuilder();
  104. strSql.Append("SELECT COUNT(1) FROM Department");
  105. strSql.Append(" WHERE ID=@in_ID");
  106. DbParameter[] cmdParms = {
  107. DataBaseOAHelper.CreateInDbParameter("@in_ID", DbType.Int32, ID)};
  108. object obj = DataBaseOAHelper.ExecuteScalar(CommandType.Text, strSql.ToString(), cmdParms);
  109. return DataBaseOAHelper.GetInt(obj) > 0;
  110. }
  111. /// <summary>
  112. /// 得到一个对象实体
  113. /// </summary>
  114. public Model.Department GetModel(int ID)
  115. {
  116. StringBuilder strSql = new StringBuilder();
  117. strSql.Append("SELECT * FROM Department ");
  118. strSql.Append(" WHERE ID=@in_ID");
  119. DbParameter[] cmdParms = {
  120. DataBaseOAHelper.CreateInDbParameter("@in_ID", DbType.Int32, ID)};
  121. Model.Department model = null;
  122. using (DbDataReader dr = DataBaseOAHelper.ExecuteReader(CommandType.Text, strSql.ToString(), cmdParms))
  123. {
  124. while (dr.Read())
  125. {
  126. model = GetModel(dr);
  127. }
  128. return model;
  129. }
  130. }
  131. /// <summary>
  132. /// 获取泛型数据列表
  133. /// </summary>
  134. public List<Model.Department> GetList()
  135. {
  136. StringBuilder strSql = new StringBuilder("SELECT * FROM Department order by deptNo asc");
  137. using (DbDataReader dr = DataBaseOAHelper.ExecuteReader(CommandType.Text, strSql.ToString(), null))
  138. {
  139. List<Model.Department> lst = GetList(dr);
  140. return lst;
  141. }
  142. }
  143. /// <summary>
  144. /// 得到数据条数
  145. /// </summary>
  146. public int GetCount(string condition)
  147. {
  148. return DataBaseOAHelper.GetCount("Department", condition);
  149. }
  150. /// <summary>
  151. /// 分页获取泛型数据列表
  152. /// </summary>
  153. public List<Model.Department> GetPageList(int pageSize, int pageIndex, string fldSort, bool fldDir, string condition)
  154. {
  155. using (DbDataReader dr = DataBaseOAHelper.GetPageList("Department", pageSize, pageIndex, fldSort, fldDir, condition))
  156. {
  157. List<Model.Department> lst = GetList(dr);
  158. return lst;
  159. }
  160. }
  161. #region -------- 私有方法,通常情况下无需修改 --------
  162. /// <summary>
  163. /// 由一行数据得到一个实体
  164. /// </summary>
  165. private Model.Department GetModel(DbDataReader dr)
  166. {
  167. Model.Department model = new Model.Department();
  168. model.ID = DataBaseOAHelper.GetInt(dr["ID"]);
  169. model.DeptId = DataBaseOAHelper.GetInt(dr["DeptId"]);
  170. model.ParentDept = DataBaseOAHelper.GetInt(dr["ParentDept"]);
  171. model.DeptName = DataBaseOAHelper.GetString(dr["DeptName"]);
  172. model.DeptNo = DataBaseOAHelper.GetInt(dr["DeptNo"]);
  173. model.TelNo = DataBaseOAHelper.GetString(dr["TelNo"]);
  174. model.FaxNo = DataBaseOAHelper.GetString(dr["FaxNo"]);
  175. model.Manager = DataBaseOAHelper.GetString(dr["Manager"]);
  176. model.Leader1 = DataBaseOAHelper.GetString(dr["Leader1"]);
  177. model.Leader2 = DataBaseOAHelper.GetString(dr["Leader2"]);
  178. model.DeptFunc = DataBaseOAHelper.GetString(dr["DeptFunc"]);
  179. return model;
  180. }
  181. /// <summary>
  182. /// 由DbDataReader得到泛型数据列表
  183. /// </summary>
  184. private List<Model.Department> GetList(DbDataReader dr)
  185. {
  186. List<Model.Department> lst = new List<Model.Department>();
  187. while (dr.Read())
  188. {
  189. lst.Add(GetModel(dr));
  190. }
  191. return lst;
  192. }
  193. #endregion
  194. }
  195. }