我有三个桌子
class Form extends React.Component {
constructor(props, context) {
super(props, context);
this.handleChangeFname = this.handleChange.bind(this);
this.handleChangeLname = this.handleChange.bind(this);
this.handleChangeEmail = this.handleChange.bind(this);
this.handleChangePhone = this.handleChange.bind(this);
this.state = {
value: null
};
}
getValidationStateFname() {
const fname = this.state.value;
if (this.state.value === null) return null;
else if (!/^[a-zA-Z]*$/.test(fname)) return 'error';
else if (/^[a-zA-Z]*$/.test(fname)) return 'success';
}
getValidationStateLname() {
const lname = this.state.value;
if (this.state.value === null) return null;
else if (!/^[a-zA-Z]*$/.test(lname)) return 'error';
else if (/^[a-zA-Z]*$/.test(lname)) return 'success';
}
getValidationStateEmail() {
const email = this.state.value;
if (this.state.value === null) return null;
else if (!/^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/.test(email)) return 'error';
else if (/^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/.test(email)) return 'success';
}
getValidationStatePhone() {
const phone = this.state.value;
if (this.state.value === null) return null;
else if (!/^[0-9]+$/.test(phone)) return 'error';
else if (/^[0-9]+$/.test(phone)) return 'success';
}
handleChange(fname) {
this.setState({ value: fname.target.value });
}
handleChange(lname) {
this.setState({ value: lname.target.value });
}
handleChange(email) {
this.setState({ value: email.target.value });
}
handleChange(phone) {
this.setState({ value: phone.target.value });
}
render() {
return (
<form>
<Grid>
<Row className="show-grid">
<Col sm={9} md={6}>
<FormGroup
controlId="formBasicText"
validationState={this.getValidationStateFname()}
>
<FormControl
type="text"
value={this.state.value}
placeholder="First Name"
onChange={this.handleChangeFname}
/>
<FormControl.Feedback />
</FormGroup>
</Col>
<Col sm={9} md={6}>
<FormGroup
controlId="formBasicText"
validationState={this.getValidationStateLname()}
>
<FormControl
type="text"
value={this.state.value}
placeholder="Last Name"
onChange={this.handleChangeLname}
/>
<FormControl.Feedback />
</FormGroup>
</Col>
<Col sm={9} md={6}>
<FormGroup
controlId="formBasicText"
validationState={this.getValidationStateEmail()}
>
<FormControl
type="text"
value={this.state.value}
placeholder="E-mail"
onChange={this.handleChangeEmail}
/>
<FormControl.Feedback />
</FormGroup>
</Col>
<Col sm={9} md={6}>
<FormGroup
controlId="formBasicText"
validationState={this.getValidationStatePhone()}
>
<FormControl
type="text"
value={this.state.value}
placeholder="Phone Number"
onChange={this.handleChangePhone}
/>
<FormControl.Feedback />
</FormGroup>
</Col>
</Row>
</Grid>
</form>
);
}
}
export default Form;
每次我在TAD表中插入一条记录时,我都需要将当前日期放在---
TAI
---
tai_id int
dai_id int
---
DAI
---
dai_id int
DaiType varchar(1)
---
TAD
---
tad_id int
tai_id int
StoreDate DateTime <<--default constraint in this field and table
字段中,但是,仅当StoreDate
表中的字段DaiType
是= DAI
。对于'S'
表中DaiType
字段中的所有其他值,DAI
中的值应默认为null。
如何仅使用约束条件来完成?我不想编写触发器或任何类型的后端作业。