diff --git a/SmartAquaViewer/Classes/DataGridAutoBuilder.cs b/SmartAquaViewer/Classes/DataGridAutoBuilder.cs new file mode 100644 index 0000000..f155d9c --- /dev/null +++ b/SmartAquaViewer/Classes/DataGridAutoBuilder.cs @@ -0,0 +1,96 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows; + +namespace SmartAquaViewer.Classes +{ + public static class DataGridAutoBuilder + { + public static void BuildColumnsFromType(DataGrid grid, IEnumerable items, + Dictionary headerMap = null, string dateFormat = "yyyy-MM-dd HH:mm:ss") + { + grid.Columns.Clear(); + var props = typeof(T).GetProperties(BindingFlags.Public | BindingFlags.Instance); + + foreach (var p in props) + { + DataGridColumn col = CreateColumnForProperty(p, headerMap, dateFormat); + if (col != null) grid.Columns.Add(col); + } + + grid.ItemsSource = items; + } + + private static DataGridColumn CreateColumnForProperty(PropertyInfo p, + Dictionary headerMap, string dateFormat) + { + string header = headerMap != null && headerMap.TryGetValue(p.Name, out var h) ? h : p.Name; + var type = Nullable.GetUnderlyingType(p.PropertyType) ?? p.PropertyType; + + // bool → CheckBox + if (type == typeof(bool)) + { + return new DataGridCheckBoxColumn + { + Header = header, + Binding = new Binding(p.Name) { Mode = BindingMode.TwoWay } + }; + } + + // enum → ComboBox(읽기/쓰기) + if (type.IsEnum) + { + return new DataGridComboBoxColumn + { + Header = header, + ItemsSource = Enum.GetValues(type), + SelectedItemBinding = new Binding(p.Name) { Mode = BindingMode.TwoWay } + }; + } + + // DateTime → 포맷 + if (type == typeof(DateTime)) + { + return new DataGridTextColumn + { + Header = header, + Binding = new Binding(p.Name) + { + Mode = BindingMode.TwoWay, + StringFormat = dateFormat + } + }; + } + + // 숫자 → 우측정렬 + if (type == typeof(int) || type == typeof(long) || + type == typeof(float) || type == typeof(double) || type == typeof(decimal)) + { + var col = new DataGridTextColumn + { + Header = header, + Binding = new Binding(p.Name) { Mode = BindingMode.TwoWay, UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged } + }; + col.ElementStyle = new Style(typeof(TextBlock)) + { + Setters = { new Setter(TextBlock.TextAlignmentProperty, TextAlignment.Right) } + }; + return col; + } + + // 기본(문자 등) + return new DataGridTextColumn + { + Header = header, + Binding = new Binding(p.Name) { Mode = BindingMode.TwoWay, UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged } + }; + } + } + +} diff --git a/SmartAquaViewer/MainWindow.xaml.cs b/SmartAquaViewer/MainWindow.xaml.cs index 21ad446..4370272 100644 --- a/SmartAquaViewer/MainWindow.xaml.cs +++ b/SmartAquaViewer/MainWindow.xaml.cs @@ -9,6 +9,7 @@ using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; using SmartAquaViewer.DataAnalisys; +using SmartAquaViewer.Model; namespace SmartAquaViewer { @@ -27,6 +28,7 @@ namespace SmartAquaViewer private void MainWindow_Loaded(object sender, RoutedEventArgs e) { var sampleData = WaterQualityVO.GetSampleData(new DateTime(2025, 8, 1), new DateTime(2025, 8, 5), 10); + Datas.SetWaterQualityVO(sampleData); } } } \ No newline at end of file diff --git a/SmartAquaViewer/Model/Datas.cs b/SmartAquaViewer/Model/Datas.cs new file mode 100644 index 0000000..6586722 --- /dev/null +++ b/SmartAquaViewer/Model/Datas.cs @@ -0,0 +1,29 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using SmartAquaViewer.DataAnalisys; + +namespace SmartAquaViewer.Model +{ + public class Datas + { + public static List WaterQualityList { get; set; } + + static Datas() + { + WaterQualityList = new List(); + } + + public static List GetWaterQualityVO() + { + return WaterQualityList; + } + + public static void SetWaterQualityVO(List sampleData) + { + WaterQualityList = sampleData; + } + } +} diff --git a/SmartAquaViewer/View/MonitoringView.xaml.cs b/SmartAquaViewer/View/MonitoringView.xaml.cs index 1844d34..166e75f 100644 --- a/SmartAquaViewer/View/MonitoringView.xaml.cs +++ b/SmartAquaViewer/View/MonitoringView.xaml.cs @@ -12,6 +12,8 @@ using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; +using SmartAquaViewer.Classes; +using SmartAquaViewer.Model; using SmartAquaViewer.ViewModel; using static SmartAquaViewer.Model.Enums; @@ -24,8 +26,6 @@ namespace SmartAquaViewer.View { private MonitoringViewModel? monitoringViewModel; - private PanelState _state = PanelState.Normal; - public MonitoringView() { InitializeComponent(); @@ -35,6 +35,44 @@ namespace SmartAquaViewer.View private void MonitoringViewModel_OnSystemChanged(string systemName) { + switch (systemName) + { + case "Tank": + + break; + case "Filter": + + break; + case "System3": + + break; + default: + + break; + } + } + + private void GetTankData() + { + //var waterTanksGroup = Datas.GetWaterQualityVO().GroupBy(w => w.WaterTank.WaterTankNum); + + //foreach (var group in waterTanksGroup) + //{ + // DataGrid dataGrid = new DataGrid(); + + // group.ToList() + + // DataGridAutoBuilder.BuildColumnsFromType(dataGrid, group, new Dictionary + // { + // { nameof(DataAnalisys.WaterQualityVO.Timestamp), "시간" }, + // { nameof(DataAnalisys.WaterTank.DO), "DO센서 (mg/L)" }, + // { nameof(DataAnalisys.WaterTank.PH), "pH센서" }, + // { nameof(DataAnalisys.WaterTank.ORP), "ORP센서 (mV)" }, + // { nameof(DataAnalisys.WaterTank.Temperature), "수온 (°C)" }, + // { nameof(DataAnalisys.WaterTank.FlowRate), "유량 (m³/s)"} + // }); + //} + } }