SyncControlPanelViewController.m 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. //
  2. // SyncControlPanelViewController.m
  3. // iSales-NPD
  4. //
  5. // Created by Ray on 7/8/16.
  6. // Copyright © 2016 United Software Applications, Inc. All rights reserved.
  7. //
  8. #import "SyncControlPanelViewController.h"
  9. #import "AppDelegate.h"
  10. #import "RAUtils.h"
  11. #import "DBUtil.h"
  12. @interface SyncControlPanelViewController ()
  13. @end
  14. @implementation SyncControlPanelViewController
  15. - (void)viewDidLoad {
  16. [super viewDidLoad];
  17. // self.edgesForExtendedLayout = UIRectEdgeNone ;
  18. self.closeButton = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"close"] imageWithRenderingMode:UIImageRenderingModeAutomatic]
  19. style:UIBarButtonItemStylePlain
  20. target:self
  21. action:@selector( onCloseClick:)];
  22. self.closeButton.enabled=false;
  23. self.navigationItem.rightBarButtonItem = self.closeButton;
  24. self.tv_log.layer.borderWidth=1 ; //边框粗细
  25. self.tv_log.layer.borderColor=[UIColor darkGrayColor].CGColor; //边框颜色
  26. UIApplication * app = [UIApplication sharedApplication];
  27. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  28. appDelegate.settingUI=self;
  29. // Do any additional setup after loading the view.
  30. }
  31. - (void)onCloseClick:(UIButton *)sender {
  32. // if(self.onDismissVC)
  33. // self.onDismissVC();
  34. [self dismissViewControllerAnimated:true completion:nil];
  35. }
  36. - (void)didReceiveMemoryWarning {
  37. [super didReceiveMemoryWarning];
  38. // Dispose of any resources that can be recreated.
  39. }
  40. -(void) onProgressUpdate
  41. {
  42. dispatch_async(dispatch_get_main_queue(), ^{
  43. UIApplication * app = [UIApplication sharedApplication];
  44. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  45. self.progress_overall.progress= appDelegate.overall_progress;
  46. self.progress_current.progress= appDelegate.file_progress;
  47. });
  48. }
  49. - (IBAction)onSendlogClick:(id)sender {
  50. UIApplication * app = [UIApplication sharedApplication];
  51. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  52. if(appDelegate.downloadlog.length==0)
  53. {
  54. [RAUtils message_box:@"Sending log" message:@"Log is empty sending canceled." completion:nil];
  55. return;
  56. }
  57. MFMailComposeViewController *mc = [[MFMailComposeViewController alloc] init];
  58. if(mc==nil)
  59. return;
  60. mc.mailComposeDelegate = self;
  61. [mc setSubject:@"offline sync log"];
  62. [mc setToRecipients:@[@"ray.zhang@united-cn.net",@"RedAntSupport@united-us.net"]];
  63. NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
  64. // CFShow(infoDictionary);
  65. // app名称
  66. NSString *app_Name = [infoDictionary objectForKey:@"CFBundleName"];
  67. // app版本
  68. NSString *app_Version = [infoDictionary objectForKey:@"CFBundleShortVersionString"];
  69. // app build版本
  70. NSString *app_build = [infoDictionary objectForKey:@"CFBundleVersion"];
  71. NSString* appinfo =[NSString stringWithFormat:@"App info: %@ %@ build%@</br>",app_Name,app_Version,app_build];
  72. NSString* userinfo =[NSString stringWithFormat:@"login info: %@ </br>",RASingleton.sharedInstance.user];
  73. // if(self.mail_content==nil)
  74. // self.mail_content=@"";
  75. NSString* htmlbody = [NSString stringWithFormat:@"<p>%@</p></br>%@%@</br></br>%@",@"Process description:",appinfo,userinfo,[appDelegate.downloadlog stringByReplacingOccurrencesOfString:@"\n" withString:@"</br>"]];
  76. [mc setMessageBody:htmlbody
  77. isHTML:YES];
  78. // NSData *data = [appDelegate.downloadlog dataUsingEncoding:NSUTF8StringEncoding];//[NSData dataWithContentsOfFile:filePath];
  79. // if(self.attachment_name.length>0)
  80. // filename = self.attachment_name;
  81. NSString* dbzippath= [DBUtil getdbzip:DBNAME];
  82. NSData *data1 = [NSData dataWithContentsOfFile:dbzippath];
  83. // filename=@"database.db";
  84. // [mc addAttachmentData:data mimeType:@"text/plain" fileName:filename];
  85. [mc addAttachmentData:data1 mimeType:@"application/zip" fileName:@"db.zip"];
  86. // [self presentModalViewController:mc animated:YES];
  87. [self presentViewController:mc animated:YES completion:nil];
  88. return;
  89. }
  90. -(void) onLogUpdate
  91. {
  92. UIApplication * app = [UIApplication sharedApplication];
  93. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  94. dispatch_async(dispatch_get_main_queue(), ^{
  95. self.tv_log.text = appDelegate.downloadlog;
  96. [self.tv_log scrollRangeToVisible:NSMakeRange(appDelegate.downloadlog.length-1,0)];
  97. });
  98. }
  99. -(void) onSyncFinish
  100. {
  101. self.closeButton.enabled=true;
  102. // UIApplication * app = [UIApplication sharedApplication];
  103. // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  104. // appDelegate.downloadlog=nil;
  105. // appDelegate.downloading=false;
  106. //// self.downloadlog=nil;
  107. //// self.downloading=false;
  108. // appDelegate.download_task=nil;
  109. // appDelegate.vid=nil;
  110. }
  111. /*
  112. #pragma mark - Navigation
  113. // In a storyboard-based application, you will often want to do a little preparation before navigation
  114. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  115. // Get the new view controller using [segue destinationViewController].
  116. // Pass the selected object to the new view controller.
  117. }
  118. */
  119. - (void)mailComposeController:(MFMailComposeViewController*)controller
  120. didFinishWithResult:(MFMailComposeResult)result
  121. error:(NSError*)error {
  122. switch (result)
  123. {
  124. case MFMailComposeResultCancelled:
  125. DebugLog(@"Mail send canceled...");
  126. break;
  127. case MFMailComposeResultSaved:
  128. DebugLog(@"Mail saved...");
  129. break;
  130. case MFMailComposeResultSent:
  131. DebugLog(@"Mail sent...");
  132. break;
  133. case MFMailComposeResultFailed:
  134. DebugLog(@"Mail send errored: %@...", [error localizedDescription]);
  135. break;
  136. default:
  137. break;
  138. }
  139. // [self dismissModalViewControllerAnimated:YES];
  140. [self dismissViewControllerAnimated:YES completion:nil];
  141. }
  142. @end