private bool SaveMainEntity()
        {
            OperationResult objOperationResult = new OperationResult();
            movementDto     objmovementDto     = new movementDto();
            MovementBL      objMovementBL      = new MovementBL();

            _movementdetailListDto = new List <movementdetailDto>();
            bool booResult = false;

            if (_Mode == "New")
            {
                //Source
                objmovementDto.v_WarehouseId = ddlWarehouseSourceId.SelectedValue.ToString();

                //Destination
                objmovementDto.v_RemoteWarehouseId = ddlWarehouseDestinationId.SelectedValue.ToString();

                if (rbLocal.Checked)
                {
                    objmovementDto.i_MotiveTypeId  = 19; //EGRESO POR TRANSFERENCIA DE ALMACENES INTERNOS
                    objmovementDto.i_ProcessTypeId = (int)Common.ProcessType.LOCAL;
                }
                else if (rbRemote.Checked)
                {
                    objmovementDto.i_MotiveTypeId  = 20; //EGRESO POR TRANSFERENCIA DE ALMACENES EXTERNOS
                    objmovementDto.i_ProcessTypeId = (int)Common.ProcessType.REMOTO;
                }

                objmovementDto.d_Date               = dtpDate.Value;
                objmovementDto.i_MovementTypeId     = (int)Common.MovementType.EGRESO; // EGRESO DE ALMACÉN
                objmovementDto.v_ReferenceDocument  = txtDocReference.Text.Trim();
                objmovementDto.i_IsLocallyProcessed = (int)Common.SiNo.NO;             // El movimiento no está procesado aún Localmente
                objmovementDto.i_IsRemoteProcessed  = (int)Common.SiNo.NO;             // El movimiento no está procesado aún Remotamente

                if (_TempMovementDetailList == null || _TempMovementDetailList.Count == 0)
                {
                    _movementdetailListDto = null;
                    MessageBox.Show("El detalle no puede estar vacio.", "ERROR!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return(false);
                }

                foreach (var item in _TempMovementDetailList)
                {
                    movementdetailDto objmovementdetailDto = new movementdetailDto();

                    objmovementdetailDto.v_ProductId      = item.v_ProductId;
                    objmovementdetailDto.r_Quantity       = item.r_Quantity;
                    objmovementdetailDto.r_Price          = item.r_Price;
                    objmovementdetailDto.i_MovementTypeId = item.i_MovementTypeId;
                    _movementdetailListDto.Add(objmovementdetailDto);
                    objmovementDto.r_TotalQuantity = objmovementDto.r_TotalQuantity + item.r_Quantity;
                }

                _MovementId = objMovementBL.AddMovement(ref objOperationResult, objmovementDto, _movementdetailListDto, Globals.ClientSession.GetAsList());
            }
            else if (_Mode == "Edit")
            {
                objmovementDto.v_MovementId = _MovementId;
                //Source
                objmovementDto.v_WarehouseId = ddlWarehouseSourceId.SelectedValue.ToString();

                //Destination
                objmovementDto.v_RemoteWarehouseId = ddlWarehouseDestinationId.SelectedValue.ToString();

                if (rbLocal.Checked)
                {
                    objmovementDto.i_MotiveTypeId  = 19; //EGRESO POR TRANSFERENCIA DE ALMACENES INTERNOS
                    objmovementDto.i_ProcessTypeId = (int)Common.ProcessType.LOCAL;
                }
                else if (rbRemote.Checked)
                {
                    objmovementDto.i_MotiveTypeId  = 20; //EGRESO POR TRANSFERENCIA DE ALMACENES EXTERNOS
                    objmovementDto.i_ProcessTypeId = (int)Common.ProcessType.REMOTO;
                }
                objmovementDto.d_Date               = dtpDate.Value;
                objmovementDto.r_TotalQuantity      = 0;
                objmovementDto.i_MovementTypeId     = (int)Common.MovementType.EGRESO; // EGRESO DE ALMACÉN
                objmovementDto.v_ReferenceDocument  = txtDocReference.Text.Trim();
                objmovementDto.i_IsLocallyProcessed = (int)Common.SiNo.NO;;            // El movimiento no está procesado aún

                if (_TempMovementDetailList == null || _TempMovementDetailList.Count == 0)
                {
                    _movementdetailListDto = null;
                    MessageBox.Show("El detalle no puede estar vacio.", "ERROR!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return(false);
                }

                foreach (var item in _TempMovementDetailList)
                {
                    movementdetailDto objmovementdetailDto = new movementdetailDto();

                    objmovementdetailDto.v_ProductId      = item.v_ProductId;
                    objmovementdetailDto.r_Quantity       = item.r_Quantity;
                    objmovementdetailDto.r_Price          = item.r_Price;
                    objmovementdetailDto.i_MovementTypeId = item.i_MovementTypeId;
                    _movementdetailListDto.Add(objmovementdetailDto);
                    objmovementDto.r_TotalQuantity = objmovementDto.r_TotalQuantity + item.r_Quantity;
                }

                objMovementBL.UpdateMovement(ref objOperationResult, objmovementDto, _movementdetailListDto, Globals.ClientSession.GetAsList());
            }

            //// Analizar el resultado de la operación
            if (objOperationResult.Success == 1)  // Operación sin error
            {
                this.DialogResult = System.Windows.Forms.DialogResult.OK;
                this.Close();
                booResult = true;
            }
            else  // Operación con error
            {
                MessageBox.Show("Error en operación:" + System.Environment.NewLine + objOperationResult.ExceptionMessage, "ERROR!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                // Se queda en el formulario.
                booResult = false;
            }
            return(booResult);
        }
Exemplo n.º 2
0
        private bool SaveMainEntity()
        {
            OperationResult objOperationResult = new OperationResult();
            movementDto     objmovementDto     = new movementDto();
            MovementBL      objMovementBL      = new MovementBL();

            _movementdetailListDto = new List <movementdetailDto>();
            bool booResult = false;

            //if (uvWarehouseOutPut.Validate(true, false).IsValid)
            //{
            if (_Mode == "New")
            {
                objmovementDto.i_MotiveTypeId = int.Parse(ddlMotiveId.SelectedValue.ToString());

                objmovementDto.d_Date               = dtpDate.Value;
                objmovementDto.v_WarehouseId        = _WarehouseId;
                objmovementDto.v_ReferenceDocument  = txtDocReference.Text.Trim();
                objmovementDto.i_IsLocallyProcessed = (int)Common.SiNo.NO;;            // El movimiento no está procesado aún
                objmovementDto.i_ProcessTypeId      = (int)Common.ProcessType.LOCAL;   // Procesado Localmente
                objmovementDto.i_MovementTypeId     = (int)Common.MovementType.EGRESO; // EGRESO DE ALMACÉN
                objmovementDto.r_TotalQuantity      = 0;
                if (_TempMovementDetailList == null || _TempMovementDetailList.Count == 0)
                {
                    _movementdetailListDto = null;
                    MessageBox.Show("El detalle no puede estar vacio.", "ERROR!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return(false);
                }

                foreach (var item in _TempMovementDetailList)
                {
                    movementdetailDto objmovementdetailDto = new movementdetailDto();

                    objmovementdetailDto.v_ProductId      = item.v_ProductId;
                    objmovementdetailDto.r_Quantity       = item.r_Quantity;
                    objmovementdetailDto.r_Price          = item.r_Price;
                    objmovementdetailDto.i_MovementTypeId = item.i_MovementTypeId;
                    _movementdetailListDto.Add(objmovementdetailDto);
                    objmovementDto.r_TotalQuantity = objmovementDto.r_TotalQuantity + item.r_Quantity;
                }

                _MovementId = objMovementBL.AddMovement(ref objOperationResult, objmovementDto, _movementdetailListDto, Globals.ClientSession.GetAsList());
            }
            else if (_Mode == "Edit")
            {
                objmovementDto.v_MovementId   = _MovementId;
                objmovementDto.i_MotiveTypeId = int.Parse(ddlMotiveId.SelectedValue.ToString());

                objmovementDto.d_Date               = dtpDate.Value;
                objmovementDto.v_WarehouseId        = _WarehouseId;
                objmovementDto.v_ReferenceDocument  = txtDocReference.Text.Trim();
                objmovementDto.i_IsLocallyProcessed = (int)Common.SiNo.NO;;            // El movimiento no está procesado aún
                objmovementDto.i_ProcessTypeId      = (int)Common.ProcessType.LOCAL;   // Procesado Localmente
                objmovementDto.i_MovementTypeId     = (int)Common.MovementType.EGRESO; // EGRESO DE ALMACÉN
                objmovementDto.r_TotalQuantity      = 0;
                if (_TempMovementDetailList == null || _TempMovementDetailList.Count == 0)
                {
                    _movementdetailListDto = null;
                    MessageBox.Show("El detalle no puede estar vacio.", "ERROR!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return(false);
                }

                foreach (var item in _TempMovementDetailList)
                {
                    movementdetailDto objmovementdetailDto = new movementdetailDto();

                    objmovementdetailDto.v_ProductId      = item.v_ProductId;
                    objmovementdetailDto.r_Quantity       = item.r_Quantity;
                    objmovementdetailDto.r_Price          = item.r_Price;
                    objmovementdetailDto.i_MovementTypeId = item.i_MovementTypeId;
                    _movementdetailListDto.Add(objmovementdetailDto);
                    objmovementDto.r_TotalQuantity = objmovementDto.r_TotalQuantity + item.r_Quantity;
                }
                objMovementBL.UpdateMovement(ref objOperationResult, objmovementDto, _movementdetailListDto, Globals.ClientSession.GetAsList());
            }
            //// Analizar el resultado de la operación
            if (objOperationResult.Success == 1)      // Operación sin error
            {
                this.DialogResult = System.Windows.Forms.DialogResult.OK;
                this.Close();
                booResult = true;
            }
            else      // Operación con error
            {
                MessageBox.Show("Error en operación:" + System.Environment.NewLine + objOperationResult.ExceptionMessage, "ERROR!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                // Se queda en el formulario.
                booResult = false;
            }
            //}
            //else
            //{
            //    MessageBox.Show("Por favor corrija la información ingresada. Vea los indicadores de error.", "Error de validación", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            //}
            return(booResult);
        }