コード例 #1
0
        /// <summary>
        /// Add new storage.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnAddStorage_Click(object sender, EventArgs e)
        {
            using (StorageForm storageForm = new StorageForm())
            {
                if (storageForm.ShowDialog() == DialogResult.OK)
                {
                    Storage storage = new Storage
                    {
                        StorageDescription = storageForm.StorageDescription,
                        StorageSize        = storageForm.StorageSize,
                        Playlists          = storageForm.Playlists
                    };

                    if (storage.Update())
                    {
                        PopulateStorage();
                    }
                }
            }
        }
コード例 #2
0
        private void mnuStorage_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
        {
            // Hide the menu before anything else happens
            mnuStorage.Hide();

            switch (e.ClickedItem.Text)
            {
            case "Edit...":
                Storage storage = new Storage();

                if (storage.Find(Convert.ToInt32(lvStorage.SelectedItems[0].Name)))
                {
                    StorageForm storageForm = new StorageForm
                    {
                        StorageId          = storage.StorageId,
                        StorageDescription = storage.StorageDescription,
                        StorageSize        = storage.StorageSize
                    };

                    if (storageForm.ShowDialog() == DialogResult.OK)
                    {
                        storage.StorageId          = storageForm.StorageId;
                        storage.StorageDescription = storageForm.StorageDescription;
                        storage.StorageSize        = storageForm.StorageSize;
                        storage.Playlists          = storageForm.Playlists;

                        if (storage.Update())
                        {
                            // Change the information in the ListView.
                            lvStorage.SelectedItems[0].Text             = storage.StorageDescription;
                            lvStorage.SelectedItems[0].SubItems[1].Text = storage.StorageSize;
                            lvStorage.SelectedItems[0].SubItems[2].Text = storage.Playlists.Count.ToString();
                        }
                    }
                }

                break;

            case "Export...":
                if (MessageBox.Show(@"Are you sure you want to do this export?", AppGlobals.AppName, MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
                {
                    ExportStorage(Convert.ToInt32(lvStorage.SelectedItems[0].Name));
                }

                break;

            case "Delete...":
                if (MessageBox.Show(@"Are you sure you want to delete this storage?", AppGlobals.AppName, MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
                {
                    Storage storageToDelete = new Storage();

                    if (storageToDelete.Find(Convert.ToInt32(lvStorage.SelectedItems[0].Name)))
                    {
                        if (storageToDelete.Delete())
                        {
                            lvStorage.Items.Remove(lvStorage.SelectedItems[0]);
                        }
                        else
                        {
                            MessageBox.Show(@"Sorry, this could not be deleted.\n\n" + storageToDelete.LastMessage, AppGlobals.AppName, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        }
                    }
                }

                break;
            }
        }