private void btnCargar_Click(object sender, EventArgs e) { if (validar()) { Veterinario v = new Veterinario(); v.pMatricula = Convert.ToInt32(txtMatricula.Text); v.pNombre = txtNombre.Text; v.pApellido = txtApellido.Text; v.pCalle = txtCalle.Text; v.pNumCalle = Convert.ToInt32(txtNumeroCalle.Text); v.pEmail = txtEmail.Text; v.pTelefono = Convert.ToInt32(txtNumTelefono.Text); v.pFecNacimiento = dtpFechaNacimiento.Value; if (rbtMasculino.Checked) { v.pSexo = 1; } else { v.pSexo = 2; } v.pSueldo = Convert.ToDouble(txtSueldo.Text); v.pFechaIngreso = dtpIngreso.Value; v.pFechaEgreso = dtpEgreso.Value; v.pCiudad = Convert.ToInt32(cboCiudades.SelectedValue); v.pEgreso = chbEnActividad.Checked; if (nuevo) //comprueba que sea un nuevo veterinario { if (!validarPk(Convert.ToInt32(txtMatricula.Text))) //comprueba que el veterinario no exista en la bd { if (v.pEgreso) //si esta en actividad se inserta un null en fechaEgreso { string consultaSql = "insert into veterinarios values (" + v.pMatricula + ", '" + v.pNombre + "','" + v.pApellido + "','" + v.pCalle + "'," + v.pNumCalle + ",'" + v.pEmail + "'," + v.pTelefono + ",'" + v.pFecNacimiento.ToString("yyyy-MM-dd HH:mm:ss.fff") + "'," + v.pSexo + "," + v.pSueldo + ",'" + v.pFechaIngreso.ToString("yyyy-MM-dd HH:mm:ss.fff") + "'," + "null," + v.pCiudad + ")"; conn.nonQuery(consultaSql); lstVeterinarios.Items.Clear(); cargarListaVeterinario(); } else//si no esta en activadad se ingresa la fecha de baja { string consultaSql = "insert into veterinarios values (" + v.pMatricula + ", '" + v.pNombre + "','" + v.pApellido + "','" + v.pCalle + "'," + v.pNumCalle + ",'" + v.pEmail + "'," + v.pTelefono + ",'" + v.pFecNacimiento.ToString("yyyy-MM-dd HH:mm:ss.fff") + "'," + v.pSexo + "," + v.pSueldo + ",'" + v.pFechaIngreso.ToString("yyyy-MM-dd HH:mm:ss.fff") + "','" + v.pFechaEgreso.ToString("yyyy-MM-dd HH:mm:ss.fff") + "'," + v.pCiudad + ")"; conn.nonQuery(consultaSql); lstVeterinarios.Items.Clear(); cargarListaVeterinario(); } } else { MessageBox.Show("El veterinario que intenta ingresar ya se encuentra en la registrado", "CUIDADO", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } else { if (v.pEgreso) { string consultaSql = "update veterinarios " + "set matricula= " + v.pMatricula + ", " + "nombre='" + v.pNombre + "'," + "Apellido='" + v.pApellido + "'," + "calle='" + v.pCalle + "'," + "numCalle=" + v.pNumCalle + "," + "email='" + v.pEmail + "'," + "telefono=" + v.pTelefono + "," + "fec_nac='" + v.pFecNacimiento.ToString("yyyy-MM-dd HH:mm:ss.fff") + "'," + "sexo= " + v.pSexo + "," + "sueldoNeto= " + v.pSueldo + "," + "fechaIngreso= '" + v.pFechaIngreso.ToString("yyyy-MM-dd HH:mm:ss.fff") + "', " + "fechaEgreso= null ," + "idCiudad= " + v.pCiudad + "where matricula= " + v.pMatricula; conn.nonQuery(consultaSql); lstVeterinarios.Items.Clear(); cargarListaVeterinario(); } else { string consultaSql = "update veterinarios " + "set matricula= " + v.pMatricula + ", " + "nombre='" + v.pNombre + "'," + "Apellido='" + v.pApellido + "'," + "calle='" + v.pCalle + "'," + "numCalle=" + v.pNumCalle + "," + "email='" + v.pEmail + "'," + "telefono=" + v.pTelefono + "," + "fec_nac='" + v.pFecNacimiento.ToString("yyyy-MM-dd HH:mm:ss.fff") + "'," + "sexo= " + v.pSexo + "," + "sueldoNeto= " + v.pSueldo + "," + "fechaIngreso= '" + v.pFechaIngreso.ToString("yyyy-MM-dd HH:mm:ss.fff") + "'," + "fechaEgreso='" + v.pFechaEgreso.ToString("yyyy-MM-dd HH:mm:ss.fff") + "'," + "idCiudad= " + v.pCiudad + "where matricula= " + v.pMatricula; conn.nonQuery(consultaSql); lstVeterinarios.Items.Clear(); cargarListaVeterinario(); } } } }
private void convertidor() { c = 0; string consultaSql = "select * from veterinarios "; conn.leerTabla(consultaSql); //carga de tabla veterinarios en un dataReader while (conn.pDr.Read()) //carga de la clase con los datos del dataReader { Veterinario v = new Veterinario(); if (!conn.pDr.IsDBNull(0)) { v.pMatricula = conn.pDr.GetInt32(0); } if (!conn.pDr.IsDBNull(1)) { v.pNombre = conn.pDr.GetString(1); } if (!conn.pDr.IsDBNull(2)) { v.pApellido = conn.pDr.GetString(2); } if (!conn.pDr.IsDBNull(3)) { v.pCalle = conn.pDr.GetString(3); } if (!conn.pDr.IsDBNull(4)) { v.pNumCalle = conn.pDr.GetInt32(4); } if (!conn.pDr.IsDBNull(5)) { v.pEmail = conn.pDr.GetString(5); } if (!conn.pDr.IsDBNull(6)) { v.pTelefono = conn.pDr.GetInt32(6); } if (!conn.pDr.IsDBNull(7)) { v.pFecNacimiento = conn.pDr.GetDateTime(7); } if (!conn.pDr.IsDBNull(8)) { v.pSexo = conn.pDr.GetInt32(8); } if (!conn.pDr.IsDBNull(9)) { v.pSueldo = Convert.ToDouble(conn.pDr.GetDecimal(9)); } if (!conn.pDr.IsDBNull(10)) { v.pFechaIngreso = conn.pDr.GetDateTime(10); } if (!conn.pDr.IsDBNull(11)) { v.pFechaEgreso = conn.pDr.GetDateTime(11); v.pEgreso = false; } if (!conn.pDr.IsDBNull(12)) { v.pCiudad = conn.pDr.GetInt32(12); } veterinarios[c] = v; c++; } conn.pDr.Close(); conn.desconectar(); }
private void veterinarioToolStripMenuItem_Click(object sender, EventArgs e) { Veterinario vto = new Veterinario(); vto.ShowDialog(); }