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