Пример #1
0
        private void cargarlistamascotas(string nombretabla)
        {
            bd.leertabla(nombretabla);
            int c = 0;

            while (bd.Reader.Read())
            {
                Mascotacls mas = new Mascotacls();
                Clientecls cli = new Clientecls();
                if (!bd.Reader.IsDBNull(0))
                {
                    mas.Id = bd.Reader.GetInt32(0);
                }
                if (!bd.Reader.IsDBNull(1))
                {
                    mas.Nombre1 = bd.Reader.GetString(1);
                }
                if (!bd.Reader.IsDBNull(2))
                {
                    mas.FecNac = bd.Reader.GetDateTime(2);
                }
                if (!bd.Reader.IsDBNull(3))
                {
                    mas.Tipo = bd.Reader.GetInt32(3);
                }
                if (!bd.Reader.IsDBNull(4))
                {
                    mas.Sexo = bd.Reader.GetBoolean(4);
                }
                if (!bd.Reader.IsDBNull(5))
                {
                    mas.Peso = bd.Reader.GetDouble(5);
                }
                if (!bd.Reader.IsDBNull(6))
                {
                    mas.Descripcion = bd.Reader.GetString(6);
                }
                mas.Cliente = cli;
                if (!bd.Reader.IsDBNull(7))
                {
                    mas.Cliente.ClienteID = bd.Reader.GetInt32(7);
                }
                arraymascotas[c] = mas;
                c++;
            }
            bd.Reader.Close();
            bd.desconectar();
            listMascotas.Items.Clear();
            for (int i = 0; i < c; i++)
            {
                listMascotas.Items.Add(arraymascotas[i].Nombre1 + "  -------  " + arraymascotas[i].Descripcion);
            }
        }
Пример #2
0
        private void btnCargar_Click(object sender, EventArgs e)
        {
            if (validar() == true)
            {
                Mascotacls m = new Mascotacls();
                m.Nombre1     = txtNombre.Text;
                m.FecNac      = dtpFechaNac.Value;
                m.Tipo        = cmbTipo.SelectedIndex;
                m.Peso        = Convert.ToDouble(txtPeso.Text);
                m.Descripcion = txtDescripcion.Text;
                m.Cliente     = arrayclientes[listCliente.SelectedIndex];
                if (rdbHembra.Checked == true)
                {
                    m.Sexo = false;
                }
                else
                {
                    m.Sexo = true;
                }
                //cargar en la basde de datos

                if (nuevo == true)
                {
                    string consultasql = "insert into mascota (Nombre,fecha_nac,tipo,sexo,peso,descripcion,cliente_id) values " +
                                         "('" + m.Nombre1 +
                                         "','" + m.FecNac +
                                         "'," + m.Tipo +
                                         "," + m.Sexo +
                                         "," + m.Peso +
                                         ",'" + m.Descripcion +
                                         "'," + m.Cliente.ClienteID + ")";
                    bd.modificarbd(consultasql);
                    cargarlistamascotas("mascota");
                }
                else
                {
                    string consultasql = "Update mascota set " +
                                         "nombre= '" + m.Nombre1 + "'," +
                                         "fecha_nac= '" + m.FecNac + "'," +
                                         "tipo= " + m.Tipo + "," +
                                         "sexo= " + m.Sexo + "," +
                                         "peso= " + m.Peso + "," +
                                         "descripcion= '" + m.Descripcion + "'," +
                                         "cliente_id= " + m.Cliente.ClienteID + " " +
                                         "where id= " + arraymascotas[listMascotas.SelectedIndex].Id;
                    bd.modificarbd(consultasql);
                    cargarlistamascotas("mascota");
                }
            }
        }
        private void arraymas()
        {
            bd.leertabla("mascota");
            int cm = 0;

            while (bd.Reader.Read())
            {
                Mascotacls m = new Mascotacls();
                m.Id          = bd.Reader.GetInt32(0);
                m.Nombre1     = bd.Reader.GetString(1);
                m.FecNac      = bd.Reader.GetDateTime(2);
                m.Tipo        = bd.Reader.GetInt32(3);
                m.Descripcion = bd.Reader.GetString(4);
                Clientecls c = new Clientecls();
                m.Cliente           = c;
                m.Cliente.ClienteID = bd.Reader.GetInt32(5);
                arraymascotas[cm]   = m;
                cm++;
            }
            bd.Reader.Close();
            bd.desconectar();
        }