AppDelegate.m 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045
  1. //
  2. // AppDelegate.m
  3. // RedAnt ERP Suite
  4. //
  5. // Created by Ray on 14-5-19.
  6. // Copyright (c) 2014年 United Software Applications, Inc. All rights reserved.
  7. //
  8. #import "AppDelegate.h"
  9. #import "UILabel+FontAppearance.h"
  10. #import "MainViewController.h"
  11. #import "PDFViewController.h"
  12. @implementation AppDelegate
  13. {
  14. #ifdef USE_SOFTSCAN
  15. DeviceInfo* _softScanDeviceInfo;
  16. #endif
  17. DeviceInfo* _deviceInfoToTrigger;
  18. }
  19. @synthesize price_hidden = _price_hidden;
  20. @synthesize ScanApi;
  21. @synthesize ScanApiConsumer;
  22. @synthesize scanApiVersion;
  23. //@synthesize devices;
  24. -(void) set_priceHidden:(bool)price_hidden
  25. {
  26. _price_hidden = price_hidden;
  27. ActiveViewController* avc=(ActiveViewController*)self.active_controller;
  28. // NSObject* obj;
  29. // [obj isEqual:@""];
  30. [avc showHidePrice];
  31. }
  32. -(void) set_main_button_panel
  33. {
  34. dispatch_async(dispatch_get_main_queue(), ^{
  35. if(self.main_vc==nil)
  36. return;
  37. MainViewController * main_vc= (MainViewController*)self.main_vc;
  38. if(self.user_type==USER_ROLE_CUSTOMER)
  39. {
  40. main_vc.customer_bp.hidden=false;
  41. main_vc.employee_bp.hidden = true;
  42. }
  43. else
  44. {
  45. main_vc.customer_bp.hidden=true;
  46. main_vc.employee_bp.hidden = false;
  47. }
  48. });
  49. }
  50. -(void) update_count_mark
  51. {
  52. dispatch_async(dispatch_get_main_queue(), ^{
  53. if(self.main_vc==nil)
  54. return;
  55. MainViewController * main_vc= (MainViewController*)self.main_vc;
  56. //cart
  57. if(self.user==nil||self.cart_count==0)
  58. {
  59. main_vc.label_ccount.hidden = true;
  60. main_vc.label_cccount.hidden=true;
  61. }
  62. else
  63. {
  64. NSString* strcount;
  65. if(self.cart_count>999)
  66. strcount=@"999+";
  67. else
  68. strcount=[NSString stringWithFormat:@"%ld",self.cart_count];
  69. main_vc.label_ccount.text = strcount;
  70. if(strcount.length==1)
  71. main_vc.label_ccount.frame = CGRectMake(128, 0, 21, 21);
  72. if(strcount.length==2)
  73. main_vc.label_ccount.frame = CGRectMake(122, 0, 25, 21);
  74. if(strcount.length==3)
  75. main_vc.label_ccount.frame = CGRectMake(118, 0, 31, 21);
  76. if(strcount.length==4)
  77. main_vc.label_ccount.frame = CGRectMake(103, 0, 42, 21);
  78. main_vc.label_ccount.hidden = false;
  79. main_vc.label_cccount.text = strcount;
  80. if(strcount.length==1)
  81. main_vc.label_cccount.frame = CGRectMake(128, 0, 21, 21);
  82. if(strcount.length==2)
  83. main_vc.label_cccount.frame = CGRectMake(122, 0, 25, 21);
  84. if(strcount.length==3)
  85. main_vc.label_cccount.frame = CGRectMake(118, 0, 31, 21);
  86. if(strcount.length==4)
  87. main_vc.label_cccount.frame = CGRectMake(103, 0, 42, 21);
  88. main_vc.label_cccount.hidden = false;
  89. }
  90. //wishlist
  91. if(self.user==nil||self.wish_count==0)
  92. {
  93. main_vc.label_wcount.hidden = true;
  94. main_vc.label_cwcount.hidden = true;
  95. }
  96. else
  97. {
  98. NSString* strcount;
  99. if(self.wish_count>999)
  100. strcount=@"999+";
  101. else
  102. strcount=[NSString stringWithFormat:@"%ld",self.wish_count];
  103. main_vc.label_wcount.text = strcount;
  104. if(strcount.length==1)
  105. main_vc.label_wcount.frame = CGRectMake(433, 0, 21, 21);
  106. if(strcount.length==2)
  107. main_vc.label_wcount.frame = CGRectMake(433-6, 0, 25, 21);//-6
  108. if(strcount.length==3)
  109. main_vc.label_wcount.frame = CGRectMake(433-10, 0, 31, 21);//-10
  110. if(strcount.length==4)
  111. main_vc.label_wcount.frame = CGRectMake(433-21, 0, 42, 21);//-21
  112. main_vc.label_wcount.hidden = false;
  113. main_vc.label_cwcount.text = strcount;
  114. if(strcount.length==1)
  115. main_vc.label_cwcount.frame = CGRectMake(433-79, 0, 21, 21);
  116. if(strcount.length==2)
  117. main_vc.label_cwcount.frame = CGRectMake(433-6-79, 0, 25, 21);//-6
  118. if(strcount.length==3)
  119. main_vc.label_cwcount.frame = CGRectMake(433-10-79, 0, 31, 21);//-10
  120. if(strcount.length==4)
  121. main_vc.label_cwcount.frame = CGRectMake(433-21-79, 0, 42, 21);//-21
  122. main_vc.label_cwcount.hidden = false;
  123. }
  124. });
  125. }
  126. -(void) closeOrder
  127. {
  128. self.order_code = nil;
  129. self.order_customer_id = nil;
  130. self.customerInfo = nil;
  131. self.contact_id = nil;
  132. // [self SetMode:nil];
  133. // [self SetSo:nil];
  134. [((MainViewController*)self.main_vc) reloadCart:true immediately:false];
  135. [((MainViewController*)self.main_vc) reloadOrder:true immediately:false];
  136. }
  137. -(void) switchToPreviousVC
  138. {
  139. MainViewController * main_vc= (MainViewController*)self.main_vc;
  140. [main_vc switchToPreviousVC];
  141. }
  142. -(void) SetMode:(NSString*)mode
  143. {
  144. dispatch_async(dispatch_get_main_queue(), ^{
  145. if(self.main_vc==nil)
  146. return;
  147. MainViewController * main_vc= (MainViewController*)self.main_vc;
  148. if(self.user==nil)
  149. {
  150. NSString* title = [NSString stringWithFormat:@"Sign in"];
  151. [main_vc.buttonUser setTitle:title forState:UIControlStateNormal];
  152. main_vc.labelMode.text=nil;
  153. [main_vc.labelMode setTextColor:UIColorFromRGB(0x336699)];
  154. // [main_vc.buttonUser setTitleColor:UIColorFromRGB(0x996633) forState:UIControlStateNormal];
  155. // main_vc.buttonUser.hidden=true;
  156. // main_vc.buttonUser.hidden=false;
  157. // [main_vc.headerView setNeedsDisplay];
  158. // [main_vc.headerView setNeedsLayout];
  159. return;
  160. }
  161. else
  162. {
  163. if(self.user_type==USER_ROLE_CUSTOMER)
  164. {
  165. NSString* title = [NSString stringWithFormat:@"%@",self.user];
  166. [main_vc.buttonUser setTitle:title forState:UIControlStateNormal];
  167. main_vc.labelMode.text=nil;
  168. [main_vc.labelMode setTextColor:UIColorFromRGB(0x336699)];
  169. // [main_vc.buttonUser setTitleColor:UIColorFromRGB(0x996633) forState:UIControlStateNormal];
  170. // main_vc.buttonUser.hidden=true;
  171. // main_vc.buttonUser.hidden=false;
  172. // [main_vc.headerView setNeedsDisplay];
  173. // [main_vc.headerView setNeedsLayout];
  174. }
  175. else
  176. {
  177. if([mode isEqualToString:@"Regular Mode"])
  178. {
  179. self.mode=@"Regular Mode";
  180. NSString* title = self.user;
  181. [main_vc.buttonUser setTitle:title forState:UIControlStateNormal];
  182. main_vc.labelMode.text=self.mode;
  183. [main_vc.labelMode setTextColor:UIColorFromRGB(0x336699)];
  184. // [main_vc.buttonUser setTitleColor:UIColorFromRGB(0x996633) forState:UIControlStateNormal];
  185. // main_vc.buttonUser.hidden=true;
  186. // main_vc.buttonUser.hidden=false;
  187. // [main_vc.headerView setNeedsDisplay];
  188. // [main_vc.headerView setNeedsLayout];
  189. }
  190. else
  191. {
  192. self.mode=@"Trade Show Mode";
  193. NSString* title = self.user;
  194. [main_vc.buttonUser setTitle:title forState:UIControlStateNormal];
  195. main_vc.labelMode.text=self.mode;
  196. [main_vc.labelMode setTextColor:UIColorFromRGB(0x009966)];
  197. // [main_vc.buttonUser setTitleColor:UIColorFromRGB(0x009966) forState:UIControlStateNormal];
  198. // main_vc.buttonUser.hidden=true;
  199. // main_vc.buttonUser.hidden=false;
  200. // [main_vc.headerView setNeedsDisplay];
  201. // [main_vc.headerView setNeedsLayout];
  202. }
  203. NSString * contact =[self.customerInfo valueForKey:@"customer_contact"];
  204. NSString * customer=[self.customerInfo valueForKey:@"customer_name"];
  205. if(self.customerInfo==nil)
  206. {
  207. // contact=@"No Name"; if(customerinfo==nil)
  208. // {
  209. contact=@"Select Contact";
  210. [main_vc.btnContact setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
  211. }
  212. else
  213. {
  214. if(contact==nil||contact.length==0)
  215. {
  216. contact=@"No Name";
  217. [main_vc.btnContact setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
  218. }
  219. else
  220. {
  221. [main_vc.btnContact setTitleColor:UIColorFromRGB(0x009900) forState:UIControlStateNormal];
  222. }
  223. }
  224. NSMutableArray* arr_contact = [[NSMutableArray alloc] init];
  225. if(contact.length>0)
  226. [arr_contact addObject:contact];
  227. if(customer.length>0)
  228. [arr_contact addObject:customer];
  229. NSString *contact_string = [arr_contact componentsJoinedByString:@" @"];
  230. [main_vc.btnContact setTitle:contact_string forState:UIControlStateNormal];
  231. }
  232. }
  233. });
  234. }
  235. -(void) SetSo:(NSString *)So
  236. {
  237. dispatch_async(dispatch_get_main_queue(), ^{
  238. if(self.main_vc==nil)
  239. return;
  240. MainViewController * main_vc= (MainViewController*)self.main_vc;
  241. if(self.user==nil)
  242. {
  243. // NSString* title = [NSString stringWithFormat:@"Sign in"];
  244. main_vc.labelSo.text=nil;
  245. return;
  246. }
  247. else
  248. {
  249. if(self.user_type==USER_ROLE_CUSTOMER)
  250. {
  251. main_vc.labelSo.text=nil;
  252. // main_vc.buttonUser.hidden=true;
  253. // main_vc.buttonUser.hidden=false;
  254. // [main_vc.headerView setNeedsDisplay];
  255. // [main_vc.headerView setNeedsLayout];
  256. }
  257. else
  258. {
  259. if(So.length==0)
  260. main_vc.labelSo.text=nil;
  261. else
  262. {
  263. NSString* text =[NSString stringWithFormat:@"SO#: %@",So];
  264. main_vc.labelSo.text=text;
  265. }
  266. }
  267. }
  268. });
  269. }
  270. //- (UIViewController*)topViewControllerWithRootViewController:(UIViewController*)rootViewController {
  271. // if ([rootViewController isKindOfClass:[UITabBarController class]]) {
  272. // UITabBarController* tabBarController = (UITabBarController*)rootViewController;
  273. // return [self topViewControllerWithRootViewController:tabBarController.selectedViewController];
  274. // } else if ([rootViewController isKindOfClass:[UINavigationController class]]) {
  275. // UINavigationController* navigationController = (UINavigationController*)rootViewController;
  276. // return [self topViewControllerWithRootViewController:navigationController.visibleViewController];
  277. // } else if (rootViewController.presentedViewController) {
  278. // UIViewController* presentedViewController = rootViewController.presentedViewController;
  279. // return [self topViewControllerWithRootViewController:presentedViewController];
  280. // } else {
  281. // return rootViewController;
  282. // }
  283. //}
  284. //- (UIViewController*)topViewController {
  285. // return [self topViewControllerWithRootViewController:[UIApplication sharedApplication].keyWindow.rootViewController];
  286. //}
  287. //-(UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
  288. ////   // Get topmost/visible view controller
  289. // UIViewController *currentViewController = [self topViewController];
  290. //
  291. // if ([currentViewController respondsToSelector:@selector(lockPortrait)]) {
  292. //
  293. // return UIInterfaceOrientationMaskPortrait;
  294. // }
  295. ////
  296. ////   // Only allow portrait (standard behaviour)
  297. // return UIInterfaceOrientationMaskAll;
  298. //}
  299. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
  300. {
  301. NSString* order_filter_source_path =[[NSBundle mainBundle] pathForResource:@"status_filter_cadedate" ofType:@"json" ];
  302. NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
  303. NSString *documents = [paths objectAtIndex:0];
  304. NSString *dist_path = [documents stringByAppendingPathComponent:@"status_filter_cadedate.json"];
  305. if ([[NSFileManager defaultManager] fileExistsAtPath:dist_path]) {
  306. NSLog(@"文件已经存在了");
  307. }
  308. else
  309. {
  310. // NSLog(@"resourceSampleImagesFolderPath=%@",resourceFolderPath);
  311. NSData *mainBundleFile = [NSData dataWithContentsOfFile:order_filter_source_path];
  312. // NSLog(@"mainBundleFile==%@",mainBundleFile);
  313. [[NSFileManager defaultManager] createFileAtPath:dist_path
  314. contents:mainBundleFile
  315. attributes:nil];
  316. }
  317. self.offline_mode = OFFLINE_MODE;
  318. // Override point for customization after application launch.
  319. if (! [iSalesDB initializeDb])
  320. // TODO: alert the user!
  321. DebugLog(@"couldn't init db");
  322. [[UIApplication sharedApplication] registerForRemoteNotificationTypes: UIRemoteNotificationTypeBadge |UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert];
  323. self.contact_id=nil;
  324. NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
  325. NSString * enable_cache = [defaults stringForKey:@"enable_cache"];
  326. if([enable_cache isEqualToString:@"false"])
  327. self.bEnable_Cache = false;
  328. else
  329. self.bEnable_Cache = true;
  330. NSDictionary* infoDict =[[NSBundle mainBundle] infoDictionary];
  331. self.build =[infoDict objectForKey:@"CFBundleVersion"];
  332. //scanner
  333. self.devices=[[NSMutableArray alloc]init];
  334. // change this to YES if you want SingleEntry to
  335. // confirm the decoded data
  336. _doAppDataConfirmation=NO;
  337. if(ScanApi==nil){
  338. #ifdef USE_SOFTSCAN
  339. // this is useful for SoftScan to keep a handle
  340. // that is used in the trigger button
  341. _softScanDeviceInfo=nil;
  342. #endif
  343. ScanApi=[[ScanApiHelper alloc]init];
  344. [ScanApi setDelegate:self];
  345. self.enable_ScannerLog = true;
  346. self.api_Status= API_STOP;
  347. }
  348. //UILabel * appearanceLabel = [UILabel appearanceWhenContainedIn:uialertcontroller.class, nil];
  349. // [appearanceLabel setAppearanceFont:[UIFont boldSystemFontOfSize:10]]; //for example
  350. return YES;
  351. }
  352. - (void)applicationWillResignActive:(UIApplication *)application
  353. {
  354. // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
  355. // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
  356. }
  357. - (void)applicationDidEnterBackground:(UIApplication *)application
  358. {
  359. // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
  360. // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
  361. }
  362. - (void)applicationWillEnterForeground:(UIApplication *)application
  363. {
  364. // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
  365. }
  366. - (void)applicationDidBecomeActive:(UIApplication *)application
  367. {
  368. // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
  369. }
  370. - (void)applicationWillTerminate:(UIApplication *)application
  371. {
  372. // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
  373. }
  374. -(void) Logout
  375. {
  376. self.user = nil;
  377. self.password=nil;
  378. self.user_icon=nil;
  379. self.user_type = 0;
  380. self.bLogin = false;
  381. self.contact_id=nil;
  382. self.customerInfo = nil;
  383. self.order_code = nil;
  384. [self SetMode:nil];
  385. }
  386. -(void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
  387. {
  388. self.duid = [[[[NSString stringWithFormat:@"%@",deviceToken] substringWithRange:NSMakeRange(0, 72)] substringWithRange:NSMakeRange(1, 71)] stringByReplacingOccurrencesOfString:@" " withString:@""];
  389. NSLog(@"regisger success:%@",deviceToken);
  390. //注册成功,将deviceToken保存到应用服务器数据库中
  391. }
  392. #pragma mark - Scaner
  393. -(void)onTimer: (NSTimer*)theTimer{
  394. if(theTimer==ScanApiConsumer){
  395. // [self addlog:@"ScanApi::doScanApiReceive:"];
  396. [ScanApi doScanApiReceive];
  397. }
  398. }
  399. -(void) addlog:(NSString*) newtext
  400. {
  401. if(!self.enable_ScannerLog)
  402. return;
  403. dispatch_async(dispatch_get_main_queue(), ^{
  404. NSString* date;
  405. NSDateFormatter* formatter = [[NSDateFormatter alloc]init];
  406. [formatter setDateFormat:@"YYYY-MM-dd hh:mm:ss"];
  407. date = [formatter stringFromDate:[NSDate date]];
  408. if(newtext.length<=0)
  409. return;
  410. NSString* text = self.log;
  411. if(text.length==0)
  412. text=@"";
  413. text = [NSString stringWithFormat:@"%@%@----------%@\n",text,date,newtext];
  414. self.log = text;
  415. ActiveViewController* avc=(ActiveViewController*)self.active_controller;
  416. [avc onLogUpdate];
  417. });
  418. }
  419. - (void)enableScanner:(bool)enable {
  420. [self addlog:@"Enable scanner:"];
  421. if(enable)
  422. {
  423. [self addlog:@"Enable"];
  424. self.api_Status = API_INIT;
  425. ActiveViewController* avc=(ActiveViewController*)self.active_controller;
  426. self.Status_Text = @"Initialize...";
  427. [avc onStatusChanged:@"Initialize..."];
  428. [ScanApi open];
  429. [self addlog:@"ScanApi open"];
  430. ScanApiConsumer=[NSTimer scheduledTimerWithTimeInterval:.2 target:self selector:@selector(onTimer:) userInfo:nil repeats:YES];
  431. [self addlog:@"ScanApiConsumer init"];
  432. // [ScanApi close];
  433. // [self addlog:@"ScanApi opent"];
  434. }
  435. else
  436. {
  437. [self addlog:@"Disable"];
  438. // [ScanApiConsumer invalidate];
  439. // ScanApiConsumer= nil;
  440. // [self addlog:@"ScanApiConsumer invalidate"];
  441. self.api_Status = API_CLOSING;
  442. ActiveViewController* avc=(ActiveViewController*)self.active_controller;
  443. self.Status_Text = @"Stoping...";
  444. [avc onStatusChanged:@"Stoping..."];
  445. [ScanApi close];
  446. [self addlog:@"ScanApi close"];
  447. }
  448. }
  449. #pragma mark - Device Info List management
  450. -(void) updateDevicesList:(DeviceInfo*) deviceInfo Add:(BOOL)add{
  451. [self addlog:@"updateDevicesList:"];
  452. if(add==YES){
  453. [self.devices addObject:deviceInfo];
  454. }
  455. else{
  456. [self.devices removeObject:deviceInfo];
  457. }
  458. NSMutableString* temp=[[NSMutableString alloc]init];
  459. for (DeviceInfo* info in self.devices) {
  460. [temp appendString:[info getName]];
  461. [temp appendString:@"\n"];
  462. }
  463. if(self.devices.count>0)
  464. [temp appendString:@"ready to scan"];
  465. else
  466. [temp appendString:@"Waiting for Scanner..."];
  467. // _Status.text=temp ;
  468. [self addlog:temp];
  469. ActiveViewController* avc=(ActiveViewController*)self.active_controller;
  470. self.Status_Text = temp;
  471. [avc onStatusChanged:temp];
  472. [avc OnUpdateDevicesList];
  473. // if ([self.active_controller respondsToSelector:@selector(lockPortrait)])
  474. // [self.dev_table reloadData];
  475. }
  476. #pragma mark - ScanApiHelper complete delegates
  477. // THE 2 FOLLOWING CALLBACKS ARE FOR DEMO ONLY FOR SHOWING HOW
  478. // TO CHECK IF A SYMBOLOGY IS ALREADY ENABLED AND IF NOT IT ENABLES
  479. // IT RIGHT THERE. THE GOAL IS TO CONFIGURE ONCE THE SCANNER WHEN IT
  480. // CONNECTS TO THE DEVICE. IF THERE IS NO SPECIFIC NEED TO CONFIGURE
  481. // THE SCANNER, THESE CALLBACKS CAN BE REMOVED
  482. // callback received when the Get Symbology Status is completed
  483. -(void)onGetSymbologyDpm:(ISktScanObject*)scanObj{
  484. [self addlog:@"onGetSymbologyDpm:"];
  485. SKTRESULT result=[[scanObj Msg]Result];
  486. if(SKTSUCCESS(result)){
  487. DeviceInfo* deviceInfo=[ScanApi getDeviceInfoFromScanObject:scanObj];
  488. if(deviceInfo!=nil){
  489. ISktScanSymbology* symbology=[[scanObj Property]Symbology];
  490. if([symbology getStatus]==kSktScanSymbologyStatusDisable){
  491. [ScanApi postSetSymbologyInfo:deviceInfo SymbologyId:kSktScanSymbologyDirectPartMarking Status:TRUE Target:self Response:@selector(onSetSymbology:)];
  492. }
  493. }
  494. }
  495. else{
  496. // an error message should be displayed here
  497. // indicating that the DPM symbology status cannot be retrieved
  498. }
  499. }
  500. // callback received when the Set Symbology Status is completed
  501. -(void)onSetSymbology:(ISktScanObject*)scanObj{
  502. [self addlog:@"onSetSymbology:"];
  503. SKTRESULT result=[[scanObj Msg]Result];
  504. if(!SKTSUCCESS(result)){
  505. // display an error message saying a symbology cannot be set
  506. }
  507. }
  508. /**
  509. *
  510. */
  511. -(void) onSetDataConfirmationMode:(ISktScanObject*)scanObj{
  512. [self addlog:@"onSetDataConfirmationMode:"];
  513. SKTRESULT result=[[scanObj Msg]Result];
  514. if(SKTSUCCESS(result)){
  515. [self addlog:@"DataConfirmation Mode OK"];
  516. }
  517. else{
  518. [self addlog:[NSString stringWithFormat:@"DataConfirmation Mode Error %ld",result]];
  519. }
  520. }
  521. /**
  522. *
  523. */
  524. -(void) onDataConfirmation:(ISktScanObject*)scanObj{
  525. [self addlog:@"onDataConfirmation:"];
  526. SKTRESULT result=[[scanObj Msg]Result];
  527. if(SKTSUCCESS(result)){
  528. [self addlog:@"Data Confirmed OK"];
  529. }
  530. else{
  531. [self addlog:[NSString stringWithFormat:@"Data Confirmed Error %ld",result]];
  532. }
  533. }
  534. /**
  535. *
  536. */
  537. -(void) onSetLocalDecodeAction:(ISktScanObject*)scanObj{
  538. [self addlog:@"onSetLocalDecodeAction:"];
  539. SKTRESULT result=[[scanObj Msg]Result];
  540. if(SKTSUCCESS(result)){
  541. [self addlog:@"Local Decode Action OK"];
  542. }
  543. else{
  544. [self addlog:[NSString stringWithFormat:@"Local Decode Action Error %ld",result]];
  545. }
  546. }
  547. /**
  548. *
  549. */
  550. -(void) onGetSoftScanStatus:(ISktScanObject*)scanObj{
  551. SKTRESULT result=[[scanObj Msg]Result];
  552. if(SKTSUCCESS(result)){
  553. ISktScanProperty* property=[scanObj Property];
  554. [self addlog:@"SoftScan status:"];
  555. if([property getByte]==kSktScanEnableSoftScan){
  556. [self addlog:@"SoftScan is ENABLED"];
  557. _softScannerEnabled=TRUE;
  558. }
  559. else{
  560. _softScannerEnabled=FALSE;
  561. [self addlog:@"SoftScan is DISABLED"];
  562. }
  563. }
  564. else{
  565. [self addlog:[ NSString stringWithFormat:@"getting SoftScanStatus returned the error %ld",result]];
  566. }
  567. }
  568. /**
  569. *
  570. */
  571. -(void) onSetSoftScanStatus:(ISktScanObject*)scanObj{
  572. [self addlog:@"onSetSoftScanStatus:"];
  573. SKTRESULT result=[[scanObj Msg]Result];
  574. if(SKTSUCCESS(result)){
  575. [self addlog:@"SoftScan set status success"];
  576. }
  577. else{
  578. [self addlog:[NSString stringWithFormat:@"SoftScan set status returned the error %ld",result]];
  579. }
  580. }
  581. /**
  582. *
  583. */
  584. -(void) onSetTrigger:(ISktScanObject*)scanObj{
  585. [self addlog:@"onSetTrigger:"];
  586. SKTRESULT result=[[scanObj Msg]Result];
  587. if(SKTSUCCESS(result)){
  588. [self addlog:@"Trigger set success"];
  589. }
  590. else{
  591. [self addlog:[NSString stringWithFormat:@"Trigger set returned the error %ld",result]];
  592. }
  593. }
  594. /**
  595. *
  596. */
  597. -(void) onGetScanApiVersion:(ISktScanObject*)scanObj{
  598. [self addlog:@"onGetScanApiVersion:"];
  599. SKTRESULT result=[[scanObj Msg]Result];
  600. if(SKTSUCCESS(result))
  601. {
  602. ISktScanProperty*property=[scanObj Property];
  603. if([property getType]==kSktScanPropTypeVersion)
  604. {
  605. scanApiVersion=[NSString stringWithFormat:@"%lx.%lx.%lx.%ld",
  606. [[property Version]getMajor],
  607. [[property Version]getMiddle],
  608. [[property Version]getMinor],
  609. [[property Version]getBuild]];
  610. }
  611. }
  612. else{
  613. scanApiVersion=[NSString stringWithFormat:@"Get ScanAPI version Error: %ld",result];
  614. }
  615. [self addlog:[NSString stringWithFormat:@"ver: %@",scanApiVersion]];
  616. }
  617. /**
  618. *
  619. */
  620. #ifdef USE_SOFTSCAN
  621. -(void) onSetOverlayView:(ISktScanObject*)scanObj{
  622. SKTRESULT result=[[scanObj Msg]Result];
  623. if(SKTSUCCESS(result)){
  624. [self addlog:@"Overlay view set success"];
  625. }
  626. else{
  627. [self addlog:[NSString stringWithFormat:@"Overlay view set returned the error %ld",result]];
  628. }
  629. }
  630. #endif
  631. /**
  632. * called each time a device connects to the host
  633. * @param result contains the result of the connection
  634. * @param newDevice contains the device information
  635. */
  636. -(void)onDeviceArrival:(SKTRESULT)result device:(DeviceInfo*)deviceInfo{
  637. [self addlog:@"onDeviceArrival:"];
  638. [self updateDevicesList:deviceInfo Add:YES];
  639. #ifdef USE_SOFTSCAN
  640. // if the scanner is a SoftScan scanner
  641. if([deviceInfo.getTypeString compare:@"SoftScan"]==NSOrderedSame){
  642. // _softScannerTriggerBtn.hidden=NO;
  643. _softScanDeviceInfo=deviceInfo;
  644. if(_deviceInfoToTrigger==nil)
  645. _deviceInfoToTrigger=deviceInfo;
  646. NSMutableDictionary* overlayParameter=[[NSMutableDictionary alloc]init];
  647. [overlayParameter setValue:self forKey:[NSString stringWithCString:kSktScanSoftScanContext encoding:NSASCIIStringEncoding]];
  648. [ScanApi postSetOverlayView:deviceInfo OverlayView:overlayParameter Target:self Response:@selector(onSetOverlayView:)];
  649. }
  650. else
  651. #endif
  652. {
  653. if([deviceInfo.getTypeString compare:@"CHS 8Ci Scanner"]==NSOrderedSame){
  654. // _softScannerTriggerBtn.hidden=NO;
  655. _deviceInfoToTrigger=deviceInfo;
  656. }
  657. if(_doAppDataConfirmation==YES){
  658. // switch the comment between the 2 following lines for handling the
  659. // data confirmation beep from the scanner (local)
  660. // if none is set, the scanner will beep only once when SingleEntry actually
  661. // confirm the decoded data, otherwise the scanner will beep twice, one locally,
  662. // and one when SingleEntry will confirm the decoded data
  663. [ScanApi postSetDecodeAction:deviceInfo DecodeAction:kSktScanLocalDecodeActionNone Target:self Response:@selector(onSetLocalDecodeAction:)];
  664. // [ScanApi postSetDecodeAction:deviceInfo DecodeAction:kSktScanLocalDecodeActionBeep|kSktScanLocalDecodeActionFlash|kSktScanLocalDecodeActionRumble Target:self Response:@selector(onSetLocalDecodeAction:)];
  665. }
  666. // for demonstration only, let's make sure the DPM is enabled
  667. // first interrogate the scanner to see if it's already enabled
  668. // and in the onGetSymbologyDpm callback, if the DPM is not already set
  669. // then we send a Symbology property to enable it.
  670. [ScanApi postGetSymbologyInfo:deviceInfo SymbologyId:kSktScanSymbologyDirectPartMarking Target:self Response:@selector(onGetSymbologyDpm:)];
  671. }
  672. }
  673. /**
  674. * called each time a device disconnect from the host
  675. * @param deviceRemoved contains the device information
  676. */
  677. -(void) onDeviceRemoval:(DeviceInfo*) deviceRemoved{
  678. [self addlog:@"onDeviceRemoval:"];
  679. [self updateDevicesList:deviceRemoved Add:NO];
  680. if(_deviceInfoToTrigger==deviceRemoved){
  681. _deviceInfoToTrigger=nil;
  682. }
  683. #ifdef USE_SOFTSCAN
  684. if(_softScanDeviceInfo==deviceRemoved){
  685. _softScanDeviceInfo=nil;
  686. }
  687. if(_deviceInfoToTrigger==nil)
  688. _deviceInfoToTrigger=_softScanDeviceInfo;
  689. #endif
  690. if(_deviceInfoToTrigger==nil){
  691. // _softScannerTriggerBtn.hidden=YES;
  692. }
  693. }
  694. /**
  695. * called each time ScanAPI is reporting an error
  696. * @param result contains the error code
  697. */
  698. -(void) onError:(SKTRESULT) result{
  699. [self addlog:@"onError:"];
  700. [self addlog:[NSString stringWithFormat:@"ScanAPI is reporting an error: %ld",result]];
  701. ActiveViewController* avc=(ActiveViewController*)self.active_controller;
  702. [avc onErrorInfo:[NSString stringWithFormat:@"ScanAPI is reporting an error: %ld",result]];
  703. // _Status.text=[NSString stringWithFormat:@"ScanAPI is reporting an error: %ld",result];
  704. }
  705. /**
  706. * called each time ScanAPI receives decoded data from scanner
  707. * @param deviceInfo contains the device information from which
  708. * the data has been decoded
  709. * @param decodedData contains the decoded data information
  710. */
  711. -(void) onDecodedDataResult:(long)result device:(DeviceInfo *)device decodedData:(ISktScanDecodedData*)decodedData{
  712. [self addlog:@"onDecodedDataResult:"];
  713. //-(void) onDecodedData:(DeviceInfo *)device decodedData:(ISktScanDecodedData*)decodedData{
  714. if(SKTSUCCESS(result)){
  715. NSString *cleanString = [[NSString stringWithUTF8String:(const char *)[decodedData getData]] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
  716. ActiveViewController* avc=(ActiveViewController*)self.active_controller;
  717. [avc onDecodedData:cleanString];
  718. //_Entry.text=[NSString stringWithUTF8String:(const char *)[decodedData getData]];
  719. [self addlog:[NSString stringWithUTF8String:(const char *)[decodedData getData]]];
  720. if(_doAppDataConfirmation==YES){
  721. [ScanApi postSetDataConfirmation:device Target:self Response:@selector(onDataConfirmation:)];
  722. }
  723. }
  724. }
  725. -(void) test_onDecodedDataResult:(NSString*) value
  726. {
  727. [self addlog:@"onDecodedDataResult:"];
  728. //-(void) onDecodedData:(DeviceInfo *)device decodedData:(ISktScanDecodedData*)decodedData{
  729. if(true){
  730. ActiveViewController* avc=(ActiveViewController*)self.active_controller;
  731. [avc onDecodedData:value];
  732. //_Entry.text=[NSString stringWithUTF8String:(const char *)[decodedData getData]];
  733. [self addlog:value];
  734. // if(_doAppDataConfirmation==YES){
  735. // [ScanApi postSetDataConfirmation:device Target:self Response:@selector(onDataConfirmation:)];
  736. // }
  737. }
  738. }
  739. -(void) didRotated
  740. {
  741. }
  742. /**
  743. * called when ScanAPI initialization has been completed
  744. * @param result contains the initialization result
  745. */
  746. -(void) onScanApiInitializeComplete:(SKTRESULT) result{
  747. [self addlog:@"onScanApiInitializeComplete:"];
  748. if(SKTSUCCESS(result))
  749. {
  750. self.api_Status = API_START;
  751. NSString* strlog =[NSString stringWithFormat:@"onScanApiInitialize SUCCESS result:%ld",result];
  752. [self addlog:strlog];
  753. #ifdef USE_SOFTSCAN
  754. // make sure we support SoftScan
  755. [ScanApi postSetSoftScanStatus:kSktScanSoftScanSupported Target:self Response:@selector(onSetSoftScanStatus:)];
  756. // check if SoftScan is enabled
  757. [ScanApi postGetSoftScanStatus:self Response:@selector(onGetSoftScanStatus:)];
  758. #else
  759. // disable support SoftScan (Default, not really needed if it was never activated)
  760. [ScanApi postSetSoftScanStatus:kSktScanSoftScanNotSupported Target:self Response:@selector(onSetSoftScanStatus:)];
  761. #endif
  762. // ask for ScanAPI version (not a requirement but always nice to know)
  763. [ScanApi postGetScanApiVersion:self Response:@selector(onGetScanApiVersion:)];
  764. // configure ScanAPI for doing App Data confirmation,
  765. // if TRUE then SingleEntry will confirm the decoded data
  766. if(_doAppDataConfirmation==YES){
  767. [ScanApi postSetConfirmationMode:kSktScanDataConfirmationModeApp Target:self Response:@selector(onSetDataConfirmationMode:)];
  768. }
  769. ActiveViewController* avc=(ActiveViewController*)self.active_controller;
  770. [avc onStatusChanged:@"Waiting for scanner..."];
  771. self.Status_Text = @"Waiting for scanner...";
  772. // _Status.text=@"Waiting for scanner...";
  773. }
  774. else{
  775. ActiveViewController* avc=(ActiveViewController*)self.active_controller;
  776. [avc onStatusChanged:[NSString stringWithFormat:@"Error initializing ScanAPI:%ld",result]];
  777. self.Status_Text =[NSString stringWithFormat:@"Error initializing ScanAPI:%ld",result];
  778. // _Status.text=[NSString stringWithFormat:@"Error initializing ScanAPI:%ld",result];
  779. NSString* strlog =[NSString stringWithFormat:@"Error initializing ScanAPI:%ld",result];
  780. [self addlog:strlog];
  781. }
  782. }
  783. /**
  784. * called when ScanAPI has been terminated. This will be
  785. * the last message received from ScanAPI
  786. */
  787. -(void) onScanApiTerminated{
  788. [self addlog:@"onScanApiTerminated:"];
  789. [ScanApiConsumer invalidate];
  790. ScanApiConsumer= nil;
  791. [self addlog:@"ScanApiConsumer invalidate"];
  792. self.api_Status = API_STOP;
  793. ActiveViewController* avc=(ActiveViewController*)self.active_controller;
  794. [avc onStatusChanged:@"Off"];
  795. self.Status_Text =@"Off";
  796. // _Status.text = @"Off";
  797. }
  798. /**
  799. * called when an error occurs during the retrieval
  800. * of a ScanObject from ScanAPI.
  801. * @param result contains the retrieval error code
  802. */
  803. -(void) onErrorRetrievingScanObject:(SKTRESULT) result{
  804. [self addlog:@"onErrorRetrievingScanObject:"];
  805. [self addlog:[NSString stringWithFormat:@"Error retrieving ScanObject:%ld",result]];
  806. //_Status.text=[NSString stringWithFormat:@"Error retrieving ScanObject:%ld",result];
  807. ActiveViewController* avc=(ActiveViewController*)self.active_controller;
  808. [avc onErrorInfo:[NSString stringWithFormat:@"Error retrieving ScanObject:%ld",result]];
  809. }
  810. -(void) printPdf:(NSString*) url
  811. {
  812. PDFViewController *ViewController = [self.main_vc.storyboard instantiateViewControllerWithIdentifier:@"PDFViewController"];
  813. ViewController.url = url;
  814. ViewController.canSave = false;
  815. // NSString* subject;
  816. // if (company.length==0) {
  817. // NSString* cur_time =[RAUtils current_date];
  818. // subject =name;//[NSString stringWithFormat:@"NPD Product List %@",cur_time];
  819. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  820. // NSString* customer_email= [appDelegate.customerInfo valueForKey:@"customer_email"];
  821. //
  822. //
  823. // NSMutableArray* send_to = [[NSMutableArray alloc]init];
  824. // if(customer_email.length>0)
  825. // {
  826. // send_to=[[customer_email componentsSeparatedByString:NSLocalizedString(@";", nil)] mutableCopy];
  827. // // customer_email compo
  828. // // [send_to addObject:customer_email];
  829. // }
  830. // ViewController.mail_to = send_to;
  831. // }
  832. // else
  833. // {
  834. // subject = [NSString stringWithFormat:@"Tear sheet for %@",company ];
  835. // }
  836. // ViewController.attachment_name = [NSString stringWithFormat:@"NPD_Product_List %@.pdf",cur_time];
  837. // ViewController.mail_subject = subject;
  838. ViewController.autoPrint=true;
  839. ViewController.hidenavi = false;
  840. [self.main_vc.navigationController pushViewController:ViewController animated:YES];
  841. // [ViewController.navigationController setNavigationBarHidden:NO animated:NO];
  842. }
  843. @end