- C# 7 and .NET Core 2.0 Blueprints
- Dirk Strauss Jas Rademeyer
- 228字
- 2021-08-27 19:55:23
Finishing up the ImportBooks code
Let's have a look at the rest of the code in the ImportBooks form. The form load just populates the storage spaces list, if any existing storage spaces have been previously saved:
private void ImportBooks_Load(object sender, EventArgs e) { PopulateStorageSpacesList(); if (dlVirtualStorageSpaces.Items.Count == 0) { dlVirtualStorageSpaces.Items.Add("<create new storage
space>"); } lblEbookCount.Text = ""; }
We now need to add the logic for changing the selected storage space. The SelectedIndexChanged() event of the dlVirtualStorageSpaces control is modified as follows:
private void dlVirtualStorageSpaces_SelectedIndexChanged(object sender, EventArgs e) { int selectedValue =
dlVirtualStorageSpaces.SelectedValue.ToString().ToInt(); if (selectedValue == (int)StorageSpaceSelection.New) // -9999 { txtNewStorageSpaceName.Visible = true; lblStorageSpaceDescription.Visible = true; txtStorageSpaceDescription.ReadOnly = false; btnSaveNewStorageSpace.Visible = true; btnCancelNewStorageSpaceSave.Visible = true; dlVirtualStorageSpaces.Enabled = false; btnAddNewStorageSpace.Enabled = false; lblEbookCount.Text = ""; } else if (selectedValue !=
(int)StorageSpaceSelection.NoSelection) { // Find the contents of the selected storage space int contentCount = (from c in spaces where c.ID == selectedValue select c).Count(); if (contentCount > 0) { StorageSpace selectedSpace = (from c in spaces where c.ID ==
selectedValue select c).First(); txtStorageSpaceDescription.Text =
selectedSpace.Description; List<Document> eBooks = (selectedSpace.BookList ==
null)
? new List<Document> { } : selectedSpace.BookList; lblEbookCount.Text = $"Storage Space contains
{eBooks.Count()} {(eBooks.Count() == 1 ? "eBook" :
"eBooks")}"; } } else { lblEbookCount.Text = ""; } }
I will not go into any detailed explanation of the code here as it is relatively obvious what it is doing.
推薦閱讀
- Learning Cython Programming
- Building a RESTful Web Service with Spring
- HTML5 Mobile Development Cookbook
- Apache Spark 2 for Beginners
- 神經(jīng)網(wǎng)絡(luò)編程實(shí)戰(zhàn):Java語言實(shí)現(xiàn)(原書第2版)
- Kinect for Windows SDK Programming Guide
- PhoneGap Mobile Application Development Cookbook
- Python編程與幾何圖形
- Scala程序員面試算法寶典
- Node.js 12實(shí)戰(zhàn)
- JavaScript悟道
- SSH框架企業(yè)級(jí)應(yīng)用實(shí)戰(zhàn)
- Unreal Engine Game Development Cookbook
- Natural Language Processing with Python Cookbook
- C++標(biāo)準(zhǔn)庫(第2版)