示例#1
0
        private void ShowBaiHat()
        {
            var db   = new DBGoMusicEntities();
            var list = db.BaiHats.ToList();

            this.lstSong.DataSource = list;
        }
示例#2
0
        private void btnDelete_Click(object sender, EventArgs e)
        {
            var db = new DBGoMusicEntities();

            if (MessageBox.Show("Do you want to delete this song?", "Confirm", MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes)
            {
                for (int i = 0; i < this.lstSong.SelectedRows.Count; i++)
                {
                    var row  = this.lstSong.SelectedRows[i];
                    var item = (BaiHat)row.DataBoundItem;

                    try
                    {
                        BaiHat bh = db.BaiHats.Find(item.id);
                        db.BaiHats.Remove(bh);
                        db.SaveChanges(); //Do it
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                }
                this.ShowBaiHat();
            }
        }
示例#3
0
 private void btnSave_Click(object sender, EventArgs e)
 {
     try
     {
         var db     = new DBGoMusicEntities();
         var updatE = db.BaiHats.Find(this.bh.id);
         updatE.Song            = this.txtName.Text;
         updatE.Singer          = this.txtSinger.Text;
         updatE.Songwriter      = this.txtWriter.Text;
         updatE.Album           = this.txtAlbum.Text;
         db.Entry(updatE).State = System.Data.Entity.EntityState.Modified;
         db.SaveChanges();
         this.Close();
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
示例#4
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            BaiHat bh = new BaiHat();

            bh.Song       = this.txtName.Text;
            bh.Singer     = this.txtSinger.Text;
            bh.Songwriter = this.txtWriter.Text;
            bh.Album      = this.txtAlbum.Text;
            try
            {
                var db = new DBGoMusicEntities();
                db.BaiHats.Add(bh);
                db.SaveChanges();
                this.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
示例#5
0
        private void txtSearch_TextChanged(object sender, EventArgs e)
        {
            DBGoMusicEntities db = new DBGoMusicEntities();

            lstSong.DataSource = db.BaiHats.ToList().Where(s => s.Song.ToLower().Contains(txtSearch.Text.ToLower().Trim())).ToList();
        }