Open5CodeServices.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data;
  4. using System.Data.Common;
  5. using System.Data.SqlClient;
  6. using System.Linq;
  7. using Lottomat.Application.Code;
  8. using Lottomat.Application.Entity.CommonEntity;
  9. using Lottomat.Application.IService.OpenCodeManage;
  10. using Lottomat.Data.Repository;
  11. using Lottomat.Util;
  12. using Lottomat.Util.Extension;
  13. namespace Lottomat.Application.Service.OpenCodeManage
  14. {
  15. /// <summary>
  16. /// 开奖5个球号的彩种数据服务
  17. /// </summary>
  18. public class Open5CodeServices : RepositoryFactory, IOpen5Code
  19. {
  20. /// <summary>
  21. /// 获取最新一条记录
  22. /// </summary>
  23. /// <param name="lottery">彩种名称</param>
  24. /// <returns></returns>
  25. public OpenCode5Model GetLastItem(SCCLottery lottery)
  26. {
  27. var TableName = lottery.GetSCCLotteryTableName();
  28. var sqlString = string.Format(LastItemSql, TableName);
  29. var ds = this.BaseRepository(DatabaseLinksEnum.LotteryNumber).FindTable(sqlString);
  30. if (ds != null && ds.DataSet.Tables.Count > 0 && ds.DataSet.Tables[0].Rows.Count > 0)
  31. {
  32. var result = BaseServices.LoadData<OpenCode5Model>(ds.DataSet.Tables[0].Rows[0]);
  33. return result;
  34. }
  35. return null;
  36. }
  37. /// <summary>
  38. /// 新增彩种开奖数据
  39. /// </summary>
  40. /// <param name="lottery">彩种名称</param>
  41. /// <param name="model">开奖数据模型</param>
  42. /// <returns></returns>
  43. public bool AddOpen5Code(SCCLottery lottery, OpenCode5Model model)
  44. {
  45. var TableName = lottery.GetSCCLotteryTableName();
  46. var sqlString = string.Format(AddItemSql, TableName);
  47. DbParameter[] param = new DbParameter[]{
  48. new SqlParameter("@Term",model.Term),
  49. new SqlParameter("@OpenCode1",model.OpenCode1),
  50. new SqlParameter("@OpenCode2",model.OpenCode2),
  51. new SqlParameter("@OpenCode3",model.OpenCode3),
  52. new SqlParameter("@OpenCode4",model.OpenCode4),
  53. new SqlParameter("@OpenCode5",model.OpenCode5),
  54. new SqlParameter("@OpenTime",model.OpenTime),
  55. new SqlParameter("@ID",Guid.NewGuid().ToString().Replace("-", ""))
  56. };
  57. var result = this.BaseRepository(DatabaseLinksEnum.LotteryNumber).ExecuteBySql(sqlString, param);
  58. return result > 0;
  59. }
  60. #region Sql语句
  61. /// <summary>
  62. /// 获取最新一条记录的Sql语句
  63. /// </summary>
  64. private static string LastItemSql = @"SELECT TOP 1 * FROM {0} ORDER BY Term DESC";
  65. /// <summary>
  66. /// 新增开奖数据的Sql语句
  67. /// </summary>
  68. private static string AddItemSql = @"IF NOT EXISTS(SELECT TOP 1 1 FROM {0} WHERE Term = @Term)
  69. BEGIN
  70. INSERT INTO {0}(Term,OpenCode1,OpenCode2,OpenCode3,OpenCode4,OpenCode5,OpenTime,Addtime,ID)
  71. SELECT @Term,@OpenCode1,@OpenCode2,@OpenCode3,@OpenCode4,@OpenCode5,@OpenTime,GETDATE(),@ID
  72. END";
  73. #endregion
  74. }
  75. }