Ejemplo n.º 1
0
        public EntAnimal Obtener(int id)
        {
            DataTable dt = new DatAnimal().Obtener(id);

            EntAnimal ani = new EntAnimal();

            if (dt.Rows.Count > 0)
            {
                ani.Id           = dt.Rows[0]["Anim_Id"] is DBNull ? 0 : Convert.ToInt32(dt.Rows[0]["Anim_Id"]);
                ani.Nombre       = dt.Rows[0]["Anim_Nomb"].ToString();
                ani.Tipo_Id      = Convert.ToInt32(dt.Rows[0]["Anim_Tipo_Id"]);
                ani.Tipo.Nombre  = dt.Rows[0]["Tipo_Nomb"].ToString();
                ani.Color_Id     = Convert.ToInt32(dt.Rows[0]["Anim_Colo_Id"]);
                ani.Color.Nombre = dt.Rows[0]["Colo_Nomb"].ToString();
                ani.Fecha_Alta   = dt.Rows[0]["Anim_Fech_Alta"] is DBNull?Convert.ToDateTime("01/01/1900") : Convert.ToDateTime(dt.Rows[0]["Anim_Fech_Alta"]);

                ani.Genero_Id     = Convert.ToInt32(dt.Rows[0]["Anim_Gene_Id"]);
                ani.Genero.Nombre = dt.Rows[0]["Gene_Nomb"].ToString();
                ani.Existencia    = Convert.ToInt32(dt.Rows[0]["Anim_Exis"]);
                ani.Edad          = Convert.ToInt32(dt.Rows[0]["Anim_Edad"]);
                ani.Peso          = Convert.ToDecimal(dt.Rows[0]["Anim_Peso"]);
                ani.Estatus       = Convert.ToBoolean(dt.Rows[0]["Anim_Esta"]);
                ani.FotoMini      = dt.Rows[0]["Anim_Foto_Mini"].ToString();
                ani.FotoPortada   = dt.Rows[0]["Anim_Foto_Port"].ToString();
                ani.Video         = dt.Rows[0]["Anim_Video"].ToString();

                return(ani);
            }
            else
            {
                throw new ApplicationException("No se encontró el animal solicitado");
            }
        }
Ejemplo n.º 2
0
        public List <EntAnimal> Obtener()
        {
            //DataTable dt = new DataTable();
            //DatAnimal da = new DatAnimal();
            //dt = da.Obtener();
            DataTable        dt   = new DatAnimal().Obtener();
            List <EntAnimal> list = new List <EntAnimal>();

            foreach (DataRow dr in dt.Rows)
            {
                EntAnimal ani = new EntAnimal();

                ani.Id           = dr["Anim_Id"] is DBNull ? 0 : Convert.ToInt32(dr["Anim_Id"]);
                ani.Nombre       = dr["Anim_Nomb"].ToString();
                ani.Tipo_Id      = Convert.ToInt32(dr["Anim_Tipo_Id"]);
                ani.Tipo.Nombre  = dr["Tipo_Nomb"].ToString();
                ani.Color_Id     = Convert.ToInt32(dr["Anim_Colo_Id"]);
                ani.Color.Nombre = dr["Colo_Nomb"].ToString();
                ani.Fecha_Alta   = dr["Anim_Fech_Alta"] is DBNull?Convert.ToDateTime("01/01/1900") : Convert.ToDateTime(dr["Anim_Fech_Alta"]);

                ani.Genero_Id     = Convert.ToInt32(dr["Anim_Gene_Id"]);
                ani.Genero.Nombre = dr["Gene_Nomb"].ToString();
                ani.Existencia    = Convert.ToInt32(dr["Anim_Exis"]);
                ani.Edad          = Convert.ToInt32(dr["Anim_Edad"]);
                ani.Peso          = Convert.ToDecimal(dr["Anim_Peso"]);
                ani.Estatus       = Convert.ToBoolean(dr["Anim_Esta"]);
                ani.FotoMini      = dr["Anim_Foto_Mini"].ToString();
                ani.FotoPortada   = dr["Anim_Foto_Port"].ToString();
                ani.Video         = dr["Anim_Video"].ToString();

                list.Add(ani);
            }

            return(list);
        }
