Code Review on Modules

For the last week of my internship, I’ve performed code review on each module that I responsible for. I’ve clean up some redundant codes and functions, renamed variables to be more understandable. Not only that, I’ve also wrote comments to clarify the implementation logic for some functions.

Secondly, during the code review, I’ve also learned on the usage of Enum, which can be used to replace or represent a group of constants. In my case, instead of assigning magic strings as the line item’s pick status, I’ve replaced it with Enum which contains the variety of pick status.

Lastly, I’ve moved all the magic strings to Parameter class. By using parameter class, it become more maintainable to all the strings inside the whole solution. For example, changing of dialog message will only require to change the string in parameter class.

Dispatcher Interface for Mocking

As I’ve wrote the integration tests for the pick module which also included the multi-threaded class, I’ve faced problem that the dispatcher in the multi-threaded class fails to mock. Since the multi-threaded class is used to refresh the data grid view within time interval, therefore fails to mock had caused all the integration tests fail to receive the data grid binding source to perform testing.

In order to solve the issue, I’ve decided to use the solution which is implement an interface for the dispatcher for mocking.

I’ve created the interface which called IDispatcher which include the BeginInvoke method. Then, instead of calling dispatcher, I’ve changed it to fire IDispatcher and its method as well. Lastly, in the integration tests, I call the mock for IDispatcher and setup its callback as (Action a) => a() to invoke the method in the multi-threaded class.

Multithreading with EventWaitHandle

For the week, I’ve found the bug caused the pick module thread fails to refresh the sales order data grid view. This is because when the data grid collection had been initialize with new data at outside of the thread, it will no longer able to update the data grid collection and reflect in UI.

Therefore, I’ve implement EventWaitHandle to solve the issue. When user had clicked on the filter sales order check box, it send signal to the thread in order to refresh the sales order data grid view immediately. While the thread will always loop the function at 5 seconds interval by using WaitOne(TimeSpan.FromSeconds(5));

Not only that, I’ve also set the EventResetMode to AutoReset which will always set the event state to false after received signal.

Implementation of Pick History View

For this week, a new feature which is the pick history view is implemented for the pick module. As what it named, it is used to view the pick history for specific line item. On line item selected, it will parse the line item id through publishing the event. While the pick history view model will subscribe the event and load the pick history with the selected line item id to filter the pick history that belongs to the line item.

Furthermore, I’ve also implemented the filtration of sales order by its pick status. Two checkbox is added to the view for user to select the type they wish to filter the sales order in different scenarios.

Lastly, I’ve conducted the integration tests for pick module in order to test out the concurrency situation will prevent the data to be entered into database and will rollback the transaction.

New feature on Pick module

For this week I’ve implement a new feature on the pick module which is to filter the line item by the current user floor. When the current user is in charge of floor 1, by selecting the checkbox, it will refresh the line item data grid view and display the line item that contains the item that located at the same floor.

In order to implement it, new aggregate of Location and Floor is created. Therefore, each Item will contains a Location that indicate their respective IDs. While each Location will contains a Items list that include all the Items in the same Location.

At last, I’ve add warning dialog that alert user that they have unsaved pick. For example, when user had picked but not saved, it will pop dialog when user is try to select the view floor only checkbox, select other sales order and select other line item.

User action validation on Pick Module

After the color indicator for pick module had been completed, for this week, I’ve implement the features that will alert user when they did not save their pick.

In order to implement the feature, I’ve used the data grid SelectionChanged event. This event will be fire when the selected item in the data grid had been changed. Therefore, I’ve retrieve the RemovedItems from the SelectionChangedEventArgs and compared its pickQuantity with database. If the pickQuantity is same with the database, it allow user to proceed with another row, reset to previous row if it is not same with database and prompt error dialog.

However, I’ve faced problem when the selected item is reset to previous item, but the focus is pointed on another row. Therefore, the PreviewLostKeyboardFocus event is used to solve the problem. It fired when the user attempt to leave the textbox focus. When the event is fired, it will work the same as the SelectionChanged event which compare the value of pickQuantity with database to verify whether user had modify the value. If the pickQuantity had been modified, it will reset the focus back to the previous textbox by using OldFocus.Focus();

Color Indicator for Pick Module

For this week, I’ve coded out the basic functionalities of the pick module which is the pick and pick all functions. While the pick function refer to when the user had enter the amount to pick, a pick data will be generate which contains the line item ID that picked, picked quantity and the user ID that perform the pick.

Before the pick is saved into database, it need to update with the stock quantity database table which increment the amount of stock and decrement in the stock quantity. For the pick all function it perform the same with the pick function with just the pick quantity is set to the line item quantity on button clicked.

After that, I’ve add in with the color indicator function which alert the user on the sales order list on which order is completely picked while which haven’t. Different line items will be indicated with their respective unique colors.

The color indicator is been called in the LoadingRow event which fired when the datagridview is generated and inserting the row into it. It read the current row cell which is the sales order first, and retrieve all the line items inside the sales order. The color indicator determine the color to set by comparing all the pick quantity with the line item quantity, when the pick quantity is equal to line item quantity, the variable picked++.

Lastly, if the picked amount is equal with the line item list count, it means all the line item inside this sales order is picked, with correct colour indicator.

Multithreading on Pick module

For this week, I’ve continue to develop on the new task which is the pick module. After the UI creation is completed, I’ve inserted some dummy data to test the UI. However, in order to make sure the user always get the latest sales order data from the database for pick module, multithreading is applied to the module.

Multithreading is used in the pick module which aim to refresh the sales order data and update the UI data grid view at the background. Not only that, it also require retrieve the latest row version in order to avoid concurrency error.

However, I’ve faced problem which update data grid binding source in the thread does not reflect in the UI data grid view even thought I’ve define a new collection for the binding source. After I’ve search for solution on the Internet, I’ve learned that I should call dispatcher for UI updating work and for the binding source, I’m only allowed to perform .Clear(), .Add(), AddRange(), and Remove() instead of defining new collection.

Brainstorming on new task

For the previous week, I had completed with the User module and merged with the master project. I’ve been assigned with new task which is develop the sales order picking module. I’ve been briefed on the module such as its functionalities, requirements, input data and output data that the module should produce.

After that, I’ve started to brainstorming toward the module. I’ve figured and listed down the business flow of the sales order picking module. First of all, user will need to select the sales order that they wish to pick. On the same time, the selected sales order details / attribute will also be shown in the same view. The line items that contained in the selected sales order. Therefore, user will able to proceed with their picking process by entering the amount to pick.

Lastly, I’ve designed the UI of the module and amend it based on the requirements and make it to be more user friendly. I’ve also started to design the Pick service which will contains all the service needed and will be used in the view model in the future.

Implementation of FlaUI and Wrapper Class

For this week, I’ve started with the unit testing for the Hash Generator application. However, due to the Hash Generator is a Windows Form application , I’ve faced the problem when conducting the unit testing. It will pop out the message box while the test is running while I will need to close the dialog manually while running the unit tests.

In order to solve this problem, I had implemented the FlaUI which is a .net library which helps with automated UI testing of Windows applications. Not only that, I’ve also learned to implement the Thread.Sleep() and Retry.WhileException() which is used to retry the automation process if it fails to find descendants.

After that, I had implement the User and Privilege Wrapper class for the entire User Module in order to place the logged in user in the wrapper class for other module to verify the user’s privilege and authorize with relevance rights.