using System; using Dapper; using HNWD.Pregrant.Model; using System.Collections.Generic; using System.Text; namespace HNWD.Pregrant.DataAccess { public class WD_ZoneInfoDataAccess : GenericDataAccess { private WD_ZoneInfo wd_ZoneInfo = null; public WD_ZoneInfoExt ext = new WD_ZoneInfoExt(); public WD_ZoneInfoDataAccess(WD_ZoneInfo wd_ZoneInfo) { this.wd_ZoneInfo = wd_ZoneInfo; } private WD_ZoneInfoDataAccess() { } private readonly static WD_ZoneInfoDataAccess wd_ZoneInfoDataAccess = new WD_ZoneInfoDataAccess(); private readonly static object lockobj = new object(); public static WD_ZoneInfoDataAccess GetInstance() { lock (lockobj) { return wd_ZoneInfoDataAccess; } } public List Query(string PartitionNo) { string where = this.strWhere(PartitionNo); string strSql = " from [WD_ZoneInfo] {0} order by [ZONE_ZONEID] "; strSql = string.Format(strSql,where); strSql = strSql.Insert(0, " select {0} "); ext.messageDataList = this.Query(strSql, new WD_ZoneInfo()); ext.messageDataList.ForEach(f => f.bSuccess = this.bSuccess); ext.messageDataList.ForEach(f => f.Code = this.Code); ext.messageDataList.ForEach(f => f.Message = this.Message); ext.messageDataList.ForEach(f => f.Rows = this.Rows); ext.bSuccess = this.bSuccess; ext.Code = this.Code; ext.Message = this.Message; ext.Rows = this.Rows; return ext.messageDataList; } public List QueryAll() { string strSql = " select {0} from [WD_ZoneInfo] "; ext.FileList = this.Query(strSql, new WD_ZoneInfo()); ext.FileList.ForEach(f => f.bSuccess = this.bSuccess); ext.FileList.ForEach(f => f.Code = this.Code); ext.FileList.ForEach(f => f.Message = this.Message); ext.FileList.ForEach(f => f.Rows = this.Rows); ext.bSuccess = this.bSuccess; ext.Code = this.Code; ext.Message = this.Message; ext.Rows = this.Rows; return ext.messageDataList; } public void UpdateZoneStatus() { string strSql = "update [WD_ZoneInfo] SET ZONE_STATUS={0} where [ID]={1} ; update [WD_RunProfile] SET [BroadcastSaveFlag]=1"; strSql = string.Format(strSql, wd_ZoneInfo.ZONE_STATUS, wd_ZoneInfo.ID); this.Execute(strSql, this.wd_ZoneInfo); } private string strWhere(string PartitionNo) { string where = string.Empty; if (PartitionNo == "0" || PartitionNo == "1" || PartitionNo == "2" || PartitionNo == "3" || PartitionNo == "4" || PartitionNo == "5") { where = " where [ZONE_ZONEID]=" + PartitionNo; } else { where = " where [ZONE_ZONEID] > 0 "; } return where; } public void Business(List il, List ul, List dl) { 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}') "; 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}' "; string strSql_d = " delete WD_ZoneInfo where ID = '{0}' "; string strSql_a = " update [WD_RunProfile] SET [BroadcastSaveFlag]=1 "; StringBuilder sb_i = new StringBuilder(); foreach (WD_ZoneInfo wd in il) { 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); } StringBuilder sb_u = new StringBuilder(); foreach (WD_ZoneInfo wd in ul) { 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); } StringBuilder sb_d = new StringBuilder(); foreach (WD_ZoneInfo wd in dl) { sb_d.AppendFormat(strSql_d, wd.ID); } this.Execute(sb_i.ToString(), sb_u.ToString(), sb_d.ToString(), strSql_a); } } }