Example #1
0
        private void btnCargar_Click(object sender, EventArgs e)
        {
            if (focus == 1)
            {
                validar();
                string  consultaSQL = "";
                Mascota m           = new Mascota();
                m.pCodigo      = Convert.ToInt32(txtID.Text);
                m.pnombre      = txtMascota.Text;
                m.pDescripcion = txtdescrip.Text;
                m.pTipo        = Convert.ToInt32(cbotipo.SelectedValue);
                m.pDueño       = Convert.ToInt32(cboDueño.SelectedValue);
                m.pVet         = Convert.ToInt32(cboVet.SelectedValue);
                if (rbtHembra.Checked)
                {
                    m.pSexo = 1;
                }
                else
                {
                    m.pSexo = 2;
                }

                m.pFecha = dtpFec_nac.Value;
                if (nuevo)
                {
                    if (!Existe(m.pCodigo))
                    {
                        consultaSQL = "INSERT INTO Mascotas ( id_Mascota,Nombre,Descripcion,Fec_Nacim,id_Tipo_Animal,Id_Dueño,Sexo,Id_Veterinario) "
                                      + "VALUES ("
                                      + m.pCodigo + ",'"
                                      + m.pnombre + "','"
                                      + m.pDescripcion + "','"
                                      + m.pFecha + "',"
                                      + m.pTipo + ","
                                      + m.pDueño + ","
                                      + m.pSexo + ","
                                      + m.pVet + ")";
                        OD.actualizarBD(consultaSQL);
                        lista = 1;
                        cargarListas("Mascotas");
                    }
                    else
                    {
                        MessageBox.Show("esta Mascota ya se encuentra registrada...");
                    }
                }



                else
                if (nuevo == false)
                {
                    consultaSQL = "UPDATE Mascotas"
                                  + " SET"
                                  + "Nombre = '" + m.pnombre + "',"
                                  + "Descripcion = '" + m.pDescripcion + "',"
                                  + "Fec_nacim = '" + m.pFecha + "',"
                                  + "id_Tipo_Animal =" + m.pTipo + ","
                                  + "id_Dueño = " + m.pDueño + ","
                                  + "sexo =" + m.pSexo + ","
                                  + "id_Veterinario =" + m.pVet
                                  + " WHERE codigo = " + m.pCodigo;
                    OD.actualizarBD(consultaSQL);
                    lista = 1;
                    cargarListas("Mascotas");
                }
            }
            if (focus == 2)
            {
                validar();
                string consultaSQL = "";
                Dueño  d           = new Dueño();
                d.pCod_dueño = Convert.ToInt32(txtIdDueño.Text);
                d.pNombres   = txtnombre.Text;
                d.pApellidos = txtApellido.Text;
                d.pDireccion = txtCalle.Text;
                d.pTelefono  = Convert.ToInt32(txtTel.Text);
                d.pEmail     = txtMail.Text;

                if (nuevo)
                {
                    if (!Existe(d.pCod_dueño))
                    {
                        consultaSQL = "INSERT INTO Dueños(Id_Dueño,Nombres,Apellidos,Calle,Telefono,[E-mail] )"
                                      + "VALUES("
                                      + d.pCod_dueño + ",'"
                                      + d.pNombres + "','"
                                      + d.pApellidos + "','"
                                      + d.pDireccion + "',"
                                      + d.pTelefono + ",'"
                                      + d.pEmail + "')";

                        OD.actualizarBD(consultaSQL);
                        lista = 2;
                        cargarListas("Dueños");
                    }
                    else
                    {
                        MessageBox.Show("el Dueño ya se encuentra registrado...");
                    }
                }

                else
                {
                    consultaSQL = "UPDATE Dueños"
                                  + " SET"
                                  + " Nombre = '" + d.pNombres + "',"
                                  + " Apellidos = '" + d.pApellidos + "',"
                                  + " Calle = '" + d.pDireccion + "',"
                                  + " Telefono =" + d.pTelefono + ","
                                  + " [E-mail] = '" + d.pEmail + "'"
                                  + " WHERE id_Dueño = " + d.pCod_dueño;
                    OD.actualizarBD(consultaSQL);
                    lista = 2;
                    cargarListas("Dueños");
                }
            }
            if (focus == 3)
            {
                validar();
                string      consultaSQL = "";
                Veterinario v           = new Veterinario();
                v.pCodigo_Veterinario = Convert.ToInt32(txtIDvet.Text);
                v.pNombres            = txtnombrevet.Text;
                v.pApellidos          = txtApellidovet.Text;
                v.pDireccion          = txtcallevet.Text;
                v.pTelefono           = Convert.ToInt32(txtTelVet.Text);
                v.pEmail = txtMalidvet.Text;
                if (cbxEspecialista.Checked)
                {
                    v.pEspecialista = 1;
                }
                else
                {
                    v.pEspecialista = 0;
                }

                if (nuevo)
                {
                    if (!Existe(v.pCodigo_Veterinario))
                    {
                        consultaSQL = "INSERT INTO Veterinarios (Id_Veterinario,Apellidos,Nombres,Telefono,Direccion,[E-mail],Especialista)"
                                      + " VALUES ("
                                      + v.pCodigo_Veterinario + ",'"
                                      + v.pApellidos + "','"
                                      + v.pNombres + "',"
                                      + v.pTelefono + ",'"
                                      + v.pDireccion + "','"
                                      + v.pEmail + "',"
                                      + v.pEspecialista + ")";

                        OD.actualizarBD(consultaSQL);
                        lista = 3;
                        cargarListas("Veterinarios");
                    }
                    else
                    {
                        MessageBox.Show("el Veterinario ya se encuentra registrado...");
                    }
                }

                if (nuevo == false)
                {
                    consultaSQL = "UPDATE Veterinarios"
                                  + " SET"
                                  + " Nombre = '" + v.pNombres + "',"
                                  + " Apellidos = '" + v.pApellidos + "',"
                                  + " Direccion = '" + v.pDireccion + "',"
                                  + " Telefono =" + v.pTelefono + ","
                                  + " [E-mail] = " + v.pEmail + "',"
                                  + " Especialista = " + v.pEspecialista
                                  + " WHERE id_Veterinario = " + v.pCodigo_Veterinario;
                    OD.actualizarBD(consultaSQL);
                    lista = 3;
                    cargarListas("Veterinarios");
                }
            }
        }
