| | |
| | | |
| | | public bool Delete(YFDelete data) |
| | | { |
| | | if (data == null) |
| | | throw new ArgumentNullException(nameof(data)); |
| | | |
| | | if (string.IsNullOrWhiteSpace(data.FBillNo)) |
| | | throw new ArgumentException("FBillNo 不能为空", nameof(data.FBillNo)); |
| | | |
| | | if (string.IsNullOrWhiteSpace(data.FBillTypeID)) |
| | | throw new ArgumentException("FBillTypeID 不能为空", nameof(data.FBillTypeID)); |
| | | |
| | | return UseTransaction(db => |
| | | { |
| | | var update = db.Deleteable<Womcaa>() |
| | | .Where(it => it.Caa001 == data.FBillNo && |
| | | it.SrcBillType == data.FBillTypeID) |
| | | .ExecuteCommand() > 0; |
| | | // 删除主表数据 |
| | | var deleteMain = db.Deleteable<Womcaa>() |
| | | .Where(it => it.Caa001 == data.FBillNo && it.SrcBillType == data.FBillTypeID) |
| | | .ExecuteCommand() > 0; |
| | | |
| | | var insertOrUpdate = db.Deleteable<Womcab>() |
| | | .Where(it => it.Cab001 == data.FBillNo && |
| | | it.Cab002 == data.FBillTypeID) |
| | | .ExecuteCommand() > 0; |
| | | // 删除子表数据 |
| | | var deleteDetail = db.Deleteable<Womcab>() |
| | | .Where(it => it.Cab001 == data.FBillNo && it.Cab002 == data.FBillTypeID) |
| | | .ExecuteCommand() > 0; |
| | | |
| | | if (!deleteMain || !deleteDetail) |
| | | throw new Exception("删除失败:主表或子表记录不存在"); |
| | | |
| | | // 调用存储过程进行后续处理 |
| | | var inputParam1 = new SugarParameter("P_WORK_NO", data.FBillNo); |
| | | var inputParam2 = new SugarParameter("P_WORK_TYPE", data.FBillTypeID); |
| | | var outParam1 = new SugarParameter("C_RESULT", null, true); // 输出参数 |
| | | var outParam2 = new SugarParameter("C_MSG", null, true); // 输出参数 |
| | | |
| | | if (update && insertOrUpdate) return 1; |
| | | throw new NotImplementedException("删除失败"); |
| | | db.Ado.ExecuteCommand( |
| | | "BEGIN PRC_DELETE_DAA(:P_WORK_NO, :P_WORK_TYPE, :C_RESULT, :C_MSG); END;", |
| | | inputParam1, inputParam2, outParam1, outParam2); |
| | | |
| | | int result = int.Parse((string)outParam1.Value); |
| | | string message = outParam2.Value == DBNull.Value ? string.Empty : (string)outParam2.Value; |
| | | |
| | | if (result == 1) |
| | | { |
| | | //存储过程失败则事务进行回滚 |
| | | db.Ado.RollbackTran(); |
| | | throw new Exception(message); |
| | | |
| | | } |
| | | |
| | | return 1; |
| | | }) > 0; |
| | | |
| | | |
| | | } |
| | | |
| | | |