private void btnHabilitar_Click(object sender, EventArgs e) { //TENGO QUE VOLVER A HABILITAR EL ROL DEL USUARIO List <Rol> roles = null; string usu; try { if (afiliadoModificar.Username == "administrador32405354") { var parametros = new Dictionary <string, object>() { { "@username", afiliadoModificar.Username.Substring(0, 5) } }; roles = ConexionesDB.ExecuteReader("UsuarioXRol_GetRolesInhabxUser", parametros).ToRoles(); usu = afiliadoModificar.Username.Substring(0, 5); } else { var parametros = new Dictionary <string, object>() { { "@username", afiliadoModificar.Username } }; roles = ConexionesDB.ExecuteReader("UsuarioXRol_GetRolesInhabxUser", parametros).ToRoles(); usu = afiliadoModificar.Username; } } catch { MessageBox.Show("No se pudo obtener el rol del usuario a modificar", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (roles.Count > 0 && roles[0].Id == 2 && roles[0].Habilitado) { Rol rolAsignado = null; foreach (Rol r in roles) { if (r.Id == 2) { rolAsignado = r; } } try { ConexionesDB.ExecuteNonQuery("RolXUsuario_Activate", new Dictionary <string, object>() { { "@rol", rolAsignado.Id }, { "@usuario", usu } }); } catch { MessageBox.Show("Error al acceder a database", "Intente nuevamente", MessageBoxButtons.OK, MessageBoxIcon.Information); } MessageBox.Show("Rol activado nuevamente", "Exito", MessageBoxButtons.OK, MessageBoxIcon.Information); ckbEstado.Checked = true; btnHabilitar.Visible = false; } else { MessageBox.Show("El rol estaba deshabilitado, habilitelo e intente nuevamente", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void dgvTurnos_DoubleClick(object sender, EventArgs e) { if (dgvTurnos.SelectedRows.Count == 1) { txtNroAfiliado.Enabled = false; DataGridViewRow row = dgvTurnos.SelectedRows[0]; DateTime fecha = ConfigTime.getFechaSinHora(); Turno t = (Turno)row.DataBoundItem; int horas = ConfigTime.getFecha().Hour; int minutos = ConfigTime.getFecha().Minute; int segundos = ConfigTime.getFecha().Second; DateTime fechaactual = ConfigTime.getFechaSinHora().AddHours(horas).AddMinutes(minutos).AddSeconds(segundos); Dictionary <string, object> parametros = new Dictionary <string, object>() { { "@nroafiliado", t.Afiliado } }; List <Bono> lista = new List <Bono>(); lista = ConexionesDB.ExecuteReader("Get_Bonos_Afiliado", parametros).ToBono(); //dgvTurnos.DataSource = listaTurnos; if (lista.Count != 0) { Dictionary <string, object> parametros2 = new Dictionary <string, object>() { { "@nroafiliado", t.Afiliado }, { "@nroturno", t.Id }, { "@fecha", fechaactual } }; try { ConexionesDB.ExecuteNonQuery("Registrar_Llegada", parametros2); MessageBox.Show("Se registro la llegada correctamente del horario: " + t.Fecha.ToString(), "Exito", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch { MessageBox.Show("Hubo un problema al registrar la llegada, intente nuevamente", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } Hide(); Main acerrar = null; FormCollection fc = Application.OpenForms; foreach (Form frm in fc) { if (frm.Name == "Main") { acerrar = (Main)frm; } } if (acerrar != null) { acerrar.Show(); } } else { MessageBox.Show("No tenia bonos comprados, compre uno primero", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } }
private void btnCrear_Click_1(object sender, EventArgs e) { var nombre = txtNombre.Text; var rol = ConexionesDB.ExecuteReader("Rol_Exists", new Dictionary <string, object>() { { "@rol", nombre } }).ToRol(); if (rol == null) { var funcionesSeleccionadas = lstFunciones.CheckedItems; if (funcionesSeleccionadas.Count > 0) { try { ConexionesDB.ExecuteNonQuery("Rol_Add", new Dictionary <string, object>() { { "@rol", nombre } }); rol = ConexionesDB.ExecuteReader("Rol_GetByName", new Dictionary <string, object>() { { "@nombre", nombre } }).ToRol(); foreach (string fun in funcionesSeleccionadas) { var id = funciones.FirstOrDefault(x => x.Descripcion == fun).Id; ConexionesDB.ExecuteNonQuery("RolXFuncion_Add", new Dictionary <string, object>() { { "@rol", rol.Id }, { "@funcion", id } }); } MessageBox.Show("Insertado con exito", "Correcto", MessageBoxButtons.OK, MessageBoxIcon.Information); txtNombre.Text = ""; //NO SE COMO GARCHA DESELECCIONAR LOS ITEMS // lstFunciones.SelectedIndex = -1; //lstFunciones.SelectedItems.Clear(); // lstFunciones.ClearSelected(); } catch { MessageBox.Show("Hubo un error en el alta", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { MessageBox.Show("Seleccione funciones", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } else { MessageBox.Show("Ya existe el rol", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private bool Modificar(Dictionary <string, object> afiliado) { if (((Plan)cmbPlan.SelectedItem).Id != planactual.Id) { if (txtCambioPlan.Text != "") { //HAY QUE CREAR UNA MODIFICACION DEL PLAN var planmodif = new Dictionary <string, object>() { { "@PlanNuevoId", ((Plan)cmbPlan.SelectedItem).Id }, { "@Username", txtNombre.Text + txtApellido.Text + txtDni.Text.ToString() }, { "@Motivo", txtCambioPlan.Text }, }; try { ConexionesDB.ExecuteNonQuery("Agregar_Modif_Plan", planmodif); } catch { MessageBox.Show("Error al modificar el plan", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } } else { MessageBox.Show("Debe completar el campo motivo", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } } afiliado.Add("@Username", txtNombre.Text + txtApellido.Text + txtDni.Text.ToString()); if (ckbCambioPlan.Visible) { afiliado.Add("@cambiarFamilia", ckbCambioPlan.Checked); } try { ConexionesDB.ExecuteNonQuery("Afiliado_Modify", afiliado); } catch { MessageBox.Show("Hubo un error inesperado en la modificacion", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } MessageBox.Show("Modificado con exito", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); return(true); }
private void btnGuardar_Click(object sender, EventArgs e) { var rol = (Rol)cmbRoles.SelectedItem; try { ConexionesDB.ExecuteNonQuery("Rol_Deactivate", new Dictionary <string, object>() { { "@rol", rol.Id } }); } catch { MessageBox.Show("Error al acceder a database", "Intente nuevamente", MessageBoxButtons.OK, MessageBoxIcon.Information); } MessageBox.Show("Dado de baja con exito", "Exito", MessageBoxButtons.OK, MessageBoxIcon.Information); LoadRoles(); }
private void btnActivar_Click(object sender, EventArgs e) { //aca va la logica para activar rol var rolAsignado = (Rol)cmbRoles.SelectedItem; try { ConexionesDB.ExecuteNonQuery("Rol_Activate", new Dictionary <string, object>() { { "@rol", rolAsignado.Id } }); } catch { MessageBox.Show("Error al acceder a database", "Intente nuevamente", MessageBoxButtons.OK, MessageBoxIcon.Information); } MessageBox.Show("Rol activado nuevamente", "Exito", MessageBoxButtons.OK, MessageBoxIcon.Information); btnActivar.Visible = false; }
private void btnBajaAfiliado_Click(object sender, EventArgs e) { //ACORDARSE QUE CUANDO LE DOY DE BAJA, HAY QUE PONER SUS TURNOS COMO DISPONIBLES, ESO ES UN TRIGGER if (dgvAfiliado.SelectedRows.Count == 1) { Afiliado afil = (Afiliado)dgvAfiliado.CurrentRow.DataBoundItem; if (afil != null) { //LE DOY DE BAJA LOGICA, REVISAR LO UNICO QUE QUEDA ES LA PARTE DE PORQUE NO ME DEVUELVE SI SE MODIFICO string user = null; if (afil.Username == "administrador32405354") { user = afil.Username.Substring(0, 5); } else { user = afil.Username; } try { ConexionesDB.ExecuteNonQuery("Afiliado_Baja_Logica", (new Dictionary <string, object> { { "@UsuarioId", user } /*, {"@ret", resp} */ })); } catch { MessageBox.Show("Error al dar de baja afiliado", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } MessageBox.Show("Se dio de baja al afiliado: " + afil.Username, "Baja", MessageBoxButtons.OK, MessageBoxIcon.Information); // else // MessageBox.Show("No se dio de baja al afiliado: " + afil.Username + "porque no tenia ningun rol o porque ya estaba de baja", "Baja", MessageBoxButtons.OK, MessageBoxIcon.Warning); ConexionesDB.DB.Close(); return; } } else { MessageBox.Show("Debe seleccionar 1 solo afiliado a dar de baja", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } }
private void button2_Click(object sender, EventArgs e) { if (txtDiagnostico.Text == "" || txtSintomas.Text == "") { MessageBox.Show("Debe completar los sintomas y enfermedades", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { int turnonro; int.TryParse(dataGridView1.SelectedCells[0].Value.ToString(), out turnonro); Dictionary <string, object> parametros2 = new Dictionary <string, object>() { { "@turnoid", turnonro } , { "@sintomas", txtSintomas.Text }, { "@enfermedades", txtDiagnostico.Text }, { "@tiempo", ckbHorario.Checked } }; try { ConexionesDB.ExecuteNonQuery("Registrar_Resultado", parametros2); } catch { MessageBox.Show("No se registro el resultado. Intente nuevamente", "Registrado", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } MessageBox.Show("Se registro el resultado con exito", "Registrado", MessageBoxButtons.OK, MessageBoxIcon.Information); } Hide(); Main aabrir = null; FormCollection fc = Application.OpenForms; foreach (Form frm in fc) { if (frm.Name == "Main") { aabrir = (Main)frm; } } if (aabrir != null) { aabrir.Show(); } }
private void generarTurnos(CustomHour horaInicio, CustomHour horaFin, DateTime fecha) { int cantTurnos = ((horaInicio.toMinutes() - horaFin.toMinutes()) / 30) * -1; int i; for (i = 0; i < cantTurnos; i++) { CustomHour aux = CustomHour.FromMinutes(horaInicio.toMinutes() + 30 * i); fecha = fecha.AddHours(aux.hora); fecha = fecha.AddMinutes(aux.minuto); //Genero el turno Dictionary <string, object> parametros = new Dictionary <string, object>() { { "@matricula", profesional.Matricula }, { "@especialidad", profesional.Especialidades[listaEspecialidades.SelectedIndex].Id }, { "@fecha", fecha } }; ConexionesDB.ExecuteNonQuery("Turno_Agregar", parametros); fecha = fecha.AddHours(-aux.hora); fecha = fecha.AddMinutes(-aux.minuto); } }
private void button_iniciar_sesion_Click(object sender, EventArgs e) { if (txtContrasenia.Text == null || txtContrasenia.Text == "" || txtUsuario.Text == null || txtUsuario.Text == "") { MessageBox.Show("Tiene que completar todos los campos", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { //fijarse en db si usuario correcto var username = txtUsuario.Text; var password = txtContrasenia.Text; if (username != null && password != null) { //OBTENGO EL USUARIO Y ME FIJO SI ESTA ACTIVO try { usuario = ConexionesDB.ExecuteReader("Usuario_Get", new Dictionary <string, object>() { { "@usuario", username } }).ToUsuario(); } catch (Exception excepcion) { MessageBox.Show("Hubo un error al acceder a la base de datos, intente nuevamente", "Intente nuevamente", MessageBoxButtons.OK, MessageBoxIcon.Information); System.IO.StreamWriter file = new System.IO.StreamWriter(Application.StartupPath + "/debug.txt"); file.WriteLine(excepcion.ToString()); file.Close(); return; } if (usuario != null && !usuario.Activo) { MessageBox.Show("Usuario Inhabilitado. Contactese con el administrador para que lo habilite", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } Dictionary <string, object> parametros = new Dictionary <string, object>(); parametros.Add("@Username", username); parametros.Add("@Password", password); //REALIZO EL LOGIN try { usuario = ConexionesDB.ExecuteReader("Usuario_LogIn", parametros).ToUsuario(); } catch { MessageBox.Show("Hubo un error al acceder a la base de datos, intente nuevamente", "Intente nuevamente", MessageBoxButtons.OK, MessageBoxIcon.Information); } if (usuario != null) { //OBTENGO LOS ROLES DEL USUARIO try { roles = ConexionesDB.ExecuteReader("UsuarioXRol_GetRolesByUser", new Dictionary <string, object>() { { "@Username", usuario.Username } }).ToRoles(); } catch { MessageBox.Show("Hubo un error al acceder a la base de datos, intente nuevamente", "Intente nuevamente", MessageBoxButtons.OK, MessageBoxIcon.Information); } if (roles.Count > 1) { cmbRol.Visible = true; cmbRol.DataSource = roles; cmbRol.DisplayMember = "Descripcion"; buttonContinuar.Visible = true; cmbRol.Focus(); button_iniciar_sesion.Visible = false; } else if (roles.Count == 0) { MessageBox.Show("Este usuario no tiene roles asignados o estan dados de baja. Contactese con el administrador", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { Main main = new Main(usuario, roles.FirstOrDefault()); main.Show(); Hide(); } } else { //LE SUMO UN INTENTO PORQUE FALLO LA CONTRASEÑA try { ConexionesDB.ExecuteNonQuery("Usuario_SumarIntento", new Dictionary <string, object>() { { "@Username", username } }); } catch { MessageBox.Show("Hubo un error al acceder a la base de datos, intente nuevamente", "Intente nuevamente", MessageBoxButtons.OK, MessageBoxIcon.Information); } var usu = ConexionesDB.ExecuteReader("Usuario_Get", new Dictionary <string, object>() { { "@usuario", username } }).ToUsuario(); if (usu != null && usu.Intentos >= 3) { //LO INHABILITO SI YA HIZO 3 INTENTOS MAL try { ConexionesDB.ExecuteNonQuery("Usuario_Inhabilitar", new Dictionary <string, object> { { "@Username", username } }); } catch { MessageBox.Show("Hubo un error al acceder a la base de datos, intente nuevamente", "Intente nuevamente", MessageBoxButtons.OK, MessageBoxIcon.Information); } MessageBox.Show("Password no corresponde con Username.", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); MessageBox.Show("Usuario ha quedado inhabilitado", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); txtContrasenia.Focus(); cmbRol.Visible = false; buttonContinuar.Visible = false; } else { MessageBox.Show("Password no corresponde con Username.", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); cmbRol.Visible = false; buttonContinuar.Visible = false; txtContrasenia.Focus(); } } } else { MessageBox.Show("Ingresar Username y Password por favor.", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); } } txtContrasenia.Clear(); }
void ButtonOKClick(object sender, EventArgs e) { if (!validarTextBoxes()) { Array.Clear(matrizHoras, 0, matrizHoras.Length); return; } if (!validarFechas()) { return; } if (!validarComboBox()) { MessageBox.Show("Debe seleccionar una especialidad", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (!validarHorasGuardadas()) { MessageBox.Show("Este profesional tiene mas de 48 hs por semana", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } //Ahora tengo que enviarlo a la bd. int agenda_id; Dictionary <string, object> parametros = new Dictionary <string, object>() { { "@matricula", profesional.Matricula }, { "@especialidad", listaEspecialidades.SelectedValue.ToString() }, { "@fecha_inicio", monthCalendar1.SelectionStart }, { "@fecha_fin", monthCalendar2.SelectionStart } }; List <string> outputParam = new List <string>() { "@id_agenda" }; SqlParameterCollection sqlParameters = ConexionesDB.ExecuteNonQueryWithOutput("Agenda_Agregar", outputParam, parametros); agenda_id = (int)sqlParameters[parametros.Count].Value; //Ya agregue la agenda, ahora tengo que enviar todas las franjas ConexionesDB.DB.Open(); bool transaccionFallida = false; int i, j; for (i = 0; i < 1; i = i + 1) { for (j = 0; j < 6; j++) { if (matrizHoras[i, j] != null) { parametros = new Dictionary <string, object>() { { "@id_agenda", agenda_id }, { "@matricula", profesional.Matricula }, { "@dia", j }, { "@hora_inicio", matrizHoras[i, j].hora }, { "@minuto_inicio", matrizHoras[i, j].minuto }, { "@hora_fin", matrizHoras[i + 1, j].hora }, { "@minuto_fin", matrizHoras[i + 1, j].minuto }, }; if (ConexionesDB.ExecuteNonQueryWithReturn("Franja_Agregar", parametros) != 0) { transaccionFallida = true; } } } } if (transaccionFallida) { //transaction.Rollback(); MessageBox.Show("La cantidad de horas introducidas entre todas las especialidades para esta semana superan las 48.", "Cantidad de horas superan 48, No se pudo registrar la agenda", MessageBoxButtons.OK, MessageBoxIcon.Error); ConexionesDB.ExecuteNonQuery("Borrar_Franjas_Agenda", new Dictionary <string, object>() { { "@agenda", agenda_id } }); ConexionesDB.DB.Close(); return; } //else transaction.Commit(); ConexionesDB.DB.Close(); //for(DateTime date = StartDate; date.Date <= EndDate.Date; date = date.AddDays(1)) for (DateTime fecha = monthCalendar1.SelectionStart; fecha.Date <= monthCalendar2.SelectionStart; fecha = fecha.AddDays(1)) { int indice = (int)fecha.DayOfWeek - 1; if (fecha.DayOfWeek != DayOfWeek.Sunday) { if (matrizHoras[0, indice] != null) { generarTurnos(matrizHoras[0, indice], matrizHoras[1, indice], fecha); } //if(matrizHoras[2,indice] != null){ // generarTurnos(matrizHoras[2,indice],matrizHoras[3,indice],fecha); //} } } MessageBox.Show("Se realizaron los turnos", "Turnos Realizados", MessageBoxButtons.OK, MessageBoxIcon.Information); Hide(); Main acerrar = null; FormCollection fc = Application.OpenForms; foreach (Form frm in fc) { if (frm.Name == "Main") { acerrar = (Main)frm; } } if (acerrar != null) { acerrar.Show(); } //Listo, cerrar el form }
private void btnCancelar_Click(object sender, EventArgs e) { if (textBox1.Text != string.Empty && cmbTipoCancelacion.Text != string.Empty) { if (chk_fecha.Checked == true) { if (chk_horario.Checked == true) { if (hora1.Text != string.Empty && hora2.Text != string.Empty && minuto1.Text != string.Empty && minuto2.Text != string.Empty) { /*QUIERE CANCELAR UN RANGO*/ int horain, horafi, minin, minfi; if (int.TryParse(hora1.Text, out horain) && int.TryParse(hora2.Text, out horafi) && int.TryParse(minuto1.Text, out minin) && int.TryParse(minuto2.Text, out minfi)) { if (horain < 24 && horain >= 0 && horafi < 24 && horafi >= 0 && minin < 60 && minin >= 0 && minfi < 60 && minfi >= 0) { DateTime d = ((Fecha)drop_fecha.SelectedItem).DiaMesAnio; DateTime dInicio = new DateTime(DateTime.Parse(ConfigurationManager.AppSettings["fecha"]).Year, 1, 1, Int32.Parse(hora1.Text), Int32.Parse(minuto1.Text), 0); TimeSpan tInicio = dInicio.TimeOfDay; DateTime dFin = new DateTime(DateTime.Parse(ConfigurationManager.AppSettings["fecha"]).Year, 1, 1, Int32.Parse(hora2.Text), Int32.Parse(minuto2.Text), 0); TimeSpan tFin = dFin.TimeOfDay; Dictionary <string, object> parametros = new Dictionary <string, object>() { { "@motivo", textBox1.Text }, { "@tipo", cmbTipoCancelacion.Text.Substring(0, 1) }, { "@matricula", profesional.Matricula }, { "@fecha", d }, { "@horain", tInicio }, { "@horafin", tFin } }; try { ConexionesDB.ExecuteNonQuery("Cancelar_Turnos_ProfxFranja", parametros); } catch { MessageBox.Show("Error al cancelar el turno, intente nuevamente", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } else { MessageBox.Show("Error en los horarios ingresadas", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } else { MessageBox.Show("Debe ingresar horarios validos numericos. Intente nuevamente", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } else { MessageBox.Show("Debe completar todos los campos", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } else { /*QUIERE CANCELAR TODO EL DIA*/ DateTime d = ((Fecha)drop_fecha.SelectedItem).DiaMesAnio; DateTime dInicio = new DateTime(ConfigTime.getFechaSinHora().Year, 1, 1, 0, 0, 0); TimeSpan tInicio = dInicio.TimeOfDay; DateTime dFin = new DateTime(ConfigTime.getFechaSinHora().Year, 1, 1, 23, 59, 0); TimeSpan tFin = dFin.TimeOfDay; Dictionary <string, object> parametros = new Dictionary <string, object>() { { "@motivo", textBox1.Text }, { "@tipo", cmbTipoCancelacion.Text.Substring(0, 1) }, { "@matricula", profesional.Matricula }, { "@fecha", d }, { "@horain", tInicio }, { "@horafin", tFin } }; try { ConexionesDB.ExecuteNonQuery("Cancelar_Turnos_ProfxFranja", parametros); } catch { MessageBox.Show("Error al cancelar el turno, intente nuevamente", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } } else { //*QUIERE CANCELAR RANGO DIAS*/ if (chk_dias.Checked == true) { DateTime dia_desde = monthCalendar1.SelectionStart; DateTime dia_hasta = monthCalendar2.SelectionStart; if (dia_desde >= DateTime.Today && dia_desde < dia_hasta) { Dictionary <string, object> parametros = new Dictionary <string, object>() { { "@motivo", textBox1.Text }, { "@tipo", cmbTipoCancelacion.Text.Substring(0, 1) }, { "@matricula", profesional.Matricula }, { "@fecha_desde", dia_desde }, { "@fecha_hasta", dia_hasta } }; try { ConexionesDB.ExecuteNonQuery("Cancelar_Turnos_Varios_Dias", parametros); } catch { MessageBox.Show("Error al cancelar el turno, intente nuevamente", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } else { MessageBox.Show("La fecha inicial tiene que ser mayor a la fecha final y posterior al dia de hoy", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } else { MessageBox.Show("Debe elegir una opcion", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } } else { MessageBox.Show("Debe completar todos los campos", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } MessageBox.Show("Se han cancelado los turnos con exito", "Cancelado", MessageBoxButtons.OK, MessageBoxIcon.Information); Hide(); Main amostrar = null; FormCollection fc = Application.OpenForms; foreach (Form frm in fc) { if (frm.Name == "Main") { amostrar = (Main)frm; } } if (amostrar != null) { amostrar.Show(); } }
private void btnModificar_Click(object sender, EventArgs e) { var rolAsignado = (Rol)cmbRoles.SelectedItem; if (txtNombre.Text != string.Empty) { try { if (txtNombre.Text != rolAsignado.Descripcion.Trim()) { var rol = ConexionesDB.ExecuteReader("Rol_Exists", new Dictionary <string, object>() { { "@rol", txtNombre.Text } }).ToRol(); if (rol == null) { try { ConexionesDB.ExecuteNonQuery("Rol_ModifyName", new Dictionary <string, object>() { { "@nombre", txtNombre.Text }, { "@id", rolAsignado.Id } }); } catch { MessageBox.Show("Error al acceder a database", "Intente nuevamente", MessageBoxButtons.OK, MessageBoxIcon.Information); } } else { MessageBox.Show("Ya existe el rol", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); txtNombre.Focus(); return; } } foreach (var item in lstFunciones.Items) { var nombre = (string)item; if (lstFunciones.CheckedItems.Contains(item)) { //Si está chequeado y no estaba, lo agrego if (!funcionesXRol.Exists(x => x.Descripcion == nombre)) { try { ConexionesDB.ExecuteNonQuery("RolXFuncion_Add", new Dictionary <string, object>() { { "@rol", rolAsignado.Id }, { "@funcion", funciones.First(x => x.Descripcion == nombre).Id } }); } catch { MessageBox.Show("Error al acceder a database", "Intente nuevamente", MessageBoxButtons.OK, MessageBoxIcon.Information); } } } else { //No esta chequedado y si estaba, lo borro if (funcionesXRol.Exists(x => x.Descripcion == nombre)) { try { ConexionesDB.ExecuteNonQuery("RolXFuncion_Remove", new Dictionary <string, object>() { { "@rol", ((Rol)cmbRoles.SelectedItem).Id }, { "@funcion", funciones.First(x => x.Descripcion == nombre).Id } }); } catch { MessageBox.Show("Error al acceder a database", "Intente nuevamente", MessageBoxButtons.OK, MessageBoxIcon.Information); } // lstFunciones.CheckedItems = false; } } } MessageBox.Show("Modificado con exito", "Exito", MessageBoxButtons.OK, MessageBoxIcon.Information); SetRoles(); } catch { MessageBox.Show("Hubo un error en la modificacion", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { MessageBox.Show("No puede quedar vacío el nombre del rol", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private bool Alta(Dictionary <string, object> afiliado) { #region OPCION 3(CONYUGE) if (opcionelegida == 3) { Usuario user; try { user = ConexionesDB.ExecuteReader("Usuario_Exists", new Dictionary <string, object>() { { "@usuarioid", txtNombre.Text + txtApellido.Text + txtDni.Text } }).ToUsuario(); } catch { MessageBox.Show("El Afiliado ingresado ya existia", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } if (user == null) { Afiliado afil; try { afil = ConexionesDB.ExecuteReader("Afiliado_MismoDni", new Dictionary <string, object>() { { "@dni", txtDni.Text } }).ToAfiliados(); } catch { MessageBox.Show("Ya existia un afiliado con ese numero de DNI", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } if (afil == null) { try { ConexionesDB.ExecuteNonQuery("Afiliado_Agregar_Familiar", afiliado); } catch { MessageBox.Show("No se pudo agregar el afiliado", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } MessageBox.Show("Se agrego correctamente el afiliado", "Exito", MessageBoxButtons.OK, MessageBoxIcon.Information); DialogResult resultado2 = MessageBox.Show("Desea agregar a algun otro familiar a la clinica?", "Consulta", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (resultado2 == DialogResult.Yes)//quiere decir que quiere registrar a su familiar { //ACA TENGO QUE IR A UN NUEVO FORM DE ALTA PARA EL FAMILIAR Afiliado afilAgregado; try { var dict = new Dictionary <string, object>() { { "@username", txtNombre.Text + txtApellido.Text + txtDni.Text.ToString() } }; afilAgregado = ConexionesDB.ExecuteReader("Afiliado_GetAfiliadoSegunUsuario", dict).ToAfiliados(); } catch { MessageBox.Show("No se ha podido agregar un familiar", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } opcionelegida = 4; frmAfiliado conyuge = new frmAfiliado(usuario, rol, afilAgregado, 4); conyuge.Show(); return(true); } else { opcionelegida = 1; } } else { MessageBox.Show("Ya existe un afiliado con ese mismo DNI", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } } else { MessageBox.Show("Ese Afiliado ya esta registrado en la clinica", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } return(true); } #endregion #region OPCION 1(ALTA AFILIADO) else if (opcionelegida == 1) { Usuario user; try { user = ConexionesDB.ExecuteReader("Usuario_Exists", new Dictionary <string, object>() { { "@usuarioid", txtNombre.Text + txtApellido.Text + txtDni.Text } }).ToUsuario(); } catch { MessageBox.Show("El Afiliado ingresado ya existia", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } if (user == null) { Afiliado afil; try { afil = ConexionesDB.ExecuteReader("Afiliado_MismoDni", new Dictionary <string, object>() { { "@dni", txtDni.Text } }).ToAfiliados(); } catch { MessageBox.Show("Ya existia un afiliado con ese numero de DNI", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } if (afil == null) { try { ConexionesDB.ExecuteNonQuery("Afiliado_Add", afiliado); ConexionesDB.ExecuteNonQuery("Hijos_En_Cero", new Dictionary <string, object> { { "@username", txtNombre.Text + txtApellido.Text + txtDni.Text.ToString() } }); } catch { MessageBox.Show("No se pudo agregar el afiliado", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } MessageBox.Show("Se agrego correctamente el afiliado", "Exito", MessageBoxButtons.OK, MessageBoxIcon.Information); if (cmbEstadoCivil.Text.Substring(0, 1) == "C")//esta casado, ofrezco si quiere registrar a su conyuge { DialogResult resultado = MessageBox.Show("Desea agregar a su conyuge a la clinica?", "Consulta", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (resultado == DialogResult.Yes)//quiere decir que quiere registrar a su conyuge { //VER PORQUE AL AFILIADO LE QUEDA 1 HIJO MAS QUE LOS QUE TIENE //ACA TENGO QUE IR A UN NUEVO FORMULARIO DE ALTA PARA EL CONYUGE //LEO EL NRO AFILIADO DEL QUE ACABO DE AGREGAR PARA PASRLO Afiliado afilAgregado; try { var dict = new Dictionary <string, object>() { { "@username", txtNombre.Text + txtApellido.Text + txtDni.Text.ToString() } }; afilAgregado = ConexionesDB.ExecuteReader("Afiliado_GetAfiliadoSegunUsuario", dict).ToAfiliados(); } catch { MessageBox.Show("No se ha podido agregar un familiar", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } opcionelegida = 3; frmAfiliado conyuge = new frmAfiliado(usuario, rol, afilAgregado, 3); conyuge.Show(); return(true); } else // no quiere registrar a su conyuge { DialogResult resultado2 = MessageBox.Show("Desea agregar a algun otro familiar a la clinica?", "Consulta", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (resultado2 == DialogResult.Yes)//quiere decir que quiere registrar a su conyuge { //ACA TENGO QUE IR A UN NUEVO FORM DE ALTA PARA EL FAMILIAR //OPCION 4 es Agregar otro familiar //VER PORQUE AL AFILIADO LE QUEDA 1 HIJO MAS QUE LOS QUE TIENE //ACA TENGO QUE IR A UN NUEVO FORMULARIO DE ALTA PARA EL CONYUGE //LEO EL NRO AFILIADO DEL QUE ACABO DE AGREGAR PARA PASRLO Afiliado afilAgregado; try { var dict = new Dictionary <string, object>() { { "@username", txtNombre.Text + txtApellido.Text + txtDni.Text.ToString() } }; afilAgregado = ConexionesDB.ExecuteReader("Afiliado_GetAfiliadoSegunUsuario", dict).ToAfiliados(); } catch { MessageBox.Show("No se ha podido agregar un familiar", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } opcionelegida = 4; frmAfiliado conyuge = new frmAfiliado(usuario, rol, afilAgregado, 4); conyuge.Show(); return(true); } } } else { DialogResult resultado3 = MessageBox.Show("Desea agregar a algun otro familiar a la clinica?", "Consulta", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (resultado3 == DialogResult.Yes)//quiere decir que quiere registrar a su conyuge { //ACA TENGO QUE IR A UN NUEVO FORM DE ALTA PARA EL FAMILIAR //OPCION 4 es Agregar otro familiar //VER PORQUE AL AFILIADO LE QUEDA 1 HIJO MAS QUE LOS QUE TIENE //ACA TENGO QUE IR A UN NUEVO FORMULARIO DE ALTA PARA EL CONYUGE //LEO EL NRO AFILIADO DEL QUE ACABO DE AGREGAR PARA PASRLO Afiliado afilAgregado; try { var dict = new Dictionary <string, object>() { { "@username", txtNombre.Text + txtApellido.Text + txtDni.Text.ToString() } }; afilAgregado = ConexionesDB.ExecuteReader("Afiliado_GetAfiliadoSegunUsuario", dict).ToAfiliados(); } catch { MessageBox.Show("No se ha podido agregar un familiar", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } opcionelegida = 4; frmAfiliado conyuge = new frmAfiliado(usuario, rol, afilAgregado, 4); conyuge.Show(); return(true); } } } else { MessageBox.Show("Ya existia un afiliado con ese DNI", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } } else { MessageBox.Show("Ese Afiliado ya esta registrado en la clinica", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } return(true); } #endregion #region OPCION 4 (ALTA FAMILIAR) if (opcionelegida == 4) { Usuario user; try { user = ConexionesDB.ExecuteReader("Usuario_Exists", new Dictionary <string, object>() { { "@usuarioid", txtNombre.Text + txtApellido.Text + txtDni.Text } }).ToUsuario(); } catch { MessageBox.Show("El Afiliado ingresado ya existia", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } if (user == null) { Afiliado afil; try { afil = ConexionesDB.ExecuteReader("Afiliado_MismoDni", new Dictionary <string, object>() { { "@dni", txtDni.Text } }).ToAfiliados(); } catch { MessageBox.Show("Ya existia un afiliado con ese numero de DNI", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } if (afil == null) { try { ConexionesDB.ExecuteNonQuery("Afiliado_Agregar_Familiar", afiliado); } catch { MessageBox.Show("No se pudo agregar el afiliado", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } MessageBox.Show("Se agrego correctamente el afiliado", "Exito", MessageBoxButtons.OK, MessageBoxIcon.Information); DialogResult resultado2 = MessageBox.Show("Desea agregar a algun otro familiar a la clinica?", "Consulta", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (resultado2 == DialogResult.Yes)//quiere decir que quiere registrar a su conyuge { //ACA TENGO QUE IR A UN NUEVO FORM DE ALTA PARA EL FAMILIAR Afiliado afilAgregado; try { var dict = new Dictionary <string, object>() { { "@username", txtNombre.Text + txtApellido.Text + txtDni.Text.ToString() } }; afilAgregado = ConexionesDB.ExecuteReader("Afiliado_GetAfiliadoSegunUsuario", dict).ToAfiliados(); } catch { MessageBox.Show("No se ha podido agregar un familiar", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } opcionelegida = 4; frmAfiliado conyuge = new frmAfiliado(usuario, rol, afilAgregado, 4); conyuge.Show(); return(true); } else { opcionelegida = 1; } } else { MessageBox.Show("Ya existia un afiliado con ese mismo DNI", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } } else { MessageBox.Show("Ese Afiliado ya esta registrado en la clinica", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } return(true); } #endregion return(false); }