MrDep.cs
上传用户:autodoor
上传日期:2022-08-04
资源大小:9973k
文件大小:8k
源码类别:

.net编程

开发平台:

Others

  1. using System;
  2. using System.Data.SqlClient;
  3. using System.Data;
  4. using qminoa.Common.Data;
  5. namespace qminoa.DA
  6. {
  7. public class MrDep :IDisposable
  8. {
  9. private string conStr ;
  10. private SqlConnection con ;
  11. private SqlDataAdapter commandAdp ;
  12. private string paramChg(string str)
  13. {
  14. str = "@"+str;
  15. return str;
  16. }
  17. public bool InsertMrBranch(string branchName,string simpleCode)
  18. {
  19. SqlCommand command = new SqlCommand();
  20. command.CommandText = "InsertMrBranch";
  21. command.Connection = con;
  22. command.CommandType = CommandType.StoredProcedure;
  23. command.Parameters.Add(paramChg(DepData.BRANCHNAME_FIELD),SqlDbType.VarChar);
  24. command.Parameters.Add(paramChg(DepData.SIMPLECODE_FIELD),SqlDbType.VarChar);
  25. command.Parameters[paramChg(DepData.BRANCHNAME_FIELD)].Value = branchName;
  26. command.Parameters[paramChg(DepData.SIMPLECODE_FIELD)].Value = simpleCode;
  27. con.Open();
  28. int result = command.ExecuteNonQuery();
  29. if(result>0)
  30. {
  31. return true;
  32. }
  33. else
  34. {
  35. return false;
  36. }
  37. }
  38. public bool UpdateMrBranch(int braID,string branchName,string simpleCode)
  39. {
  40. SqlCommand command = new SqlCommand();
  41. command.CommandText = "UpdateMrBranch";
  42. command.Connection = con;
  43. command.CommandType = CommandType.StoredProcedure;
  44. command.Parameters.Add(paramChg(DepData.BRANCHID_FIELD),SqlDbType.Int);
  45. command.Parameters.Add(paramChg(DepData.BRANCHNAME_FIELD),SqlDbType.VarChar);
  46. command.Parameters.Add(paramChg(DepData.SIMPLECODE_FIELD),SqlDbType.VarChar);
  47. //
  48. command.Parameters[paramChg(DepData.BRANCHID_FIELD)].Value = braID; 
  49. command.Parameters[paramChg(DepData.BRANCHNAME_FIELD)].Value = branchName;
  50. command.Parameters[paramChg(DepData.SIMPLECODE_FIELD)].Value = simpleCode;
  51. con.Open();
  52. int result = command.ExecuteNonQuery();
  53. if(result>0)
  54. {
  55. return true;
  56. }
  57. else
  58. {
  59. return false;
  60. }
  61. }
  62. public bool DeleteMrBranch(int braID)
  63. {
  64. SqlCommand command = new SqlCommand();
  65. command.CommandText = "DeleteMrBranch";
  66. command.Connection = con;
  67. command.CommandType = CommandType.StoredProcedure;
  68. SqlParameter param = new SqlParameter(paramChg(DepData.BRANCHID_FIELD),SqlDbType.Int);
  69. param.Value = braID;
  70. command.Parameters.Add(param);
  71. con.Open();
  72. int result = command.ExecuteNonQuery();
  73. if(result>0)
  74. {
  75. return true;
  76. }
  77. else
  78. {
  79. return false;
  80. }
  81. }
  82. public DataSet GetDepData_By_BranchID(int branchID)
  83. {
  84. SqlCommand command = new SqlCommand();
  85. command.CommandText = "GetDepInfByBranchID";
  86. command.Connection = con;
  87. command.CommandType = CommandType.StoredProcedure;
  88. SqlParameter param = new SqlParameter(paramChg(DepData.BRANCHID_FIELD),SqlDbType.Int);
  89. param.Value = branchID;
  90. command.Parameters.Add(param);
  91. commandAdp.SelectCommand = command;
  92. DataSet data = new DataSet();
  93. commandAdp.Fill(data);
  94. return data;
  95. }
  96. public DataSet GetDepData_By_DepID(int depID)
  97. {
  98. SqlCommand command = new SqlCommand();
  99. command.CommandText = "GetDepInfByDepID";
  100. command.Connection = con;
  101. command.CommandType = CommandType.StoredProcedure;
  102. SqlParameter param = new SqlParameter(paramChg(DepData.DEPID_FIELD),SqlDbType.Int);
  103. param.Value = depID;
  104. command.Parameters.Add(param);
  105. commandAdp.SelectCommand = command;
  106. DataSet data = new DataSet();
  107. commandAdp.Fill(data);
  108. return data;
  109. }
  110. public DataSet GetDepData()
  111. {
  112. SqlCommand  command = new SqlCommand();
  113. command.CommandText = "GetDepInf";
  114. command.Connection = con;
  115. command.CommandType = CommandType.StoredProcedure;
  116. commandAdp.SelectCommand = command;
  117. DataSet data = new DataSet();
  118. commandAdp.Fill(data);
  119. return data;
  120. }
  121. public DataSet GetBraData()
  122. {
  123. SqlCommand  command = new SqlCommand();
  124. command.CommandText = "GetBraInf";
  125. command.Connection = con;
  126. command.CommandType = CommandType.StoredProcedure;
  127. commandAdp.SelectCommand = command;
  128. DataSet data = new DataSet();
  129. commandAdp.Fill(data);
  130. return data;
  131. }
  132. public bool DeleteMrDep(int depID)
  133. {
  134. SqlCommand command = new SqlCommand();
  135. command.CommandText = "DeleteMrDep";
  136. command.CommandType = CommandType.StoredProcedure;
  137. SqlParameter param = new SqlParameter(paramChg(DepData.DEPID_FIELD),SqlDbType.Int);
  138. param.Value = depID;
  139. command.Parameters.Add(param);
  140. command.Connection = con;
  141. con.Open();
  142. int i = command.ExecuteNonQuery();
  143. con.Close();
  144. if(i==0)
  145. return false;
  146. else
  147. return true;
  148. }
  149. public bool InsertMrDep(DepData depData)
  150. {
  151. commandAdp.InsertCommand = GetCommand();
  152. commandAdp.InsertCommand.CommandText = "InsertMrDep";
  153. int result = commandAdp.Update(depData,DepData.DEP_TABLE_NAME);
  154. if(result>0)
  155. return true;
  156. else
  157. return false;
  158. }
  159. public bool UpdateMrDep(DepData depData)
  160. {
  161. commandAdp.UpdateCommand = GetCommand();
  162. commandAdp.UpdateCommand.CommandText = "UpdateMrDep";
  163. commandAdp.UpdateCommand.Parameters.Add(new SqlParameter(paramChg(DepData.DEPID_FIELD),SqlDbType.Int));
  164. commandAdp.UpdateCommand.Parameters[paramChg(DepData.DEPID_FIELD)].SourceColumn = DepData.DEPID_FIELD;
  165. int result = commandAdp.Update(depData,DepData.DEP_TABLE_NAME);
  166. if(result>0)
  167. return true;
  168. else
  169. return false;
  170. }
  171. private SqlCommand GetCommand()
  172. {
  173. SqlCommand command = new SqlCommand();
  174. command.Connection = con;
  175. command.CommandType = CommandType.StoredProcedure;
  176. SqlParameterCollection param = command.Parameters;
  177. param.Add(new SqlParameter(paramChg(DepData.BRANCHID_FIELD),SqlDbType.Int));
  178. param.Add(new SqlParameter(paramChg(DepData.DEPNAME_FIELD),SqlDbType.VarChar));
  179. param.Add(new SqlParameter(paramChg(DepData.MANAGER_FIELD),SqlDbType.VarChar));
  180. param.Add(new SqlParameter(paramChg(DepData.TEL1_FIELD),SqlDbType.VarChar));
  181. param.Add(new SqlParameter(paramChg(DepData.TEL2_FIELD),SqlDbType.VarChar));
  182. param.Add(new SqlParameter(paramChg(DepData.FAX_FIELD),SqlDbType.VarChar));
  183. param.Add(new SqlParameter(paramChg(DepData.PROVINCE_FIELD),SqlDbType.VarChar));
  184. param.Add(new SqlParameter(paramChg(DepData.CITY_FIELD),SqlDbType.VarChar));
  185. param.Add(new SqlParameter(paramChg(DepData.DISTRICT_FIELD),SqlDbType.VarChar));
  186. param.Add(new SqlParameter(paramChg(DepData.STREET_FIELD),SqlDbType.VarChar));
  187. param.Add(new SqlParameter(paramChg(DepData.POSTCODE_FIELD),SqlDbType.VarChar));
  188. param[paramChg(DepData.BRANCHID_FIELD)].SourceColumn = DepData.BRANCHID_FIELD;
  189. param[paramChg(DepData.DEPNAME_FIELD)].SourceColumn = DepData.DEPNAME_FIELD;
  190. param[paramChg(DepData.MANAGER_FIELD)].SourceColumn = DepData.MANAGER_FIELD;
  191. param[paramChg(DepData.TEL1_FIELD)].SourceColumn = DepData.TEL1_FIELD;
  192. param[paramChg(DepData.TEL2_FIELD)].SourceColumn = DepData.TEL2_FIELD;
  193. param[paramChg(DepData.FAX_FIELD)].SourceColumn = DepData.FAX_FIELD;
  194. param[paramChg(DepData.PROVINCE_FIELD)].SourceColumn = DepData.PROVINCE_FIELD;
  195. param[paramChg(DepData.CITY_FIELD)].SourceColumn = DepData.CITY_FIELD;
  196. param[paramChg(DepData.DISTRICT_FIELD)].SourceColumn = DepData.DISTRICT_FIELD;
  197. param[paramChg(DepData.STREET_FIELD)].SourceColumn = DepData.STREET_FIELD;
  198. param[paramChg(DepData.POSTCODE_FIELD)].SourceColumn = DepData.POSTCODE_FIELD;
  199. return command;
  200. }
  201. public void Dispose()
  202. {
  203. Dispose(true);
  204. GC.SuppressFinalize(true);
  205. }
  206. protected virtual void Dispose(bool disposing)
  207. {
  208. }
  209. public MrDep()
  210. {
  211. conStr = System.Configuration.ConfigurationSettings.AppSettings.Get("ConnectionString");
  212. con = new SqlConnection(conStr);
  213. commandAdp = new SqlDataAdapter();
  214. }
  215. }
  216. }