SelectUploadOrderViewController.m 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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 == 0) {
  65. [uploadArray addObject:so_id];
  66. }
  67. }
  68. if (self.returnValue && uploadArray.count) {
  69. self.returnValue(uploadArray);
  70. }
  71. [self dismissViewControllerAnimated:true completion:nil];
  72. }
  73. #pragma mark - dataSource
  74. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  75. return 1;
  76. }
  77. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  78. return self.sync_data.count;
  79. }
  80. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  81. SelectOrderTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"SelectOrderTableViewCell" forIndexPath:indexPath];
  82. NSDictionary *dic = [self.sync_data objectAtIndex:indexPath.row];
  83. int check = [dic[@"check"] integerValue];
  84. NSString *so_id = dic[@"so_id"];
  85. NSString *company_name = dic[@"company_name"];
  86. if (check)
  87. cell.checkedButton.selected = YES;
  88. cell.labelsoid.text = so_id;
  89. cell.labelcompany.text = company_name;
  90. return cell;
  91. }
  92. #pragma mark - delegate
  93. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  94. return 44;
  95. }
  96. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  97. SelectOrderTableViewCell *cell = (SelectOrderTableViewCell *)[tableView cellForRowAtIndexPath:indexPath];
  98. cell.selected = NO;
  99. cell.checkedButton.selected = !cell.checkedButton.selected;
  100. NSMutableDictionary *dic = (NSMutableDictionary *)[self.sync_data objectAtIndex:indexPath.row];
  101. int check = [dic[@"check"] integerValue];
  102. if (cell.checkedButton.selected) {
  103. check = 1;
  104. } else {
  105. check = 0;
  106. }
  107. [dic setValue:[NSNumber numberWithInteger:check] forKey:@"check"];
  108. }
  109. //- (BOOL
  110. @end