private void btnUpdate_Click(object sender, EventArgs e) { if (listCD.Count == 0) { MessageBox.Show("You don't have any item to update", "Update Error", MessageBoxButtons.OK); return; } if (gvCD.SelectedRows.Count == 0) { ErrorClick.SetError(btnSave, "Please select row!!!"); return; } ErrorClick.Clear(); DataGridViewRow row = gvCD.SelectedRows[0]; FormInput update = new FormInput(); CDInformation cd = new CDInformation( row.Cells[0].Value.ToString(), row.Cells[1].Value.ToString(), row.Cells[2].Value.ToString(), row.Cells[3].Value.ToString(), int.Parse(row.Cells[4].Value.ToString())); for (int i = 0; i < lSong.Items.Count; i++) { cd.Song.Add((string)lSong.Items[i]); } update.setInfo(cd); lSong.Items.Clear(); update.Owner = this; update.IsAdd = false; update.ShowDialog(); }
private void btnLoad_Click(object sender, EventArgs e) { DialogResult result = FileOpenDialog.ShowDialog(); if (result == DialogResult.OK) { string file = FileOpenDialog.FileName; string[] CDs = File.ReadAllLines(file); listCD = new List <CDInformation>(); if (CDs == null || CDs.Count() == 0) { MessageBox.Show("File is empty!!!", "Empty File", MessageBoxButtons.OK); return; } foreach (string CD in CDs) { string[] CDInfo = CD.Split('~'); CDInformation info = new CDInformation( CDInfo[0], CDInfo[1], CDInfo[2], CDInfo[3], int.Parse(CDInfo[4])); string[] songs = CDInfo[5].Split('#'); foreach (string song in songs) { info.Song.Add(song); } listCD.Add(info); } loadListData(); } }
public void addNew() { CDInformation cd = new CDInformation( txtID.Text, txtAlbum.Text, txtSinger.Text, cbxGenre.Text, int.Parse(txtDuration.Text) ); for (int i = 0; i < listSongs.Items.Count; i++) { cd.Song.Add(listSongs.Items[i].ToString()); } FormManage owner = (FormManage)this.Owner; foreach (CDInformation CD in owner.ListCD) { if (owner.ListCD.Count == 0) { break; } if (CD.ID1.Equals(txtID.Text)) { ErrorID.SetError(txtID, "This ID is already existed!!"); return; } } ErrorID.Clear(); owner.ListCD.Add(cd); owner.loadListData(); btnReset_Click(this, null); }
public void setInfo(CDInformation cd) { txtID.Text = cd.ID1; txtID.Enabled = false; txtAlbum.Text = cd.Album1; txtSinger.Text = cd.Singer1; cbxGenre.SelectedIndex = cbxGenre.FindStringExact(cd.Genre1); txtDuration.Text = cd.Duration.ToString(); listSongs.Items.Clear(); listSongs.Items.AddRange(cd.Song.ToArray()); }
public void update() { FormManage ownder = (FormManage)this.Owner; DataGridViewRow row = new DataGridViewRow(); CDInformation cd = new CDInformation( txtID.Text, txtAlbum.Text, txtSinger.Text, cbxGenre.Text, int.Parse(txtDuration.Text) ); for (int i = 0; i < listSongs.Items.Count; i++) { cd.Song.Add(listSongs.Items[i].ToString()); } FormManage owner = (FormManage)this.Owner; foreach (CDInformation CD in owner.ListCD) { if (owner.ListCD.Count == 0) { break; } if (CD.ID1.Equals(txtID.Text)) { CD.Album1 = cd.Album1; CD.Singer1 = cd.Singer1; CD.Genre1 = cd.Genre1; CD.Duration = cd.Duration; CD.Song = cd.Song; break; } } owner.loadListData(); this.Close(); }