Open3CodeServices.cs 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. /// 开奖3个球号的彩种数据服务
  17. /// </summary>
  18. public class Open3CodeServices : RepositoryFactory, IOpen3Code
  19. {
  20. /// <summary>
  21. /// 获取最新一条记录
  22. /// </summary>
  23. /// <param name="lottery">彩种名称</param>
  24. /// <returns></returns>
  25. public OpenCode3Model 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<OpenCode3Model>(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 AddOpen3Code(SCCLottery lottery, OpenCode3Model 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("@OpenTime",model.OpenTime),
  53. new SqlParameter("@ID",Guid.NewGuid().ToString().Replace("-", ""))
  54. };
  55. var result = this.BaseRepository(DatabaseLinksEnum.LotteryNumber).ExecuteBySql(sqlString, param);
  56. return result > 0;
  57. }
  58. #region Sql语句
  59. /// <summary>
  60. /// 获取最新一条记录的Sql语句
  61. /// </summary>
  62. private static string LastItemSql = @"SELECT TOP 1 * FROM {0} ORDER BY Term DESC";
  63. /// <summary>
  64. /// 获取前一天列表的Sql语句
  65. /// </summary>
  66. private static string YesterdayListSql = @"SELECT * FROM {0}
  67. WHERE CONVERT(varchar(10),OpenTime,112)={1}
  68. ORDER BY OpenTime DESC";
  69. /// <summary>
  70. /// 新增开奖数据的Sql语句
  71. /// </summary>
  72. private static string AddItemSql = @"IF NOT EXISTS(SELECT TOP 1 1 FROM {0} WHERE Term = @Term)
  73. BEGIN
  74. INSERT INTO {0}(Term,OpenCode1,OpenCode2,OpenCode3,OpenTime,Addtime,ID)
  75. SELECT @Term,@OpenCode1,@OpenCode2,@OpenCode3,@OpenTime,GETDATE(),@ID
  76. END";
  77. #endregion
  78. }
  79. }