private void frmOccupationalHistory_Load(object sender, EventArgs e)
        {
            OperationResult objOperationResult = new OperationResult();
            HistoryBL       objHistoryBL       = new HistoryBL();

            LoadTreeDangers(145);
            LoadTreeEPP(146);

            dtpDateTimeStar.Value = dtpDateTimeStar.Value.AddMonths(-1);

            if (_Mode == "New")
            {
                // Additional logic here.
            }
            else if (_Mode == "Edit")
            {
                _objhistoryDto = new historyDto();

                _objhistoryDto = _objHistoryBL.GetHistory(ref objOperationResult, _HistoryId);

                dtpDateTimeStar.Value            = _objhistoryDto.d_StartDate.Value;
                dptDateTimeEnd.Value             = _objhistoryDto.d_EndDate.Value;
                txtOrganization.Text             = _objhistoryDto.v_Organization;
                txtTypeActivity.Text             = _objhistoryDto.v_TypeActivity;
                txtOccupation.Text               = _objhistoryDto.v_workstation;
                ddlTypeOperationId.SelectedValue = _objhistoryDto.i_TypeOperationId.ToString();
                txtGeographicalHeight.Text       = _objhistoryDto.i_GeografixcaHeight.ToString();

                _TempWorkstationDangersList = objHistoryBL.GetWorkstationDangersagedAndFiltered(ref objOperationResult, 0, null, "v_ParentName ASC", "", _HistoryId);
                grdDataDangers.DataSource   = _TempWorkstationDangersList;

                _TempTypeOfEEPList    = objHistoryBL.GetTypeOfEEPPagedAndFiltered(ref objOperationResult, 0, null, "v_TypeofEEPName ASC", "", _HistoryId);
                grdDataEPP.DataSource = _TempTypeOfEEPList;
            }
        }
        protected void btnSaveRefresh_Click(object sender, EventArgs e)
        {
            string Mode     = Request.QueryString["Mode"].ToString();
            string PersonId = "";

            if (Request.QueryString["v_PersonId"] != null)
            {
                PersonId = Request.QueryString["v_PersonId"].ToString();
            }

            OperationResult objOperationResult = new OperationResult();

            if (Mode == "New")
            {
                _objhistoryDto = new historyDto();

                _objhistoryDto.v_PersonId          = Session["PersonId"].ToString();
                _objhistoryDto.d_StartDate         = dtcFechaInicio.SelectedDate;
                _objhistoryDto.d_EndDate           = dtcFechaFin.SelectedDate;
                _objhistoryDto.v_Organization      = txtEmpresa.Text;
                _objhistoryDto.i_SoloAnio          = chkSoloAnio.Checked == true ? 1 : 0;
                _objhistoryDto.v_TypeActivity      = txtArea.Text;
                _objhistoryDto.v_workstation       = txtPuestoTrabajo.Text;
                _objhistoryDto.i_TrabajoActual     = chkPuestoActual.Checked == true ? 1 : 0;
                _objhistoryDto.i_TypeOperationId   = int.Parse(ddlTipoOperacion.SelectedValue.ToString());
                _objhistoryDto.i_GeografixcaHeight = txtAlturaGeografica.Text == "" ? 0 : int.Parse(txtAlturaGeografica.Text.ToString());

                _objHistoryBL.AddHistory(ref objOperationResult, _objhistoryDto, ((ClientSession)Session["objClientSession"]).GetAsList());
            }
            else if (Mode == "Edit")
            {
                historyDto objEntity = (historyDto)Session["objEntity"];

                objEntity.d_StartDate         = dtcFechaInicio.SelectedDate;
                objEntity.d_EndDate           = dtcFechaFin.SelectedDate;
                objEntity.v_Organization      = txtEmpresa.Text;
                objEntity.i_SoloAnio          = chkSoloAnio.Checked == true ? 1 : 0;
                objEntity.v_TypeActivity      = txtArea.Text;
                objEntity.v_workstation       = txtPuestoTrabajo.Text;
                objEntity.i_TrabajoActual     = chkPuestoActual.Checked == true ? 1 : 0;
                objEntity.i_TypeOperationId   = int.Parse(ddlTipoOperacion.SelectedValue.ToString());
                objEntity.i_GeografixcaHeight = txtAlturaGeografica.Text == "" ? 0 : int.Parse(txtAlturaGeografica.Text.ToString());

                _objHistoryBL.UpdateHistory(ref objOperationResult, objEntity, ((ClientSession)Session["objClientSession"]).GetAsList());
            }

            //Analizar el resultado de la operación
            if (objOperationResult.Success == 1)  // Operación sin error
            {
                // Cerrar página actual y hacer postback en el padre para actualizar
                PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference());
            }
            else  // Operación con error
            {
                Alert.ShowInTop("Error en operación:" + System.Environment.NewLine + objOperationResult.ExceptionMessage);
                // Se queda en el formulario.
            }
        }
        private void LoadData()
        {
            OperationResult objOperationResult = new OperationResult();
            string          Mode      = Request.QueryString["Mode"].ToString();
            string          HistoryId = "";

            if (Request.QueryString["v_HistoryId"] != null)
            {
                HistoryId = Request.QueryString["v_HistoryId"].ToString();
            }

            if (Mode == "New")
            {
                dtcFechaInicio.SelectedDate = DateTime.Now;
                dtcFechaFin.SelectedDate    = DateTime.Now;
                chkSoloAnio.Checked         = true;
                txtEmpresa.Text             = "";
                txtArea.Text                   = "";
                txtPuestoTrabajo.Text          = "";
                chkPuestoActual.Checked        = false;
                txtAlturaGeografica.Text       = "";
                ddlTipoOperacion.SelectedValue = "1";
            }
            else if (Mode == "Edit")
            {
                _objhistoryDto = new historyDto();

                _objhistoryDto = _objHistoryBL.GetHistory(ref objOperationResult, HistoryId);

                Session["objEntity"]        = _objhistoryDto;
                dtcFechaInicio.SelectedDate = _objhistoryDto.d_StartDate.Value;
                dtcFechaFin.SelectedDate    = _objhistoryDto.d_EndDate.Value;
                chkSoloAnio.Checked         = _objhistoryDto.i_SoloAnio == 1 ? true : false;
                txtEmpresa.Text             = _objhistoryDto.v_Organization;
                txtArea.Text                   = _objhistoryDto.v_TypeActivity;
                txtPuestoTrabajo.Text          = _objhistoryDto.v_workstation;
                ddlTipoOperacion.SelectedValue = _objhistoryDto.i_TypeOperationId.ToString();
                txtAlturaGeografica.Text       = _objhistoryDto.i_GeografixcaHeight == 0 ? "" : _objhistoryDto.i_GeografixcaHeight.ToString();

                if (_objhistoryDto.i_TrabajoActual != null)
                {
                    if (_objhistoryDto.i_TrabajoActual == 1)
                    {
                        chkPuestoActual.Checked = true;
                    }
                    else
                    {
                        chkPuestoActual.Checked = false;
                    }
                }
            }
        }
        private void frmOccupationalHistory_Load(object sender, EventArgs e)
        {
            #region Mayusculas - Normal
            var _EsMayuscula = int.Parse(Common.Utils.GetApplicationConfigValue("EsMayuscula"));
            if (_EsMayuscula == 1)
            {
                SearchControlAndSetEvents(this);
            }


            #endregion
            OperationResult objOperationResult = new OperationResult();
            HistoryBL       objHistoryBL       = new HistoryBL();

            LoadTreeDangers(145);
            LoadTreeEPP(146);

            dtpDateTimeStar.Value = dtpDateTimeStar.Value.AddMonths(-1);

            DateTime now = DateTime.Now;
            dtpDateTimeStar.Value = now.AddDays(1 - now.Day);

            DateTime now2 = DateTime.Now;
            dptDateTimeEnd.Value = now2.AddDays(1 - now2.Day);

            if (_Mode == "New")
            {
                // Additional logic here.
            }
            else if (_Mode == "Edit")
            {
                _objhistoryDto = new historyDto();

                _objhistoryDto = _objHistoryBL.GetHistory(ref objOperationResult, _HistoryId);

                dtpDateTimeStar.Value            = _objhistoryDto.d_StartDate.Value;
                dptDateTimeEnd.Value             = _objhistoryDto.d_EndDate.Value;
                txtOrganization.Text             = _objhistoryDto.v_Organization;
                txtTypeActivity.Text             = _objhistoryDto.v_TypeActivity;
                txtOccupation.Text               = _objhistoryDto.v_workstation;
                ddlTypeOperationId.SelectedValue = _objhistoryDto.i_TypeOperationId.ToString();
                txtGeographicalHeight.Text       = _objhistoryDto.i_GeografixcaHeight == 0 ? "" : _objhistoryDto.i_GeografixcaHeight.ToString();

                if (_objhistoryDto.i_TrabajoActual != null)
                {
                    if (_objhistoryDto.i_TrabajoActual == 1)
                    {
                        chkPuestoActual.Checked = true;
                    }
                    else
                    {
                        chkPuestoActual.Checked = false;
                    }
                }


                _TempWorkstationDangersList = objHistoryBL.GetWorkstationDangersagedAndFiltered(ref objOperationResult, 0, null, "v_ParentName ASC", "", _HistoryId);
                grdDataDangers.DataSource   = _TempWorkstationDangersList;

                _TempTypeOfEEPList    = objHistoryBL.GetTypeOfEEPPagedAndFiltered(ref objOperationResult, 0, null, "v_TypeofEEPName ASC", "", _HistoryId);
                grdDataEPP.DataSource = _TempTypeOfEEPList;
            }
        }
        private void btnSave_Click(object sender, EventArgs e)
        {
            OperationResult objOperationResult = new OperationResult();

            _workstationdangersListDto = new List <workstationdangersDto>();
            _typeofeepListDto          = new List <typeofeepDto>();

            _workstationdangersListDtoDelete = new List <workstationdangersDto>();
            _typeofeepListDtoDelete          = new List <typeofeepDto>();

            _typeofeepListUpdate             = new List <typeofeepDto>();
            _workstationdangersListDtoUpdate = new List <workstationdangersDto>();


            HistoryBL objHistoryBL = new HistoryBL();

            if (ultraValidator1.Validate(true, false).IsValid)
            {
                if (txtOrganization.Text.Trim() == string.Empty)
                {
                    MessageBox.Show("Por favor ingrese un nombre apropiado para Organización.", "Error de validación", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
                if (txtTypeActivity.Text.Trim() == string.Empty)
                {
                    MessageBox.Show("Por favor ingrese un nombre apropiado para Tipo de Actividad.", "Error de validación", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
                if (txtOccupation.Text.Trim() == string.Empty)
                {
                    MessageBox.Show("Por favor ingrese un nombre apropiado para Puesto de Trabajo.", "Error de validación", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
                //if (txtGeographicalHeight.Text.Trim() == string.Empty)
                //{
                //    MessageBox.Show("Por favor ingrese un nombre apropiado para Altura Geográfica", "Error de validación", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                //    return;
                //}
                if (_Mode == "New")
                {
                    _objhistoryDto = new historyDto();

                    _objhistoryDto.v_PersonId          = _PacientId;
                    _objhistoryDto.d_StartDate         = dtpDateTimeStar.Value.Date;
                    _objhistoryDto.d_EndDate           = dptDateTimeEnd.Value.Date;
                    _objhistoryDto.v_Organization      = txtOrganization.Text;
                    _objhistoryDto.v_TypeActivity      = txtTypeActivity.Text;
                    _objhistoryDto.v_workstation       = txtOccupation.Text;
                    _objhistoryDto.i_TrabajoActual     = chkPuestoActual.Checked == true? 1 :0;
                    _objhistoryDto.i_TypeOperationId   = int.Parse(ddlTypeOperationId.SelectedValue.ToString());
                    _objhistoryDto.i_GeografixcaHeight = txtGeographicalHeight.Text == "" ? 0 : int.Parse(txtGeographicalHeight.Text.ToString());

                    _HistoryId = objHistoryBL.AddHistory(ref objOperationResult, _TempWorkstationDangersList, _TempTypeOfEEPList, _objhistoryDto, Globals.ClientSession.GetAsList());
                }
                else if (_Mode == "Edit")
                {
                    _objhistoryDto.v_PersonId          = _PacientId;
                    _objhistoryDto.d_StartDate         = dtpDateTimeStar.Value.Date;
                    _objhistoryDto.d_EndDate           = dptDateTimeEnd.Value.Date;
                    _objhistoryDto.v_Organization      = txtOrganization.Text;
                    _objhistoryDto.v_TypeActivity      = txtTypeActivity.Text;
                    _objhistoryDto.v_workstation       = txtOccupation.Text;
                    _objhistoryDto.i_TrabajoActual     = chkPuestoActual.Checked == true ? 1 : 0;
                    _objhistoryDto.i_TypeOperationId   = int.Parse(ddlTypeOperationId.SelectedValue.ToString());
                    _objhistoryDto.i_GeografixcaHeight = txtGeographicalHeight.Text == "" ? 0 : int.Parse(txtGeographicalHeight.Text.ToString());

                    //Temporal Peligros
                    foreach (var item in _TempWorkstationDangersList)
                    {
                        //Add
                        if (item.i_RecordType == (int)RecordType.Temporal && item.i_RecordStatus == (int)RecordStatus.Agregado)
                        {
                            workstationdangersDto workstationdangersDto = new workstationdangersDto();

                            workstationdangersDto.i_DangerId = item.i_DangerId;

                            workstationdangersDto.v_TimeOfExposureToNoise = item.v_TimeOfExposureToNoise;
                            workstationdangersDto.i_NoiseLevel            = item.i_NoiseLevel;
                            workstationdangersDto.i_NoiseSource           = item.i_NoiseSource;

                            _workstationdangersListDto.Add(workstationdangersDto);
                        }

                        // Update
                        if (item.i_RecordType == (int)RecordType.NoTemporal && (item.i_RecordStatus == (int)RecordStatus.Modificado || item.i_RecordStatus == (int)RecordStatus.Grabado))
                        {
                            workstationdangersDto workstationdangersDto = new workstationdangersDto();
                            workstationdangersDto.v_WorkstationDangersId = item.v_WorkstationDangersId;
                            workstationdangersDto.i_DangerId             = item.i_DangerId;

                            workstationdangersDto.v_TimeOfExposureToNoise = item.v_TimeOfExposureToNoise;
                            workstationdangersDto.i_NoiseLevel            = item.i_NoiseLevel;
                            workstationdangersDto.i_NoiseSource           = item.i_NoiseSource;

                            _workstationdangersListDtoUpdate.Add(workstationdangersDto);
                        }

                        //Delete
                        if (item.i_RecordType == (int)RecordType.NoTemporal && item.i_RecordStatus == (int)RecordStatus.EliminadoLogico)
                        {
                            workstationdangersDto workstationdangersDto = new workstationdangersDto();
                            workstationdangersDto.v_WorkstationDangersId = item.v_WorkstationDangersId;
                            workstationdangersDto.i_DangerId             = item.i_DangerId;
                            _workstationdangersListDtoDelete.Add(workstationdangersDto);
                        }
                    }

                    //Temporal EPP

                    foreach (var item in _TempTypeOfEEPList)
                    {
                        //Add
                        if (item.i_RecordType == (int)RecordType.Temporal && item.i_RecordStatus == (int)RecordStatus.Agregado)
                        {
                            typeofeepDto typeofeepDto = new typeofeepDto();

                            typeofeepDto.i_TypeofEEPId = item.i_TypeofEEPId;
                            typeofeepDto.r_Percentage  = item.r_Percentage;

                            _typeofeepListDto.Add(typeofeepDto);
                        }

                        // Update
                        if (item.i_RecordType == (int)RecordType.NoTemporal && (item.i_RecordStatus == (int)RecordStatus.Modificado || item.i_RecordStatus == (int)RecordStatus.Grabado))
                        {
                            typeofeepDto typeofeepDto = new typeofeepDto();

                            typeofeepDto.v_TypeofEEPId = item.v_TypeofEEPId;
                            typeofeepDto.r_Percentage  = item.r_Percentage;
                            _typeofeepListUpdate.Add(typeofeepDto);
                        }

                        //Delete
                        if (item.i_RecordType == (int)RecordType.NoTemporal && item.i_RecordStatus == (int)RecordStatus.EliminadoLogico)
                        {
                            typeofeepDto typeofeepDto = new typeofeepDto();
                            typeofeepDto.v_TypeofEEPId = item.v_TypeofEEPId;
                            //typeofeepDto.i_TypeofEEPId = item.i_TypeofEEPId;

                            _typeofeepListDtoDelete.Add(typeofeepDto);
                        }
                    }

                    _objHistoryBL.UpdateHistory(ref objOperationResult,
                                                _workstationdangersListDto,
                                                _workstationdangersListDtoDelete,
                                                _workstationdangersListDtoUpdate,
                                                _typeofeepListDto,
                                                _typeofeepListUpdate,
                                                _typeofeepListDtoDelete,
                                                _objhistoryDto,
                                                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();
                }
                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.
                }
            }
            else
            {
                MessageBox.Show("Por favor corrija la información ingresada. Vea los indicadores de error.", "Error de validación", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }