test persons

This commit is contained in:
Luc Vandenbroucke 2020-02-11 16:33:49 +01:00
parent df163e6727
commit e29970b7a9
10 changed files with 197 additions and 46 deletions

View file

@ -37,11 +37,15 @@ void OkReadBadge::BadgeUnmanaged::GetDeviceUSB(std::wstring vid, std::wstring pi
auto x = sDeviceID.find(vid); auto x = sDeviceID.find(vid);
auto y = sDeviceID.find(pid); auto y = sDeviceID.find(pid);
auto z = sDeviceID.find(pid2); auto z = sDeviceID.find(pid2);
if (x < 100)
{
System::Diagnostics::Trace::WriteLine( gcnew System::String(sDeviceID.c_str()));
}
if (x < 100 && (y < 100 || z < 100)) if (x < 100 && (y < 100 || z < 100))
{ {
DWORD deviceInterfaceIndex = 0; DWORD deviceInterfaceIndex = 0;
deviceInterfaceData.cbSize = sizeof(deviceInterfaceData); deviceInterfaceData.cbSize = sizeof(deviceInterfaceData);
System::Diagnostics::Trace::WriteLine(String::Format("x {0}", x));
if (SetupDiEnumDeviceInterfaces(deviceInterfaceSet, &deviceInfoData, &hid, deviceInterfaceIndex, &deviceInterfaceData)) if (SetupDiEnumDeviceInterfaces(deviceInterfaceSet, &deviceInfoData, &hid, deviceInterfaceIndex, &deviceInterfaceData))
{ {
deviceInterfaceData.cbSize = sizeof(deviceInterfaceData); deviceInterfaceData.cbSize = sizeof(deviceInterfaceData);

View file

@ -32,6 +32,50 @@ namespace OkReadBadge
bool nextFinish = false; bool nextFinish = false;
bool completed = false; bool completed = false;
char Res [100]; char Res [100];
char CSN[50];
char Site[20];
char Badge[20];
int parse(char *rall)
{
int items;
char *source;
int sourcelen;
char *dest;
int destlen;
char *r = rall;
char *mx = r + strlen(rall);
items = 0;
Res[0] = 0;
while (r < mx && items<3) {
if (!strncmp("csn:", r, 4)) {
items++;
dest = CSN; destlen = sizeof(CSN);
source = r + 4; //na csn:
}
else if (!strncmp("site:", r, 4)) {
items++;
dest = Site; destlen = sizeof(Site);
source = r + 5; //na site:
}
else if (!strncmp("code:", r, 4)) {
items++;
dest = Badge; destlen = sizeof(Badge);
source = r + 5; //na code:
}
else {
dest = NULL; destlen = 0;
}
char *x = strchr(source, ';');
*x = 0; sourcelen = strlen(source);
if (dest != NULL) {
memcpy_s(dest, destlen, source, sourcelen + 1);
}
r = x + 1;
}
return items;
}
static bool CALLBACK Message(int err, LPARAM param) static bool CALLBACK Message(int err, LPARAM param)
{ {
@ -42,15 +86,43 @@ namespace OkReadBadge
char *r = (char *)&bu->buffer[4]; char *r = (char *)&bu->buffer[4];
r[l] = 0; r[l] = 0;
if (bu->nextCSN) { if (bu->nextCSN) {
memcpy_s(bu->Res, 100, r, l + 1); bu->nextCSN = false; } memcpy_s(bu->CSN, sizeof(bu->CSN), r, l + 1);
memcpy_s(bu->Res, sizeof(bu->Res), r, l + 1);
bu->nextCSN = false;
}
else if (bu->nextSite) { else if (bu->nextSite) {
memcpy_s(bu->Site, 20, r, l + 1);
strncat_s(bu->Res, (const char *)r, l); bu->nextSite = false; } strncat_s(bu->Res, (const char *)r, l); bu->nextSite = false; }
else if (bu->nextCode) { else if (bu->nextCode) {
memcpy_s(bu->Badge, sizeof(bu->Badge), r, l + 1);
strncat_s(bu->Res, (const char *)r, l); bu->nextCode = false; bu->nextFinish = true; strncat_s(bu->Res, (const char *)r, l); bu->nextCode = false; bu->nextFinish = true;
} }
else if (!strncmp("csn:", r, 4)) { else if (!strncmp("csn:", r, 4)) {
bu->nextCSN = true; bu->nextFinish = bu->nextCode = bu->nextSite = bu->completed = false;
if (strstr(r, "code:") != NULL) {
int it = bu->parse(r);
//char *s = r + 4; //na csn:
//char *x = strchr(r, ';');
//*x = 0; l = strlen(s);
//memcpy_s(bu->CSN, sizeof(bu->CSN), s, l + 1);
////x+1 should be "site:"
//s = x + 6; // n a site:v
//x = strchr(s, ';'); *x = 0; l = strlen(s);
////x+1 should be "code:"
//memcpy_s(bu->Site, sizeof(bu->Site), s, l + 1);
//s = x + 6; // no code:
//x = strchr(s, ';'); *x = 0; l = strlen(s);
//memcpy_s(bu->Badge, sizeof(bu->Badge), s, l + 1);
bu->completed = true;
}
else {
memset(bu->Res, 0, sizeof(bu->Res)); memset(bu->Res, 0, sizeof(bu->Res));
bu->nextCSN = true; bu->nextFinish = bu->nextCode = bu->nextSite = bu->completed = false ; memset(bu->CSN, 0, sizeof(bu->CSN));
memset(bu->Site, 0, sizeof(bu->Site));
memset(bu->Badge, 0, sizeof(bu->Badge));
bu->completed = false;
bu->m_clr->Final = false;
}
} }
else if (!strncmp("site:", r, 5)) { bu->nextSite = true; } else if (!strncmp("site:", r, 5)) { bu->nextSite = true; }
else if (!strncmp("code:", r, 5)) { bu->nextCode = true; } else if (!strncmp("code:", r, 5)) { bu->nextCode = true; }
@ -62,13 +134,23 @@ namespace OkReadBadge
bu->completed = true; bu->completed = true;
} }
} }
if (bu->completed)
{
bu->m_clr->Final = true;
bu->m_clr->CSN= gcnew String(bu->CSN);
bu->m_clr->Site = gcnew String(bu->Site);
bu->m_clr->Badge= gcnew String(bu->Badge);
}
else
bu->m_clr->Result = gcnew String(r); bu->m_clr->Result = gcnew String(r);
} }
else { else {
if (bu->nextCSN | bu->nextFinish | bu->nextCode | bu->nextSite | bu->nextCSN ) if (bu->nextCSN | bu->nextFinish | bu->nextCode | bu->nextSite | bu->nextCSN )
bu->m_clr->Result = gcnew String(bu->Res); bu->m_clr->Result = gcnew String(bu->Res);
else else {
bu->m_clr->Result = String::Empty; bu->m_clr->Result = String::Empty;
bu->m_clr->Final = false;
}
} }
return bu->m_clr->OnMessage((int)err); return bu->m_clr->OnMessage((int)err);
} }

