OrderDiscountViewController.m 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. //
  2. // OrderDiscountViewController.m
  3. // iSales-CONTRAST
  4. //
  5. // Created by Rui Zhang on 7/5/22.
  6. // Copyright © 2022 United Software Applications, Inc. All rights reserved.
  7. //
  8. #import "OrderDiscountViewController.h"
  9. #import "RAUtils.h"
  10. #define NUMBERS @"0123456789\n"
  11. @interface OrderDiscountViewController ()
  12. @end
  13. @implementation OrderDiscountViewController
  14. - (void)viewDidLoad {
  15. [super viewDidLoad];
  16. // Do any additional setup after loading the view.
  17. }
  18. /*
  19. #pragma mark - Navigation
  20. // In a storyboard-based application, you will often want to do a little preparation before navigation
  21. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  22. // Get the new view controller using [segue destinationViewController].
  23. // Pass the selected object to the new view controller.
  24. }
  25. */
  26. - (IBAction)onUpdate:(id)sender {
  27. if([self.textfieldDiscount.text intValue]>100)
  28. {
  29. [RAUtils message_box:@"Warrning" message:@"Illegal input" completion:nil];
  30. return;
  31. }
  32. [self dismissViewControllerAnimated:NO
  33. completion:^{
  34. if(self.onSetValue)
  35. self.onSetValue( [self.textfieldDiscount.text intValue]);
  36. }];
  37. }
  38. - (IBAction)onCancel:(id)sender {
  39. [self dismissViewControllerAnimated:NO
  40. completion:^{
  41. }];
  42. }
  43. -(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
  44. // DebugLog(@"text:%@",textField.text);
  45. NSCharacterSet *cs;
  46. cs = [[NSCharacterSet characterSetWithCharactersInString:NUMBERS]invertedSet];
  47. NSString *filtered = [[string componentsSeparatedByCharactersInSet:cs]componentsJoinedByString:@""];
  48. BOOL canChange = [string isEqualToString:filtered];
  49. return canChange;
  50. }
  51. @end