public Atc GetAtcById(int id) { List <DbParameter> _parametros = new List <DbParameter>(); // Definição do parâmetros da consulta: SqlParameter pid = new SqlParameter() { ParameterName = "@id", Value = id }; _parametros.Add(pid); // Fim da definição dos parâmetros query = @"SELECT AtcId, Nome, UF, NomePres, NomeVPres, NomePSec, NomeSSec, NomePTes, NomeSTes, Site, SiteDiretoria, Ativo, Codigo FROM dbo.AD_ATC WHERE AtcId = @id"; // Define o banco de dados que será usando: CommandSql cmd = new CommandSql(strConnSql, query, EnumDatabaseType.SqlServer, parametros: _parametros); // Obtém os dados do banco de dados: Atc atc = GetCollection <Atc>(cmd)?.FirstOrDefault <Atc>(); return(atc); }
private void UpdateAtcs(Snapshot snapshot, Root jsonData) { snapshot.Atcs.Clear(); foreach (var item in jsonData.controllers) { Atc atc = BuildAtc(item); snapshot.Atcs.Add(atc); } }
public Atc SetAtc() { Atc _a = new Atc() { AtcId = 0, Nome = "", UF = "", Ativo = true, Codigo = 0 }; return(_a); }
private static Atc BuildAtc(Model.Back.Vatsim.JsonModel.Controller item) { Atc ret = new Atc() { Callsign = item.callsign, Frequency = item.frequency, Name = item.name }; return(ret); }
// --- コンストラクタ --- /// <summary>新しいインスタンスを作成する</summary> /// <param name="panel">パネルに渡す値</param> /// <param name="playSound">サウンドを再生するためのデリゲート</param> internal Train(int[] panel, PlaySoundDelegate playSound) { this.PluginInitializing = false; this.Specs = new VehicleSpecs(0, BrakeTypes.ElectromagneticStraightAirBrake, 0, false, 0); this.State = new VehicleState(0.0, new Speed(0.0), 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0); this.Handles = new ReadOnlyHandles(new Handles(0, 0, 0, false)); this.Doors = DoorStates.None; this.Panel = panel; this.Sounds = new Sounds(playSound); this.Accel = new Accel(); this.Atc = new Atc(this); this.AtsP = new AtsP(this); this.Sub = new Sub(this); this.Devices = new Device[] { this.Accel, this.Atc, this.AtsP, this.Sub }; }
public string Save(Atc a) { ArgumentsValidator.RaiseExceptionOfInvalidArguments( RaiseException.IfNullOrEmpty(a.Nome, "Nome da ATC não informado"), RaiseException.IfNullOrEmpty(a.NomePres, "Nome do Presidente não informado") ); Atc _a = new Atc() { AtcId = a.AtcId, Nome = Functions.AjustaTamanhoString(a.Nome, 100), UF = Functions.AjustaTamanhoString(a.UF, 2), NomePres = Functions.AjustaTamanhoString(a.NomePres, 100), NomeVPres = Functions.AjustaTamanhoString(a.NomeVPres, 100), NomePSec = Functions.AjustaTamanhoString(a.NomePSec, 100), NomeSSec = Functions.AjustaTamanhoString(a.NomeSSec, 100), NomePTes = Functions.AjustaTamanhoString(a.NomePTes, 100), NomeSTes = Functions.AjustaTamanhoString(a.NomeSTes, 100), Site = Functions.AjustaTamanhoString(a.Site, 100), SiteDiretoria = Functions.AjustaTamanhoString(a.SiteDiretoria, 100), Ativo = a.Ativo, Codigo = a.Codigo }; try { if (_a.AtcId == 0) { return(_atcService.Insert(_a)); } else { return(_atcService.Update(a.AtcId, _a)); } } catch (Exception ex) { throw ex; } }
public string ToString(string strChiaveRecord) { string str = ""; string strDataPrescrizione = " "; if (this.DataPrescrizione != null) { DateTime dtTemp = (DateTime)this.DataPrescrizione; strDataPrescrizione = dtTemp.ToString("yyyyMMdd"); } str += CodiceTargatura.PadRight(10, ' '); str += PeriodoCompetenza.PadRight(6, ' '); str += CodiceRegionale.PadRight(10, ' '); str += CodiceRicetta.PadRight(10, ' '); str += ProgressivoRicetta.ToString("00000"); str += Provincia.PadRight(2, ' '); str += Minsan.PadRight(9, ' '); str += Quantita.ToString("0000"); str += Prodotto.PadRight(60, ' '); str += PrincipioAttivo.PadRight(100, ' '); str += Atc.PadRight(7, ' '); // 217 + 7 str += PrezzoLordo.ToString("0000000000"); // 224 +10 str += PrezzoNetto.ToString("0000000000"); // 234 +10 str += ImportoCompenso.ToString("0000000000"); // 244 +10 str += prezzoAcquisto.ToString("0000000000"); // 254 +10 str += DataChiusura.ToString("yyyyMMdd"); str += CodiceFarmaciaAsl.PadRight(10, ' '); // 272 + 10 str += PercentualeCompenso.ToString("00000"); // 282 + 5 str += UnitaPosologiche.ToString("00000"); str += strDataPrescrizione; // 292 + 8 str += CompensoPerPezzo.ToString("0000000000"); // 300 + 10 str += new string(' ', 179); str += strChiaveRecord.PadLeft(16, '0'); // 489+16 str += terminatore; return(str); }
public Task <HttpResponseMessage> Post(Atc atc) { HttpResponseMessage response = new HttpResponseMessage(); var tsc = new TaskCompletionSource <HttpResponseMessage>(); string resultado = "false"; try { if (atc == null) { throw new ArgumentNullException("O objeto 'Atc' está nulo!"); } resultado = _atcApplication.Save(atc); response = Request.CreateResponse(HttpStatusCode.OK, resultado); response.ReasonPhrase = resultado; tsc.SetResult(response); return(tsc.Task); } catch (Exception ex) { if (ex.GetType().Name == "InvalidOperationException" || ex.Source == "prmToolkit.Validation") { response = Request.CreateResponse(HttpStatusCode.NotFound); response.ReasonPhrase = ex.Message; } else { response = Request.CreateResponse(HttpStatusCode.BadRequest, ex.Message); } tsc.SetResult(response); return(tsc.Task); } }
public async Task <HttpResponseMessage> SetLocationUpdates() { int responseVal = 0; string responseText = "OK"; bool error = false; var rawContent = await Request.Content.ReadAsStringAsync(); #region Method Specific Variables Users requesterUser = default; var parameters = new { AccessToken = default(string), LocationList = new[] { new { Latitude = default(string), Longitude = default(string), Altitude = default(string), Speed = default(string), Accuracy = default(string), Date = default(string) } }.ToList() }; #endregion #region Parameter Controls try { parameters = JsonConvert.DeserializeAnonymousType(rawContent, parameters); } catch { responseVal = 4; responseText = TruckGo.WarningDictionary[4]; error = true; } if (!error) { string lastControl = default; decimal lat, lon, alt, speed; try { lastControl = nameof(parameters.AccessToken); if (string.IsNullOrWhiteSpace(parameters.AccessToken)) { throw new Exception(); } foreach (var eachData in parameters.LocationList) { lastControl = nameof(eachData.Latitude); lat = Convert.ToDecimal(eachData.Latitude.ToString().Replace(".", ",")); lastControl = nameof(eachData.Longitude); lon = Convert.ToDecimal(eachData.Longitude.ToString().Replace(".", ",")); lastControl = nameof(eachData.Altitude); alt = Convert.ToDecimal(eachData.Altitude.ToString().Replace(".", ",")); lastControl = nameof(eachData.Speed); speed = Convert.ToDecimal(eachData.Speed.ToString().Replace(".", ",")); lastControl = nameof(eachData.Accuracy); if (string.IsNullOrEmpty(eachData.Accuracy)) { throw new Exception(); } lastControl = nameof(eachData.Date); if (string.IsNullOrWhiteSpace(eachData.Date)) { throw new Exception(); } var trial = Convert.ToDateTime(eachData.Date); } } catch { responseVal = 8; responseText = TruckGo.WarningDictionary[8].Replace("Parameter", lastControl); error = true; } } #endregion #region Main Process if (!error) { using (TruckGoEntities db = new TruckGoEntities()) { requesterUser = await TruckGo.GetUserByAccessToken(parameters.AccessToken, db); if (requesterUser == null) { responseVal = 2; responseText = TruckGo.WarningDictionary[2]; error = true; } if (!error) { var activeVehicle = await db.Vehicles.FirstOrDefaultAsync(vehicle => vehicle.UserID == requesterUser.UserID && vehicle.State); if (activeVehicle == null) { responseVal = 9; responseText = TruckGo.WarningDictionary[9]; error = true; } else { var lastLocation = await db.Atc.OrderByDescending(atc => atc.Date).FirstOrDefaultAsync(atc => atc.VehicleID == activeVehicle.VehicleID); foreach (var eachData in parameters.LocationList) { bool insert = false; decimal angle = 0; if (lastLocation == null) { insert = true; } else { if (TruckGo.DistanceCalculator( Convert.ToDouble(eachData.Latitude.Replace(".", ",")), Convert.ToDouble(eachData.Longitude.Replace(".", ",")), Convert.ToDouble(lastLocation.Latitude.Replace(".", ",")), Convert.ToDouble(lastLocation.Longitude.Replace(".", ","))) >= 0.05) { insert = true; } angle = (int)TruckGo.AngleFromCoordinate( Convert.ToDouble(lastLocation.Latitude.Replace(".", ",")), Convert.ToDouble(lastLocation.Longitude.Replace(".", ",")), Convert.ToDouble(eachData.Latitude.Replace(".", ",")), Convert.ToDouble(eachData.Longitude.Replace(".", ","))); } if (insert) { Atc newLocation = new Atc { VehicleID = activeVehicle.VehicleID, Accuracy = eachData.Accuracy, Altitude = eachData.Altitude, Angle = angle, Latitude = eachData.Latitude.Replace(",", "."), Longitude = eachData.Longitude.Replace(",", "."), Speed = Convert.ToDecimal(eachData.Speed), Date = Convert.ToDateTime(eachData.Date), CreateDate = DateTime.Now }; db.Atc.Add(newLocation); } } await db.SaveChangesAsync(); } } } } #endregion string responseString = JsonConvert.SerializeObject(new { responseVal, responseText }); return(new HttpResponseMessage { Content = new StringContent(responseString) }); }
public string Insert(Atc atc) { bool _resultado = false; string _msg = ""; Int32 id = 0; string _ident = ""; using (SqlConnection connection = new SqlConnection(strConnSql)) { connection.Open(); SqlCommand command = connection.CreateCommand(); SqlTransaction transaction; // Start a local transaction. transaction = connection.BeginTransaction("IncluirATC"); command.Connection = connection; command.Transaction = transaction; try { command.CommandText = "" + "INSERT into dbo.AD_ATC (Nome, UF, NomePres, NomeVPres, NomePSec, NomeSSec, " + " NomePTes, NomeSTes, Site, SiteDiretoria, Codigo) " + "VALUES(@Nome, @UF, @NomePres, @NomeVPres, @NomePSec, @NomeSSec, " + " @NomePTes, @NomeSTes, @Site, @SiteDiretoria, @Codigo) " + "SELECT CAST(scope_identity() AS int) "; command.Parameters.AddWithValue("Nome", atc.Nome); command.Parameters.AddWithValue("UF", atc.UF); command.Parameters.AddWithValue("NomePres", atc.NomePres); command.Parameters.AddWithValue("NomeVPres", atc.NomeVPres); command.Parameters.AddWithValue("NomePSec", atc.NomePSec); command.Parameters.AddWithValue("NomeSSec", atc.NomeSSec); command.Parameters.AddWithValue("NomePTes", atc.NomePTes); command.Parameters.AddWithValue("NomeSTes", atc.NomeSTes); command.Parameters.AddWithValue("Site", atc.Site); command.Parameters.AddWithValue("SiteDiretoria", atc.SiteDiretoria); command.Parameters.AddWithValue("Codigo", atc.Codigo); id = (Int32)command.ExecuteScalar(); _resultado = id > 0; if (id > 0) { _ident = _ident.PadLeft(10 - id.ToString().Length, '0') + id.ToString(); } _msg = id > 0 ? $"{_ident}Inclusão realizada com sucesso" : $"{_ident}Inclusão Não realizada com sucesso"; transaction.Commit(); } catch (Exception ex) { // Attempt to roll back the transaction. try { transaction.Rollback(); } catch (Exception ex2) { throw new Exception($"Rollback Exception Type:{ex2.GetType()}. Erro:{ex2.Message}"); } throw new Exception($"Commit Exception Type:{ex.GetType()}. Erro:{ex.Message}"); } finally { connection.Close(); } } return(_msg); }
public string Update(int id, Atc atc) { bool _resultado = false; string _msg = ""; using (SqlConnection connection = new SqlConnection(strConnSql)) { connection.Open(); SqlCommand command = connection.CreateCommand(); SqlTransaction transaction; // Start a local transaction. transaction = connection.BeginTransaction("AtualizarATC"); command.Connection = connection; command.Transaction = transaction; try { command.CommandText = "" + "UPDATE dbo.AD_Atc " + "SET Nome = @Nome, UF = @UF, NomePres = @NomePres, NomeVPres = @NomeVPres, " + " NomePSec = @NomePSec, NomeSSec = @NomeSSec, NomePTes = @NomePTes, " + " NomeSTes = @NomeSTes, Site = @Site, SiteDiretoria = @SiteDiretoria, " + " Codigo = @Codigo, Ativo = @Ativo " + "WHERE AtcId = @id"; command.Parameters.AddWithValue("Nome", atc.Nome); command.Parameters.AddWithValue("UF", atc.UF); command.Parameters.AddWithValue("NomePres", atc.NomePres); command.Parameters.AddWithValue("NomeVPres", atc.NomeVPres); command.Parameters.AddWithValue("NomePSec", atc.NomePSec); command.Parameters.AddWithValue("NomeSSec", atc.NomeSSec); command.Parameters.AddWithValue("NomePTes", atc.NomePTes); command.Parameters.AddWithValue("NomeSTes", atc.NomeSTes); command.Parameters.AddWithValue("Site", atc.Site); command.Parameters.AddWithValue("SiteDiretoria", atc.SiteDiretoria); command.Parameters.AddWithValue("Codigo", atc.Codigo); command.Parameters.AddWithValue("Ativo", atc.Ativo); command.Parameters.AddWithValue("id", id); int x = command.ExecuteNonQuery(); _resultado = x > 0; _msg = x > 0 ? "Atualização realizada com sucesso" : "Atualização NÃO realizada com sucesso"; transaction.Commit(); } catch (Exception ex) { try { transaction.Rollback(); } catch (Exception ex2) { throw new Exception($"Rollback Exception Type:{ex2.GetType()}. Erro:{ex2.Message}"); } throw new Exception($"Commit Exception Type:{ex.GetType()}. Erro:{ex.Message}"); } finally { connection.Close(); } } return(_msg); }
public string Update(int id, Atc atc) { return(_atcRepository.Update(id, atc)); }
public string Insert(Atc atc) { return(_atcRepository.Insert(atc)); }