MES Customization to "LOG OUT" and Employee

I am Trying to Logout an employee while keeping them clocked in without having to touch the screen, in my customization.

I tried this - did not work. (sorry could not get the code brackets to work)

EpiButton btnLogOut = (EpiButton)csm.GetNativeControlReference("a2f6e795-4ab3-4121-bce4-e1d5f0881b0a");
btnLogOut.PerformClick();

I am also Clocking out the employee in another step in my code with the oTrans.ClockOut(); but have not been able to find a built in method to do the Logout.

Trace no help.

Any Assistance would be appreciated.

it’s 2 backtics. The key next to the 1. before and after

```
your code
```

3 :smiling_imp:

Ok, now that I wrote that, it looks like it’s kissing an imp. (Or possibly shaking it’s booty)

I tried your code and it worked perfectly.

:thinking:

Where are you running this code? You may have to wait until this action is completed before continuing.
Are you sure the code is firing? Add a MessageBox before it, or debug in Visual Studio.

So I enabled this code again
EpiButton btnLogOut = (EpiButton)csm.GetNativeControlReference("a2f6e795-4ab3-4121-bce4-e1d5f0881b0a"); btnLogOut.PerformClick();

My Mes Screen does not update to show that the current EmpID is logged out after creating an IND labor detail record. If i could get that to work I would be good. Here is my code where I created the record and then try to log out. What am I doing wrong that does not allow the MES Main form to clear after the btnLogOut.PerformClick();?

	private void LogOut()
	{
		
		EpiButton btnLogOut = (EpiButton)csm.GetNativeControlReference("a2f6e795-4ab3-4121-bce4-e1d5f0881b0a");
		btnLogOut.PerformClick();

        System.Windows.Forms.Application.DoEvents();
//		//oTrans.Refresh();
		NewIndRecCreated = true;
		oTrans.Update();
		//oTrans.Refresh();

        System.Windows.Forms.Application.DoEvents();

	} // ClockOut()``


private void MESControl_AfterFieldChange(object sender, DataColumnChangeEventArgs args)
{
	// ** Argument Properties and Uses **
	// args.Row["FieldName"]
	// args.Column, args.ProposedValue, args.Row
	// Add Event Handler Code
	switch (args.Column.ColumnName)
	{
		case "EmployeeID":
			//Open BAQ to look for Indirect Labor Record for Current Emp. 
			//If Record exists proceed with Customization to delete current record.
			//If no Indirect Record exists create labor detail record and logout.
			NewIndRecCreated = false;
			UserID = ((Ice.Core.Session)oTrans.Session).UserID; 
			EpiDataView edvEmp = (EpiDataView)(oTrans.EpiDataViews["LaborHed"]);
			//EpiDataView edvDtl = (EpiDataView)(oTrans.EpiDataViews["LaborDtl"]);
			if (edvEmp == null){return;}
			if (!edvEmp.HasRow){return;}
			EmpID = edvEmp.dataView[edvEmp.Row]["EmployeeNum"].ToString();
			int LaborHeadSeq = Convert.ToInt32(Convert.ToDouble(edvEmp.dataView[edvEmp.Row]["LaborHedSeq"].ToString()));
			string baqID = "DTS-AlertIndirectRecPresent";
			DynamicQueryAdapter DQAdpt = new DynamicQueryAdapter(oTrans);
			if ((DQAdpt.BOConnect() == true))
			{
				Ice.BO.QueryExecutionDataSet execSet = DQAdpt.GetQueryExecutionParametersByID(baqID);
				execSet.ExecutionParameter.Clear();
				execSet.ExecutionParameter.AddExecutionParameterRow("EmpID", EmpID.ToString(), "nvarchar", false, Guid.NewGuid(), "A");
				DQAdpt.ExecuteByID(baqID, execSet);
				DataSet dSet = DQAdpt.QueryResults;
				//If no Indirect Record exists create labor detail record and logout.
				if (dSet.Tables[0].Rows.Count == 0)
				{
					LaborAdapter LAdpt = new LaborAdapter(oTrans);
		            LAdpt.BOConnect();
					LAdpt.GetByID(LaborHeadSeq);
					//LAdpt.GetNewLaborDtl(LaborHeadSeq); //See how many records are currently in the labor detail table
		            int LaborDtlIndex = LAdpt.LaborData.LaborDtl.Rows.Count;

		            //Start production activity
		            LAdpt.StartActivity(LaborHeadSeq, "I");
		            LAdpt.LaborData.LaborDtl.Rows[LaborDtlIndex]["LaborType"]= "I";
		            LAdpt.LaborData.LaborDtl.Rows[LaborDtlIndex]["LaborTypePseudo"]= "I";
		            LAdpt.LaborData.LaborDtl.Rows[LaborDtlIndex]["JCDept"]= "RGDept01";
		            LAdpt.LaborData.LaborDtl.Rows[LaborDtlIndex]["ResourceGrpID"]= "ALT";
		            LAdpt.LaborData.LaborDtl.Rows[LaborDtlIndex]["IndirectCode"]= "ALT";
		            LAdpt.LaborData.LaborDtl.Rows[LaborDtlIndex]["ExpenseCode"]= "IND";
		            LAdpt.Update();
					LAdpt.Dispose();


					LogOut();
					oTrans.Refresh();
					MessageBox.Show("New I Record Created");
        			System.Windows.Forms.Application.DoEvents();
					
					
				}
			
			}
			//Reset counter to check for Indirect Records when EmpID changes.
			InitializeCnt = 0;
			break;
		
	}
}