View file

@ -21,10 +21,10 @@
<PropertyGroup Label="Globals"> <PropertyGroup Label="Globals">
<VCProjectVersion>15.0</VCProjectVersion> <VCProjectVersion>15.0</VCProjectVersion>
<ProjectGuid>{F98F3496-8A4C-4BDB-9F17-C7AF47A60739}</ProjectGuid> <ProjectGuid>{F98F3496-8A4C-4BDB-9F17-C7AF47A60739}</ProjectGuid>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<Keyword>ManagedCProj</Keyword> <Keyword>ManagedCProj</Keyword>
<RootNamespace>OkReadBadge</RootNamespace> <RootNamespace>OkReadBadge</RootNamespace>
<WindowsTargetPlatformVersion>10.0.16299.0</WindowsTargetPlatformVersion> <WindowsTargetPlatformVersion>10.0.16299.0</WindowsTargetPlatformVersion>
<TargetFrameworkVersion>4.7.2</TargetFrameworkVersion>
</PropertyGroup> </PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">

View file

@ -13,6 +13,10 @@ namespace OkReadBadge
delegate bool delMessage(int err); delegate bool delMessage(int err);
delMessage^ OnMessage; delMessage^ OnMessage;
String^ Result; String^ Result;
String^ CSN;
String^ Site;
String^ Badge;
bool Final;
bool Message(int err) bool Message(int err)
{ {
System::Diagnostics::Debug::WriteLine(err.ToString()); System::Diagnostics::Debug::WriteLine(err.ToString());
@ -20,6 +24,8 @@ namespace OkReadBadge
} }
BadgeMessageHandler() BadgeMessageHandler()
{ {
Final = false;
Result = CSN= Site = Badge = String::Empty;
OnMessage = gcnew delMessage(this, &BadgeMessageHandler::Message); OnMessage = gcnew delMessage(this, &BadgeMessageHandler::Message);
} }
}; };

