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

.net编程

开发平台:

Others

  1. using System;
  2. using System.Data;
  3. using System.Data.SqlClient;
  4. using qminoa.Common.Data;
  5. namespace qminoa.DA.Schedule
  6. {
  7. public class ScheduleDA
  8. {
  9. private String conn=System.Configuration.ConfigurationSettings.AppSettings.Get("ConnectionString");
  10. public ScheduleDA()
  11. {
  12. }
  13. public SqlCommand cpOtherManRead(int schid)
  14. {
  15. SqlConnection objconnection = new SqlConnection(conn);
  16. SqlCommand objcommand=new SqlCommand();
  17. objcommand.Connection =objconnection;  
  18. objcommand.CommandText = "cpOtherManRead";
  19. objcommand.CommandType = CommandType.StoredProcedure;
  20. objcommand.Parameters.Add(new SqlParameter("@schid", SqlDbType.Int));
  21. objcommand.Parameters["@schid"].Value=schid;
  22. return objcommand;
  23. }
  24. public SqlCommand SchRead(int EmpID,DateTime FDate)
  25. {
  26. SqlConnection objconnection = new SqlConnection(conn);
  27. SqlCommand objcommand=new SqlCommand(); 
  28. objcommand.Connection =objconnection;
  29. objcommand.CommandText = "cpMyAllSch";
  30. objcommand.CommandType = CommandType.StoredProcedure; 
  31. objcommand.Parameters.Add(new SqlParameter("@EmpID", SqlDbType.Int));
  32. objcommand.Parameters["@EmpID"].Value=EmpID;
  33. objcommand.Parameters.Add(new SqlParameter("@FDate", SqlDbType.DateTime));
  34. objcommand.Parameters["@FDate"].Value=FDate;
  35. return objcommand;
  36. }
  37. public int IsMySchedule(int EmpID,int id)
  38. {
  39. int opt = -1;
  40. SqlCommand objcommand = new SqlCommand();
  41. SqlDataReader cpread;
  42. SqlConnection objconnection = new SqlConnection(conn);
  43. objcommand.Connection =objconnection;
  44. objcommand.CommandText = "cpIsMySchedule";
  45. objcommand.CommandType = CommandType.StoredProcedure;
  46. objcommand.Parameters.Add(new SqlParameter("@SchID", SqlDbType.Int));
  47. objcommand.Parameters["@SchID"].Value=id;
  48. objcommand.Connection.Open();
  49. cpread = objcommand.ExecuteReader();
  50. cpread.Read();
  51. if(EmpID == Int16.Parse(cpread.GetValue(0).ToString()))
  52. {
  53. opt = 0;
  54. }
  55. cpread.Close();
  56. objcommand.Connection.Close();
  57. return opt;
  58. }
  59. public DataSet cpMySch(int SchID)
  60. {
  61. SqlCommand command = new SqlCommand();
  62. command.CommandText = "cpMySchByID";
  63. command.CommandType = CommandType.StoredProcedure;
  64. command.Connection = new SqlConnection(conn);
  65. SqlParameter param = new SqlParameter(paramChg(ScheduleData.SCHID_FIELD),SqlDbType.Int);
  66. param.Value = SchID;
  67. command.Parameters.Add(param);
  68. SqlDataAdapter commandAdp = new SqlDataAdapter();
  69. commandAdp.SelectCommand = command;
  70. DataSet data = new DataSet();
  71. try
  72. {
  73. commandAdp.Fill(data);
  74. }
  75. catch(Exception ex)
  76. {
  77. throw new ApplicationException(ex.ToString());
  78. }
  79. return data;
  80. }
  81. public DataSet cpScheduleTip(int empID)
  82. {
  83. SqlCommand command = new SqlCommand();
  84. command.CommandText = "cpScheduleTip";
  85. command.CommandType = CommandType.StoredProcedure;
  86. command.Connection = new SqlConnection(conn);
  87. SqlParameter param = new SqlParameter("@EmpID",SqlDbType.Int);
  88. param.Value = empID;
  89. command.Parameters.Add(param);
  90. SqlDataAdapter commandAdp = new SqlDataAdapter();
  91. commandAdp.SelectCommand = command;
  92. DataSet data = new DataSet();
  93. try
  94. {
  95. commandAdp.Fill(data);
  96. }
  97. catch(Exception ex)
  98. {
  99. throw new ApplicationException(ex.ToString());
  100. }
  101. return data;
  102. }
  103. public void cpSchDel(int schid)
  104. {
  105. SqlConnection objconnection = new SqlConnection(conn);
  106. SqlCommand objcommand=new SqlCommand(); 
  107. objcommand.Connection =objconnection;  
  108. objcommand.CommandText = "cpSchDel";
  109. objcommand.CommandType = CommandType.StoredProcedure;
  110.   objcommand.Parameters.Add(new SqlParameter("@schid", SqlDbType.Int));
  111. objcommand.Parameters["@schid"].Value=schid;
  112. objcommand.Connection.Open();
  113. objcommand.ExecuteNonQuery();
  114. objcommand.Connection.Close();
  115. }
  116. public void cpDelOtherMan(int schid)
  117. {
  118. SqlConnection objconnection = new SqlConnection(conn);
  119. SqlCommand objcommand=new SqlCommand(); 
  120. objcommand.Connection =objconnection;  
  121. objcommand.CommandText = "cpDelOtherMan";
  122. objcommand.CommandType = CommandType.StoredProcedure; 
  123. objcommand.Parameters.Add(new SqlParameter("@schid", SqlDbType.Int));
  124. objcommand.Parameters["@schid"].Value=schid;
  125. objcommand.Connection.Open();
  126. objcommand.ExecuteNonQuery();
  127. objcommand.Connection.Close();
  128. }
  129. public void cpOtherManAddUp(int schid,string otherman)
  130. {
  131. SqlConnection objconnection = new SqlConnection(conn);
  132. SqlCommand objcommand=new SqlCommand(); 
  133. objcommand.Connection =objconnection;  
  134. objcommand.CommandText = "cpOtherManAddUp";
  135. objcommand.CommandType = CommandType.StoredProcedure; 
  136. objcommand.Parameters.Add(new SqlParameter("@schid", SqlDbType.Int));
  137. objcommand.Parameters["@schid"].Value=schid;
  138. objcommand.Parameters.Add(new SqlParameter("@otherman", SqlDbType.VarChar));
  139. objcommand.Parameters["@otherman"].Value=otherman;
  140. objcommand.Connection.Open();
  141. objcommand.ExecuteNonQuery();
  142. objcommand.Connection.Close();
  143. }
  144. public int ScheduleAdd(ScheduleData schdata)
  145. {
  146. SqlCommand command = new SqlCommand();
  147. command.CommandType = CommandType.StoredProcedure;
  148. command.Connection = new SqlConnection(conn);
  149. command.CommandText = "cpScheduleAdd";
  150. SqlParameter paramTmp = new SqlParameter("@Identify",SqlDbType.Int);
  151. paramTmp.Direction = ParameterDirection.ReturnValue;
  152. command.Parameters.Add(paramTmp);
  153. command.Parameters.Add(paramChg(ScheduleData.EMPID_FIELD),SqlDbType.Int);
  154. command.Parameters.Add(paramChg(ScheduleData.SUBJECT_FIELD),SqlDbType.VarChar);
  155. command.Parameters.Add(paramChg(ScheduleData.SCHTYPE_FIELD),SqlDbType.VarChar);
  156. command.Parameters.Add(paramChg(ScheduleData.PLACE_FIELD),SqlDbType.VarChar);
  157. command.Parameters.Add(paramChg(ScheduleData.CONTENT_FIELD),SqlDbType.Text);
  158. command.Parameters.Add(paramChg(ScheduleData.PRIVFLAG_FIELD),SqlDbType.Bit);
  159. command.Parameters.Add(paramChg(ScheduleData.REPEATFLAG_FIELD),SqlDbType.Bit);
  160. command.Parameters.Add(paramChg(ScheduleData.REQUENCATE_FIELD),SqlDbType.Char);
  161. command.Parameters.Add(paramChg(ScheduleData.UPTODATE_FIELD),SqlDbType.DateTime);
  162. command.Parameters.Add(paramChg(ScheduleData.REMINDFLAG_FIELD),SqlDbType.Bit);
  163. command.Parameters.Add(paramChg(ScheduleData.REMINDDAY_FIELD),SqlDbType.SmallInt);
  164. command.Parameters.Add(paramChg(ScheduleData.FDATE_FIELD),SqlDbType.DateTime);
  165. command.Parameters.Add(paramChg(ScheduleData.TDATE_FIELD),SqlDbType.DateTime);
  166. command.Parameters[paramChg(ScheduleData.EMPID_FIELD)].SourceColumn = ScheduleData.EMPID_FIELD;
  167. command.Parameters[paramChg(ScheduleData.SUBJECT_FIELD)].SourceColumn = ScheduleData.SUBJECT_FIELD;
  168. command.Parameters[paramChg(ScheduleData.SCHTYPE_FIELD)].SourceColumn = ScheduleData.SCHTYPE_FIELD;
  169. command.Parameters[paramChg(ScheduleData.PLACE_FIELD)].SourceColumn = ScheduleData.PLACE_FIELD;
  170. command.Parameters[paramChg(ScheduleData.CONTENT_FIELD)].SourceColumn = ScheduleData.CONTENT_FIELD;
  171. command.Parameters[paramChg(ScheduleData.PRIVFLAG_FIELD)].SourceColumn = ScheduleData.PRIVFLAG_FIELD;
  172. command.Parameters[paramChg(ScheduleData.REPEATFLAG_FIELD)].SourceColumn = ScheduleData.REPEATFLAG_FIELD;
  173. command.Parameters[paramChg(ScheduleData.REQUENCATE_FIELD)].SourceColumn = ScheduleData.REQUENCATE_FIELD;
  174. command.Parameters[paramChg(ScheduleData.UPTODATE_FIELD)].SourceColumn = ScheduleData.UPTODATE_FIELD;
  175. command.Parameters[paramChg(ScheduleData.REMINDFLAG_FIELD)].SourceColumn = ScheduleData.REMINDFLAG_FIELD;
  176. command.Parameters[paramChg(ScheduleData.REMINDDAY_FIELD)].SourceColumn = ScheduleData.REMINDDAY_FIELD;
  177. command.Parameters[paramChg(ScheduleData.FDATE_FIELD)].SourceColumn = ScheduleData.FDATE_FIELD;
  178. command.Parameters[paramChg(ScheduleData.TDATE_FIELD)].SourceColumn = ScheduleData.TDATE_FIELD;
  179. SqlDataAdapter commandAdp = new SqlDataAdapter();
  180. commandAdp.UpdateCommand = command;
  181. int result = commandAdp.Update(schdata,ScheduleData.SCHEDULE_TABLE);
  182. if(result>0)
  183. return (int)commandAdp.UpdateCommand.Parameters["@Identify"].Value;
  184. else
  185. return 0;
  186. }
  187. public bool ScheduleUpdate(ScheduleData schdata)
  188. {
  189. SqlCommand command = new SqlCommand();
  190. command.CommandType = CommandType.StoredProcedure;
  191. command.Connection = new SqlConnection(conn);
  192. command.CommandText = "cpScheduleUpdate";
  193. command.Parameters.Add(paramChg(ScheduleData.SCHID_FIELD),SqlDbType.Int);
  194. command.Parameters.Add(paramChg(ScheduleData.EMPID_FIELD),SqlDbType.Int);
  195. command.Parameters.Add(paramChg(ScheduleData.SUBJECT_FIELD),SqlDbType.VarChar);
  196. command.Parameters.Add(paramChg(ScheduleData.SCHTYPE_FIELD),SqlDbType.VarChar);
  197. command.Parameters.Add(paramChg(ScheduleData.PLACE_FIELD),SqlDbType.VarChar);
  198. command.Parameters.Add(paramChg(ScheduleData.CONTENT_FIELD),SqlDbType.Text);
  199. command.Parameters.Add(paramChg(ScheduleData.PRIVFLAG_FIELD),SqlDbType.Bit);
  200. command.Parameters.Add(paramChg(ScheduleData.REPEATFLAG_FIELD),SqlDbType.Bit);
  201. command.Parameters.Add(paramChg(ScheduleData.REQUENCATE_FIELD),SqlDbType.Char);
  202. command.Parameters.Add(paramChg(ScheduleData.UPTODATE_FIELD),SqlDbType.DateTime);
  203. command.Parameters.Add(paramChg(ScheduleData.REMINDFLAG_FIELD),SqlDbType.Bit);
  204. command.Parameters.Add(paramChg(ScheduleData.REMINDDAY_FIELD),SqlDbType.SmallInt);
  205. command.Parameters.Add(paramChg(ScheduleData.FDATE_FIELD),SqlDbType.DateTime);
  206. command.Parameters.Add(paramChg(ScheduleData.TDATE_FIELD),SqlDbType.DateTime);
  207. command.Parameters[paramChg(ScheduleData.SCHID_FIELD)].SourceColumn = ScheduleData.SCHID_FIELD;
  208. command.Parameters[paramChg(ScheduleData.EMPID_FIELD)].SourceColumn = ScheduleData.EMPID_FIELD;
  209. command.Parameters[paramChg(ScheduleData.SUBJECT_FIELD)].SourceColumn = ScheduleData.SUBJECT_FIELD;
  210. command.Parameters[paramChg(ScheduleData.SCHTYPE_FIELD)].SourceColumn = ScheduleData.SCHTYPE_FIELD;
  211. command.Parameters[paramChg(ScheduleData.PLACE_FIELD)].SourceColumn = ScheduleData.PLACE_FIELD;
  212. command.Parameters[paramChg(ScheduleData.CONTENT_FIELD)].SourceColumn = ScheduleData.CONTENT_FIELD;
  213. command.Parameters[paramChg(ScheduleData.PRIVFLAG_FIELD)].SourceColumn = ScheduleData.PRIVFLAG_FIELD;
  214. command.Parameters[paramChg(ScheduleData.REPEATFLAG_FIELD)].SourceColumn = ScheduleData.REPEATFLAG_FIELD;
  215. command.Parameters[paramChg(ScheduleData.REQUENCATE_FIELD)].SourceColumn = ScheduleData.REQUENCATE_FIELD;
  216. command.Parameters[paramChg(ScheduleData.UPTODATE_FIELD)].SourceColumn = ScheduleData.UPTODATE_FIELD;
  217. command.Parameters[paramChg(ScheduleData.REMINDFLAG_FIELD)].SourceColumn = ScheduleData.REMINDFLAG_FIELD;
  218. command.Parameters[paramChg(ScheduleData.REMINDDAY_FIELD)].SourceColumn = ScheduleData.REMINDDAY_FIELD;
  219. command.Parameters[paramChg(ScheduleData.FDATE_FIELD)].SourceColumn = ScheduleData.FDATE_FIELD;
  220. command.Parameters[paramChg(ScheduleData.TDATE_FIELD)].SourceColumn = ScheduleData.TDATE_FIELD;
  221. SqlDataAdapter commandAdp = new SqlDataAdapter();
  222. commandAdp.UpdateCommand = command;
  223. commandAdp.Update(schdata,ScheduleData.SCHEDULE_TABLE);
  224. if(schdata.HasErrors)
  225. {
  226. schdata.Tables[ScheduleData.SCHEDULE_TABLE].GetErrors()[0].ClearErrors();
  227. return false;
  228. }
  229. else
  230. {
  231. schdata.AcceptChanges();
  232. return true;
  233. }
  234. }
  235. private string paramChg(string str)
  236. {
  237. str = "@"+str;
  238. return str;
  239. }
  240. public DataSet dropPlacebind()
  241. {
  242. DataSet objdataset=new DataSet ();
  243. SqlDataAdapter objadapter=new SqlDataAdapter("cpDropPlaceBind",conn);
  244. objadapter.Fill(objdataset, "tablename");
  245. return objdataset;
  246. }
  247. public DataSet dropTypebind()
  248. {
  249. DataSet objdataset=new DataSet ();
  250. SqlDataAdapter objadapter=new SqlDataAdapter("cpDropTypeBind",conn);
  251. objadapter.Fill(objdataset, "tablename");
  252. return objdataset;
  253. }
  254. public DataTable cpdepempread(string Branch,string Dep,string EmpName)
  255. {
  256. SqlDataAdapter objadapter = new SqlDataAdapter();
  257. SqlCommand objcommand;
  258. DataTable objdataset = new DataTable();
  259. objadapter.SelectCommand = new SqlCommand(); 
  260. objadapter.SelectCommand.Connection = new SqlConnection(conn);
  261. objcommand = objadapter.SelectCommand;
  262. objcommand.CommandText = "cpDepEmpRead";
  263. objcommand.CommandType = CommandType.StoredProcedure;
  264. objcommand.Parameters.Add(new SqlParameter("@Branch", SqlDbType.VarChar));
  265. objcommand.Parameters["@Branch"].Value=Branch;
  266. objcommand.Parameters.Add(new SqlParameter("@Dep", SqlDbType.VarChar));
  267. objcommand.Parameters["@Dep"].Value=Dep;
  268. objcommand.Parameters.Add(new SqlParameter("@EmpName", SqlDbType.VarChar));
  269. objcommand.Parameters["@EmpName"].Value=EmpName;
  270. objadapter.Fill(objdataset);
  271. return objdataset;
  272. }
  273. public DataTable cpdepschread(DateTime fdate,int empid)
  274. {
  275. SqlDataAdapter objadapter = new SqlDataAdapter();
  276. SqlCommand objcommand;
  277. DataTable objdataset = new DataTable();
  278. objadapter.SelectCommand = new SqlCommand(); 
  279. objadapter.SelectCommand.Connection = new SqlConnection(conn);
  280. objcommand = objadapter.SelectCommand;
  281. objcommand.CommandText = "cpDepSchRead";
  282. objcommand.CommandType = CommandType.StoredProcedure;
  283. objcommand.Parameters.Add(new SqlParameter("@Fdate", SqlDbType.DateTime));
  284. objcommand.Parameters["@Fdate"].Value=fdate;
  285. objcommand.Parameters.Add(new SqlParameter("@EmpID", SqlDbType.Int));
  286. objcommand.Parameters["@EmpID"].Value=empid;
  287. objadapter.Fill(objdataset);
  288. return objdataset;
  289. }
  290. }
  291. }