SelectUploadOrderViewController.m 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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. @interface SelectUploadOrderViewController ()<UITableViewDataSource,UITableViewDelegate>
  13. @property (nonatomic,strong) NSMutableArray<NSDictionary *> *sync_data;
  14. @property (strong, nonatomic) IBOutlet UITableView *syncDataTableView;
  15. @property (strong, nonatomic) IBOutlet UIButton *uploadButton;
  16. @end
  17. @implementation SelectUploadOrderViewController
  18. - (void)viewDidLoad {
  19. [super viewDidLoad];
  20. // Do any additional setup after loading the view.
  21. // self.syncDataTableView.delegate = self;
  22. // self.syncDataTableView.dataSource = self;
  23. }
  24. - (void)didReceiveMemoryWarning {
  25. [super didReceiveMemoryWarning];
  26. // Dispose of any resources that can be recreated.
  27. }
  28. - (NSMutableArray<NSDictionary *> *)sync_data {
  29. if (!_sync_data) {
  30. _sync_data = [NSMutableArray array];
  31. 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 ;";
  32. [iSalesDB jk_query:sql completion:^(sqlite3_stmt *stmt, NSMutableDictionary *container, long *count) {
  33. const char *cn = (char *)sqlite3_column_text(stmt,0);
  34. if (cn == NULL) {
  35. cn = "";
  36. }
  37. const char *_id = (char *)sqlite3_column_text(stmt,1);
  38. if (_id == NULL) {
  39. _id = "";
  40. }
  41. const char *data = (char *)sqlite3_column_text(stmt,2);
  42. if (data == NULL) {
  43. data = "";
  44. }
  45. NSString *company_name = [NSString stringWithUTF8String:cn];
  46. NSString *so_id = [NSString stringWithUTF8String:_id];
  47. NSString *sync_data_str = [NSString stringWithUTF8String:data];
  48. NSDictionary *dic = [@{
  49. @"check" : @(1),
  50. @"company_name" : company_name,
  51. @"so_id" : so_id,
  52. @"sync_data" : sync_data_str
  53. } mutableCopy];
  54. [_sync_data addObject:dic];
  55. }];
  56. }
  57. return _sync_data;
  58. }
  59. - (IBAction)uploadButtonClicked:(UIButton *)sender {
  60. NSMutableArray *uploadArray = [NSMutableArray array];
  61. for (NSDictionary *dic in self.sync_data) {
  62. int check = [dic[@"check"] integerValue];
  63. NSString *so_id = dic[@"so_id"];
  64. if (check == 1) {
  65. [uploadArray addObject:so_id];
  66. }
  67. }
  68. [self dismissViewControllerAnimated:true completion:^{
  69. if (self.returnValue ) {
  70. self.returnValue(uploadArray);
  71. } ;
  72. }];
  73. }
  74. #pragma mark - dataSource
  75. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  76. return 1;
  77. }
  78. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  79. return self.sync_data.count;
  80. }
  81. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  82. SelectOrderTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"SelectOrderTableViewCell" forIndexPath:indexPath];
  83. NSDictionary *dic = [self.sync_data objectAtIndex:indexPath.row];
  84. int check = [dic[@"check"] integerValue];
  85. NSString *so_id = dic[@"so_id"];
  86. NSString *company_name = dic[@"company_name"];
  87. if (check)
  88. cell.checkedButton.selected = YES;
  89. cell.labelsoid.text = so_id;
  90. cell.labelcompany.text = company_name;
  91. __weak typeof(self) weakSelf = self;
  92. __weak typeof(tableView) weakTable = tableView;
  93. // NSIndexPath *idxPath = [NSIndexPath indexPathForRow:indexPath.row inSection:0];
  94. cell.checkBlock = ^{
  95. [weakSelf tableView:weakTable didSelectRowAtIndexPath:indexPath];
  96. };
  97. return cell;
  98. }
  99. #pragma mark - delegate
  100. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  101. return 44;
  102. }
  103. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  104. SelectOrderTableViewCell *cell = (SelectOrderTableViewCell *)[tableView cellForRowAtIndexPath:indexPath];
  105. cell.selected = NO;
  106. cell.checkedButton.selected = !cell.checkedButton.selected;
  107. NSMutableDictionary *dic = (NSMutableDictionary *)[self.sync_data objectAtIndex:indexPath.row];
  108. int check = [dic[@"check"] integerValue];
  109. if (cell.checkedButton.selected) {
  110. check = 1;
  111. } else {
  112. check = 0;
  113. }
  114. [dic setValue:[NSNumber numberWithInteger:check] forKey:@"check"];
  115. }
  116. //- (BOOL
  117. @end