public ResponseCustomDataUpdate CustomDataUpdate([FromBody] RequestCustomDataUpdate request) { try { CustomDataBLL bll = new CustomDataBLL(); return(bll.CustomDataUpdate(request)); } catch (Exception ex) { throw new HttpResponseException( Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message)); } }
public ResponseCustomDataUpdate CustomDataUpdate(RequestCustomDataUpdate request) { ResponseCustomDataUpdate response = new ResponseCustomDataUpdate(); using (cnn = GetConnection()) { var ts = cnn.BeginTransaction(); try { var user = this.UserInfoGet(request.Token, ts); Dictionary <string, string> saveData = List2Dic(request.Data); #region code ,name verification var d = cnn.Query(@"select * from TKS_FAS_CaculateHelperDetail where code=@Code and accountId=@AccountId and parentId=@ParentId", new { Code = saveData["Code"], AccountId = user.AccountId, ParentId = request.Head.Id //item id }, ts); if (d.Count() > 0) { throw new NormalException("编码已经存在"); } d = cnn.Query(@"select * from TKS_FAS_CaculateHelperDetail where name=@Name and accountId=@AccountId and parentId=@ParentId", new { Name = saveData["Name"], AccountId = user.AccountId, ParentId = request.Head.Id//item id }, ts); if (d.Count() > 0) { throw new NormalException("名称已经存在"); } #endregion var item = cnn.QueryFirstOrDefault <TKS_FAS_CaculateHelperDetail>(@"select * from TKS_FAS_CaculateHelperDetail where id=@id", new { id = request.Id }, ts); string orginalName = item.Name; string upSql = @"update TKS_FAS_FGLBalance set Name = REPLACE(Name,'@OrignalName','@Name') where CalItem1=@CalItem1 and AccountId=@AccountId AND CalValue1=@CalValue1"; cnn.Execute(upSql, new { OrignalName = orginalName, Name = saveData["Name"], CalItem1 = item.ParentId, CalValue1 = item.Code, AccountId = item.AccountId }, ts); string upSql1 = @"update TKS_FAS_DocDetail set SubjectDescription = REPLACE(SubjectDescription,'" + orginalName + @"','" + saveData["Name"] + @"') where CalItem1='" + item.ParentId + "' and AccountId='" + item.AccountId + @"' AND CalValue1= '" + item.Code + "'"; cnn.Execute(upSql1, null, ts); //string upSql1 = @"update TKS_FAS_DocDetail set // SubjectDescription = REPLACE(SubjectDescription,'@OrignalName','@Name') // where CalItem1=@CalItem1 and AccountId=@AccountId AND // CalValue1=@CalValue1"; //var res = cnn.Execute(upSql1, new //{ // OrignalName = orginalName, // Name = saveData["Name"], // CalItem1 = item.ParentId, // CalValue1 = item.Code, // AccountId = item.AccountId //}, ts); string sql = @"update TKS_FAS_CaculateHelperDetail set code=@Code, name=@Name, memo=@Memo, custom1=@Custom1, custom2=@Custom2, custom3=@Custom3, custom4=@Custom4, custom5=@Custom5, custom6=@Custom6, custom7=@Custom7, custom8=@Custom8, isValid=@IsValid where id=@Id "; var data = LoadByDic(saveData); data.Id = request.Id; int r = cnn.Execute(sql, data, ts); if (r == 1) { ts.Commit(); response.IsSuccess = true; response.Message = "更新成功"; return(response); } else { throw new AppException(user.User.UserName, "CustomDataUpdate", "数据更新异常", r + "行数据被更新"); } } catch (Exception ex) { ts.Rollback(); return(this.DealException(response, ex) as ResponseCustomDataUpdate); } } }