using System.Collections.Generic; using System.Windows; using System.Windows.Controls; using System.Windows.Input; using System.Windows.Media; namespace VisionCommonUI { public partial class MessageBoxSaveData : Window { private MessageBoxResult mMessageBoxResult = MessageBoxResult.None; private Dictionary _OldValues; private Dictionary _NewValues; /// /// 데이터 저장시, 전후 값을 비교하기 위함. /// /// 비교할 데이터의 변경 전의 값들 /// 비교할 데이터의 변경 후의 값들 public MessageBoxSaveData(Dictionary oldValues, Dictionary newValues) { _OldValues = oldValues; _NewValues = newValues; InitializeComponent(); CreateCmpTableItems(); } private void CreateCmpTableItems() { foreach (var newValuePair in _NewValues) { // Create (PropName/OldValue/NewValue) Table var grid = new Grid() { Margin = new Thickness(5) }; var rowDef1 = new RowDefinition(); var colDef1 = new ColumnDefinition(); var colDef2 = new ColumnDefinition(); var colDef3 = new ColumnDefinition(); grid.RowDefinitions.Add(rowDef1); grid.ColumnDefinitions.Add(colDef1); grid.ColumnDefinitions.Add(colDef2); grid.ColumnDefinitions.Add(colDef3); // Property Name var tbPropName = new TextBlock(); tbPropName.Style = this.FindResource("styleTextBlockTitleVerySmall") as Style; tbPropName.Text = newValuePair.Key; tbPropName.TextAlignment = TextAlignment.Right; Grid.SetRow(tbPropName, 0); Grid.SetColumn(tbPropName, 0); grid.Children.Add(tbPropName); // Old Value var tbOldValue = new TextBlock(); tbOldValue.Style = this.FindResource("styleTextBlockTitleVerySmall") as Style; tbOldValue.Foreground = Brushes.Cyan; if (_OldValues.ContainsKey(newValuePair.Key)) tbOldValue.Text = _OldValues[newValuePair.Key].ToString(); Grid.SetRow(tbOldValue, 0); Grid.SetColumn(tbOldValue, 1); grid.Children.Add(tbOldValue); // New Value var tbNewValue = new TextBlock(); tbNewValue.Style = this.FindResource("styleTextBlockTitleVerySmall") as Style; tbNewValue.Foreground = Brushes.Cyan; tbNewValue.Text = _NewValues[newValuePair.Key].ToString(); if (!tbNewValue.Text.Equals(tbOldValue.Text)) tbNewValue.Foreground = Brushes.Red; Grid.SetRow(tbNewValue, 0); Grid.SetColumn(tbNewValue, 2); grid.Children.Add(tbNewValue); spCmpTable.Children.Add(grid); } this.SizeToContent = SizeToContent.Height; } public MessageBoxResult ShowDialog(string statusMsg) { tbStatusMessage.Text = statusMsg; this.ShowDialog(); return mMessageBoxResult; } private void Button_Click_Question_Yes(object sender, RoutedEventArgs e) { mMessageBoxResult = MessageBoxResult.Yes; tbStatusMessage.Text = string.Empty; this.Close(); } private void Button_Click_Question_No(object sender, RoutedEventArgs e) { mMessageBoxResult = MessageBoxResult.No; tbStatusMessage.Text = string.Empty; this.Close(); } private void MessageBox_KeyDown(object sender, KeyEventArgs e) { if (e.Key == Key.Enter) { Button_Click_Question_Yes(sender, e); } else if (e.Key == Key.Escape) { Button_Click_Question_No(sender, e); } } } }