private void LoadData()
        {
            OperationResult objOperationResult = new OperationResult();

            var objData1 = BLL.Utils.GetSystemParameterForCombo(ref objOperationResult, 110, "");  // Motivos de Ingreso
            // Remover el elemento TRANSFERENCIA ENTRE ALMACENES
            var objData1List = objData1.ToList();

            objData1List.RemoveAll(item => Int32.Parse(item.Id) < 11);
            objData1List.RemoveAll(item => Int32.Parse(item.Id) > 18);
            //// Llenar el combo de Motivos
            Utils.LoadDropDownList(ddlMotiveId, "Value1", "Id", objData1List, DropDownListAction.Select);
            Utils.LoadDropDownList(ddlProductId, "Value1", "Id", BLL.Utils.GetProductWarehouse(ref objOperationResult, "Value2==" + "\"" + _WarehouseId + "\""), DropDownListAction.Select);
            if (_Mode == "New")
            {
                txtIsProcessed.Text  = "NO";
                txtDocReference.Text = "";
                dtpDate.Value        = DateTime.Now.Date;
                _booAlreadySaved     = false;
            }
            else if (_Mode == "Edit")
            {
                // Get the Entity Data

                movementDto objMovementDto = new movementDto();
                MovementBL  objMovementBL  = new MovementBL();

                movementdetailDto objmovementdetailDto = new movementdetailDto();

                supplierDto objSupplierDto = new supplierDto();
                SupplierBL  objSupplierBL  = new SupplierBL();

                string pstrFilterExpression = null;

                objMovementDto = objMovementBL.GetMovement(ref objOperationResult, _MovementId);

                ddlMotiveId.SelectedValue = objMovementDto.i_MotiveTypeId.ToString();
                txtDocReference.Text      = objMovementDto.v_ReferenceDocument;
                dtpDate.Value             = (DateTime)objMovementDto.d_Date;
                if (objMovementDto.i_IsLocallyProcessed == (int)Common.SiNo.NO)
                {
                    txtIsProcessed.Text       = "NO";
                    btnSaveRefresh.Enabled    = true;
                    btnConfirmProcess.Enabled = true;
                    btnDiscardProcess.Enabled = true;
                }
                else
                {
                    txtIsProcessed.Text       = "SI";
                    btnSaveRefresh.Enabled    = false;
                    btnConfirmProcess.Enabled = false;
                    btnDiscardProcess.Enabled = false;
                    groupBox1.Enabled         = false;
                    groupBox2.Enabled         = false;
                }

                pstrFilterExpression    = "v_MovementId==" + "\"" + objMovementDto.v_MovementId + "\"" + "&&" + "v_WarehouseId==" + "\"" + objMovementDto.v_WarehouseId + "\"";
                _TempMovementDetailList = objMovementBL.GetMovementDeatilPagedAndFiltered(ref objOperationResult, 0, null, "", pstrFilterExpression);
                lblRecordCount.Text     = string.Format("Se encontraron {0} registros.", _TempMovementDetailList.Count());

                grdData.DataSource = _TempMovementDetailList;
                _booAlreadySaved   = true;
            }
        }
        private void LoadData()
        {
            OperationResult objOperationResult = new OperationResult();

            Utils.LoadDropDownList(ddlProductId, "Value1", "Id", BLL.Utils.GetProductWarehouse(ref objOperationResult, "Id==" + "\"" + -1 + "\""), DropDownListAction.Select); // el combo producto se carga vacio hasta que se seleccione un almacén de origen.
            lblNodeSource.Text   = Globals.ClientSession.v_CurrentExecutionNodeName;
            dtpDate.CustomFormat = "dd/MM/yyyy";
            if (_Mode == "New")
            {
                _booAlreadySaved = false;
                //Source
                Utils.LoadDropDownList(ddlOrganizationLocationSourceId, "Value1", "Id", BLL.Utils.GetJoinOrganizationAndLocationNotInRestricted(ref objOperationResult, Globals.ClientSession.i_CurrentExecutionNodeId), DropDownListAction.Select);
                Utils.LoadDropDownList(ddlWarehouseSourceId, "Value1", "Id", BLL.Utils.GetWarehouseNotInRestricted(ref objOperationResult, Globals.ClientSession.i_CurrentExecutionNodeId, "-1", "-1"), DropDownListAction.Select);

                //Destination
                Utils.LoadDropDownList(ddlNodeDestinationId, "Value1", "Id", BLL.Utils.GetAllNodeForCombo(ref objOperationResult), DropDownListAction.Select);
                if (rbLocal.Checked == true)
                {
                    ddlNodeDestinationId.Enabled       = false;
                    ddlNodeDestinationId.SelectedValue = Globals.ClientSession.i_CurrentExecutionNodeId.ToString();
                }
                else
                {
                    ddlNodeDestinationId.Enabled = true;
                }

                Utils.LoadDropDownList(ddlOrganizationLocationDestinationId, "Value1", "Id", BLL.Utils.GetJoinOrganizationAndLocationNotInRestricted(ref objOperationResult, Globals.ClientSession.i_CurrentExecutionNodeId), DropDownListAction.Select);
                Utils.LoadDropDownList(ddlWarehouseDestinationId, "Value1", "Id", BLL.Utils.GetWarehouseNotInRestricted(ref objOperationResult, Globals.ClientSession.i_CurrentExecutionNodeId, "-1", "-1"), DropDownListAction.Select);

                txtIsProcessed.Text  = "NO";
                txtDocReference.Text = "";
                dtpDate.Value        = DateTime.Now.Date;
            }
            else if (_Mode == "Edit")
            {
                // Get the Entity Data

                warehouseDto objwarehouseDto = new warehouseDto();
                WarehouseBL  objWarehouseBL  = new WarehouseBL();

                movementDto objMovementDto = new movementDto();
                MovementBL  objMovementBL  = new MovementBL();

                movementdetailDto objmovementdetailDto = new movementdetailDto();

                supplierDto objSupplierDto = new supplierDto();
                SupplierBL  objSupplierBL  = new SupplierBL();

                nodeorganizationlocationwarehouseprofileDto objnodeorganizationlocationwarehouseprofileDto = new nodeorganizationlocationwarehouseprofileDto();
                NodeBL objNodeBL = new NodeBL();
                _booAlreadySaved = true;
                string pstrFilterExpression = null;

                objMovementDto = objMovementBL.GetMovement(ref objOperationResult, _MovementId);

                //Source
                Utils.LoadDropDownList(ddlOrganizationLocationSourceId, "Value1", "Id", BLL.Utils.GetJoinOrganizationAndLocationNotInRestricted(ref objOperationResult, Globals.ClientSession.i_CurrentExecutionNodeId), DropDownListAction.Select);
                objwarehouseDto = objWarehouseBL.GetWarehouse(ref objOperationResult, objMovementDto.v_WarehouseId);
                ddlOrganizationLocationSourceId.SelectedValue = Globals.ClientSession.i_CurrentExecutionNodeId + "|" + objwarehouseDto.v_OrganizationId + "|" + objwarehouseDto.v_LocationId;
                ddlWarehouseSourceId.SelectedValue            = objwarehouseDto.v_WarehouseId;

                //Destination
                Utils.LoadDropDownList(ddlNodeDestinationId, "Value1", "Id", BLL.Utils.GetAllNodeForCombo(ref objOperationResult), DropDownListAction.Select);

                objnodeorganizationlocationwarehouseprofileDto = objNodeBL.GetNodeOrganizationLocationWarehouseProfile(ref objOperationResult, objMovementDto.v_RemoteWarehouseId);

                if (Globals.ClientSession.i_CurrentExecutionNodeId.ToString() == objnodeorganizationlocationwarehouseprofileDto.i_NodeId.ToString())
                {
                    ddlNodeDestinationId.Enabled = false;
                    rbLocal.Checked = true;
                }
                else
                {
                    ddlNodeDestinationId.Enabled = true;
                    rbRemote.Checked             = true;
                }

                ddlNodeDestinationId.SelectedValue = objnodeorganizationlocationwarehouseprofileDto.i_NodeId.ToString();
                ddlOrganizationLocationDestinationId.SelectedValue = objnodeorganizationlocationwarehouseprofileDto.i_NodeId.ToString() + "|" + objnodeorganizationlocationwarehouseprofileDto.v_OrganizationId + "|" + objnodeorganizationlocationwarehouseprofileDto.v_LocationId;
                ddlWarehouseDestinationId.SelectedValue            = objMovementDto.v_RemoteWarehouseId;
                txtDocReference.Text = objMovementDto.v_ReferenceDocument;
                dtpDate.Value        = (DateTime)objMovementDto.d_Date;
                if (objMovementDto.i_IsLocallyProcessed == (int)Common.SiNo.NO)
                {
                    txtIsProcessed.Text       = "NO";
                    btnSaveRefresh.Enabled    = true;
                    btnConfirmProcess.Enabled = true;
                    btnDiscardProcess.Enabled = true;
                }
                else
                {
                    txtIsProcessed.Text       = "SI";
                    btnSaveRefresh.Enabled    = false;
                    btnConfirmProcess.Enabled = false;
                    btnDiscardProcess.Enabled = false;
                }

                pstrFilterExpression    = "v_MovementId==" + "\"" + objMovementDto.v_MovementId + "\"" + "&&" + "v_WarehouseId==" + "\"" + objMovementDto.v_WarehouseId + "\"";
                _TempMovementDetailList = objMovementBL.GetMovementDeatilPagedAndFiltered(ref objOperationResult, 0, null, "", pstrFilterExpression);
                lblRecordCount.Text     = string.Format("Se encontraron {0} registros.", _TempMovementDetailList.Count());

                grdData.DataSource = _TempMovementDetailList;
            }
        }
        private bool SaveMainEntity()
        {
            OperationResult objOperationResult = new OperationResult();
            movementDto     objmovementDto     = new movementDto();
            MovementBL      objMovementBL      = new MovementBL();

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

            //if (uvWarehouseInput.Validate(true, false).IsValid)
            //{
            if (_Mode == "New")
            {
                objmovementDto.i_MotiveTypeId       = Int32.Parse(ddlMotiveId.SelectedValue.ToString());
                objmovementDto.v_SupplierId         = _SupplierId;
                objmovementDto.d_Date               = dtpDate.Value;
                objmovementDto.v_WarehouseId        = _WarehouseId;
                objmovementDto.v_ReferenceDocument  = txtDocReference.Text.Trim();;
                objmovementDto.i_IsLocallyProcessed = (int)Common.SiNo.NO;              //El movimiento inicia como no procesado
                objmovementDto.i_ProcessTypeId      = (int)Common.ProcessType.LOCAL;    // Procesado Localmente
                objmovementDto.i_MovementTypeId     = (int)Common.MovementType.INGRESO; //(Ingreso, Egreso)
                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);
                }
                else
                {
                    foreach (var item in _TempMovementDetailList)
                    {
                        movementdetailDto objmovementdetailDto = new movementdetailDto();

                        objmovementdetailDto.i_MovementTypeId = item.i_MovementTypeId;
                        objmovementdetailDto.r_Quantity       = item.r_Quantity;
                        objmovementdetailDto.r_Price          = item.r_Price;
                        objmovementdetailDto.v_ProductId      = item.v_ProductId;
                        _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 = objMovementBL.GetMovement(ref objOperationResult, _MovementId);

                objmovementDto.v_MovementId         = _MovementId;
                objmovementDto.i_MotiveTypeId       = Int32.Parse(ddlMotiveId.SelectedValue.ToString());
                objmovementDto.v_SupplierId         = _SupplierId;
                objmovementDto.d_Date               = dtpDate.Value;
                objmovementDto.v_WarehouseId        = _WarehouseId;
                objmovementDto.v_ReferenceDocument  = txtDocReference.Text;
                objmovementDto.i_IsLocallyProcessed = (int)Common.SiNo.NO;              //El movimiento inicia como no procesado
                objmovementDto.i_ProcessTypeId      = (int)Common.ProcessType.LOCAL;    // Procesado Localmente
                objmovementDto.i_MovementTypeId     = (int)Common.MovementType.INGRESO; //(Ingreso, Egreso)

                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.i_MovementTypeId = item.i_MovementTypeId;
                    objmovementdetailDto.r_Quantity       = item.r_Quantity;
                    objmovementdetailDto.r_Price          = item.r_Price;
                    objmovementdetailDto.v_ProductId      = item.v_ProductId;
                    _movementdetailListDto.Add(objmovementdetailDto);
                }
                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);
            //    booResult = false;
            //}

            return(booResult);
        }