diff --git a/GHNamespace8/MainMenu.cs b/GHNamespace8/MainMenu.cs index c63eabd..046dec2 100644 --- a/GHNamespace8/MainMenu.cs +++ b/GHNamespace8/MainMenu.cs @@ -341,6 +341,8 @@ public class MainMenu : Form }; private IContainer components; + private ToolStripMenuItem _exportSongListToolStripMenuItem; + private ToolStripMenuItem _exportSongListToolStripMenuItem1; private TabControl _tabControl; private TabPage _setlistTab; private ToolStripContainer _setlistConfigContainer; @@ -2050,6 +2052,8 @@ private void InitializeComponent() _saveSghMenuItem = new ToolStripMenuItem(); _saveChartMenuItem = new ToolStripMenuItem(); _exportSetlistAsChartsToolStripMenuItem = new ToolStripMenuItem(); + _exportSongListToolStripMenuItem = new ToolStripMenuItem(); + _exportSongListToolStripMenuItem1 = new ToolStripMenuItem(); _toolStripSeparator6 = new ToolStripSeparator(); _exitMenuItem = new ToolStripMenuItem(); _addMenuItem = new ToolStripMenuItem(); @@ -2310,6 +2314,8 @@ private void InitializeComponent() _saveSghMenuItem, _saveChartMenuItem, _exportSetlistAsChartsToolStripMenuItem, + _exportSongListToolStripMenuItem, + _exportSongListToolStripMenuItem1, _toolStripSeparator6, _exitMenuItem }); @@ -2396,6 +2402,24 @@ private void InitializeComponent() _exportSetlistAsChartsToolStripMenuItem.Size = new Size(264, 22); _exportSetlistAsChartsToolStripMenuItem.Text = "Export Setlist as Charts"; _exportSetlistAsChartsToolStripMenuItem.Click += exportSetlistAsChartsToolStripMenuItem_Click_1; + // + // exportSongListToolStripMenuItem + // + _exportSongListToolStripMenuItem.Enabled = false; + _exportSongListToolStripMenuItem.Name = "exportSongListToolStripMenuItem"; + _exportSongListToolStripMenuItem.Size = new Size(264, 22); + _exportSongListToolStripMenuItem.Text = "Export Setlist as CSV"; + _exportSongListToolStripMenuItem.ToolTipText = "Export songs in the selected setlist as CSV"; + _exportSongListToolStripMenuItem.Click += new EventHandler(exportSongListToolStripMenuItem_Click); + // + // exportSongListToolStripMenuItem1 + // + _exportSongListToolStripMenuItem1.Enabled = false; + _exportSongListToolStripMenuItem1.Name = "exportSongListToolStripMenuItem1"; + _exportSongListToolStripMenuItem1.Size = new Size(264, 22); + _exportSongListToolStripMenuItem1.Text = "Export Songlist as CSV"; + _exportSongListToolStripMenuItem1.ToolTipText = "Export the whole songlist as CSV"; + _exportSongListToolStripMenuItem1.Click += new EventHandler(exportSongListToolStripMenuItem1_Click); // // toolStripSeparator6 // @@ -3915,6 +3939,8 @@ private void method_12(bool bool1) argAc0.Enabled = bool1; argB30.Enabled = bool1; export.Enabled = bool1; + _exportSongListToolStripMenuItem.Enabled = bool1; + _exportSongListToolStripMenuItem1.Enabled = bool1; } public void InitializeLanguageList() @@ -4516,5 +4542,123 @@ private void TierApply_Btn_Click(object sender, EventArgs e) private void forceRB3MidConversionToolStripMenuItem_Click(object sender, EventArgs e) { } + + private void exportSongListToolStripMenuItem_Click(object sender, EventArgs e) + { + if (_gh3Songlist.Gh3SetlistList.ContainsKey(_selectedSetlist)) + { + SaveFileDialog saveFileDlg = new SaveFileDialog(); + saveFileDlg.Filter = "CSV files (*.csv)|*.csv"; + saveFileDlg.Title = "Please select where you would like to save the songlist"; + saveFileDlg.FileName = String.Format("{0}.csv", _setlistDropBox.Text); + if (saveFileDlg.ShowDialog() != DialogResult.OK) + { + return; + } + + // Open selected file for writing + using (Stream myStream = saveFileDlg.OpenFile()) + { + if (myStream == null) + { + MessageBox.Show("Couldn't open file for writing"); + return; + } + + // Get songs for this setlist + List songs = new List(); + foreach (Gh3Tier tier in _gh3Songlist.Gh3SetlistList[_selectedSetlist].Tiers) + { + foreach (Gh3Song song in tier.Songs) + { + songs.Add(song); + } + } + + // Sort songs by artist and title + songs = songs.OrderBy(song => song.Artist).ThenBy(song => song.Title).ToList(); + + // Write to file + using (StreamWriter outFile = new StreamWriter(myStream)) + { + // Write CSV header + outFile.WriteLine("\"artist\",\"song\""); + foreach (Gh3Song song in songs) + { + outFile.WriteLine(String.Format("\"{0}\",\"{1}\"", song.Artist.Replace("\"", "\"\""), + song.Title.Replace("\"", "\"\""))); + } + } + } + + MessageBox.Show("Done."); + } + } + + private void exportSongListToolStripMenuItem1_Click(object sender, EventArgs e) + { + SortSongListForm form = new SortSongListForm(); + form.ShowDialog(); + + bool sortBySetlist = form.sortBy == SortSongListForm.SortBy.Setlist; + + SaveFileDialog saveFileDlg = new SaveFileDialog(); + saveFileDlg.Filter = "CSV files (*.csv)|*.csv"; + saveFileDlg.Title = "Please select where you would like to save the songlist"; + saveFileDlg.FileName = "songlist.csv"; + if (saveFileDlg.ShowDialog() != DialogResult.OK) + { + return; + } + + // Open selected file for writing + using (Stream myStream = saveFileDlg.OpenFile()) + { + if (myStream == null) + { + MessageBox.Show("Couldn't open file for writing"); + return; + } + + // Retrieve songs and associated setlist name + List> songs = new List>(); + // Setlist contains a pair of setlist name => setlist id + foreach (KeyValuePair setlist in _gh3Songlist.Class2140) + { + foreach (Gh3Tier tier in _gh3Songlist.Gh3SetlistList[_selectedSetlist = _gh3Songlist.method_9(setlist.Key)].Tiers) + { + foreach (Gh3Song song in tier.Songs) + { + songs.Add(new KeyValuePair(setlist.Key, song)); + } + } + } + + // Sort by setlist or artist + if (sortBySetlist) + { + songs = songs.OrderBy(pair => pair.Key).ThenBy(pair => pair.Value.Artist).ThenBy(pair => pair.Value.Title).ToList(); + } + else + { + songs = songs.OrderBy(pair => pair.Value.Artist).ThenBy(pair => pair.Value.Title).ThenBy(pair => pair.Key).ToList(); + } + + // Write results to file + using (StreamWriter outFile = new StreamWriter(myStream)) + { + // Write CSV header + outFile.WriteLine("\"artist\",\"song\",\"setlist\""); + foreach (KeyValuePair song in songs) + { + outFile.WriteLine(String.Format("\"{1}\",\"{2}\",\"{0}\"", song.Key.Replace("\"", "\"\""), + song.Value.Artist.Replace("\"", "\"\""), + song.Value.Title.Replace("\"", "\"\""))); + } + } + } + + MessageBox.Show("Done."); + } } } \ No newline at end of file diff --git a/GHNamespace8/SortSongListForm.Designer.cs b/GHNamespace8/SortSongListForm.Designer.cs new file mode 100644 index 0000000..fcabb07 --- /dev/null +++ b/GHNamespace8/SortSongListForm.Designer.cs @@ -0,0 +1,73 @@ +namespace GHNamespace8 +{ + partial class SortSongListForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.button1 = new System.Windows.Forms.Button(); + this.button2 = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // button1 + // + this.button1.Location = new System.Drawing.Point(38, 38); + this.button1.Name = "button1"; + this.button1.Size = new System.Drawing.Size(150, 23); + this.button1.TabIndex = 0; + this.button1.Text = "Sort by Setlist"; + this.button1.UseVisualStyleBackColor = true; + this.button1.Click += new System.EventHandler(this.button1_Click_1); + // + // button2 + // + this.button2.Location = new System.Drawing.Point(209, 38); + this.button2.Name = "button2"; + this.button2.Size = new System.Drawing.Size(150, 23); + this.button2.TabIndex = 1; + this.button2.Text = "Sort by Artist"; + this.button2.UseVisualStyleBackColor = true; + this.button2.Click += new System.EventHandler(this.button2_Click); + // + // SortSongListForm + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(398, 101); + this.Controls.Add(this.button2); + this.Controls.Add(this.button1); + this.Name = "SortSongListForm"; + this.Text = "Sort Song List"; + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.Button button1; + private System.Windows.Forms.Button button2; + } +} \ No newline at end of file diff --git a/GHNamespace8/SortSongListForm.cs b/GHNamespace8/SortSongListForm.cs new file mode 100644 index 0000000..7988bdb --- /dev/null +++ b/GHNamespace8/SortSongListForm.cs @@ -0,0 +1,32 @@ +using System; +using System.Windows.Forms; + +namespace GHNamespace8 +{ + public partial class SortSongListForm : Form + { + public enum SortBy + { + Setlist, + Artist + }; + public SortBy sortBy; + + public SortSongListForm() + { + InitializeComponent(); + } + + private void button1_Click_1(object sender, EventArgs e) + { + sortBy = SortBy.Setlist; + this.Close(); + } + + private void button2_Click(object sender, EventArgs e) + { + sortBy = SortBy.Artist; + this.Close(); + } + } +} diff --git a/GHNamespace8/SortSongListForm.resx b/GHNamespace8/SortSongListForm.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/GHNamespace8/SortSongListForm.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/GHTCP-cleaned.csproj b/GHTCP-cleaned.csproj index e62777c..2dfba0d 100644 --- a/GHTCP-cleaned.csproj +++ b/GHTCP-cleaned.csproj @@ -61,8 +61,10 @@ + + @@ -666,6 +668,12 @@ Form + + Form + + + SortSongListForm.cs + Form @@ -1109,6 +1117,9 @@ Designer + + SortSongListForm.cs +