SelectUploadOrderViewController.m 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. //
  2. // SelectUploadOrderViewController.m
  3. // iSales-NPD
  4. //
  5. // Created by Ray on 9/3/16.
  6. // Copyright © 2016 United Software Applications, Inc. All rights reserved.
  7. //
  8. #import "SelectUploadOrderViewController.h"
  9. #import "iSalesDB.h"
  10. #import <sqlite3.h>
  11. #import "SelectOrderTableViewCell.h"
  12. #import "DefaultTableHeaderView.h"
  13. #import "DefaultAppearance.h"
  14. @interface SelectUploadOrderViewController ()<UITableViewDataSource,UITableViewDelegate>
  15. @property (nonatomic,strong) NSMutableArray<NSDictionary *> *sync_data;
  16. @property (strong, nonatomic) IBOutlet UITableView *syncDataTableView;
  17. @property (strong, nonatomic) IBOutlet UIButton *uploadButton;
  18. @end
  19. @implementation SelectUploadOrderViewController
  20. - (void)viewDidLoad {
  21. [super viewDidLoad];
  22. // Do any additional setup after loading the view.
  23. // self.syncDataTableView.delegate = self;
  24. // self.syncDataTableView.dataSource = self;
  25. UIBarButtonItem *closeButton = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"close"] imageWithRenderingMode:UIImageRenderingModeAutomatic]
  26. style:UIBarButtonItemStylePlain
  27. target:self
  28. action:@selector( onCloseClick:)];
  29. self.navigationItem.rightBarButtonItem = closeButton;
  30. }
  31. - (void)didReceiveMemoryWarning {
  32. [super didReceiveMemoryWarning];
  33. // Dispose of any resources that can be recreated.
  34. }
  35. - (NSMutableArray<NSDictionary *> *)sync_data {
  36. if (!_sync_data) {
  37. _sync_data = [NSMutableArray array];
  38. NSString *sql = @"select decrypt(c.company_name),o.so_id,o.sync_data from (select so_id,sync_data,customer_cid from offline_order where sync_data not null) as o join offline_contact as c on c.contact_id = o.customer_cid ;";
  39. [iSalesDB jk_query:sql completion:^(sqlite3_stmt *stmt, NSMutableDictionary *container, long *count) {
  40. const char *cn = (char *)sqlite3_column_text(stmt,0);
  41. if (cn == NULL) {
  42. cn = "";
  43. }
  44. const char *_id = (char *)sqlite3_column_text(stmt,1);
  45. if (_id == NULL) {
  46. _id = "";
  47. }
  48. const char *data = (char *)sqlite3_column_text(stmt,2);
  49. if (data == NULL) {
  50. data = "";
  51. }
  52. NSString *company_name = [NSString stringWithUTF8String:cn];
  53. NSString *so_id = [NSString stringWithUTF8String:_id];
  54. NSString *sync_data_str = [NSString stringWithUTF8String:data];
  55. NSDictionary *dic = [@{
  56. @"check" : @(1),
  57. @"company_name" : company_name,
  58. @"so_id" : so_id,
  59. @"sync_data" : sync_data_str
  60. } mutableCopy];
  61. [_sync_data addObject:dic];
  62. }];
  63. }
  64. return _sync_data;
  65. }
  66. - (IBAction)uploadButtonClicked:(UIButton *)sender {
  67. NSMutableArray *uploadArray = [NSMutableArray array];
  68. for (NSDictionary *dic in self.sync_data) {
  69. int check = [dic[@"check"] integerValue];
  70. NSString *so_id = dic[@"so_id"];
  71. if (check == 1) {
  72. [uploadArray addObject:so_id];
  73. }
  74. }
  75. [self dismissViewControllerAnimated:true completion:^{
  76. if (self.returnValue ) {
  77. self.returnValue(uploadArray);
  78. } ;
  79. }];
  80. }
  81. #pragma mark - dataSource
  82. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  83. return 1;
  84. }
  85. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  86. return self.sync_data.count;
  87. }
  88. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  89. SelectOrderTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"SelectOrderTableViewCell" forIndexPath:indexPath];
  90. NSDictionary *dic = [self.sync_data objectAtIndex:indexPath.row];
  91. int check = [dic[@"check"] integerValue];
  92. NSString *so_id = dic[@"so_id"];
  93. NSString *company_name = dic[@"company_name"];
  94. if (check)
  95. cell.checkedButton.selected = YES;
  96. cell.labelsoid.text = so_id;
  97. cell.labelcompany.text = company_name;
  98. __weak typeof(self) weakSelf = self;
  99. __weak typeof(tableView) weakTable = tableView;
  100. // NSIndexPath *idxPath = [NSIndexPath indexPathForRow:indexPath.row inSection:0];
  101. cell.checkBlock = ^{
  102. [weakSelf tableView:weakTable didSelectRowAtIndexPath:indexPath];
  103. };
  104. return cell;
  105. }
  106. #pragma mark - delegate
  107. - (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  108. {
  109. NSString* value =[DefaultAppearance get_noneappearance_value:@"DefaultTableHeaderView" valuename:@"title_text_color"];
  110. if(value==nil)
  111. value=@"";
  112. unsigned long color = strtoul([value UTF8String],0,16);
  113. DefaultTableHeaderView* myView = [[DefaultTableHeaderView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 0.0001)];
  114. myView.layer.shadowPath =[UIBezierPath bezierPathWithRect:myView.bounds].CGPath;
  115. myView.layer.shadowColor = [UIColor blackColor].CGColor;
  116. myView.layer.shadowOffset = CGSizeMake(0, 0);
  117. myView.layer.shadowOpacity = 0.5;
  118. myView.layer.shadowRadius = 2.0;
  119. UILabel *solabel = [[UILabel alloc] initWithFrame:CGRectMake(48, 2, 100, 22)];
  120. solabel.textColor=UIColorFromRGB(color);
  121. solabel.backgroundColor = [UIColor clearColor];
  122. solabel.text=NSLocalizedString(@"SO#", nil);
  123. [solabel sizeToFit];
  124. [myView addSubview:solabel];
  125. UILabel *userlabel = [[UILabel alloc] initWithFrame:CGRectMake(48, 21, 100, 22)];
  126. userlabel.textColor=UIColorFromRGB(color);
  127. userlabel.backgroundColor = [UIColor clearColor];
  128. userlabel.text=NSLocalizedString(@"Contact", nil);
  129. [userlabel sizeToFit];
  130. [myView addSubview:userlabel];
  131. myView.autoresizesSubviews=true;
  132. myView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
  133. //
  134. return myView;
  135. }
  136. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  137. {
  138. return 44;
  139. }
  140. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  141. return 86;
  142. }
  143. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  144. SelectOrderTableViewCell *cell = (SelectOrderTableViewCell *)[tableView cellForRowAtIndexPath:indexPath];
  145. cell.selected = NO;
  146. cell.checkedButton.selected = !cell.checkedButton.selected;
  147. NSMutableDictionary *dic = (NSMutableDictionary *)[self.sync_data objectAtIndex:indexPath.row];
  148. int check = [dic[@"check"] integerValue];
  149. if (cell.checkedButton.selected) {
  150. check = 1;
  151. } else {
  152. check = 0;
  153. }
  154. [dic setValue:[NSNumber numberWithInteger:check] forKey:@"check"];
  155. }
  156. //- (BOOL
  157. - (void)onCloseClick:(UIButton *)sender {
  158. [self dismissViewControllerAnimated:true completion:nil];
  159. }
  160. @end