Ejemplo n.º 3
0
        public void Insertar(EntAnimal ent)
        {
            int filas = new DatAnimal().Insertar(ent.Nombre, ent.Tipo_Id, ent.Color_Id, ent.Genero_Id, ent.Existencia, ent.Edad, ent.Peso, ent.Estatus, ent.FotoPortada, ent.FotoMini, ent.Video);

            if (filas != 1)
            {
                throw new ApplicationException("Error al insertar animal");
            }
        }
Ejemplo n.º 4
0
 protected void gvAnimales_RowUpdating(object sender, GridViewUpdateEventArgs e)
 {
     try
     {
         EntAnimal ani = new EntAnimal();
         ani.Nombre      = ((TextBox)gvAnimales.Rows[e.RowIndex].FindControl("txtNombreEIT")).Text;
         ani.Color_Id    = Convert.ToInt32(((DropDownList)gvAnimales.Rows[e.RowIndex].FindControl("ddlColorEIT")).SelectedValue);
         ani.Genero_Id   = Convert.ToInt32(((DropDownList)gvAnimales.Rows[e.RowIndex].FindControl("ddlGeneroEIT")).SelectedValue);
         ani.Peso        = Convert.ToDecimal(((TextBox)gvAnimales.Rows[e.RowIndex].FindControl("txtPesoEIT")).Text);
         ani.Fecha_Alta  = Convert.ToDateTime(((TextBox)gvAnimales.Rows[e.RowIndex].FindControl("txtFechaEIT")).Text);
         ani.Estatus     = ((CheckBox)gvAnimales.Rows[e.RowIndex].FindControl("chkEstatusEIT")).Checked;
         ani.FotoPortada = "img\\" + ((FileUpload)gvAnimales.Rows[e.RowIndex].FindControl("fuFotoPortadaEIT")).FileName;
     }
     catch (Exception ex)
     {
         MostrarMensaje(ex.Message);
     }
 }
