small stability

This commit is contained in:
Luc 2021-04-27 15:40:55 +02:00
parent df90ac8073
commit a0b5891dee
5 changed files with 53 additions and 27 deletions

View file

@ -44,5 +44,6 @@
<add key="Reader" value="HID Global OMNIKEY 5022 Smart Card Reader 0" /> <add key="Reader" value="HID Global OMNIKEY 5022 Smart Card Reader 0" />
<add key="TestCSN" value=""/> <add key="TestCSN" value=""/>
<add key="TestCode" value=""/> <add key="TestCode" value=""/>
<add key="sqlLogFolder" value="c:\logs"/>
</appSettings> </appSettings>
</configuration> </configuration>

View file

@ -291,12 +291,11 @@ namespace eDosStation
{ {
User u = new User(); User u = new User();
object[] Values = null; object[] Values = null;
if (int.TryParse(Code,out int PersID))
using (var cmd = new SqlCommand("GetPersonInfo", localConnection)) using (var cmd = new SqlCommand("GetPersonInfo", localConnection))
{ {
cmd.CommandType = System.Data.CommandType.StoredProcedure; cmd.CommandType = System.Data.CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("csn", CSN); if (int.TryParse(Code, out int PersID) ) cmd.Parameters.AddWithValue("PersID", PersID);
cmd.Parameters.AddWithValue("PersID", PersID); else cmd.Parameters.AddWithValue("csn", CSN);
//if (!string.IsNullOrWhiteSpace(Code)) cmd.Parameters.AddWithValue("Badge", Code); //if (!string.IsNullOrWhiteSpace(Code)) cmd.Parameters.AddWithValue("Badge", Code);
checkCon(true); checkCon(true);
cmd.Connection = localConnection; cmd.Connection = localConnection;

View file

@ -33,6 +33,9 @@
</TextBlock> </TextBlock>
</StackPanel> </StackPanel>
</Border> </Border>
<StackPanel VerticalAlignment="Center">
<telerik:RadButton Name="LeesCancel" Content="Cancel" Click="LeesCancel_Click" Width="300" Height="50" CornerRadius="10" TextBlock.FontSize="25" Margin="20,20,0,0" />
</StackPanel>
<StackPanel Orientation="Horizontal"> <StackPanel Orientation="Horizontal">
<TextBlock x:Name="CSN" /> <TextBlock x:Name="CSN" />
<TextBlock x:Name="Site" /> <TextBlock x:Name="Site" />

View file

@ -8,14 +8,12 @@ using System.Windows.Threading;
namespace eDosStation namespace eDosStation
{ {
/// <summary> /// <summary>
/// Interaction logic for EntryBadge.xaml /// Interaction logic for EntryBadge.xaml
/// </summary> /// </summary>
public partial class EntryBadge : Window public partial class EntryBadge : Window
{ {
const int PageTimeout = 10000; const int PageTimeout = 10000;
bool initialising = true; bool initialising = true;
Station thisStation; Station thisStation;
EpdBaseClr.Epd2 ep; EpdBaseClr.Epd2 ep;
@ -51,6 +49,7 @@ namespace eDosStation
thisStation = curStation; thisStation = curStation;
_User = null; _User = null;
} }
private bool LoadDoses() private bool LoadDoses()
{ {
bool rv = true; bool rv = true;
@ -131,7 +130,14 @@ namespace eDosStation
private void DoEPD() private void DoEPD()
{ {
int? StationVisitID = null; int? StationVisitID = null;
int? ID_Visit= DataInterface.NextID(); int? ID_Visit = null;
try
{
ID_Visit = DataInterface.NextID();
} catch (System.Exception ex)
{
MessageBox.Show($"Error {ex.Message}");
}
if (ID_Visit.HasValue && LoadDoses()) if (ID_Visit.HasValue && LoadDoses())
{ {
bool isBG = (ep.epdType != 3); //3 = zwarte 0=grijs bool isBG = (ep.epdType != 3); //3 = zwarte 0=grijs
@ -145,7 +151,7 @@ namespace eDosStation
dataInterface.VisitInitCommand.Parameters["EPD_InternalID"].Value = (int)ep.EpdID; dataInterface.VisitInitCommand.Parameters["EPD_InternalID"].Value = (int)ep.EpdID;
dataInterface.VisitInitCommand.Parameters["isBG"].Value = isBG; dataInterface.VisitInitCommand.Parameters["isBG"].Value = isBG;
dataInterface.VisitInitCommand.Parameters["ENTRY_EPD_CLOCK"].Value = ep.CountsClock; dataInterface.VisitInitCommand.Parameters["ENTRY_EPD_CLOCK"].Value = ep.CountsClock;
using (var l = new SqlLog()) using (var l = new SqlLog())
try try
@ -369,7 +375,7 @@ namespace eDosStation
void CheckBadge() void CheckBadge()
{ {
_User = dataInterface.GetUser(CSN.Text, Code.Text); _User = dataInterface.GetUser(CSN.Text, Code.Text);
ShowUserInfo(); //AskTask(); if (!ShowUserInfo()) endPage();
} }
public void showBadge(int persID, string csn) public void showBadge(int persID, string csn)
{ {
@ -594,6 +600,11 @@ namespace eDosStation
} }
private void LeesCancel_Click(object sender, RoutedEventArgs e)
{
endPage();
}
private void DfReader_BadgeTO(LSWDesfirePublic.CCard Sender, EventArgs e) private void DfReader_BadgeTO(LSWDesfirePublic.CCard Sender, EventArgs e)
{ {
this.Dispatcher.Invoke(new Action(() => endPage())); this.Dispatcher.Invoke(new Action(() => endPage()));

View file

@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Configuration;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -8,15 +9,23 @@ namespace eDosStation
{ {
public class SqlLog: IDisposable public class SqlLog: IDisposable
{ {
private string sqlLogFolder;
private string sqlLogFile;
private bool disposed = false; private bool disposed = false;
System.IO.StreamWriter wr; System.IO.StreamWriter wr;
System.Globalization.CultureInfo ci = System.Globalization.CultureInfo.GetCultureInfo("en-US"); System.Globalization.CultureInfo ci = System.Globalization.CultureInfo.GetCultureInfo("en-US");
public SqlLog() public SqlLog()
{ {
wr = null;
try try
{ {
wr = new System.IO.StreamWriter(@"c:\temp\sql.txt", true); sqlLogFolder = ConfigurationManager.AppSettings["sqlLogFolder"];
if (System.IO.Directory.Exists(sqlLogFolder))
{
sqlLogFile = System.IO.Path.Combine(sqlLogFolder, "sql.txt");
wr = new System.IO.StreamWriter(sqlLogFile, true);
}
} catch(System.Exception ex) } catch(System.Exception ex)
{ {
System.Diagnostics.Debug.WriteLine(ex.Message); System.Diagnostics.Debug.WriteLine(ex.Message);
@ -35,7 +44,7 @@ namespace eDosStation
if (disposing) if (disposing)
{ {
if (wr?.BaseStream != null) wr.Close(); if (wr?.BaseStream != null) wr.Close();
wr.Dispose(); wr?.Dispose();
} }
disposed = true; disposed = true;
} }
@ -47,7 +56,7 @@ namespace eDosStation
public void LogCommand(string ermsg) public void LogCommand(string ermsg)
{ {
if (wr.BaseStream.CanWrite) if (wr !=null && wr.BaseStream.CanWrite)
{ {
wr.WriteLine($"-- {System.DateTime.Now.ToString("yyyy-MM-dd HH:mm")} --- err {ermsg} ---"); wr.WriteLine($"-- {System.DateTime.Now.ToString("yyyy-MM-dd HH:mm")} --- err {ermsg} ---");
wr.Flush(); wr.Flush();
@ -56,26 +65,29 @@ namespace eDosStation
public void LogCommand(System.Data.SqlClient.SqlCommand co ) public void LogCommand(System.Data.SqlClient.SqlCommand co )
{ {
wr.WriteLine($"-- {System.DateTime.Now.ToString("yyyy-MM-dd HH:mm")} ---"); if (wr != null)
if (co.CommandType == System.Data.CommandType.StoredProcedure) wr.Write("exec ");
wr.Write(co.CommandText);
int paidx = 0;
foreach (System.Data.SqlClient.SqlParameter pa in co.Parameters)
{ {
if (paidx++ > 0) wr.Write(","); wr.WriteLine($"-- {System.DateTime.Now.ToString("yyyy-MM-dd HH:mm")} ---");
wr.Write($" @{pa.ParameterName}="); if (co.CommandType == System.Data.CommandType.StoredProcedure) wr.Write("exec ");
if (pa.Value == DBNull.Value) wr.Write("null"); wr.Write(co.CommandText);
else if (pa.DbType == System.Data.DbType.String) wr.Write($"'{pa.Value}'"); int paidx = 0;
else if (pa.DbType == System.Data.DbType.DateTime) wr.Write($"'{pa.Value:yyyyMMdd HH:mm}'"); foreach (System.Data.SqlClient.SqlParameter pa in co.Parameters)
else if (pa.DbType == System.Data.DbType.Double)
{ {
wr.Write(((double)pa.Value).ToString("0.0",ci)); if (paidx++ > 0) wr.Write(",");
wr.Write($" @{pa.ParameterName}=");
if (pa.Value == DBNull.Value) wr.Write("null");
else if (pa.DbType == System.Data.DbType.String) wr.Write($"'{pa.Value}'");
else if (pa.DbType == System.Data.DbType.DateTime) wr.Write($"'{pa.Value:yyyyMMdd HH:mm}'");
else if (pa.DbType == System.Data.DbType.Double)
{
wr.Write(((double)pa.Value).ToString("0.0", ci));
}
else wr.Write(pa.Value);
} }
else wr.Write(pa.Value); wr.WriteLine();
wr.WriteLine("----");
wr.Flush();
} }
wr.WriteLine();
wr.WriteLine("----");
wr.Flush();
} }
} }
} }