Ejemplo n.º 1
0
        public componentDto GetMedicalExam(ref OperationResult pobjOperationResult, string pstrMedicalExamId)
        {
            //mon.IsActive = true;

            try
            {
                SigesoftEntitiesModel dbContext    = new SigesoftEntitiesModel();
                componentDto          objDtoEntity = null;

                var objEntity = (from a in dbContext.component
                                 where a.v_ComponentId == pstrMedicalExamId
                                 select a).FirstOrDefault();

                if (objEntity != null)
                {
                    objDtoEntity = componentAssembler.ToDTO(objEntity);
                }

                pobjOperationResult.Success = 1;
                return(objDtoEntity);
            }
            catch (Exception ex)
            {
                pobjOperationResult.Success          = 0;
                pobjOperationResult.ExceptionMessage = Common.Utils.ExceptionFormatter(ex);
                return(null);
            }
        }
Ejemplo n.º 2
0
        public void AddMedicalExam(ref OperationResult pobjOperationResult, componentDto pobjDtoEntity, List <string> ClientSession)
        {
            //mon.IsActive = true;
            string NewId = "(No generado)";

            try
            {
                SigesoftEntitiesModel dbContext = new SigesoftEntitiesModel();
                component             objEntity = componentAssembler.ToEntity(pobjDtoEntity);

                //var query = from A in dbContext.component

                var Result = (from A in dbContext.component
                              where A.i_IsDeleted == 0 && A.v_Name == pobjDtoEntity.v_Name
                              select A).FirstOrDefault();
                if (Result != null)
                {
                    pobjOperationResult.ErrorMessage = "El nombre ya se encuentra registrado";
                    pobjOperationResult.Success      = 0;
                    return;
                }

                objEntity.d_InsertDate   = DateTime.Now;
                objEntity.i_InsertUserId = Int32.Parse(ClientSession[2]);
                objEntity.i_IsDeleted    = 0;
                // Autogeneramos el Pk de la tabla
                int intNodeId = int.Parse(ClientSession[0]);
                NewId = Common.Utils.GetNewId(intNodeId, Utils.GetNextSecuentialId(intNodeId, 17), "ME");
                objEntity.v_ComponentId = NewId;


                dbContext.AddTocomponent(objEntity);
                dbContext.SaveChanges();

                pobjOperationResult.Success = 1;
                // Llenar entidad Log
                LogBL.SaveLog(ClientSession[0], ClientSession[1], ClientSession[2], LogEventType.CREACION, "EXAMEN MÉDICO", "v_MedicalExamId=" + NewId.ToString(), Success.Ok, null);
                return;
            }
            catch (Exception ex)
            {
                pobjOperationResult.Success          = 0;
                pobjOperationResult.ExceptionMessage = Common.Utils.ExceptionFormatter(ex);
                // Llenar entidad Log
                LogBL.SaveLog(ClientSession[0], ClientSession[1], ClientSession[2], LogEventType.CREACION, "EXAMEN MÉDICO", "v_MedicalExamId=" + NewId.ToString(), Success.Failed, pobjOperationResult.ExceptionMessage);
                return;
            }
        }
        private void frmMedicalExamEdicion_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();

            //Llenado de combos
            Utils.LoadComboTreeBoxList(ddlCategoryId, BLL.Utils.GetSystemParameterForComboTreeBox(ref objOperationResult, 116, null), DropDownListAction.Select);
            Utils.LoadDropDownList(ddlDiagnosableId, "Value1", "Id", BLL.Utils.GetSystemParameterForCombo(ref objOperationResult, 111, null), DropDownListAction.Select);
            Utils.LoadDropDownList(ddlComponentTypeId, "Value1", "Id", BLL.Utils.GetSystemParameterForCombo(ref objOperationResult, 126, null), DropDownListAction.Select);
            Utils.LoadDropDownList(ddlUIIsVisibleId, "Value1", "Id", BLL.Utils.GetSystemParameterForCombo(ref objOperationResult, 111, null), DropDownListAction.Select);
            Utils.LoadDropDownList(ddlIsApprovedId, "Value1", "Id", BLL.Utils.GetSystemParameterForCombo(ref objOperationResult, 111, null), DropDownListAction.Select);

            if (Mode == "New")
            {
                // Additional logic here.
            }
            else if (Mode == "Edit")
            {
                // Get the Entity Data
                objmedicalexamDto = new componentDto();

                objmedicalexamDto = _objMedicalExamBL.GetMedicalExam(ref objOperationResult, MedicalExamId);

                txtInsertName.Text = objmedicalexamDto.v_Name;
                _NameComponentOld  = objmedicalexamDto.v_Name;

                ComboTreeNode nodoABuscar = ddlCategoryId.AllNodes.First(x => x.Tag.ToString() == objmedicalexamDto.i_CategoryId.ToString());
                ddlCategoryId.SelectedNode = nodoABuscar;

                unBasePrice.Text = objmedicalexamDto.r_BasePrice.ToString();
                ddlDiagnosableId.SelectedValue   = objmedicalexamDto.i_DiagnosableId.ToString();
                ddlComponentTypeId.SelectedValue = objmedicalexamDto.i_ComponentTypeId.ToString();

                ddlUIIsVisibleId.SelectedValue = objmedicalexamDto.i_UIIsVisibleId.ToString();
                unUIIndex.Value = objmedicalexamDto.i_UIIndex;

                ddlIsApprovedId.SelectedValue = objmedicalexamDto.i_IsApprovedId.ToString();
                unValidInDays.Value           = objmedicalexamDto.i_ValidInDays.ToString();
            }
        }
