BundleModelViewController.m 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. //
  2. // BundleModelViewController.m
  3. // RedAnt ERP Mobile
  4. //
  5. // Created by Ray on 10/31/15.
  6. // Copyright © 2015 United Software Applications, Inc. All rights reserved.
  7. //
  8. #import "BundleModelViewController.h"
  9. #import "const.h"
  10. #import "BundleModelCell.h"
  11. #import "DefaultTableHeaderView.h"
  12. #import "DefaultAppearance.h"
  13. #define DEF_CELL_HEIGHT 44
  14. //#define DEF_TABLE_HEIGHT 44
  15. //#define LINE_WIDTH 0
  16. //#define CELL_MARGIN 0
  17. #define LABEL_MARGIN 11
  18. @interface BundleModelViewController ()
  19. @end
  20. @implementation BundleModelViewController
  21. - (void)viewDidLoad {
  22. [super viewDidLoad];
  23. self.navigationItem.title=@"Bundle Items";
  24. UIBarButtonItem *closeButton = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"close"] imageWithRenderingMode:UIImageRenderingModeAutomatic]
  25. style:UIBarButtonItemStylePlain
  26. target:self
  27. action:@selector( onCloseClick:)];
  28. //[[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Close", nil) style:UIBarButtonItemStylePlain target:self action:@selector(onCloseClick:)];
  29. // closeButton.title = @"Close";
  30. self.navigationItem.rightBarButtonItem = closeButton;
  31. // Do any additional setup after loading the view.
  32. }
  33. - (void)onCloseClick:(UIButton *)sender {
  34. [self dismissViewControllerAnimated:true completion:nil];
  35. }
  36. - (void)didReceiveMemoryWarning {
  37. [super didReceiveMemoryWarning];
  38. // Dispose of any resources that can be recreated.
  39. }
  40. /*
  41. #pragma mark - Navigation
  42. // In a storyboard-based application, you will often want to do a little preparation before navigation
  43. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  44. // Get the new view controller using [segue destinationViewController].
  45. // Pass the selected object to the new view controller.
  46. }
  47. */
  48. #pragma mark - Table view data source
  49. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
  50. {
  51. NSDictionary * item_json = [self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  52. NSString* value = [item_json valueForKey:@"description"];
  53. float width = 254;
  54. width-=40;
  55. CGSize constraintkey = CGSizeMake(width-2*LABEL_MARGIN, 10.0f);//key label width is 40% cell width;
  56. CGRect frame;
  57. frame.size = constraintkey;
  58. frame.origin.x=0;
  59. frame.origin.y=0;
  60. RTLabel* rtlabel = [[RTLabel alloc] initWithFrame:frame];
  61. [rtlabel setText: value];
  62. CGSize optimumSize = [rtlabel optimumSize];
  63. float height = optimumSize.height;
  64. height = MAX(height+2*LABEL_MARGIN, DEF_CELL_HEIGHT);
  65. return height;
  66. }
  67. //- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  68. //{
  69. // return 0;
  70. //}
  71. //- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
  72. //{
  73. // return 0;
  74. //}
  75. //- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
  76. //{
  77. // UIView* myView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 0.0001)];
  78. // return myView;
  79. //
  80. //}
  81. //- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  82. //{
  83. // UIView* myView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 0.0001)];
  84. //// myView.backgroundColor = [UIColor colorWithRed:0.10 green:0.68 blue:0.94 alpha:0.7];
  85. //// UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, 90, 22)];
  86. //// titleLabel.textColor=[UIColor whiteColor];
  87. //// titleLabel.backgroundColor = [UIColor clearColor];
  88. //// if(section==0)
  89. //// titleLabel.text=NSLocalizedString(@"display_items", nil);
  90. //// else
  91. //// titleLabel.text=NSLocalizedString(@"hide_items", nil);
  92. //// [titleLabel sizeToFit];
  93. //// [myView addSubview:titleLabel];
  94. ////
  95. // return myView;
  96. //}
  97. //
  98. //- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
  99. // if(section==0)
  100. // return nil;
  101. // else
  102. // return @"detail section";
  103. //}
  104. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  105. {
  106. return 1;
  107. }
  108. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  109. {
  110. return 33;
  111. }
  112. - (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  113. {
  114. NSString* value =[DefaultAppearance get_noneappearance_value:@"DefaultTableHeaderView" valuename:@"title_text_color"];
  115. if(value==nil)
  116. value=@"";
  117. unsigned long color = strtoul([value UTF8String],0,16);
  118. DefaultTableHeaderView* myView = [[DefaultTableHeaderView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 0.0001)];
  119. // myView.backgroundColor = UIColorFromRGB(0x996633);
  120. myView.layer.shadowColor = [UIColor blackColor].CGColor;
  121. myView.layer.shadowOffset = CGSizeMake(0, 0);
  122. myView.layer.shadowOpacity = 0.5;
  123. myView.layer.shadowRadius = 2.0;
  124. UILabel *modellabel = [[UILabel alloc] initWithFrame:CGRectMake(50, 5.5, 90, 22)];
  125. modellabel.textColor=UIColorFromRGB(color);
  126. modellabel.backgroundColor = [UIColor clearColor];
  127. modellabel.text=NSLocalizedString(@"Model", nil);
  128. [modellabel sizeToFit];
  129. [myView addSubview:modellabel];
  130. UILabel *description = [[UILabel alloc] initWithFrame:CGRectMake(200, 5.5, 90, 22)];
  131. description.textColor=UIColorFromRGB(color);
  132. description.backgroundColor = [UIColor clearColor];
  133. description.text=NSLocalizedString(@"Description", nil);
  134. [description sizeToFit];
  135. [myView addSubview:description];
  136. UILabel *qtylabel = [[UILabel alloc] initWithFrame:CGRectMake(400, 5.5, 90, 22)];
  137. qtylabel.textColor=UIColorFromRGB(color);
  138. qtylabel.backgroundColor = [UIColor clearColor];
  139. qtylabel.text=NSLocalizedString(@"QTY", nil);
  140. [qtylabel sizeToFit];
  141. [myView addSubview:qtylabel];
  142. UILabel *pricelabel = [[UILabel alloc] initWithFrame:CGRectMake(450, 5.5, 90, 22)];
  143. pricelabel.textColor=UIColorFromRGB(color);
  144. pricelabel.backgroundColor = [UIColor clearColor];
  145. pricelabel.text=NSLocalizedString(@"Unit Price", nil);
  146. [pricelabel sizeToFit];
  147. [myView addSubview:pricelabel];
  148. //
  149. return myView;
  150. }
  151. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  152. {
  153. // NSDictionary * item_json = [self.content_data objectForKey:@"items"];
  154. int count =[[self.content_data valueForKey:@"count"] intValue];
  155. return count;
  156. }
  157. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  158. {
  159. NSString *CellIdentifier = @"BundleModelCell";
  160. BundleModelCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  161. NSDictionary * item_json = [self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  162. cell.labelModel.text = [item_json valueForKey:@"model"];
  163. if([ [NSString stringWithFormat:@"%@", [item_json valueForKey:@"unit_price"] ] isEqualToString:@"No Price"])
  164. cell.labelPrice.text=@"No Price";
  165. else
  166. cell.labelPrice.text=[NSString stringWithFormat:@"$%.2f",[[item_json valueForKey:@"unit_price"] floatValue]];
  167. cell.labelQTY.text=[NSString stringWithFormat:@"%d",[[item_json valueForKey:@"modulus"] intValue]];
  168. cell.labelDescription.text = [item_json valueForKey:@"description"];
  169. cell.backgroundColor = [UIColor whiteColor];
  170. return cell;
  171. // }
  172. // else
  173. // {
  174. // NSString *CellIdentifier = @"OrderInfoListItem";
  175. // UITableViewCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  176. // return cell;
  177. // }
  178. }
  179. @end