public ResponseFixedAssetsDelete FixedAssetsDelete([FromBody] RequestFixedAssetsDelete request) { try { FixedAssetsBLL bll = new FixedAssetsBLL(); return(bll.FixedAssetsDelete(request)); } catch (Exception ex) { throw new HttpResponseException( Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message)); } }
public ResponseFixedAssetsDelete FixedAssetsDelete(RequestFixedAssetsDelete request) { ResponseFixedAssetsDelete response = new ResponseFixedAssetsDelete(); using (cnn = GetConnection()) { var ts = cnn.BeginTransaction(); try { string sql = "select * from TKS_FAS_FixedAssetsChange where parentId=@ParentId"; var data = cnn.Query <TKS_FAS_FixedAssetsChange>(sql, new { ParentId = request.Data.Id }, ts).ToList(); bool flag = false; if (data.Count() > 0) { PeriodBLL bll = new PeriodBLL(cnn); foreach (var item in data) { flag = bll.IsPeriodPaid(item.PeriodId, ts); if (flag == true) { break; } } } if (flag)//已经结转 不允许删除凭证 { throw new NormalException("固定资产生成的凭证已经期末结转,不允许删除"); } else { sql = @" delete from TKS_FAS_FixedAssets where id=@Id"; cnn.Execute(sql, request.Data, ts); sql = "delete from TKS_FAS_FixedAssetsChange where parentId=@ParentId"; cnn.Execute(sql, new { ParentId = request.Data.Id }, ts); foreach (var item in data) { sql = "delete from TKS_FAS_Doc where id=@Id"; cnn.Execute(sql, new { Id = item.DocId }, ts); sql = "delete from TKS_FAS_DocDetail where parentId=@ParentId"; cnn.Execute(sql, new { ParentId = item.DocId }, ts); } //add by Hero.Zhang删除对应的log sql = @" delete from TKS_FAS_FixedAssetsLog where FixedId=@FixedId"; cnn.Execute(sql, new { FixedId = request.Data.Id }, ts); } ts.Commit(); response.IsSuccess = true; response.Message = "删除成功"; return(response); } catch (Exception ex) { ts.Rollback(); return(this.DealException(response, ex) as ResponseFixedAssetsDelete); } } }