📄 state.cs
字号:
using System;
using System.Collections.Generic;
using System.Text;
using RedCorona.Net;
using System.Net.Sockets;
using System.Windows.Forms;
using System.Web;
using System.Collections.Specialized;
namespace Registration
{
class State
{
ClientInfo client;
Socket sock;
public bool IsConnectedToServer;
public bool IsConnectingToServer;
private int visitorCount = 0;
public string VisitorCount
{
get
{
return this.visitorCount.ToString();
}
}
public void ConnectToServer()
{
IsConnectingToServer = true;
try
{
sock = Sockets.CreateTCPSocket(clsGlobal.ServerIP, clsGlobal.ServerPort);
client = new ClientInfo(sock, true);
client.OnRead += new ConnectionRead(ReadData);
client.Delimiter = '\n'; // this is the default, shown for illustration
IsConnectedToServer = true;
}
catch (Exception ex)
{
IsConnectedToServer = false;
}
IsConnectingToServer = false;
}
public void Reconnect()
{
IsConnectedToServer = false;
try
{
sock.Close();
}
catch { }
try
{
client.Close();
}
catch { }
sock = null;
client = null;
ConnectToServer();
}
void ReadData(ClientInfo ci, String text)
{
if (text.Contains("VISITORCOUNT="))
{
int.TryParse(Tools.StripNonNumeric(text),out this.visitorCount);
}
if (text.Contains("ACT=REGACK"))
{
NameValueCollection nsv = Tools.GetValues(text);
clsGlobal.g_objfrmMain.ReceiveRegistrationAck(nsv["VisitorId"]);
}
}
public State()
{
ConnectToServer();
}
public int cTime
{
get
{
return DateTime.Now.Hour * 100 + DateTime.Now.Minute;
}
}
public bool IsVisitingHours
{
get
{
if (clsGlobal.a_visitStart <= cTime && cTime <= clsGlobal.a_visitEnd)
return true;
if (clsGlobal.e_visitStart <= cTime && cTime <= clsGlobal.e_visitEnd)
return true;
return false;
}
}
public bool IsNextVisitingHoursEvening
{
get
{
if (clsGlobal.a_visitEnd < cTime && cTime < clsGlobal.e_visitStart)
return true;
else
return false;
}
}
public bool IsNextVisitingHoursAfternoon
{
get
{
if (clsGlobal.e_visitEnd < cTime || cTime < clsGlobal.a_visitStart)
return true;
else
return false;
}
}
public bool SendRegistration(Transaction ts)
{
try
{
if(!IsConnectedToServer)
ConnectToServer();
if (IsConnectedToServer)
{
ts.VisitorId = Guid.NewGuid().ToString();
string message = "ACT=REGISTER";
message += "&VisitorId=" + HttpUtility.UrlEncode(ts.VisitorId);
message += "&VisitorName=" + HttpUtility.UrlEncode(ts.VisitorName);
message += "&VisitorIC=" + HttpUtility.UrlEncode(ts.VisitorNRIC);
message += "&PatientName=" + HttpUtility.UrlEncode(ts.PatientsName);
message += "&ContactNumber=" + HttpUtility.UrlEncode(ts.VisitorContactNo);
message += "&FingerTemplate=" + HttpUtility.UrlEncode(ts.SecondTemplate);
message += "\n";
client.Send(message);
return true;
}
else
{
return false;
}
}
catch (Exception ex)
{
return false;
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -