using System; using System.Collections.Generic; using System.Globalization; using System.Linq; using System.Text; using System.Text.RegularExpressions; using System.Threading; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; using SPC.Kiosk.Base; namespace SPC.Kiosk.Common { /// /// NumericPad.xaml에 대한 상호 작용 논리 /// public partial class NumericPad2 : UserControl { #region [ Members ] /// /// Noraml Bakcground /// public static readonly DependencyProperty NormalBrushProperty = DependencyProperty.Register(nameof(NormalBrush), typeof(string), typeof(NumericPad2), new PropertyMetadata("White")); /// /// Touch Down Bakcground /// public static readonly DependencyProperty DownBrushProperty = DependencyProperty.Register(nameof(DownBrush), typeof(string), typeof(NumericPad2), new PropertyMetadata("DarkGray")); /// /// Cancel Noraml Bakcground /// public static readonly DependencyProperty CancelNormalBrushProperty = DependencyProperty.Register(nameof(CancelNormalBrush), typeof(string), typeof(NumericPad2), new PropertyMetadata("DarkRed")); /// /// Cancel Down Bakcground /// public static readonly DependencyProperty CancelDownBrushProperty = DependencyProperty.Register(nameof(CancelDownBrush), typeof(string), typeof(NumericPad2), new PropertyMetadata("DarkGray")); /// /// Click Animation Type /// public static readonly DependencyProperty ClickAnimationTypeProperty = DependencyProperty.Register(nameof(ClickAnimationType), typeof(ButtonAnimationType), typeof(NumericPad2), new PropertyMetadata(ButtonAnimationType.None)); /// /// Button Text Foreground /// public static readonly DependencyProperty TextForegroundProperty = DependencyProperty.Register(nameof(TextForeground), typeof(string), typeof(NumericPad2), new PropertyMetadata("Black")); /// /// Cancel & Back Button Foreground /// public static readonly DependencyProperty CancelForegroundProperty = DependencyProperty.Register(nameof(CancelForeground), typeof(string), typeof(NumericPad2), new PropertyMetadata("White")); /// /// Input Text /// public static readonly DependencyProperty InputTextProperty = DependencyProperty.Register(nameof(InputText), typeof(string), typeof(NumericPad2), new PropertyMetadata(string.Empty, new PropertyChangedCallback(OnInputTextPropertyChanged))); /// /// Show Text With Mask /// public static readonly DependencyProperty ShowTextProperty = DependencyProperty.Register(nameof(ShowText), typeof(string), typeof(NumericPad2), new PropertyMetadata(string.Empty)); /// /// Text Area Visible /// public static readonly DependencyProperty TextVisibleProperty = DependencyProperty.Register(nameof(TextVisibility), typeof(Visibility), typeof(NumericPad2), new PropertyMetadata(Visibility.Visible)); /// /// Guid Text (Mutil Language) /// public static readonly DependencyProperty GuidTextProperty = DependencyProperty.Register(nameof(GuidText), typeof(List), typeof(NumericPad2), new PropertyMetadata(default(List), new PropertyChangedCallback(OnGuidTextPropertyChanged))); /// /// Cancel Text /// public static readonly DependencyProperty CancelTextProperty = DependencyProperty.Register(nameof(CancelText), typeof(string), typeof(NumericPad2), new PropertyMetadata("Cancel", new PropertyChangedCallback(OnCancelTextPropertyChanged))); /// /// Cancel Text (Mutil Language) /// public static readonly DependencyProperty CancelLanguageTextProperty = DependencyProperty.Register(nameof(CancelLanguageText), typeof(List), typeof(NumericPad2), new PropertyMetadata(default(List), new PropertyChangedCallback(OnCancelLanguageTextPropertyChanged))); /// /// Display Language Type /// public static readonly DependencyProperty DisplayLanguagePropery = DependencyProperty.Register(nameof(DisplayLanguage), typeof(SupportLanguageType), typeof(NumericPad2), new PropertyMetadata(SupportLanguageType.ko, new PropertyChangedCallback(OnDisplayLanguageProperyChanged))); /// /// Max input Length /// public static readonly DependencyProperty MaxLengthPropery = DependencyProperty.Register(nameof(MaxLength), typeof(int), typeof(NumericPad2), new PropertyMetadata(0)); /// /// Is Formated Show Text /// public static readonly DependencyProperty FormatedPropery = DependencyProperty.Register(nameof(Formated), typeof(bool), typeof(NumericPad2), new PropertyMetadata(false)); /// /// Is Formated Show Text /// public bool Formated { get { return (bool)GetValue(FormatedPropery); } set { SetValue(FormatedPropery, value); } } /// /// Max input Length /// public int MaxLength { get { return (int)GetValue(MaxLengthPropery); } set { SetValue(MaxLengthPropery, value); } } /// /// Text Area Visibility /// public Visibility TextVisibility { get { return (Visibility)GetValue(TextVisibleProperty); } set { SetValue(TextVisibleProperty, value); } } /// /// Input Text (Real Data) /// public string InputText { get { return (string)GetValue(InputTextProperty); } set { SetValue(InputTextProperty, value); } } /// /// Show Text With Mask /// public string ShowText { get { return (string)GetValue(ShowTextProperty); } set { SetValue(ShowTextProperty, value); } } /// /// Guid Text (Multi Language) /// public List GuidText { get { return (List)GetValue(GuidTextProperty); } set { SetValue(GuidTextProperty, value); } } /// /// Display Language Type /// public SupportLanguageType DisplayLanguage { get { return (SupportLanguageType)GetValue(DisplayLanguagePropery); } set { SetValue(DisplayLanguagePropery, value); } } /// /// Cancel Text /// public string CancelText { get { return (string)GetValue(CancelTextProperty); } set { SetValue(CancelTextProperty, value); } } /// /// Cancel Text (Multi Language) /// public List CancelLanguageText { get { return (List)GetValue(CancelLanguageTextProperty); } set { SetValue(CancelLanguageTextProperty, value); } } /// /// Noraml Bakcground /// public string NormalBrush { get { return (string)GetValue(NormalBrushProperty); } set { SetValue(NormalBrushProperty, value); } } /// /// Mouse/Touch Down Bakcground /// public string DownBrush { get { return (string)GetValue(DownBrushProperty); } set { SetValue(DownBrushProperty, value); } } /// /// Cancel Button NormalBrush /// public string CancelNormalBrush { get { return (string)GetValue(CancelNormalBrushProperty); } set { SetValue(CancelNormalBrushProperty, value); } } /// /// Mouse/Touch Down Bakcground /// public string CancelDownBrush { get { return (string)GetValue(CancelDownBrushProperty); } set { SetValue(CancelDownBrushProperty, value); } } /// /// Button Animation Type /// public ButtonAnimationType ClickAnimationType { get { return (ButtonAnimationType)GetValue(ClickAnimationTypeProperty); } set { SetValue(ClickAnimationTypeProperty, value); } } /// /// Button Text Foreground /// public string TextForeground { get { return (string)GetValue(TextForegroundProperty); } set { SetValue(TextForegroundProperty, value); } } /// /// Cancel Button Foreground /// public string CancelForeground { get { return (string)GetValue(CancelForegroundProperty); } set { SetValue(CancelForegroundProperty, value); } } #endregion Members #region [ Ctor/Etc ] /// /// Ctor /// public NumericPad2() { InitializeComponent(); foreach (var aElement in this.BaseGrid.Children) { if (aElement is AnimationButton aNumberButton) { aNumberButton.MouseClicked += NumberButton_MouseClicked; } } } #endregion Ctor #region [ Methods ] private void SetShowText(string _showText) { string displayText = _showText; if (!string.IsNullOrEmpty(displayText)) { if (displayText.Length < 10) { //pass } else if (displayText.Length.Equals(10) && Formated) { var displayChars = displayText.ToCharArray(); displayText = string.Empty; for (int i = 0; i < displayChars.Length; i++) { if (i > 2 && i < 6) { displayText += '*'; } else { displayText += displayChars[i]; } } } else if (displayText.Length.Equals(11) && Formated) { var displayChars = displayText.ToCharArray(); displayText = string.Empty; for (int i = 0; i < displayChars.Length; i++) { if (i > 2 && i < 7) { displayText += '*'; } else { displayText += displayChars[i]; } } } else if (displayText.Length < 17 && Formated) { var displayChars = displayText.ToCharArray(); displayText = string.Empty; for (int i = 0; i < displayChars.Length; i++) { if (i > 5 && i < 14) { displayText += '*'; } else { displayText += displayChars[i]; } } } else if (Formated) { var displayChars = displayText.ToCharArray(); displayText = string.Empty; for (int i = 0; i < displayChars.Length; i++) { if (i > 3 && i < 16) { displayText += '*'; } else { displayText += displayChars[i]; } } } string formatedString = string.Empty; if (Formated) { if (displayText.Length.Equals(10)) { formatedString = string.Format("{0}-{1}-{2}" , displayText.Substring(0, 3) , displayText.Substring(3, 3) , displayText.Substring(6, 4)); } else if (displayText.Length.Equals(11)) { formatedString = string.Format("{0}-{1}-{2}" , displayText.Substring(0, 3) , displayText.Substring(3, 4) , displayText.Substring(7, 4)); } else if (displayText.Length.Equals(16)) { formatedString = string.Format("{0}-{1}-{2}-{3}" , displayText.Substring(0, 4) , displayText.Substring(4, 4) , displayText.Substring(8, 4) , displayText.Substring(12, 4)); } else if (displayText.Length.Equals(20)) { formatedString = string.Format("{0}-{1}-{2}-{3}-{4}" , displayText.Substring(0, 4) , displayText.Substring(4, 4) , displayText.Substring(8, 4) , displayText.Substring(12, 4) , displayText.Substring(16, 4)); } } else { formatedString = (int.Parse(displayText)).ToString("#,###"); } if (!string.IsNullOrEmpty(formatedString)) displayText = formatedString; this.ShowText = displayText; } else { this.ShowText = this.GuidText.GetLanguageData(this.DisplayLanguage); } } private double SetEtcTextFontSize(AnimationButton _target, string _text) { double result = 20d; try { var textLength = string.IsNullOrEmpty(_text.Trim()) ? 1 : _text.Trim().Length; var fontSize = 0d; switch (textLength) { case 1: case 2: case 3: case 4: fontSize = 0.35; break; default: fontSize = 0.3; break; } result = _target.ActualHeight > 0 ? _target.ActualHeight * fontSize : 20d; } catch { result = 20d; } return result; } #endregion Methods #region [ Event Handlers ] private static void OnCancelTextPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { if (e.NewValue != null ) { var target = d as NumericPad2; var aElement = target.BaseGrid.FindName("ButtonCancel"); if (aElement is AnimationButton aNumberButton) { var newFontSize = target.SetEtcTextFontSize(aNumberButton, (string)e.NewValue); target.ButtonCancel.TextFontSize = newFontSize; } } } private static void OnCancelLanguageTextPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { if (e.NewValue != null ) { var target = d as NumericPad2; var aElement = target.BaseGrid.FindName("ButtonCancel"); if (aElement is AnimationButton aNumberButton) { var newFontSize = target.SetEtcTextFontSize(aNumberButton ,((List)e.NewValue).GetLanguageData(target.DisplayLanguage)); target.ButtonCancel.TextFontSize = newFontSize; } } } private static void OnGuidTextPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { if (e.NewValue != null) { var target = d as NumericPad2; target.SetShowText(target.InputText); } } private static void OnDisplayLanguageProperyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { if (e.NewValue != null ) { var target = d as NumericPad2; foreach (var aElement in target.BaseGrid.Children) { if (aElement is AnimationButton aNumberButton && aNumberButton.Name.StartsWith("ButtonCancel")) { aNumberButton.DisplayLanguage = (SupportLanguageType)e.NewValue; } } target.SetShowText(target.InputText); } } private static void OnInputTextPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { var target = d as NumericPad2; var inputText = (string)e.NewValue; target.SetShowText(inputText); } private void NumberButton_MouseClicked(object sender, RoutedEventArgs e) { if (sender is AnimationButton aNumberButton) { switch (aNumberButton.Name) { case nameof(ButtonCancel): this.InputText = string.Empty; break; case nameof(ButtonBack): if (this.InputText != null && this.InputText.Length > 0) { this.InputText = this.InputText.Remove(this.InputText.Length - 1, 1); } break; default: if (!this.MaxLength.Equals(0) ) { if (this.InputText.Length < this.MaxLength) { this.InputText = this.InputText + aNumberButton.Text; } } else { if (!(this.InputText.Length.Equals(0) && aNumberButton.Text.Equals("0"))) { this.InputText = this.InputText + aNumberButton.Text; } } break; } } } #endregion Event Handlers } }