376 lines
13 KiB
C#
376 lines
13 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.Data.SqlClient;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows;
|
|
using System.Windows.Controls;
|
|
using System.Windows.Data;
|
|
using System.Windows.Documents;
|
|
using System.Windows.Input;
|
|
using System.Windows.Media;
|
|
using System.Windows.Media.Imaging;
|
|
using System.Windows.Shapes;
|
|
using System.Windows.Threading;
|
|
|
|
namespace eDosStation
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
/// Interaction logic for EntryBadge.xaml
|
|
/// </summary>
|
|
public partial class EntryBadge : Window
|
|
{
|
|
EpdBaseClr.Epd2 ep;
|
|
bool EpdFound = false;
|
|
DispatcherTimer dispatcherTimer;
|
|
int Search;
|
|
|
|
public static OkReadBadge.Badging a;
|
|
System.Threading.Thread t;
|
|
bool nextCSN = false;
|
|
bool nextSite = false;
|
|
bool nextCode = false;
|
|
bool nextFinish = false;
|
|
string csn, site, code;
|
|
static User _User;
|
|
|
|
DataSet1.GetTaskInfoRow CurTaskRow;
|
|
|
|
public EntryBadge()
|
|
{
|
|
InitializeComponent();
|
|
_User = null;
|
|
}
|
|
|
|
private bool LoadDoses()
|
|
{
|
|
bool rv = true;
|
|
ep.GetStatus();
|
|
|
|
if (ep.Issued)
|
|
{
|
|
MessageBox.Show("EPD is currently issued\nPlease take an other", "EDP", MessageBoxButton.OK, MessageBoxImage.Hand, MessageBoxResult.OK, MessageBoxOptions.ServiceNotification);
|
|
this.Close();
|
|
return false;
|
|
}
|
|
statusEPD.Text = $"EPD: {ep.b.CurrentDeviceID}";
|
|
ep.ReadTresholds();
|
|
|
|
return rv;
|
|
//ep.Hp07THDose =
|
|
}
|
|
|
|
private void DispatcherTimer_Tick(object sender, EventArgs e)
|
|
{
|
|
dispatcherTimer.Stop();
|
|
ep.Connect();
|
|
if (ep.DeviceCount == 1)
|
|
{
|
|
EpdFound = true;
|
|
DoEPD();
|
|
}
|
|
if (!EpdFound)
|
|
{
|
|
Search--;
|
|
if (Search > 0)
|
|
{
|
|
statusEPD.Text = $"Search {Search}";
|
|
dispatcherTimer.Start();
|
|
}
|
|
else
|
|
{
|
|
statusEPD.Text = $"Search Timeout";
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
private void DoEPD()
|
|
{
|
|
if (LoadDoses())
|
|
{
|
|
bool isBG = (ep.epdType == 3);
|
|
int? VisitID = null;
|
|
using (var co = new System.Data.SqlClient.SqlConnection(Properties.Settings.Default.RemoteSQL))
|
|
{
|
|
using (var cmd1 = new SqlCommand("VisitInit", co))
|
|
{
|
|
cmd1.CommandType = CommandType.StoredProcedure;
|
|
var pa = new SqlParameter("PersID", SqlDbType.Int, 4); pa.Value = _User.PersID; cmd1.Parameters.Add(pa);
|
|
pa = new SqlParameter("ID_Task", SqlDbType.Int, 4); pa.Value = CurTaskRow.ID_Task; cmd1.Parameters.Add(pa);
|
|
pa = new SqlParameter("Inst_CODE", SqlDbType.Int, 4); pa.Value = CurTaskRow.Inst_CODE; cmd1.Parameters.Add(pa);
|
|
pa = new SqlParameter("EPD_InternalID", SqlDbType.Int, 4); pa.Value = (int)ep.EpdID; cmd1.Parameters.Add(pa);
|
|
pa = new SqlParameter("isBG", SqlDbType.Bit, 4); pa.Value = isBG; cmd1.Parameters.Add(pa);
|
|
pa = new SqlParameter("ID_Visit", SqlDbType.Int, 4); pa.Direction = ParameterDirection.Output; cmd1.Parameters.Add(pa);
|
|
co.Open();
|
|
cmd1.ExecuteNonQuery();
|
|
VisitID = (int?)cmd1.Parameters["ID_Visit"].Value;
|
|
co.Close();
|
|
}
|
|
}
|
|
|
|
ep.WearerID = VisitID.ToString();
|
|
ep.WearerName = _User.PersID.ToString();
|
|
|
|
ep.Hp07RateOn = CurTaskRow.HP07RateON;
|
|
ep.Hp07RateOff = CurTaskRow.HP07RateOFF;
|
|
ep.Hp10Rate1On = CurTaskRow.HP10Rate1ON;
|
|
ep.Hp10Rate1Off = CurTaskRow.HP10Rate1ON;
|
|
ep.Hp10Rate2On = CurTaskRow.HP10Rate2ON;
|
|
ep.Hp10Rate2Off = CurTaskRow.HP10Rate2ON;
|
|
ep.Hp10THDose1 = CurTaskRow.Hp10Dose1;
|
|
ep.Hp10THDose2 = CurTaskRow.Hp10Dose2;
|
|
ep.Hp07THDose = CurTaskRow.Hp07Dose;
|
|
|
|
int? kx = null;
|
|
if (!CurTaskRow.IsFNGain_ANGainValueNull()) kx = (int)CurTaskRow.FNGain_ANGainValue;
|
|
if (kx != null && (ep.K3 != kx || ep.K4 != kx))
|
|
{
|
|
ep.K3 = ep.K4 = kx.Value;
|
|
|
|
//ep.K1 = 903;
|
|
//ep.K2 = 613;
|
|
//ep.K3 = 90;
|
|
//ep.K4 = 90;
|
|
//ep.K5 = 13100;
|
|
//ep.K6 = 1310;
|
|
|
|
//ep.K1 = 857;
|
|
//ep.K2 = 595;
|
|
//ep.K3 = 100;
|
|
//ep.K4 = 100;
|
|
//ep.K5 = 13100;
|
|
//ep.K6 = 1310;
|
|
|
|
if (ep.K6 != 1310)
|
|
{
|
|
MessageBox.Show("Alarm");
|
|
}
|
|
|
|
ep.WriteCalibration();
|
|
}
|
|
|
|
ep.SetIssued();
|
|
IssueOK.Visibility = Visibility.Visible;
|
|
}
|
|
}
|
|
|
|
private void GetEPD()
|
|
{
|
|
if (_User == null || CurTaskRow == null) return;
|
|
|
|
ep = new EpdBaseClr.Epd2(Properties.Settings.Default.comport);
|
|
ep.Connect();
|
|
if (ep.DeviceCount == 1)
|
|
{
|
|
EpdFound = true;
|
|
DoEPD();
|
|
}
|
|
if (!EpdFound)
|
|
{
|
|
statusEPD.Text = $"EPD: Wait ";
|
|
Search = 100;
|
|
dispatcherTimer = new DispatcherTimer();
|
|
dispatcherTimer.Tick += DispatcherTimer_Tick;
|
|
dispatcherTimer.Interval = new TimeSpan(0, 0, 2);
|
|
dispatcherTimer.Start();
|
|
return;
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
void AskTask()
|
|
{
|
|
eDosStation.DataSet1 dataSet1 = ((eDosStation.DataSet1)(this.FindResource("dataSet1")));
|
|
using (var dataSet1GetTaskInfoTableAdapter = new eDosStation.DataSet1TableAdapters.GetTaskInfoTableAdapter())
|
|
{
|
|
dataSet1GetTaskInfoTableAdapter.Fill(dataSet1.GetTaskInfo, null, _User.Margin);
|
|
}
|
|
tbTask.IsSelected = true;
|
|
|
|
}
|
|
void CheckBadge()
|
|
{
|
|
_User = new User(CSN.Text, Code.Text);
|
|
if (_User.AccessAllow == true)
|
|
AskTask();
|
|
else
|
|
Close();
|
|
}
|
|
public void showBadge()
|
|
{
|
|
CSN.Text = csn;
|
|
Site.Text = site;
|
|
Code.Text = code;
|
|
Dispatcher.Invoke(CheckBadge);
|
|
}
|
|
bool Msg(int err)
|
|
{
|
|
if (err == 0)
|
|
{
|
|
if (a.clr.Result.StartsWith("csn:", StringComparison.InvariantCultureIgnoreCase) && a.clr.Result.EndsWith(";"))
|
|
{ //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);
|
|
if (ar.StartsWith("site:")) site = ar.Substring(5);
|
|
if (ar.StartsWith("code:")) code = ar.Substring(5);
|
|
}
|
|
this.Dispatcher.Invoke(new Action(() => showBadge()));
|
|
}
|
|
else
|
|
{
|
|
if (a.clr.Result.Equals(";"))
|
|
{
|
|
if (nextSite) site = string.Empty;
|
|
if (nextCode) code = string.Empty;
|
|
if (nextFinish || nextCode)
|
|
{
|
|
this.Dispatcher.Invoke(new Action(() => showBadge()));
|
|
}
|
|
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
|
|
System.Diagnostics.Debug.WriteLine($"Error {err}");
|
|
|
|
|
|
|
|
return false;
|
|
}
|
|
|
|
private void BClear_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
CSN.Text = string.Empty;
|
|
Site.Text = string.Empty;
|
|
Code.Text = string.Empty;
|
|
}
|
|
|
|
private void TaskOK_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
bool isOk = false;
|
|
switch (TaskOK.Tag)
|
|
{
|
|
case "A": //No access
|
|
break;
|
|
case "M": //Margin
|
|
break;
|
|
case "B": // Badge
|
|
break;
|
|
case "L": //Locked
|
|
break;
|
|
case "O": // OK
|
|
isOk = true;
|
|
break;
|
|
}
|
|
|
|
if (isOk)
|
|
{
|
|
tbEPD.IsSelected = true;
|
|
System.Windows.Data.CollectionViewSource getTaskListViewSource = ((System.Windows.Data.CollectionViewSource)(this.FindResource("getTaskListViewSource")));
|
|
var rv = getTaskListViewSource.View.CurrentItem as DataRowView;
|
|
CurTaskRow = rv.Row as DataSet1.GetTaskInfoRow;
|
|
GetEPD();
|
|
}
|
|
}
|
|
|
|
private void ListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
|
{
|
|
var lb = sender as ListBox;
|
|
DataRowView o = null;
|
|
if (e.AddedItems.Count > 0)
|
|
{
|
|
o = e.AddedItems[0] as DataRowView;
|
|
}
|
|
bool exceeded = false;
|
|
if (o != null)
|
|
{
|
|
exceeded = (((DataSet1.GetTaskInfoRow)o.Row).MarginExceeded);
|
|
}
|
|
if (_User == null) { TaskOK.Content = "Badge"; TaskOK.Tag = "B"; }
|
|
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 (exceeded == true) { TaskOK.Content = "No Margin"; TaskOK.Tag = "M"; }
|
|
else
|
|
{
|
|
TaskOK.Content = "OK"; TaskOK.Tag = "O";
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void CbAlara_Checked(object sender, RoutedEventArgs e)
|
|
{
|
|
|
|
bool isAlara = (cbAlara.IsChecked == true);
|
|
if (isAlara) cbAlara.Content = "Alara"; else cbAlara.Content = "Normal";
|
|
//cbNormal.IsChecked = !isAlara;
|
|
System.Windows.Data.CollectionViewSource getTaskListViewSource = ((System.Windows.Data.CollectionViewSource)(this.FindResource("getTaskListViewSource")));
|
|
|
|
var dv = getTaskListViewSource.View.SourceCollection as DataView;
|
|
if (isAlara) dv.RowFilter = "ID_Task>=1000"; else dv.RowFilter = "ID_Task<1000";
|
|
getTaskListViewSource.View.MoveCurrentToFirst();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void Starter()
|
|
{
|
|
a = new OkReadBadge.Badging(Msg);
|
|
a.Start();
|
|
}
|
|
private void Window_Loaded(object sender, RoutedEventArgs e)
|
|
{
|
|
tbEntry.IsSelected = true;
|
|
IssueOK.Visibility = Visibility.Hidden;
|
|
|
|
eDosStation.DataSet1 dataSet1 = ((eDosStation.DataSet1)(this.FindResource("dataSet1")));
|
|
//using (eDosStation.DataSet1TableAdapters.GetTaskListTableAdapter dataSet1GetTaskListTableAdapter = new eDosStation.DataSet1TableAdapters.GetTaskListTableAdapter())
|
|
//{
|
|
// dataSet1GetTaskListTableAdapter.Fill(dataSet1.GetTaskList);
|
|
//}
|
|
using (var dataSet1GetTaskInfoTableAdapter = new eDosStation.DataSet1TableAdapters.GetTaskInfoTableAdapter())
|
|
{
|
|
dataSet1GetTaskInfoTableAdapter.Fill(dataSet1.GetTaskInfo, null, null);
|
|
}
|
|
|
|
|
|
|
|
System.Windows.Data.CollectionViewSource getTaskListViewSource = ((System.Windows.Data.CollectionViewSource)(this.FindResource("getTaskListViewSource")));
|
|
getTaskListViewSource.View.MoveCurrentToFirst();
|
|
|
|
|
|
////Real
|
|
//t = new System.Threading.Thread(() => Starter());
|
|
//t.Start();
|
|
|
|
|
|
|
|
////Debug
|
|
_User = new User("0428790A0B4E80", string.Empty);
|
|
|
|
Dispatcher.InvokeAsync(AskTask);
|
|
}
|
|
}
|
|
}
|