View file

@ -32,6 +32,9 @@
<setting name="TestCSN" serializeAs="String"> <setting name="TestCSN" serializeAs="String">
<value>0428790A0B4E80</value> <value>0428790A0B4E80</value>
</setting> </setting>
<setting name="useTestButtons" serializeAs="String">
<value>True</value>
</setting>
</eDosStation.Properties.Settings> </eDosStation.Properties.Settings>
</userSettings> </userSettings>
</configuration> </configuration>

View file

@ -32,7 +32,10 @@
<TextBlock x:Name="Site" /> <TextBlock x:Name="Site" />
<TextBlock x:Name="Code" /> <TextBlock x:Name="Code" />
</StackPanel> </StackPanel>
<StackPanel Orientation="Horizontal" Margin="0,50,0,0" Name="pTestButtons">
</StackPanel> </StackPanel>
</StackPanel>
</TabItem> </TabItem>
<TabItem Name="tbUser" > <TabItem Name="tbUser" >
<StackPanel HorizontalAlignment="Center" VerticalAlignment="Center" Orientation="Vertical"> <StackPanel HorizontalAlignment="Center" VerticalAlignment="Center" Orientation="Vertical">

View file

@ -293,10 +293,10 @@ namespace eDosStation
else else
{ {
tbUser.IsSelected = true; tbUser.IsSelected = true;
if (_User == null || _User.VisitIDLocked == true || _User.AccessAllow == false) if (_User == null || _User.VisitIDLocked >0 || _User.AccessAllow == false)
{ {
//tbNotAllowed.IsSelected = true; //tbNotAllowed.IsSelected = true;
if (_User.VisitIDLocked == true || _User.AccessAllow == false) if (_User.VisitIDLocked > 0|| _User.AccessAllow == false)
ReasonNoAccess = _User.ReasonNoAccess; ReasonNoAccess = _User.ReasonNoAccess;
else ReasonNoAccess = getCommentOnEvent(string.Empty, 3); else ReasonNoAccess = getCommentOnEvent(string.Empty, 3);
} }
@ -376,40 +376,48 @@ namespace eDosStation
if (err == 0) if (err == 0)
{ {
System.Diagnostics.Debug.WriteLine($"msg result={a.clr.Result}"); System.Diagnostics.Debug.WriteLine($"msg result={a.clr.Result} {a.clr.Final}");
if (a.clr.Result.StartsWith("csn:", StringComparison.InvariantCultureIgnoreCase) && a.clr.Result.EndsWith(";")) if (a.clr.Final)
{ //GEn 2
csn = string.Empty;
foreach (string ar in a.clr.Result.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries))
{ {
if (ar.StartsWith("csn:")) csn = ar.Substring(4); csn = a.clr.CSN;
if (ar.StartsWith("site:")) site = ar.Substring(5); site = a.clr.Site;
if (ar.StartsWith("code:")) code = ar.Substring(5); code = a.clr.Badge;
}
this.Dispatcher.Invoke(new Action(() => showBadge())); this.Dispatcher.Invoke(new Action(() => showBadge()));
StopReadBadge = true; StopReadBadge = true;
} }
else // if (a.clr.Result.StartsWith("csn:", StringComparison.InvariantCultureIgnoreCase) && a.clr.Result.EndsWith(";"))
{ // { //GEn 2
if (a.clr.Result.Equals(";")) // csn = string.Empty;
{ // foreach (string ar in a.clr.Result.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries))
if (nextSite) site = string.Empty; // {
if (nextCode) code = string.Empty; // if (ar.StartsWith("csn:")) csn = ar.Substring(4);
if (nextFinish || nextCode) // if (ar.StartsWith("site:")) site = ar.Substring(5);
{ // if (ar.StartsWith("code:")) code = ar.Substring(5);
this.Dispatcher.Invoke(new Action(() => showBadge())); // }
StopReadBadge = true; // this.Dispatcher.Invoke(new Action(() => showBadge()));
} // StopReadBadge = true;
nextCSN = nextSite = nextCode = nextFinish = false; // }
} // else
else if (nextCSN) { csn = a.clr.Result; nextCSN = nextFinish = false; } // {
else if (nextSite) { site = a.clr.Result; nextSite = false; } // if (a.clr.Result.Equals(";"))
else if (nextCode) { code = a.clr.Result; nextCode = false; nextFinish = true; } // {
else if (a.clr.Result.Equals("csn:")) { nextCSN = true; nextCode = nextSite = false; } // if (nextSite) site = string.Empty;
else if (a.clr.Result.Equals("site:")) { nextSite = true; nextCSN = nextCode = false; } // if (nextCode) code = string.Empty;
else if (a.clr.Result.Equals("code:")) { nextCode = true; nextCSN = nextSite = false; } // if (nextFinish || nextCode)
else System.Diagnostics.Debug.WriteLine(a.clr.Result); // {
} // this.Dispatcher.Invoke(new Action(() => showBadge()));
// StopReadBadge = true;
// }
// nextCSN = nextSite = nextCode = nextFinish = false;
// }
// else if (nextCSN) { csn = a.clr.Result; nextCSN = nextFinish = false; }
// else if (nextSite) { site = a.clr.Result; nextSite = false; }
// else if (nextCode) { code = a.clr.Result; nextCode = false; nextFinish = true; }
// else if (a.clr.Result.Equals("csn:")) { nextCSN = true; nextCode = nextSite = false; }
// else if (a.clr.Result.Equals("site:")) { nextSite = true; nextCSN = nextCode = false; }
// else if (a.clr.Result.Equals("code:")) { nextCode = true; nextCSN = nextSite = false; }
// else System.Diagnostics.Debug.WriteLine(a.clr.Result);
// }
} }
else else
System.Diagnostics.Debug.WriteLine($"Error {err}"); System.Diagnostics.Debug.WriteLine($"Error {err}");
@ -477,7 +485,7 @@ namespace eDosStation
} }
if (_User == null) { TaskOK.Content = "Badge"; TaskOK.Tag = "B"; } if (_User == null) { TaskOK.Content = "Badge"; TaskOK.Tag = "B"; }
else if (_User.AccessAllow != true) { TaskOK.Content = "No Access"; TaskOK.Tag = "A"; } else if (_User.AccessAllow != true) { TaskOK.Content = "No Access"; TaskOK.Tag = "A"; }
else if (_User.VisitIDLocked == true) { TaskOK.Content = "Locked"; TaskOK.Tag = "L"; } else if (_User.VisitIDLocked >0 ) { TaskOK.Content = "Locked"; TaskOK.Tag = "L"; }
else if (exceeded == true) { TaskOK.Content = "No Margin"; TaskOK.Tag = "M"; } else if (exceeded == true) { TaskOK.Content = "No Margin"; TaskOK.Tag = "M"; }
else else
{ {
@ -530,6 +538,13 @@ namespace eDosStation
Close(); Close();
} }
private void BTestPerson_Click(object sender, RoutedEventArgs e)
{
Button b = sender as Button;
_User = new User("TP"+b.Tag, "");
ShowUserInfo(); //AskTask();
}
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e) private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{ {
t = null; t = null;
@ -560,6 +575,26 @@ namespace eDosStation
MessageBox.Show($"Badgereader error {ex.Message}", "Error", MessageBoxButton.OK, MessageBoxImage.Exclamation); MessageBox.Show($"Badgereader error {ex.Message}", "Error", MessageBoxButton.OK, MessageBoxImage.Exclamation);
} }
} }
private void AddTestButtons()
{
//pTestButtons
//<Button Height="30" Content="*TP 1*" Tag="1" Name="bTestPerson1" Click="BTestPerson_Click" Margin="0,0,20,0"/>
StackPanel sp = pTestButtons;
Button b;
Thickness m = new Thickness(0, 0, 20, 0);
for (int i = 1; i < 15; i++)
{
b = new Button();
b.Click += BTestPerson_Click;
b.Tag = i.ToString();
b.Content = $"* TP {i} *";
b.Height = 30;
b.Margin = m;
sp.Children.Add(b);
}
}
private void Window_Loaded(object sender, RoutedEventArgs e) private void Window_Loaded(object sender, RoutedEventArgs e)
{ {
EpdFound = false; EpdFound = false;
@ -586,6 +621,9 @@ namespace eDosStation
string TestCSN = thisStation.TestCSN; string TestCSN = thisStation.TestCSN;
initialising = false; initialising = false;
if (Properties.Settings.Default.useTestButtons)
AddTestButtons();
if (string.IsNullOrWhiteSpace(TestCSN)) if (string.IsNullOrWhiteSpace(TestCSN))
{ {
t = new System.Threading.Thread(() => Starter()); t = new System.Threading.Thread(() => Starter());

View file

@ -104,5 +104,17 @@ namespace eDosStation.Properties {
this["TestCSN"] = value; this["TestCSN"] = value;
} }
} }
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("True")]
public bool useTestButtons {
get {
return ((bool)(this["useTestButtons"]));
}
set {
this["useTestButtons"] = value;
}
}
} }
} }

