protected void btnSubir_Click(object sender, EventArgs e)
        {
            OperationResult objOperationResult = new OperationResult();
            CalendarBL      objCalendarBL      = new CalendarBL();
            calendarDto     objCalendarDto     = new calendarDto();
            PacientBL       objPacientBL       = new PacientBL();
            pacientDto      objPacientDto      = new pacientDto();
            PacientList     PacientList        = new PacientList();

            if (dpFechaInicio.SelectedDate.Value < DateTime.Now.Date)
            {
                Alert.ShowInTop("No se permite agendar con una fecha anterior a la actual.", "Error de validación");
                return;
            }

            string CalendarId;
            string PacientId = "";

            StringBuilder sbDatos = new StringBuilder();

            var ListaGrilla = (List <Sigesoft.Node.WinClient.BE.PacientList>)Session["_TempPacientList"];

            foreach (var item in ListaGrilla)
            {
                personDto objPersonDto = new personDto();
                //Validar si el trabajador existe
                objPersonDto = objPacientBL.GetPersonByNroDocument(ref objOperationResult, item.v_DocNumber);
                if (objPersonDto != null)
                {
                    objPersonDto.v_FirstName       = item.v_FirstName.Trim();
                    objPersonDto.v_FirstLastName   = item.v_FirstLastName.Trim();
                    objPersonDto.v_SecondLastName  = item.v_SecondLastName.Trim();
                    objPersonDto.i_DocTypeId       = item.i_DocTypeId;
                    objPersonDto.v_DocNumber       = item.v_DocNumber;
                    objPersonDto.i_SexTypeId       = item.i_SexTypeId;
                    objPersonDto.d_Birthdate       = item.d_Birthdate;
                    objPersonDto.i_LevelOfId       = -1;
                    objPersonDto.i_MaritalStatusId = -1;

                    objPersonDto.i_BloodGroupId           = -1;
                    objPersonDto.i_BloodFactorId          = -1;
                    objPersonDto.i_DepartmentId           = -1;
                    objPersonDto.i_ProvinceId             = -1;
                    objPersonDto.i_DistrictId             = -1;
                    objPersonDto.i_ResidenceInWorkplaceId = -1;
                    objPersonDto.i_TypeOfInsuranceId      = -1;
                    objPersonDto.i_OccupationTypeId       = -1;
                    objPersonDto.i_AltitudeWorkId         = -1;
                    objPersonDto.i_PlaceWorkId            = -1;
                    objPersonDto.i_Relationship           = -1;

                    objPersonDto.v_CurrentOccupation = item.v_CurrentOccupation;
                    objPacientBL.UpdatePacient(ref objOperationResult, objPersonDto, ((ClientSession)Session["objClientSession"]).GetAsList(), objPersonDto.v_DocNumber, objPersonDto.v_DocNumber);
                    PacientId = objPersonDto.v_PersonId;
                }
                else
                {
                    objPersonDto                          = new personDto();
                    objPersonDto.v_FirstName              = item.v_FirstName.Trim();
                    objPersonDto.v_FirstLastName          = item.v_FirstLastName.Trim();
                    objPersonDto.v_SecondLastName         = item.v_SecondLastName.Trim();
                    objPersonDto.i_DocTypeId              = item.i_DocTypeId;
                    objPersonDto.v_DocNumber              = item.v_DocNumber;
                    objPersonDto.i_SexTypeId              = item.i_SexTypeId;
                    objPersonDto.d_Birthdate              = item.d_Birthdate;
                    objPersonDto.i_LevelOfId              = -1;
                    objPersonDto.i_MaritalStatusId        = -1;
                    objPersonDto.i_BloodGroupId           = -1;
                    objPersonDto.i_BloodFactorId          = -1;
                    objPersonDto.i_DepartmentId           = -1;
                    objPersonDto.i_ProvinceId             = -1;
                    objPersonDto.i_DistrictId             = -1;
                    objPersonDto.i_ResidenceInWorkplaceId = -1;
                    objPersonDto.i_TypeOfInsuranceId      = -1;
                    objPersonDto.i_OccupationTypeId       = -1;
                    objPersonDto.i_AltitudeWorkId         = -1;
                    objPersonDto.i_PlaceWorkId            = -1;
                    objPersonDto.i_Relationship           = -1;
                    objPersonDto.v_Deducible              = 0;
                    //objPersonDto.v_Password = item.v_DocNumber;
                    objPersonDto.v_CurrentOccupation = item.v_CurrentOccupation;

                    PacientId = objPacientBL.AddPacient(ref objOperationResult, objPersonDto, ((ClientSession)Session["objClientSession"]).GetAsList());
                }

                var Verificar = objPacientBL.GetBlackList(ref objOperationResult, objPersonDto.v_PersonId);


                if (PacientId != null && Verificar == null)      // Se grabo el paciente y se lo agenda
                {
                    objCalendarDto.v_PersonId         = PacientId;
                    objCalendarDto.d_DateTimeCalendar = dpFechaInicio.SelectedDate.Value;
                    objCalendarDto.i_ServiceTypeId    = (int)ServiceType.Empresarial;
                    objCalendarDto.i_CalendarStatusId = (int)CalendarStatus.Agendado;
                    objCalendarDto.i_ServiceId        = (int)MasterService.Eso;
                    //objCalendarDto.v_ProtocolId = _ProtocolId;
                    //Obtener Id de Protocolo por medio del código del protocolo
                    var ProtocolId = oProtocolBL.ObtenerProtocoloIdPorCodigoProtocolo(ddlProtocoloId.SelectedText);
                    if (ProtocolId == null)
                    {
                        Alert.ShowInTop("El protocolo no existe en el sistema.", "ERRROR!");
                        return;
                    }
                    objCalendarDto.v_ProtocolId        = ProtocolId;
                    objCalendarDto.i_NewContinuationId = (int)modality.NuevoServicio;
                    objCalendarDto.i_LineStatusId      = (int)LineStatus.FueraCircuito;
                    objCalendarDto.i_IsVipId           = (int)SiNo.NO;

                    CalendarId = objPacientBL.AddShedule(ref objOperationResult, objCalendarDto, ((ClientSession)Session["objClientSession"]).GetAsList(), ProtocolId, PacientId, (int)MasterService.Eso, "Nuevo");
                }
                else      // no se grabro el paciente
                {
                    sbDatos.Append("PACIENTE :  ");
                    sbDatos.Append(objPersonDto.v_FirstName + " " + objPersonDto.v_FirstLastName + " " + objPersonDto.v_SecondLastName);
                    sbDatos.Append("  DOCUMENTO :  ");
                    sbDatos.Append(objPersonDto.v_DocNumber);
                    sbDatos.Append("\n");
                }
            }

            //iniciar circuitos


            if (objOperationResult.Success == 1)      // Operación sin error
            {
                Alert.Show("Se agendó correctamente.");
            }
            else    // Operación con error
            {
                Alert.ShowInTop("Error al agendar, por favor comuníquese con su proveedor", "ERROR!");
            }
        }