You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

194 lines
8.2 KiB

//
// AddDBViewController.m
// watch
//
// Created by xTT on 2017/7/15.
// Copyright © 2017年 xTT. All rights reserved.
//
#import "AddDBViewController.h"
#import "AddWeekTableViewCell.h"
#import "DurationTimeTableViewCell.h"
#import "DisturbBan.h"
#import "SelectWeekViewController.h"
@interface AddDBViewController ()
@end
@implementation AddDBViewController
@synthesize myDataSource = _myDataSource;
- (NSMutableArray *)myDataSource{
if (!_myDataSource) {
_myDataSource = [[NSMutableArray alloc] initWithArray:@[@[@"时间",@"星期"]]];
}
return _myDataSource;
}
- (DisturbBan *)infoDisturBan{
if (!_infoDisturBan) {
_infoDisturBan = [[DisturbBan alloc] init];
[_infoDisturBan setDefaultValue];
}
return _infoDisturBan;
}
-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
if (!self.isAdd) {
self.title = @"添加上课禁用";
}else{
self.title = @"编辑上课禁用";
}
}
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
[self zx_setRightBtnWithText:@"保存" clickedBlock:^(ZXNavItemBtn * _Nonnull btn) {
[self rightBarItemClick];
}];
[self.myTableView mas_remakeConstraints:^(MASConstraintMaker *make) {
make.left.right.equalTo(self.view);
make.top.equalTo(self.view).offset(iPhoneX_NavHeight);
make.bottom.equalTo(self.view.mas_bottom);
}];
//注册 cell
[self.myTableView registerNib:[UINib nibWithNibName:@"AddWeekTableViewCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"AddWeekTableViewCellID"];
[self.myTableView registerNib:[UINib nibWithNibName:@"DurationTimeTableViewCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"DurationTimeTableViewCellID"];
}
- (void)rightBarItemClick
{
[self.view endEditing:YES];
//比较2个时间段 结束时间需大于开始时间
NSDateFormatter * df = [[NSDateFormatter alloc]init];
[df setDateFormat:@"HH:mm"];
double startTime =[df dateFromString:self.infoDisturBan.starttime].timeIntervalSince1970;
double endTime =[df dateFromString:self.infoDisturBan.endedtime].timeIntervalSince1970;
if(endTime <= startTime){
LGAlertView *alertView = [[LGAlertView alloc] initWithTitle:@"提示" message:@"结束时间需大于开始时间" style:LGAlertViewStyleAlert buttonTitles:@[@"确定"] cancelButtonTitle:nil destructiveButtonTitle:nil actionHandler:^(LGAlertView *alertView, NSString *title, NSUInteger index) {
} cancelHandler:nil destructiveHandler:nil];
[alertView showAnimated:YES completionHandler:nil];
return;
}
[self.infoDisturBan saveSuccess:^{
[self goBack:nil];
} failure:^{}];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
NSString *title = self.myDataSource[indexPath.section][indexPath.row];
if ([title isEqualToString:@"星期"]) {
AddWeekTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"AddWeekTableViewCellID" forIndexPath:indexPath];
cell.aTitleLabel.text = title;
[cell setWeek:self.infoDisturBan.week];
WEAKSELF
cell.weekSelectBlack = ^(NSString *selectWeek) {
weakSelf.infoDisturBan.week = selectWeek;
};
cell.accessoryType = UITableViewCellAccessoryNone;
return cell;
}else{
DurationTimeTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"DurationTimeTableViewCellID" forIndexPath:indexPath];
cell.aTitleLabel.text = title;
cell.startTextField.text = self.infoDisturBan.starttime;
cell.endTextField.text = self.infoDisturBan.endedtime;
NSDateFormatter * df = [[NSDateFormatter alloc]init];
[df setDateFormat:@"HH:mm"];
[cell timeInputViewWithModel:UIDatePickerModeTime WithTextField:cell.startTextField WithDate:[df dateFromString:self.infoDisturBan.starttime]];
[cell timeInputViewWithModel:UIDatePickerModeTime WithTextField:cell.endTextField WithDate:[df dateFromString:self.infoDisturBan.endedtime]];
WEAKSELF
__block DurationTimeTableViewCell *assCell = cell;
cell.durationBlock = ^(NSString *textStr, BOOL isStart) {
if (isStart) {
weakSelf.infoDisturBan.starttime = textStr;
//比较2个时间段 开始时间需小于结束时间
NSDateFormatter * df = [[NSDateFormatter alloc]init];
[df setDateFormat:@"HH:mm"];
double startTime =[df dateFromString:weakSelf.infoDisturBan.starttime].timeIntervalSince1970;
double endTime =[df dateFromString:weakSelf.infoDisturBan.endedtime].timeIntervalSince1970;
if(startTime >= endTime ){
[assCell.startTextField resignFirstResponder];
LGAlertView *alertView = [[LGAlertView alloc] initWithTitle:@"提示" message:@"开始时间需小于结束时间" style:LGAlertViewStyleAlert buttonTitles:@[@"确定"] cancelButtonTitle:nil destructiveButtonTitle:nil actionHandler:^(LGAlertView *alertView, NSString *title, NSUInteger index) {
//焦点移动到 结束时间
[assCell.startTextField becomeFirstResponder];
} cancelHandler:nil destructiveHandler:nil];
[alertView showAnimated:YES completionHandler:nil];
}
}else{
weakSelf.infoDisturBan.endedtime = textStr;
//比较2个时间段 结束时间需大于开始时间
NSDateFormatter * df = [[NSDateFormatter alloc]init];
[df setDateFormat:@"HH:mm"];
double startTime =[df dateFromString:weakSelf.infoDisturBan.starttime].timeIntervalSince1970;
double endTime =[df dateFromString:weakSelf.infoDisturBan.endedtime].timeIntervalSince1970;
if(endTime <= startTime){
[assCell.endTextField resignFirstResponder];
LGAlertView *alertView = [[LGAlertView alloc] initWithTitle:@"提示" message:@"结束时间需大于开始时间" style:LGAlertViewStyleAlert buttonTitles:@[@"确定"] cancelButtonTitle:nil destructiveButtonTitle:nil actionHandler:^(LGAlertView *alertView, NSString *title, NSUInteger index) {
//焦点移动到 结束时间
[assCell.endTextField becomeFirstResponder];
} cancelHandler:nil destructiveHandler:nil];
[alertView showAnimated:YES completionHandler:nil];
}
}
};
return cell;
}
return nil;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
if (section == self.myDataSource.count - 1) {
return 15 + 44;
}
return [super tableView:tableView heightForFooterInSection:section];
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
UIView *view = [[UIView alloc] initWithFrame:CGRectZero];
if (section == self.myDataSource.count - 1) {
UILabel *lable1 = [[UILabel alloc] initWithFrame:CGRectMake(14, 15,
SWIDTH-28, 44)];
lable1.text = @"提示:可设置上课时段禁用,禁用时段开启后,设备将只有sos呼救功能可使用,其他功能不能使用。";
lable1.numberOfLines = 0;
lable1.font = [UIFont systemFontOfSize:13];
lable1.lineBreakMode = NSLineBreakByCharWrapping;
lable1.textColor = [UIColor lightGrayColor];
[view addSubview:lable1];
}
return view;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
@end