• C# KTV 系统 SQL数据库连接 C# 应用窗体


    ---恢复内容开始---

    五道口 北大青鸟校区

    KTV项目

    指导老师: 袁玉明

     SQL数据库关系图

     

    第一步:

      1  private void DoubleClicklvContry() 
      2         {
      3             if (this.lvtype.SelectedItems[0]!=null)
      4             {
      5                 this.lvContry.Visible = true;
      6                 this.lvtype.Visible = false;
      7                 type = this.lvtype.SelectedItems[0].Tag.ToString();
      8                 this.lvContry.Location = this.lvtype.Location;
      9                 lvContry.Dock = DockStyle.Fill;
     10             }
     11             string sql = "select singertype_id,singertype_name,singertype_imageURL from singer_type";
     12             cmd = new SqlCommand(sql, con.Conntion);
     13             try
     14             {
     15                 con.OpenConntion();
     16                 SqlDataReader reader = cmd.ExecuteReader();
     17                 if (this.lvContry.Items != null)
     18                 {
     19                     lvSinger.Items.Clear();
     20                 }
     21                 if (reader.HasRows)
     22                 {
     23                     int index = 0;
     24                     while (reader.Read())
     25                     {
     26                         ListViewItem item = new ListViewItem();
     27                         item.Text = reader[1].ToString();
     28                         item.Tag = reader[0].ToString(); 
     29                         this.imageList2.Images.Add(Image.FromFile(@"E:KTVSingerTypeIamge" + reader[2].ToString()));
     30                         item.ImageIndex =index;
     31                         this.lvContry.Items.Add(item);
     32                         index++;
     33                     }
     34                 }
     35                 reader.Close();
     36             }
     37             catch (Exception ex)
     38             {
     39                 MessageBox.Show(ex.Message);
     40             }
     41             finally 
     42             {
     43                 con.CloseConntion();
     44             }
     45         }
     46 
     47 
     48 第二部:
     49         private void lvtype_DoubleClick_1(object sender, EventArgs e)
     50         {
     51             DoubleClicklvContry();
     52         }
     53         /// <summary>
     54         /// 给lvSinger添加数据
     55         /// </summary>
     56         private void DoubleClicklvSinger() 
     57         {
     58             if (this.lvContry.SelectedItems[0]!=null)
     59             {
     60                 this.lvSinger.Visible = true;
     61                 this.lvContry.Visible = false;
     62                 this.lvSinger.Location = this.lvContry.Location;
     63                 this.lvSinger.Dock = DockStyle.Fill;
     64 
     65                 string sql = string.Format("select singer_id,singer_name,singer_photo_url from singer_info where singer_sex='{0}' and singertype_id={1}",
     66                 type,Convert.ToInt32(this.lvContry.SelectedItems[0].Tag));
     67                 cmd=new SqlCommand(sql,con.Conntion);
     68                 try
     69                 {
     70                     con.OpenConntion();
     71                     //imageList3.Images.Clear();
     72                     SqlDataReader reader = cmd.ExecuteReader();
     73                     if (this.lvSinger.Items!=null)
     74                     {
     75                         lvSinger.Items.Clear();
     76                     }
     77                     if (reader.HasRows)
     78                     {
     79                         int index = 0;
     80                         while (reader.Read())
     81                         {
     82                             ListViewItem item = new ListViewItem();
     83                             item.Text = reader[1].ToString();
     84                             item.Tag = reader[0].ToString();
     85                             this.imageList3.Images.Add(Image.FromFile(@"E:KTVsingerPhoto" + reader[2].ToString()));
     86                             item.ImageIndex = index;
     87                             this.lvSinger.Items.Add(item);
     88                             index++;
     89                         }
     90                     }
     91                     reader.Close();
     92                 }
     93                 catch (Exception ex)
     94                 {
     95                     MessageBox.Show(ex.Message);
     96                 }
     97                 finally {
     98                     con.CloseConntion();
     99                 }
    100             }
    101         }
    102 
    103 
    

    104 第三部:  查找到该地区的歌手的歌曲

     1    private void lvContry_DoubleClick(object sender, EventArgs e)
     2         {
     3             DoubleClicklvSinger();
     4         }        private void DoubleClickSong() 
     5         {
     6             if (this.lvSinger.SelectedItems[0]!=null)
     7             {
     8                  string sql = string.Format("select song_id,song_name,song_url,singer_name from song_info,singer_info"+
     9                 " where song_info.singer_id=singer_info.singer_id and singer_info.singer_id={0}",Convert.ToInt32(this.lvSinger.SelectedItems[0].Tag));
    10                  FrmSong fs = new FrmSong();
    11                  fs.sql = sql;
    12 
    13                  fs.Show();
    14                  this.Hide();
    15             }

    第四部:   选中歌手信息数据库连接↓

    1   private void FrmSong_Load(object sender, EventArgs e)
    2         {
    3            
    4             adapter = new SqlDataAdapter(sql, db.Conntion);
    5             adapter.Fill(ds, "song_info");
    6       
    7             this.dataGridView1.DataSource = ds.Tables["song_info"];
    8             this.dataGridView1.AutoGenerateColumns = false;

     

    以点歌曲传惨的列表

     public string Name { get; set; }
            public string age { get; set; }
            private void BOFANG_Load(object sender, EventArgs e)
            {
                this.listView1.Items.Clear();
                foreach (Song item in ListSong.list)
                {
                    ListViewItem lvitem = new ListViewItem(item.SongName);
                    lvitem.SubItems.Add(item.SongPath);
                    string sate = item.Sate == Sateze.unPaly ? "未播放" : "已播放";
                    lvitem.SubItems.Add(sate);
                    this.listView1.Items.Add(lvitem);

    播放音乐原理图

    第五部:  if 判定DATA 窗体传惨
    传送到以点歌曲中
    private void dataGridView1_DoubleClick(object sender, EventArgs e)
            {
                if (this.dataGridView1.SelectedRows[0] != null)
                {
                    BOFANG dd = new BOFANG();
                    Song song = new Song();
                    song.SongName = this.dataGridView1.SelectedRows[0].Cells[3].Value.ToString();
                    song.SongPath = this.dataGridView1.SelectedRows[0].Cells[2].Value.ToString();
                    dd.Name = song.SongName;
                    ListSong.AddSong(song);
                    
                    MessageBox.Show("添加成功,请在已点歌曲中查看!!!");
    
    
    
    
    第六步:拼音点歌
     
    private void button1_Click(object sender, EventArgs e)
            {
                string en = textBox1.Text;
                SqlConnection con = new SqlConnection(Sql.str);
                string sql =string.Format( "select * from song_info where  song_ab like '"+en+"%'");
             SqlDataAdapter da = new SqlDataAdapter(sql,con);
                DataSet ds = new DataSet();
    
                da.Fill(ds, "song_info");
    
                dataGridView1.DataSource = ds.Tables["song_info"];
                SqlCommand cmd = new SqlCommand(sql,con);
                try
                {
                    con.Open();
                    int count = cmd.ExecuteNonQuery();
                    if (count > 0)
                    {
                        MessageBox.Show("查找成功");
                    }
                  
                }
                catch (Exception)
                {
    
                    MessageBox.Show("网络异常请检查网络或者SQL 数据库!!!");
                    con.Close();

    ---恢复内容结束---

  • 相关阅读:
    线段树lazy标记??Hdu4902
    3D游戏引擎〇 開始
    实时分析之客户画像项目实践
    ubuntu14.04系统中virtualbox安装Oracle VM VirtualBox Extension Pack包
    《Android源代码设计模式解析与实战》读书笔记(二十二)
    最长递增子序列的数量
    springmvc学习笔记(19)-RESTful支持
    hadoop(三):hdfs 机架感知
    hadoop(二):hdfs HA原理及安装
    hadoop(一):深度剖析hdfs原理
  • 原文地址:https://www.cnblogs.com/bdqnbenet/p/4671452.html
Copyright © 2020-2023  润新知