public DataRow ObtenerModeloNomina(Decimal ID_EMPRESA, String ID_CIUDAD, Decimal ID_CENTRO_C, Decimal ID_SUB_C)
 {
     condicionComercial _condicionComercial = new condicionComercial(Empresa, Usuario);
     DataTable _dataTable = _condicionComercial.ObtenerCondicionesEconomicasPorId(ID_EMPRESA, ID_CIUDAD, ID_CENTRO_C, ID_SUB_C);
     DataRow _dataRow = null;
     if (_dataTable.Rows.Count > 0) _dataRow = _dataTable.Rows[0];
     return _dataRow;
 }
    private void controlesParaNuevaCondicionEconomica()
    {
        capturarVariablesGlogales();

        if ((String.IsNullOrEmpty(ID_CIUDAD) == true) && (ID_CENTRO_C == 0) && (ID_SUB_C == 0))
        {
            configurarBotonesDeAccion(false, true, true, false);

            configurarMensajes(true, System.Drawing.Color.Red);
            Label_MENSAJE.Text = "ADVERTENCIA: No se encontraron registros de condiciones económicas para mostrar, por favor digitelas y guarde.";

            Panel_CONTROL_REGISTRO.Visible = false;

            Panel_COD_CONDICIONES.Visible = false;

            CheckBox_FACTURA_NOMINA.Checked = false;

            cargar_DropDownList_MOD_SOPORTE();
            cargar_DropDownList_MOD_FACTURA();

            TextBox_AD_NOM.Text = "0";
            CheckBox_SOLO_DEV.Checked = false;
            CheckBox_APL_MTZ.Checked = false;

            TextBox_AD_PENSION.Text = "0";
            TextBox_AD_SALUD.Text = "0";
            TextBox_AD_RIESGOS.Text = "0";
            TextBox_AD_APO_SENA.Text = "0";
            TextBox_AD_APO_ICBF.Text = "0";
            TextBox_AD_APO_CAJA.Text = "0";
            TextBox_AD_VACACIONES.Text = "0";
            TextBox_AD_CESANTIA.Text = "0";
            TextBox_AD_INT_CES.Text = "0";
            TextBox_AD_PRIMA.Text = "0";
            TextBox_AD_SEG_VID.Text = "0";

            CheckBox_SUB_PENSION.Checked = false;
            CheckBox_SUB_SALUD.Checked = false;
            CheckBox_SUB_RIESGO.Checked = false;
            CheckBox_SUB_SENA.Checked = false;
            CheckBox_SUB_ICBF.Checked = false;
            CheckBox_SUB_CAJA.Checked = false;
            CheckBox_SUB_VACACIONES.Checked = false;
            CheckBox_SUB_CESANTIAS.Checked = false;
            CheckBox_SUB_INT_CES.Checked = false;
            CheckBox_SUB_PRIMA.Checked = false;
            CheckBox_SUB_SEG_VID.Checked = false;

            CheckBox_RET_VAC.Checked = false;
            CheckBox_RET_CES.Checked = false;
            CheckBox_RET_INT_CES.Checked = false;
            CheckBox_RET_PRIM.Checked = false;

            TextBox_DIAS_VNC.Text = "";

            cargar_DropDownList_REGIMEN();

            TextBox_OBS_FACT.Text = "";

            habilitarSeccionServiciosParaDatosNuevos(true);

            mostrar_modulo_copia_condiciones_grupoempresarial();
        }
        else
        {
            Decimal ID_EMPRESA_1 = ID_EMPRESA;
            String ID_CIUDAD_1 = null;
            Decimal ID_CENTRO_C_1 = 0;
            Decimal ID_SUB_C_1 = 0;

            Panel_FORMULARIO.Visible = true;
            Panel_FORMULARIO.Enabled = true;

            Panel_COPIA_CONDICIONES_ECONOMICAS_GRUPO_EMPRESARIAL.Visible = false;

            configurarMensajes(false, System.Drawing.Color.Green);

            condicionComercial _condicionComercial = new condicionComercial(Session["idEmpresa"].ToString(),Session["USU_LOG"].ToString());

            if (ID_SUB_C != 0)
            {
                subCentroCosto _subCentroCosto = new subCentroCosto(Session["idEmpresa"].ToString(), Session["USU_LOG"].ToString());
                DataTable tablainfoSubCentro = _subCentroCosto.ObtenerSubCentrosDeCostoPorIdSubCosto(ID_SUB_C);
                DataRow infoSubCentro = tablainfoSubCentro.Rows[0];

                ID_EMPRESA_1 = ID_EMPRESA;
                ID_CIUDAD_1 = null;
                ID_CENTRO_C_1 = Convert.ToDecimal(infoSubCentro["ID_CENTRO_C"]);
                ID_SUB_C_1 = 0;
            }
            else
            {
                if (ID_CENTRO_C != 0)
                {
                    centroCosto _centroCosto = new centroCosto(Session["idEmpresa"].ToString(), Session["USU_LOG"].ToString());
                    DataTable tablaCentroCosto = _centroCosto.ObtenerCentrosDeCostoPorIdCentroCosto(ID_CENTRO_C);
                    DataRow infoCentroCosto = tablaCentroCosto.Rows[0];

                    ID_EMPRESA_1 = ID_EMPRESA;
                    ID_CIUDAD_1 = infoCentroCosto["ID_CIUDAD"].ToString().Trim();
                    ID_CENTRO_C_1 = 0;
                    ID_SUB_C_1 = 0;
                }
            }

            DataTable tablaCondicionesHeredadas = _condicionComercial.ObtenerCondicionesEconomicasPorId(ID_EMPRESA_1, ID_CIUDAD_1, ID_CENTRO_C_1, ID_SUB_C_1);

            if (tablaCondicionesHeredadas.Rows.Count <= 0)
            {
                configurarBotonesDeAccion(false, true, true, true);

                configurarMensajes(true, System.Drawing.Color.Red);
                Label_MENSAJE.Text = "ADVERTENCIA: No se encontraron registros de condiciones económicas para mostrar y no se pudieron heredar condiciones económicas de la entidad anterior a la seleccionada,  por favor digite las nuevas condiciones y guarde.";

                Panel_CONTROL_REGISTRO.Visible = false;

                Panel_COD_CONDICIONES.Visible = false;

                CheckBox_FACTURA_NOMINA.Checked = false;

                cargar_DropDownList_MOD_SOPORTE();
                cargar_DropDownList_MOD_FACTURA();

                TextBox_AD_NOM.Text = "0,00";
                CheckBox_SOLO_DEV.Checked = false;
                CheckBox_APL_MTZ.Checked = false;

                TextBox_AD_PENSION.Text = "0,00";
                TextBox_AD_SALUD.Text = "0,00";
                TextBox_AD_RIESGOS.Text = "0,00";
                TextBox_AD_APO_SENA.Text = "0,00";
                TextBox_AD_APO_ICBF.Text = "0,00";
                TextBox_AD_APO_CAJA.Text = "0,00";
                TextBox_AD_VACACIONES.Text = "0,00";
                TextBox_AD_CESANTIA.Text = "0,00";
                TextBox_AD_INT_CES.Text = "0,00";
                TextBox_AD_PRIMA.Text = "0,00";
                TextBox_AD_SEG_VID.Text = "0,00";

                CheckBox_SUB_PENSION.Checked = false;
                CheckBox_SUB_SALUD.Checked = false;
                CheckBox_SUB_RIESGO.Checked = false;
                CheckBox_SUB_SENA.Checked = false;
                CheckBox_SUB_ICBF.Checked = false;
                CheckBox_SUB_CAJA.Checked = false;
                CheckBox_SUB_VACACIONES.Checked = false;
                CheckBox_SUB_CESANTIAS.Checked = false;
                CheckBox_SUB_INT_CES.Checked = false;
                CheckBox_SUB_PRIMA.Checked = false;
                CheckBox_SUB_SEG_VID.Checked = false;

                CheckBox_RET_VAC.Checked = false;
                CheckBox_RET_CES.Checked = false;
                CheckBox_RET_INT_CES.Checked = false;
                CheckBox_RET_PRIM.Checked = false;

                TextBox_DIAS_VNC.Text = "";

                cargar_DropDownList_REGIMEN();

                TextBox_OBS_FACT.Text = "";

                habilitarSeccionServiciosParaDatosNuevos(true);
            }
            else
            {
                DataRow infoCondicionesComerciales = tablaCondicionesHeredadas.Rows[0];

                configurarMensajes(true, System.Drawing.Color.Red);
                Label_MENSAJE.Text = "ADVERTENCIA: No se encontraron registros de condiciones económicas para mostrar, se heredaron las condiciones económicas de la entidad anterior a la seleccionada, por favor realice los cambios necesarios y guarde la información.";

                configurarBotonesDeAccion(false, true, true, true);

                Panel_CONTROL_REGISTRO.Visible = false;

                Panel_COD_CONDICIONES.Visible = false;

                cargar_campos_condiciones_comerciales(infoCondicionesComerciales);

                TextBox_USU_CRE.Text = "";
                TextBox_FCH_CRE.Text = "";
                TextBox_HOR_CRE.Text = "";
                TextBox_USU_MOD.Text = "";
                TextBox_FCH_MOD.Text = "";
                TextBox_HOR_MOD.Text = "";

                TextBox_COD_CONDICION.Text = "";

                DataTable tablaServiciosHeredados;

                if (ID_SUB_C != 0)
                {
                    tablaServiciosHeredados = _condicionComercial.ObtenerServiciosPorEmpresaPorIdCentroC(ID_CENTRO_C_1);
                }
                else
                {
                    if (ID_CENTRO_C != 0)
                    {
                        tablaServiciosHeredados = _condicionComercial.ObtenerServiciosPorEmpresaPorIdCiudad(ID_CIUDAD_1, ID_EMPRESA_1);
                    }
                    else
                    {
                        tablaServiciosHeredados = _condicionComercial.ObtenerServiciosPorEmpresaPorIdEmpresa(ID_EMPRESA_1);
                    }
                }

                if (tablaServiciosHeredados.Rows.Count <= 0)
                {
                    habilitarSeccionServiciosParaDatosNuevos(true);
                }
                else
                {

                    List<servicio> listaServicios = new List<servicio>();
                    Session.Remove("listaServicios_" + ID_EMPRESA.ToString());
                    Session.Add("listaServicios_" + ID_EMPRESA.ToString(), listaServicios);
                    List<detalleServicio> listaDetallesServicio = new List<detalleServicio>();
                    Session.Remove("listaDetallesServicio_" + ID_EMPRESA.ToString());
                    Session.Add("listaDetallesServicio_" + ID_EMPRESA.ToString(), listaDetallesServicio);

                    cargarInformacionServiciosComplementariosDeUnaEntidad(tablaServiciosHeredados, true, true);
                }

                if ((String.IsNullOrEmpty(ID_CIUDAD) == true) && (ID_CENTRO_C == 0) && (ID_SUB_C == 0))
                {
                    Panel_ESTRUCTURA_CENTRO_COSTOS.Visible = true;
                    cargarEstructuraDeCC();

                    configurarMensajesCC(true, System.Drawing.Color.Red);
                    Label_MENSAJE_CC.Text = "Por favor seleccionar una ciudad de la lista de cobertura.";

                    configurarMensajesSUBCC(true, System.Drawing.Color.Red);
                    Label_MENSAJE_SUB_CC.Text = "Por favor seleccionar un centro de costo de la lista de centros de costo.";
                }
                else
                {
                    Panel_ESTRUCTURA_CENTRO_COSTOS.Visible = false;
                }
            }
        }
    }
    protected void Button_COPIAR_CONDICIONES_GRUPO_Click(object sender, EventArgs e)
    {
        Decimal ID_EMPRESA_SELECICONADA = Convert.ToDecimal(DropDownList_EMPRESAS_DEL_GRUPO.SelectedValue);

        condicionComercial _condicionComercial = new condicionComercial(Session["idEmpresa"].ToString(), Session["USU_LOG"].ToString());
        DataTable tablaCondiciones = _condicionComercial.ObtenerCondicionesEconomicasPorId(ID_EMPRESA_SELECICONADA, null, 0, 0);
        DataRow infoCondiciones = tablaCondiciones.Rows[0];

        cargar_campos_condiciones_comerciales(infoCondiciones);

        DataTable tablaServiciosAnteriores;
        while(GridView_SERVICIOS_INCLUIDOS.Rows.Count > 0)
        {
            tablaServiciosAnteriores = obtenerDataTableDeGridViewServiciosActules();
            eliminar_servicio_de_grilla_y_lista_session(tablaServiciosAnteriores, GridView_SERVICIOS_INCLUIDOS.Rows.Count -1);
        }

        List<servicio> listaServicios = capturarListaServiciosDesdeSession();
        List<detalleServicio> listaDetalles = capturarListaDetallesServicioDesdeSession();

        DataTable tablaServiciosDeLaEntidad;

        tablaServiciosDeLaEntidad = _condicionComercial.ObtenerServiciosPorEmpresaPorIdEmpresa(ID_EMPRESA_SELECICONADA);

        if (tablaServiciosDeLaEntidad.Rows.Count <= 0)
        {
            habilitarSeccionServiciosParaDatosNuevos(true);

            Session.Remove("listaServicios_" + ID_EMPRESA.ToString());
            Session.Add("listaServicios_" + ID_EMPRESA.ToString(), listaServicios);
            Session.Remove("listaDetallesServicio_" + ID_EMPRESA.ToString());
            Session.Add("listaDetallesServicio_" + ID_EMPRESA.ToString(), listaDetalles);
        }
        else
        {
            cargarInformacionServiciosComplementariosDeUnaEntidad(tablaServiciosDeLaEntidad, true, true);
        }
    }
    private void cargar_GridView_COBERTURA()
    {
        tools _tools = new tools();
        SecureQueryString QueryStringSeguro;
        QueryStringSeguro = new SecureQueryString(_tools.byteParaQueryStringSeguro(), Request["data"]);

        Decimal ID_EMPRESA = Convert.ToDecimal(QueryStringSeguro["reg"]);

        cobertura _cobertura = new cobertura(Session["idEmpresa"].ToString());

        DataTable tablaCobertura = _cobertura.obtenerCoberturaDeUnCliente(ID_EMPRESA);

        if (tablaCobertura.Rows.Count <= 0)
        {
            configurarMensajesCobertura(true, System.Drawing.Color.Red);
            Label_MENSAJE_COBERTURA.Text = "La empresa no tiene configurada actualmente una cobertura.";
        }
        else
        {
            configurarMensajesCobertura(false, System.Drawing.Color.Red);

            GridView_COBERTURA.DataSource = tablaCobertura;
            GridView_COBERTURA.DataBind();

            DataRow filaEnTablaCobertura;
            condicionComercial _condicionComercial = new condicionComercial(Session["idEmpresa"].ToString(), Session["USU_LOG"].ToString());
            DataTable tablaCondicionesComercialesDeCobertura;

            centroCosto _centroCosto = new centroCosto(Session["idEmpresa"].ToString(), Session["USU_LOG"].ToString());
            DataTable tablaCentrosDeCostoCiudad;
            for (int i = 0; i < tablaCobertura.Rows.Count; i++)
            {
                filaEnTablaCobertura = tablaCobertura.Rows[i];

                tablaCondicionesComercialesDeCobertura = _condicionComercial.ObtenerCondicionesEconomicasPorId(ID_EMPRESA, filaEnTablaCobertura["Código Ciudad"].ToString(), 0, 0);
                if (tablaCondicionesComercialesDeCobertura.Rows.Count <= 0)
                {
                    GridView_COBERTURA.Rows[i].BackColor = colorNo;
                }
                else
                {
                    GridView_COBERTURA.Rows[i].BackColor = colorSi;
                }

                tablaCentrosDeCostoCiudad = _centroCosto.ObtenerCentrosDeCostoPorIdEmpresaIdCiudad(ID_EMPRESA, filaEnTablaCobertura["Código Ciudad"].ToString());
                if (tablaCentrosDeCostoCiudad.Rows.Count <= 0)
                {
                    GridView_COBERTURA.Rows[i].Cells[1].Enabled = false;
                }
                else
                {
                    GridView_COBERTURA.Rows[i].Cells[1].Enabled = true;
                }

            }
        }

        configurarMensajesCC(true, System.Drawing.Color.Red);
        Label_MENSAJE_CC.Text = "Por favor seleccionar una ciudad de la lista de cobertura.";
        GridView_CENTROS_DE_COSTO.DataSource = null;
        GridView_CENTROS_DE_COSTO.DataBind();

        configurarMensajesSUBCC(true, System.Drawing.Color.Red);
        Label_MENSAJE_SUB_CC.Text = "Por favor seleccionar un centro de costo de la lista de centros de costo.";
        GridView_SUB_CENTROS_DE_COSTO.DataSource = null;
        GridView_SUB_CENTROS_DE_COSTO.DataBind();
    }
    private void cargar_GridView_SUB_CENTROS_DE_COSTO(Decimal ID_EMPRESA, Decimal ID_CENTRO_C)
    {
        subCentroCosto _subCentroCosto = new subCentroCosto(Session["idEmpresa"].ToString(), Session["USU_LOG"].ToString());

        DataTable tablaSUBCCDeCC = _subCentroCosto.ObtenerSubCentrosDeCostoPorIdEmpresaIdCentroCosto(ID_EMPRESA, ID_CENTRO_C);

        if (tablaSUBCCDeCC.Rows.Count <= 0)
        {
            configurarMensajesSUBCC(true, System.Drawing.Color.Red);
            Label_MENSAJE_COBERTURA.Text = "El Centro de costos seleccionado no tiene sub centros.";
        }
        else
        {
            configurarMensajesSUBCC(false, System.Drawing.Color.Red);

            GridView_SUB_CENTROS_DE_COSTO.DataSource = tablaSUBCCDeCC;
            GridView_SUB_CENTROS_DE_COSTO.DataBind();

            DataRow filaEnTablaSUBCC;
            condicionComercial _condicionComercial = new condicionComercial(Session["idEmpresa"].ToString(), Session["USU_LOG"].ToString());
            DataTable tablaCondicionesComercialesDeSUBCC;

            for (int i = 0; i < tablaSUBCCDeCC.Rows.Count; i++)
            {
                filaEnTablaSUBCC = tablaSUBCCDeCC.Rows[i];

                tablaCondicionesComercialesDeSUBCC = _condicionComercial.ObtenerCondicionesEconomicasPorId(ID_EMPRESA, null,0, Convert.ToDecimal(filaEnTablaSUBCC["ID_SUB_C"]));
                if (tablaCondicionesComercialesDeSUBCC.Rows.Count <= 0)
                {
                    GridView_SUB_CENTROS_DE_COSTO.Rows[i].BackColor = colorNo;
                }
                else
                {
                    GridView_SUB_CENTROS_DE_COSTO.Rows[i].BackColor = colorSi;
                }

                GridView_SUB_CENTROS_DE_COSTO.Rows[i].Cells[2].Enabled = false;
            }
        }
    }
    private void cargarInfoCondiciones(Boolean bModificar)
    {
        capturarVariablesGlogales();

        if (ID_SUB_C != 0)
        {
            subCentroCosto _subCentroCostoMODULO = new subCentroCosto(Session["idEmpresa"].ToString(), Session["USU_LOG"].ToString());
            DataTable tablaInfoSubCentro = _subCentroCostoMODULO.ObtenerSubCentrosDeCostoPorIdSubCosto(ID_SUB_C);
            DataRow filaTablaInfoSubCentro = tablaInfoSubCentro.Rows[0];

            configurarInfoAdicionalModulo(true, filaTablaInfoSubCentro["NOM_SUB_C"].ToString());

            Panel_COPIA_CONDICIONES_ECONOMICAS_GRUPO_EMPRESARIAL.Visible = false;
        }
        else
        {
            if (ID_CENTRO_C != 0)
            {
                centroCosto _centroCostoMODULO = new centroCosto(Session["idEmpresa"].ToString(), Session["USU_LOG"].ToString());
                DataTable tablaInfoCC = _centroCostoMODULO.ObtenerCentrosDeCostoPorIdCentroCosto(ID_CENTRO_C);
                DataRow filaTablaInfoCC = tablaInfoCC.Rows[0];

                configurarInfoAdicionalModulo(true, filaTablaInfoCC["NOM_CC"].ToString());

                Panel_COPIA_CONDICIONES_ECONOMICAS_GRUPO_EMPRESARIAL.Visible = false;
            }
            else
            {
                if ((String.IsNullOrEmpty(ID_CIUDAD) == false) && (ID_EMPRESA != 0))
                {
                    cobertura _coberturaMODULO = new cobertura(Session["idEmpresa"].ToString());
                    DataTable tablaInfoCiudad = _coberturaMODULO.obtenerNombreCiudadPorIdCiudad(ID_CIUDAD);
                    DataRow filaTablaInfoCiudad = tablaInfoCiudad.Rows[0];

                    configurarInfoAdicionalModulo(true, filaTablaInfoCiudad["NOMBRE"].ToString());

                    Panel_COPIA_CONDICIONES_ECONOMICAS_GRUPO_EMPRESARIAL.Visible = false;
                }
                else
                {
                    cliente _clienteMODULO = new cliente(Session["idEmpresa"].ToString(), Session["USU_LOG"].ToString());
                    DataTable tablaInfoCliente = _clienteMODULO.ObtenerEmpresaConIdEmpresa(ID_EMPRESA);
                    DataRow filaTablaInfoCliente = tablaInfoCliente.Rows[0];

                    configurarInfoAdicionalModulo(true, filaTablaInfoCliente["RAZ_SOCIAL"].ToString());
                    Panel_COPIA_CONDICIONES_ECONOMICAS_GRUPO_EMPRESARIAL.Visible = true;
                }
            }
        }

        condicionComercial _condicionComercial = new condicionComercial(Session["idEmpresa"].ToString(), Session["USU_LOG"].ToString());

        DataTable tablaCondiciones = _condicionComercial.ObtenerCondicionesEconomicasPorId(ID_EMPRESA, ID_CIUDAD, ID_CENTRO_C, ID_SUB_C);
        if (tablaCondiciones.Rows.Count <= 0)
        {
            if (_condicionComercial.MensajeError != null)
            {
                if ((String.IsNullOrEmpty(ID_CIUDAD) == true) && (ID_CENTRO_C == 0) && (ID_SUB_C == 0))
                {
                    configurarBotonesDeAccion(false, false, false, false);
                }
                else
                {
                    configurarBotonesDeAccion(false, false, false, true);
                }

                Panel_FORMULARIO.Visible = false;

                Panel_SECCION_SERVICIOS.Visible = false;

                Panel_ESTRUCTURA_CENTRO_COSTOS.Visible = false;

                configurarMensajes(true, System.Drawing.Color.Red);
                Label_MENSAJE.Text = _condicionComercial.MensajeError;

                Panel_COPIA_CONDICIONES_ECONOMICAS_GRUPO_EMPRESARIAL.Visible = false;
            }
            else
            {
                if ((String.IsNullOrEmpty(ID_CIUDAD) == true) && (ID_CENTRO_C == 0) && (ID_SUB_C == 0))
                {
                    configurarBotonesDeAccion(false, true, true, false);
                }
                else
                {
                    configurarBotonesDeAccion(false, true, true, true);
                }

                Panel_FORMULARIO.Visible = true;

                Panel_SECCION_SERVICIOS.Visible = false;

                Panel_ESTRUCTURA_CENTRO_COSTOS.Visible = true;

                controlesParaNuevaCondicionEconomica();

                if ((String.IsNullOrEmpty(ID_CIUDAD) == true) && (ID_CENTRO_C == 0) && (ID_SUB_C == 0))
                {
                    Panel_ESTRUCTURA_CENTRO_COSTOS.Visible = true;
                    cargarEstructuraDeCC();

                    configurarMensajesCC(true, System.Drawing.Color.Red);
                    Label_MENSAJE_CC.Text = "Por favor seleccionar una ciudad de la lista de cobertura.";

                    configurarMensajesSUBCC(true, System.Drawing.Color.Red);
                    Label_MENSAJE_SUB_CC.Text = "Por favor seleccionar un centro de costo de la lista de centros de costo.";
                }
                else
                {
                    Panel_ESTRUCTURA_CENTRO_COSTOS.Visible = false;
                }
            }
        }
        else
        {

            if (bModificar == true)
            {
                if ((String.IsNullOrEmpty(ID_CIUDAD) == true) && (ID_CENTRO_C == 0) && (ID_SUB_C == 0))
                {
                    configurarBotonesDeAccion(false, true, true, false);
                }
                else
                {
                    configurarBotonesDeAccion(false, true, true, true);
                }

                Panel_FORMULARIO.Enabled = true;

                Panel_CONTROL_REGISTRO.Visible = false;

                Panel_COD_CONDICIONES.Visible = false;

                Panel_COPIA_CONDICIONES_ECONOMICAS_GRUPO_EMPRESARIAL.Visible = true;
                mostrar_modulo_copia_condiciones_grupoempresarial();

            }
            else
            {
                if ((String.IsNullOrEmpty(ID_CIUDAD) == true) && (ID_CENTRO_C == 0) && (ID_SUB_C == 0))
                {
                    configurarBotonesDeAccion(true, false, false, false);
                }
                else
                {
                    configurarBotonesDeAccion(true, false, false, true);
                }

                Panel_FORMULARIO.Enabled = false;

                Panel_CONTROL_REGISTRO.Visible = true;
                Panel_CONTROL_REGISTRO.Enabled = false;

                Panel_COD_CONDICIONES.Visible = true;
                Panel_COD_CONDICIONES.Enabled = false;

                Panel_COPIA_CONDICIONES_ECONOMICAS_GRUPO_EMPRESARIAL.Visible = false;
            }

            Panel_FORMULARIO.Visible = true;

            configurarMensajes(false, System.Drawing.Color.Green);

            DataRow infoCondicionesComerciales = tablaCondiciones.Rows[0];

            cargar_campos_condiciones_comerciales(infoCondicionesComerciales);

            DataTable tablaServiciosDeLaEntidad;
            if (ID_SUB_C != 0)
            {
                tablaServiciosDeLaEntidad = _condicionComercial.ObtenerServiciosPorEmpresaPorIdSubC(ID_SUB_C);

                Panel_COPIA_CONDICIONES_ECONOMICAS_GRUPO_EMPRESARIAL.Visible = false;
            }
            else
            {
                if (ID_CENTRO_C != 0)
                {
                    tablaServiciosDeLaEntidad = _condicionComercial.ObtenerServiciosPorEmpresaPorIdCentroC(ID_CENTRO_C);

                    Panel_COPIA_CONDICIONES_ECONOMICAS_GRUPO_EMPRESARIAL.Visible = false;
                }
                else
                {
                    if ((ID_EMPRESA != 0) && (String.IsNullOrEmpty(ID_CIUDAD) == false))
                    {
                        tablaServiciosDeLaEntidad = _condicionComercial.ObtenerServiciosPorEmpresaPorIdCiudad(ID_CIUDAD, ID_EMPRESA);

                        Panel_COPIA_CONDICIONES_ECONOMICAS_GRUPO_EMPRESARIAL.Visible = false;
                    }
                    else
                    {
                        tablaServiciosDeLaEntidad = _condicionComercial.ObtenerServiciosPorEmpresaPorIdEmpresa(ID_EMPRESA);

                    }
                }
            }

            if (tablaServiciosDeLaEntidad.Rows.Count <= 0)
            {
                habilitarSeccionServiciosParaDatosNuevos(bModificar);
            }
            else
            {

                List<servicio> listaServicios = new List<servicio>();
                Session.Remove("listaServicios_" + ID_EMPRESA.ToString());
                Session.Add("listaServicios_" + ID_EMPRESA.ToString(), listaServicios);
                List<detalleServicio> listaDetallesServicio = new List<detalleServicio>();
                Session.Remove("listaDetallesServicio_" + ID_EMPRESA.ToString());
                Session.Add("listaDetallesServicio_" + ID_EMPRESA.ToString(), listaDetallesServicio);

                cargarInformacionServiciosComplementariosDeUnaEntidad(tablaServiciosDeLaEntidad, bModificar, false);
            }

            if ((String.IsNullOrEmpty(ID_CIUDAD) == true) && (ID_CENTRO_C == 0) && (ID_SUB_C == 0))
            {
                Panel_ESTRUCTURA_CENTRO_COSTOS.Visible = true;
                cargarEstructuraDeCC();

                configurarMensajesCC(true, System.Drawing.Color.Red);
                Label_MENSAJE_CC.Text = "Por favor seleccionar una ciudad de la lista de cobertura.";

                configurarMensajesSUBCC(true, System.Drawing.Color.Red);
                Label_MENSAJE_SUB_CC.Text = "Por favor seleccionar un centro de costo de la lista de centros de costo.";
            }
            else
            {
                Panel_ESTRUCTURA_CENTRO_COSTOS.Visible = false;
            }
        }
    }
    private void cargar_GridView_CENTROS_DE_COSTO(Decimal ID_EMPRESA, String ID_CIUDAD)
    {
        centroCosto _centroCosto = new centroCosto(Session["idEmpresa"].ToString(), Session["USU_LOG"].ToString());

        DataTable tablaCCDeCiudad = _centroCosto.ObtenerCentrosDeCostoPorIdEmpresaIdCiudad(ID_EMPRESA, ID_CIUDAD);

        if (tablaCCDeCiudad.Rows.Count <= 0)
        {
            configurarMensajesCC(true, System.Drawing.Color.Red);
            Label_MENSAJE_COBERTURA.Text = "La Ciudad no tiene centros de costo actualmente.";
        }
        else
        {
            configurarMensajesCC(false, System.Drawing.Color.Red);

            GridView_CENTROS_DE_COSTO.DataSource = tablaCCDeCiudad;
            GridView_CENTROS_DE_COSTO.DataBind();

            DataRow filaEnTablaCC;
            condicionComercial _condicionComercial = new condicionComercial(Session["idEmpresa"].ToString(), Session["USU_LOG"].ToString());
            DataTable tablaCondicionesComercialesDeCC;

            subCentroCosto _subCentroCosto = new subCentroCosto(Session["idEmpresa"].ToString(), Session["USU_LOG"].ToString());
            DataTable tablaSUBCCDeCC;
            for (int i = 0; i < tablaCCDeCiudad.Rows.Count; i++)
            {
                filaEnTablaCC = tablaCCDeCiudad.Rows[i];

                tablaCondicionesComercialesDeCC = _condicionComercial.ObtenerCondicionesEconomicasPorId(ID_EMPRESA, null, Convert.ToDecimal(filaEnTablaCC["ID_CENTRO_C"]), 0);
                if (tablaCondicionesComercialesDeCC.Rows.Count <= 0)
                {
                    GridView_CENTROS_DE_COSTO.Rows[i].BackColor = colorNo;
                }
                else
                {
                    GridView_CENTROS_DE_COSTO.Rows[i].BackColor = colorSi;
                }

                tablaSUBCCDeCC = _subCentroCosto.ObtenerSubCentrosDeCostoPorIdEmpresaIdCentroCosto(ID_EMPRESA, Convert.ToDecimal(filaEnTablaCC["ID_CENTRO_C"]));
                if (tablaSUBCCDeCC.Rows.Count <= 0)
                {
                    GridView_CENTROS_DE_COSTO.Rows[i].Cells[2].Enabled = false;
                }
                else
                {
                    GridView_CENTROS_DE_COSTO.Rows[i].Cells[2].Enabled = true;
                }
            }
        }

        configurarMensajesSUBCC(true, System.Drawing.Color.Red);
        Label_MENSAJE_SUB_CC.Text = "Por favor seleccionar un centro de costo de la lista de centros de costo.";
        GridView_SUB_CENTROS_DE_COSTO.DataSource = null;
        GridView_SUB_CENTROS_DE_COSTO.DataBind();
    }
    private void controlesParaNuevaCondicionEconomica()
    {
        tools _tools = new tools();
        SecureQueryString QueryStringSeguro;
        QueryStringSeguro = new SecureQueryString(_tools.byteParaQueryStringSeguro(), Request["data"]);

        Decimal ID_EMPRESA = Convert.ToDecimal(QueryStringSeguro["reg"]);
        String ID_CIUDAD = null;
        Decimal ID_CENTRO_C = 0;
        Decimal ID_SUB_C = 0;

        try
        {
            ID_CIUDAD = QueryStringSeguro["codCiudad"].ToString();
        }
        catch
        {
            ID_CIUDAD = null;
        }

        try
        {
            ID_CENTRO_C = Convert.ToDecimal(QueryStringSeguro["codCC"]);
        }
        catch
        {
            ID_CENTRO_C = 0;
        }

        try
        {
            ID_SUB_C = Convert.ToDecimal(QueryStringSeguro["codSUBCC"]);
        }
        catch
        {
            ID_SUB_C = 0;
        }

        Decimal ID_EMPRESA_1 = ID_EMPRESA;
        String ID_CIUDAD_1 = null;
        Decimal ID_CENTRO_C_1 = 0;
        Decimal ID_SUB_C_1 = 0;

        if (ID_SUB_C != 0)
        {
            subCentroCosto _subCentroCosto = new subCentroCosto(Session["idEmpresa"].ToString(), Session["USU_LOG"].ToString());
            DataTable tablainfoSubCentro = _subCentroCosto.ObtenerSubCentrosDeCostoPorIdSubCosto(ID_SUB_C);
            DataRow infoSubCentro = tablainfoSubCentro.Rows[0];

            ID_EMPRESA_1 = ID_EMPRESA;
            ID_CIUDAD_1 = null;
            ID_CENTRO_C_1 = Convert.ToDecimal(infoSubCentro["ID_CENTRO_C"]);
            ID_SUB_C_1 = 0;
        }
        else
        {
            if (ID_CENTRO_C != 0)
            {
                centroCosto _centroCosto = new centroCosto(Session["idEmpresa"].ToString(), Session["USU_LOG"].ToString());
                DataTable tablaCentroCosto = _centroCosto.ObtenerCentrosDeCostoPorIdCentroCosto(ID_CENTRO_C);
                DataRow infoCentroCosto = tablaCentroCosto.Rows[0];

                ID_EMPRESA_1 = ID_EMPRESA;
                ID_CIUDAD_1 = infoCentroCosto["ID_CIUDAD"].ToString().Trim();
                ID_CENTRO_C_1 = 0;
                ID_SUB_C_1 = 0;
            }
        }

        condicionComercial _condicionComercial = new condicionComercial(Session["idEmpresa"].ToString(), Session["USU_LOG"].ToString());

        DataTable tablaCondicionesHeredadas = _condicionComercial.ObtenerCondicionesEconomicasPorId(ID_EMPRESA_1, ID_CIUDAD_1, ID_CENTRO_C_1, ID_SUB_C_1);

        if (tablaCondicionesHeredadas.Rows.Count <= 0)
        {
            if (_condicionComercial.MensajeError != null)
            {
                configurarBotonesDeAccion(false, false, false, true);

                Panel_FORMULARIO.Visible = false;

                configurarMensajes(true, System.Drawing.Color.Red);
                Label_MENSAJE.Text = _condicionComercial.MensajeError;
            }
            else
            {
                configurarBotonesDeAccion(false, true, true, true);

                Panel_FORMULARIO.Visible = true;

                Panel_SERVICIOS_COMPLEMENTARIOS.Visible = false;

                configurarMensajes(true, System.Drawing.Color.Red);
                Label_MENSAJE.Text = "ADVERTENCIA: No se encontraron registros de condiciones económicas para mostrar y la entidad anterior no tiene condiciones económicas para heredar, por favor digitelas y guarde.";

                Panel_CONTROL_REGISTRO.Visible = false;

                Panel_COD_CONDICIONES.Visible = false;

                CheckBox_FACTURA_NOMINA.Checked = false;

                cargar_DropDownList_MOD_SOPORTE();
                cargar_DropDownList_MOD_FACTURA();

                TextBox_AD_NOM.Text = "0";
                CheckBox_SOLO_DEV.Checked = false;

                TextBox_AD_PENSION.Text = "0";
                TextBox_AD_SALUD.Text = "0";
                TextBox_AD_RIESGOS.Text = "0";
                TextBox_AD_APO_SENA.Text = "0";
                TextBox_AD_APO_ICBF.Text = "0";
                TextBox_AD_APO_CAJA.Text = "0";
                TextBox_AD_VACACIONES.Text = "0";
                TextBox_AD_CESANTIA.Text = "0";
                TextBox_AD_INT_CES.Text = "0";
                TextBox_AD_PRIMA.Text = "0";
                TextBox_AD_SEG_VID.Text = "0";

                CheckBox_SUB_PENSION.Checked = false;
                CheckBox_SUB_SALUD.Checked = false;
                CheckBox_SUB_RIESGO.Checked = false;
                CheckBox_SUB_SENA.Checked = false;
                CheckBox_SUB_ICBF.Checked = false;
                CheckBox_SUB_CAJA.Checked = false;
                CheckBox_SUB_VACACIONES.Checked = false;
                CheckBox_SUB_CESANTIAS.Checked = false;
                CheckBox_SUB_INT_CES.Checked = false;
                CheckBox_SUB_PRIMA.Checked = false;
                CheckBox_SUB_SEG_VID.Checked = false;

                CheckBox_RET_VAC.Checked = false;
                CheckBox_RET_CES.Checked = false;
                CheckBox_RET_INT_CES.Checked = false;
                CheckBox_RET_PRIM.Checked = false;

                TextBox_DIAS_VNC.Text = "";

                cargar_DropDownList_REGIMEN();

                TextBox_OBS_FACT.Text = "";

                List<servicio> listaServicios = new List<servicio>();
                Session.Remove("listaServicios_" + ID_EMPRESA.ToString());
                Session.Add("listaServicios_" + ID_EMPRESA.ToString(), listaServicios);
                List<detalleServicio> listaDetallesServicio = new List<detalleServicio>();
                Session.Remove("listaDetallesServicio_" + ID_EMPRESA.ToString());
                Session.Add("listaDetallesServicio_" + ID_EMPRESA.ToString(), listaDetallesServicio);

                CheckBox_ACTIVAR_SERVICIO_COMPLEMENTARIO.Checked = false;
                cargarTextCheckActivarServicios(ID_EMPRESA, ID_CIUDAD, ID_CENTRO_C, ID_SUB_C, "sin");
                Panel_SERVICIOS_COMPLEMENTARIOS.Visible = false;
            }
        }
        else
        {
            configurarBotonesDeAccion(false, true, true, true);

            Panel_FORMULARIO.Visible = true;
            Panel_FORMULARIO.Enabled = true;

            configurarMensajes(true, System.Drawing.Color.Red);
            Label_MENSAJE.Text = "ADVERTENCIA: No se encontraron registros de condiciones económicas para mostrar, pero se heredaron las condiciones económicas desde la entidad anterior, REALICE LOS CAMBIOS NECESARIOS Y GUARDE LA INFORMACIÓN.";

            DataRow infoCondicionesComerciales = tablaCondicionesHeredadas.Rows[0];

            Panel_CONTROL_REGISTRO.Visible = false;

            Panel_COD_CONDICIONES.Visible = false;

            if (infoCondicionesComerciales["FACTURA"].ToString().Trim() == "N")
            {
                CheckBox_FACTURA_NOMINA.Checked = false;
            }
            else
            {
                if (infoCondicionesComerciales["FACTURA"].ToString().Trim() == "S")
                {
                    CheckBox_FACTURA_NOMINA.Checked = true;
                }
            }

            cargar_DropDownList_MOD_SOPORTE();
            DropDownList_MOD_SOPORTE.SelectedValue = infoCondicionesComerciales["MOD_SOPORTE"].ToString().Trim();
            cargar_DropDownList_MOD_FACTURA();
            DropDownList_MOD_FACTURA.SelectedValue = infoCondicionesComerciales["MOD_FACTURA"].ToString().Trim();

            TextBox_AD_NOM.Text = String.Format("{0:N2}", Convert.ToDecimal(infoCondicionesComerciales["AD_NOM"]));

            if (infoCondicionesComerciales["SOLO_DEV"].ToString().Trim() == "N")
            {
                CheckBox_SOLO_DEV.Checked = false;
            }
            else
            {
                if (infoCondicionesComerciales["SOLO_DEV"].ToString().Trim() == "S")
                {
                    CheckBox_SOLO_DEV.Checked = true;
                }
            }

            TextBox_AD_PENSION.Text = String.Format("{0:N2}", Convert.ToDecimal(infoCondicionesComerciales["AD_PENSION"]));
            TextBox_AD_SALUD.Text = String.Format("{0:N2}", Convert.ToDecimal(infoCondicionesComerciales["AD_SALUD"]));
            TextBox_AD_RIESGOS.Text = String.Format("{0:N2}", Convert.ToDecimal(infoCondicionesComerciales["AD_RIESGOS"]));
            TextBox_AD_APO_SENA.Text = String.Format("{0:N2}", Convert.ToDecimal(infoCondicionesComerciales["AD_APO_SENA"]));
            TextBox_AD_APO_ICBF.Text = String.Format("{0:N2}", Convert.ToDecimal(infoCondicionesComerciales["AD_APO_ICBF"]));
            TextBox_AD_APO_CAJA.Text = String.Format("{0:N2}", Convert.ToDecimal(infoCondicionesComerciales["AD_APO_CAJA"]));
            TextBox_AD_VACACIONES.Text = String.Format("{0:N2}", Convert.ToDecimal(infoCondicionesComerciales["AD_VACACIONES"]));
            TextBox_AD_CESANTIA.Text = String.Format("{0:N2}", Convert.ToDecimal(infoCondicionesComerciales["AD_CESANTIA"]));
            TextBox_AD_INT_CES.Text = String.Format("{0:N2}", Convert.ToDecimal(infoCondicionesComerciales["AD_INT_CES"]));
            TextBox_AD_PRIMA.Text = String.Format("{0:N2}", Convert.ToDecimal(infoCondicionesComerciales["AD_PRIMA"]));
            TextBox_AD_SEG_VID.Text = String.Format("{0:N2}", Convert.ToDecimal(infoCondicionesComerciales["AD_SEG_VID"]));

            cargarCheckBox(CheckBox_SUB_PENSION, infoCondicionesComerciales["SUB_PENSION"].ToString().Trim());
            cargarCheckBox(CheckBox_SUB_SALUD, infoCondicionesComerciales["SUB_SALUD"].ToString().Trim());
            cargarCheckBox(CheckBox_SUB_RIESGO, infoCondicionesComerciales["SUB_RIESGOS"].ToString().Trim());
            cargarCheckBox(CheckBox_SUB_SENA, infoCondicionesComerciales["SUB_SENA"].ToString().Trim());
            cargarCheckBox(CheckBox_SUB_ICBF, infoCondicionesComerciales["SUB_ICBF"].ToString().Trim());
            cargarCheckBox(CheckBox_SUB_CAJA, infoCondicionesComerciales["SUB_CAJA"].ToString().Trim());
            cargarCheckBox(CheckBox_SUB_VACACIONES, infoCondicionesComerciales["SUB_VACACIONES"].ToString().Trim());
            cargarCheckBox(CheckBox_SUB_CESANTIAS, infoCondicionesComerciales["SUB_CESANTIAS"].ToString().Trim());
            cargarCheckBox(CheckBox_SUB_INT_CES, infoCondicionesComerciales["SUB_INT_CES"].ToString().Trim());
            cargarCheckBox(CheckBox_SUB_PRIMA, infoCondicionesComerciales["SUB_PRIMA"].ToString().Trim());
            cargarCheckBox(CheckBox_SUB_SEG_VID, infoCondicionesComerciales["SUB_SEG_VID"].ToString().Trim());

            cargarCheckBox(CheckBox_RET_VAC, infoCondicionesComerciales["RET_VAC"].ToString().Trim());
            cargarCheckBox(CheckBox_RET_CES, infoCondicionesComerciales["RET_CES"].ToString().Trim());
            cargarCheckBox(CheckBox_RET_INT_CES, infoCondicionesComerciales["RET_INT_CES"].ToString().Trim());
            cargarCheckBox(CheckBox_RET_PRIM, infoCondicionesComerciales["RET_PRIM"].ToString().Trim());

            TextBox_DIAS_VNC.Text = infoCondicionesComerciales["DIAS_VNC"].ToString().Trim();

            cargar_DropDownList_REGIMEN();
            DropDownList_REGIMEN.SelectedValue = infoCondicionesComerciales["REGIMEN"].ToString().Trim();

            TextBox_OBS_FACT.Text = infoCondicionesComerciales["OBS_FACT"].ToString().Trim();

            DataTable tablaServiciosEspecificos;

            if (ID_SUB_C != 0)
            {
                tablaServiciosEspecificos = _condicionComercial.ObtenerServiciosPorEmpresaPorIdCentroC(ID_CENTRO_C_1);
            }
            else
            {
                if (ID_CENTRO_C != 0)
                {
                    tablaServiciosEspecificos = _condicionComercial.ObtenerServiciosPorEmpresaPorIdCiudad(ID_CIUDAD_1, ID_EMPRESA_1);
                }
                else
                {
                    tablaServiciosEspecificos = _condicionComercial.ObtenerServiciosPorEmpresaPorIdEmpresa(ID_EMPRESA_1);
                }
            }

            if (tablaServiciosEspecificos.Rows.Count <= 0)
            {
                CheckBox_ACTIVAR_SERVICIO_COMPLEMENTARIO.Checked = false;
                cargarTextCheckActivarServicios(ID_EMPRESA, ID_CIUDAD, ID_CENTRO_C, ID_SUB_C, "sin");
                Panel_SERVICIOS_COMPLEMENTARIOS.Visible = false;

                List<servicio> listaServicios = new List<servicio>();
                Session.Remove("listaServicios_" + ID_EMPRESA.ToString());
                Session.Add("listaServicios_" + ID_EMPRESA.ToString(), listaServicios);
                List<detalleServicio> listaDetallesServicio = new List<detalleServicio>();
                Session.Remove("listaDetallesServicio_" + ID_EMPRESA.ToString());
                Session.Add("listaDetallesServicio_" + ID_EMPRESA.ToString(), listaDetallesServicio);
            }
            else
            {
                CheckBox_ACTIVAR_SERVICIO_COMPLEMENTARIO.Checked = true;
                cargarTextCheckActivarServicios(ID_EMPRESA, ID_CIUDAD, ID_CENTRO_C, ID_SUB_C, "con");
                Panel_SERVICIOS_COMPLEMENTARIOS.Visible = true;
                configurarMensajesServicioComplementario(false, System.Drawing.Color.Green);
                cargarInformacionServiciosComplementariosEspecificos(tablaServiciosEspecificos, true);

                Panel_SERVICIOS_COMPLEMENTARIOS_ADICIONAR.Visible = true;
            }
        }
    }
    private void cargarInfoCondiciones(Boolean bModificar)
    {
        tools _tools = new tools();
        SecureQueryString QueryStringSeguro;
        QueryStringSeguro = new SecureQueryString(_tools.byteParaQueryStringSeguro(), Request["data"]);

        Decimal ID_EMPRESA = Convert.ToDecimal(QueryStringSeguro["reg"]);
        String ID_CIUDAD = null;
        Decimal ID_CENTRO_C = 0;
        Decimal ID_SUB_C = 0;

        try
        {
            ID_CIUDAD = QueryStringSeguro["codCiudad"].ToString();
        }
        catch
        {
            ID_CIUDAD = null;
        }

        try
        {
            ID_CENTRO_C = Convert.ToDecimal(QueryStringSeguro["codCC"]);
        }
        catch
        {
            ID_CENTRO_C = 0;
        }

        try
        {
            ID_SUB_C = Convert.ToDecimal(QueryStringSeguro["codSUBCC"]);
        }
        catch
        {
            ID_SUB_C = 0;
        }

        if (ID_SUB_C != 0)
        {
            subCentroCosto _subCentroCostoMODULO = new subCentroCosto(Session["idEmpresa"].ToString(), Session["USU_LOG"].ToString());
            DataTable tablaInfoSubCentro = _subCentroCostoMODULO.ObtenerSubCentrosDeCostoPorIdSubCosto(ID_SUB_C);
            DataRow filaTablaInfoSubCentro = tablaInfoSubCentro.Rows[0];

            configurarInfoAdicionalModulo(true, filaTablaInfoSubCentro["NOM_SUB_C"].ToString());
        }
        else
        {
            if (ID_CENTRO_C != 0)
            {
                centroCosto _centroCostoMODULO = new centroCosto(Session["idEmpresa"].ToString(), Session["USU_LOG"].ToString());
                DataTable tablaInfoCC = _centroCostoMODULO.ObtenerCentrosDeCostoPorIdCentroCosto(ID_CENTRO_C);
                DataRow filaTablaInfoCC = tablaInfoCC.Rows[0];

                configurarInfoAdicionalModulo(true, filaTablaInfoCC["NOM_CC"].ToString());
            }
            else
            {
                if ((String.IsNullOrEmpty(ID_CIUDAD) == false) && (ID_EMPRESA != 0))
                {
                    cobertura _coberturaMODULO = new cobertura(Session["idEmpresa"].ToString());
                    DataTable tablaInfoCiudad = _coberturaMODULO.obtenerNombreCiudadPorIdCiudad(ID_CIUDAD);
                    DataRow filaTablaInfoCiudad = tablaInfoCiudad.Rows[0];

                    configurarInfoAdicionalModulo(true, filaTablaInfoCiudad["NOMBRE"].ToString());
                }
                else
                {
                    cliente _clienteMODULO = new cliente(Session["idEmpresa"].ToString(), Session["USU_LOG"].ToString());
                    DataTable tablaInfoCliente = _clienteMODULO.ObtenerEmpresaConIdEmpresa(ID_EMPRESA);
                    DataRow filaTablaInfoCliente = tablaInfoCliente.Rows[0];

                    configurarInfoAdicionalModulo(true, filaTablaInfoCliente["RAZ_SOCIAL"].ToString());
                }
            }
        }

        condicionComercial _condicionComercial = new condicionComercial(Session["idEmpresa"].ToString(), Session["USU_LOG"].ToString());

        DataTable tablaCondiciones = _condicionComercial.ObtenerCondicionesEconomicasPorId(ID_EMPRESA, ID_CIUDAD, ID_CENTRO_C, ID_SUB_C);
        if (tablaCondiciones.Rows.Count <= 0)
        {
            if (_condicionComercial.MensajeError != null)
            {
                configurarBotonesDeAccion(false, false, false, true);

                Panel_FORMULARIO.Visible = false;

                configurarMensajes(true, System.Drawing.Color.Red);
                Label_MENSAJE.Text = _condicionComercial.MensajeError;
            }
            else
            {
                configurarBotonesDeAccion(false, true, true, true);

                Panel_FORMULARIO.Visible = true;

                Panel_SERVICIOS_COMPLEMENTARIOS.Visible = false;

                controlesParaNuevaCondicionEconomica();
            }
        }
        else
        {
            if (bModificar == true)
            {
                configurarBotonesDeAccion(false, true, true, true);
            }
            else
            {
                configurarBotonesDeAccion(true, false, false, true);
            }

            Panel_FORMULARIO.Visible = true;
            if (bModificar == true)
            {
                Panel_FORMULARIO.Enabled = true;
            }
            else
            {
                Panel_FORMULARIO.Enabled = false;
            }

            configurarMensajes(false, System.Drawing.Color.Green);

            DataRow infoCondicionesComerciales = tablaCondiciones.Rows[0];

            if (bModificar == false)
            {
                Panel_CONTROL_REGISTRO.Visible = true;
                Panel_CONTROL_REGISTRO.Enabled = false;
                TextBox_USU_CRE.Text = infoCondicionesComerciales["USU_CRE"].ToString();
                try
                {
                    TextBox_FCH_CRE.Text = DateTime.Parse(infoCondicionesComerciales["FCH_CRE"].ToString()).ToShortDateString();
                    TextBox_HOR_CRE.Text = DateTime.Parse(infoCondicionesComerciales["FCH_CRE"].ToString()).ToShortTimeString();
                }
                catch
                {
                    TextBox_FCH_CRE.Text = "";
                    TextBox_HOR_CRE.Text = "";
                }
                TextBox_USU_MOD.Text = infoCondicionesComerciales["USU_MOD"].ToString();
                try
                {
                    TextBox_FCH_MOD.Text = DateTime.Parse(infoCondicionesComerciales["FCH_MOD"].ToString()).ToShortDateString();
                    TextBox_HOR_MOD.Text = DateTime.Parse(infoCondicionesComerciales["FCH_MOD"].ToString()).ToShortTimeString();
                }
                catch
                {
                    TextBox_FCH_MOD.Text = "";
                    TextBox_HOR_MOD.Text = "";
                }
            }
            else
            {
                Panel_CONTROL_REGISTRO.Visible = false;
            }

            if (bModificar == false)
            {
                Panel_COD_CONDICIONES.Visible = true;
                Panel_COD_CONDICIONES.Enabled = false;
                TextBox_COD_CONDICION.Text = infoCondicionesComerciales["REGISTRO"].ToString().Trim();
            }
            else
            {
                Panel_COD_CONDICIONES.Visible = false;
            }

            if (infoCondicionesComerciales["FACTURA"].ToString().Trim() == "N")
            {
                CheckBox_FACTURA_NOMINA.Checked = false;
            }
            else
            {
                if (infoCondicionesComerciales["FACTURA"].ToString().Trim() == "S")
                {
                    CheckBox_FACTURA_NOMINA.Checked = true;
                }
            }

            cargar_DropDownList_MOD_SOPORTE();
            DropDownList_MOD_SOPORTE.SelectedValue = infoCondicionesComerciales["MOD_SOPORTE"].ToString().Trim();
            cargar_DropDownList_MOD_FACTURA();
            DropDownList_MOD_FACTURA.SelectedValue = infoCondicionesComerciales["MOD_FACTURA"].ToString().Trim();

            TextBox_AD_NOM.Text = String.Format("{0:N2}",Convert.ToDecimal(infoCondicionesComerciales["AD_NOM"]));

            if (infoCondicionesComerciales["SOLO_DEV"].ToString().Trim() == "N")
            {
                CheckBox_SOLO_DEV.Checked = false;
            }
            else
            {
                if (infoCondicionesComerciales["SOLO_DEV"].ToString().Trim() == "S")
                {
                    CheckBox_SOLO_DEV.Checked = true;
                }
            }

            TextBox_AD_PENSION.Text = String.Format("{0:N2}",Convert.ToDecimal(infoCondicionesComerciales["AD_PENSION"]));
            TextBox_AD_SALUD.Text = String.Format("{0:N2}",Convert.ToDecimal(infoCondicionesComerciales["AD_SALUD"]));
            TextBox_AD_RIESGOS.Text = String.Format("{0:N2}",Convert.ToDecimal(infoCondicionesComerciales["AD_RIESGOS"]));
            TextBox_AD_APO_SENA.Text = String.Format("{0:N2}",Convert.ToDecimal(infoCondicionesComerciales["AD_APO_SENA"]));
            TextBox_AD_APO_ICBF.Text = String.Format("{0:N2}",Convert.ToDecimal(infoCondicionesComerciales["AD_APO_ICBF"]));
            TextBox_AD_APO_CAJA.Text = String.Format("{0:N2}",Convert.ToDecimal(infoCondicionesComerciales["AD_APO_CAJA"]));
            TextBox_AD_VACACIONES.Text = String.Format("{0:N2}",Convert.ToDecimal(infoCondicionesComerciales["AD_VACACIONES"]));
            TextBox_AD_CESANTIA.Text = String.Format("{0:N2}",Convert.ToDecimal(infoCondicionesComerciales["AD_CESANTIA"]));
            TextBox_AD_INT_CES.Text = String.Format("{0:N2}",Convert.ToDecimal(infoCondicionesComerciales["AD_INT_CES"]));
            TextBox_AD_PRIMA.Text = String.Format("{0:N2}",Convert.ToDecimal(infoCondicionesComerciales["AD_PRIMA"]));
            TextBox_AD_SEG_VID.Text = String.Format("{0:N2}",Convert.ToDecimal(infoCondicionesComerciales["AD_SEG_VID"]));

            cargarCheckBox(CheckBox_SUB_PENSION,infoCondicionesComerciales["SUB_PENSION"].ToString().Trim());
            cargarCheckBox(CheckBox_SUB_SALUD, infoCondicionesComerciales["SUB_SALUD"].ToString().Trim());
            cargarCheckBox(CheckBox_SUB_RIESGO, infoCondicionesComerciales["SUB_RIESGOS"].ToString().Trim());
            cargarCheckBox(CheckBox_SUB_SENA, infoCondicionesComerciales["SUB_SENA"].ToString().Trim());
            cargarCheckBox(CheckBox_SUB_ICBF, infoCondicionesComerciales["SUB_ICBF"].ToString().Trim());
            cargarCheckBox(CheckBox_SUB_CAJA, infoCondicionesComerciales["SUB_CAJA"].ToString().Trim());
            cargarCheckBox(CheckBox_SUB_VACACIONES, infoCondicionesComerciales["SUB_VACACIONES"].ToString().Trim());
            cargarCheckBox(CheckBox_SUB_CESANTIAS, infoCondicionesComerciales["SUB_CESANTIAS"].ToString().Trim());
            cargarCheckBox(CheckBox_SUB_INT_CES, infoCondicionesComerciales["SUB_INT_CES"].ToString().Trim());
            cargarCheckBox(CheckBox_SUB_PRIMA, infoCondicionesComerciales["SUB_PRIMA"].ToString().Trim());
            cargarCheckBox(CheckBox_SUB_SEG_VID, infoCondicionesComerciales["SUB_SEG_VID"].ToString().Trim());

            cargarCheckBox(CheckBox_RET_VAC, infoCondicionesComerciales["RET_VAC"].ToString().Trim());
            cargarCheckBox(CheckBox_RET_CES, infoCondicionesComerciales["RET_CES"].ToString().Trim());
            cargarCheckBox(CheckBox_RET_INT_CES, infoCondicionesComerciales["RET_INT_CES"].ToString().Trim());
            cargarCheckBox(CheckBox_RET_PRIM, infoCondicionesComerciales["RET_PRIM"].ToString().Trim());

            TextBox_DIAS_VNC.Text = infoCondicionesComerciales["DIAS_VNC"].ToString().Trim();

            cargar_DropDownList_REGIMEN();
            DropDownList_REGIMEN.SelectedValue = infoCondicionesComerciales["REGIMEN"].ToString().Trim();

            TextBox_OBS_FACT.Text = infoCondicionesComerciales["OBS_FACT"].ToString().Trim();

            DataTable tablaServiciosEspecificos;

            if (ID_SUB_C != 0)
            {
                tablaServiciosEspecificos = _condicionComercial.ObtenerServiciosPorEmpresaPorIdSubC(ID_SUB_C);
            }
            else
            {
                if (ID_CENTRO_C != 0)
                {
                    tablaServiciosEspecificos = _condicionComercial.ObtenerServiciosPorEmpresaPorIdCentroC(ID_CENTRO_C);
                }
                else
                {
                    if ((ID_EMPRESA != 0) && (String.IsNullOrEmpty(ID_CIUDAD) == false))
                    {
                        tablaServiciosEspecificos = _condicionComercial.ObtenerServiciosPorEmpresaPorIdCiudad(ID_CIUDAD, ID_EMPRESA);
                    }
                    else
                    {
                        tablaServiciosEspecificos = _condicionComercial.ObtenerServiciosPorEmpresaPorIdEmpresa(ID_EMPRESA);
                    }
                }
            }

            if (tablaServiciosEspecificos.Rows.Count <= 0)
            {
                CheckBox_ACTIVAR_SERVICIO_COMPLEMENTARIO.Checked = false;
                cargarTextCheckActivarServicios(ID_EMPRESA, ID_CIUDAD, ID_CENTRO_C, ID_SUB_C, "sin");
                Panel_SERVICIOS_COMPLEMENTARIOS.Visible = false;

                List<servicio> listaServicios = new List<servicio>();
                Session.Remove("listaServicios_" + ID_EMPRESA.ToString());
                Session.Add("listaServicios_" + ID_EMPRESA.ToString(), listaServicios);
                List<detalleServicio> listaDetallesServicio = new List<detalleServicio>();
                Session.Remove("listaDetallesServicio_" + ID_EMPRESA.ToString());
                Session.Add("listaDetallesServicio_" + ID_EMPRESA.ToString(), listaDetallesServicio);
            }
            else
            {
                CheckBox_ACTIVAR_SERVICIO_COMPLEMENTARIO.Checked = true;
                cargarTextCheckActivarServicios(ID_EMPRESA, ID_CIUDAD, ID_CENTRO_C, ID_SUB_C, "con");
                Panel_SERVICIOS_COMPLEMENTARIOS.Visible = true;
                configurarMensajesServicioComplementario(false, System.Drawing.Color.Green);
                cargarInformacionServiciosComplementariosEspecificos(tablaServiciosEspecificos, false);

                if (bModificar == true)
                {
                    Panel_SERVICIOS_COMPLEMENTARIOS_ADICIONAR.Visible = true;
                }
                else
                {
                    Panel_SERVICIOS_COMPLEMENTARIOS_ADICIONAR.Visible = false;
                }
            }
        }
    }
    protected void Button_EMPEZAR_CONFIGURACION_Click(object sender, EventArgs e)
    {
        Decimal ID_EMPRESA = Convert.ToDecimal(HiddenField_ID_EMPRESA.Value);
        Decimal ID_PERFIL = Convert.ToDecimal(HiddenField_ID_PERFIL.Value);

        Boolean verificador = true;
        verificador = determinarIDsSubCCentrosCCiudad();

        if (verificador == true)
        {
            servicio _servicio = new servicio(Session["idEmpresa"].ToString(), Session["USU_LOG"].ToString());
            DataTable tablaServiciosComplementariosAsociados;

            condicionesContratacion _condicionesContratacion = new condicionesContratacion(Session["idEmpresa"].ToString(), Session["USU_LOG"].ToString());
            DataTable tablaCondicionContratacion;

            condicionComercial _condicionComercial = new condicionComercial(Session["idEmpresa"].ToString(), Session["USU_LOG"].ToString());
            DataTable tablaCondicionComercial;

            tablaCondicionContratacion = _condicionesContratacion.ObtenerCondicionContratacionPorUbicacion(ID_PERFIL, GLO_ID_CIUDAD, GLO_ID_CENTRO_C, GLO_ID_SUB_C, GLO_ID_SERVICIO);
            tablaServiciosComplementariosAsociados = _servicio.ObtenerServiciosComplementariosPorUbicacion(GLO_ID_CIUDAD, GLO_ID_CENTRO_C, GLO_ID_SUB_C, GLO_ID_SERVICIO);

            if (tablaCondicionContratacion.Rows.Count > 0)
            {
                Informar(Panel_FONDO_MENSAJE, Image_MENSAJE_POPUP, Panel_MENSAJES, Label_MENSAJE, "La UBICACIÓN, PERFIL Y/Ó SERVICIO seleccionado YA POSEE CONDICIONES DE CONTRATACIÓN configuradas.", Proceso.Advertencia);
            }
            else
            {
                tablaCondicionComercial = _condicionComercial.ObtenerCondicionesEconomicasPorId(ID_EMPRESA, GLO_ID_CIUDAD, GLO_ID_CENTRO_C, GLO_ID_SUB_C);

                if (tablaCondicionComercial.Rows.Count <= 0)
                {
                    EnviarCorreoAComercial();
                }

                Ocultar(Acciones.Inicio);
                Desactivar(Acciones.Inicio);
                Mostrar(Acciones.NuevaCondicionSegundaParte);
                Activar(Acciones.NuevaCondicionSegundaParte);

                CargarInterfazNuevaCondicionSegundaParte(tablaServiciosComplementariosAsociados);
            }
        }
        else
        {
            Informar(Panel_FONDO_MENSAJE, Image_MENSAJE_POPUP, Panel_MENSAJES, Label_MENSAJE, "Debe seleccionar por lo mínimo una ciudad, para aplicar nuevas condiciones.", Proceso.Advertencia);
        }
    }
    private void cargarInfoCondiciones(Boolean bModificar)
    {
        tools _tools = new tools();
        SecureQueryString QueryStringSeguro;
        QueryStringSeguro = new SecureQueryString(_tools.byteParaQueryStringSeguro(), Request["data"].ToString());

        Decimal ID_EMPRESA = Convert.ToDecimal(QueryStringSeguro["reg"]);

        cliente _clienteMODULO = new cliente(Session["idEmpresa"].ToString(), Session["USU_LOG"].ToString());
        DataTable tablaInfoCliente = _clienteMODULO.ObtenerEmpresaConIdEmpresa(ID_EMPRESA);
        DataRow filaTablaInfoCliente = tablaInfoCliente.Rows[0];

        configurarInfoAdicionalModulo(true, filaTablaInfoCliente["RAZ_SOCIAL"].ToString());

        condicionComercial _condicionComercial = new condicionComercial(Session["idEmpresa"].ToString(), Session["USU_LOG"].ToString());

        DataTable tablaCondiciones = _condicionComercial.ObtenerCondicionesEconomicasPorId(ID_EMPRESA, null, 0, 0);
        if (tablaCondiciones.Rows.Count <= 0)
        {
            if (_condicionComercial.MensajeError != null)
            {
                configurarBotonesDeAccion(false, false, false);

                Panel_COPIA_CONDICIONES_ECONOMICAS_GRUPO_EMPRESARIAL.Visible = false;

                Panel_FORMULARIO.Visible = false;

                Panel_ESTRUCTURA_CENTRO_COSTOS.Visible = false;

                configurarMensajes(true, System.Drawing.Color.Red);
                Label_MENSAJE.Text = _condicionComercial.MensajeError;
            }
            else
            {
                configurarBotonesDeAccion(false, true, true);

                Panel_FORMULARIO.Visible = true;

                Panel_SERVICIOS_COMPLEMENTARIOS.Visible = false;

                Panel_ESTRUCTURA_CENTRO_COSTOS.Visible = true;

                configurarMensajes(true, System.Drawing.Color.Red);
                Label_MENSAJE.Text = "ADVERTENCIA: No se encontraron registros de condiciones económicas para mostrar, por favor digitelas y guarde.";

                controlesParaNuevaCondicionEconomica();

                cargarEstructuraDeCC();

                configurarMensajesCC(true, System.Drawing.Color.Red);
                Label_MENSAJE_CC.Text = "Por favor seleccionar una ciudad de la lista de cobertura.";

                configurarMensajesSUBCC(true, System.Drawing.Color.Red);
                Label_MENSAJE_SUB_CC.Text = "Por favor seleccionar un centro de costo de la lista de centros de costo.";
            }
        }
        else
        {
            Panel_FORMULARIO.Visible = true;

            if (bModificar == true)
            {
                configurarBotonesDeAccion(false, true, true);
                Panel_FORMULARIO.Enabled = true;

                Panel_CONTROL_REGISTRO.Visible = false;

                Panel_COD_CONDICIONES.Visible = false;

                Panel_COPIA_CONDICIONES_ECONOMICAS_GRUPO_EMPRESARIAL.Visible = true;

                mostrar_modulo_copia_condiciones_grupoempresarial();
            }
            else
            {
                configurarBotonesDeAccion(true, false, false);
                Panel_FORMULARIO.Enabled = false;

                Panel_CONTROL_REGISTRO.Visible = true;
                Panel_CONTROL_REGISTRO.Enabled = false;

                Panel_COD_CONDICIONES.Visible = true;
                Panel_COD_CONDICIONES.Enabled = false;

                Panel_COPIA_CONDICIONES_ECONOMICAS_GRUPO_EMPRESARIAL.Visible = false;

            }

            configurarMensajes(false, System.Drawing.Color.Green);

            DataRow infoCondicionesComerciales = tablaCondiciones.Rows[0];

            cargar_campos_condiciones_comerciales(infoCondicionesComerciales);

            DataTable tablaServiciosDeLaEmpresa = _condicionComercial.ObtenerServiciosPorEmpresaPorIdEmpresa(ID_EMPRESA);
            if (tablaServiciosDeLaEmpresa.Rows.Count <= 0)
            {
                CheckBox_ACTIVAR_SERVICIO_COMPLEMENTARIO.Checked = false;
                CheckBox_ACTIVAR_SERVICIO_COMPLEMENTARIO.Text = "Servicios complementarios para empresa";
                Panel_SERVICIOS_COMPLEMENTARIOS.Visible = false;

                List<servicio> listaServicios = new List<servicio>();
                Session.Remove("listaServicios_" + ID_EMPRESA.ToString());
                Session.Add("listaServicios_" + ID_EMPRESA.ToString(), listaServicios);
                List<detalleServicio> listaDetallesServicio = new List<detalleServicio>();
                Session.Remove("listaDetallesServicio_" + ID_EMPRESA.ToString());
                Session.Add("listaDetallesServicio_" + ID_EMPRESA.ToString(), listaDetallesServicio);
            }
            else
            {
                CheckBox_ACTIVAR_SERVICIO_COMPLEMENTARIO.Checked = true;
                CheckBox_ACTIVAR_SERVICIO_COMPLEMENTARIO.Text = "Empresa con servicios complementarios";
                Panel_SERVICIOS_COMPLEMENTARIOS.Visible = true;
                configurarMensajesServicioComplementario(false, System.Drawing.Color.Green);

                cargarInformacionServiciosComplementariosDeUnaEmpresa(tablaServiciosDeLaEmpresa, bModificar);
            }

            cargarEstructuraDeCC();

            configurarMensajesCC(true, System.Drawing.Color.Red);
            Label_MENSAJE_CC.Text = "Por favor seleccionar una ciudad de la lista de cobertura.";

            configurarMensajesSUBCC(true, System.Drawing.Color.Red);
            Label_MENSAJE_SUB_CC.Text = "Por favor seleccionar un centro de costo de la lista de centros de costo.";
        }
    }
    protected void Button_COPIAR_CONDICIONES_GRUPO_Click(object sender, EventArgs e)
    {
        Decimal ID_EMPRESA_SELECICONADA = Convert.ToDecimal(DropDownList_EMPRESAS_DEL_GRUPO.SelectedValue);

        condicionComercial _condicionComercial = new condicionComercial(Session["idEmpresa"].ToString(), Session["USU_LOG"].ToString());
        DataTable tablaCondiciones = _condicionComercial.ObtenerCondicionesEconomicasPorId(ID_EMPRESA_SELECICONADA, null, 0, 0);
        DataRow infoCondiciones = tablaCondiciones.Rows[0];

        cargar_campos_condiciones_comerciales(infoCondiciones);

        desactivar_o_eliminar_servicio_en_lista_de_session();

        List<servicio> listaServicio = capturarListaServiciosDesdeSession();
        List<detalleServicio> listaDetalles = capturarListaDetallesServicioDesdeSession();

        DataTable tablaServiciosDeLaEmpresa = _condicionComercial.ObtenerServiciosPorEmpresaPorIdEmpresa(ID_EMPRESA_SELECICONADA);
        if (tablaServiciosDeLaEmpresa.Rows.Count <= 0)
        {
            CheckBox_ACTIVAR_SERVICIO_COMPLEMENTARIO.Checked = false;
            CheckBox_ACTIVAR_SERVICIO_COMPLEMENTARIO.Text = "Servicios complementarios para empresa";
            Panel_SERVICIOS_COMPLEMENTARIOS.Visible = false;

            GridView_SERVICIOS_INCLUIDOS.DataSource = null;
            GridView_SERVICIOS_INCLUIDOS.DataBind();
        }
        else
        {
            CheckBox_ACTIVAR_SERVICIO_COMPLEMENTARIO.Checked = true;
            CheckBox_ACTIVAR_SERVICIO_COMPLEMENTARIO.Text = "Empresa con servicios complementarios";
            Panel_SERVICIOS_COMPLEMENTARIOS.Visible = true;
            configurarMensajesServicioComplementario(false, System.Drawing.Color.Green);

            cargarinformacionServiciosComplementariosDesdeCopiaGrupoEmpresarial(tablaServiciosDeLaEmpresa, true);
        }
    }