| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468 |
- //
- // RAUtils.m
- // RedAnt ERP Mobile
- //
- // Created by Ray on 9/17/15.
- // Copyright (c) 2015 United Software Applications, Inc. All rights reserved.
- //
- #import "RAUtils.h"
- #import "LoginViewController.h"
- #import "MainViewController.h"
- #import <sys/param.h>
- #import <sys/mount.h>
- #import "ZipArchive.h"
- @implementation RAUtils
- +(NSString*) getdbzip
- {
-
-
- NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
- NSString *documents = /*[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];*/[paths objectAtIndex:0];
- NSString *database_path = [documents stringByAppendingPathComponent:DBNAME];
-
-
- NSString* temp = NSTemporaryDirectory();
-
- NSString* uuid=[[NSUUID UUID] UUIDString];
-
- NSString *tempfile = [temp stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.zip",uuid]];
-
- ZipArchive* zip = [[ZipArchive alloc] init];
-
-
- BOOL result = [zip CreateZipFile2:tempfile Password:@"usai2010"];
-
- result = [zip addFileToZip:database_path newname:[database_path lastPathComponent]];
- return tempfile;
-
-
- }
- +(NSData*) getdbfile
- {
- NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
- NSString *documents = /*[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];*/[paths objectAtIndex:0];
- NSString *database_path = [documents stringByAppendingPathComponent:DBNAME];
- return [NSData dataWithContentsOfFile:database_path];
-
-
- }
- +(NSDictionary*) dictfromfile:(NSString*) path
- {
- NSData *filedata = [NSData dataWithContentsOfFile:path];
-
- NSError *error = nil;
- NSDictionary *string2dic = [NSJSONSerialization JSONObjectWithData: filedata
- options: NSJSONReadingMutableContainers
- error: &error];
- // NSLog(@"%@",string2dic);
- return string2dic;
-
- }
- + (NSArray*) allFilesAtPath:(NSString*) dirString
- {
-
- NSMutableArray* array = [NSMutableArray arrayWithCapacity:10];
-
- NSFileManager* fileMgr = [NSFileManager defaultManager];
-
- NSArray* tempArray = [fileMgr contentsOfDirectoryAtPath:dirString error:nil];
-
- for (NSString* fileName in tempArray) {
-
- BOOL flag = YES;
-
- NSString* fullPath = [dirString stringByAppendingPathComponent:fileName];
-
- if ([fileMgr fileExistsAtPath:fullPath isDirectory:&flag]) {
-
- if (!flag) {
-
- [array addObject:fullPath];
-
- }
-
- }
-
- }
-
- return array;
-
- }
- + (bool)mergeContentsOfPath:(NSString *)srcDir intoPath:(NSString *)dstDir error:(NSError**)err {
-
- NSLog(@"- mergeContentsOfPath: %@\n intoPath: %@", srcDir, dstDir);
-
- NSFileManager *fm = [NSFileManager defaultManager];
- NSDirectoryEnumerator *srcDirEnum = [fm enumeratorAtPath:srcDir];
- NSString *subPath;
- while ((subPath = [srcDirEnum nextObject])) {
-
- NSLog(@" subPath: %@", subPath);
- NSString *srcFullPath = [srcDir stringByAppendingPathComponent:subPath];
- NSString *potentialDstPath = [dstDir stringByAppendingPathComponent:subPath];
-
- // Need to also check if file exists because if it doesn't, value of `isDirectory` is undefined.
- BOOL isDirectory = ([[NSFileManager defaultManager] fileExistsAtPath:srcFullPath isDirectory:&isDirectory] && isDirectory);
-
- // Create directory, or delete existing file and move file to destination
- if (isDirectory) {
- NSLog(@" create directory");
- [fm createDirectoryAtPath:potentialDstPath withIntermediateDirectories:YES attributes:nil error:err];
- if (err && *err) {
- NSLog(@"ERROR: %@", *err);
- return false;
- }
- }
- else {
- if ([fm fileExistsAtPath:potentialDstPath]) {
- NSLog(@" removeItemAtPath");
- [fm removeItemAtPath:potentialDstPath error:err];
- if (err && *err) {
- NSLog(@"ERROR: %@", *err);
- return false;
- }
- }
-
- NSLog(@" moveItemAtPath");
- [fm moveItemAtPath:srcFullPath toPath:potentialDstPath error:err];
- if (err && *err) {
- NSLog(@"ERROR: %@", *err);
- return false;
- }
- }
- }
- [fm removeItemAtPath:srcDir error:err];
- if (err && *err) {
- NSLog(@"ERROR: %@", *err);
- return false;
- }
- return true;
- }
- +(void) enum_font
- {
- return;
- NSArray *familys = [UIFont familyNames];
-
- for (int i = 0; i < familys.count; i++)
- {
- NSString *family = [familys objectAtIndex:i];
- NSLog(@"=====Fontfamily:%@", family);
- NSArray *fonts = [UIFont fontNamesForFamilyName:family];
- for(int j = 0; j < fonts.count; j++)
- {
- NSLog(@"***FontName:%@", [fonts objectAtIndex:j]);
- }
- }
- }
- + (CGRect)rectAlign:(CGRect )parent rect:(CGRect)rect hAlign:(NSString*)hAlign vAlign:(NSString*)vAlign
- {
- // double cx=parent.origin.x+parent.size.width/2;
- // double cy=parent.origin.y+parent.size.height/2;
- CGPoint centerpoint= CGPointMake(parent.origin.x+parent.size.width/2,parent.origin.y+parent.size.height/2);
- if([hAlign.lowercaseString isEqualToString:@"center"])
- {
- rect=CGRectMake(centerpoint.x-rect.size.width/2, rect.origin.y, rect.size.width, rect.size.height);
- }
-
- if([vAlign.lowercaseString isEqualToString:@"middle"])
- {
- rect=CGRectMake(rect.origin.x, centerpoint.y-rect.size.height/2, rect.size.width, rect.size.height);
- }
-
- return rect;
-
- }
- + (CGRect)rectVAlign:(CGRect )parent rect:(CGRect)rect vAlign:(NSString*)vAlign
- {
- // double cx=parent.origin.x+parent.size.width/2;
- // double cy=parent.origin.y+parent.size.height/2;
- CGPoint centerpoint= CGPointMake(parent.origin.x+parent.size.width/2,parent.origin.y+parent.size.height/2);
-
- if([vAlign.lowercaseString isEqualToString:@"middle"])
- {
- rect=CGRectMake(rect.origin.x, centerpoint.y-rect.size.height/2, rect.size.width, rect.size.height);
- }
-
- return rect;
-
- }
- + (CGRect)scaleToSize:(CGRect )from to:(CGSize)to
- {
- if(from.size.width/from.size.height>to.width/to.height)
- {
- return CGRectMake(from.origin.x, from.origin.y, to.width, to.width*from.size.height/from.size.width);
- }
- else
- {
- return CGRectMake(from.origin.x, from.origin.y, to.height*from.size.width/from.size.height, to.height);
- }
- // // 创建一个bitmap的context
- // // 并把它设置成为当前正在使用的context
- // UIGraphicsBeginImageContext(size);
- // // 绘制改变大小的图片
- // [img drawInRect:CGRectMake(0, 0, size.width, size.height)];
- // // 从当前context中创建一个改变大小后的图片
- // UIImage* scaledImage = UIGraphicsGetImageFromCurrentImageContext();
- // // 使当前的context出堆栈
- // UIGraphicsEndImageContext();
- // // 返回新的改变大小后的图片
- //
- // // NSData *imageData=UIImageJPEGRepresentation(scaledImage, 1.f);
- // return scaledImage;
- }
- + (UIImage *)scaleToSize:(UIImage *)img size:(CGSize)size{
- // 创建一个bitmap的context
- // 并把它设置成为当前正在使用的context
- UIGraphicsBeginImageContext(size);
- // 绘制改变大小的图片
- [img drawInRect:CGRectMake(0, 0, size.width, size.height)];
- // 从当前context中创建一个改变大小后的图片
- UIImage* scaledImage = UIGraphicsGetImageFromCurrentImageContext();
- // 使当前的context出堆栈
- UIGraphicsEndImageContext();
- // 返回新的改变大小后的图片
-
- // NSData *imageData=UIImageJPEGRepresentation(scaledImage, 1.f);
- return scaledImage;
- }
- +(UIImage*)img_compress:(UIImage*)image kbsize:(float) size
- {
-
-
-
- //UIImage *image=[UIImage imageNamed:@"xxoo.jpeg"];
- NSData *imageData=UIImageJPEGRepresentation(image, 1.f);
-
- if(size>imageData.length/1024)
- return image;
-
- // CGFloat size=40.f;// kb
- CGFloat scale=size/(imageData.length/1024);
-
- scale = sqrt (scale);
-
- CGSize newsize=image.size;
- newsize.height = newsize.height*scale;
- newsize.width = newsize.width*scale;
-
- return [RAUtils scaleToSize:image size:newsize];
- // NSData *newData=UIImageJPEGRepresentation(image, scale);
-
- // UIImage* ret= [[UIImage alloc] initWithData:newData];
- //
- // return ret;
- }
- +(NSString*) FloatFormat:(float)value
- {
- if (fmodf(value, 1)==0)
- {
-
- return [NSString stringWithFormat:@"%.0f",value];
-
- } else if (fmodf(value*10, 1)==0)
- {
-
- return [NSString stringWithFormat:@"%.1f",value];
-
- }
- else if (fmodf(value*100, 1)==0)
- {
-
- return [NSString stringWithFormat:@"%.2f",value];
-
- }
- else if (fmodf(value*1000, 1)==0)
- {
-
- return [NSString stringWithFormat:@"%.3f",value];
-
- }
- else
- {
-
- return [NSString stringWithFormat:@"%.4f",value];
-
-
- }
- return nil;
- }
- +(UIViewController*) getViewController:(UIView*) view
- {
- for (UIView* next = [view superview]; next; next = next.superview) {
- UIResponder* nextResponder = [next nextResponder];
- if ([nextResponder isKindOfClass:[UIViewController class]]) {
- return (UIViewController*)nextResponder;
- }
- }
- return nil;
- }
- + (float)fileSizeForDir:(NSString*)path//计算文件夹下文件的总大小
- {
- NSFileManager *fileManager = [[NSFileManager alloc] init];
- float size =0;
- NSArray* array = [fileManager contentsOfDirectoryAtPath:path error:nil];
- for(int i = 0; i<[array count]; i++)
- {
- NSString *fullPath = [path stringByAppendingPathComponent:[array objectAtIndex:i]];
- BOOL isDir;
- if ( !([fileManager fileExistsAtPath:fullPath isDirectory:&isDir] && isDir) )
- {
- NSDictionary *fileAttributeDic=[fileManager attributesOfItemAtPath:fullPath error:nil];
- size+= fileAttributeDic.fileSize/ 1024.0/1024.0;
- }
- else
- {
- size+=[self fileSizeForDir:fullPath];
- }
- }
- return size;
- }
- +(NSDictionary*) error_dict:(NSError*)error
- {
- if(error==nil)
- return nil;
- NSMutableDictionary* ret = [[NSMutableDictionary alloc] init];
- [ret setValue:[NSString stringWithFormat:@"%d",error.code] forKey:@"error_code"];
- [ret setValue:error.domain forKey:@"err_domain"];
- [ret setValue:[error localizedDescription] forKey:@"err_message"];
- // [ret setObject:error.userInfo forKey:@"user_info"];
- return ret;
- }
- +(NSString*) current_date
- {
- NSDate * date = [NSDate date];
- NSTimeInterval sec = [date timeIntervalSinceNow];
- NSDate * currentDate = [[NSDate alloc] initWithTimeIntervalSinceNow:sec];
-
- NSDateFormatter * df = [[NSDateFormatter alloc] init ];
- [df setDateFormat:@"MM/dd/yyyy HH:mm:ss"];
- NSString * na = [df stringFromDate:currentDate];
- return na;
- }
- +(void) message_alert :(NSString*) msg title:(NSString*) title controller:(UIViewController*) vc
- {
- if(title==nil)
- title = @"Message";
-
-
- return [self alert_view:msg title:title];
-
-
- UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:title message:nil preferredStyle:UIAlertControllerStyleAlert];
- //block代码块取代了delegate
-
-
- // [alertControl addTextFieldWithConfigurationHandler:^(UITextField *textField) {
- // textField.text = self.save_name;
- //
- //
- // }];
-
- // UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
- //
- // UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Delete Order"];
- // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
- //
- // NSDictionary* return_json = [iSalesNetwork delete_Order:orderid];
- //
- // dispatch_async(dispatch_get_main_queue(), ^{
- // [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
- //
- //
- // if([[return_json valueForKey:@"result"] intValue]==2)
- // {
- //
- // [RAUtils error_alert:nil title:@"Order Delete"] ;
- // }
- // else
- // {
- // [RAUtils error_alert:[return_json valueForKey:@"err_msg"] title:@"Delete Order Failed."] ;
- // }
- //
- //
- //
- //
- // });
- // });
- //
- //
- // }];
-
- UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"Ok" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
- //NSLog(@"Cancel");
- }];
- // [alertControl addAction:actionOne];
-
- [alertControl addAction:alertthree];
-
-
- UIAlertAction *alertcancel = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
- }];
- [alertControl addAction:alertcancel];
- //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
-
-
-
-
- [vc presentViewController:alertControl animated:YES completion:nil];
-
-
-
- return;
-
-
-
-
- }
- +(void) neworder:(UIViewController*) vc selectorholder:(id)holder selector:(SEL)addtocart
- {
-
- UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Create Order"];
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
-
- NSDictionary* return_json = [iSalesNetwork new_Order];
-
- dispatch_async(dispatch_get_main_queue(), ^{
- [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
-
-
- if([[return_json valueForKey:@"result"] intValue]==2)
- {
- int result=[[return_json valueForKey:@"result"] intValue];
- if(result==2)
- {
- //successed.
-
- NSString* order_code = [return_json valueForKey:@"orderCode"];
- AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
- appDelegate.order_code = order_code;
- appDelegate.order_status = [[return_json valueForKey:@"orderStatus"] intValue];
-
- [holder performSelector:addtocart];
-
-
- // [self ReloadData];
-
-
- // if(self.shopCartBlock!=nil)
- // {
- // UIImage* img=[self photoStackView:self.photoStack photoForIndex:0];
- //
- //
- // CGRect iv_rect = CGRectMake(self.btnaddCart.center.x-50, self.btnaddCart.center.y-50, 100, 100);
- // UIImageView* iv = [[UIImageView alloc] initWithFrame:iv_rect];
- // iv.image = img;
- // // [self.contentView addSubview:iv];
- // self.shopCartBlock(iv);
- //
- // }
-
- }
- }
- else
- {
- [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Create Order" controller:vc] ;
- }
-
-
-
-
- });
- });
- }
- +(void) add_to_cart:(UIViewController*) vc selectorholder:(id)holder selector:(SEL)addtocart
- {
- UIApplication * app = [UIApplication sharedApplication];
- AppDelegate *appDelegate = (AppDelegate *)[app delegate];
- MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
-
-
-
- if(appDelegate.bLogin==false)
- {
-
- LoginViewController * loginvc =[ vc.storyboard instantiateViewControllerWithIdentifier:@"LoginViewController"];
-
- loginvc.returnValue = ^(bool blogin){
-
- if(blogin)
- {
- if(/*appDelegate.user_type==USER_ROLE_EMPLOYEE*/ true)
- {
-
- [main_vc checklogin:false];
-
-
- NSString* msg =@"";
- // if(appDelegate.contact_id.length>0)
- // {
- // msg = [msg stringByAppendingString:@"Customer:"];
- // msg = [msg stringByAppendingString:appDelegate.customerInfo[@"customer_name"]];
- //
- // }
-
- UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Add to cart" message:msg preferredStyle:UIAlertControllerStyleAlert];
- //block代码块取代了delegate
-
-
-
- UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Check for saved order" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
-
-
- // vc.disable_refresh = true;
- OrderListViewController* ovc =[ vc.storyboard instantiateViewControllerWithIdentifier:@"OrderListViewController"];
- ovc.showNavibar = true;
- //ovc.customer_id = appDelegate.contact_id;
- ovc.selectOrder = ^(NSMutableDictionary* order_detail){
-
- [holder performSelector:addtocart];
-
-
- };
- ovc.init_style = OL_OPEN;
-
- ovc.onCancel = ^(){
-
- // self.disable_refresh = false;
-
-
-
- };
-
- [vc.navigationController pushViewController:ovc animated:true];
-
-
-
-
-
- }];
-
- UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"Create new order" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
-
-
- {
- //create new;
- // self.disable_refresh = true;
- if(appDelegate.customerInfo==nil)// select contact if current contact not exist
- {
- ContactListViewController* cvc = [vc.storyboard instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
- cvc.showNavibar = true;
- cvc.contact_type = @"Sales_Order_Customer";
- cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
-
- appDelegate.contact_id=[value valueForKey:@"customer_cid"];
- appDelegate.customerInfo = value;
-
-
- if(appDelegate.order_code==nil)
- [self neworder:vc selectorholder:holder selector:addtocart];
- // neworder();
-
- // [main_vc checklogin:true];
- // [self handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
-
- //
- // if(self.returnValue)
- // self.returnValue(value);
- };
-
- cvc.onCancel = ^(){
-
- [RAUtils message_alert:@"Cannot create order without cursomer infomation." title:@"New Order Error" controller:vc];
-
- // self.disable_refresh = false;
-
- };
- cvc.onReset = ^(){
- // [main_vc checklogin:true];
- };
-
- [vc.navigationController pushViewController:cvc animated:true];
- }
- else
- {
- [self neworder:vc selectorholder:holder selector:addtocart];
- }
-
- }
-
-
- NSLog(@"No");
- }];
- [alertControl addAction:actionOne];
-
- [alertControl addAction:alertthree];
-
- UIAlertAction *alertcancel = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
- }];
- [alertControl addAction:alertcancel];
-
- //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
-
-
- [vc presentViewController:alertControl animated:YES completion:nil];
-
-
-
-
-
-
-
- }
-
- else
- {
-
- //customer login;
- [main_vc checklogin:false];
- //[self addtocart];
- [holder performSelector:addtocart];
- }
- }
-
-
- };
-
- UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:loginvc] ;
-
-
-
-
-
- // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
-
- navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
- [vc presentViewController:navi animated:YES completion:^{
-
- // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
-
- NSLog(@"LoginViewController present.........");
-
- // self.btop = false;
- // <#code#>
- }];
- }
- else
- {
- if(/*appDelegate.user_type==USER_ROLE_EMPLOYEE&&/*appDelegate.contact_id==nil&&*/appDelegate.order_code==nil)
- {
- if(appDelegate.contact_id.length==0)
- {
-
-
-
- NSString* msg =@"";
-
-
- UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Add to cart" message:msg preferredStyle:UIAlertControllerStyleAlert];
- //block代码块取代了delegate
-
-
-
- UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Check for saved order" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
-
-
- // vc.disable_refresh = true;
- OrderListViewController* ovc =[ vc.storyboard instantiateViewControllerWithIdentifier:@"OrderListViewController"];
- ovc.showNavibar = true;
- //ovc.customer_id = appDelegate.contact_id;
- ovc.selectOrder = ^(NSMutableDictionary* order_detail){
-
- [holder performSelector:addtocart];
-
-
- };
- ovc.init_style = OL_OPEN;
-
- ovc.onCancel = ^(){
-
- // self.disable_refresh = false;
-
-
-
- };
-
- [vc.navigationController pushViewController:ovc animated:true];
-
-
-
-
-
- }];
-
- UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"Create new order" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
-
-
- {
- //create new;
- // self.disable_refresh = true;
- if(appDelegate.customerInfo==nil)// select contact if current contact not exist
- {
- ContactListViewController* cvc = [vc.storyboard instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
- cvc.showNavibar = true;
- cvc.contact_type = @"Sales_Order_Customer";
- cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
-
- appDelegate.contact_id=[value valueForKey:@"customer_cid"];
- appDelegate.customerInfo = value;
-
-
- if(appDelegate.order_code==nil)
- [self neworder:vc selectorholder:holder selector:addtocart];
- // neworder();
-
- // [main_vc checklogin:true];
- // [self handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
-
- //
- // if(self.returnValue)
- // self.returnValue(value);
- };
-
- cvc.onCancel = ^(){
-
- [RAUtils message_alert:@"Cannot create order without cursomer infomation." title:@"New Order Error" controller:vc];
-
- // self.disable_refresh = false;
-
- };
- cvc.onReset = ^(){
- // [main_vc checklogin:true];
- };
-
- [vc.navigationController pushViewController:cvc animated:true];
- }
- else
- {
- [self neworder:vc selectorholder:holder selector:addtocart];
- }
-
- }
-
-
- NSLog(@"No");
- }];
- [alertControl addAction:actionOne];
-
- [alertControl addAction:alertthree];
- UIAlertAction *alertcancel = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
- }];
- [alertControl addAction:alertcancel];
-
- //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
-
-
- [vc presentViewController:alertControl animated:YES completion:nil];
-
-
-
-
-
-
-
- }
-
- else
-
- {
-
- UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait..." title:@"Checking Pending Order"];
-
-
-
-
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
-
- NSDictionary* return_json = [iSalesNetwork request_PendingOrder:appDelegate.contact_id];
-
- dispatch_async(dispatch_get_main_queue(), ^{
-
- [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
-
- if([[return_json valueForKey:@"result"] intValue]==2)
- {
-
- bool openPendingOrder= [[return_json valueForKey:@"hasPending"] boolValue];
- bool createNewOrder=appDelegate.can_create_order;
-
- if(openPendingOrder&&createNewOrder)
- {
-
- NSString* msg =@"";
- if(appDelegate.contact_id.length>0)
- {
- msg = [msg stringByAppendingString:@"Customer:"];
- msg = [msg stringByAppendingString:appDelegate.customerInfo[@"customer_name"]];
-
- }
-
- UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Add to cart" message:msg preferredStyle:UIAlertControllerStyleAlert];
- //block代码块取代了delegate
-
-
-
- UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Check for saved order" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
-
-
- // vc.disable_refresh = true;
- OrderListViewController* ovc =[ vc.storyboard instantiateViewControllerWithIdentifier:@"OrderListViewController"];
- ovc.showNavibar = true;
- ovc.customer_id = appDelegate.contact_id;
- ovc.selectOrder = ^(NSMutableDictionary* order_detail){
-
- [holder performSelector:addtocart];
-
-
- };
- ovc.init_style = OL_OPEN;
-
- ovc.onCancel = ^(){
-
- // self.disable_refresh = false;
-
-
-
- };
-
- [vc.navigationController pushViewController:ovc animated:true];
-
-
-
-
-
- }];
-
- UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"Create new order" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
-
-
- {
- //create new;
- // self.disable_refresh = true;
- if(appDelegate.customerInfo==nil)// select contact if current contact not exist
- {
- ContactListViewController* cvc = [vc.storyboard instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
- cvc.showNavibar = true;
- cvc.contact_type = @"Sales_Order_Customer";
- cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
-
- appDelegate.contact_id=[value valueForKey:@"customer_cid"];
- appDelegate.customerInfo = value;
-
-
- if(appDelegate.order_code==nil)
- [self neworder:vc selectorholder:holder selector:addtocart];
- // neworder();
-
- // [main_vc checklogin:true];
- // [self handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
-
- //
- // if(self.returnValue)
- // self.returnValue(value);
- };
-
- cvc.onCancel = ^(){
-
- [RAUtils message_alert:@"Cannot create order without cursomer infomation." title:@"New Order Error" controller:vc];
-
- // self.disable_refresh = false;
-
- };
- cvc.onReset = ^(){
- // [main_vc checklogin:true];
- };
-
- [vc.navigationController pushViewController:cvc animated:true];
- }
- else
- {
- [self neworder:vc selectorholder:holder selector:addtocart];
- }
-
- }
-
-
- NSLog(@"No");
- }];
- [alertControl addAction:actionOne];
-
- [alertControl addAction:alertthree];
-
- UIAlertAction *alertcancel = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
- }];
- [alertControl addAction:alertcancel];
- //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
-
-
- [vc presentViewController:alertControl animated:YES completion:nil];
-
-
-
-
-
-
- }
- else
- {
- if(openPendingOrder)
- {
- NSString* msg =@"";
- if(appDelegate.contact_id.length>0)
- {
- msg = [msg stringByAppendingString:@"Customer:"];
- msg = [msg stringByAppendingString:appDelegate.customerInfo[@"customer_name"]];
-
- }
-
- UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Add to cart" message:msg preferredStyle:UIAlertControllerStyleAlert];
- //block代码块取代了delegate
-
-
-
- UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Check for saved order" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
-
-
- // vc.disable_refresh = true;
- OrderListViewController* ovc =[ vc.storyboard instantiateViewControllerWithIdentifier:@"OrderListViewController"];
- ovc.showNavibar = true;
- ovc.customer_id = appDelegate.contact_id;
- ovc.selectOrder = ^(NSMutableDictionary* order_detail){
-
- [holder performSelector:addtocart];
-
-
- };
- ovc.init_style = OL_OPEN;
-
- ovc.onCancel = ^(){
-
- // self.disable_refresh = false;
-
-
-
- };
-
- [vc.navigationController pushViewController:ovc animated:true];
-
-
-
-
-
- }];
-
-
- [alertControl addAction:actionOne];
- UIAlertAction *alertcancel = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
- }];
- [alertControl addAction:alertcancel];
-
- // [alertControl addAction:alertthree];
-
- //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
-
-
- [vc presentViewController:alertControl animated:YES completion:nil];
-
-
-
-
-
-
-
- }
- else if(createNewOrder)
- {
- NSString* msg =@"";
- if(appDelegate.contact_id.length>0)
- {
- msg = [msg stringByAppendingString:@"Customer:"];
- msg = [msg stringByAppendingString:appDelegate.customerInfo[@"customer_name"]];
-
- }
-
- UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Add to cart" message:msg preferredStyle:UIAlertControllerStyleAlert];
- //block代码块取代了delegate
-
-
-
-
-
- UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"Create new order" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
-
-
- {
- //create new;
- // self.disable_refresh = true;
- if(appDelegate.customerInfo==nil)// select contact if current contact not exist
- {
- ContactListViewController* cvc = [vc.storyboard instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
- cvc.showNavibar = true;
- cvc.contact_type = @"Sales_Order_Customer";
- cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
-
- appDelegate.contact_id=[value valueForKey:@"customer_cid"];
- appDelegate.customerInfo = value;
-
-
- if(appDelegate.order_code==nil)
- [self neworder:vc selectorholder:holder selector:addtocart];
- // neworder();
-
- // [main_vc checklogin:true];
- // [self handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
-
- //
- // if(self.returnValue)
- // self.returnValue(value);
- };
-
- cvc.onCancel = ^(){
-
- [RAUtils message_alert:@"Cannot create order without cursomer infomation." title:@"New Order Error" controller:vc];
-
- // self.disable_refresh = false;
-
- };
- cvc.onReset = ^(){
- // [main_vc checklogin:true];
- };
-
- [vc.navigationController pushViewController:cvc animated:true];
- }
- else
- {
- [self neworder:vc selectorholder:holder selector:addtocart];
- }
-
- }
-
-
- NSLog(@"No");
- }];
- // [alertControl addAction:actionOne];
-
- [alertControl addAction:alertthree];
-
- UIAlertAction *alertcancel = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
- }];
- [alertControl addAction:alertcancel];
-
- //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
-
-
- [vc presentViewController:alertControl animated:YES completion:nil];
-
-
-
-
-
- }
- else
- {
- [RAUtils message_alert:[return_json valueForKey:@"You donot have permission to access order"] title:@"Add To Cart" controller:vc];
- }
-
- }
-
-
- }
- else
- {
-
- [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Check Pending Order" controller:vc] ;
- }
-
-
-
-
- });
- });
-
-
- }
- // // [main_vc checklogin:false];
- //
- // if(appDelegate.can_create_order)
- // {
- // NSString* msg =@"";
- // if(appDelegate.contact_id.length>0)
- // {
- // msg = [msg stringByAppendingString:@"\n\nCustomer:"];
- // msg = [msg stringByAppendingString:appDelegate.customerInfo[@"customer_name"]];
- //
- // }
- // UIAlertView * alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Add to cart", nil) message:msg delegate:self cancelButtonTitle:NSLocalizedString(@"Cancel", nil) otherButtonTitles:NSLocalizedString(@"Check for saved order", nil),NSLocalizedString(@"Create new order", nil), nil];
- //
- // // alert.
- // [alert show];
- // }
- // else
- // {
- // UIAlertView * alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Add to cart", nil) message:NSLocalizedString(@"", nil) delegate:self cancelButtonTitle:NSLocalizedString(@"Cancel", nil) otherButtonTitles:NSLocalizedString(@"Check for saved order", nil), nil];
- //
- // // alert.
- // [alert show];
- // }
- }
- else
- {
-
- // if(appDelegate.order_code==nil)
- // [ self neworder];
- // else
- [holder performSelector:addtocart];
-
-
-
- }
- }
-
- }
- +(void) add_recent_model:(NSDictionary*) model
- {
-
- NSMutableDictionary * newdict = [[NSMutableDictionary alloc]init];
- [newdict setObject:model forKey:@"item_0"];
-
-
-
-
- AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
- int count=[appDelegate.recent_model[@"count"] intValue];
- for(int i=0;i<count;i++)
- {
- NSMutableDictionary * mitem= appDelegate.recent_model[[NSString stringWithFormat:@"item_%d",i]];
- if([mitem[@"product_id"] isEqualToString:model[@"product_id"]])
- continue;
- [newdict setObject:mitem forKey:[NSString stringWithFormat:@"item_%lu",(unsigned long)newdict.allKeys.count]];
-
- }
- newdict[@"count"]=[NSString stringWithFormat:@"%lu",(unsigned long)newdict.allKeys.count];
-
-
- appDelegate.recent_model = newdict;
- //
- //
- // if(!bexist)
- // {
- // [appDelegate.recent_model setObject:item forKey:[NSString stringWithFormat:@"item_%d",count]];
- // appDelegate.recent_model[@"count"]=[NSString stringWithFormat:@"%d",count+1];
- // }
- }
- +(void) alert_view :(NSString*) msg title:(NSString*) title
- {
- if(title==nil)
- title = @"Message";
- if(msg.length>0)
- {
- title=[NSString stringWithFormat:@"%@\n\n%@",title,msg];
- }
- UIAlertView * alert = [[UIAlertView alloc] initWithTitle: title message:nil delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
- [alert show];
- }
- + (long long) freeDiskSpaceInMegaBytes{
- struct statfs buf;
- long long freespace = -1;
- if(statfs("/var", &buf) >= 0){
- freespace = (long long)(buf.f_bsize * buf.f_bfree);
- }
- NSLog([NSString stringWithFormat:@"手机剩余存储空间为:%qi MB" ,freespace/1024/1024]);
- return freespace/1024/1024;
- }
- +(UIAlertView * ) waiting_alert :(NSString*) msg title:(NSString*) title
- {
- if(title==nil)
- title = @"Please Wait";
- if(msg==nil)
- msg= @"Waiting...";
- NSAssert(msg!=nil, @"error message from json is nil");
- UIAlertView * alert = [[UIAlertView alloc] initWithTitle:title message:msg delegate:nil cancelButtonTitle:nil otherButtonTitles:nil, nil];
- [alert show];
- //
- //
- // UIActivityIndicatorView *aiView = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(125.0, 80.0, 30.0, 30.0)];
- // aiView.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge;
- // // check if os version is 7 or above. ios7.0及以上UIAlertView弃用了addSubview方法
- //// if ([[[UIDevice currentDevice] systemVersion] compare:@"7.0"] != NSOrderedAscending) {
- //// [alert setValue:aiView forKey:@"accessoryView"];
- //// }else{
- //// [alert addSubview:aiView];
- //// }
- //
- // aiView.hidden = false;
- // aiView.hidesWhenStopped = false;
- // [aiView startAnimating];
- //
- //[alert addSubview:aiView];
-
- return alert;
- //return nil;
- // return alert;
- // UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"Error!" message:@"User&Password can not be empty!" delegate:nil cancelButtonTitle:NSLocalizedString(@"ok", nil) , nil];
- //[alert show];
- }
- +(NSDictionary*) device_info
- {
-
-
- NSDictionary* infoDict =[[NSBundle mainBundle] infoDictionary];
- NSString* build =[infoDict objectForKey:@"CFBundleVersion"];
- NSString* version =[infoDict objectForKey:@"CFBundleShortVersionString"];
- NSString* versionNum = [NSString stringWithFormat:@"Version: %@ Build %@",version,build];
-
- NSMutableDictionary * info = [[NSMutableDictionary alloc]init];
- [info setValue:[[UIDevice currentDevice] name] forKey:@"name"];
- [info setValue:[[UIDevice currentDevice] systemVersion] forKey:@"systemVersion"];
- [info setValue:[[UIDevice currentDevice] model] forKey:@"model"];
- [info setValue:versionNum forKey:@"ver"];
- [info setValue:[[UIDevice currentDevice] localizedModel] forKey:@"localizedModel"];
-
- return info;
- // [info setValue:[[UIDevice currentDevice] name] forKey:@"name"];
- // [info setValue:[[UIDevice currentDevice] name] forKey:@"name"];
- // [info setValue:[[UIDevice currentDevice] name] forKey:@"name"];
-
- }
- +(NSArray*) string2arr:(NSString*) string separator:(NSString*)separator
- {
- NSArray *stringArray = [string componentsSeparatedByString:separator];
-
- return stringArray;
- }
- +(NSString*) arr2string:(NSArray *) arr separator:(NSString*)separator trim:(bool) btrim
- {
- if(arr.count==0)
- return nil;
- NSMutableArray * marr = [arr mutableCopy];
-
- begin:
- for (NSString* item in marr) {
- if(item.length==0 )
- if( btrim)
- {
-
- [marr removeObject:item];
- goto begin;
- }
-
- }
- NSString * ret = [marr componentsJoinedByString:separator];
- return ret;
- }
- +(NSString*) arr2string:(NSArray *) arr separator:(NSString*)separator trim:(bool) btrim brackets:(NSString*)brackets
- {
- if(brackets!=nil)
- separator = [NSString stringWithFormat:@"%@%@%@",brackets,separator,brackets];
- NSMutableArray * marr = [arr mutableCopy];
- begin:
- for (NSString* item in marr) {
- if(item.length==0 )
- if( btrim)
- {
-
- [marr removeObject:item];
- goto begin;
- }
-
-
-
- }
- NSString * ret = [marr componentsJoinedByString:separator];
-
- if(brackets!=nil)
- ret = [NSString stringWithFormat:@"%@%@%@",brackets,ret,brackets];
-
- return ret;
- }
- +(NSDictionary*) string2dict:(NSString*) str
- {
-
- if(str==nil)
- return nil;
- NSError *error = nil;
- NSDictionary *string2dic = [NSJSONSerialization JSONObjectWithData: [str dataUsingEncoding:NSUTF8StringEncoding]
- options: NSJSONReadingMutableContainers
- error: &error];
- NSLog(@"%@",string2dic);
- return string2dic;
- }
- +(UIColor*) strColor:(NSString*) color
- {
- if([color.lowercaseString isEqualToString:@"red"])
- return [UIColor redColor];
-
- return [UIColor blackColor];
- }
- +(NSData*) dict2data:(NSDictionary*) dict
- {
- if(dict==nil)
- return nil;
- // 将NSDictionary转化为NSData
- NSData *data = [NSJSONSerialization dataWithJSONObject:dict options:kNilOptions error:nil];
- return data;
- }
- +(NSString*) dict2string:(NSDictionary*) dict
- {
-
- if(dict==nil)
- return nil;
-
- // 将NSDictionary转化为NSData
- NSData *data = [NSJSONSerialization dataWithJSONObject:dict options:kNilOptions error:nil];
-
- // 再将NSData转为字符串
- NSString *jsonStr = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
-
- return jsonStr;
- }
- +(NSString*) base64en:(NSString*) string
- {
-
- if(string == nil)
-
- return nil;
-
- NSData *data = [string dataUsingEncoding:NSUTF8StringEncoding];
- NSString *stringBase64 = [data base64EncodedStringWithOptions:0]; // base64格式的字符串
-
- return stringBase64;
- }
- +(NSString*) base64de:(NSString*) stringBase64
- {
-
- if(stringBase64==nil)
- return nil;
- NSData *data = [[NSData alloc] initWithBase64EncodedString:stringBase64 options:NSDataBase64DecodingIgnoreUnknownCharacters];
- NSString *string =[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
- return string;
- }
- +(void) deletefiles :(NSString*) path
- {
-
- // NSString *extension = @"m4r";
- NSFileManager *fileManager = [NSFileManager defaultManager];
- // NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
- // NSString *documentsDirectory = [paths objectAtIndex:0];
-
- NSArray *contents = [fileManager contentsOfDirectoryAtPath:path error:NULL];
- NSEnumerator *e = [contents objectEnumerator];
- NSString *filename;
- while ((filename = [e nextObject])) {
-
- bool result= [fileManager removeItemAtPath:[path stringByAppendingPathComponent:filename] error:NULL];
-
- if(!result)
- NSLog(@"delete file failed %@------%@",path,filename);
- }
- }
- +(NSMutableArray*)dictionary2array:(NSDictionary*)json count_fields:(NSString*) count_fields item_mark:(NSString*) item_mark items_mark:(NSString* )items_mark
- {
- if(json==nil)
- return nil;
- NSMutableArray* ret = [[NSMutableArray alloc] init];
-
- int count = [[json valueForKey:count_fields] intValue];
-
- NSDictionary* items = nil;
- if(items_mark==nil)
- items = json;
- else
- items = [json objectForKey:items_mark];
- for(int i=0;i<count;i++)
- {
- NSDictionary* obj = [items objectForKey:[NSString stringWithFormat:@"%@%d",item_mark,i]];
- [ret addObject:obj];
- }
- return ret;
- }
- +(NSDictionary*) error_json :(int)code err_msg:(NSString*)msg
- {
-
- NSMutableDictionary* ret = [[NSMutableDictionary alloc] init];
- //#define RESULT_FALSE 0
- //#define RESULT_TRUE 2
- //#define RESULT_NET_ERROR -3
- //#define RESULT_NET_NOTAVAILABLE -4
- //#define RESULT_ERROR -5
- //#define RESULT_LOCALFILE_ERROR -7
- //#define RESULT_USERAUTH_ERROR -9
- //#define RESULT_UPDATE_USERAUTH_ERROR -11
- //#define RESULT_SESSION_EXPIRED -13
- //#define RESULT_VER_LOW
-
- if(msg.length<=0)
- {
- switch (code) {
- case RESULT_NET_NOTAVAILABLE:
- msg= MSG_NET_NOTAVAILABLE;
- break;
-
- default:
- // assert(@"UNDEFINE ERROR CODE!");
- break;
- }
- }
- // if(code==RESULT_NET_NOTAVAILABLE)
- // [ret setValue:[NSString stringWithFormat:@"%d",RESULT_NET_ERROR] forKey:@"result"];
- // else
- [ret setValue:[NSString stringWithFormat:@"%d",code] forKey:@"result"];
- [ret setValue:msg forKey:@"err_msg"];
-
- // NSData *jsonData = [NSJSONSerialization dataWithJSONObject:ret
- // options:0
- // error:nil];
-
- return ret;
- }
- + (CGRect)relativeFrameForScreenWithView:(UIView *)v
- {
- UIWindow * window=[[[UIApplication sharedApplication] delegate] window];
- CGRect rect=[v convertRect: v.bounds toView:window];
- return rect;
-
-
- // BOOL iOS7 = [[[UIDevice currentDevice] systemVersion] floatValue] >= 7;
- //
- // CGFloat screenHeight = [UIScreen mainScreen].bounds.size.height;
- // if (!iOS7) {
- // screenHeight -= 20;
- // }
- // UIView *view = v;
- // CGFloat x = .0;
- // CGFloat y = .0;
- // while (view.frame.size.width != 320 || view.frame.size.height != screenHeight) {
- // x += view.frame.origin.x;
- // y += view.frame.origin.y;
- // view = view.superview;
- // if ([view isKindOfClass:[UIScrollView class]]) {
- // x -= ((UIScrollView *) view).contentOffset.x;
- // y -= ((UIScrollView *) view).contentOffset.y;
- // }
- // }
- // return CGRectMake(x, y, v.frame.size.width, v.frame.size.height);
- }
- @end
|