AmountManagerView.xaml.cs 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. using Muchinfo.MTPClient.Bank.ViewModels;
  2. using Muchinfo.MTPClient.Data.Enums;
  3. using System;
  4. using System.Windows;
  5. using System.Windows.Controls;
  6. namespace Muchinfo.MTPClient.Bank.Views
  7. {
  8. /// <summary>
  9. /// AmountManagerView.xaml 的交互逻辑
  10. /// </summary>
  11. public partial class AmountManagerView : Window
  12. {
  13. public AmountManagerView(FundsApplyType applyType)
  14. {
  15. InitializeComponent();
  16. this.DataContext = new AmountManagerViewModel(applyType);
  17. this.Closed += AmountManagerView_Closed;
  18. }
  19. void AmountManagerView_Closed(object sender, EventArgs e)
  20. {
  21. var viewmodel = this.DataContext as AmountManagerViewModel;
  22. if (viewmodel != null)
  23. {
  24. viewmodel.Cleanup();
  25. }
  26. }
  27. private void TextBox_TextChanged(object sender, System.Windows.Controls.TextChangedEventArgs e)
  28. {
  29. try
  30. {
  31. //屏蔽中文输入和非法字符粘贴输入
  32. TextBox textBox = sender as TextBox;
  33. TextChange[] change = new TextChange[e.Changes.Count];
  34. e.Changes.CopyTo(change, 0);
  35. int offset = change[0].Offset;
  36. decimal numb = 0;
  37. if (change[0].AddedLength > 0)
  38. {
  39. if (!decimal.TryParse(textBox.Text, out numb))
  40. {
  41. textBox.Text = textBox.Text.Remove(offset, change[0].AddedLength);
  42. textBox.Select(offset, 0);
  43. }
  44. string[] strArray = textBox.Text.Split('.');
  45. if (strArray != null && strArray.Length == 2)
  46. {
  47. if (strArray[1].Length > 2)
  48. {
  49. textBox.Text = textBox.Text.Remove(offset, change[0].AddedLength);
  50. textBox.Select(offset, 0);
  51. }
  52. }
  53. }
  54. }
  55. catch (System.Exception ex)
  56. {
  57. }
  58. }
  59. private void TextBox_KeyUp(object sender, System.Windows.Input.KeyEventArgs e)
  60. {
  61. TextBox textBox = sender as TextBox;
  62. if (string.IsNullOrEmpty(textBox.Text))
  63. {
  64. textBox.Text = "0";
  65. textBox.SelectAll();
  66. }
  67. }
  68. private void GetFocus(object sender, System.Windows.RoutedEventArgs e)
  69. {
  70. TextBox textB = sender as TextBox;
  71. if (textB.Text == "0")
  72. {
  73. textB.SelectAll();
  74. }
  75. }
  76. private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
  77. {
  78. var window = new InMoneyGuide()
  79. {
  80. Owner = Application.Current.MainWindow,
  81. WindowStartupLocation = WindowStartupLocation.CenterOwner
  82. };
  83. window.Show();
  84. }
  85. }
  86. }