- C# 7 and .NET Core 2.0 Blueprints
- Dirk Strauss Jas Rademeyer
- 382字
- 2021-08-27 19:55:22
The ImportBooks form
The ImportBooks form does exactly what the name suggests. It allows us to create Virtual Storage Spaces and to import books into those spaces. The form design is as follows:

The TreeView controls are prefixed with tv, buttons with btn, combo boxes with dl, textboxes with txt, and date time pickers with dt. When this form loads, if there are any storage spaces defined then these will be listed in the dlVirtualStorageSpaces combo box. Clicking on the Select source folder button will allow us to select a source folder to look for eBooks.
If a storage space does not exist, we can add a new Virtual Storage Space by clicking the btnAddNewStorageSpace button. This will allow us to add a name and description for the new storage space and click on the btnSaveNewStorageSpace button.
Selecting an eBook from the tvFoundBooks TreeView will populate the File details group of controls to the right of the form. You can then add additional Book details and click on the btnAddeBookToStorageSpace button to add the book to our space:
- You need to ensure that the following namespaces are added to your ImportBooks class:
using eBookManager.Engine; using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Windows.Forms; using static eBookManager.Helper.ExtensionMethods; using static System.Math;
- Next, let's start at the most logical place to begin with, which is the constructor ImportBooks() and the form variables. Add the following code above the constructor:
private string _jsonPath; private List<StorageSpace> spaces; private enum StorageSpaceSelection { New = -9999, NoSelection = -1 }
The usefulness of the enumerator will become evident later on in code. The _jsonPath variable will contain the path to the file used to store our eBook information.
- Modify the constructor as follows:
public ImportBooks() { InitializeComponent(); _jsonPath = Path.Combine(Application.StartupPath,
"bookData.txt"); spaces = spaces.ReadFromDataStore(_jsonPath); }
The _jsonPath is initialized to the executing folder for the application and the file hard coded to bookData.txt. You could provide a settings screen if you wanted to configure these settings, but I just decided to make the application use a hard-coded setting.
- Next, we need to add another enumerator that defines the file extensions that we will be able to save in our application. It is here that we will see another feature of C# 7 called expression-bodied properties.
- Developing Mobile Web ArcGIS Applications
- 軟件測試項目實戰之性能測試篇
- Visual Basic程序設計與應用實踐教程
- SSM輕量級框架應用實戰
- FFmpeg入門詳解:音視頻原理及應用
- 從0到1:Python數據分析
- AppInventor實踐教程:Android智能應用開發前傳
- 移動界面(Web/App)Photoshop UI設計十全大補
- Python Data Analysis Cookbook
- 0 bug:C/C++商用工程之道
- Visual Foxpro 9.0數據庫程序設計教程
- The Professional ScrumMaster’s Handbook
- Visual Basic 6.0程序設計實驗教程
- C陷阱與缺陷
- 你好!Java