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