using Oracle.ManagedDataAccess.Client; using System; using System.Collections.Generic; using System.Net; using System.Net.Http; using System.Text; using System.Threading.Tasks; using System.Web.Http; using Xylem.Common.Logic.ServiceCore; namespace Xylem.Common.Service.MeterProcessState.Controllers { [RoutePrefix("api/LuController")] public class LuController : ApiController { public static class GlobalConfig { public static Lazy connectionString = new Lazy(() => System.Configuration.ConfigurationManager.ConnectionStrings["default"].ConnectionString ); } [Route("GetNZDaten")] public async Task GetNZDaten(string Seriennumer = "") { try { using (var dataAccess = new SqlDataAccess(GlobalConfig.connectionString.Value)) { StringBuilder query = new StringBuilder(); query.AppendLine("SELECT TOP 1 * from Verbundzaehler where (Q1_SOLL is NULL) and (SerienNrNebenzaehler > 0 or KundeneigeneSerNrNbZ <> '') and (Herkunft is null or Herkunft <> 'M') and AnlageDatum > getdate() - 7 order by Datum desc "); var retDic = new List>(); var dt = dataAccess.ExecuteQuery(query.ToString()); foreach (var item in dt.Select()) { string strSQLOra; int lngSerial; string strSerial; double Q1; double Q2; double F1; double F2; lngSerial = (int)item["SerienNrNebenzaehler"]; strSerial = item["KundeneigeneSerNrNbZ"].ToString().Trim(); if (strSerial == "" && lngSerial > 0) { strSQLOra = "SELECT * FROM PRIMA_RO.DT01_LAATZEN WHERE ZAEHLERNUMMER ='" + lngSerial.ToString("00000000") + "'"; } else { if (strSerial != "") { //kundeneigenen NZ SerienNr ist bekannt strSQLOra = "SELECT * FROM PRIMA_RO.DT01_LAATZEN WHERE ZAEHLERNUMMER='" + strSerial.Replace(" ", "") + "' or ZAEHLERNUMMER='" + strSerial + "'"; } else { return Request.CreateResponse(HttpStatusCode.OK, await Task.Run(() => { return "ERROR 1#"; })); // ' weder kundeneigenen SerienNr noch numerische NZ SerienNr bekannt } } // create connection OracleConnection con = new OracleConnection(); // create connection string using builder OracleConnectionStringBuilder ocsb = new OracleConnectionStringBuilder(); ocsb.Password = "senspi2012"; ocsb.UserID = "prima_ro"; ocsb.DataSource = "//SLUORADB:1521/DT01"; // connect con.ConnectionString = ocsb.ConnectionString; con.Open(); OracleCommand command = con.CreateCommand(); command.CommandText = strSQLOra; OracleDataReader reader = command.ExecuteReader(); while (reader.Read()) { Q1 = ((double)reader["Q1_SOLL"]) / 1000; Q2 = ((double)reader["Q2_SOLL"]) / 1000; F1 = (double)reader["FEHLER_Q1"]; F2 = (double)reader["FEHLER_Q2"]; } } return Request.CreateResponse(HttpStatusCode.OK, await Task.Run(() => { return "store"; })); } } catch (Exception ex) { return Request.CreateResponse(HttpStatusCode.InternalServerError, ex.ToString() + "
" + ex.InnerException.ToString()); } } //connect //If Not rs.EOF Then // If lngSerial = 0 Then // StatusBar1.SimpleText = "LU: " & lngCount & "/" & ProgressBar1.Max & " " & strSerial & " " & Q1 & "=" & F1 & ", " & Q2 & " =" & F2 & " " & rsSQL("AnlageDatum") // Else // StatusBar1.SimpleText = "LU: " & lngCount & "/" & ProgressBar1.Max & " " & Format(lngSerial, "00000000") & " " & Q1 & "=" & F1 & ", " & Q2 & " =" & F2 & " " & rsSQL("AnlageDatum") // End If // 'Debug.Print Format(lngSerial, "00000000") & " " & Q1 & "=" & F1 & ", " & Q2 & " =" & F2 // DoEvents // If Not rsSQL Is Nothing Then // ' Reihenfolge wieder zurückgesetzt Q1 < Q2 2018-04-19 // If Q1 Tauschen // rsSQL("Q1_SOLL") = Q2 // rsSQL("FEHLER_Q1") = F2 // rsSQL("Q2_SOLL") = Q1 // rsSQL("FEHLER_Q2") = F1 // End If // Debug.Print rs("ZAEHLERNUMMER") // If Val(rsSQL("SerienNrNebenzaehlerLU") &"") = 0 And lngSerial > 0 Then // rsSQL("SerienNrNebenzaehlerLU") = lngSerial // End If // rsSQL("Herkunft") = "L" // rsSQL("ErgaenzungDatum") = Now // rsSQL.Update // Debug.Print lngCount &"/" & ProgressBar1.Max & " OK " & lngSerial & " / " & strSerial // End If //Else // StatusBar1.SimpleText = lngCount & "/" & ProgressBar1.Max & " unbekannte SNr: " & lngSerial & " / " & strSerial // Debug.Print StatusBar1.SimpleText & " " & Now // 'Debug.Print lngCount & "/" & ProgressBar1.Max & " unbekannt " & Format(lngSerial, "00000000") & " / " & strSerial // DoEvents // 'rsSQL("Q1_SOLL") = 0 // 'rsSQL("Herkunft") = "u" // 'rsSQL("Info") = "unbekannt in LU" // 'rsSQL.Update //End If //Exit Sub //Errorhandler: // Dim errnum As Long // Dim errdesc As String // errnum = Err.Number // errdesc = Err.Description // PrintStatus "Fehler " & errnum & " in Ergaenze(): " & errdesc & " SQL=" & strSQL //End Sub } }