NDeliveryOrderView.xaml.cs 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. using Muchinfo.MTPClient.Data.Model.Delivery;
  2. using Muchinfo.MTPClient.Delivery.ViewModels;
  3. using System.Windows;
  4. using System.Windows.Input;
  5. using Xceed.Wpf.Toolkit;
  6. namespace Muchinfo.MTPClient.Delivery.Views
  7. {
  8. /// <summary>
  9. /// Description for NDeliveryOrderView.
  10. /// </summary>
  11. public partial class NDeliveryOrderView : Window
  12. {
  13. /// <summary>
  14. /// Initializes a new instance of the NDeliveryOrderView class.
  15. /// </summary>
  16. public NDeliveryOrderView()
  17. {
  18. InitializeComponent();
  19. }
  20. public NDeliveryOrderView(DeliveryOrderMessage parameter)
  21. {
  22. InitializeComponent();
  23. this.DataContext = new NDeliveryOrderViewModel(parameter);
  24. }
  25. private void SelectQty_KeyDown(object sender, KeyEventArgs e)
  26. {
  27. var txtInput = (DecimalUpDown)sender;
  28. if ((e.Key >= Key.NumPad0 && e.Key <= Key.NumPad9) || (e.Key >= Key.D0 && e.Key <= Key.D9))
  29. {
  30. e.Handled = false;
  31. }
  32. else if ((e.Key == Key.Decimal || e.Key == Key.OemPeriod))
  33. {
  34. e.Handled = false;
  35. }
  36. else
  37. {
  38. e.Handled = true;
  39. }
  40. if (txtInput.Text!=null && txtInput.Text.Contains(".") && txtInput.Text.Length >= 8)
  41. {
  42. e.Handled = true;
  43. }
  44. else if (txtInput.Text!=null && !txtInput.Text.Contains(".") && txtInput.Text.Length >= 6)
  45. {
  46. e.Handled = true;
  47. }
  48. if (!string.IsNullOrEmpty(txtInput.Text))
  49. {
  50. var current = decimal.Parse(txtInput.Text);
  51. if (current > txtInput.Maximum)
  52. {
  53. txtInput.Text = txtInput.Maximum.ToString();
  54. }
  55. }
  56. }
  57. private void DecimalUpDown_KeyDown(object sender, System.Windows.Input.KeyEventArgs e)
  58. {
  59. var txtInput = (DecimalUpDown)sender;
  60. if (txtInput.Text.Length >= 6)
  61. {
  62. e.Handled = true;
  63. }
  64. else
  65. {
  66. e.Handled = false;
  67. }
  68. }
  69. }
  70. }