| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371 |
- //
- // ViewController.m
- // AntsContract
- //
- // Created by Ray on 12/16/16.
- // Copyright © 2016 United Software Applications, Inc. All rights reserved.
- //
- #import "RootViewController.h"
- #import "DocumentPageViewController.h"
- #import "LoginViewController.h"
- #import "AppDelegate.h"
- #import "RAUtils.h"
- #import "PDFViewController.h"
- #import "DocumentListViewController.h"
- #import "ACNetwork.h"
- #import "PDFUtils.h"
- @interface RootViewController ()
- @end
- @implementation RootViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
- self.title= @"eSign";
- self.welcomeLabel.text=@"Not sign in";
- self.buttonHIC.enabled = false;
- self.buttonSRL.enabled = false;
- self.coverView.hidden = false;
-
- [self OnSigninClick:self.ibSignin];
- // Do any additional setup after loading the view, typically from a nib.
- }
- -(void) leak_debug
- {
-
-
- CGPDFDocumentRef document = [PDFUtils OpenPDF:@"GEIC - Home Improvement Contract 2017.pdf"];
- // self.total_page = CGPDFDocumentGetNumberOfPages (self.document);
-
- NSMutableDictionary * controlTemplate = [self templateInit:[PDFUtils loadControl:@"GEIC - Home Improvement Contract 2017.json"]];
-
-
- NSString* pdffile = [PDFUtils SavePDF:controlTemplate source:document window_rect:CGRectMake(0, 0, 768, 960)];
-
- CGPDFDocumentRelease(document);
-
- // CFRelease(document);
-
- NSString* zipfile=[ACNetwork prepareUploadFile:pdffile json:controlTemplate];
-
- [self previewPDF:pdffile];
-
-
-
-
-
-
- }
- -(NSMutableDictionary*) templateInit:(NSMutableDictionary*) template
- {
-
-
- NSString* temp = NSTemporaryDirectory();
- NSString* filename =[NSString stringWithFormat:@"%@.png", [[NSUUID UUID] UUIDString]];
- NSString* qrpath=[temp stringByAppendingPathComponent:filename];
- UIImage* qrimg=[RAUtils generateBarCode:@"leak test" width:300 height:44];//[QRCodeGenerator qrImageForString:order_code imageSize:240];
- bool bwrite=[UIImagePNGRepresentation(qrimg)writeToFile: qrpath atomically:YES];
-
-
-
- for(int i=0;i<[template[@"count"] intValue];i++)
- {
- NSMutableDictionary* page =template[[NSString stringWithFormat:@"page_%d",i]];
- for(int j=0;j<[page[@"count"] intValue];j++)
- {
- NSMutableDictionary* control =page[[NSString stringWithFormat:@"control_%d",j]];
- NSString* type = control[@"type"];
- NSString* field =control[@"field"];
- if([type isEqualToString:@"Label"])
- {
- if([field isEqualToString:@"doc_number"])
- {
- control[@"value"]= @"leak test";
- }
- }
- else if([type isEqualToString:@"Image"])
- {
- NSString* name =control[@"name"];
- if([name isEqualToString:@"BarCode"])
- {
- control[@"value"]= qrpath;
- }
- }
- else if([type isEqualToString:@"DatePicker"])
- {
- NSString* name =control[@"aname"];
- if([name isEqualToString:@"Today's Date"])
- {
- NSDateFormatter * formatter = [[NSDateFormatter alloc]init];
- [formatter setDateFormat:@"MM/dd/yyyy"];
- NSString* date = [formatter stringFromDate:[NSDate date]] ;
-
- control[@"value"]= date;
- }
- }
- }
- }
- return template;
- }
- - (IBAction)onNewCustomerClick:(id)sender {
- // [self leak_debug];
- // return;
-
- __weak typeof(self) weakSelf = self;
-
-
- UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait..." title:@"Create customer"];
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
-
-
- NSMutableDictionary* json=[[ACNetwork new_document] mutableCopy];
-
- dispatch_async(dispatch_get_main_queue(), ^{
- [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
-
-
- if([json[@"result"] intValue]==RESULT_TRUE)
-
- {
- DocumentPageViewController* dvc = [self.storyboard instantiateViewControllerWithIdentifier:@"DocumentPageViewController" ];
-
- dvc.templateName = @"GEIC - Home Improvement Contract 2017.json";
- dvc.pdfName = @"GEIC - Home Improvement Contract 2017.pdf";
- dvc.docment_id = json[@"doc_number"];
- dvc.OnSave=^(NSString* file)
- {
- [weakSelf previewPDF:file];
- };
-
- [self.navigationController pushViewController:dvc animated:true];
- }
- else
- {
- [RAUtils message_alert:[json valueForKey:@"err_msg"] title:@"Create Customer" controller:self] ;
- }
-
-
- });
- });
-
-
-
-
-
-
-
- }
- - (IBAction)onCustomerPerDocClick:(id)sender {
-
- DocumentListViewController* docVC =[self.storyboard instantiateViewControllerWithIdentifier:@"DocumentListViewController" ];
-
- [self.navigationController pushViewController:docVC animated:true];
- }
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- - (IBAction)OnSigninClick:(id)sender {
-
-
- UIBarButtonItem* bbitem = sender;
-
- AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
- if(appDelegate.bLogin)
- {
- UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Are you sure to sign out?" message:nil preferredStyle:UIAlertControllerStyleAlert];
-
- UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
-
-
- UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait..." title:@"Sign out"];
-
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
-
- NSDictionary* logout_json = nil;
-
-
-
- logout_json = [ACNetwork logout];
-
- dispatch_async(dispatch_get_main_queue(), ^{
-
-
- [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
- if([[logout_json valueForKey:@"result"] intValue]==2)
- {
- self.welcomeLabel.text=@"Not sign in";
- // [sender setTitle:@"Sign in" forState:UIControlStateNormal];
- [bbitem setTitle:@"Sign in"];
-
- self.buttonHIC.enabled = false;
- self.buttonSRL.enabled = false;
- self.coverView.hidden = false;
- }
- else
- {
- [RAUtils message_alert:[logout_json valueForKey:@"err_msg"] title:@"Sign out" controller:self] ;
- }
-
-
-
-
- });
- });
-
-
-
- }];
- // [alertControl addAction:actionOne];
-
- [alertControl addAction:alertthree];
-
-
- UIAlertAction *alertcancel = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
- }];
- [alertControl addAction:alertcancel];
- //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
-
-
-
-
- [self presentViewController:alertControl animated:YES completion:nil];
-
- }
- else
- {
- LoginViewController * loginvc =[ self.storyboard instantiateViewControllerWithIdentifier:@"LoginViewController"];
- loginvc.returnValue = ^(bool blogin){
-
- // [self checklogin :true];
-
- if(blogin)
- {
-
- self.welcomeLabel.text=[NSString stringWithFormat:@"Welcome %@",appDelegate.user];
-
- [bbitem setTitle:@"Sign out"];
- self.buttonHIC.enabled = true;
- self.buttonSRL.enabled = true;
- self.coverView.hidden = true;
-
- }
- else
- {
- self.welcomeLabel.text=@"Not sign in";
- self.buttonHIC.enabled = false;
- self.buttonSRL.enabled = false;
- self.coverView.hidden = false;
- }
-
- };
-
- UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:loginvc] ;
-
-
-
-
-
-
- navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
- [self presentViewController:navi animated:YES completion:^{
-
- DebugLog(@"login present.........");
-
- }];
- }
-
-
- }
- -(void) previewPDF:(NSString*)file
- {
- return;
- NSString* name=@"";//[self.content_data[indexPath.row] valueForKey:@"tear_name"];
- NSString* url= file;//[self.content_data[indexPath.row] valueForKey:@"pdf_path"];
-
-
-
- bool isLocalFile= true;//[self.content_data[indexPath.row] valueForKey:@"isLocalFile"];
-
- PDFViewController *ViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"PDFViewController"];
- ViewController.url = url;
- ViewController.canSave = false;
- ViewController.isLocalfile=isLocalFile;
- ViewController.defaultStyle = true;
- NSString* subject;
- // if (company.length==0) {
-
- NSString* cur_time =[RAUtils current_date];
- subject =name;//[NSString stringWithFormat:@"NPD Product List %@",cur_time];
-
- AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
- // NSString* customer_email= [appDelegate.customerInfo valueForKey:@"customer_email"];
-
-
- NSMutableArray* send_to = [[NSMutableArray alloc]init];
- // if(customer_email.length>0)
- // {
- // send_to=[[customer_email componentsSeparatedByString:NSLocalizedString(@";", nil)] mutableCopy];
- // // customer_email compo
- // // [send_to addObject:customer_email];
- // }
- ViewController.mail_to = send_to;
-
- // }
- // else
- // {
- // subject = [NSString stringWithFormat:@"Tear sheet for %@",company ];
- // }
- // ViewController.attachment_name = [NSString stringWithFormat:@"NPD_Product_List %@.pdf",cur_time];
- ViewController.mail_subject = subject;
-
- ViewController.hidenavi = false;
- [self.navigationController pushViewController:ViewController animated:YES];
- }
- - (IBAction)OnHICClick:(id)sender {
-
-
- __weak typeof(self) weakSelf = self;
-
-
- DocumentPageViewController* dvc = [self.storyboard instantiateViewControllerWithIdentifier:@"DocumentPageViewController" ];
-
- dvc.templateName = @"GEIC - Home Improvement Contract 2016.json";
- dvc.pdfName = @"GEIC - Home Improvement Contract 2017.pdf";
-
- dvc.OnSave=^(NSString* file)
- {
- // [weakSelf previewPDF:file];
- };
-
- [self.navigationController pushViewController:dvc animated:true];
- }
- - (IBAction)OnSRLClick:(id)sender {
-
- DocumentPageViewController* dvc = [self.storyboard instantiateViewControllerWithIdentifier:@"DocumentPageViewController" ];
-
- dvc.templateName = @"SUBCONTRACTORS REFERRAL LIST.json";
- dvc.pdfName = @"SUBCONTRACTORS REFERRAL LIST.pdf";
- dvc.OnSave=^(NSString* file)
- {
-
- //[self previewPDF:file];
- };
-
- [self.navigationController pushViewController:dvc animated:true];
- }
- @end
|