Open10CodeServices.cs 3.6 KB

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