``

Could you explain why you are doing what you are doing?

We are trying to capture indirect time for an alert meter test and there are a line of emplyoees waiting to take the test.

The process is walk up to the first MES Screen and we have a barcode scanner waiting for the Emp to scan his card.

When the card is scanned the at the “CLOCK IN” MES the Indirect labor record is created and I am trying to log out the employee while keeping the LaborDetail Record as the Active Trans. Next person walks up same process.

After the Emp takes the test on a separate iPad then the Emp walks up to the CLOCK OUT MES and scans his badge. The customization then checks to see if there is already and Indirect LaborDetail record and if so the Indirect labor record is ended it clocks the employee out.

Pop up a messagebox in your logout function and make sure it is firing.

I ran it in Visual Studio and it is stepping through the code.

Try reversing these to

					oTrans.Refresh();
					LogOut();

Also, if that doesn’t get you closer, I would remove the LogOut() for testing, and after this procedure,
click the logout button and see if does what is expected.

@josecgomez Do you see anything here? I don’t do a whole lot with labor records in MES.

I mean if you are invoking the Logout button click it should do what the logout button does naturally I’m not sure how / why that wouldn’t work.
If you do it by hand it works fine I take it?

Yes the button works when you click it manually.
We used an oTrans.ClockOut() for when I wanted to end the Indirect Labor Detail Record but there is no oTrans.LogOut()…

Try invoking this mind you this is for my version but I suspect not much has changed

using System.Reflection;

oTrans.GetType().GetMethod("logOut",BindingFlags.Instance|BindingFlags.NonPublic).Invoke(oTrans,null);

That did the trick sir!!!

Thanks

Mike

Not sure if you got the message I sent from email but can you use this code for ClockOut as well?

oTrans.GetType().GetMethod("logOut",BindingFlags.Instance|BindingFlags.NonPublic).Invoke(oTrans,null);

Jose

Would there be and option for ClockOut on this same code?

``

No clock out is a different code is a different function all together you can just do

oTrans.ClockOut without reflection

It would be more like:

oTrans.GetType().GetMethod("ClockOut",BindingFlags.Instance|BindingFlags.Public).Invoke(oTrans,null);

However, since you can call oTrans.ClockOut() directly, there is really no need.

oTrans.ClockOut(); does work but it does not clear the EmployeeID box

It Looks like it gets reloaded after the oTrans.ClockOut