7.0 KiB
source_files, generated_at, model, schema_version, sha256
| source_files | generated_at | model | schema_version | sha256 | |||
|---|---|---|---|---|---|---|---|
|
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 viaInitializeComponent(). -
btnBrowse_Click(object sender, EventArgs e)
Event handler for the Source folder browse button. Opens aFolderBrowserDialog, setstbSourceLocation.Textto the selected path, and callsLoadSourceDG()to populate the source sensor grid. -
btnDestinationBrowse_Click(object sender, EventArgs e)
Event handler for the Destination folder browse button. Opens aFolderBrowserDialog, setstbDestination.Textto the selected path, and callsLoadDestinationDG()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) istrue, it retrieves theSensorDataobject fromUserData, adds it to_destination, saves the destination database, retrieves the latest calibration for that sensor’s serial number, adds the calibration, and saves again. Errors are collected and displayed in aMessageBox. After processing,LoadDestinationDG()is called to refresh the destination grid. -
lbSelectAll_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
Sets the checkbox value (column 1) totruefor all sensor rows indgSource. -
lbInvertSelection_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
Toggles the checkbox value (column 1) for all sensor rows indgSource. -
lbClearAll_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
Sets the checkbox value (column 1) tofalsefor all sensor rows indgSource.
3. Invariants
- The source and destination directories must contain a valid
SensorDBTables.DataTableFilename(exact filename not specified in source, but required forLoadSourceDG()to succeed). _sourceDBand_destinationare instance fields of typeDTS.SensorDB.SensorDBTables;_sourceDBis only initialized inLoadSourceDG(),_destinationonly inLoadDestinationDG().- 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 checkbox2:SerialNumber3:Comment4:Id5:Range.High.ToString()6:MeasurementUnit
- The
Save(null)method is called twice per selected sensor: once after addingSensorData, once after addingSensorCalibration. This implies the destination database file is overwritten on each save (no incremental updates). GetLatestCalibrationBySerialNumber()is called only if_sourceDBis non-null and the sensor data was successfully loaded.
4. Dependencies
- External Libraries:
System.Windows.Forms(forForm,Button,FolderBrowserDialog,MessageBox, etc.)C1.Win.C1FlexGrid(forC1FlexGridcontrol used fordgSourceanddgDestination)DTS.SensorDB(custom namespace; used viaSensorDBTablesandSensorData,SensorCalibrationtypes)
- Internal Dependencies:
DTS.SensorDB.SensorDBTablesis 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()returningSensorData[] - Instance method
Add(object)(used for bothSensorDataandSensorCalibration) - Instance method
Save(object)(called withnull) - Instance method
GetLatestCalibrationBySerialNumber(string serialNumber)returningSensorCalibration
- Static field
- Consumers:
- Only consumed by
Program.Main()(entry point launchingForm1). No other modules reference it.
- Only consumed by
5. Gotchas
- Partial initialization risk: If
LoadSourceDG()fails or is never called,_sourceDBremainsnull, andbutton1_Click()silently skips sensor/ calibration processing for all rows (due toif (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 (1–6) 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
Nsucceeds but adding its calibration fails, sensorNremains 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: PassingnulltoSave()may imply saving to a default path or in-place; behavior depends onDTS.SensorDBimplementation.- 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.