private double CalculateDistance(GPSRecord start, GPSRecord end) { var sCoord = new GeoCoordinate(start.Latitude, start.Longitude); var eCoord = new GeoCoordinate(end.Latitude, end.Longitude); return(sCoord.GetDistanceTo(eCoord)); //meterben adja vissza }
public async Task <ActionResult <GPSRecord> > PostGPSRecord(GPSRecord gPSRecord) { var result = await _gpsRecordRepository.PostGPSRecord(gPSRecord); //Publish to RabbitMQ // var eventMessage = new GPSRecordIntegrationEvent(Guid.NewGuid(), // gPSRecord.GPSRecordId, // gPSRecord.GpsSerialNumber, // gPSRecord.Latitude, // gPSRecord.Longitude, // gPSRecord.Fuel, // gPSRecord.Speed, // gPSRecord.CreateDate, // gPSRecord.CreateBy // ); // try // { // _eventBus.Publish(eventMessage); // } // catch (Exception ex) // { // _logger.LogError(ex, "ERROR Publishing integration event: {IntegrationEventId} from {AppName}", eventMessage.GPSRecordId,"GPSRecordController"); // throw; // } return(gPSRecord); }
/// <summary> /// 更新数据 /// </summary> /// <param name='model'>实体</param> /// <returns>bool</returns> public bool Update(GPSRecord model) { bool result = false; var e = new ModelExceptions(); int _rseult = instance.Update(model); if (_rseult > 0) { result = true; } return(result); }
public GPSRecord GetMax(string car) { var list = instance.GetMax(car); GPSRecord model = new GPSRecord(); if (list.Count > 0) { model = list[0]; } else { model = null; } return(model); }
/// <summary> /// 获取实体数据 /// </summary> /// <param name='strCondition'>条件(AND Code='11')</param> /// <returns>model</returns> public GPSRecord GetModel(string strCondition) { List <GPSRecord> list = instance.GetListByWhere(strCondition); GPSRecord model = new GPSRecord(); if (list != null && list.Count > 0) { model = list[0]; } else { model = null; } return(model); }
/// <summary> /// 插入数据 /// </summary> /// <param name='model'>实体</param> /// <param name='model'>是否完成验证</param> /// <returns>bool</returns> public bool Insert(GPSRecord model, bool IsValid) { var e = new ModelExceptions(); bool result = false; if (e.IsValid && IsValid) { //完成了验证,开始更新数据库了 int _result = instance.Add(model); if (_result > 0) { result = true; } } return(result); }
/// <summary> /// 逻辑删除数据 /// </summary> /// <param name='model'>model</param> /// <returns>bool</returns> public bool Delete(string Condition) { bool result = false; List <GPSRecord> list = instance.GetListByWhere(Condition); if (list.Count > 0) { GPSRecord model = list[0]; model.Stat = 1; int _rseult = instance.Update(model); if (_rseult > 0) { result = true; } } return(result); }
public double getAngle(out DateTime dt) { GPSRecord record; do { string sRecord = m_gpsFileReader.ReadLine(); if (sRecord == "" || sRecord == null) { dt = new DateTime(); return double.MinValue; } record = parseRecord(sRecord); } while (record == m_lastRecord); dt = record.dt; double angle = countDir(m_lastRecord, record); m_lastRecord=record; return angle; }
/// <summary> /// 插入数据 /// </summary> /// <param name='model'>实体</param> /// <returns>bool</returns> public bool Insert(GPSRecord model) { bool result = false; try { int _result = instance.Add(model); if (_result > 0) { result = true; } } catch (Exception ex) { throw ex; } return(result); }
public GPSAngle(string gpsFileName) { try { m_gpsFileReader = new StreamReader(gpsFileName); } catch (IOException e) { Console.WriteLine(e.Message); } GPSRecord tempRecord = new GPSRecord("2012/1/1", 0, 0); do { string sRecord=m_gpsFileReader.ReadLine(); tempRecord = parseRecord(sRecord); } while (tempRecord.latitude==0&&tempRecord.longitude==0); m_lastRecord = tempRecord; }
public void ParseString(string line, Flight flight) { if (line.StartsWith("HFDTE")) { string datestr1 = line.Substring(5, 4); string datestr2 = line.Substring(9, 2); string datestr = datestr1 + "20" + datestr2; flight.Date = DateTime.ParseExact(datestr, "ddMMyyyy", CultureInfo.InvariantCulture); } else if (line.StartsWith("B")) { GPSRecord record = new GPSRecord(); string datestring = line.Substring(1, 6); string latitudestring = line.Substring(7, 7); string longitudestring = line.Substring(15, 8); string altitudestring = line.Substring(25, 5); record.TimeStamp = DateTime.ParseExact(datestring, "HHmmss", CultureInfo.InvariantCulture); //// double deg = Convert.ToDouble(latitudestring.Substring(0, 2)); double wholemin = Convert.ToDouble(latitudestring.Substring(2, 2)); double fracmin = Convert.ToDouble(latitudestring.Substring(4, 3)); double fraction = (wholemin + fracmin / 1000) / 60; double latitude = deg + fraction; record.Latitude = latitude; //// double deg2 = Convert.ToDouble(longitudestring.Substring(0, 3)); double wholemin2 = Convert.ToDouble(longitudestring.Substring(3, 2)); double fracmin2 = Convert.ToDouble(longitudestring.Substring(5, 3)); var fraction2 = (wholemin2 + fracmin2 / 1000) / 60; var longitude = deg2 + fraction2; record.Longitude = longitude; record.Altitude = Convert.ToInt32(altitudestring); //méter record.Flight = flight; flight.GPSRecords.Add(record); //elmentem egy listába } }
private double countDir(GPSRecord r1, GPSRecord r2) { double width, height,angle; if (r1.latitude == r2.latitude && r1.longitude == r2.longitude) return -1; height = (r2.latitude - r1.latitude) * Math.PI * GeneralTool.RADIUS_A / 180; double tempCos = Math.Pow(Math.Sin(ToRad(r2.latitude)), 2) + Math.Cos(ToRad(r2.longitude - r1.longitude)) * Math.Pow(Math.Cos(ToRad(r2.latitude)), 2); tempCos = Math.Abs(tempCos); width = Math.Acos(tempCos) * GeneralTool.RADIUS_A; angle = Math.Atan2(height, width)*180/Math.PI; if (r1.longitude > r2.longitude) angle = 180 - angle; else if (angle < 0) angle += 360; return angle; }
public List <GPSRecord> GetMax(string car) { List <GPSRecord> ret = new List <GPSRecord>(); string sql = "SELECT top 1 Record_ID,License_Plate,Terminal_ID,PlateColor,DataType,GPSTime,Longitude,Latitude,GPSFlag,Speed,Direction,Comm_Type,MDTStatus,MDTAlarm,Data_Length,DataContend,Stat,CreateTime FROM GPSRecord where 1=1 AND ((Stat is null) or (Stat=0) ) and License_Plate='" + car + "' ORDER BY Record_ID desc "; SqlDataReader dr = null; try { dr = (SqlDataReader)idb.ReturnReader(sql); while (dr.Read()) { GPSRecord gPSRecord = new GPSRecord(); if (dr["Record_ID"] != DBNull.Value) { gPSRecord.Record_ID = Convert.ToDecimal(dr["Record_ID"]); } if (dr["License_Plate"] != DBNull.Value) { gPSRecord.License_Plate = Convert.ToString(dr["License_Plate"]); } if (dr["Terminal_ID"] != DBNull.Value) { gPSRecord.Terminal_ID = Convert.ToString(dr["Terminal_ID"]); } if (dr["PlateColor"] != DBNull.Value) { gPSRecord.PlateColor = Convert.ToInt32(dr["PlateColor"]); } if (dr["DataType"] != DBNull.Value) { gPSRecord.DataType = Convert.ToInt32(dr["DataType"]); } if (dr["GPSTime"] != DBNull.Value) { gPSRecord.GPSTime = Convert.ToDateTime(dr["GPSTime"]); } if (dr["Longitude"] != DBNull.Value) { gPSRecord.Longitude = Convert.ToDecimal(dr["Longitude"]); } if (dr["Latitude"] != DBNull.Value) { gPSRecord.Latitude = Convert.ToDecimal(dr["Latitude"]); } if (dr["GPSFlag"] != DBNull.Value) { gPSRecord.GPSFlag = Convert.ToInt32(dr["GPSFlag"]); } if (dr["Speed"] != DBNull.Value) { gPSRecord.Speed = Convert.ToInt32(dr["Speed"]); } if (dr["Direction"] != DBNull.Value) { gPSRecord.Direction = Convert.ToInt32(dr["Direction"]); } if (dr["Comm_Type"] != DBNull.Value) { gPSRecord.Comm_Type = Convert.ToInt32(dr["Comm_Type"]); } if (dr["MDTStatus"] != DBNull.Value) { gPSRecord.MDTStatus = Convert.ToInt32(dr["MDTStatus"]); } if (dr["MDTAlarm"] != DBNull.Value) { gPSRecord.MDTAlarm = Convert.ToInt32(dr["MDTAlarm"]); } if (dr["Data_Length"] != DBNull.Value) { gPSRecord.Data_Length = Convert.ToInt32(dr["Data_Length"]); } if (dr["DataContend"] != DBNull.Value) { gPSRecord.DataContend = Convert.ToString(dr["DataContend"]); } if (dr["Stat"] != DBNull.Value) { gPSRecord.Stat = Convert.ToInt32(dr["Stat"]); } if (dr["CreateTime"] != DBNull.Value) { gPSRecord.CreateTime = Convert.ToDateTime(dr["CreateTime"]); } ret.Add(gPSRecord); } } catch (System.Exception ex) { throw ex; } finally { if (dr != null) { dr.Close(); } if (idb.GetConnection() != null && idb.GetConnection().State == ConnectionState.Open) { idb.GetConnection().Close(); } } return(ret); }
/// <summary> /// 获取指定的GPSRecord对象(即:一条记录 /// </summary> public GPSRecord GetByKey(decimal record_ID) { GPSRecord gPSRecord = new GPSRecord(); string sql = "SELECT Record_ID,License_Plate,Terminal_ID,PlateColor,DataType,GPSTime,Longitude,Latitude,GPSFlag,Speed,Direction,Comm_Type,MDTStatus,MDTAlarm,Data_Length,DataContend,Stat,CreateTime FROM GPSRecord WHERE 1=1 AND ((Stat is null) or (Stat=0) ) AND Record_ID=@Record_ID "; idb.AddParameter("@Record_ID", record_ID); SqlDataReader dr = null; try { dr = (SqlDataReader)idb.ReturnReader(sql); while (dr.Read()) { if (dr["Record_ID"] != DBNull.Value) { gPSRecord.Record_ID = Convert.ToDecimal(dr["Record_ID"]); } if (dr["License_Plate"] != DBNull.Value) { gPSRecord.License_Plate = Convert.ToString(dr["License_Plate"]); } if (dr["Terminal_ID"] != DBNull.Value) { gPSRecord.Terminal_ID = Convert.ToString(dr["Terminal_ID"]); } if (dr["PlateColor"] != DBNull.Value) { gPSRecord.PlateColor = Convert.ToInt32(dr["PlateColor"]); } if (dr["DataType"] != DBNull.Value) { gPSRecord.DataType = Convert.ToInt32(dr["DataType"]); } if (dr["GPSTime"] != DBNull.Value) { gPSRecord.GPSTime = Convert.ToDateTime(dr["GPSTime"]); } if (dr["Longitude"] != DBNull.Value) { gPSRecord.Longitude = Convert.ToDecimal(dr["Longitude"]); } if (dr["Latitude"] != DBNull.Value) { gPSRecord.Latitude = Convert.ToDecimal(dr["Latitude"]); } if (dr["GPSFlag"] != DBNull.Value) { gPSRecord.GPSFlag = Convert.ToInt32(dr["GPSFlag"]); } if (dr["Speed"] != DBNull.Value) { gPSRecord.Speed = Convert.ToInt32(dr["Speed"]); } if (dr["Direction"] != DBNull.Value) { gPSRecord.Direction = Convert.ToInt32(dr["Direction"]); } if (dr["Comm_Type"] != DBNull.Value) { gPSRecord.Comm_Type = Convert.ToInt32(dr["Comm_Type"]); } if (dr["MDTStatus"] != DBNull.Value) { gPSRecord.MDTStatus = Convert.ToInt32(dr["MDTStatus"]); } if (dr["MDTAlarm"] != DBNull.Value) { gPSRecord.MDTAlarm = Convert.ToInt32(dr["MDTAlarm"]); } if (dr["Data_Length"] != DBNull.Value) { gPSRecord.Data_Length = Convert.ToInt32(dr["Data_Length"]); } if (dr["DataContend"] != DBNull.Value) { gPSRecord.DataContend = Convert.ToString(dr["DataContend"]); } if (dr["Stat"] != DBNull.Value) { gPSRecord.Stat = Convert.ToInt32(dr["Stat"]); } if (dr["CreateTime"] != DBNull.Value) { gPSRecord.CreateTime = Convert.ToDateTime(dr["CreateTime"]); } } }catch (System.Exception ex) { throw ex; } finally { if (dr != null) { dr.Close(); } if (idb.GetConnection() != null && idb.GetConnection().State == ConnectionState.Open) { idb.GetConnection().Close(); } } return(gPSRecord); }
/// <summary> /// 更新GPSRecord对象(即:一条记录 /// </summary> public int Update(GPSRecord gPSRecord) { StringBuilder sbParameter = new StringBuilder(); StringBuilder sb = new StringBuilder(); sb.Append(@"UPDATE GPSRecord SET "); if (gPSRecord.License_Plate_IsChanged) { sbParameter.Append("License_Plate=@License_Plate, "); } if (gPSRecord.Terminal_ID_IsChanged) { sbParameter.Append("Terminal_ID=@Terminal_ID, "); } if (gPSRecord.PlateColor_IsChanged) { sbParameter.Append("PlateColor=@PlateColor, "); } if (gPSRecord.DataType_IsChanged) { sbParameter.Append("DataType=@DataType, "); } if (gPSRecord.GPSTime_IsChanged) { sbParameter.Append("GPSTime=@GPSTime, "); } if (gPSRecord.Longitude_IsChanged) { sbParameter.Append("Longitude=@Longitude, "); } if (gPSRecord.Latitude_IsChanged) { sbParameter.Append("Latitude=@Latitude, "); } if (gPSRecord.GPSFlag_IsChanged) { sbParameter.Append("GPSFlag=@GPSFlag, "); } if (gPSRecord.Speed_IsChanged) { sbParameter.Append("Speed=@Speed, "); } if (gPSRecord.Direction_IsChanged) { sbParameter.Append("Direction=@Direction, "); } if (gPSRecord.Comm_Type_IsChanged) { sbParameter.Append("Comm_Type=@Comm_Type, "); } if (gPSRecord.MDTStatus_IsChanged) { sbParameter.Append("MDTStatus=@MDTStatus, "); } if (gPSRecord.MDTAlarm_IsChanged) { sbParameter.Append("MDTAlarm=@MDTAlarm, "); } if (gPSRecord.Data_Length_IsChanged) { sbParameter.Append("Data_Length=@Data_Length, "); } if (gPSRecord.DataContend_IsChanged) { sbParameter.Append("DataContend=@DataContend, "); } if (gPSRecord.Stat_IsChanged) { sbParameter.Append("Stat=@Stat, "); } if (gPSRecord.CreateTime_IsChanged) { sbParameter.Append("CreateTime=@CreateTime "); } sb.Append(sbParameter.ToString().Trim().TrimEnd(',')); sb.Append(" WHERE 1=1 AND ((Stat is null) or (Stat=0)) and Record_ID=@Record_ID; "); string sql = sb.ToString(); if (gPSRecord.License_Plate_IsChanged) { if (string.IsNullOrEmpty(gPSRecord.License_Plate)) { idb.AddParameter("@License_Plate", DBNull.Value); } else { idb.AddParameter("@License_Plate", gPSRecord.License_Plate); } } if (gPSRecord.Terminal_ID_IsChanged) { if (string.IsNullOrEmpty(gPSRecord.Terminal_ID)) { idb.AddParameter("@Terminal_ID", DBNull.Value); } else { idb.AddParameter("@Terminal_ID", gPSRecord.Terminal_ID); } } if (gPSRecord.PlateColor_IsChanged) { if (gPSRecord.PlateColor == 0) { idb.AddParameter("@PlateColor", 0); } else { idb.AddParameter("@PlateColor", gPSRecord.PlateColor); } } if (gPSRecord.DataType_IsChanged) { if (gPSRecord.DataType == 0) { idb.AddParameter("@DataType", 0); } else { idb.AddParameter("@DataType", gPSRecord.DataType); } } if (gPSRecord.GPSTime_IsChanged) { if (gPSRecord.GPSTime == DateTime.MinValue) { idb.AddParameter("@GPSTime", DBNull.Value); } else { idb.AddParameter("@GPSTime", gPSRecord.GPSTime); } } if (gPSRecord.Longitude_IsChanged) { if (gPSRecord.Longitude == 0) { idb.AddParameter("@Longitude", 0); } else { idb.AddParameter("@Longitude", gPSRecord.Longitude); } } if (gPSRecord.Latitude_IsChanged) { if (gPSRecord.Latitude == 0) { idb.AddParameter("@Latitude", 0); } else { idb.AddParameter("@Latitude", gPSRecord.Latitude); } } if (gPSRecord.GPSFlag_IsChanged) { if (gPSRecord.GPSFlag == 0) { idb.AddParameter("@GPSFlag", 0); } else { idb.AddParameter("@GPSFlag", gPSRecord.GPSFlag); } } if (gPSRecord.Speed_IsChanged) { if (gPSRecord.Speed == 0) { idb.AddParameter("@Speed", 0); } else { idb.AddParameter("@Speed", gPSRecord.Speed); } } if (gPSRecord.Direction_IsChanged) { if (gPSRecord.Direction == 0) { idb.AddParameter("@Direction", 0); } else { idb.AddParameter("@Direction", gPSRecord.Direction); } } if (gPSRecord.Comm_Type_IsChanged) { if (gPSRecord.Comm_Type == 0) { idb.AddParameter("@Comm_Type", 0); } else { idb.AddParameter("@Comm_Type", gPSRecord.Comm_Type); } } if (gPSRecord.MDTStatus_IsChanged) { if (gPSRecord.MDTStatus == 0) { idb.AddParameter("@MDTStatus", 0); } else { idb.AddParameter("@MDTStatus", gPSRecord.MDTStatus); } } if (gPSRecord.MDTAlarm_IsChanged) { if (gPSRecord.MDTAlarm == 0) { idb.AddParameter("@MDTAlarm", 0); } else { idb.AddParameter("@MDTAlarm", gPSRecord.MDTAlarm); } } if (gPSRecord.Data_Length_IsChanged) { if (gPSRecord.Data_Length == 0) { idb.AddParameter("@Data_Length", 0); } else { idb.AddParameter("@Data_Length", gPSRecord.Data_Length); } } if (gPSRecord.DataContend_IsChanged) { if (string.IsNullOrEmpty(gPSRecord.DataContend)) { idb.AddParameter("@DataContend", DBNull.Value); } else { idb.AddParameter("@DataContend", gPSRecord.DataContend); } } if (gPSRecord.Stat_IsChanged) { if (gPSRecord.Stat == 0) { idb.AddParameter("@Stat", 0); } else { idb.AddParameter("@Stat", gPSRecord.Stat); } } if (gPSRecord.CreateTime_IsChanged) { if (gPSRecord.CreateTime == DateTime.MinValue) { idb.AddParameter("@CreateTime", DBNull.Value); } else { idb.AddParameter("@CreateTime", gPSRecord.CreateTime); } } idb.AddParameter("@Record_ID", gPSRecord.Record_ID); return(idb.ExeCmd(sql)); }
/// <summary> /// 添加GPSRecord对象(即:一条记录) /// </summary> public int Add(GPSRecord gPSRecord) { string sql = "INSERT INTO GPSRecord (License_Plate,Terminal_ID,PlateColor,DataType,GPSTime,Longitude,Latitude,GPSFlag,Speed,Direction,Comm_Type,MDTStatus,MDTAlarm,Data_Length,DataContend,Stat,CreateTime) VALUES (@License_Plate,@Terminal_ID,@PlateColor,@DataType,@GPSTime,@Longitude,@Latitude,@GPSFlag,@Speed,@Direction,@Comm_Type,@MDTStatus,@MDTAlarm,@Data_Length,@DataContend,@Stat,@CreateTime)"; if (string.IsNullOrEmpty(gPSRecord.License_Plate)) { idb.AddParameter("@License_Plate", DBNull.Value); } else { idb.AddParameter("@License_Plate", gPSRecord.License_Plate); } if (string.IsNullOrEmpty(gPSRecord.Terminal_ID)) { idb.AddParameter("@Terminal_ID", DBNull.Value); } else { idb.AddParameter("@Terminal_ID", gPSRecord.Terminal_ID); } if (gPSRecord.PlateColor == 0) { idb.AddParameter("@PlateColor", 0); } else { idb.AddParameter("@PlateColor", gPSRecord.PlateColor); } if (gPSRecord.DataType == 0) { idb.AddParameter("@DataType", 0); } else { idb.AddParameter("@DataType", gPSRecord.DataType); } if (gPSRecord.GPSTime == DateTime.MinValue) { idb.AddParameter("@GPSTime", DBNull.Value); } else { idb.AddParameter("@GPSTime", gPSRecord.GPSTime); } if (gPSRecord.Longitude == 0) { idb.AddParameter("@Longitude", 0); } else { idb.AddParameter("@Longitude", gPSRecord.Longitude); } if (gPSRecord.Latitude == 0) { idb.AddParameter("@Latitude", 0); } else { idb.AddParameter("@Latitude", gPSRecord.Latitude); } if (gPSRecord.GPSFlag == 0) { idb.AddParameter("@GPSFlag", 0); } else { idb.AddParameter("@GPSFlag", gPSRecord.GPSFlag); } if (gPSRecord.Speed == 0) { idb.AddParameter("@Speed", 0); } else { idb.AddParameter("@Speed", gPSRecord.Speed); } if (gPSRecord.Direction == 0) { idb.AddParameter("@Direction", 0); } else { idb.AddParameter("@Direction", gPSRecord.Direction); } if (gPSRecord.Comm_Type == 0) { idb.AddParameter("@Comm_Type", 0); } else { idb.AddParameter("@Comm_Type", gPSRecord.Comm_Type); } if (gPSRecord.MDTStatus == 0) { idb.AddParameter("@MDTStatus", 0); } else { idb.AddParameter("@MDTStatus", gPSRecord.MDTStatus); } if (gPSRecord.MDTAlarm == 0) { idb.AddParameter("@MDTAlarm", 0); } else { idb.AddParameter("@MDTAlarm", gPSRecord.MDTAlarm); } if (gPSRecord.Data_Length == 0) { idb.AddParameter("@Data_Length", 0); } else { idb.AddParameter("@Data_Length", gPSRecord.Data_Length); } if (string.IsNullOrEmpty(gPSRecord.DataContend)) { idb.AddParameter("@DataContend", DBNull.Value); } else { idb.AddParameter("@DataContend", gPSRecord.DataContend); } if (gPSRecord.Stat == 0) { idb.AddParameter("@Stat", 0); } else { idb.AddParameter("@Stat", gPSRecord.Stat); } if (gPSRecord.CreateTime == DateTime.MinValue) { idb.AddParameter("@CreateTime", DBNull.Value); } else { idb.AddParameter("@CreateTime", gPSRecord.CreateTime); } return(idb.ExeCmd(sql)); }
public void UpdateGPSRecord(GPSRecord record) { applicationContext.GPSRecords.Update(record); }
/// <summary> /// 获取实体数据 /// </summary> /// <param name='strCondition'>条件(AND Code='11')</param> /// <returns>model</returns> public GPSRecord GetModel(int id) { GPSRecord model = instance.GetByKey(id); return(model); }
private string readAllGPSRecord() { string sRecord,res=""; GPSRecord lastRecord = new GPSRecord(0, 0); while ((sRecord=m_fileReader.ReadLine())!=null) { GPSRecord record = parseRecord(sRecord); if (record == lastRecord) continue; res += record.ToString(true) + ",0 "; } return res; }
public GPSRecord GetGPSRecord(Guid id) { GPSRecord record = applicationContext.GPSRecords.SingleOrDefault(g => g.GPSRecordId == id); return(record); }