diff --git a/TN3270Sharp.Example.App/Example3270App.cs b/TN3270Sharp.Example.App/Example3270App.cs index 7bf3a1e..96c06eb 100644 --- a/TN3270Sharp.Example.App/Example3270App.cs +++ b/TN3270Sharp.Example.App/Example3270App.cs @@ -73,6 +73,7 @@ public void CreateServer() var fName = screens[ProgramScreen.FormScreen].GetFieldData("fname"); var lName = screens[ProgramScreen.FormScreen].GetFieldData("lname"); var password = screens[ProgramScreen.FormScreen].GetFieldData("password"); + var employeeId = screens[ProgramScreen.FormScreen].GetFieldData("employeeId"); // Check for errors... string? errorMessage = null; @@ -82,8 +83,10 @@ public void CreateServer() errorMessage = "Last Name field is required."; else if (string.IsNullOrWhiteSpace(password)) errorMessage = "Password field is required."; + else if (string.IsNullOrWhiteSpace(employeeId)) + errorMessage = "EmployeeId field is required."; - if(!string.IsNullOrWhiteSpace(password) && password.Trim().ToUpper() != "ADMIN") + if (!string.IsNullOrWhiteSpace(password) && password.Trim().ToUpper() != "ADMIN") errorMessage = "Invalid password."; if (!string.IsNullOrWhiteSpace(errorMessage)) @@ -109,6 +112,7 @@ public void CreateServer() screens[ProgramScreen.FormScreen].ClearFieldValue("fname"); screens[ProgramScreen.FormScreen].ClearFieldValue("lname"); screens[ProgramScreen.FormScreen].ClearFieldValue("password"); + screens[ProgramScreen.FormScreen].ClearFieldValue("employeeId"); screens[ProgramScreen.FormScreen].ClearFieldValue("errormsg"); }, formScreenAction); @@ -160,6 +164,9 @@ private Dictionary DefineScreens() FormScreen.AddText(7,1,"Password . . . ."); FormScreen.AddInput(7,20,"password", true); FormScreen.AddEOF(7, 41); + FormScreen.AddText(8, 1, "Employee ID . ."); + FormScreen.AddInput(8, 20, "employeeId", numericonly: true); + FormScreen.AddEOF(8, 41); FormScreen.AddText(9,1,"Press"); FormScreen.AddText(9,7,"ENTER", true); FormScreen.AddText(9,13,"to submit your name."); diff --git a/TN3270Sharp/Field.cs b/TN3270Sharp/Field.cs index 47c4875..b620114 100644 --- a/TN3270Sharp/Field.cs +++ b/TN3270Sharp/Field.cs @@ -51,6 +51,9 @@ public class Field // password input field). public bool Hidden { get; set; } + // NumericOnly indicates if the client only accepts numeric input. + public bool NumericOnly { get; set; } + // Color is the field color. The default value is the default color. public Colors Color { get; set; } diff --git a/TN3270Sharp/Screen.cs b/TN3270Sharp/Screen.cs index 237945b..74136eb 100644 --- a/TN3270Sharp/Screen.cs +++ b/TN3270Sharp/Screen.cs @@ -95,8 +95,9 @@ public void AddText(int row, int column, string contents, bool intensity = false /// text is hidden (i.e., password) /// is input field writable (true/false) /// should the input field be underscored (true/false) + /// allows only numeric input /// - public void AddInput(int row, int column, string name, bool hidden = false, bool write = true, bool underscore = true) + public void AddInput(int row, int column, string name, bool hidden = false, bool write = true, bool underscore = true, bool numericonly = false) => Fields.Add(new Field { Column = column, @@ -107,6 +108,7 @@ public void AddInput(int row, int column, string name, bool hidden = false, bool ? Highlight.Underscore : Highlight.DefaultHighlight, Hidden = hidden, + NumericOnly = numericonly, }); /// @@ -120,11 +122,12 @@ public void AddInput(int row, int column, string name, bool hidden = false, bool /// text is hidden (i.e., password) /// is input field writable (true/false) /// should the input field be underscored (true/false) + /// allows only numeric input /// public void AddInput(int row, int column, int length, string name, bool hidden = false, bool write = true, - bool underscore = true) + bool underscore = true, bool numericonly = false) { - AddInput(row, column, name, hidden, write, underscore); + AddInput(row, column, name, hidden, write, underscore, numericonly); AddEOF(row, column + length + 1); } @@ -157,6 +160,7 @@ public byte[] BuildField(Field fld) buffer.Add((byte)ControlChars.SF); buffer.Add((byte)( (fld.Write ? AttribChar.Unprotected : AttribChar.Protected) | + (fld.NumericOnly ? AttribChar.Numeric : AttribChar.Alpha) | (fld.Intensity ? AttribChar.Intensity : AttribChar.Normal) | (fld.Hidden ? AttribChar.Hidden : AttribChar.Normal) )); @@ -179,6 +183,7 @@ public byte[] BuildField(Field fld) buffer.Add(0xc0); buffer.Add((byte)( (fld.Write ? AttribChar.Unprotected : AttribChar.Protected) | + (fld.NumericOnly ? AttribChar.Numeric : AttribChar.Alpha) | (fld.Intensity ? AttribChar.Intensity : AttribChar.Normal) | (fld.Hidden ? AttribChar.Hidden : AttribChar.Normal) ));