private void RefreshTmpRecomendationList(List <RecomendationList> precomendations)
        {
            _tmpRecomendationList = new List <RecomendationList>();

            if (precomendations == null)
            {
                return;
            }

            foreach (var item in precomendations)
            {
                // Agregar restricciones a la Lista mas lo que ya tiene
                RecomendationList recomendation = new RecomendationList();

                recomendation.v_RecommendationId       = item.v_RecommendationId;
                recomendation.v_ComponentId            = item.v_ComponentId;
                recomendation.v_DiagnosticRepositoryId = item.v_DiagnosticRepositoryId;
                recomendation.v_MasterRecommendationId = item.v_MasterRecommendationId;
                recomendation.v_RecommendationName     = item.v_RecommendationName;
                recomendation.i_RecordStatus           = item.i_RecordStatus;
                recomendation.i_RecordType             = item.i_RecordType;
                recomendation.v_ServiceId = item.v_ServiceId;

                _tmpRecomendationList.Add(recomendation);
            }
        }
        private void btnAgregarRecomendaciones_Click(object sender, EventArgs e)
        {
            var frm = new frmMasterRecommendationRestricction("Recomendaciones", (int)Typifying.Recomendaciones, ModeOperation.Total);

            frm.ShowDialog();

            if (_tmpRecomendationList == null)
            {
                _tmpRecomendationList = new List <RecomendationList>();
            }

            var recomendationId    = frm._masterRecommendationRestricctionId;
            var recommendationName = frm._masterRecommendationRestricctionName;

            if (recomendationId != null && recommendationName != null)
            {
                var recomendation = _tmpRecomendationList.Find(p => p.v_RecommendationId == recomendationId);

                if (recomendation == null)   // agregar con normalidad [insert]  a la bolsa
                {
                    // Agregar restricciones a la Lista
                    RecomendationList recomendationList = new RecomendationList();

                    recomendationList.v_RecommendationId       = Guid.NewGuid().ToString();
                    recomendationList.v_DiagnosticRepositoryId = Guid.NewGuid().ToString();
                    recomendationList.v_MasterRecommendationId = recomendationId;
                    recomendationList.v_ServiceId          = _serviceId;
                    recomendationList.v_ComponentId        = _componentId;
                    recomendationList.v_RecommendationName = recommendationName;
                    recomendationList.i_RecordStatus       = (int)RecordStatus.Agregado;
                    recomendationList.i_RecordType         = (int)RecordType.Temporal;
                    recomendationList.v_ComponentId        = _componentIds[0];

                    _tmpRecomendationList.Add(recomendationList);
                }
                else    // La restriccion ya esta agregado en la bolsa hay que actualizar su estado
                {
                    MessageBox.Show("Por favor seleccione otra Recomendación. ya existe", "Error de validación", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
            }

            // Cargar grilla
            grdRecomendaciones.DataSource = new RecomendationList();
            grdRecomendaciones.DataSource = _tmpRecomendationList;
            grdRecomendaciones.Refresh();
            lblRecordCountRecomendaciones_AnalisisDx.Text = string.Format("Se encontraron {0} registros.", _tmpRecomendationList.Count());
        }
        private void btnRecomendaciones_Click(object sender, EventArgs e)
        {
            var frm = new frmMasterRecommendationRestricction("Recomendaciones", (int)Typifying.Recomendaciones, ModeOperation.Total);

            frm.ShowDialog();

            if (_tmpExamDiagnosticComponentList == null)
            {
                _tmpExamDiagnosticComponentList = new List <DiagnosticRepositoryList>();
            }

            if (_tmpRecomendationList == null)
            {
                _tmpRecomendationList = new List <RecomendationList>();
            }

            var recomendationId    = frm._masterRecommendationRestricctionId;
            var recommendationName = frm._masterRecommendationRestricctionName;

            if (recomendationId != null && recommendationName != null)
            {
                var recomendation = _tmpRecomendationList.Find(p => p.v_MasterRecommendationId == recomendationId);

                if (_mode == "New" || _mode == "Edit")
                {
                    if (recomendation == null)   // agregar con normalidad [insert]  a la bolsa
                    {
                        // Agregar restricciones a la Lista
                        RecomendationList recomendationList = new RecomendationList();

                        recomendationList.v_RecommendationId       = Guid.NewGuid().ToString();
                        recomendationList.v_DiagnosticRepositoryId = Guid.NewGuid().ToString();
                        recomendationList.v_MasterRecommendationId = recomendationId;
                        recomendationList.v_ServiceId          = _serviceId;
                        recomendationList.v_ComponentId        = ddlComponentId.SelectedValue.ToString(); //_componentId;
                        recomendationList.v_RecommendationName = recommendationName;
                        recomendationList.i_RecordStatus       = (int)RecordStatus.Agregado;
                        recomendationList.i_RecordType         = (int)RecordType.Temporal;

                        _tmpRecomendationList.Add(recomendationList);
                    }
                    else    // La restriccion ya esta agregado en la bolsa hay que actualizar su estado
                    {
                        if (recomendation.i_RecordStatus == (int)RecordStatus.EliminadoLogico)
                        {
                            if (recomendation.i_RecordType == (int)RecordType.NoTemporal)   // El registro Tiene in ID de BD
                            {
                                recomendation.v_MasterRecommendationId = recomendationId;
                                recomendation.v_RecommendationName     = recommendationName;
                                recomendation.i_RecordStatus           = (int)RecordStatus.Grabado;
                            }
                            else if (recomendation.i_RecordType == (int)RecordType.Temporal)   // El registro tiene un ID temporal [GUID]
                            {
                                recomendation.v_MasterRecommendationId = recomendationId;
                                recomendation.v_RecommendationName     = recommendationName;
                                recomendation.i_RecordStatus           = (int)RecordStatus.Agregado;
                            }
                        }
                        else
                        {
                            MessageBox.Show("Por favor seleccione otra Recomendación. ya existe", "Error de validación", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            return;
                        }
                    }
                }
            }

            var dataList = _tmpRecomendationList.FindAll(p => p.i_RecordStatus != (int)RecordStatus.EliminadoLogico);

            // Cargar grilla
            grdRecomendaciones.DataSource = new RecomendationList();
            grdRecomendaciones.DataSource = dataList;
            grdRecomendaciones.Refresh();
            lblRecordCountRecomendaciones.Text = string.Format("Se encontraron {0} registros.", dataList.Count());
        }
        private void grdData_DoubleClick(object sender, EventArgs e)
        {
            //if (ddlComponentId.SelectedValue.ToString() == "-1")
            //{
            //    MessageBox.Show("Por favor seleccione un examen", "Error de validación", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            //    return;
            //}
            var x = (KeyValueDTO)ddlComponentId.SelectedItem;


            if (x.Value4 == 0.0)
            {
                MessageBox.Show("Por favor seleccione un consultorio", "Error de validación", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            if (cboExamen.SelectedValue == null)
            {
                MessageBox.Show("Por favor seleccione un Examen", "Error de validación", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            lblDiagnostico.Text             = "";
            _tmpRecomendationList           = new List <RecomendationList>();
            _tmpRestrictionByDiagnosticList = new List <RestrictionList>();

            var Filtro = _TempListaDxfrecuentes.Find(p => p.v_DxFrecuenteId == _DxFrecuenteId);

            lblDiagnostico.Text = Filtro.v_DiseasesName + " / " + Filtro.v_CIE10Id;
            _diagnosticId       = Filtro.v_DiseasesId;

            var Recomendaciones = Filtro.DxFrecuenteDetalle.FindAll(p => p.i_Tipo != 2);

            foreach (var item in Recomendaciones)
            {
                if (_tmpRecomendationList == null)
                {
                    _tmpRecomendationList = new List <RecomendationList>();
                }

                var recomendation = _tmpRecomendationList.Find(p => p.v_MasterRecommendationId == item.v_MasterRecommendationRestricctionId);

                if (recomendation == null)   // agregar con normalidad [insert]  a la bolsa
                {
                    RecomendationList recomendationList = new RecomendationList();

                    recomendationList.v_RecommendationId       = Guid.NewGuid().ToString();
                    recomendationList.v_DiagnosticRepositoryId = Guid.NewGuid().ToString();
                    recomendationList.v_MasterRecommendationId = item.v_MasterRecommendationRestricctionId;
                    recomendationList.v_ServiceId = _serviceId;
                    //recomendationList.v_ComponentId = _componentIds[0];
                    recomendationList.v_ComponentId = _examenId;
                    //recomendationList.v_ComponentId = ddlComponentId.SelectedValue.ToString(); //_componentId;
                    recomendationList.v_RecommendationName = item.v_RecomendacionName;
                    recomendationList.i_RecordStatus       = (int)RecordStatus.Agregado;
                    recomendationList.i_RecordType         = (int)RecordType.Temporal;

                    _tmpRecomendationList.Add(recomendationList);
                }
            }

            var dataListReco = _tmpRecomendationList.FindAll(p => p.i_RecordStatus != (int)RecordStatus.EliminadoLogico);

            // Cargar grilla
            grdRecomendaciones.DataSource = new RecomendationList();
            grdRecomendaciones.DataSource = dataListReco;
            grdRecomendaciones.Refresh();
            lblRecordCountRecomendaciones_AnalisisDx.Text = string.Format("Se encontraron {0} registros.", dataListReco.Count());


            var Restricciones = Filtro.DxFrecuenteDetalle.FindAll(p => p.i_Tipo != 1);

            foreach (var item in Restricciones)
            {
                if (_tmpRestrictionByDiagnosticList == null)
                {
                    _tmpRestrictionByDiagnosticList = new List <RestrictionList>();
                }
                var restriction = _tmpRestrictionByDiagnosticList.Find(p => p.v_MasterRestrictionId == item.v_MasterRecommendationRestricctionId);

                if (restriction == null)   // agregar con normalidad [insert]  a la bolsa
                {
                    RestrictionList restrictionByDiagnostic = new RestrictionList();
                    restrictionByDiagnostic.v_RestrictionByDiagnosticId = Guid.NewGuid().ToString();
                    restrictionByDiagnostic.v_DiagnosticRepositoryId    = Guid.NewGuid().ToString();
                    restrictionByDiagnostic.v_MasterRestrictionId       = item.v_MasterRecommendationRestricctionId;
                    restrictionByDiagnostic.v_ServiceId = _serviceId;
                    //restrictionByDiagnostic.v_ComponentId = _componentIds[0];
                    restrictionByDiagnostic.v_ComponentId = _examenId;
                    //restrictionByDiagnostic.v_ComponentId = ddlComponentId.SelectedValue.ToString(); // _componentId;
                    restrictionByDiagnostic.v_RestrictionName = item.v_RestriccionName;
                    restrictionByDiagnostic.i_RecordStatus    = (int)RecordStatus.Agregado;
                    restrictionByDiagnostic.i_RecordType      = (int)RecordType.Temporal;

                    _tmpRestrictionByDiagnosticList.Add(restrictionByDiagnostic);
                }
            }


            var dataListRest = _tmpRestrictionByDiagnosticList.FindAll(p => p.i_RecordStatus != (int)RecordStatus.EliminadoLogico);

            // Cargar grilla
            grdRestricciones.DataSource = new RestrictionList();
            grdRestricciones.DataSource = dataListRest;
            grdRestricciones.Refresh();
            lblRecordCountRestricciones_AnalisisDx.Text = string.Format("Se encontraron {0} registros.", dataListRest.Count());
        }