Stock Management Case Study

In the previous chapters we presented several applications for managing the inventory. In this chapter we created the GUI version of the stock management application. You can view the items that are currently in stock, add new items, and modify the details of the existing items. Figure 14-11 shows the main window of our application.

Figure 14-11. Stock Management application window.


For this demonstration, we used several back-end components. Some of them we already met in the previous chapters and some we created especially for the study.

  • StockItem provides the functionality of the item in stock with several properties: ID, Name, Price, Quantity.

  • IStock defines an interface in C# for managing the stock items (adding, removing, modifying).

  • Stock implements the IStock interface and manages the items using the ArrayList.

All these components reside inside the case study directory (StockMgrForm) in their own folders. Please refer to the readme.txt file inside the StockMgrForm directory for application building instructions.

The application has two additional forms for adding a new item (ItemFrm) and modifying the details of an existing item (DetailsFrm). Pressing the “Add New Item…” button will cause the ItemFrm dialog to be shown. We may show the form as a dialog box by calling the ShowDialog method of the Form class as we did in the handler of the button click event in our StockMgrForm:

sub btnAddItem_Click
{
   my $this = shift;

   my $dlg = "ItemFrm"->new();
   if ($dlg->ShowDialog() != enum("DialogResult.OK"))
   {
      $dlg->Dispose();
      return;
   }
   my $name = $dlg->{itemName};
   my $price = $dlg->{itemPrice};
   my $qty = $dlg->{itemQuantity};
   $dlg->Dispose();

   my $id = $this->{f_stock}->GenerateID();
   $this->{f_stock}->AddItem("StockItem"->new($id, $name,
                             $price, $qty));
   $this->ShowItems();
}

After the user closes the dialog, we examine the return value of ShowDialog to check whether the user added a new item or cancelled the action. If the method returns DialogResult.OK, the user did not cancel the action and we may read the details of a new item through the ItemFrm properties and add this new item to stock.

Figure 14-12 shows the dialog box for adding a new item.

Figure 14-12. Dialog for adding a new item.


Similarly, we may change the details of an existing item by selecting it inside the listbox and pressing the “Modify/View Details…” button. Figure 14-13 shows the DetailsFrm dialog box that we use to edit item details.

Figure 14-13. Dialog for modifying item details.


To remove an item, simply select it and press the “Remove Item” button. The application will show the confirmation message box and will act according to your response.

In the next chapter, we will present the database version of the Stock Management System application.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.137.171.121