public bool Delete(TableLogViewModel dt, int id) { TableLog dr = db.TableLogs.Where(i => i.tlID == id).FirstOrDefault(); db.TableLogs.Remove(dr); var Result = db.SaveChanges(); return(Result == 1); }
public bool Update(TableLogViewModel dt, int id) { TableLog dr = db.TableLogs.Where(i => i.tlID == id).FirstOrDefault(); dr.tlID = dt.ID; dr.tlType = dt.LogType; dr.tlDate = dt.LogDate; dr.tlDescription = dt.LogDescription; var Result = db.SaveChanges(); return(Result == 1); }
public int Insert(TableLogViewModel dt) { TableLog dr = new TableLog(); dr.tlType = dt.LogType; dr.tlDate = dt.LogDate; dr.tlDescription = dt.LogDescription; db.TableLogs.Add(dr); var Result = db.SaveChanges(); return(dr.tlID); }
protected override CategoryFascicle BeforeDelete(CategoryFascicle entity, CategoryFascicle entityTransformed) { if (CurrentDeleteActionType != Common.Infrastructures.DeleteActionType.DeleteCategoryFascicle) { throw new DSWException(EXCEPTION_MESSAGE, null, DSWExceptionCode.SS_NotAllowedOperation); } if (entityTransformed.FascicleType == FascicleType.Procedure) { ICollection <CategoryFascicleTableValuedModel> subCategoryFascicles = _unitOfWork.Repository <CategoryFascicle>().GetCategorySubFascicles(entityTransformed.Category.EntityShortId); CategoryFascicle categoryFascicle; foreach (CategoryFascicleTableValuedModel toDelete in subCategoryFascicles) { categoryFascicle = _unitOfWork.Repository <CategoryFascicle>().FindIncludeRights(toDelete.IdCategoryFascicle).Single(); _unitOfWork.Repository <CategoryFascicleRight>().DeleteRange(categoryFascicle.CategoryFascicleRights.ToList()); _unitOfWork.Repository <CategoryFascicle>().Delete(categoryFascicle); } ICollection <CategoryFascicle> periodicCategoryFascicleReferences = _unitOfWork.Repository <CategoryFascicle>().GetAllPeriodicByCategory(entityTransformed.Category.EntityShortId).ToList(); CategoryFascicleRight specialRight; foreach (CategoryFascicle periodicCategoryFascicleReference in periodicCategoryFascicleReferences) { _unitOfWork.Repository <CategoryFascicleRight>().DeleteRange(periodicCategoryFascicleReference.CategoryFascicleRights.ToList()); if (_parameterEnvService.FascicleContainerEnabled) { specialRight = new CategoryFascicleRight() { CategoryFascicle = periodicCategoryFascicleReference, Role = _unitOfWork.Repository <Role>().GetByUniqueId(Guid.Empty).Single() }; _unitOfWork.Repository <CategoryFascicleRight>().Insert(specialRight); } } } if (entityTransformed.CategoryFascicleRights != null && entityTransformed.CategoryFascicleRights.Count > 0) { _unitOfWork.Repository <CategoryFascicleRight>().DeleteRange(entityTransformed.CategoryFascicleRights.ToList()); } TableLog tableLog = TableLogService.CreateLog(entity.UniqueId, null, TableLogEvent.DELETE, $"Eliminato piano di fascicolazione di tipo {entityTransformed.FascicleType.ToString()} con environment {entityTransformed.DSWEnvironment}", nameof(CategoryFascicle), CurrentDomainUser.Account); _unitOfWork.Repository <TableLog>().Insert(tableLog); return(base.BeforeDelete(entity, entityTransformed)); }
public void MoveToTableGraph([CanBeNull] string userAnswerIn, [NotNull] TableGraph tableGraphIn) { CurrentTableGraph = tableGraphIn; UserMistakeCount = 0; if (!string.IsNullOrEmpty(userAnswerIn)) { PrintUserTextToChat(userAnswerIn); } PrintSystemTextToChat(tableGraphIn.Question, tableGraphIn.IsShowConsultation ? tableGraphIn.Consultation : null); TableLog tableLog = new TableLog() { UserAnswer = userAnswerIn, SystemTableGraph = tableGraphIn }; TableLogs.Add(tableLog); }
public async Task <Tuple <string, TableInfo> > UpdateTableInfoAsync(string oldTableName, TableInfo oldTableInfo) { ConvertInfo converter = null; if (StringUtils.EqualsIgnoreCase(TableAdministrator.OldTableName, oldTableName)) { var table = new TableAdministrator(_databaseManager); converter = table.Converter; } else if (StringUtils.EqualsIgnoreCase(TableAdministratorsInRoles.OldTableName, oldTableName)) { var table = new TableAdministratorsInRoles(_databaseManager); converter = table.Converter; } else if (ListUtils.ContainsIgnoreCase(TableChannel.OldTableNames, oldTableName)) { var table = new TableChannel(_databaseManager); converter = table.Converter; } else if (ListUtils.ContainsIgnoreCase(TableChannelGroup.OldTableNames, oldTableName)) { var table = new TableChannelGroup(_databaseManager); converter = table.Converter; } else if (StringUtils.EqualsIgnoreCase(TableConfig.OldTableName, oldTableName)) { var table = new TableConfig(_databaseManager); converter = table.Converter; } else if (StringUtils.EqualsIgnoreCase(TableContentCheck.OldTableName, oldTableName)) { var table = new TableContentCheck(_databaseManager); converter = table.Converter; } else if (ListUtils.ContainsIgnoreCase(TableContentGroup.OldTableNames, oldTableName)) { var table = new TableContentGroup(_databaseManager); converter = table.Converter; } else if (StringUtils.EqualsIgnoreCase(TableDbCache.OldTableName, oldTableName)) { var table = new TableDbCache(_databaseManager); converter = table.Converter; } else if (StringUtils.EqualsIgnoreCase(TableErrorLog.OldTableName, oldTableName)) { converter = TableErrorLog.Converter; } else if (StringUtils.EqualsIgnoreCase(TableLog.OldTableName, oldTableName)) { var table = new TableLog(_databaseManager); converter = table.Converter; } else if (StringUtils.EqualsIgnoreCase(TablePermissionsInRoles.OldTableName, oldTableName)) { var table = new TablePermissionsInRoles(_databaseManager); converter = table.Converter; } else if (ListUtils.ContainsIgnoreCase(TableRelatedField.OldTableNames, oldTableName)) { var table = new TableRelatedField(_databaseManager); converter = table.Converter; } else if (ListUtils.ContainsIgnoreCase(TableRelatedFieldItem.OldTableNames, oldTableName)) { var table = new TableRelatedFieldItem(_databaseManager); converter = table.Converter; } else if (StringUtils.EqualsIgnoreCase(TableRole.OldTableName, oldTableName)) { var table = new TableRole(_databaseManager); converter = table.Converter; } else if (ListUtils.ContainsIgnoreCase(TableSite.OldTableNames, oldTableName)) { var table = new TableSite(_databaseManager); converter = table.Converter; } else if (ListUtils.ContainsIgnoreCase(TableSiteLog.OldTableNames, oldTableName)) { var table = new TableSiteLog(_databaseManager); converter = table.Converter; } else if (ListUtils.ContainsIgnoreCase(TableSitePermissions.OldTableNames, oldTableName)) { var table = new TableSitePermissions(_databaseManager); converter = table.Converter; } else if (StringUtils.EqualsIgnoreCase(TableTableStyle.OldTableName, oldTableName)) { var table = new TableTableStyle(_databaseManager); converter = table.Converter; } else if (StringUtils.EqualsIgnoreCase(TableContentTag.OldTableName, oldTableName)) { var table = new TableContentTag(_databaseManager); converter = table.Converter; } else if (ListUtils.ContainsIgnoreCase(TableTemplate.OldTableNames, oldTableName)) { var table = new TableTemplate(_databaseManager); converter = table.Converter; } else if (ListUtils.ContainsIgnoreCase(TableTemplateLog.OldTableNames, oldTableName)) { var table = new TableTemplateLog(_databaseManager); converter = table.Converter; } else if (StringUtils.EqualsIgnoreCase(TableUser.OldTableName, oldTableName)) { var table = new TableUser(_databaseManager); converter = table.Converter; } return(await GetNewTableInfoAsync(oldTableName, oldTableInfo, converter)); }
/// <summary> /// Loads database data into in-memory objects /// </summary> public void Load() { // NeoFly database file path string dbPath = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) + @"\NeoFly\common.db"; if (!File.Exists(dbPath)) { throw new FileNotFoundException(dbPath); } DataSetNeoFlyData = new DataSet(); // In-memory log table structure TableLog = DataSetNeoFlyData.Tables.Add("log"); TableLog.Columns.Add("Export", typeof(bool)); TableLog.Columns.Add("Id", typeof(int)); TableLog.Columns.Add("Date", typeof(DateTime)); TableLog.Columns.Add("From", typeof(string)); TableLog.Columns.Add("To", typeof(string)); // In-memory trajectory log table structure TableTrajectoryLog = DataSetNeoFlyData.Tables.Add("trajectoryLog"); TableTrajectoryLog.Columns.Add("Id", typeof(int)); TableTrajectoryLog.Columns.Add("FlightId", typeof(int)); TableTrajectoryLog.Columns.Add("Lon", typeof(double)); TableTrajectoryLog.Columns.Add("Lat", typeof(double)); TableTrajectoryLog.Columns.Add("Altitude", typeof(int)); // Relation between flight and flight trajectory RelationLoTrajectoryLog = DataSetNeoFlyData.Relations.Add(TableLog.Columns["Id"], TableTrajectoryLog.Columns["FlightId"]); // Db connection using (var connection = new SqliteConnection("Data Source=" + dbPath)) { connection.Open(); // Airport command var commandAirport = connection.CreateCommand(); commandAirport.CommandText = "SELECT lonx, laty, altitude FROM airport WHERE ident = $ident"; commandAirport.Parameters.Add("$ident", SqliteType.Text); commandAirport.Prepare(); // Trajectory log command var commandTrajectoryLog = connection.CreateCommand(); commandTrajectoryLog.CommandText = "SELECT id, location, altitude FROM trajectoryLog WHERE flightId = $flightId ORDER BY id"; commandTrajectoryLog.Parameters.Add("$flightId", SqliteType.Integer); commandTrajectoryLog.Prepare(); // Log command var commandLog = connection.CreateCommand(); commandLog.CommandText = "SELECT COUNT(*) FROM log"; int logCount = Convert.ToInt32(commandLog.ExecuteScalar()); int currentLog = 0; LoadStarted?.Invoke(this, new NeoFlyDataLoadEventArgs() { RowCount = logCount }); commandLog = connection.CreateCommand(); commandLog.CommandText = "SELECT id, date, fp FROM log ORDER BY date"; using (var readerLog = commandLog.ExecuteReader()) { while (readerLog.Read()) { try { // Flight var row = TableLog.NewRow(); row["Id"] = readerLog.GetInt32(0); row["Date"] = readerLog.GetDateTime(1); string[] fp = readerLog.GetString(2).Split('>'); row["From"] = fp[0]; row["To"] = fp[1]; row["Export"] = true; TableLog.Rows.Add(row); // Trajectory bool trajectoryData = false; commandTrajectoryLog.Parameters["$flightId"].Value = row["Id"]; using (var readerTrajectoryLog = commandTrajectoryLog.ExecuteReader()) { while (readerTrajectoryLog.Read()) { var trajRow = TableTrajectoryLog.NewRow(); trajRow["Id"] = readerTrajectoryLog.GetInt32(0); trajRow["FlightId"] = row["Id"]; // The location field may be corrupt, in that case the row is skipped string[] location = readerTrajectoryLog.GetString(1).Split(','); if (location.Length != 2) { continue; } // The latitude value is checked double coordValue; if (!double.TryParse(location[0], NumberStyles.Float, CultureInfo.InvariantCulture, out coordValue)) { continue; } trajRow["Lat"] = coordValue; // The longitude value is checked if (!double.TryParse(location[1], NumberStyles.Float, CultureInfo.InvariantCulture, out coordValue)) { continue; } trajRow["Lon"] = coordValue; // Altitude trajRow["Altitude"] = readerTrajectoryLog.GetInt32(2); // We skip the row is the coordinates are "0,0" if ((double)trajRow["Lat"] == 0 && (double)trajRow["Lon"] == 0) { continue; } TableTrajectoryLog.Rows.Add(trajRow); trajectoryData = true; } } // If no trajectory data is available (old NeoFly version), we add two waypoints: departure and arrival if (!trajectoryData) { foreach (string airportId in fp) { commandAirport.Parameters["$ident"].Value = airportId; using (var readerFrom = commandAirport.ExecuteReader()) { if (readerFrom.Read()) { var trajRow = TableTrajectoryLog.NewRow(); trajRow["FlightId"] = row["Id"]; trajRow["Lon"] = readerFrom.GetDouble(0); trajRow["Lat"] = readerFrom.GetDouble(1); trajRow["Altitude"] = readerFrom.GetInt32(2); TableTrajectoryLog.Rows.Add(trajRow); } } } } } finally { LoadProgress?.Invoke(this, new NeoFlyDataLoadEventArgs() { CurrentRow = ++currentLog }); } } } LoadEnded?.Invoke(this, null); } }
/// <summary> /// Exports in-memory data to a GPX file /// </summary> /// <param name="options">Export options in key-value pairs</param> public void ExportToGPXFile(Dictionary <string, string> options) { if (!options.ContainsKey("file")) { throw new ExportOptionException("Provide a file name to export to.\nEx: NeoFlyExport.exe --file=neofly.gpx"); } const double footMeterRatio = 0.3048; // Segment list List <trkType> trks = new List <trkType>(); // Rows to be exported IEnumerable <DataRow> exportRows; // If only the file name is provided, we export all selected rows if (options.Count == 1) { exportRows = TableLog.AsEnumerable().Where(row => row.Field <bool>("Export")); } // If a log ID is provided, we export only this one else if (options.ContainsKey("logid")) { exportRows = TableLog.AsEnumerable().Where(row => row.Field <int>("Id").ToString() == options["logid"]); } // Other filters are processed else { exportRows = TableLog.AsEnumerable(); // dateFrom: Exports all rows after this date if (options.ContainsKey("datefrom")) { if (!DateTime.TryParse(options["datefrom"], out DateTime dateFrom)) { throw new ExportOptionException($"Incorrect dateFrom value: {options["datefrom"]}."); } exportRows = exportRows.Where(row => row.Field <DateTime>("Date").Date >= dateFrom.Date); } // dateTo: Exports all rows before this date if (options.ContainsKey("dateto")) { if (!DateTime.TryParse(options["dateto"], out DateTime dateTo)) { throw new ExportOptionException($"Incorrect dateTo value: {options["dateto"]}."); } exportRows = exportRows.Where(row => row.Field <DateTime>("Date").Date <= dateTo.Date); } } foreach (DataRow row in exportRows) { // Trajectory waypoints DataRow[] trajectoryWaypoints = row.GetChildRows(RelationLoTrajectoryLog); if (trajectoryWaypoints.Length < 1) { continue; } // Waypoint list List <wptType> wpts = new List <wptType>(); foreach (DataRow dataRow in trajectoryWaypoints) { wpts.Add(new wptType() { lon = Convert.ToDecimal(dataRow["Lon"]), lat = Convert.ToDecimal(dataRow["Lat"]), ele = Convert.ToDecimal((int)dataRow["Altitude"] / footMeterRatio), eleSpecified = true }); } // Labels and time for departure and arrival wpts[0].name = (string)row["From"]; wpts[0].time = row.Field <DateTime>("Date").ToUniversalTime(); wpts[0].timeSpecified = true; wpts[wpts.Count - 1].name = (string)row["To"]; // Track trkType trk = new trkType() { name = $"{row["From"]}>{row["To"]}", trkseg = new trksegType[1] }; trk.trkseg[0] = new trksegType() { trkpt = wpts.ToArray() }; trks.Add(trk); } // GPX object gpxType gpxData = new gpxType() { trk = trks.ToArray(), creator = "NeoFlyExport " + typeof(NeoFlyData).Assembly.GetName().Version.ToString() }; // Write to xml file XmlSerializer xmlSerializer = new XmlSerializer(typeof(gpxType)); using (var swFile = new StreamWriter(options["file"])) xmlSerializer.Serialize(swFile, gpxData); }
public async Task <Tuple <string, TableInfo> > UpdateTableInfoAsync(string oldTableName, TableInfo oldTableInfo, List <string> tableNameListForGovPublic, List <string> tableNameListForGovInteract, List <string> tableNameListForJob) { ConvertInfo converter = null; if (StringUtils.EqualsIgnoreCase(TableAdministrator.OldTableName, oldTableName)) { var table = new TableAdministrator(_databaseManager); converter = table.Converter; } else if (StringUtils.EqualsIgnoreCase(TableAdministratorsInRoles.OldTableName, oldTableName)) { var table = new TableAdministratorsInRoles(_databaseManager); converter = table.Converter; } else if (ListUtils.ContainsIgnoreCase(TableChannel.OldTableNames, oldTableName)) { var table = new TableChannel(_databaseManager); converter = table.Converter; } else if (ListUtils.ContainsIgnoreCase(TableChannelGroup.OldTableNames, oldTableName)) { var table = new TableChannelGroup(_databaseManager); converter = table.Converter; } else if (StringUtils.EqualsIgnoreCase(TableConfig.OldTableName, oldTableName)) { var table = new TableConfig(_databaseManager); converter = table.Converter; } else if (StringUtils.EqualsIgnoreCase(TableContentCheck.OldTableName, oldTableName)) { var table = new TableContentCheck(_databaseManager); converter = table.Converter; } else if (ListUtils.ContainsIgnoreCase(TableContentGroup.OldTableNames, oldTableName)) { var table = new TableContentGroup(_databaseManager); converter = table.Converter; } else if (StringUtils.EqualsIgnoreCase(TableDbCache.OldTableName, oldTableName)) { var table = new TableDbCache(_databaseManager); converter = table.Converter; } else if (StringUtils.EqualsIgnoreCase(TableErrorLog.OldTableName, oldTableName)) { converter = TableErrorLog.Converter; } else if (StringUtils.EqualsIgnoreCase(TableLog.OldTableName, oldTableName)) { var table = new TableLog(_databaseManager); converter = table.Converter; } else if (StringUtils.EqualsIgnoreCase(TablePermissionsInRoles.OldTableName, oldTableName)) { var table = new TablePermissionsInRoles(_databaseManager); converter = table.Converter; } else if (ListUtils.ContainsIgnoreCase(TableRelatedField.OldTableNames, oldTableName)) { var table = new TableRelatedField(_databaseManager); converter = table.Converter; } else if (ListUtils.ContainsIgnoreCase(TableRelatedFieldItem.OldTableNames, oldTableName)) { var table = new TableRelatedFieldItem(_databaseManager); converter = table.Converter; } else if (StringUtils.EqualsIgnoreCase(TableRole.OldTableName, oldTableName)) { var table = new TableRole(_databaseManager); converter = table.Converter; } else if (ListUtils.ContainsIgnoreCase(TableSite.OldTableNames, oldTableName)) { var table = new TableSite(_databaseManager); converter = table.Converter; } else if (ListUtils.ContainsIgnoreCase(TableSiteLog.OldTableNames, oldTableName)) { var table = new TableSiteLog(_databaseManager); converter = table.Converter; } else if (ListUtils.ContainsIgnoreCase(TableSitePermissions.OldTableNames, oldTableName)) { var table = new TableSitePermissions(_databaseManager); converter = table.Converter; } else if (StringUtils.EqualsIgnoreCase(TableTableStyle.OldTableName, oldTableName)) { var table = new TableTableStyle(_databaseManager); converter = table.Converter; } else if (StringUtils.EqualsIgnoreCase(TableContentTag.OldTableName, oldTableName)) { var table = new TableContentTag(_databaseManager); converter = table.Converter; } else if (ListUtils.ContainsIgnoreCase(TableTemplate.OldTableNames, oldTableName)) { var table = new TableTemplate(_databaseManager); converter = table.Converter; } else if (ListUtils.ContainsIgnoreCase(TableTemplateLog.OldTableNames, oldTableName)) { var table = new TableTemplateLog(_databaseManager); converter = table.Converter; } else if (StringUtils.EqualsIgnoreCase(TableUser.OldTableName, oldTableName)) { var table = new TableUser(_databaseManager); converter = table.Converter; } else if (StringUtils.EqualsIgnoreCase(TableGovInteractChannel.OldTableName, oldTableName)) { var table = new TableGovInteractChannel(); converter = table.Converter; } else if (StringUtils.EqualsIgnoreCase(TableGovInteractLog.OldTableName, oldTableName)) { converter = TableGovInteractLog.Converter; } else if (StringUtils.EqualsIgnoreCase(TableGovInteractPermissions.OldTableName, oldTableName)) { converter = TableGovInteractPermissions.Converter; } else if (StringUtils.EqualsIgnoreCase(TableGovInteractRemark.OldTableName, oldTableName)) { converter = TableGovInteractRemark.Converter; } else if (StringUtils.EqualsIgnoreCase(TableGovInteractReply.OldTableName, oldTableName)) { converter = TableGovInteractReply.Converter; } else if (StringUtils.EqualsIgnoreCase(TableGovInteractType.OldTableName, oldTableName)) { converter = TableGovInteractType.Converter; } else if (StringUtils.EqualsIgnoreCase(TableGovPublicCategory.OldTableName, oldTableName)) { converter = TableGovPublicCategory.Converter; } else if (StringUtils.EqualsIgnoreCase(TableGovPublicCategoryClass.OldTableName, oldTableName)) { converter = TableGovPublicCategoryClass.Converter; } else if (StringUtils.EqualsIgnoreCase(TableGovPublicIdentifierRule.OldTableName, oldTableName)) { converter = TableGovPublicIdentifierRule.Converter; } else if (StringUtils.EqualsIgnoreCase(TableGovPublicIdentifierSeq.OldTableName, oldTableName)) { converter = TableGovPublicIdentifierSeq.Converter; } else if (ListUtils.ContainsIgnoreCase(tableNameListForGovPublic, oldTableName)) { var table = new TableGovPublicContent(_settingsManager); converter = table.GetConverter(oldTableInfo.Columns); } else if (ListUtils.ContainsIgnoreCase(tableNameListForGovInteract, oldTableName)) { var table = new TableGovInteractContent(_settingsManager); converter = table.GetConverter(oldTableInfo.Columns); } else if (ListUtils.ContainsIgnoreCase(tableNameListForJob, oldTableName)) { var table = new TableJobsContent(_settingsManager); converter = table.GetConverter(oldTableInfo.Columns); } return(await GetNewTableInfoAsync(oldTableName, oldTableInfo, converter)); }