コード例 #1
0
 /// <summary>
 /// 根据梦想Id获取梦想编辑信息
 /// </summary>
 /// <param name="id"></param>
 /// <returns></returns>
 public DreamInfoEditModel GetDreamInfoById(string id)
 {
     try
     {
         if (string.IsNullOrWhiteSpace(id))
         {
             throw new Exception("梦想Id不能为空!");
         }
         DreamInfoEditModel result = new DreamInfoEditModel();
         DataTable          dt     = _sql.Query("SELECT DreamCode,StartStage,EndStage,Type FROM DreamInfo WHERE IsDeleted = 0 AND DreamInfoId = @id", new Dictionary <string, object> {
             { "@id", id }
         });
         if (dt != null && dt.Rows.Count > 0)
         {
             result.DreamInfoId = id;
             result.DreamCode   = Cast.ConToString(dt.Rows[0]["DreamCode"]);
             result.StartStage  = Cast.ConToInt(dt.Rows[0]["StartStage"]);
             result.EndStage    = Cast.ConToInt(dt.Rows[0]["EndStage"]);
             result.Type        = Cast.ConToInt(dt.Rows[0]["Type"]);
         }
         return(result);
     }
     catch (Exception ex)
     {
         _log.Error(ex);
         throw ex;
     }
 }
コード例 #2
0
 /// <summary>
 /// 创建或更新梦想信息
 /// </summary>
 /// <param name="info">梦想编辑信息</param>
 /// <returns></returns>
 public string CreateOrUpdateDreamInfo(DreamInfoEditModel info)
 {
     try
     {
         if (string.IsNullOrWhiteSpace(info.DreamCode))
         {
             throw new Exception("彩票号码不能为空!");
         }
         info.DreamCode = info.DreamCode.Trim(' ');
         if (!info.DreamCode.Contains(' '))
         {
             throw new Exception("彩票号码以空格隔开!");
         }
         if (info.Type == (int)DreamInfoEnum.Type.DLT && info.DreamCode.Split(' ').Length != 7)
         {
             throw new Exception("大乐透号码必须为7位!");
         }
         else if (info.Type == (int)DreamInfoEnum.Type.PL3 && info.DreamCode.Split(' ').Length != 3)
         {
             throw new Exception("排列三号码必须为3位!");
         }
         else if (info.Type == (int)DreamInfoEnum.Type.PL5 && info.DreamCode.Split(' ').Length != 5)
         {
             throw new Exception("排列五号码必须为5位!");
         }
         _sql.OpenDb();
         string    result    = string.Empty;
         DreamInfo DreamInfo = new DreamInfo();
         info.FillTableWithModel <DreamInfo>(DreamInfo);
         if (!string.IsNullOrEmpty(info.DreamInfoId))
         {
             DreamInfo.UserInfoId = Guid.Parse(_identity.UserId);
             _sql.Update(DreamInfo);
             result = Constants.UpdateSuccessMssg;
         }
         else
         {
             DreamInfo.UserInfoId = Guid.Parse(_identity.UserId);
             _sql.Create(DreamInfo);
             result = Constants.CreateSuccessMssg;
         }
         return(result);
     }
     catch (Exception ex)
     {
         _log.Error(ex);
         throw ex;
     }
     finally
     {
         _sql.CloseDb();
     }
 }