Open7CodeServices.cs 3.4 KB

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