コード例 #1
0
        public List <ItemApp> GetItemApps()
        {
            using (SqlConnection con = new SqlConnection(connectionString))
            {
                con.Open();
                SqlCommand cmd = new SqlCommand("select * from itemTable", con);

                cmd.CommandType = CommandType.Text;


                SqlDataReader reader = cmd.ExecuteReader();

                while (reader.Read())
                {
                    ItemApp itemApp = new ItemApp();

                    itemApp.ItemID = Convert.ToInt32(reader[0]);

                    byte[] myImage = new byte[0];
                    myImage = (byte[])reader[1];
                    MemoryStream stream = new MemoryStream(myImage);
                    itemApp.ImageFile = Image.FromStream(stream);

                    itemApp.Title       = reader[2].ToString();
                    itemApp.Description = reader[3].ToString();
                    itemApp.PriceTag    = Convert.ToDouble(reader[4]);

                    itemAppList.Add(itemApp);
                }

                reader.Close();
                con.Close();
            }
            return(itemAppList);
        }
コード例 #2
0
        public List <ItemApp> GetListaItems(int idrol)
        {
            List <ItemApp> litem    = new List <ItemApp>();
            List <ItemApp> lsubitem = new List <ItemApp>();

            try
            {
                ConsultaMySql consulta = new ConsultaMySql(@"select * from newlafarnet.item_apps i
                    inner join newlafarnet.item_rol ir on i.id = ir.id_item_app
                    where ir.id_rol = " + idrol + @" and tipo = 'm';");
                DataTable     dt       = consulta.EjecutarConsulta(Parametros.ConexionBDMySQL());
                if (dt.Rows.Count <= 0)
                {
                    throw new Exception("No trajo datos  de la consulta de la base de datos");
                }

                foreach (DataRow item in dt.Rows)
                {
                    ItemApp ia = new ItemApp
                    {
                        id                   = Convert.ToInt32(item["id"]),
                        url                  = (item["url"]).ToString(),
                        icon                 = (item["icon"]).ToString(),
                        app_id               = Convert.ToInt32(item["app_id"]),
                        itemName             = (item["itemName"]).ToString(),
                        tipo                 = (item["tipo"]).ToString(),
                        id_mother            = Convert.ToInt32(item["id_mother"]),
                        usuario_creacion     = (item["usuario_creacion"]).ToString(),
                        fecha_creacion       = Convert.ToDateTime(item["fecha_creacion"]),
                        usuario_modificacion = (item["usuario_modificacion"]).ToString(),
                        fecha_modificacion   = Convert.ToDateTime(item["fecha_modificacion"]),
                        items                = this.GetListaSubItems(idrol, Convert.ToInt32(item["id"]))
                    };
                    litem.Add(ia);
                }
                return(litem);
            }
            catch (Exception ex)
            {
                return(litem);
            }
        }