WD_ZoneInfoDataAccess.cs 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. using System;
  2. using Dapper;
  3. using HNWD.Pregrant.Model;
  4. using System.Collections.Generic;
  5. using System.Text;
  6. namespace HNWD.Pregrant.DataAccess
  7. {
  8. public class WD_ZoneInfoDataAccess : GenericDataAccess<WD_ZoneInfo>
  9. {
  10. private WD_ZoneInfo wd_ZoneInfo = null;
  11. public WD_ZoneInfoExt ext = new WD_ZoneInfoExt();
  12. public WD_ZoneInfoDataAccess(WD_ZoneInfo wd_ZoneInfo)
  13. {
  14. this.wd_ZoneInfo = wd_ZoneInfo;
  15. }
  16. private WD_ZoneInfoDataAccess()
  17. {
  18. }
  19. private readonly static WD_ZoneInfoDataAccess wd_ZoneInfoDataAccess = new WD_ZoneInfoDataAccess();
  20. private readonly static object lockobj = new object();
  21. public static WD_ZoneInfoDataAccess GetInstance()
  22. {
  23. lock (lockobj)
  24. {
  25. return wd_ZoneInfoDataAccess;
  26. }
  27. }
  28. public List<WD_ZoneInfo> Query(string PartitionNo)
  29. {
  30. string where = this.strWhere(PartitionNo);
  31. string strSql = " from [WD_ZoneInfo] {0} order by [ZONE_ZONEID] ";
  32. strSql = string.Format(strSql,where);
  33. strSql = strSql.Insert(0, " select {0} ");
  34. ext.messageDataList = this.Query(strSql, new WD_ZoneInfo());
  35. ext.messageDataList.ForEach(f => f.bSuccess = this.bSuccess);
  36. ext.messageDataList.ForEach(f => f.Code = this.Code);
  37. ext.messageDataList.ForEach(f => f.Message = this.Message);
  38. ext.messageDataList.ForEach(f => f.Rows = this.Rows);
  39. ext.bSuccess = this.bSuccess;
  40. ext.Code = this.Code;
  41. ext.Message = this.Message;
  42. ext.Rows = this.Rows;
  43. return ext.messageDataList;
  44. }
  45. public List<WD_ZoneInfo> QueryAll()
  46. {
  47. string strSql = " select {0} from [WD_ZoneInfo] ";
  48. ext.FileList = this.Query(strSql, new WD_ZoneInfo());
  49. ext.FileList.ForEach(f => f.bSuccess = this.bSuccess);
  50. ext.FileList.ForEach(f => f.Code = this.Code);
  51. ext.FileList.ForEach(f => f.Message = this.Message);
  52. ext.FileList.ForEach(f => f.Rows = this.Rows);
  53. ext.bSuccess = this.bSuccess;
  54. ext.Code = this.Code;
  55. ext.Message = this.Message;
  56. ext.Rows = this.Rows;
  57. return ext.messageDataList;
  58. }
  59. public void UpdateZoneStatus()
  60. {
  61. string strSql = "update [WD_ZoneInfo] SET ZONE_STATUS={0} where [ID]={1} ; update [WD_RunProfile] SET [BroadcastSaveFlag]=1";
  62. strSql = string.Format(strSql, wd_ZoneInfo.ZONE_STATUS, wd_ZoneInfo.ID);
  63. this.Execute(strSql, this.wd_ZoneInfo);
  64. }
  65. private string strWhere(string PartitionNo)
  66. {
  67. string where = string.Empty;
  68. if (PartitionNo == "0" || PartitionNo == "1" || PartitionNo == "2" || PartitionNo == "3" || PartitionNo == "4" || PartitionNo == "5")
  69. {
  70. where = " where [ZONE_ZONEID]=" + PartitionNo;
  71. }
  72. else
  73. {
  74. where = " where [ZONE_ZONEID] > 0 ";
  75. }
  76. return where;
  77. }
  78. public void Business(List<WD_ZoneInfo> il, List<WD_ZoneInfo> ul, List<WD_ZoneInfo> dl)
  79. {
  80. string strSql_i = " Insert into WD_ZoneInfo([ZONE_ZONEID],[ZONE_FILELIST],[ZONE_STATUS],[ZONE_CONTENT],[ZONE_WEEK],[ZONE_STARTTIME],[ZONE_ENDTIME],[ZONE_DATETIME]) VALUES ('{0}' , '{1}', '{2}', '{3}', '{4}', '{5}', '{6}', '{7}') ";
  81. string strSql_u = " Update WD_ZoneInfo set ZONE_ZONEID = '{0}' , ZONE_FILELIST = '{1}' , ZONE_STATUS = '{2}' , ZONE_CONTENT = '{3}' , ZONE_WEEK = '{4}', ZONE_STARTTIME = '{5}' , ZONE_ENDTIME = '{6}' , ZONE_DATETIME = '{7}' where ID = '{8}' ";
  82. string strSql_d = " delete WD_ZoneInfo where ID = '{0}' ";
  83. string strSql_a = " update [WD_RunProfile] SET [BroadcastSaveFlag]=1 ";
  84. StringBuilder sb_i = new StringBuilder();
  85. foreach (WD_ZoneInfo wd in il)
  86. {
  87. sb_i.AppendFormat(strSql_i, wd.ZONE_ZONEID, wd.ZONE_FILELIST, wd.ZONE_STATUS, wd.ZONE_CONTENT, wd.ZONE_WEEK, wd.ZONE_STARTTIME, wd.ZONE_ENDTIME, wd.ZONE_DATETIME);
  88. }
  89. StringBuilder sb_u = new StringBuilder();
  90. foreach (WD_ZoneInfo wd in ul)
  91. {
  92. sb_u.AppendFormat(strSql_u, wd.ZONE_ZONEID, wd.ZONE_FILELIST, wd.ZONE_STATUS, wd.ZONE_CONTENT, wd.ZONE_WEEK, wd.ZONE_STARTTIME, wd.ZONE_ENDTIME, wd.ZONE_DATETIME, wd.ID);
  93. }
  94. StringBuilder sb_d = new StringBuilder();
  95. foreach (WD_ZoneInfo wd in dl)
  96. {
  97. sb_d.AppendFormat(strSql_d, wd.ID);
  98. }
  99. this.Execute(sb_i.ToString(), sb_u.ToString(), sb_d.ToString(), strSql_a);
  100. }
  101. }
  102. }