官术网_书友最值得收藏!

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.

主站蜘蛛池模板: 浦城县| 大名县| 余干县| 抚州市| 澜沧| 葫芦岛市| 龙口市| 安岳县| 孟连| 安龙县| 申扎县| 栾城县| 阿坝| 东光县| 香港 | 景谷| 邵武市| 青浦区| 玉田县| 玛纳斯县| 武强县| 太康县| 法库县| 思南县| 石台县| 米泉市| 来凤县| 桐乡市| 平远县| 三河市| 昌图县| 田阳县| 新宁县| 佛教| 武宣县| 鹤岗市| 永泰县| 修水县| 陕西省| 乃东县| 景洪市|