Пример #1
0
        /*
         * Manages the Edit link click event
         */
        private void EditLink(DataGridViewCellEventArgs e)
        {
            //Open EditDialog
            using (EditDialog dlg = new EditDialog()) {
                // Fill in all the data
                dlg.SongTitle  = dataGridView1.Rows[e.RowIndex].Cells["song"].Value.ToString();
                dlg.Artist     = dataGridView1.Rows[e.RowIndex].Cells["artist"].Value.ToString();
                dlg.Genre      = dataGridView1.Rows[e.RowIndex].Cells["genre"].Value.ToString();
                dlg.Tuning     = dataGridView1.Rows[e.RowIndex].Cells["tuning"].Value.ToString();
                dlg.Difficulty = dataGridView1.Rows[e.RowIndex].Cells["difficulty"].Value.ToString();
                dlg.Filename   = dataGridView1.Rows[e.RowIndex].Cells[0].Tag.ToString();
                dlg.Favorite   = Boolean.Parse(dataGridView1.Rows[e.RowIndex].Tag.ToString().Split('|')[1]);
                dlg.ToLearn    = Boolean.Parse(dataGridView1.Rows[e.RowIndex].Tag.ToString().Split('|')[2]);

                DialogResult result = dlg.ShowDialog();

                // Pressed OK?
                if (result == DialogResult.OK)
                {
                    // Update Database with the new Values
                    bool resQuery = DatabaseManager.ExecuteNonQuery(DatabaseManager.DATABASE_FILENAME,
                                                                    $"UPDATE TabRegister SET filename = \"{dlg.Filename}\", song = \"{dlg.SongTitle}\"," +
                                                                    $"artist = \"{dlg.Artist}\", genre = \"{dlg.Genre}\", tuning = \"{dlg.Tuning}\", difficulty = \"{dlg.Difficulty}\"," +
                                                                    $"favorite = \"{(dlg.Favorite ? -1 : 0)}\", toLearn = \"{(dlg.ToLearn ? -1 : 0)}\"" +
                                                                    $"WHERE ID = {dataGridView1.Rows[e.RowIndex].Tag.ToString().Split('|')[0]};");
                    // If the query was successful: Edit the datarow
                    if (resQuery)
                    {
                        // Update View
                        dataGridView1.Rows[e.RowIndex].Cells[0].Tag   = dlg.Filename;
                        dataGridView1.Rows[e.RowIndex].Cells[1].Value = dlg.SongTitle;
                        dataGridView1.Rows[e.RowIndex].Cells[2].Value = dlg.Artist;
                        dataGridView1.Rows[e.RowIndex].Cells[3].Value = dlg.Genre;
                        dataGridView1.Rows[e.RowIndex].Cells[4].Value = dlg.Tuning;
                        //date update not needed
                        dataGridView1.Rows[e.RowIndex].Cells[6].Value = dlg.Difficulty + "/10";
                        //Update Tags
                        dataGridView1.Rows[e.RowIndex].Tag = dataGridView1.Rows[e.RowIndex].Tag.ToString().Split('|')[0] + "|" + dlg.Favorite + "|" + dlg.ToLearn;
                    }
                }
            }
        }
Пример #2
0
        /*
         * Manage the New Tab click event
         */
        private void Btn_newTab_Click(object sender, EventArgs e)
        {
            // Open Edit/Add Dialog
            using (EditDialog dlg = new EditDialog()) {
                DialogResult result = dlg.ShowDialog();

                if (result == DialogResult.OK)
                {
                    // Update Database; add the values to the database
                    bool resQuery = DatabaseManager.ExecuteNonQuery(DatabaseManager.DATABASE_FILENAME,
                                                                    $"INSERT INTO TabRegister (filename, song, artist, genre, tuning, difficulty, favorite, toLearn) " +
                                                                    $"VALUES (\"{dlg.Filename}\", \"{dlg.SongTitle}\"," +
                                                                    $" \"{dlg.Artist}\", \"{dlg.Genre}\", \"{dlg.Tuning}\", \"{dlg.Difficulty}\"," +
                                                                    $" \"{(dlg.Favorite ? -1 : 0 )}\", \"{(dlg.ToLearn ? -1 : 0)}\");");

                    // If the Query was successful:
                    if (resQuery)
                    {
                        // Update View to display all data (Just clicks the home button)
                        Btn_home_Click(null, null);
                    }
                }
            }
        }