| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163 |
- //
- // EditModelPriceViewController.m
- // RedAnt ERP Mobile
- //
- // Created by Ray on 9/16/15.
- // Copyright (c) 2015 United Software Applications, Inc. All rights reserved.
- //
- #import "EditModelPriceViewController.h"
- #import "RAUtils.h"
- #import "RANetwork.h"
- #define NUMBERS @"0123456789.\n"
- @interface EditModelPriceViewController ()
- @end
- @implementation EditModelPriceViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
-
- self.editPrice.text = [NSString stringWithFormat:@"%.2f", self.price ];
-
-
- self.editDiscount.text = [NSString stringWithFormat:@"%@", [RAUtils FloatFormat:self.discount] ];
-
- self.labelNewPrice.text = [NSString stringWithFormat:@"%.2f",self.price* (1.0-self.discount/100)];
-
- if(self.hide_discount)
- {
- self.editDiscount.hidden=true;
- self.labelDiscount.hidden=true;
- self.labelCalPrice.text = @"New price:";
-
-
-
- }
- // Do any additional setup after loading the view.
- }
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- /*
- #pragma mark - Navigation
- // In a storyboard-based application, you will often want to do a little preparation before navigation
- - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
- // Get the new view controller using [segue destinationViewController].
- // Pass the selected object to the new view controller.
- }
- */
- - (IBAction)onCloseClicked:(id)sender {
- [self dismissViewControllerAnimated:NO
- completion:^{
-
-
- }];
- }
- - (IBAction)onSaveClicked:(id)sender {
-
-
-
- if([self.editDiscount.text floatValue]>100.0)
- {
-
- [RAUtils message_box:@"Some Requried Fields Are Missing." message:@"Fields with * mark cannot be empty." completion:nil];
-
- self.editDiscount.text=@"0";
-
- return;
- }
-
-
- [self update_newprice];
-
-
- [self dismissViewControllerAnimated:NO
- completion:^{
- if(self.onSetValue)
- self.onSetValue( self.price,self.discount);
-
- }];
- }
- #pragma mark textField delegate
- - (BOOL)textFieldShouldReturn:(UITextField *)textField {
- [textField resignFirstResponder];
- return NO;
- }
- -(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
-
-
- if(textField.text.length==0 && [string isEqualToString:@"."])
- return false;
-
- NSCharacterSet *cs;
- cs = [[NSCharacterSet characterSetWithCharactersInString:NUMBERS]invertedSet];
- //
- NSString *filtered = [[string componentsSeparatedByCharactersInSet:cs]componentsJoinedByString:@""];
-
- BOOL canChange = [string isEqualToString:filtered];
- //
- //
- //
- //
- return canChange;
- // return true;
- }
- -(void) update_newprice
- {
- self.price = [self.editPrice.text doubleValue];
-
- self.discount = [self.editDiscount.text doubleValue];
-
-
- self.labelNewPrice.text = [NSString stringWithFormat:@"%.2f",self.price* (1.0-self.discount/100)];
-
- }
- - (void)textFieldDidEndEditing:(UITextField *)textField
- {
-
- if(textField.tag==2)
- {
- if(textField.text.length==0)
- textField.text=@"0";
-
- if([textField.text floatValue]>100.0)
- {
-
-
-
- [RAUtils message_box:@"Input Error." message:@"Discount must less than 100." completion:nil];
- textField.text=@"0";
- }
- }
- else
- {
- float f = [textField.text floatValue];
- textField.text=[NSString stringWithFormat:@"%.2f",f];
- }
-
- [self update_newprice];
-
- }
- - (void)textFieldDidBeginEditing:(UITextField *)textField
- {
- //
- // self.lastedit = textField;
- }
- @end
|