Ejemplo n.º 4
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            if (cboMedico.SelectedValue.ToString() == "-1")
            {
                MessageBox.Show("Seleccionar un médico tratante", " ¡ VALIDACIÓN!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }
            if (_auxiliaryExams == null)
            {
                _auxiliaryExams = new List <ServiceComponentList>();
            }

            // Save ListView / recorrer la lista de examenes seleccionados
            foreach (ListViewItem item in lvExamenesSeleccionados.Items)
            {
                var fields           = item.SubItems;
                var ComponentId      = fields[1].Text.Split('|');
                var NombreComponente = fields[0].Text.Split('|');



                MedicalExamBL objComponentBL  = new MedicalExamBL();
                componentDto  objComponentDto = new componentDto();

                OperationResult objOperationResult = new OperationResult();
                foreach (var scid in ComponentId)
                {
                    var conCargoA = -1;
                    if (_type == "Hospi")
                    {
                        var oFrmType = new frmType();
                        oFrmType.ShowDialog();

                        if (oFrmType._conCargoA == "Médico")
                        {
                            conCargoA = 1;
                        }
                        else
                        {
                            conCargoA = 2;
                        }
                    }

                    objComponentDto = objComponentBL.GetMedicalExam(ref objOperationResult, scid);
                    SystemParameterBL oSp = new SystemParameterBL();
                    var o = oSp.GetSystemParameter(ref objOperationResult, 116, int.Parse(objComponentDto.i_CategoryId.ToString()));
                    //Lógica de Aumento de Precio Base

                    var porcentajes = o.v_Field.Split('-');

                    float p1 = porcentajes[0] == null ? 0 : float.Parse(porcentajes[0].ToString());

                    float p2 = porcentajes[1] == null ? 0 : float.Parse(porcentajes[1].ToString());

                    float pb          = objComponentDto.r_BasePrice.Value;
                    var   precio_base = pb + (pb * p1 / 100) + (pb * p2 / 100);
                    //FormPrecioComponente frm = new FormPrecioComponente("", "", "");
                    //frmConfigSeguros frm1 = new frmConfigSeguros(0, 0, 0, "", "");
                    ServiceComponentList auxiliaryExam          = new ServiceComponentList();
                    servicecomponentDto  objServiceComponentDto = new servicecomponentDto();
                    ServiceBL            _ObjServiceBL          = new ServiceBL();
                    TicketBL             oTicketBL = new TicketBL();
                    if (_modo == "ASEGU")
                    {
                        #region OLD Logica antigua
                        #region Conexion SAM
                        //ConexionSigesoft conectasam = new ConexionSigesoft();
                        //conectasam.opensigesoft();
                        #endregion
                        #region Query
                        //var componente = NombreComponente[0].ToString();
                        //var cadena1 = "select PL.i_EsDeducible, PL.i_EsCoaseguro, PL.d_Importe, PL.d_ImporteCo from [dbo].[plan] PL where PL.v_IdUnidadProductiva='" + lineId + "' and PL.v_ProtocoloId='" + _protocolId + "' ";
                        //SqlCommand comando = new SqlCommand(cadena1, connection: conectasam.conectarsigesoft);
                        //SqlDataReader lector = comando.ExecuteReader();
                        //int deducible = 0;
                        //int coaseguro = 0;
                        //decimal? importe = 0;
                        //decimal? importeCo = 0;
                        //while (lector.Read())
                        //{
                        //    deducible = int.Parse(lector.GetValue(0).ToString()); coaseguro = int.Parse(lector.GetValue(1).ToString()); importe = decimal.Parse(lector.GetValue(2).ToString()); importeCo = decimal.Parse(lector.GetValue(3).ToString());
                        //}
                        //lector.Close();
                        //string factores = ""; string aseguradoraName = ""; string organizationId = "";
                        //var factorGlobal = "";
                        //var cadena2 = "select PR.r_PriceFactor, OO.v_Name, PR.v_CustomerOrganizationId from Organization OO inner join protocol PR On PR.v_AseguradoraOrganizationId = OO.v_OrganizationId where PR.v_ProtocolId ='" + _protocolId + "'";
                        //comando = new SqlCommand(cadena2, connection: conectasam.conectarsigesoft);
                        //lector = comando.ExecuteReader();
                        //while (lector.Read())
                        //{
                        //    factores = lector.GetValue(0).ToString();
                        //    var factorArray = factores.Split('|');// factores[0].ToString().Split('|');
                        //    factorGlobal = factorArray[0];
                        //    aseguradoraName = lector.GetValue(1).ToString();
                        //    organizationId = lector.GetValue(2).ToString();
                        //}
                        //lector.Close();
                        //string empresa = "";
                        //var cadena3 = "select v_Name from Organization OO  where OO.v_OrganizationId ='" + organizationId + "'";
                        //comando = new SqlCommand(cadena3, connection: conectasam.conectarsigesoft);
                        //lector = comando.ExecuteReader();
                        //while (lector.Read())
                        //{
                        //    empresa = lector.GetValue(0).ToString();
                        //}
                        //lector.Close();
                        #endregion
                        #region Lógica PARA SABER SI ES DEDUCIBLE O COASEGURO
                        //if (rbNuevaConsulta.Checked)// QUIERE DECIR QUE ES UNA NUEVA ATENCION Y DEBE SER CONSIDERADO COMO DEDUCIBLE SIN FACTOR
                        //{
                        //    factorGlobal = "1";
                        //    coaseguro = 0;
                        //    importeCo = null;
                        //}
                        //else if (rbAdicional.Checked) // QUIERE DECIR QUE ES UN COMPONENTE ADICIONAL Y DEBE SER CONSIDERADO COMO COASEGURO CON FACTOR
                        //{
                        //    deducible = 0;
                        //    importe = null;
                        //}
                        #endregion
                        #region Formulario
                        //precio_base = (float)objComponentDto.r_PriceSegus;// se cambia el precio inicial por el SEGUS
                        //frmConfigSeguros frm1 = new frmConfigSeguros(deducible, coaseguro, importe, precio_base.ToString(), factorGlobal, importeCo);
                        //frm1.Text = aseguradoraName + " / " + empresa;
                        //frm1.ShowDialog();
                        #endregion
                        #endregion

                        #region Obteniendo los campos de la BD
                        ConexionSigesoft conectasam = new ConexionSigesoft();
                        conectasam.opensigesoft();
                        var           componente      = NombreComponente[0].ToString();
                        var           cadena          = "select i_KindOfService from  component where v_ComponentId='" + objComponentDto.v_ComponentId + "'";
                        SqlCommand    comando         = new SqlCommand(cadena, connection: conectasam.conectarsigesoft);
                        SqlDataReader lector          = comando.ExecuteReader();
                        int           i_KindOfService = 0;
                        while (lector.Read())
                        {
                            try
                            {
                                i_KindOfService = int.Parse(lector.GetValue(0).ToString());
                            }
                            catch (Exception exception)
                            {
                                MessageBox.Show(exception.Message, " ¡ ERROR !", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                return;
                            }
                        }
                        lector.Close();
                        var cadena1 = "select PL.i_PlanId, PL.i_EsCoaseguro, PL.d_Importe, PL.d_ImporteCo " +
                                      "from [dbo].[plan] PL " +
                                      "where PL.v_IdUnidadProductiva='" + lineId + "' and PL.v_ProtocoloId='" + _protocolId + "' ";
                        comando = new SqlCommand(cadena1, connection: conectasam.conectarsigesoft);
                        lector  = comando.ExecuteReader();
                        string PlanId = ""; int coaseguro = 0; decimal?importe = 0; decimal?importeCo = 0;
                        while (lector.Read())
                        {
                            try
                            {
                                PlanId    = lector.GetValue(0).ToString();
                                coaseguro = int.Parse(lector.GetValue(1).ToString());
                                importe   = decimal.Parse(lector.GetValue(2).ToString());
                                importeCo = decimal.Parse(lector.GetValue(3).ToString());
                            }
                            catch (Exception exception)
                            {
                                MessageBox.Show(exception.Message, " ¡ ERROR !", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                return;
                            }
                        }
                        lector.Close();
                        string factores = ""; string aseguradoraName = ""; string organizationId = ""; var factorGlobal = "";
                        var    cadena2 = "select PR.r_PriceFactor, OO.v_Name, PR.v_CustomerOrganizationId " +
                                         "from Organization OO " +
                                         "inner join protocol PR On PR.v_AseguradoraOrganizationId = OO.v_OrganizationId " +
                                         "where PR.v_ProtocolId ='" + _protocolId + "'";
                        comando = new SqlCommand(cadena2, connection: conectasam.conectarsigesoft);
                        lector  = comando.ExecuteReader();
                        while (lector.Read())
                        {
                            try
                            {
                                factores = lector.GetValue(0).ToString();
                                var factorArray = factores.Split('|');// factores[0].ToString().Split('|');
                                factorGlobal    = factorArray[0];
                                aseguradoraName = lector.GetValue(1).ToString();
                                organizationId  = lector.GetValue(2).ToString();
                            }
                            catch (Exception exception)
                            {
                                MessageBox.Show(exception.Message, " ¡ ERROR !", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                return;
                            }
                        }
                        lector.Close();
                        #endregion

                        #region Según el tipo de componente se hace el calculo
                        switch (i_KindOfService)
                        {
                        //CLINICA
                        case 1:
                        {
                            if (objComponentDto.r_PriceSegus != 0)
                            {
                                objServiceComponentDto.r_Price            = objComponentDto.r_PriceSegus;
                                objServiceComponentDto.d_SaldoPaciente    = importe;
                                objServiceComponentDto.d_SaldoAseguradora = (decimal)objComponentDto.r_PriceSegus - importe;
                            }
                            else
                            {
                                frmConfigSeguros frm1 = new frmConfigSeguros("1");
                                frm1.ShowDialog();
                                objServiceComponentDto.r_Price            = (float)frm1.nuevoPrecio;
                                objServiceComponentDto.d_SaldoPaciente    = importe;
                                objServiceComponentDto.d_SaldoAseguradora = frm1.nuevoPrecio - importe;
                            }
                        }
                        break;

                        //SERVICIOS AUXILIARES
                        case 2:
                        {
                            if (objComponentDto.r_PriceSegus != 0)
                            {
                                objServiceComponentDto.r_Price            = objComponentDto.r_PriceSegus * float.Parse(factorGlobal);
                                objServiceComponentDto.d_SaldoPaciente    = importeCo * (decimal)objServiceComponentDto.r_Price / 100;
                                objServiceComponentDto.d_SaldoAseguradora = (100 - importeCo) * (decimal)objServiceComponentDto.r_Price / 100;
                            }
                            else
                            {
                                frmConfigSeguros frm1 = new frmConfigSeguros(factorGlobal);
                                frm1.ShowDialog();
                                objServiceComponentDto.r_Price            = (float)frm1.nuevoPrecio;
                                objServiceComponentDto.d_SaldoPaciente    = importeCo * frm1.nuevoPrecio / 100;
                                objServiceComponentDto.d_SaldoAseguradora = (100 - importeCo) * frm1.nuevoPrecio / 100;
                            }
                        }
                        break;

                        //HONORARIOS MÉDICOS Y/O QUIRURGICOS
                        case 3:
                        {
                            if (objComponentDto.r_PriceSegus != 0)
                            {
                                objServiceComponentDto.r_Price            = objComponentDto.r_PriceSegus * float.Parse(factorGlobal);
                                objServiceComponentDto.d_SaldoPaciente    = importeCo * (decimal)objServiceComponentDto.r_Price / 100;
                                objServiceComponentDto.d_SaldoAseguradora = (100 - importeCo) * (decimal)objServiceComponentDto.r_Price / 100;
                            }
                            else
                            {
                                frmConfigSeguros frm1 = new frmConfigSeguros(factorGlobal);
                                frm1.ShowDialog();
                                objServiceComponentDto.r_Price            = (float)frm1.nuevoPrecio;
                                objServiceComponentDto.d_SaldoPaciente    = importeCo * frm1.nuevoPrecio / 100;
                                objServiceComponentDto.d_SaldoAseguradora = (100 - importeCo) * frm1.nuevoPrecio / 100;
                            }
                        }
                        break;
                        }
                        #endregion



                        objServiceComponentDto.v_ServiceId              = _serviceId;
                        objServiceComponentDto.i_ExternalInternalId     = (int)Common.ComponenteProcedencia.Interno;
                        objServiceComponentDto.i_ServiceComponentTypeId = 1;
                        objServiceComponentDto.i_IsVisibleId            = 1;
                        objServiceComponentDto.i_IsInheritedId          = (int)Common.SiNo.NO;
                        objServiceComponentDto.d_StartDate              = null;
                        objServiceComponentDto.d_EndDate                  = null;
                        objServiceComponentDto.i_index                    = 1;
                        objServiceComponentDto.v_ComponentId              = scid;
                        objServiceComponentDto.i_IsInvoicedId             = (int)Common.SiNo.NO;
                        objServiceComponentDto.i_ServiceComponentStatusId = (int)Common.ServiceStatus.PorIniciar;
                        objServiceComponentDto.i_QueueStatusId            = (int)Common.QueueStatusId.LIBRE;
                        objServiceComponentDto.i_Iscalling                = (int)Common.Flag_Call.NoseLlamo;
                        objServiceComponentDto.i_Iscalling_1              = (int)Common.Flag_Call.NoseLlamo;
                        objServiceComponentDto.i_IsManuallyAddedId        = (int)Common.SiNo.NO;
                        objServiceComponentDto.i_IsRequiredId             = (int)Common.SiNo.SI;
                        objServiceComponentDto.v_IdUnidadProductiva       = txtUnidProdId.Text;
                        objServiceComponentDto.i_MedicoTratanteId         = int.Parse(cboMedico.SelectedValue.ToString());
                        if (rbNuevaConsulta.Checked)
                        {
                            objServiceComponentDto.i_TipoDesc = 1;
                        }
                        else if (rbAdicional.Checked)
                        {
                            objServiceComponentDto.i_TipoDesc = 2;
                        }

                        _ObjServiceBL.AddServiceComponent(ref objOperationResult, objServiceComponentDto, Globals.ClientSession.GetAsList());
                        #region Update a service agrega el PlanId
                        cadena1 = "update service set " +
                                  "i_PlanId = '" + PlanId + "' " +
                                  "where v_ServiceId = '" + _serviceId + "' ";
                        comando = new SqlCommand(cadena1, connection: conectasam.conectarsigesoft);
                        lector  = comando.ExecuteReader();
                        lector.Close();
                        #endregion
                    }
                    else
                    {
                        FormPrecioComponente frm = new FormPrecioComponente(NombreComponente[0].ToString(), precio_base.ToString(), "");
                        frm.ShowDialog();
                        objServiceComponentDto.i_ConCargoA              = conCargoA;
                        objServiceComponentDto.v_ServiceId              = _serviceId;
                        objServiceComponentDto.i_ExternalInternalId     = (int)Common.ComponenteProcedencia.Interno;
                        objServiceComponentDto.i_ServiceComponentTypeId = 1;
                        objServiceComponentDto.i_IsVisibleId            = 1;
                        objServiceComponentDto.i_IsInheritedId          = (int)Common.SiNo.NO;
                        objServiceComponentDto.d_StartDate              = null;
                        objServiceComponentDto.d_EndDate                  = null;
                        objServiceComponentDto.i_index                    = 1;
                        objServiceComponentDto.r_Price                    = frm.Precio;
                        objServiceComponentDto.v_ComponentId              = scid;
                        objServiceComponentDto.i_IsInvoicedId             = (int)Common.SiNo.NO;
                        objServiceComponentDto.i_ServiceComponentStatusId = (int)Common.ServiceStatus.PorIniciar;
                        objServiceComponentDto.i_QueueStatusId            = (int)Common.QueueStatusId.LIBRE;
                        //objServiceComponentDto.i_IsRequiredId = (int)Common.SiNo.SI;
                        objServiceComponentDto.i_Iscalling          = (int)Common.Flag_Call.NoseLlamo;
                        objServiceComponentDto.i_Iscalling_1        = (int)Common.Flag_Call.NoseLlamo;
                        objServiceComponentDto.i_IsManuallyAddedId  = (int)Common.SiNo.NO;
                        objServiceComponentDto.i_IsRequiredId       = (int)Common.SiNo.SI;
                        objServiceComponentDto.v_IdUnidadProductiva = objComponentDto.v_IdUnidadProductiva;
                        objServiceComponentDto.i_MedicoTratanteId   = int.Parse(cboMedico.SelectedValue.ToString());
                        objServiceComponentDto.d_SaldoPaciente      = 0;
                        objServiceComponentDto.d_SaldoAseguradora   = 0;
                        _ObjServiceBL.AddServiceComponent(ref objOperationResult, objServiceComponentDto, Globals.ClientSession.GetAsList());
                    }
                }

                //Actualizo si son examenes adicionales
                if (_DataSource.Count > 0)
                {
                    new AdditionalExamBL().UpdateAdditionalExamByComponentIdAndServiceId(ComponentId[0], _serviceId,
                                                                                         Globals.ClientSession.i_SystemUserId);
                }
            }

            MessageBox.Show("Se grabo correctamente", " ¡ INFORMACIÓN !", MessageBoxButtons.OK, MessageBoxIcon.Information);
            this.DialogResult = DialogResult.OK;
        }
Ejemplo n.º 5
0
        public void UpdateMedicalExam(ref OperationResult pobjOperationResult, bool pbIsChangeName, componentDto pobjDtoEntity, List <string> ClientSession)
        {
            //mon.IsActive = true;

            try
            {
                SigesoftEntitiesModel dbContext = new SigesoftEntitiesModel();

                #region Validar Nombre de componente

                if (pobjDtoEntity != null && pbIsChangeName == true)
                {
                    OperationResult objOperationResult6  = new OperationResult();
                    string          strfilterExpression1 = string.Format("v_Name==\"{0}\"&&i_Isdeleted==0", pobjDtoEntity.v_Name);

                    var _recordCount1 = GetMedicalExamCount(ref objOperationResult6, strfilterExpression1);

                    if (_recordCount1 != 0)
                    {
                        pobjOperationResult.ErrorMessage = "El nombre del componente ya existe";
                        return;
                    }
                }
                #endregion
                // Obtener la entidad fuente
                var objEntitySource = (from a in dbContext.component
                                       where a.v_ComponentId == pobjDtoEntity.v_ComponentId
                                       select a).FirstOrDefault();

                // Crear la entidad con los datos actualizados
                pobjDtoEntity.d_UpdateDate   = DateTime.Now;
                pobjDtoEntity.i_UpdateUserId = Int32.Parse(ClientSession[2]);
                component objEntity = componentAssembler.ToEntity(pobjDtoEntity);

                // Copiar los valores desde la entidad actualizada a la Entidad Fuente
                dbContext.component.ApplyCurrentValues(objEntity);

                // Guardar los cambios
                dbContext.SaveChanges();

                pobjOperationResult.Success = 1;
                // Llenar entidad Log
                LogBL.SaveLog(ClientSession[0], ClientSession[1], ClientSession[2], LogEventType.ACTUALIZACION, "EXAMEN MÉDICO", "v_MedicalExamId=" + objEntity.v_ComponentId.ToString(), Success.Ok, null);
                return;
            }
            catch (Exception ex)
            {
                pobjOperationResult.Success          = 0;
                pobjOperationResult.ExceptionMessage = Common.Utils.ExceptionFormatter(ex);
                // Llenar entidad Log
                LogBL.SaveLog(ClientSession[0], ClientSession[1], ClientSession[2], LogEventType.ACTUALIZACION, "EXAMEN MÉDICO", "v_MedicalExamId=" + pobjDtoEntity.v_ComponentId.ToString(), Success.Failed, pobjOperationResult.ExceptionMessage);
                return;
            }
        }
        private void btnOK_Click(object sender, EventArgs e)
        {
            OperationResult objOperationResult = new OperationResult();

            if (uvMedicalExamEdit.Validate(true, false).IsValid)
            {
                if (txtInsertName.Text.Trim() == "")
                {
                    MessageBox.Show("Por favor ingrese un nombre apropiado para la Examen Médico.", "Error de validación", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }

                if (MessageBox.Show("¿Está seguro de agregar / modificar la Examen Médico?.", "Pregunta", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.No)
                {
                    return;
                }

                if (Mode == "New")
                {
                    float priceSegus;
                    if (txtTarifaSegus.Text == "")
                    {
                        priceSegus = 0;
                    }
                    else
                    {
                        priceSegus = float.Parse(txtTarifaSegus.Text);
                    }
                    objmedicalexamDto = new componentDto();

                    // Populate the entity
                    objmedicalexamDto.v_Name = txtInsertName.Text;

                    objmedicalexamDto.i_CategoryId         = Convert.ToInt32(ddlCategoryId.SelectedNode.Parent.Tag);
                    objmedicalexamDto.r_BasePrice          = float.Parse(unBasePrice.Text);
                    objmedicalexamDto.i_DiagnosableId      = Convert.ToInt32(ddlDiagnosableId.SelectedValue);
                    objmedicalexamDto.i_ComponentTypeId    = Convert.ToInt32(ddlComponentTypeId.SelectedValue);
                    objmedicalexamDto.i_UIIsVisibleId      = Convert.ToInt32(ddlUIIsVisibleId.SelectedValue);
                    objmedicalexamDto.i_UIIndex            = Convert.ToInt32(unUIIndex.Value);
                    objmedicalexamDto.i_IsApprovedId       = Convert.ToInt32(ddlIsApprovedId.SelectedValue);
                    objmedicalexamDto.i_ValidInDays        = Convert.ToInt32(unValidInDays.Value);
                    objmedicalexamDto.v_IdUnidadProductiva = ddlUnidadProductiva.SelectedValue.ToString();
                    objmedicalexamDto.r_PriceSegus         = priceSegus;
                    objmedicalexamDto.v_CodigoSegus        = txtCodigoSegus.Text;
                    objmedicalexamDto.i_KindOfService      = Int32.Parse(ddlKindOfService.SelectedValue.ToString());
                    objmedicalexamDto.i_PriceIsRecharged   = Int32.Parse(cbRecargable.SelectedValue.ToString());
                    // Save the data
                    _objMedicalExamBL.AddMedicalExam(ref objOperationResult, objmedicalexamDto, Globals.ClientSession.GetAsList());
                }
                else if (Mode == "Edit")
                {
                    bool  pbIsChangeName;
                    float priceSegus;
                    if (txtTarifaSegus.Text == "")
                    {
                        priceSegus = 0;
                    }
                    else
                    {
                        priceSegus = float.Parse(txtTarifaSegus.Text);
                    }

                    // Populate the entity
                    if (_NameComponentOld != txtInsertName.Text)
                    {
                        pbIsChangeName = true;
                    }
                    else
                    {
                        pbIsChangeName = false;
                    }
                    objmedicalexamDto.v_Name = txtInsertName.Text;

                    objmedicalexamDto.i_CategoryId         = Convert.ToInt32(ddlCategoryId.SelectedNode.Parent.Tag);
                    objmedicalexamDto.r_BasePrice          = float.Parse(unBasePrice.Text);
                    objmedicalexamDto.i_DiagnosableId      = Convert.ToInt32(ddlDiagnosableId.SelectedValue);
                    objmedicalexamDto.i_ComponentTypeId    = Convert.ToInt32(ddlComponentTypeId.SelectedValue);
                    objmedicalexamDto.i_UIIsVisibleId      = Convert.ToInt32(ddlUIIsVisibleId.SelectedValue);
                    objmedicalexamDto.i_UIIndex            = Convert.ToInt32(unUIIndex.Value);
                    objmedicalexamDto.i_IsApprovedId       = Convert.ToInt32(ddlIsApprovedId.SelectedValue);
                    objmedicalexamDto.i_ValidInDays        = Convert.ToInt32(unValidInDays.Value);
                    objmedicalexamDto.v_IdUnidadProductiva = ddlUnidadProductiva.SelectedValue.ToString();
                    objmedicalexamDto.r_PriceSegus         = priceSegus;
                    objmedicalexamDto.v_CodigoSegus        = txtCodigoSegus.Text;
                    objmedicalexamDto.i_KindOfService      = Int32.Parse(ddlKindOfService.SelectedValue.ToString());
                    objmedicalexamDto.i_PriceIsRecharged   = Int32.Parse(cbRecargable.SelectedValue.ToString());
                    objmedicalexamDto.v_ComentaryUpdate    = GetChanges();
                    // Save the data
                    _objMedicalExamBL.UpdateMedicalExam(ref objOperationResult, pbIsChangeName, objmedicalexamDto, 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
                {
                    if (objOperationResult.ErrorMessage != null)
                    {
                        MessageBox.Show(objOperationResult.ErrorMessage, "ERROR!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    else
                    {
                        MessageBox.Show(Constants.GenericErrorMessage, "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);
            }
        }
        private void frmMedicalExamEdicion_Load(object sender, EventArgs e)
        {
            try
            {
                #region Mayusculas - Normal
                var _EsMayuscula = int.Parse(Common.Utils.GetApplicationConfigValue("EsMayuscula"));
                if (_EsMayuscula == 1)
                {
                    SearchControlAndSetEvents(this);
                }


                #endregion
                OperationResult objOperationResult = new OperationResult();

                //Llenado de combos

                Utils.LoadComboTreeBoxList(ddlCategoryId, BLL.Utils.GetSystemParameterForComboTreeBox(ref objOperationResult, 116, null), DropDownListAction.Select);
                Utils.LoadDropDownList(ddlDiagnosableId, "Value1", "Id", BLL.Utils.GetSystemParameterForCombo(ref objOperationResult, 111, null), DropDownListAction.Select);
                Utils.LoadDropDownList(cbRecargable, "Value1", "Id", BLL.Utils.GetSystemParameterForCombo(ref objOperationResult, 111, null), DropDownListAction.Select);
                Utils.LoadDropDownList(ddlComponentTypeId, "Value1", "Id", BLL.Utils.GetSystemParameterForCombo(ref objOperationResult, 126, null), DropDownListAction.Select);
                Utils.LoadDropDownList(ddlKindOfService, "Value1", "Id", BLL.Utils.GetSystemParameterForCombo(ref objOperationResult, 358, null), DropDownListAction.Select);
                Utils.LoadDropDownList(ddlUIIsVisibleId, "Value1", "Id", BLL.Utils.GetSystemParameterForCombo(ref objOperationResult, 111, null), DropDownListAction.Select);
                Utils.LoadDropDownList(ddlIsApprovedId, "Value1", "Id", BLL.Utils.GetSystemParameterForCombo(ref objOperationResult, 111, null), DropDownListAction.Select);
                MedicamentoDao.ObtenerLineasParaCombo(ddlUnidadProductiva);
                if (Mode == "New")
                {
                    // Additional logic here.
                }
                else if (Mode == "Edit")
                {
                    // Get the Entity Data
                    objmedicalexamDto = new componentDto();

                    objmedicalexamDto = _objMedicalExamBL.GetMedicalExam(ref objOperationResult, MedicalExamId);

                    txtInsertName.Text = objmedicalexamDto.v_Name;
                    _NameComponentOld  = objmedicalexamDto.v_Name;

                    ComboTreeNode nodoABuscar = null;

                    foreach (var nodeParent in ddlCategoryId.Nodes)
                    {
                        foreach (var nodeChildCategory in nodeParent.Nodes)
                        {
                            if (nodeChildCategory.Tag.ToString() == objmedicalexamDto.i_CategoryId.ToString())
                            {
                                foreach (var nodeChildSubCategory in nodeChildCategory.Nodes)
                                {
                                    if (nodeChildSubCategory.Tag.ToString() == Orden)
                                    {
                                        nodoABuscar = nodeChildSubCategory;
                                    }
                                }
                            }
                        }
                    }
                    if (nodoABuscar != null)
                    {
                        ddlCategoryId.SelectedNode = nodoABuscar;
                    }


                    unBasePrice.Text = objmedicalexamDto.r_BasePrice.ToString();
                    ddlDiagnosableId.SelectedValue   = objmedicalexamDto.i_DiagnosableId.ToString();
                    ddlComponentTypeId.SelectedValue = objmedicalexamDto.i_ComponentTypeId.ToString();
                    ddlKindOfService.SelectedValue   = objmedicalexamDto.i_KindOfService.ToString();
                    cbRecargable.SelectedValue       = objmedicalexamDto.i_PriceIsRecharged.ToString();
                    ddlUIIsVisibleId.SelectedValue   = objmedicalexamDto.i_UIIsVisibleId.ToString();
                    unUIIndex.Value = objmedicalexamDto.i_UIIndex;

                    ddlIsApprovedId.SelectedValue = objmedicalexamDto.i_IsApprovedId.ToString();
                    unValidInDays.Value           = objmedicalexamDto.i_ValidInDays.ToString();
                    if (objmedicalexamDto.v_IdUnidadProductiva != null)
                    {
                        ddlUnidadProductiva.SelectedValue = objmedicalexamDto.v_IdUnidadProductiva;
                    }
                    else
                    {
                        ddlUnidadProductiva.SelectedIndex = 0;
                    }
                    txtTarifaSegus.Text = objmedicalexamDto.r_PriceSegus.ToString();
                    txtCodigoSegus.Text = objmedicalexamDto.v_CodigoSegus;
                }

                SetOldValues();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }