zoukankan      html  css  js  c++  java
  • KTV项目之3个ListView的跳转和加载歌手图片

    第一个ListView:

    第二个ListView:

    第三个ListView:

    定义一个KTVUtil类,在里面定义一个静态变量保存歌手图片

    1         //定义一个静态变量保存歌手图片路径
    2         public static string imagePath = "";

    在主窗体load事件拿歌手图片的前半部分路径:

     1  //连接字符串
     2             String str = "Data Source=.;Initial Catalog=MyKTV;uid=sa;";
     3             //创建连接对象
     4             SqlConnection con = new SqlConnection(str);
     5             con.Open();
     6             //准备sql语句
     7             string sql = "select resource_path from resource_path where resource_id=1";
     8             //创建命令对象
     9             SqlCommand cmd = new SqlCommand(sql, con);
    10             KTVUtil.imagePath = cmd.ExecuteScalar().ToString();
    11             con.Close();

    在第一个ListView_Click事件:

     1 listView2.Items.Clear();
     2             if (listView1.SelectedItems[0] != null)
     3             {
     4                 //隐藏歌手地区类的listView,显示歌手类的listView
     5                 listView1.Visible = false;
     6                 listView2.Location = listView1.Location;
     7                 listView2.Dock = DockStyle.Fill;
     8                 listView2.Visible = true;
     9                 this.singer_sex = Convert.ToString(listView1.SelectedItems[0].Tag);
    10                 
    11             }
    12             //连接字符串
    13             String str = "Data Source=.;Initial Catalog=MyKTV;uid=sa;";
    14             //创建连接对象
    15             SqlConnection con = new SqlConnection(str);
    16             //准备sql语句
    17             string sql = "select singertype_id,singertype_name from singer_type";
    18             //创建命令对象
    19             SqlCommand cmd = new SqlCommand(sql,con);
    20             try
    21             {
    22                 con.Open();
    23                 SqlDataReader dr = cmd.ExecuteReader();
    24                 listView3.Items.Clear();
    25 
    26                 if(dr.HasRows){
    27                     int index = 0;
    28                     while(dr.Read()){   //每Read一次拿到一个地区
    29                         //从数据库中读取一个歌手分类信息,就要创建一个ListViewItem
    30                         ListViewItem lvitem = new ListViewItem();
    31                         int typeId = Convert.ToInt32(dr["singertype_id"]);
    32                         string typename = Convert.ToString(dr["singertype_name"]);
    33                         lvitem.Text = typename;
    34                         lvitem.Tag = typeId;
    35                         lvitem.ImageIndex = index;
    36                         listView2.Items.Add(lvitem);
    37                         index++;
    38                                                               
    39                     }
    40                 }
    41             }
    42             catch
    43             {
    44                 MessageBox.Show("系统维护中");
    45             }
    46             finally {
    47                 
    48             }
    49         

     在第二个ListView_Click事件:

     1 listView1.Visible = false;
     2             listView2.Visible = false;
     3             listView3.Visible = true;
     4             listView3.Dock = DockStyle.Fill;
     5             listView3.Location = listView1.Location;
     6             this.singertype_id = Convert.ToInt32(listView2.SelectedItems[0].Tag);
     7             
     8             string str = "Data source = .; Initial catalog=MyKTV ;Uid = sa;";
     9             SqlConnection con = new SqlConnection(str);
    10            
    11             string sql = "select singer_id , singer_name , singer_photo_url from singer_info where singer_sex='"+singer_sex+"' and singertype_id="+singertype_id+ "";
    12             SqlCommand com = new SqlCommand(sql, con);
    13             con.Open();
    14        
    15             SqlDataReader dr = com.ExecuteReader();
    16           
    17             listView3.Items.Clear();
    18             int Imageindex = 0;   //歌手图像的索引
    19             if (dr.HasRows) {
    20                 while (dr.Read())
    21                 {
    22                   ListViewItem item = new ListViewItem();
    23                   string fullpath = KTVUtil.imagePath + "\" + Convert.ToString(dr["singer_photo_url"]);
    24                   imageList3.Images.Add(Image.FromFile(fullpath));
    25                   item.Text =Convert.ToString(dr["singer_name"]);
    26                   item.Tag = Convert.ToString(dr["singer_id"]);
    27                   item.ImageIndex = Imageindex;
    28                   listView3.Items.Add(item);
    29                   Imageindex++;
    30               }
    31               dr.Close();
    32             }
    33             con.Close();
  • 相关阅读:
    通过扩展让ASP.NET Web API支持JSONP -摘自网络
    怎么从sqlserver 数据库导出 insert 的数据语句
    'System.Web.Http.GlobalConfiguration' does not contain a definition for 'Configure'
    android学习笔记---发送状态栏通知
    .NET项目框架(转)
    Linux下查看文件权限、修改文件权限的方法
    免费的在线Web文件管理器:Net2FTP,Pydio,eXtplorer,KodExplorer–功能强大
    electronic data interchange 电子数据交换
    Asp.Net中Ajax实现登陆判断
    如何用JS判断网页中某个id的网页元素是否存在
  • 原文地址:https://www.cnblogs.com/liutao1122/p/6553446.html
Copyright © 2011-2022 走看看