Tuesday 28 November 2017

Epicor E10 Creating your own MES (MES Customization)

This guide is to demonstrate how to create a custom C# application that calls Epicor function for some simple operations.

Our company would like to remove the Clock card system and use the Clock in and Clock out function in Epicor. We have purchased a Windows 10 tablet and realised that MES is hard to drive without a keyboard and mouse.

To over come that, I decided to customise the MES screen. I just wanted to replace the typing of the Employee ID to become a drop down box, but I cannot find a solution to it.

So I decided to read up on how to create my own program that can call to Epicor function directly.

Here are all the steps I took to create my version of MES.

Prerequisite:
-Install Epicor client on the computer
-Have a valid epicor user account
-Visual Studio (2017 is shown)

1. Create a New Project in Visual Studio

2. I use Windows Forms App , I believe it will work for WPF App too


3. Add references to the project

Browse to "C:\Epicor\ERP10.0Client\Client\"

Add the following files to references (See Picture)





4. Add a combo box and 2 x buttons on the form




5. Rename button1 to clock in and button 2 to clock out



6. Double click on the Form area, this will automatically add the Form load event

7. Here is the coding part.

First, get the list of active employee and populate bind it to the comboBox datasource.

Modify the Form Load function and add some properties to the form

using Erp.BO;
using Erp.Proxy.BO;
using Ice.Core;
using Ice.Lib.Framework;
using System;
using System.Windows.Forms;

namespace MyMES

{
   public partial class Form1 : Form
   {
      private EmpBasicImpl empBO;
      private EmpBasicDataSet empBasicDataSet;
      private Session epiSession;
      private LaborImpl laborBO;
      private LaborDataSet laborDataSet;

      public Form1()

      {
         InitializeComponent();
      }

      private void Form1_Load(object sender, EventArgs e)

      {
         // This connects to epicor using the provided user name and password and consumes a license
         epiSession = new Session("manager", "manager", "XXXXXXXXXXXXXXXX", Session.LicenseType.Default, @"C:\Epicor\ERP10.0Client\Client\config\Server.sysconfig");

         empBO = WCFServiceSupport.CreateImpl<Erp.Proxy.BO.EmpBasicImpl>((Ice.Core.Session)epiSession, Erp.Proxy.BO.EmpBasicImpl.UriPath);

         laborBO = WCFServiceSupport.CreateImpl<Erp.Proxy.BO.LaborImpl>((Ice.Core.Session)epiSession, Erp.Proxy.BO.LaborImpl.UriPath);

         bool outBool;

         empBasicDataSet = empBO.GetRows("EmpStatus = 'A'", "", "", "", "", "", "", "", 100, 0, out outBool);

         comboBox1.DataSource = empBasicDataSet.EmpBasic;

         comboBox1.DisplayMember = "Name";
         comboBox1.ValueMember = "EmpID";
      }
   }
}


You will have to replace XXXXXXX with the URL of your Epicor Server. You can find that value in the sysconfig file <AppServerURL value="XXXXXXXXXXXXXXXX" />

Run the code and see the list of Employee being populated

8. Add code for Clock in

Get back into the Form1 designer. Double clock on the Clock in button, the event will be automatically added.

Here we will make use of the employee Business object and run the function ClockIn.


      private void button1_Click(object sender, EventArgs e)
      {

         string empID;

         if (comboBox1.SelectedValue != null)
         {
            empID = comboBox1.SelectedValue.ToString();
         }
         else
         {
            return;
         }

         if (empID != "")
         {
            try
            {
               empBO.ClockIn((string)comboBox1.SelectedValue, 1);
            }
            catch (Exception exception)
            {
               MessageBox.Show(exception.Message);
               return;
            }
         }
      }


9. Add code for Clock out

Clocking out is slightly harder as if you do not check, you can left with active activities while the employee has clocked out.

So here, we want to stop the clock out process unless the employee has no active activity.

private void button2_Click(object sender, EventArgs e)
      {
         string empID;

         if (comboBox1.SelectedValue != null)
         {
            empID = comboBox1.SelectedValue.ToString();
         }
         else
         {
            return;
         }

         if (empID != "")
         {
            // Test if the person has any operation that is active

            bool outBool;
            string today = DateTime.Now.ToString(@"yyyy\/MM\/dd");

            // laborDtlDataSet = laborDtlBO.GetRows("EmployeeNum = '" + @empID + "'" + " And ClockInDate='" + today + "' And ActiveTrans = 1", 100, 0, out outBool);
            laborDataSet = laborBO.GetRows("EmployeeNum = '" + @empID + "'" + " And ClockInDate='" + today + "' And ActiveTrans = 1", "EmployeeNum = '" + @empID + "'" + " And ClockInDate='" + today + "' And ActiveTrans = 1", "", "", "", "", "", "", "", "", "", "", 100, 0, out outBool);

            if (laborDataSet.LaborDtl.Count > 0)
            {
               string errorMsg = "You have " + laborDataSet.LaborDtl.Count + " active operation, please End Activity before clocking out.";
               MessageBox.Show(errorMsg, "Error");
               return;
            }

            try
            {
               empBO.ClockOut(ref empID);
            }
            catch (Exception exception)
            {
               MessageBox.Show(exception.Message);
               return;
            }

            // If there is no exception, clock out successfully
         }
      }


This is my new MEW that can run on my new Tablet for clocking in and out. Of course, you may want to make it more beautiful and user friendly.



2 comments:

  1. Wonderful site you have here but I was wondering if you knew of any message boards that cover the same topics discussed here? I'd really love to be a part of online community where I can get suggestions from other experienced people that share the same interest. If you have any suggestions, please let me know. Thanks! epicor dashboard

    ReplyDelete
  2. Sorry for the late reply. I seldom check my blog for the last 2 years. I am now part of this community https://www.epiusers.help/ See you there

    ReplyDelete