View file

@ -28,5 +28,8 @@
<Setting Name="TestCSN" Type="System.String" Scope="User"> <Setting Name="TestCSN" Type="System.String" Scope="User">
<Value Profile="(Default)">0428790A0B4E80</Value> <Value Profile="(Default)">0428790A0B4E80</Value>
</Setting> </Setting>
<Setting Name="useTestButtons" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">True</Value>
</Setting>
</Settings> </Settings>
</SettingsFile> </SettingsFile>

View file

@ -16,7 +16,7 @@ namespace eDosStation
public string Language { get; set; } public string Language { get; set; }
public bool? AccessAllow { get; set; } public bool? AccessAllow { get; set; }
public double? Margin { get; set; } public double? Margin { get; set; }
public bool? VisitIDLocked { get; set; } public int? VisitIDLocked { get; set; }
public string ReasonNoAccess { get; set; } public string ReasonNoAccess { get; set; }
public string UserComment { get; set; } public string UserComment { get; set; }
@ -51,10 +51,10 @@ namespace eDosStation
Language = Values[rs.GetOrdinal("Language")].ToString(); Language = Values[rs.GetOrdinal("Language")].ToString();
AccessAllow = Values[rs.GetOrdinal("AccessAllow")] as bool?; AccessAllow = Values[rs.GetOrdinal("AccessAllow")] as bool?;
Margin = Values[rs.GetOrdinal("AccessAllow")] as double?; Margin = Values[rs.GetOrdinal("AccessAllow")] as double?;
VisitIDLocked = Values[rs.GetOrdinal("VisitIDLocked")] as bool?; VisitIDLocked = Values[rs.GetOrdinal("VisitIDLocked")] as int?;
ReasonNoAccess = Values[rs.GetOrdinal("ReasonNoAccess")].ToString().Replace("\\n","\n"); ReasonNoAccess = Values[rs.GetOrdinal("ReasonNoAccess")].ToString().Replace("\\n","\n");
UserComment = Values[rs.GetOrdinal("Comment")].ToString(); UserComment = Values[rs.GetOrdinal("Comment")].ToString();
AllOk = (AccessAllow == true & VisitIDLocked == true); AllOk = (AccessAllow == true && VisitIDLocked == 0 );
} else } else
{ {
// Not found // Not found
@ -65,10 +65,10 @@ namespace eDosStation
Language = "N"; Language = "N";
AccessAllow = false; AccessAllow = false;
Margin = 0; Margin = 0;
VisitIDLocked = false; VisitIDLocked = 0;
ReasonNoAccess = "Not found"; ReasonNoAccess = "Not found";
UserComment = ""; UserComment = "";
AllOk = (AccessAllow == true & VisitIDLocked == true); AllOk = (AccessAllow == true & VisitIDLocked == 0);
} }
rs.Close(); rs.Close();
} }