LogEnter is called each time a user data entry occurs. Originally designed to assist in logging data entry actions, it can also be used to monitor user data entry.
/// <summary>
/// Log Screen Entry plug-in
/// </summary>
/// <param name="logger">Active logger, can log extra lines using methods</param>
/// <param name="aidKeys">Aid key or keys triggering screen entry</param>
/// <param name="fields">null or array of Field objects entered by user</param>
/// <param name="oScreen">Active FSCProLib HostScreen object</param>
/// <returns>handled indicator--if true is returned, the logger will not log this screen,
/// return false for a normal logging of the screen</returns>
static public bool LogEnter(DebugLogs logger, string aidKeys, Field[] fields, HostScreen oScreen)
{
string ScreenID = oScreen.getScreenName();
// ScreenID now contains the qualified screen name that has been entered into
/* This code, taken from the Debug.LogScreen code, demonstrates how to access all
* the screen text for logging--the oScreen.getText() can also retrieve any text
* using row,column,length.
int rows = oScreen.screenRowSize;
int cols = oScreen.screenColSize;
string screenText = oScreen.text;
// 5250 Message line tweak...sometimes definition may have 25 rows
// which will give a 5250 rowsize of 26 (oops)...
int rows2 = screenText.Length / cols;
if ((rows2 < rows) &&
((rows == 25) || (rows == 28)))
{
screenText += oScreen.getText(rows, 1, cols);
rows2 = screenText.Length / cols;
}
rows = rows2;
for (int i = 0; i < rows; i++)
{
string rowText=screenText.Substring(i * cols, cols)));
}
*/
// Following just logs the user field data-entry using the active Screen definition
// for the session...for an intelligent logger, you can use the individual field names,
// which are fully qualified (ScreenID.FieldName for default maps, ScreenID.MapName.FieldName
// for any multirow/non-default map) to decide what logging to perform.
bool onLogon = (ScreenID == "Signon");
if (fields != null)
{
foreach (Field field in fields)
{
int multiRowIndex=0;
// Note, the SCDispatcher.GetFieldName is highly efficient and uses a runtime
// cache of field offsets to I.D. the field, so don't worry about using it for
// every user update (but can also use ScreenID to decide when to check anyway)
string fieldName=SCDispatcher.GetFieldName(oScreen,field.offset,out multiRowIndex);
if (onLogon &&
(fieldName == "Signon.Userid"))
{
if (logger.oConn.owner==".NET")
{
DateTime dt=DateTime.Now;
logger.oConn.owner=String.Format("{0}_{1}_{2,-14:HH:mm:ss:fff}",
field.text,dt.ToShortDateString(),dt);
}
}
string multiRowInfo=(multiRowIndex==0) ? "" : " (rowIndex="+multiRowIndex.ToString()+")";
if (fieldName.StartsWith("!")) // password
logger.Log("FieldChange",fieldName.Substring(1)+" = \""+new String('*',field.text.Length)+"\""+multiRowInfo);
else
logger.Log("FieldChange", fieldName + " = \"" + field.text + "\"" + multiRowInfo);
}
}
if (ScreenID == "AcctSummary")
{
logger.Log("AcctSummary", "AccountHolder = \"" + SCDispatcher.GetFieldValue(oScreen, "AccountHolder"));
logger.Log("AcctSummary", "EstNextBill = \"" + SCDispatcher.GetFieldValue(oScreen, "EstNextBill"));
try
{
string test = SCDispatcher.GetFieldValue(oScreen, "bozo");
string test2 = SCDispatcher.GetFieldValue(oScreen, null);
string test3 = SCDispatcher.GetFieldValue(oScreen, "bozo", "bozo", 300);
logger.Log("AcctSummaryTest", ((test == null) ? "test1Good" : "odd test1") + " " +
((test2 == null) ? "test2Good" : "odd test2") + " " +
((test3 == null) ? "test3Good" : "odd test3"));
}
catch (System.Exception ex)
{
logger.Log("AcctSummaryEX", ex.ToString());
}
}
else if (ScreenID == "AcctTrans")
{
int row;
StringBuilder sb = new StringBuilder();
for (row = 0; row < 10; row++)
{
sb.Append("Row:" + row.ToString() + " " + SCDispatcher.GetFieldValue(oScreen, "rowData", "Date", row));
sb.Append(", " + SCDispatcher.GetFieldValue(oScreen, "rowData", "Action", row));
sb.Append(", " + SCDispatcher.GetFieldValue(oScreen, "rowData", "EffDue", row));
sb.Append(", " + SCDispatcher.GetFieldValue(oScreen, "rowData", "Amount", row));
sb.Append(", " + SCDispatcher.GetFieldValue(oScreen, "rowData", "MinDue", row));
sb.Append(", " + SCDispatcher.GetFieldValue(oScreen, "rowData", "Description", row));
sb.Append(", " + SCDispatcher.GetFieldValue(oScreen, "rowData", "Lob", row));
}
logger.Log("AcctTrans", "Rows=" + sb.ToString());
}
else if (ScreenID == "PolicySelect")
{
StringBuilder sb = new StringBuilder();
ScreenDef sd = oScreen.getScreenDef();
for (int mapID = 0; mapID < sd.mapCount; mapID++)
{
ScreenMap map = sd.getScreenMap(mapID);
for (int fieldID = 0; fieldID < map.fieldCount; fieldID++)
{
MapField field = map.getMapField(fieldID);
if (field.write)
{
if (sb.Length>0)
sb.Append("; ");
sb.Append(field.name + "=\"" + oScreen.getText(field.row, field.column, field.length)+"\"");
}
}
}
logger.Log("PolicySelect", "Entry Fields: " + sb.ToString());
}
return true; // don't need this image...
}