Files
2026-04-17 14:55:32 -04:00

7.0 KiB
Raw Permalink Blame History

source_files, generated_at, model, schema_version, sha256
source_files generated_at model schema_version sha256
DataPRO/SLICEDBMerge/SLICEDBMerge/Program.cs
DataPRO/SLICEDBMerge/SLICEDBMerge/Form1.cs
DataPRO/SLICEDBMerge/SLICEDBMerge/Form1.Designer.cs
2026-04-16T04:28:15.975483+00:00 Qwen/Qwen3-Coder-Next-FP8 1 352f915421417df4

SLICEDBMerge Module Documentation

1. Purpose

This module is a Windows Forms desktop application designed to merge sensor data and calibration records from a source sensor database directory into a destination sensor database directory. It provides a user interface to browse and select directories, display available sensors in both source and destination locations, allow selective inclusion of sensors via checkboxes, and perform the merge operation by appending selected sensor data and their latest calibration records to the destination database. The tool is intended for database consolidation or migration scenarios where sensor metadata and calibration history need to be transferred between physical database folders.

2. Public Interface

The module exposes only one public class: Form1, which serves as the main application window. All interaction occurs through UI controls; there are no other public APIs.

  • Form1()
    Constructor. Initializes the form and its components via InitializeComponent().

  • btnBrowse_Click(object sender, EventArgs e)
    Event handler for the Source folder browse button. Opens a FolderBrowserDialog, sets tbSourceLocation.Text to the selected path, and calls LoadSourceDG() to populate the source sensor grid.

  • btnDestinationBrowse_Click(object sender, EventArgs e)
    Event handler for the Destination folder browse button. Opens a FolderBrowserDialog, sets tbDestination.Text to the selected path, and calls LoadDestinationDG() to populate the destination sensor grid.

  • button1_Click(object sender, EventArgs e)
    Event handler for the Merge button. Iterates over rows in the source grid (dgSource) starting at index 1 (skipping header), and for each row where column index 1 (checkbox) is true, it retrieves the SensorData object from UserData, adds it to _destination, saves the destination database, retrieves the latest calibration for that sensors serial number, adds the calibration, and saves again. Errors are collected and displayed in a MessageBox. After processing, LoadDestinationDG() is called to refresh the destination grid.

  • lbSelectAll_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
    Sets the checkbox value (column 1) to true for all sensor rows in dgSource.

  • lbInvertSelection_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
    Toggles the checkbox value (column 1) for all sensor rows in dgSource.

  • lbClearAll_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
    Sets the checkbox value (column 1) to false for all sensor rows in dgSource.

3. Invariants

  • The source and destination directories must contain a valid SensorDBTables.DataTableFilename (exact filename not specified in source, but required for LoadSourceDG() to succeed).
  • _sourceDB and _destination are instance fields of type DTS.SensorDB.SensorDBTables; _sourceDB is only initialized in LoadSourceDG(), _destination only in LoadDestinationDG().
  • Grid rows are indexed starting at 0, but data rows begin at index 1 (row 0 is assumed to be a header row).
  • Column 1 of each grid row is used as a boolean checkbox for selection.
  • Column indices for sensor data in the grid are fixed:
    • 1: selection checkbox
    • 2: SerialNumber
    • 3: Comment
    • 4: Id
    • 5: Range.High.ToString()
    • 6: MeasurementUnit
  • The Save(null) method is called twice per selected sensor: once after adding SensorData, once after adding SensorCalibration. This implies the destination database file is overwritten on each save (no incremental updates).
  • GetLatestCalibrationBySerialNumber() is called only if _sourceDB is non-null and the sensor data was successfully loaded.

4. Dependencies

  • External Libraries:
    • System.Windows.Forms (for Form, Button, FolderBrowserDialog, MessageBox, etc.)
    • C1.Win.C1FlexGrid (for C1FlexGrid control used for dgSource and dgDestination)
    • DTS.SensorDB (custom namespace; used via SensorDBTables and SensorData, SensorCalibration types)
  • Internal Dependencies:
    • DTS.SensorDB.SensorDBTables is assumed to provide:
      • Static field DataTableFilename (used to check existence of database file)
      • Instance method Load(string path, bool flag1, object flag2, int flag3, int flag4)
      • Instance method GetAllSensors() returning SensorData[]
      • Instance method Add(object) (used for both SensorData and SensorCalibration)
      • Instance method Save(object) (called with null)
      • Instance method GetLatestCalibrationBySerialNumber(string serialNumber) returning SensorCalibration
  • Consumers:
    • Only consumed by Program.Main() (entry point launching Form1). No other modules reference it.

5. Gotchas

  • Partial initialization risk: If LoadSourceDG() fails or is never called, _sourceDB remains null, and button1_Click() silently skips sensor/ calibration processing for all rows (due to if (null == _sourceDB) { continue; }).
  • No validation of destination database structure: The code assumes _destination.Add() and _destination.Save() will succeed regardless of whether the destination folder already contains a valid database or conflicting entries.
  • Overly broad exception handling: Exceptions during merge are caught per-sensor, but only the message is shown; stack traces and context are lost. Also, a failure in one sensor does not abort the entire merge.
  • Hardcoded grid row/column assumptions: Logic assumes row 0 is header and data starts at row 1; column indices (16) are hardcoded. Changes to grid layout in the designer will break functionality silently.
  • No concurrency protection: If the destination database is accessed concurrently (e.g., by another process), Save(null) may cause corruption or exceptions.
  • No rollback on partial failure: If adding sensor N succeeds but adding its calibration fails, sensor N remains in the destination database, leading to inconsistent state.
  • No duplicate detection: The code does not check if a sensor or calibration already exists in the destination before adding, potentially causing duplicates or errors depending on SensorDBTables.Add() behavior.
  • Save(null) semantics unclear: Passing null to Save() may imply saving to a default path or in-place; behavior depends on DTS.SensorDB implementation.
  • No progress feedback: Merging many sensors provides no UI feedback during the operation, risking perceived unresponsiveness.
  • No cleanup on error: If an exception occurs mid-merge, the partially modified destination database may be left in an inconsistent state.

None identified from source alone beyond those listed.