VisaCustomerSchoolService.cs 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using Models;
  6. using System.Data.SqlClient;
  7. using System.Data;
  8. namespace DAL
  9. {
  10. public class VisaCustomerSchoolService
  11. {
  12. List<VisaCustomerSchool> excuteSql(string sql, params SqlParameter[] param)
  13. {
  14. return ServiceBase<VisaCustomerSchool>.excuteSql(new VisaCustomerSchool(), "VisaCustomerSchool", sql, CommandType.Text, param);
  15. }
  16. VisaCustomerSchool excuteType(string sql, params SqlParameter[] param)
  17. {
  18. //查询结果放入对象集合
  19. List<VisaCustomerSchool> hdList = excuteSql(sql, param);
  20. //判断集合是否为空
  21. if (hdList == null || hdList.Count == 0)
  22. //返回null
  23. return null;
  24. //返回单个对象
  25. return hdList[0];
  26. }
  27. //增Add
  28. public bool Add(VisaCustomerSchool Dov)
  29. {
  30. string sql = "insert into VisaCustomerSchool values(@DCid,@School,@Address,@Teacher,@Subject,@StudyStart,@StudyEnd);SELECT @@IDENTITY";
  31. SqlParameter[] parameter = new SqlParameter[]{
  32. new SqlParameter("@DCid",Dov.DCid),
  33. new SqlParameter("@School",Dov.School),
  34. new SqlParameter("@Address",Dov.Address),
  35. new SqlParameter("@Teacher",Dov.Teacher),
  36. new SqlParameter("@Subject",Dov.Subject),
  37. new SqlParameter("@StudyStart",Dov.StudyStart),
  38. new SqlParameter("@StudyEnd",Dov.StudyEnd)
  39. };
  40. if (SqlHelper.ExecuteNonQuery(sql, CommandType.Text, parameter) > 0)
  41. return true;
  42. return false;
  43. }
  44. //改Update
  45. public bool Edit(VisaCustomerSchool Dov)
  46. {
  47. string sql = "update VisaCustomerSchool set DCid=@DCid,School=@School,Address=@Address,Teacher=@Teacher,Subject=@Subject,StudyStart=@StudyStart,StudyEnd=@StudyEnd where Id = @Id";
  48. SqlParameter[] parameter = new SqlParameter[]{
  49. new SqlParameter("@DCid",Dov.DCid),
  50. new SqlParameter("@School",Dov.School),
  51. new SqlParameter("@Address",Dov.Address),
  52. new SqlParameter("@Teacher",Dov.Teacher),
  53. new SqlParameter("@Subject",Dov.Subject),
  54. new SqlParameter("@StudyStart",Dov.StudyStart),
  55. new SqlParameter("@StudyEnd",Dov.StudyEnd),
  56. new SqlParameter("@Id",Dov.Id)
  57. };
  58. if (SqlHelper.ExecuteNonQuery(sql, CommandType.Text, parameter) > 0)
  59. return true;
  60. return false;
  61. }
  62. public bool del(int DCID)
  63. {
  64. if (SqlHelper.ExecuteNonQuery("delete from VisaCustomerSchool where DCid=@DCId", CommandType.Text, new SqlParameter("@DCId", DCID)) > 0)
  65. return true;
  66. return false;
  67. }
  68. public List<VisaCustomerSchool> GetAllByDCID(int DCID)
  69. {
  70. return excuteSql("select * from VisaCustomerSchool where DCId=@DCId order by Id", new SqlParameter("@DCId", DCID));
  71. }
  72. public VisaCustomerSchool GetByID(int id)
  73. {
  74. return excuteType("select * from VisaCustomerSchool where Id=@Id", new SqlParameter("@Id", id));
  75. }
  76. }
  77. }