Ejemplo n.º 5
0
    private void ModificarDatos(int Id)
    {
        EntAnimal ani = new EntAnimal();

        ani.Id         = Id;
        ani.Nombre     = txtNomb.Text.Trim();
        ani.Tipo_Id    = Convert.ToInt32(ddlTipo.SelectedValue);
        ani.Color_Id   = Convert.ToInt32(ddlColor.SelectedValue);
        ani.Genero_Id  = Convert.ToInt32(ddlGenero.SelectedValue);
        ani.Existencia = Convert.ToInt32(txtExit.Text.Trim());
        ani.Edad       = Convert.ToInt32(txtEdad.Text.Trim());
        ani.Peso       = Convert.ToDecimal(txtPeso.Text.Trim());
        ani.Estatus    = Convert.ToBoolean(1);

        if (fuFotoPortada.HasFile)
        {
            string               ruta      = Server.MapPath(@"img\");
            int                  fileSize  = fuFotoPortada.PostedFile.ContentLength;
            string               extension = System.IO.Path.GetExtension(fuFotoPortada.FileName);
            MemoryStream         str       = new MemoryStream(fuFotoPortada.FileBytes);
            System.Drawing.Image bmp       = System.Drawing.Image.FromStream(str);
            int                  ancho     = bmp.Width;
            int                  alto      = bmp.Height;

            if (fileSize <= 2100000 && (extension == ".jpg" || extension == ".jpeg") && (ancho == 1280 || alto == 720))
            {
                fuFotoPortada.SaveAs(ruta + fuFotoPortada.FileName);
                ani.FotoPortada = "img\\" + fuFotoPortada.FileName;
            }
            else
            {
                MostrarMensaje(string.Format("Tu archivo {0} es demasiado grande o no cumple con la extension \"jpg\" o no cumple con las dimensiones 1280 * 720", fuFotoPortada.FileName));
            }
        }
        else
        {
            ani.FotoPortada = ViewState["FotoPortada"].ToString();
        }
        ani.FotoMini = "img\\hipoMini.jpg";
        ani.Video    = txtUrl.Text.Trim() == "" ? "https://www.youtube.com/embed/xPndNFuqEWY" : txtUrl.Text.Trim();

        new BusAnimal().Actualizar(ani);
        Response.Redirect(Request.CurrentExecutionFilePath);
    }
Ejemplo n.º 6
0
    private void InsertarDatos()
    {
        EntAnimal ani = new EntAnimal();

        ani.Nombre     = txtNomb.Text.Trim();
        ani.Tipo_Id    = Convert.ToInt32(ddlTipo.SelectedValue);
        ani.Color_Id   = Convert.ToInt32(ddlColor.SelectedValue);
        ani.Genero_Id  = Convert.ToInt32(ddlGenero.SelectedValue);
        ani.Existencia = Convert.ToInt32(txtExit.Text.Trim());
        ani.Edad       = Convert.ToInt32(txtEdad.Text.Trim());
        ani.Peso       = Convert.ToDecimal(txtPeso.Text.Trim());
        ani.Estatus    = Convert.ToBoolean(1);

        if (fuFotoPortada.HasFile)
        {
            string ruta      = Server.MapPath(@"img\");
            int    fileSize  = fuFotoPortada.PostedFile.ContentLength;
            string extension = System.IO.Path.GetExtension(fuFotoPortada.FileName);
            if (fileSize <= 2100000 && (extension == ".jpg" || extension == ".jpeg"))
            {
                fuFotoPortada.SaveAs(ruta + fuFotoPortada.FileName);
                ani.FotoPortada = "img\\" + fuFotoPortada.FileName;
            }
            else
            {
                MostrarMensaje(string.Format("Tu archivo {0} es demasiado grande o no cumple con la extension \"jpg\"", fuFotoPortada.FileName));
            }
        }
        else
        {
            MostrarMensaje("Falta Foto de portada");
        }
        ani.FotoMini = "img\\hipoMini.jpg";
        ani.Video    = txtUrl.Text.Trim() == "" ? "https://www.youtube.com/embed/xPndNFuqEWY" : txtUrl.Text.Trim();
        new BusAnimal().Insertar(ani);
        Response.Redirect(Request.CurrentExecutionFilePath);
    }
Ejemplo n.º 7
0
        private void AddPet(object sender, RoutedEventArgs e)
        {
            String name = Name.Text;

            if (Age.Text == "")
            {
                MessageBox.Show("Fill all required fields!");
                return;
            }
            int       age         = Int32.Parse(Age.Text);
            String    breed       = Breed.Text;
            String    description = Description.Text;
            EntAnimal animal      = new EntAnimal();

            if (name == "")
            {
                MessageBox.Show("Fill all required fields!");
                return;
            }
            if (imageData == null)
            {
                MessageBox.Show("Fill all required fields!");
                return;
            }

            animal.name  = name;
            animal.image = imageData;
            animal.age   = age;
            int size_id = 0;

            if (size == "Small")
            {
                size_id = 1;
            }
            else if (size == "Medium")
            {
                size_id = 2;
            }
            else
            {
                size_id = 3;
            }
            animal.sizeId = size_id;
            int type_id = 0;

            if (type == "Cat")
            {
                type_id = 2;
            }
            else
            {
                type_id = 1;
            }
            animal.typeId = type_id;
            if (breed == "")
            {
                MessageBox.Show("Fill all required fields!");
                return;
            }
            animal.breed = breed;
            if (description == "")
            {
                MessageBox.Show("Fill all required fields!");
                return;
            }
            animal.description = description;
            animal.sex         = sex;
            PetsContext context = new PetsContext();

            context.Animals.Add(animal);
            context.SaveChanges();
            petsImproved.MainWindow.AppWindow.getData();
            this.Close();
        }