Overcoming Labor Time Format Issues in Epicor 9
We developed a custom "Overall Equipment Effectiveness" application for a local manufacturing company. The application records employee production on a daily basis. The employee start and end times are recorded but need to be stored in a decimal value in order to interact with a legacy ERP system. We simply masked these decimal values as time values using a standard .NET TextBox control. The client later requested a tracker view, allowing administrators the ability to view and edit already posted records. This proved to be an issue as we were displaying their decimal values with no mask, i.e. 8.75 instead of 8:45, 6.25 instead of 6:15.
.NET has the ability to format columns in DataGridViews using standard functionality. The problem here is that these decimals cannot be converted to a DateTime format because the DataGridViewCellStyle.Format property won’t recognize decimal values as DateTimes. To get around this, we wrote a custom class that inherited both IFormatProvider and ICustomFormatter, and utilized the Format method. In doing this, we could pass any value into my CustomClass.Format method and parse the data any way we needed.
Since the Format method inherited takes a string as its value parameter, we split the string into two. We then took the second string, the values after the decimal, and converted them into their appropriate time counterparts. By setting the FormatProvider of the columns we need to change to a new instance of our custom formatting class, and tying into the DataGridView.CellFormatting event, we can then pass our values to be formatted and have the appropriate values returned. It is important to explicitly cast the FormatProvider of the CellStyle for the columns to ICustomFormatter, otherwise it will not format.