using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace SliceDBMerge { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void btnBrowse_Click(object sender, EventArgs e) { using (FolderBrowserDialog fbd = new FolderBrowserDialog()) { if (fbd.ShowDialog() == DialogResult.OK) { tbSourceLocation.Text = fbd.SelectedPath; LoadSourceDG(); } } } private void btnDestinationBrowse_Click(object sender, EventArgs e) { using (FolderBrowserDialog fbd = new FolderBrowserDialog()) { if (fbd.ShowDialog() == DialogResult.OK) { tbDestination.Text = fbd.SelectedPath; LoadDestinationDG(); } } } private DTS.SensorDB.SensorDBTables _sourceDB; private void LoadSourceDG() { try { dgSource.Rows.RemoveRange(1, dgSource.Rows.Count - 1); if (!System.IO.File.Exists(System.IO.Path.Combine(tbSourceLocation.Text, DTS.SensorDB.SensorDBTables.DataTableFilename))) { MessageBox.Show("No sensors in directory"); return; } _sourceDB = new DTS.SensorDB.SensorDBTables(); _sourceDB.Load(tbSourceLocation.Text, true, null, 0, 0); DTS.SensorDB.SensorData[] sensors = _sourceDB.GetAllSensors(); foreach (DTS.SensorDB.SensorData sd in sensors) { C1.Win.C1FlexGrid.Row r = dgSource.Rows.Add(); r.UserData = sd; r[1] = true; r[2] = sd.SerialNumber; r[3] = sd.Comment; r[4] = sd.Id; r[5] = sd.Range.High.ToString(); r[6] = sd.MeasurementUnit; } dgSource.AutoSizeCols(); } catch (System.Exception ex) { MessageBox.Show(ex.Message); } } private DTS.SensorDB.SensorDBTables _destination; private void LoadDestinationDG() { try { dgDestination.Rows.RemoveRange(1, dgDestination.Rows.Count - 1); _destination = new DTS.SensorDB.SensorDBTables(); _destination.Load(tbDestination.Text, true, null, 0, 0); DTS.SensorDB.SensorData[] sensors = _destination.GetAllSensors(); foreach (DTS.SensorDB.SensorData sd in sensors) { C1.Win.C1FlexGrid.Row r = dgDestination.Rows.Add(); r.UserData = sd; r[1] = true; r[2] = sd.SerialNumber; r[3] = sd.Comment; r[4] = sd.Id; r[5] = sd.Range.High.ToString(); r[6] = sd.MeasurementUnit; } dgDestination.AutoSizeCols(); } catch (System.Exception ex) { MessageBox.Show(ex.Message); } } private void button1_Click(object sender, EventArgs e) { List errors = new List(); for (int i = 1; i < dgSource.Rows.Count; i++) { if ((bool)dgSource[i, 1]) { DTS.SensorDB.SensorData sd = dgSource.Rows[i].UserData as DTS.SensorDB.SensorData; if (null == sd) { continue; } if (null == _destination) { continue; } try { _destination.Add(sd); _destination.Save(null); DTS.SensorDB.SensorCalibration cal = _sourceDB.GetLatestCalibrationBySerialNumber(sd.SerialNumber); _destination.Add(cal); _destination.Save(null); } catch (System.Exception ex) { errors.Add(ex.Message); } } } if (errors.Count > 0) { MessageBox.Show(string.Join("\n", errors.ToArray())); } LoadDestinationDG(); } private void lbSelectAll_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { for (int i = 1; i < dgSource.Rows.Count; i++) { dgSource[i, 1] = true; } } private void lbInvertSelection_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { for (int i = 1; i < dgSource.Rows.Count; i++) { dgSource[i, 1] = !(bool)dgSource[i, 1]; } } private void lbClearAll_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { for (int i = 1; i < dgSource.Rows.Count; i++) { dgSource[i, 1] = false; } } } }