Example #2
0
        private void cargarListas(string nombreTabla)
        {
            if (lista == 1)
            {
                nombreTabla = "Mascotas";
                c           = 0;
                lstMascota.Items.Clear();
                OD.leerTabla(nombreTabla);
                while (OD.pLector.Read())
                {
                    Mascota M = new Mascota();
                    if (!OD.pLector.IsDBNull(0))
                    {
                        M.pCodigo = OD.pLector.GetInt32(0);
                    }
                    if (!OD.pLector.IsDBNull(1))
                    {
                        M.pnombre = OD.pLector.GetString(1);
                    }
                    if (!OD.pLector.IsDBNull(2))
                    {
                        M.pDescripcion = OD.pLector.GetString(2);
                    }
                    if (!OD.pLector.IsDBNull(3))
                    {
                        M.pFecha = OD.pLector.GetDateTime(3);
                    }
                    if (!OD.pLector.IsDBNull(4))
                    {
                        M.pTipo = OD.pLector.GetInt32(4);
                    }
                    if (!OD.pLector.IsDBNull(5))
                    {
                        M.pDueño = OD.pLector.GetInt32(5);
                    }
                    if (!OD.pLector.IsDBNull(6))
                    {
                        M.pSexo = OD.pLector.GetInt32(6);
                    }
                    if (!OD.pLector.IsDBNull(7))
                    {
                        M.pVet = OD.pLector.GetInt32(7);
                    }

                    MA[c] = M;
                    c++;
                }
                OD.pLector.Close();
                OD.desconectar();
                for (int i = 0; i < c; i++)

                {
                    lstMascota.Items.Add(MA[i].pCodigo + " - " + MA[i].pnombre).ToString();
                }
            }
            else
            if (lista == 2)
            {
                nombreTabla = "Dueños";
                c           = 0;
                lstDueños.Items.Clear();
                OD.leerTabla(nombreTabla);
                while (OD.pLector.Read())
                {
                    Dueño d = new Dueño();
                    if (!OD.pLector.IsDBNull(0))
                    {
                        d.pCod_dueño = OD.pLector.GetInt32(0);
                    }
                    if (!OD.pLector.IsDBNull(1))
                    {
                        d.pNombres = OD.pLector.GetString(1);
                    }
                    if (!OD.pLector.IsDBNull(2))
                    {
                        d.pApellidos = OD.pLector.GetString(2);
                    }
                    if (!OD.pLector.IsDBNull(3))
                    {
                        d.pDireccion = OD.pLector.GetString(3);
                    }
                    if (!OD.pLector.IsDBNull(4))
                    {
                        d.pTelefono = OD.pLector.GetInt32(4);
                    }
                    if (!OD.pLector.IsDBNull(5))
                    {
                        d.pEmail = OD.pLector.GetString(5);
                    }

                    DU[c] = d;
                    c++;
                }
                OD.pLector.Close();
                OD.desconectar();
                for (int i = 0; i < c; i++)

                {
                    lstDueños.Items.Add(DU[i].pCod_dueño + " - " + DU[i].pNombres).ToString();
                }
            }
            else
            if (lista == 3)
            {
                nombreTabla = "Veterinarios";
                c           = 0;
                lstVet.Items.Clear();
                OD.leerTabla(nombreTabla);
                while (OD.pLector.Read())
                {
                    Veterinario v = new Veterinario();
                    if (!OD.pLector.IsDBNull(0))
                    {
                        v.pCodigo_Veterinario = OD.pLector.GetInt32(0);
                    }
                    if (!OD.pLector.IsDBNull(1))
                    {
                        v.pNombres = OD.pLector.GetString(1);
                    }
                    if (!OD.pLector.IsDBNull(2))
                    {
                        v.pApellidos = OD.pLector.GetString(2);
                    }
                    if (!OD.pLector.IsDBNull(3))
                    {
                        v.pTelefono = OD.pLector.GetInt32(3);
                    }
                    if (!OD.pLector.IsDBNull(4))
                    {
                        v.pDireccion = OD.pLector.GetString(4);
                    }
                    if (!OD.pLector.IsDBNull(5))
                    {
                        v.pEmail = OD.pLector.GetString(5);
                    }
                    //if (!OD.pLector.IsDBNull(6))
                    //    v.pEspecialista = OD.pLector.GetBoolean(6);


                    VE[c] = v;
                    c++;
                }
                OD.pLector.Close();
                OD.desconectar();
                for (int i = 0; i < c; i++)

                {
                    lstVet.Items.Add(VE[i].pCodigo_Veterinario + " - " + VE[i].pNombres).ToString();
                }
            }
        }