DurationPopupView.m 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. //
  2. // DurationPopupView.m
  3. // kneet2
  4. //
  5. // Created by Jason Lee on 1/25/16.
  6. // Copyright (c) 2015 ntels. All rights reserved.
  7. //
  8. #import "JDObject.h"
  9. #import "CustomLabel.h"
  10. #import "CustomButton.h"
  11. #import "DurationPopupView.h"
  12. #import "DatePickerButton.h"
  13. #import "CustomTextField.h"
  14. @interface DurationPopupView ()<UITextFieldDelegate> {
  15. }
  16. @end
  17. @implementation DurationPopupView
  18. - (id)initFromNib {
  19. for (UIView *view in [CommonUtil nibViews:@"DurationPopupView"]) {
  20. if ([view isKindOfClass:[DurationPopupView class]]) {
  21. self = (DurationPopupView *)view;
  22. //XIB의 경우, 현재 화면 사이즈로 맞춰줘야 함.
  23. self.frame = [UIScreen mainScreen].bounds;
  24. NSDate *date = [NSDate new];
  25. _tfStartYear.placeholder = _tfEndYear.placeholder = [NSString stringWithFormat:@"%ld", date.year];
  26. _tfStartMonth.placeholder = _tfEndMonth.placeholder = [NSString stringWithFormat:@"%ld", date.month];
  27. _tfStartDay.placeholder = _tfEndDay.placeholder = [NSString stringWithFormat:@"%ld", date.day];
  28. [self.imgTitleBar setImage:[UIImage imageNamed:@"img_popup_bg_head"]inset:UIEdgeInsetsMake(kfTopInset,kfRightInset,kfBottomInset,kfLeftInset)];
  29. [self.btnConfirm setBackgroundImage:[UIImage imageNamed:@"img_popup_btn_right"] forState:UIControlStateNormal capInsets:UIEdgeInsetsMake(kfTopInset,kfRightInset,kfBottomInset,kfLeftInset)];
  30. [self.btnConfirm setBackgroundImage:[UIImage imageNamed:@"img_popup_btn_right_press"] forState:UIControlStateHighlighted capInsets:UIEdgeInsetsMake(kfTopInset,kfRightInset,kfBottomInset,kfLeftInset)];
  31. [self.btnCancel setBackgroundImage:[UIImage imageNamed:@"img_popup_btn_left"] forState:UIControlStateNormal capInsets:UIEdgeInsetsMake(kfTopInset,kfRightInset,kfBottomInset,kfLeftInset)];
  32. [self.btnCancel setBackgroundImage:[UIImage imageNamed:@"img_popup_btn_left_press"] forState:UIControlStateHighlighted capInsets:UIEdgeInsetsMake(kfTopInset,kfRightInset,kfBottomInset,kfLeftInset)];
  33. //Localization
  34. [self.btnConfirm setTitle:NSLocalizedString(@"확인", @"확인") forState:UIControlStateNormal];
  35. [self.btnCancel setTitle:NSLocalizedString(@"취소", @"취소") forState:UIControlStateNormal];
  36. }
  37. }
  38. return self;
  39. }
  40. - (void)didMoveToSuperview {
  41. }
  42. - (void)setCondition:(ItemModel *)condition {
  43. _condition = condition;
  44. if (_condition.itemSubTypeCode && [_condition.itemSubTypeCode isEqualToString:ksConditionSubTypeCodeDueDate]) {
  45. // ItemSubModel *subCondition = _condition.subItems && _condition.subItems.count ? _condition.subItems[0] : nil;
  46. // if (subCondition) {
  47. // //set values.
  48. // NSArray *darray = [subCondition.cmdclsValueMsg componentsSeparatedByString:@"~"];
  49. //
  50. // //from
  51. // [_btnFrom setTitle:darray[0] forState:UIControlStateNormal];
  52. // if (darray.count > 1) {//to
  53. // [_btnTo setTitle:darray[1] forState:UIControlStateNormal];
  54. // }
  55. // }
  56. } else {
  57. _condition.itemName = @"이 기간동안만";
  58. _condition.itemSubTypeCode = ksConditionSubTypeCodeDueDate;
  59. }
  60. }
  61. #pragma mark - textfiled delegate
  62. - (void)moveToNextField:(id)sender {
  63. UITextField *tf = sender;
  64. UITextField *nextTf = [self viewWithTag:tf.tag + 1];
  65. [nextTf becomeFirstResponder];
  66. }
  67. - (void)moveToPrevField:(id)sender {
  68. UITextField *tf = sender;
  69. UITextField *nextTf = [self viewWithTag:tf.tag - 1];
  70. [nextTf becomeFirstResponder];
  71. }
  72. - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
  73. NSString *text = [textField.text stringByReplacingCharactersInRange:range withString:string];
  74. BOOL isYear = textField.tag == 1 || textField.tag == 4;
  75. BOOL isMonth = textField.tag == 2 || textField.tag == 5;
  76. BOOL isDay = textField.tag == 3 || textField.tag == 6;
  77. //4자리 입력
  78. if (isYear && text.length > 4) {
  79. return NO;
  80. }
  81. else if(isMonth && [text integerValue] > 12) {
  82. textField.text = @"12" ;
  83. return NO;
  84. }
  85. else if(isDay && [text integerValue] > 31) {
  86. textField.text = @"31" ;
  87. return NO;
  88. }
  89. else if(!isYear && text.length > 2) {
  90. return NO;
  91. }
  92. return YES;
  93. }
  94. //custom textfiled auto scroll
  95. - (void)textFieldDidBeginEditing:(UITextField *)textField {
  96. [textField becomeFirstResponder];
  97. }
  98. - (BOOL)validateDate{
  99. NSDate *today = [NSDate new];
  100. NSString *todayStr = [NSString stringWithFormat:@"%04ld%02ld%02ld", today.year, today.month, today.day];
  101. BOOL check = YES;
  102. NSString *start = [NSString stringWithFormat:@"%04ld%02ld%02ld",
  103. [_tfStartYear.text integerValue],
  104. [_tfStartMonth.text integerValue],
  105. [_tfStartDay.text integerValue]];
  106. NSString *end = [NSString stringWithFormat:@"%04ld%02ld%02ld",
  107. [_tfEndYear.text integerValue],
  108. [_tfEndMonth.text integerValue],
  109. [_tfEndDay.text integerValue]];
  110. if ([todayStr integerValue] > [start integerValue]) check = NO;
  111. if ([todayStr integerValue] > [end integerValue]) check = NO;
  112. NSLog(@"check : %d", check);
  113. NSLog(@"%ld %ld", [todayStr integerValue], [start integerValue]);
  114. if (!check) [[JDFacade facade] alert:@"기간을 다시 확인하세요."];
  115. return check;
  116. }
  117. #pragma mark - UI Events
  118. - (IBAction)btnConfirmTouched:(id)sender {
  119. //validate
  120. ItemSubModel *subCondition = nil;
  121. if (_condition.subItems && _condition.subItems.count) {
  122. subCondition = _condition.subItems[0];
  123. } else {
  124. subCondition = [[ItemSubModel alloc] init];
  125. _condition.subItems = (NSMutableArray<ItemSubModel> *)[[NSMutableArray alloc] init];
  126. [_condition.subItems addObject:subCondition];
  127. }
  128. NSString *start = [NSString stringWithFormat:@"%04ld%02ld%02ld",
  129. [_tfStartYear.text integerValue],
  130. [_tfStartMonth.text integerValue],
  131. [_tfStartDay.text integerValue]];
  132. NSString *end = [NSString stringWithFormat:@"%04ld%02ld%02ld",
  133. [_tfEndYear.text integerValue],
  134. [_tfEndMonth.text integerValue],
  135. [_tfEndDay.text integerValue]];
  136. if (![self validateDate])
  137. return;
  138. // subCondition.sourceId = @"VAR";
  139. subCondition.conditionTypeCode = @"09";
  140. subCondition.cmdclsValue = [NSString stringWithFormat:@"%@~%@", start, end];
  141. subCondition.cmdclsValueMsg = [NSString stringWithFormat:@"%@ ~ %@", start, end];
  142. [super btnConfirmTouched:sender];
  143. }
  144. @end