VisaCustomerCompanyService.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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 VisaCustomerCompanyService
  11. {
  12. List<VisaCustomerCompany> excuteSql(string sql, params SqlParameter[] param)
  13. {
  14. return ServiceBase<VisaCustomerCompany>.excuteSql(new VisaCustomerCompany(), "VisaCustomerCompany", sql, CommandType.Text, param);
  15. }
  16. VisaCustomerCompany excuteType(string sql, params SqlParameter[] param)
  17. {
  18. //查询结果放入对象集合
  19. List<VisaCustomerCompany> 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(VisaCustomerCompany Dov)
  29. {
  30. string sql = "insert into VisaCustomerCompany values(@DCid,@Company,@CompanyAddress,@Phone,@Job,@LeaderName,@WorkStart,@WorkEnd,@WorkState);SELECT @@IDENTITY";
  31. SqlParameter[] parameter = new SqlParameter[]{
  32. new SqlParameter("@DCid",Dov.DCid),
  33. new SqlParameter("@Company",Dov.Company),
  34. new SqlParameter("@CompanyAddress",Dov.CompanyAddress),
  35. new SqlParameter("@Phone",Dov.Phone),
  36. new SqlParameter("@Job",Dov.Job),
  37. new SqlParameter("@LeaderName",Dov.LeaderName),
  38. new SqlParameter("@WorkStart",Dov.WorkStart),
  39. new SqlParameter("@WorkEnd",Dov.WorkEnd),
  40. new SqlParameter("@WorkState",Dov.WorkState)
  41. };
  42. if (SqlHelper.ExecuteNonQuery(sql, CommandType.Text, parameter) > 0)
  43. return true;
  44. return false;
  45. }
  46. //改Update
  47. public bool Edit(VisaCustomerCompany Dov)
  48. {
  49. string sql = "update VisaCustomerCompany set DCid=@DCid,Company=@Company,CompanyAddress=@CompanyAddress,Phone=@Phone,Job=@Job,LeaderName=@LeaderName,WorkStart=@WorkStart,WorkEnd=@WorkEnd,WorkState=@WorkState where Id = @Id";
  50. SqlParameter[] parameter = new SqlParameter[]{
  51. new SqlParameter("@DCid",Dov.DCid),
  52. new SqlParameter("@Company",Dov.Company),
  53. new SqlParameter("@CompanyAddress",Dov.CompanyAddress),
  54. new SqlParameter("@Phone",Dov.Phone),
  55. new SqlParameter("@Job",Dov.Job),
  56. new SqlParameter("@LeaderName",Dov.LeaderName),
  57. new SqlParameter("@WorkStart",Dov.WorkStart),
  58. new SqlParameter("@WorkEnd",Dov.WorkEnd),
  59. new SqlParameter("@WorkState",Dov.WorkState),
  60. new SqlParameter("@Id",Dov.Id)
  61. };
  62. if (SqlHelper.ExecuteNonQuery(sql, CommandType.Text, parameter) > 0)
  63. return true;
  64. return false;
  65. }
  66. public bool del(int DCID)
  67. {
  68. if (SqlHelper.ExecuteNonQuery("delete from VisaCustomerCompany where DCid=@DCId", CommandType.Text, new SqlParameter("@DCId", DCID)) > 0)
  69. return true;
  70. return false;
  71. }
  72. public List<VisaCustomerCompany> GetAllByDCID(int DCID)
  73. {
  74. return excuteSql("select * from VisaCustomerCompany where DCId=@DCId order by Id", new SqlParameter("@DCId", DCID));
  75. }
  76. public VisaCustomerCompany GetByID(int id)
  77. {
  78. return excuteType("select * from VisaCustomerCompany where Id=@Id", new SqlParameter("@Id", id));
  79. }
  80. }
  81. }