Add Product to Inventory System
Add Product to Inventory System
Exception handling for incorrect selling price inputs is implemented through the `SellingPrice` method, which checks inputs against a regex pattern appropriate for currency values. If the input doesn't match, a `CurrencyFormatException` is thrown, prompting an error message to the user. This safeguards against incorrect pricing formats and ensures data integrity .
Setting `gridViewProductList.AutoSizeColumnsMode` to `DataGridViewAutoSizeColumnsMode.Fill` ensures that all columns in the DataGridView control adjust their widths proportionally so that they completely fill the control. This enhances user interface design by making use of available space efficiently, improving readability and user experience .
The `showProductList` variable is a `BindingSource` object used to store and manage the collection of `ProductClass` objects. It acts as a bridge between the data source (products list) and data-bound controls (like DataGridView), allowing for dynamic display and updates of product information without manual data management .
The `ProductClass` design supports encapsulation by declaring its fields as private and providing public properties with getters and setters. This ensures the internal state of product objects is hidden from outside direct access while allowing controlled modifications via properties, maintaining the integrity and consistency of the data encapsulated within .
The handling of regular expressions plays a crucial role in ensuring data validity and robustness. By enforcing format rules on product names, quantities, and prices, the application prevents incorrect data inputs that could lead to runtime errors or database inconsistencies. This ultimately enhances system robustness by reducing vulnerabilities related to invalid data entries .
The application uses a regular expression to validate that the product name contains only alphabetic characters. If the name is invalid, a `StringFormatException` is thrown and a message is displayed to inform the user. This is enforced in the `Product_Name` method where a regex check ensures the name adheres to the specified format .
A missing `InitializeComponent` call in the `frmAddProduct` constructor would prevent the form control components from initializing, leading to a malfunction of the form UI. Controls would not be correctly instantiated or positioned, resulting in display errors or application crashes as the visual and interactive elements rely on this setup to function correctly .
The program uses a regular expression within the `Quantity` method to validate that the quantity consists only of numeric characters. If the input fails this pattern match, a `NumberFormatException` is thrown, prompting a message box alerting the user of a 'Number format input in quantity' issue .
The constructor, `frmAddProduct`, initializes the form component and sets up the `showProductList` as a new `BindingSource`. This enables the application to manage and bind lists and other collections to data-bound controls, such as a `DataGridView`, for displaying products within the form .
The application categorizes products using a predefined list of categories available in the `ListProductCategory` array. These categories include "Beverages," "Bread/Bakery," "Canned/Jarred Goods," "Dairy," "Frozen Foods," "Meat," "Personal Care," and "Other," which are added to a ComboBox for selection during product entry .