From da4af4cb2ab1fbd74de61e4e63e85785433f2555 Mon Sep 17 00:00:00 2001 From: Jorge Luis caudillo esparza Date: Tue, 18 Aug 2026 03:22:46 -0700 Subject: [PATCH] orden etapas --- .../IFraccionamientoRepository.cs | 6 + .../IFraccionamientoService.cs | 6 + .../FraccionamientoRepository.cs | 32 ++- .../FraccionamientoService.cs | 193 +++++++++++++++--- .../FraccionamientoDetalle.aspx | 29 ++- .../FraccionamientoDetalle.aspx.cs | 100 +++++++-- .../FraccionamientoDetalle.aspx.designer.cs | 27 ++- 7 files changed, 331 insertions(+), 62 deletions(-) diff --git a/SIG.Web/App_Code/Contracts/Fraccionamientos/IFraccionamientoRepository.cs b/SIG.Web/App_Code/Contracts/Fraccionamientos/IFraccionamientoRepository.cs index f24699d..53b280e 100644 --- a/SIG.Web/App_Code/Contracts/Fraccionamientos/IFraccionamientoRepository.cs +++ b/SIG.Web/App_Code/Contracts/Fraccionamientos/IFraccionamientoRepository.cs @@ -29,6 +29,12 @@ namespace SIG.Web.AppCode.Contracts.Fraccionamientos string domainName); DbResult> ListStageProcedures(int developmentId, int executingUser, string domainName); DbResult SaveStage(FraccionamientoEtapaModel stage, int executingUser, string domainName); + DbResult MoveStageOrder( + int stageId, + int referenceStageId, + bool placeAfter, + int executingUser, + string domainName); DbResult DeleteStage(int stageId, int executingUser, string domainName); DbResult> ListLots( int developmentId, diff --git a/SIG.Web/App_Code/Contracts/Fraccionamientos/IFraccionamientoService.cs b/SIG.Web/App_Code/Contracts/Fraccionamientos/IFraccionamientoService.cs index 3f0cf3a..37b5ed2 100644 --- a/SIG.Web/App_Code/Contracts/Fraccionamientos/IFraccionamientoService.cs +++ b/SIG.Web/App_Code/Contracts/Fraccionamientos/IFraccionamientoService.cs @@ -32,6 +32,12 @@ namespace SIG.Web.AppCode.Contracts.Fraccionamientos string domainName); DbResult> ListStageProcedures(int developmentId, int executingUser, string domainName); DbResult SaveStage(FraccionamientoEtapaModel stage, int executingUser, string domainName); + DbResult MoveStageOrder( + int stageId, + int referenceStageId, + bool placeAfter, + int executingUser, + string domainName); DbResult DeleteStage(int stageId, int executingUser, string domainName); DbResult> ListLots( int developmentId, diff --git a/SIG.Web/App_Code/Repositories/Fraccionamientos/FraccionamientoRepository.cs b/SIG.Web/App_Code/Repositories/Fraccionamientos/FraccionamientoRepository.cs index 84fcdd0..1be752c 100644 --- a/SIG.Web/App_Code/Repositories/Fraccionamientos/FraccionamientoRepository.cs +++ b/SIG.Web/App_Code/Repositories/Fraccionamientos/FraccionamientoRepository.cs @@ -205,11 +205,41 @@ namespace SIG.Web.AppCode.Repositories.Fraccionamientos StoredProcedureCommand.AddInput(command, "@CveFraccionamiento", stage.CveFraccionamiento, DbType.Int32); StoredProcedureCommand.AddInput(command, "@Etapa", stage.Etapa, DbType.String); StoredProcedureCommand.AddInput(command, "@Hectareas", stage.Hectareas, DbType.Decimal); - StoredProcedureCommand.AddInput(command, "@Orden", stage.Orden, DbType.Int32); StoredProcedureCommand.AddInput(command, "@EsActivo", stage.EsActivo, DbType.Boolean); }); } + public DbResult MoveStageOrder( + int stageId, + int referenceStageId, + bool placeAfter, + int executingUser, + string domainName) + { + return Execute( + "dbo.PA_Fraccionamientos_EtapaOrdenMove", + executingUser, + domainName, + command => + { + StoredProcedureCommand.AddInput( + command, + "@CveFraccionamientoEtapa", + stageId, + DbType.Int32); + StoredProcedureCommand.AddInput( + command, + "@CveFraccionamientoEtapaReferencia", + referenceStageId, + DbType.Int32); + StoredProcedureCommand.AddInput( + command, + "@ColocarDespues", + placeAfter, + DbType.Boolean); + }); + } + public DbResult DeleteStage(int stageId, int executingUser, string domainName) { return Execute( diff --git a/SIG.Web/App_Code/Services/Fraccionamientos/FraccionamientoService.cs b/SIG.Web/App_Code/Services/Fraccionamientos/FraccionamientoService.cs index ab23265..e74ebca 100644 --- a/SIG.Web/App_Code/Services/Fraccionamientos/FraccionamientoService.cs +++ b/SIG.Web/App_Code/Services/Fraccionamientos/FraccionamientoService.cs @@ -305,41 +305,176 @@ namespace SIG.Web.AppCode.Services.Fraccionamientos bool isNewStage = stage.CveFraccionamientoEtapa <= 0; stage.Etapa = stage.Etapa.Trim(); - Func> saveAction = () => _repository.SaveStage( - stage, - executingUser, - domainName); - - if (isNewStage) + using (var transaction = new TransactionLogic()) { - return ExecuteInTransaction( - () => _repository.Get( - stage.CveFraccionamiento, + FraccionamientoEtapaModel previous = null; + int clientId; + + if (isNewStage) + { + DbResult developmentResult = + _repository.Get( + stage.CveFraccionamiento, + executingUser, + domainName); + + if (!developmentResult.Success || + developmentResult.Data == null) + { + return DbResult.Fail( + developmentResult.UserMessage, + developmentResult.TechnicalMessage, + developmentResult.Exception); + } + + clientId = developmentResult.Data.CveCliente; + } + else + { + DbResult previousResult = + _repository.GetStage( + stage.CveFraccionamientoEtapa, + executingUser, + domainName); + + if (!previousResult.Success || + previousResult.Data == null) + { + return DbResult.Fail( + previousResult.UserMessage, + previousResult.TechnicalMessage, + previousResult.Exception); + } + + previous = previousResult.Data; + clientId = previous.CveCliente; + } + + DbResult saveResult = _repository.SaveStage( + stage, + executingUser, + domainName); + + if (!saveResult.Success) + { + return saveResult; + } + + DbResult currentResult = + _repository.GetStage( + saveResult.Data, executingUser, - domainName), - saveAction, - (development, stageId) => SingleEvent( + domainName); + + if (!currentResult.Success || currentResult.Data == null) + { + return DbResult.Fail( + currentResult.UserMessage, + currentResult.TechnicalMessage, + currentResult.Exception); + } + + DbResult auditResult = RegisterEvents( + SingleEvent( FraccionamientoBitacoraFactory.CreateStage( - null, - stage, - stageId, - development.CveCliente, - BitacoraTipoMovimiento.Agregado))); + previous, + currentResult.Data, + saveResult.Data, + clientId, + isNewStage + ? BitacoraTipoMovimiento.Agregado + : BitacoraTipoMovimiento.Editado))); + + if (!auditResult.Success) + { + return DbResult.Fail( + auditResult.UserMessage, + auditResult.TechnicalMessage, + auditResult.Exception); + } + + transaction.Commit(); + return saveResult; + } + } + + public DbResult MoveStageOrder( + int stageId, + int referenceStageId, + bool placeAfter, + int executingUser, + string domainName) + { + if (stageId <= 0 || + referenceStageId <= 0 || + stageId == referenceStageId) + { + return Fail( + "Seleccione una posición válida para mover la etapa."); } - return ExecuteInTransaction( - () => _repository.GetStage( - stage.CveFraccionamientoEtapa, - executingUser, - domainName), - saveAction, - (previous, stageId) => SingleEvent( - FraccionamientoBitacoraFactory.CreateStage( - previous, - stage, + using (var transaction = new TransactionLogic()) + { + DbResult previousResult = + _repository.GetStage( stageId, - previous.CveCliente, - BitacoraTipoMovimiento.Editado))); + executingUser, + domainName); + + if (!previousResult.Success || previousResult.Data == null) + { + return DbResult.Fail( + previousResult.UserMessage, + previousResult.TechnicalMessage, + previousResult.Exception); + } + + DbResult moveResult = _repository.MoveStageOrder( + stageId, + referenceStageId, + placeAfter, + executingUser, + domainName); + + if (!moveResult.Success) + { + return moveResult; + } + + DbResult currentResult = + _repository.GetStage( + stageId, + executingUser, + domainName); + + if (!currentResult.Success || currentResult.Data == null) + { + return DbResult.Fail( + currentResult.UserMessage, + currentResult.TechnicalMessage, + currentResult.Exception); + } + + DbResult auditResult = RegisterEvents( + SingleEvent( + FraccionamientoBitacoraFactory.CreateStage( + previousResult.Data, + currentResult.Data, + stageId, + previousResult.Data.CveCliente, + BitacoraTipoMovimiento.Editado))); + + if (!auditResult.Success) + { + return DbResult.Fail( + auditResult.UserMessage, + auditResult.TechnicalMessage, + auditResult.Exception); + } + + transaction.Commit(); + return moveResult; + } } public DbResult DeleteStage( diff --git a/SIG.Web/Pages/Fraccionamientos/FraccionamientoDetalle.aspx b/SIG.Web/Pages/Fraccionamientos/FraccionamientoDetalle.aspx index 749e6d8..4610655 100644 --- a/SIG.Web/Pages/Fraccionamientos/FraccionamientoDetalle.aspx +++ b/SIG.Web/Pages/Fraccionamientos/FraccionamientoDetalle.aspx @@ -9,6 +9,9 @@ + @@ -216,6 +219,15 @@ CssClass="table table-hover Widthall" OnRowCommand="GvStages_RowCommand"> + + + + + + + - + + +