PopModeViewController.m 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. //
  2. // PopModeViewController.m
  3. // RA Image
  4. //
  5. // Created by Jack on 2017/5/2.
  6. // Copyright © 2017年 USAI. All rights reserved.
  7. //
  8. #import "config.h"
  9. #import "PopModeViewController.h"
  10. #import "UploadViewController.h"
  11. #import "AESCrypt.h"
  12. @interface PopModeViewController ()
  13. @property (strong, nonatomic) IBOutlet UIButton *scanBtn;
  14. @property (strong, nonatomic) IBOutlet UIButton *camerBtn;
  15. @property (strong, nonatomic) IBOutlet UIButton *uploadBtn;
  16. @property (strong, nonatomic) IBOutlet UIButton *imgBtn;
  17. @property (strong, nonatomic) IBOutlet UILabel *barcodeLabel;
  18. @property (strong, nonatomic) IBOutlet UIButton *typeBtn;
  19. @property (strong, nonatomic) IBOutlet UILabel *photoCountLabel;
  20. @end
  21. @implementation PopModeViewController
  22. - (void)viewDidLoad {
  23. [super viewDidLoad];
  24. self.verify_msg0=[NSString stringWithFormat:@"%@ does not exist",self.barcodeTitle];
  25. // Do any additional setup after loading the view.
  26. self.imgBtn.layer.borderColor = [UIColor blackColor].CGColor;
  27. self.imgBtn.layer.borderWidth = 1.0f;
  28. self.barcodeLabel.text = [NSString stringWithFormat:@"%@:",self.barcodeTitle];
  29. }
  30. - (void)didReceiveMemoryWarning {
  31. [super didReceiveMemoryWarning];
  32. // Dispose of any resources that can be recreated.
  33. }
  34. #pragma mark - Private
  35. - (void)clear {
  36. self.barcode = nil;
  37. [self.imgBtn setBackgroundImage:nil forState:UIControlStateNormal];
  38. [self clearPhotos];
  39. }
  40. #pragma mark - Button Action
  41. - (IBAction)imgBtnClick:(UIButton *)sender {
  42. [self showPhotoList];
  43. }
  44. - (IBAction)scanBtnClick:(UIButton *)sender {
  45. [self showScanner];
  46. }
  47. - (IBAction)cameraBtnClick:(UIButton *)sender {
  48. [self clickCameraButton];
  49. }
  50. - (IBAction)uploadBtnClick:(UIButton *)sender {
  51. if (![self shouldUploadWithCurrentNerworkStatus]) {
  52. [self.view makeToast:@"Current network is not WiFi" duration:3.0 position:CSToastPositionCenter];
  53. return;
  54. }
  55. // check piid, photo...
  56. if(self.barcode.length ==0)
  57. {
  58. [RAUtils message_alert:[NSString stringWithFormat:@"%@ cann't be blank",self.barcodeTitle] title:@"Warning" controller:self];
  59. return;
  60. }
  61. if(self.photos.count ==0)
  62. {
  63. [RAUtils message_alert:@"You must take at least one photo." title:@"Warning" controller:self];
  64. return;
  65. }
  66. AppDelegate* Appdelegate=(AppDelegate*)[UIApplication sharedApplication].delegate;
  67. NSString* encryptu=[AESCrypt AES128Encrypt:Appdelegate.user key:@"usai"];
  68. NSString* encryptp=[AESCrypt AES128Encrypt:Appdelegate.password key:@"usai"];
  69. NSMutableDictionary* params = [@{
  70. @"user" : encryptu,
  71. @"password" : encryptp,
  72. @"mode":self.name,
  73. @"barcode":self.barcode,
  74. @"_operate":@"valid_upload",
  75. @"platform":@"ios",
  76. } mutableCopy];
  77. [self verify:params];
  78. // UploadViewController *upVC = (UploadViewController *)[self viewControllerInStoryboard:@"Upload" withId:@"UploadViewController"];
  79. // [self.navigationController pushViewController:upVC animated:YES];
  80. }
  81. -(void)addTasks
  82. {
  83. AppDelegate* Appdelegate=(AppDelegate*)[UIApplication sharedApplication].delegate;
  84. //prepare upload
  85. NSMutableArray* tasks = [NSMutableArray new];
  86. for(NSMutableDictionary* photo in self.photos)
  87. {
  88. NSMutableDictionary* task=[[NSMutableDictionary alloc]init];
  89. task[@"path"]=self.name;
  90. task[@"file"]=photo[@"file"];
  91. task[@"url"]=Appdelegate.address;
  92. NSString *md5 = [photo objectForKey:@"md5"];
  93. NSString* encryptu=[AESCrypt AES128Encrypt:Appdelegate.user key:@"usai"];
  94. NSString* encryptp=[AESCrypt AES128Encrypt:Appdelegate.password key:@"usai"];
  95. NSDictionary* params = @{
  96. @"user" : encryptu,
  97. @"password" : encryptp,
  98. @"mode":self.name,
  99. @"barcode":self.barcode,
  100. @"_operate":@"upload",
  101. @"platform":@"ios",
  102. @"md5":md5
  103. };
  104. task[@"params"]=params;
  105. NSString *file = photo[@"file"];
  106. [self moveTmpImageToCache:file];
  107. [tasks addObject:task];
  108. }
  109. // // add upload tasks;
  110. [Appdelegate.uploadManager addTasks:tasks];
  111. [self clear];
  112. }
  113. - (IBAction)typeBtnClick:(UIButton *)sender {
  114. [self showBarcodeInput:self.inputKeyboardType];//UIKeyboardTypeNumberPad
  115. }
  116. #pragma mark - Super Method
  117. - (void)receiveImage:(UIImage *)img {
  118. [self.imgBtn setBackgroundImage:img forState:UIControlStateNormal];
  119. }
  120. - (void)setBarcode:(NSString *)barcode {
  121. [super setBarcode:barcode];
  122. if (!barcode) {
  123. barcode = @"";
  124. }
  125. else
  126. {
  127. if(![RAUtils isNumeric:barcode]&&![self.name isEqualToString:@"Receiving"])
  128. {
  129. NSString* msg = [NSString stringWithFormat:@"%@ must be a number",self.barcodeTitle];
  130. [self.view makeToast:msg duration:3.0 position:CSToastPositionCenter];
  131. barcode = @"";
  132. }
  133. }
  134. self.barcodeLabel.text = [NSString stringWithFormat:@"%@:%@",self.barcodeTitle,barcode];
  135. }
  136. - (void)setPhotoCount:(NSUInteger)photoCount {
  137. [super setPhotoCount:photoCount];
  138. NSString *str = nil;
  139. if (photoCount > 0) {
  140. str = [NSString stringWithFormat:@"%lu Photos",photoCount];
  141. } else {
  142. str = @"No Photos";
  143. }
  144. self.photoCountLabel.text = str;
  145. }
  146. @end