sync + badgereader update central
This commit is contained in:
parent
461ea83d4a
commit
95f923d22e
3 changed files with 78 additions and 39 deletions
|
|
@ -9,6 +9,10 @@
|
|||
<add name="eDosStation.Properties.Settings.localConnectionString"
|
||||
connectionString="Data Source=HPHDB;Initial Catalog=eDosLocal;User ID=eDosStation;Password=Infopla+8;TrustServerCertificate=True;Application Name=eDosStation"
|
||||
providerName="System.Data.SqlClient" />
|
||||
<add name="eDosConnectionString"
|
||||
connectionString="Data Source=HPHDB;Initial Catalog=eDos;User ID=eDosStation;Password=Infopla+8;TrustServerCertificate=True;Application Name=eDosStation"
|
||||
providerName="System.Data.SqlClient" />
|
||||
|
||||
</connectionStrings>
|
||||
<startup>
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8"/>
|
||||
|
|
|
|||
|
|
@ -13,8 +13,8 @@ namespace eDosStation
|
|||
{
|
||||
public int ID_Station;
|
||||
public bool isLocal = false;
|
||||
private string currentConStr;
|
||||
public System.Data.SqlClient.SqlConnection localConnection;
|
||||
private string currentConStr, ConCentralStr;
|
||||
public System.Data.SqlClient.SqlConnection localConnection, centralConnection;
|
||||
public System.Data.SqlClient.SqlCommand VisitInitCommand;
|
||||
public static SqlCommand VisitExitCommand;
|
||||
public static SqlCommand NextIDCommand;
|
||||
|
|
@ -59,6 +59,24 @@ namespace eDosStation
|
|||
if (rv && !leaveOpen) localConnection?.Close();
|
||||
return rv;
|
||||
}
|
||||
public bool checkConCentral(bool leaveOpen = false)
|
||||
{
|
||||
bool rv = false;
|
||||
|
||||
if (centralConnection != null && centralConnection.State == System.Data.ConnectionState.Open) return true;
|
||||
try
|
||||
{
|
||||
if (centralConnection == null || string.IsNullOrEmpty(centralConnection.ConnectionString)) centralConnection = new SqlConnection(ConCentralStr);
|
||||
centralConnection.Open();
|
||||
rv = true;
|
||||
}
|
||||
catch (System.Exception ex)
|
||||
{
|
||||
System.Windows.MessageBox.Show($"Opening '{ConCentralStr}' error :{ex.Message}");
|
||||
}
|
||||
if (rv && !leaveOpen) centralConnection?.Close();
|
||||
return rv;
|
||||
}
|
||||
|
||||
internal void SetStation(int curIDStation)
|
||||
{
|
||||
|
|
@ -85,6 +103,7 @@ namespace eDosStation
|
|||
{
|
||||
first();
|
||||
currentConStr = System.Configuration.ConfigurationManager.ConnectionStrings["eDosStation.Properties.Settings.localConnectionString"].ConnectionString;
|
||||
ConCentralStr = System.Configuration.ConfigurationManager.ConnectionStrings["eDosConnectionString"].ConnectionString;
|
||||
localConnection = new SqlConnection(currentConStr);
|
||||
NextIDCommand = new SqlCommand("SELECT NEXT VALUE FOR VisitSequence as VisitID", localConnection);
|
||||
isLocal = true;
|
||||
|
|
@ -124,7 +143,13 @@ namespace eDosStation
|
|||
return localConnection;
|
||||
}
|
||||
|
||||
void MakeCommands()
|
||||
public System.Data.SqlClient.SqlConnection getConCentral(bool LeaveOpen)
|
||||
{
|
||||
checkConCentral(LeaveOpen);
|
||||
return centralConnection;
|
||||
}
|
||||
|
||||
void MakeCommands()
|
||||
{
|
||||
LastIDCommand = new SqlCommand("VisitIDLast", localConnection);
|
||||
LastIDCommand.CommandType = CommandType.StoredProcedure;
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ namespace eDosStation
|
|||
public string Inst_Name1 { get; set; }
|
||||
public string Inst_Name2 { get; set; }
|
||||
public string TestCSN { get; set; }
|
||||
public string TestCode { get; set; }
|
||||
public string TestCode { get; set; }
|
||||
public string Reader { get; internal set; }
|
||||
|
||||
public bool Changed = false;
|
||||
|
|
@ -26,7 +26,7 @@ namespace eDosStation
|
|||
public string ErrorMessage;
|
||||
public StringBuilder insComments;
|
||||
public TextBlock tbComments;
|
||||
public DataInterface dataInterface;
|
||||
public DataInterface dataInterface;
|
||||
|
||||
public Station(DataInterface mDataInterface, string Station)
|
||||
{
|
||||
|
|
@ -36,7 +36,7 @@ namespace eDosStation
|
|||
ComPort = 0;
|
||||
Inst_CODE1 = 1;
|
||||
Inst_CODE2 = 11;
|
||||
Inst_Name1 = "BR1";
|
||||
Inst_Name1 = "BR1";
|
||||
Inst_Name2 = "Venus";
|
||||
TestCSN = System.Configuration.ConfigurationManager.AppSettings["TestCSN"];
|
||||
TestCode = System.Configuration.ConfigurationManager.AppSettings["TestCode"];
|
||||
|
|
@ -77,7 +77,7 @@ namespace eDosStation
|
|||
TestCSN = System.Configuration.ConfigurationManager.AppSettings["TestCSN"];
|
||||
TestCode = System.Configuration.ConfigurationManager.AppSettings["TestCode"];
|
||||
Changed = true;
|
||||
Reader= System.Configuration.ConfigurationManager.AppSettings["Reader"];
|
||||
Reader = System.Configuration.ConfigurationManager.AppSettings["Reader"];
|
||||
}
|
||||
rs.Close();
|
||||
}
|
||||
|
|
@ -125,44 +125,54 @@ namespace eDosStation
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
private void UpdateToDb(SqlConnection co, SqlCommand cmd)
|
||||
{
|
||||
cmd.Connection = co;
|
||||
cmd.ExecuteNonQuery();
|
||||
}
|
||||
public void Update()
|
||||
{
|
||||
var co = dataInterface.getCon(true);
|
||||
|
||||
SqlConnection co=null;
|
||||
using (var cmd = new SqlCommand("StationSettingsUpdate"))
|
||||
{
|
||||
using (var cmd = new SqlCommand("StationSettingsUpdate", co))
|
||||
cmd.CommandType = System.Data.CommandType.StoredProcedure;
|
||||
cmd.Parameters.AddWithValue("ComPort", ComPort);
|
||||
|
||||
if (!string.IsNullOrEmpty(Inst_Name1) && Inst_CODE1 > 0)
|
||||
{
|
||||
cmd.CommandType = System.Data.CommandType.StoredProcedure;
|
||||
cmd.Parameters.AddWithValue("ComPort", ComPort);
|
||||
|
||||
if (!string.IsNullOrEmpty(Inst_Name1) && Inst_CODE1 > 0)
|
||||
{
|
||||
cmd.Parameters.AddWithValue("Inst_CODE1", Inst_CODE1);
|
||||
cmd.Parameters.AddWithValue("Inst_Name1", Inst_Name1);
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(Inst_Name2) && Inst_CODE2 > 0)
|
||||
{
|
||||
cmd.Parameters.AddWithValue("Inst_CODE2", Inst_CODE2);
|
||||
cmd.Parameters.AddWithValue("Inst_Name2", Inst_Name2);
|
||||
}
|
||||
if (!string.IsNullOrEmpty(TestCSN))
|
||||
cmd.Parameters.AddWithValue("TestCSN", TestCSN);
|
||||
|
||||
if (!string.IsNullOrEmpty(Reader))
|
||||
cmd.Parameters.AddWithValue("@Reader", Reader);
|
||||
|
||||
try
|
||||
{
|
||||
cmd.ExecuteNonQuery();
|
||||
}
|
||||
catch (System.Exception ex)
|
||||
{
|
||||
Error = 1;
|
||||
ErrorMessage = ex.Message;
|
||||
}
|
||||
co.Close();
|
||||
cmd.Parameters.AddWithValue("Inst_CODE1", Inst_CODE1);
|
||||
cmd.Parameters.AddWithValue("Inst_Name1", Inst_Name1);
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(Inst_Name2) && Inst_CODE2 > 0)
|
||||
{
|
||||
cmd.Parameters.AddWithValue("Inst_CODE2", Inst_CODE2);
|
||||
cmd.Parameters.AddWithValue("Inst_Name2", Inst_Name2);
|
||||
}
|
||||
if (!string.IsNullOrEmpty(TestCSN))
|
||||
cmd.Parameters.AddWithValue("TestCSN", TestCSN);
|
||||
|
||||
if (!string.IsNullOrEmpty(Reader))
|
||||
cmd.Parameters.AddWithValue("@Reader", Reader);
|
||||
|
||||
try
|
||||
{
|
||||
co = dataInterface.getCon(true);
|
||||
UpdateToDb(co, cmd);
|
||||
co.Close();
|
||||
co = dataInterface.getConCentral(true);
|
||||
UpdateToDb(co, cmd);
|
||||
}
|
||||
catch (System.Exception ex)
|
||||
{
|
||||
Error = 1;
|
||||
ErrorMessage = ex.Message;
|
||||
}
|
||||
co?.Close();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue