Prevent a user from being able to register for multiple jobs

I am trying to prevent a user from being able to register for multiple jobs simultaneously in the MES.

Code

var tt = ds.LaborHed.FirstOrDefault(r=>r.Added());
bool flag = false;

if( tt != null )
{
  string empID = tt.EmployeeNum;
  var activeLabor = (from lh in Db.LaborHed
                       where lh.EmployeeNum == empID && lh.ActiveTrans == true
                       select lh).FirstOrDefault();
  if (activeLabor != null)
  {
     throw new Ice.Common.BusinessObjectException("You already have an active job. Finish the current job before starting a new one.");
     flag = true; 
  }                       
}
else
{
    // Lanzar un error si no se encontrĂł ningĂşn registro
    throw new Ice.Common.BusinessObjectException("No record of work activity was found.");
}

return flag;

Can someone tell me why it doesn’t throw the exception when we start production?

Heeeeelp me?

Try this method instead.

Erp.BO.LaborSvc/StartActivityByEmp

If I’m reading your question correctly, you want your operators to ONLY be able to clock into a single job at a time.

If that is the case, then the field you need to check is LaborDtl.ActiveTrans… not LaborHed.ActiveTrans. The LaborDtl table is what stores job labor activity… LaborHed stores the daily clockin/clockout (typically used for payroll reporting).

4 Likes

You are right Ernie, the table you mention is the correct one.

How to recover the EmployeeID?

Why are you using a transaction scope?

Add Newtonsoft.Json to the using and references.

Take all that out and run this:

    var activeLaborDtl = (from ld in Db.LaborDtl
                          where ld.EmployeeNum == empId
                          && ld.ActiveTrans == true // Verificar que la transacción esté activa
                          select ld).FirstOrDefault();

    // If you already have an active activity, throw an exception to block new entry
    if (activeLaborDtl != null)
    {
        throw new Ice.Common.BusinessObjectException("The operator already has a job in progress. Complete or stop the current activity before starting another.");
    }
    else
   {
       throw new BLException(JsonConvert.SerializeObject(activeLaborDtl, Formatting.Indented));
   }

Then see what is wrong.

The empID comes with a name (Louis.Martinez), when it should be a Number (52358).
For example: