private PumpStateModel1Model GetPumpStateModel1(PumpConnectionData pumpConnection)
        {
            var query     = $"select * from {pumpConnection.DatabaseNaming} where DateAndTime < (select max(DateAndTime) from {pumpConnection.DatabaseNaming})";
            var stateData = SQLHelper.Query(pumpConnection.ConnectionString, query).Tables[0];

            if (stateData.Rows.Count > 0)
            {
                var dr        = stateData.Rows[0];
                var pumpState = new PumpStateModel1Model();
                pumpState.PumpId         = pumpConnection.PumpId;
                pumpState.DateAndTime    = SQLHelper.TryGetValue <DateTime>(dr, "DateAndTime");
                pumpState.IndexNo        = SQLHelper.TryGetValue <int>(dr, "INDEX");
                pumpState.StatusGen      = SQLHelper.TryGetValue <bool?>(dr, "Status_Gen");
                pumpState.StatusMotor    = SQLHelper.TryGetValue <bool?>(dr, "Status_Motor");
                pumpState.StatusBarGen   = SQLHelper.TryGetValue <int?>(dr, "Status_Bar_Gen");
                pumpState.LEDGen         = SQLHelper.TryGetValue <bool?>(dr, "LED_Gen");
                pumpState.StatusBarMotor = SQLHelper.TryGetValue <int?>(dr, "Status_Bar_Motor");
                pumpState.LEDMotor       = SQLHelper.TryGetValue <bool?>(dr, "LED_Motor");
                pumpState.L1NGen         = SQLHelper.TryGetValue <double?>(dr, "L1_N_Gen");
                pumpState.L2NGen         = SQLHelper.TryGetValue <double?>(dr, "L2_N_Gen");
                pumpState.L3NGen         = SQLHelper.TryGetValue <double?>(dr, "L3_N_Gen");
                pumpState.TempGen        = SQLHelper.TryGetValue <double?>(dr, "Temp_Gen");
                pumpState.L1L2Gen        = SQLHelper.TryGetValue <double?>(dr, "L1_L2_Gen");
                pumpState.L2L3Gen        = SQLHelper.TryGetValue <double?>(dr, "L2_L3_Gen");
                pumpState.L3L1Gen        = SQLHelper.TryGetValue <double?>(dr, "L3_L1_Gen");
                pumpState.SpeedGen       = SQLHelper.TryGetValue <double?>(dr, "Speed_Gen");
                pumpState.Fuel           = SQLHelper.TryGetValue <double?>(dr, "Fuel");
                pumpState.Battery        = SQLHelper.TryGetValue <double?>(dr, "Battery");
                pumpState.Oil            = SQLHelper.TryGetValue <double?>(dr, "Oil");
                pumpState.Charge         = SQLHelper.TryGetValue <double?>(dr, "Charge");
                pumpState.FrequencyGen   = SQLHelper.TryGetValue <double?>(dr, "Frequency_Gen");
                pumpState.KWHGen         = SQLHelper.TryGetValue <double?>(dr, "kWh_Gen");
                pumpState.P1NMotor       = SQLHelper.TryGetValue <double?>(dr, "P1_N_Motor");
                pumpState.P2NMotor       = SQLHelper.TryGetValue <double?>(dr, "P2_N_Motor");
                pumpState.P3NMotor       = SQLHelper.TryGetValue <double?>(dr, "P3_N_Motor");
                pumpState.TempMotor      = SQLHelper.TryGetValue <double?>(dr, "Temp_Motor");
                pumpState.AmpL1          = SQLHelper.TryGetValue <double?>(dr, "Amp_L1");
                pumpState.AmpL2          = SQLHelper.TryGetValue <double?>(dr, "Amp_L2");
                pumpState.AmpL3          = SQLHelper.TryGetValue <double?>(dr, "Amp_L3");
                pumpState.SpeedMotor     = SQLHelper.TryGetValue <double?>(dr, "Speed_Motor");
                pumpState.Pressure       = SQLHelper.TryGetValue <double?>(dr, "Pressure");
                pumpState.Vibration      = SQLHelper.TryGetValue <double?>(dr, "Vibration");
                pumpState.Flow           = SQLHelper.TryGetValue <double?>(dr, "Flow");
                pumpState.FrequencyMotor = SQLHelper.TryGetValue <double?>(dr, "Frequency_Motor");
                pumpState.KWHMotor       = SQLHelper.TryGetValue <double?>(dr, "kWh_Motor");
                pumpState.TimeMTNHour    = SQLHelper.TryGetValue <double?>(dr, "Time_MTN_Hour");
                pumpState.TimeMTNMin     = SQLHelper.TryGetValue <double?>(dr, "Time_MTN_Min");
                pumpState.TimeMTNSec     = SQLHelper.TryGetValue <double?>(dr, "Time_MTN_Sec");
                pumpState.LEDIDELRate    = SQLHelper.TryGetValue <int?>(dr, "LED_IDEL_RATE");
                pumpState.KW1            = SQLHelper.TryGetValue <double?>(dr, "kW1");
                pumpState.KW2            = SQLHelper.TryGetValue <double?>(dr, "kW2");
                pumpState.KW3            = SQLHelper.TryGetValue <double?>(dr, "kW3");
                return(pumpState);
            }
            else
            {
                return(new PumpStateModel1Model());
            }
        }
 private async Task SendState(PumpConnectionData pump)
 {
     await Task.Run(() =>
     {
         if (pump.PumpModelCode == "Model1")
         {
             var state = GetPumpStateModel1(pump);
             connection.SendAsync("SendPumpStateModel1", state);
         }
         else if (pump.PumpModelCode == "Model2")
         {
             var state = GetPumpStateModel2(pump);
             connection.SendAsync("SendPumpStateModel2", state);
         }
     });
 }
        private PumpStateModel2Model GetPumpStateModel2(PumpConnectionData pumpConnection)
        {
            var query     = $"select * from {pumpConnection.DatabaseNaming} where DateAndTime < (select max(DateAndTime) from {pumpConnection.DatabaseNaming})";
            var stateData = SQLHelper.Query(pumpConnection.ConnectionString, query).Tables[0];

            if (stateData.Rows.Count > 0)
            {
                var dr        = stateData.Rows[0];
                var pumpState = new PumpStateModel2Model();
                pumpState.PumpId      = pumpConnection.PumpId;
                pumpState.DateAndTime = SQLHelper.TryGetValue <DateTime>(dr, "DateAndTime");
                pumpState.IndexNo     = SQLHelper.TryGetValue <int>(dr, "INDEX");
                pumpState.Status      = SQLHelper.TryGetValue <double?>(dr, "Status");
                pumpState.LEDEngine   = SQLHelper.TryGetValue <bool?>(dr, "LED_Engine");
                pumpState.StatusBar   = SQLHelper.TryGetValue <int?>(dr, "Status_Bar");
                pumpState.Speed       = SQLHelper.TryGetValue <double?>(dr, "Speed");
                pumpState.FuelLevel   = SQLHelper.TryGetValue <double?>(dr, "Fuel_Level");
                pumpState.Battery     = SQLHelper.TryGetValue <double?>(dr, "Battery");
                pumpState.OilPressure = SQLHelper.TryGetValue <double?>(dr, "Oil_Pressure");
                pumpState.Charge      = SQLHelper.TryGetValue <double?>(dr, "Charge");
                pumpState.Frequency   = SQLHelper.TryGetValue <double?>(dr, "Frequency");
                pumpState.KWh         = SQLHelper.TryGetValue <double?>(dr, "kWh");
                pumpState.Temperature = SQLHelper.TryGetValue <double?>(dr, "Temperature");
                pumpState.Pressure    = SQLHelper.TryGetValue <double?>(dr, "Pressure");
                pumpState.Vibration   = SQLHelper.TryGetValue <double?>(dr, "Vibration");
                pumpState.FlowMeter   = SQLHelper.TryGetValue <double?>(dr, "Flow_Meter");
                pumpState.TimeMTNHour = SQLHelper.TryGetValue <double?>(dr, "Time_MTN_Hour");
                pumpState.TimeMTNMin  = SQLHelper.TryGetValue <double?>(dr, "Time_MTN_Min");
                pumpState.TimeMTNSec  = SQLHelper.TryGetValue <double?>(dr, "Time_MTN_Sec");
                pumpState.LEDOffFuel  = SQLHelper.TryGetValue <double?>(dr, "LED_Off_Fuel");
                return(pumpState);
            }
            else
            {
                return(new PumpStateModel2Model());
            }
        }