Multi form entry

This commit is contained in:
Mike Phares 2023-04-01 13:02:33 -07:00
parent 3884ce824a
commit d3794bf9cc
2 changed files with 51 additions and 28 deletions

2
.vscode/launch.json vendored
View File

@ -198,7 +198,7 @@
"type": "coreclr", "type": "coreclr",
"request": "launch", "request": "launch",
"preLaunchTask": "build", "preLaunchTask": "build",
"program": "${workspaceFolder}/Person/bin/Debug/net7.0/win-x64/Person.dll", "program": "${workspaceFolder}/Person/bin/Debug/net6.0/Person.dll",
"args": [ "args": [
"s" "s"
], ],

View File

@ -79,11 +79,13 @@ public class Person
ConsoleKey sex; ConsoleKey sex;
long personKey; long personKey;
string? lastName; string? lastName;
string[] segments;
string middleName; string middleName;
string? firstName; string? firstName;
DateTime? dateTime; DateTime? dateTime;
PersonName personName; PersonName personName;
string checkDirectory; string checkDirectory;
DateTime parseDateTime;
ConsoleKey? consoleKey; ConsoleKey? consoleKey;
string? approximateYears; string? approximateYears;
string personKeyFormatted; string personKeyFormatted;
@ -96,6 +98,8 @@ public class Person
log.Information(". . ."); log.Information(". . .");
if (consoleKey is not ConsoleKey.Y and not ConsoleKey.N) if (consoleKey is not ConsoleKey.Y and not ConsoleKey.N)
break; break;
else if (consoleKey is ConsoleKey.N)
break;
firstName = null; firstName = null;
for (int f = 0; f < 5; f++) for (int f = 0; f < 5; f++)
{ {
@ -112,20 +116,32 @@ public class Person
lastName = null; lastName = null;
for (int f = 0; f < 5; f++) for (int f = 0; f < 5; f++)
{ {
log.Information("Enter persons last name (minimum length of two characters)"); segments = firstName.Split(' ');
line = System.Console.ReadLine(); if (segments.Length > 1)
log.Information(". . ."); lastName = segments[^1];
if (string.IsNullOrEmpty(line) || line.Length < 2) else
continue; {
lastName = line.Trim(); log.Information("Enter persons last name (minimum length of two characters)");
line = System.Console.ReadLine();
log.Information(". . .");
if (string.IsNullOrEmpty(line) || line.Length < 2)
continue;
lastName = line.Trim();
}
break; break;
} }
if (lastName is null) if (lastName is null)
continue; continue;
log.Information("Enter persons middle name (press enter if they don't have a middle name)"); segments = firstName.Split(' ');
line = System.Console.ReadLine(); if (segments.Length > 2)
log.Information(". . ."); middleName = segments[1];
middleName = string.IsNullOrEmpty(line) ? string.Empty : line; else
{
log.Information("Enter persons middle name (press enter if they don't have a middle name)");
line = System.Console.ReadLine();
log.Information(". . .");
middleName = string.IsNullOrEmpty(line) ? string.Empty : line;
}
log.Information("Enter persons alias (press enter if they don't have a alias)"); log.Information("Enter persons alias (press enter if they don't have a alias)");
line = System.Console.ReadLine(); line = System.Console.ReadLine();
log.Information(". . ."); log.Information(". . .");
@ -143,8 +159,6 @@ public class Person
log.Information(". . ."); log.Information(". . .");
if (consoleKey is not ConsoleKey.Y and not ConsoleKey.N) if (consoleKey is not ConsoleKey.Y and not ConsoleKey.N)
continue; continue;
else if (consoleKey is ConsoleKey.N)
break;
deceased = consoleKey == ConsoleKey.Y; deceased = consoleKey == ConsoleKey.Y;
dateTime = null; dateTime = null;
approximateYears = null; approximateYears = null;
@ -169,27 +183,18 @@ public class Person
else else
{ {
month = line.Trim(); month = line.Trim();
log.Information("Enter persons birthday day (press enter if not known)"); if (DateTime.TryParse(month, out parseDateTime) && parseDateTime != DateTime.MinValue)
line = System.Console.ReadLine();
log.Information(". . .");
if (string.IsNullOrEmpty(line))
{ {
log.Information("Enter persons approximate age"); month = parseDateTime.Month.ToString();
line = System.Console.ReadLine(); day = parseDateTime.Day.ToString();
log.Information(". . ."); year = parseDateTime.Year.ToString();
if (string.IsNullOrEmpty(line) || !int.TryParse(line, out _))
continue;
approximateYears = line.Trim();
} }
else else
{ {
day = line.Trim(); log.Information("Enter persons birthday day (press enter if not known)");
log.Information("Enter persons birthday year (press enter if not known)");
line = System.Console.ReadLine(); line = System.Console.ReadLine();
log.Information(". . ."); log.Information(". . .");
if (!string.IsNullOrEmpty(line)) if (string.IsNullOrEmpty(line))
year = line.Trim();
else
{ {
log.Information("Enter persons approximate age"); log.Information("Enter persons approximate age");
line = System.Console.ReadLine(); line = System.Console.ReadLine();
@ -198,6 +203,24 @@ public class Person
continue; continue;
approximateYears = line.Trim(); approximateYears = line.Trim();
} }
else
{
day = line.Trim();
log.Information("Enter persons birthday year (press enter if not known)");
line = System.Console.ReadLine();
log.Information(". . .");
if (!string.IsNullOrEmpty(line))
year = line.Trim();
else
{
log.Information("Enter persons approximate age");
line = System.Console.ReadLine();
log.Information(". . .");
if (string.IsNullOrEmpty(line) || !int.TryParse(line, out _))
continue;
approximateYears = line.Trim();
}
}
} }
} }
if (month is null || day is null || year is null) if (month is null || day is null || year is null)