Ejemplo n.º 1
0
 public void AddSong(Song song)
 {
     this.BeginUpdate();
     ListViewItem lvi = new ListViewItem();
     lvi.Tag = song;
     lvi.Text = song.Number.ToString();
     lvi.SubItems.Add(song.Title);
     base.Items.Add(lvi);
     this.EndUpdate();
 }
Ejemplo n.º 2
0
 public bool Equals(Song other)
 {
     if (ReferenceEquals(null, other)) return false;
       if (ReferenceEquals(this, other)) return true;
       return Equals(other.id, this.id) && other.nr == this.nr;
 }
Ejemplo n.º 3
0
        /// <summary>
        /// add songs to SortedList (Song as value,song-number as key)
        /// </summary>
        /// <returns>SortedList containing all songs, null on error</returns>
        public SortedList GetSongs(SortedList songs, string url, bool imp)
        {
            long start = Util.getCurrentTicks();
            try
            {
                this.doc.Load(url);
                this.InitStyles(url);
                XmlNodeList nodes = this.doc.GetElementsByTagName("Song");
                for (int i = 0; i < nodes.Count; i++)
                {
                    XmlNode songNode = nodes[i];

                    int nr;
                    string title;
                    string text;

                    string id = songNode.Attributes["id"].Value;
                    string desc = songNode.Attributes["zus"].Value;
                    string translations = songNode.Attributes["trans"].Value;

                    if (songNode["Number"] != null &&
                        songNode["Title"] != null &&
                        songNode["Text"] != null)
                    {
                        nr = Int32.Parse(songNode["Number"].InnerText);
                        highestID = nr > highestID ? nr : highestID;
                        title = songNode["Title"].InnerText;
                        text = songNode["Text"].InnerText;
                    }
                    else
                    {
                        throw new NotValidException();
                    }

                    Song newSong = new Song(nr, title, text, id, desc, imp);

                    if (songNode.Attributes["style"] != null && !string.IsNullOrEmpty(songNode.Attributes["style"].InnerText))
                    {
                        Guid styleId = Guid.Parse(songNode.Attributes["style"].InnerText);
                        newSong.Style = Styles.FirstOrDefault(s => s.ID == styleId);
                        newSong.UseDefaultStyle = false;
                    }
                    else
                    {
                        // use default style for this song
                        newSong.Style = Styles.FirstOrDefault(s => s.IsDefault);
                        newSong.UseDefaultStyle = true;
                    }

                    this.GetTranslations(newSong, translations, imp);

                    try
                    {
                        songs.Add(newSong.ID, newSong);
                    }
                    catch (ArgumentException)
                    {
                        string msg = "Wollen Sie Lied Nr." + nr + " ersetzen?\n";
                        msg += "(drücken Sie \"abbrechen\", wenn Sie das Lied überspringen wollen.)";
                        DialogResult dr = MessageBox.Show(msg, "lyra import",
                                                          MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
                        if (dr == DialogResult.Yes)
                        {
                            songs.Remove(newSong.ID);
                            songs.Add(newSong.ID, newSong);
                        }
                        else if (dr == DialogResult.No)
                        {
                            newSong.nextID();
                            songs.Add(newSong.ID, newSong);
                        }
                        else
                        {
                            // cancel <-> ignore song
                        }
                        continue;
                    }
                }
                Util.addLoadTime(Util.getCurrentTicks() - start);
                // return SortedList with songs
                return songs;
            }
            catch (XmlException xmlEx)
            {
                Util.MBoxError(xmlEx.Message, xmlEx);
            }
            catch (NotValidException nValEx)
            {
                Util.MBoxError(nValEx.Message, nValEx);
            }
            catch (Exception e)
            {
                Util.MBoxError(e.Message, e);
            }
            return null;
        }
Ejemplo n.º 4
0
        // ok
        private void button1_Click(object sender, EventArgs e)
        {
            int nr;
            try
            {
                nr = Int32.Parse(this.textBox2.Text);
            }
            catch (Exception ex)
            {
                Util.MBoxError("Überprüfen Sie die Liednummer!", ex);
                this.textBox2.Focus();
                this.textBox2.SelectAll();
                return;
            }
            string title = this.textBox1.Text;
            string text = this.richTextBox1.Text;
            string desc = this.textBox3.Text == "---" ? "" : this.textBox3.Text;
            if (this.toDel != null && nr == this.toDel.Number) // number hasn't changed!
            {
                this.song = this.toDel;
            }
            if (this.song != null)
            {
                this.song.Title = title;
                this.song.Text = text;
                this.song.Desc = desc;
                this.song.BackgroundPicture = this.textBox4.Text;
                this.song.Transparency = this.trackBar1.Value;
                this.song.Scale = this.checkBox2.Checked;
                this.owner.Status = "Liedtext editiert...";
            }
            else
            {
                string id = "s" + Util.toFour(nr);
                ISong newSong = new Song(nr, title, text, id, desc, true);
                newSong.BackgroundPicture = this.textBox4.Text;
                newSong.Transparency = this.trackBar1.Value;
                newSong.Scale = this.checkBox2.Checked;
                if (this.toDel != null)
                {
                    CopyTrans(this.toDel, newSong);
                    this.toDel.Delete();
                }
                try
                {
                    this.owner.AddSong(newSong);
                }
                catch
                {
                    string msg = "Diese Liednummer wurde bereits einmal verwendet!\n";
                    msg += "Soll das Lied trotzdem hinzugefügt werden?\n";
                    msg += "(evtl. haben Sie das Lied bereits einer anderen Nummer zugewiesen,\n";
                    msg += "in diesem Fall einfach \"Ja\" klicken!)";

                    DialogResult dr = MessageBox.Show(this, msg, "lyra - neues Lied hinzufügen",
                                                      MessageBoxButtons.YesNo, MessageBoxIcon.Warning);

                    if (dr == DialogResult.Yes)
                    {
                        newSong.nextID();
                        this.owner.AddSong(newSong);
                    }
                    else
                    {
                        return;
                    }
                }
                this.owner.Status = "Neues Lied erfolgreich hinzugefügt...";
            }
            this.owner.UpdateListBox();
            this.owner.ToUpdate(true);
            this.Close();
        }
Ejemplo n.º 5
0
 private void previewButton_Click(object sender, EventArgs e)
 {
     string id = Util.PREVIEW_SONG_ID;
     string title = this.textBox1.Text;
     string text = this.richTextBox1.Text;
     int nr = 0;
     try
     {
         nr = int.Parse(this.textBox2.Text);
     }
     catch (Exception)
     { }
     string desc = this.textBox3.Text == "---" ? "" : this.textBox3.Text;
     ISong previewSong = new Song(nr, title, text, id, desc, true);
     previewSong.BackgroundPicture = this.textBox4.Text;
     previewSong.Transparency = this.trackBar1.Value;
     previewSong.Scale = this.checkBox2.Checked;
     ListBox previewListBox = new ListBox();
     previewListBox.Items.Add(previewSong);
     View.ShowSong(previewSong, this.owner, previewListBox);
 }
Ejemplo n.º 6
0
        /// <summary>
        /// add songs to SortedList (Song as value,song-number as key)
        /// </summary>
        /// <returns>SortedList containing all songs, null on error</returns>
        public SortedList getSongs(SortedList songs, string url, bool imp)
        {
            long start = Util.getCurrentTicks();
            try
            {
                doc.Load(url);
                XmlNodeList nodes = doc.GetElementsByTagName("Song");
                for (int i = 0; i < nodes.Count; i++)
                {
                    int nr;
                    string title;
                    string text;

                    string id = nodes[i].Attributes["id"].Value;
                    string desc = nodes[i].Attributes["zus"].Value;
                    string translations = nodes[i].Attributes["trans"].Value;

                    XmlNodeList songchildren = nodes[i].ChildNodes;
                    if ((songchildren[0].Name == "Number") &&
                        (songchildren[1].Name == "Title") &&
                        (songchildren[2].Name == "Text"))
                    {
                        nr = Int32.Parse(songchildren[0].InnerText);
                        highestID = nr > highestID ? nr : highestID;
                        title = songchildren[1].InnerText;
                        text = songchildren[2].InnerText;
                    }
                    else
                    {
                        throw new NotValidException();
                    }

                    Song newSong = new Song(nr, title, text, id, desc, imp);

                    if (songchildren.Count == 4)
                    {
                        XmlNodeList bgdesc = songchildren[3].ChildNodes;
                        if (songchildren[3].Name == "Background" && bgdesc.Count == 3 && bgdesc[0].Name == "uri"
                            && bgdesc[1].Name == "transparency" && bgdesc[2].Name == "scale")
                        {
                            newSong.BackgroundPicture = bgdesc[0].InnerText;
                            newSong.Transparency = Int32.Parse(bgdesc[1].InnerText);
                            newSong.Scale = bgdesc[2].InnerText == "yes";
                        }
                        else
                        {
                            throw new NotValidException("background node not valid");
                        }
                    }

                    this.GetTranslations(newSong, translations, imp);

                    try
                    {
                        songs.Add(newSong.ID, newSong);
                    }
                    catch (ArgumentException)
                    {
                        string msg = "Wollen Sie Lied Nr." + nr + " ersetzen?\n";
                        msg += "(drücken Sie \"abbrechen\", wenn Sie das Lied überspringen wollen.)";
                        DialogResult dr = MessageBox.Show(msg, "lyra import",
                                                          MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
                        if (dr == DialogResult.Yes)
                        {
                            songs.Remove(newSong.ID);
                            songs.Add(newSong.ID, newSong);
                        }
                        else if (dr == DialogResult.No)
                        {
                            newSong.nextID();
                            songs.Add(newSong.ID, newSong);
                        }
                        else
                        {
                            // cancel <-> ignore song
                        }
                        continue;
                    }
                }
                Util.addLoadTime(Util.getCurrentTicks() - start);
                // return SortedList with songs
                return songs;
            }
            catch (XmlException xmlEx)
            {
                Util.MBoxError(xmlEx.Message, xmlEx);
            }
            catch (NotValidException nValEx)
            {
                Util.MBoxError(nValEx.Message, nValEx);
            }
            catch (Exception e)
            {
                Util.MBoxError(e.Message, e);
            }
            return null;
        }
Ejemplo n.º 7
0
Archivo: GUI.cs Proyecto: ogirard/lyra2
        private void ImportLTX(string url, bool append)
        {
            if (!append)
              {
            this.storage.Clear();
            Util.DELALL = true;
              }

              StreamReader reader = new StreamReader(url);
              try
              {
            string line;
            int nr = 0;
            bool intext = false;
            while ((line = reader.ReadLine()) != null)
            {
              string title = "";
              if (intext)
              {
            string text = "";
            if (line.EndsWith("#END"))
            {
              text += line.Substring(0, line.Length - 4);
              ISong song = new Song(nr, title, text, "s" + Util.toFour(nr), "", true);
              text = title = "";
              intext = false;
              try
              {
                this.storage.AddSong(song);
              }
              catch (ArgumentException)
              {
                string msg = "Wollen Sie Lied Nr." + nr + " ersetzen?\n";
                msg += "(drücken Sie \"abbrechen\", wenn Sie das Lied überspringen wollen.)";
                DialogResult dr =
                    MessageBox.Show(this, msg,
                                    "lyra import", MessageBoxButtons.YesNoCancel,
                                    MessageBoxIcon.Question);
                if (dr == DialogResult.Yes)
                {
                  this.storage.RemoveSong(song.ID);
                  this.storage.AddSong(song);
                }
                else if (dr == DialogResult.No)
                {
                  song.nextID();
                  this.storage.AddSong(song);
                }
                else
                {
                  // cancel <-> ignore song
                }
                continue;
              }
            }
            else
            {
              text += line + "\n";
            }
              }
              // first line of song
              else if (line != "")
              {
            string[] words = line.Split(' ');
            title = line.Substring(words[0].Length + 1);
            nr = Int32.Parse(words[0]);
            intext = true;
              }
            }
            this.storage.DisplaySongs(this.allSongsListBox);
            this.ToUpdate(true);
            this.Status = "LTX-Import erfolgreich! :-)";
              }
              catch (Exception ie)
              {
            Util.MBoxError("Fehler beim Importieren.\n" + ie.Message, ie);
            this.Status = "Beim LTX-Import ging leider etwas schief. :-(";
              }
        }