public ResponseFixedAssetsUpdate FixedAssetsUpdate([FromBody] RequestFixedAssetsUpdate request) { try { FixedAssetsBLL bll = new FixedAssetsBLL(); return(bll.FixedAssetsUpdate(request)); } catch (Exception ex) { throw new HttpResponseException( Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message)); } }
public ResponseFixedAssetsUpdate FixedAssetsUpdate(RequestFixedAssetsUpdate request) { ResponseFixedAssetsUpdate response = new ResponseFixedAssetsUpdate(); using (cnn = GetConnection()) { var ts = cnn.BeginTransaction(); try { var user = this.UserInfoGet(request.Token, ts); //更新固定资产前,先检查是否存在变更记录,若存在,先更新变更记录 var check = "select * from TKS_FAS_FixedAssetsChange where ParentId=@id"; var dataUpdate = cnn.Query(check, new { id = request.Data.Id }, ts); if (dataUpdate.Count() > 0) { //add by Hero.Zhang如果购入类型是期初,则删除变更记录 if (request.Data.AddType == "期初") { cnn.Execute(@"delete from TKS_FAS_FixedAssetsChange where ParentId=@id", new { id = request.Data.Id }, ts); } else { //获取更新前固定资产 var data = cnn.QueryFirst <TKS_FAS_FixedAssets>("select * from TKS_FAS_FixedAssets where id=@Id", new { Id = request.Data.Id }, ts); if (data != null) { string updateSql = @"update TKS_FAS_FixedAssetsChange set DocNo = @DocNo, AssetsName = @AssetsName, PreContent = @PreContent, CurContent = @CurContent where ParentId=@Id"; cnn.Execute(updateSql, new { DocNo = data.DocNo, AssetsName = data.Name, PreContent = request.Data.InitialAssetValue, CurContent = request.Data.InitialAssetValue, Id = request.Data.Id }, ts); } } } else { //add by Hero.Zhang //如果不存在变更记录,判断是否是期初购入类型,不是期初则新增变更记录 if (request.Data.AddType != "期初") { AccountSetBLL account = new AccountSetBLL(cnn); var period = account.GetActivePeriod(user.AccountId, ts); request.Data.AccountId = user.AccountId; request.Data.StartPeriod = period.Id;//当前期间为录入期间 request.Data.CreateUser = user.User.UserName; request.Data.CreateDate = DateTime.Now; AddChange(request.Data, ts); } } string sql = @"UPDATE TKS_FAS_FixedAssets SET DocNo = @DocNo ,Name = @Name ,AddType = @AddType ,AssetsClass = @AssetsClass ,SpecificationType = @SpecificationType ,StartUseDate = @StartUseDate ,UseDeptId = @UseDeptId ,UseDeptName = @UseDeptName ,Supplier = @Supplier ,DepreciationMethod = @DepreciationMethod ,IsStartPeriodDepreciation = @IsStartPeriodDepreciation ,ADSubjectCode = @ADSubjectCode ,ADSubjectName = @ADSubjectName ,DCostSubjectCode = @DCostSubjectCode ,DCostSubjectName = @DCostSubjectName ,AssetImpairmentSubjectCode = @AssetImpairmentSubjectCode ,AssetImpairmentSubjectName = @AssetImpairmentSubjectName ,InitialAssetValue = @InitialAssetValue ,ScrapValueRate = @ScrapValueRate ,ScrapValue = @ScrapValue ,PreUseMonth = @PreUseMonth ,DpreMonth = @DpreMonth ,RemainderUseMonth = @RemainderUseMonth ,AccumulativeDpre = @AccumulativeDpre ,AccumulativeDpre_Y = @AccumulativeDpre_Y ,PreviousAccumulativeDpre = @PreviousAccumulativeDpre ,DprePerMonth = @DprePerMonth ,GDCode=@GDCode ,GDName=@GDName ,InputVAT=@InputVAT ,Memo = @Memo WHERE Id=@Id"; cnn.Execute(sql, request.Data, ts); ts.Commit(); response.IsSuccess = true; response.Message = "更新成功"; return(response); } catch (Exception ex) { ts.Rollback(); return(this.DealException(response, ex) as ResponseFixedAssetsUpdate); } } }