EditModelPriceViewController.m 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. //
  2. // EditModelPriceViewController.m
  3. // RedAnt ERP Mobile
  4. //
  5. // Created by Ray on 9/16/15.
  6. // Copyright (c) 2015 United Software Applications, Inc. All rights reserved.
  7. //
  8. #import "EditModelPriceViewController.h"
  9. #import "RAUtils.h"
  10. #import "RANetwork.h"
  11. #define NUMBERS @"0123456789.\n"
  12. @interface EditModelPriceViewController ()
  13. @end
  14. @implementation EditModelPriceViewController
  15. - (void)viewDidLoad {
  16. [super viewDidLoad];
  17. self.editPrice.text = [NSString stringWithFormat:@"%.2f", self.price ];
  18. self.editDiscount.text = [NSString stringWithFormat:@"%@", [RAUtils FloatFormat:self.discount] ];
  19. self.labelNewPrice.text = [NSString stringWithFormat:@"%.2f",self.price* (1.0-self.discount/100)];
  20. if(self.hide_discount)
  21. {
  22. self.editDiscount.hidden=true;
  23. self.labelDiscount.hidden=true;
  24. self.labelCalPrice.text = @"New price:";
  25. }
  26. // Do any additional setup after loading the view.
  27. }
  28. - (void)didReceiveMemoryWarning {
  29. [super didReceiveMemoryWarning];
  30. // Dispose of any resources that can be recreated.
  31. }
  32. /*
  33. #pragma mark - Navigation
  34. // In a storyboard-based application, you will often want to do a little preparation before navigation
  35. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  36. // Get the new view controller using [segue destinationViewController].
  37. // Pass the selected object to the new view controller.
  38. }
  39. */
  40. - (IBAction)onCloseClicked:(id)sender {
  41. [self dismissViewControllerAnimated:NO
  42. completion:^{
  43. }];
  44. }
  45. - (IBAction)onSaveClicked:(id)sender {
  46. if([self.editDiscount.text floatValue]>100.0)
  47. {
  48. [RAUtils message_box:@"Some Requried Fields Are Missing." message:@"Fields with * mark cannot be empty." completion:nil];
  49. self.editDiscount.text=@"0";
  50. return;
  51. }
  52. [self update_newprice];
  53. [self dismissViewControllerAnimated:NO
  54. completion:^{
  55. if(self.onSetValue)
  56. self.onSetValue( self.price,self.discount);
  57. }];
  58. }
  59. #pragma mark textField delegate
  60. - (BOOL)textFieldShouldReturn:(UITextField *)textField {
  61. [textField resignFirstResponder];
  62. return NO;
  63. }
  64. -(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
  65. if(textField.text.length==0 && [string isEqualToString:@"."])
  66. return false;
  67. NSCharacterSet *cs;
  68. cs = [[NSCharacterSet characterSetWithCharactersInString:NUMBERS]invertedSet];
  69. //
  70. NSString *filtered = [[string componentsSeparatedByCharactersInSet:cs]componentsJoinedByString:@""];
  71. BOOL canChange = [string isEqualToString:filtered];
  72. //
  73. //
  74. //
  75. //
  76. return canChange;
  77. // return true;
  78. }
  79. -(void) update_newprice
  80. {
  81. self.price = [self.editPrice.text doubleValue];
  82. self.discount = [self.editDiscount.text doubleValue];
  83. self.labelNewPrice.text = [NSString stringWithFormat:@"%.2f",self.price* (1.0-self.discount/100)];
  84. }
  85. - (void)textFieldDidEndEditing:(UITextField *)textField
  86. {
  87. if(textField.tag==2)
  88. {
  89. if(textField.text.length==0)
  90. textField.text=@"0";
  91. if([textField.text floatValue]>100.0)
  92. {
  93. [RAUtils message_box:@"Input Error." message:@"Discount must less than 100." completion:nil];
  94. textField.text=@"0";
  95. }
  96. }
  97. else
  98. {
  99. float f = [textField.text floatValue];
  100. textField.text=[NSString stringWithFormat:@"%.2f",f];
  101. }
  102. [self update_newprice];
  103. }
  104. - (void)textFieldDidBeginEditing:(UITextField *)textField
  105. {
  106. //
  107. // self.lastedit = textField;
  108. }
  109. @end