zoukankan      html  css  js  c++  java
  • KTV项目中歌星点歌3个ListView的跳转

    歌星点歌3个ListView之间的跳转代码如下:

    string singtype = "组合";
    int singertype_id=0;
    string result = "";
    private void 歌星点歌_Load(object sender, EventArgs e)
    {
       listView2.Visible = false;//隐藏地区
       listView3.Visible = false;//隐藏歌手
    }
    //由歌手类型跳转到地区即第二个listview
    private void listView1_SelectedIndexChanged(object sender, EventArgs e)
    {
    LoadSinger();
    }
    public void LoadSinger()
    {
    if (listView1.SelectedItems[0]!= null)
    {
    //隐藏歌手类别,显示listview2即地区
    listView1.Visible = false; //隐藏第一个窗体即第一个ListView
    listView2.Location = listView1.Location;
    listView2.Dock = DockStyle.Fill; //填充父容器
    listView2.Visible = true; //显示第二个窗体
    this.singtype = Convert.ToString(listView1.SelectedItems[0].Tag);//记录选择的歌手类型(组合)
    }

    //连接数据库,创建对象
    SqlConnection con = new SqlConnection(SQL.str);
    //准备sql语句
    string sql = "select singertype_id ,singertype_name from dbo.[singer_type(歌手分类表)] ";
    //命令
    SqlCommand cmd = new SqlCommand(sql, con);

    try
    {
    //打开连接
    con.Open();
    SqlDataReader dr = cmd.ExecuteReader();
    listView2.Items.Clear();
    if (dr.HasRows)
    {
    int ImageIndex = 0;
    while (dr.Read())
    {
    ListViewItem lvitem = new ListViewItem();
    int typeid = Convert.ToInt32(dr["singertype_id"]);
    string typename = Convert.ToString(dr["singertype_name"]);
    lvitem.Text = typename;
    lvitem.Tag = typeid;
    lvitem.ImageIndex = ImageIndex;
    listView2.Items.Add(lvitem);
    ImageIndex++;
    }
    }
    }
    catch
    {
    MessageBox.Show("系统维修");
    }
    finally
    {
    con.Close();
    }
    }


    //由地区跳转到歌手即第三个listview
    private void listView2_SelectedIndexChanged(object sender, EventArgs e)
    {
    Singer();
    }
    public void Singer()
    {
    if (listView1.SelectedItems[0] != null)
    {
    listView1.Visible = false;//隐藏第一个窗体
    listView2.Visible = false;//隐藏第二个窗体
    listView3.Dock = DockStyle.Fill; //填充父容器
    listView3.Visible = true;//显示第三个窗体

    this.singertype_id = Convert.ToInt32(listView2.SelectedItems[0].Tag);//记录选择的Tag的值
    }
    SqlConnection con = new SqlConnection(SQL.str);

    if(result!="组合"){
    result = singtype == "女歌手" ? "女歌手" : "男歌手";
    }
    string sql = "select singer_phone_url,singertype_id,singer_name from [singer_info(歌手表)] where singer_sex='" + result + "' and singertype_id=" + singertype_id + "";

    SqlCommand cmd = new SqlCommand(sql, con);
    con.Open();
    SqlDataReader dr = cmd.ExecuteReader();
    int ImageIndex = 0;
    imageList3.Images.Clear();
    listView3.Items.Clear();

    if (dr.HasRows)
    {
    while (dr.Read())
    {
    ListViewItem lvitem = new ListViewItem();
    string fullphoto = KTVUtil.imagePath + "\" + dr["singer_phone_url"].ToString();
    //将头像放到imagelist中
    imageList3.Images.Add(Image.FromFile(fullphoto));
    //将歌手添加到listview中
    int typeid = Convert.ToInt32(dr["singertype_id"]);
    string typename = Convert.ToString(dr["singer_name"]);
    lvitem.Text = Convert.ToString(typename);
    lvitem.Tag = typeid;
    lvitem.ImageIndex = ImageIndex;
    ImageIndex++;
    listView3.Items.Add(lvitem);

    }
    }
    }

  • 相关阅读:
    win10系统u盘安装单个文件超过4g解决办法
    单片机下使用IIC
    uart
    socket
    Linux中 ./configure --prefix命令
    linux下配置安装python3
    linux下的dhcp服务器实现
    安卓出现错误: java.lang.ClassCastException: android.widget.TextView cannot be cast to android.widget.EditText
    C语言基础02
    C语言基础01
  • 原文地址:https://www.cnblogs.com/sujulin/p/6553001.html
Copyright © 2011-2022 走看看