public Empleado BuscarEmpleado(Empleado aux1) { try { Empleado aux = new Empleado(); DataAccessLayer cn = new DataAccessLayer(); Horario_service horarios = new Horario_service(); Especialidad_service espec = new Especialidad_service(); IList <Horario> hora = new List <Horario>(); IList <Especialidad> ESPECIALIDADES = new List <Especialidad>(); string consulta = "select E.ID_EMPLEADO,E.ID_CATEGORIA,E.NOMBRE,E.APELLIDO,E.DNI,E.FECHA_NAC,E.DIRECCION,E.IDLOCALIDAD,P.IDPROVINCIA,E.TELEFONO,E.EMAIL,E.SEXO,E.ELIMINADO from empleado AS E INNER JOIN LOCALIDAD AS L ON L.IDLOCALIDAD=E.IDLOCALIDAD INNER JOIN PROVINCIA AS P ON P.IDPROVINCIA=L.IDPROVINCIA where ELIMINADO=0 and ID_EMPLEADO=" + aux1.ID_Empleado1; cn.setearComandoText(consulta); cn.abrirConexion(); cn.ejecutarQuery(); while (cn.Lector.Read()) { aux.ID_Empleado1 = cn.Lector.GetInt32(0); aux.ID_Categoria1 = cn.Lector.GetInt32(1); aux.Nombre1 = cn.Lector.GetString(2); aux.Apellido1 = cn.Lector.GetString(3); aux.DNI1 = cn.Lector.GetString(4); aux.Fecha_Nac1 = Convert.ToString(cn.Lector.GetDateTime(5)); aux.Direccion1 = cn.Lector.GetString(6); aux.Localidad = new Localidad() { ID_Localidad1 = cn.Lector.GetInt32(7) }; aux.Provincia = new Provincia() { ID_Provincia1 = cn.Lector.GetInt32(8) }; aux.Telefono1 = cn.Lector.GetString(9); aux.Email1 = cn.Lector.GetString(10); aux.Sexo1 = cn.Lector.GetBoolean(11); aux.Eliminado1 = cn.Lector.GetBoolean(12); } ESPECIALIDADES = espec.traerEspecialidades(aux1.ID_Empleado1); hora = horarios.BuscarHorario(aux1.ID_Empleado1); for (int x = 0; x < hora.Count; x++) { Horario h = new Horario(); h = hora[x]; aux.ListaHorarios.Add(h); } for (int x = 0; x < ESPECIALIDADES.Count; x++) { aux.Lista_Especialidades.Add(ESPECIALIDADES[x]); } return(aux); } catch (Exception ex) { throw ex; } }
public void GuardarMedico(Empleado Nuevo) { SqlConnection cn = new SqlConnection(); SqlCommand cm = new SqlCommand(); Horario_service horarios = new Horario_service(); UsuarioService usuario = new UsuarioService(); Horario h = new Horario(); Especialidad_service EspecialidadX_med = new Especialidad_service(); EspecialidadXMed esM = new EspecialidadXMed(); try { cn.ConnectionString = "Data Source=LOCAL\\SQLEXPRESS;Initial Catalog=CLINICA_TOLOZA;Integrated Security=True"; cm.CommandType = System.Data.CommandType.StoredProcedure; cm.Connection = cn; cm.CommandText = "SP_AGREGAR_EMPLEADO"; cm.Parameters.Clear(); cm.Parameters.AddWithValue("@ID_CATEGORIA", Nuevo.ID_Categoria1); cm.Parameters.AddWithValue("@NOMBRE", Nuevo.Nombre1); cm.Parameters.AddWithValue("@APELLIDO", Nuevo.Apellido1); cm.Parameters.AddWithValue("@DNI", Nuevo.DNI1); cm.Parameters.AddWithValue("@FECHA_NAC", Convert.ToDateTime(Nuevo.Fecha_Nac1)); cm.Parameters.AddWithValue("@DIRECCION", Nuevo.Direccion1); cm.Parameters.AddWithValue("@IDLOCALIDAD", Nuevo.Localidad.ID_Localidad1); cm.Parameters.AddWithValue("@TELEFONO", Nuevo.Telefono1); cm.Parameters.AddWithValue("@EMAIL", Nuevo.Email1); cm.Parameters.AddWithValue("@SEXO", Nuevo.Sexo1); cm.Parameters.AddWithValue("@ELIMINADO", Nuevo.Eliminado1); cn.Open(); Nuevo.ID_Empleado1 = Convert.ToInt32(cm.ExecuteScalar()); Nuevo.Usser.ID_Empleado1 = Nuevo.ID_Empleado1; for (int i = 0; i < Nuevo.ListaHorarios.Count; i++) { Nuevo.ListaHorarios[i].ID_Empleado1 = Nuevo.ID_Empleado1; //horarios.GuerdarHorarios(Nuevo.ListaHorarios); } for (int j = 0; j < Nuevo.ListaHorarios.Count; j++) { h = Nuevo.ListaHorarios[j]; string dia = h.Dia1; horarios.GuerdarHorarios(h); } for (int x = 0; x < Nuevo.Lista_Especialidades.Count; x++) { esM.ID_Empleado1 = Nuevo.ID_Empleado1; esM.ID_Especilaidad1 = Nuevo.Lista_Especialidades[x].ID_Especialidad1; esM.Eliminado1 = false; EspecialidadX_med.guardarEspecialidadXMed(esM); } usuario.guardarUsuario(Nuevo.Usser); } catch (Exception ex) { throw ex; } finally { cn.Close(); cn.Dispose(); cm.Dispose(); } }