StudentAdd.js
6.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
import React from 'react';
import {post} from 'axios';
import Dialog from '@material-ui/core/Dialog';
import DialogActions from '@material-ui/core/DialogActions';
import DialogTitle from '@material-ui/core/DialogTitle';
import DialogContent from '@material-ui/core/DialogContent';
import Textfield from '@material-ui/core/TextField';
import Button from '@material-ui/core/Button';
import{withStyles}from '@material-ui/core/styles';
import { createMuiTheme } from '@material-ui/core/styles';
import {blue, pink} from '@material-ui/core/colors';
const theme = createMuiTheme({
palette: {
primary: {
main: blue[100],
},
secondary: {
main: pink[100],
},
},
});
const primary = blue[100]; //#bbdefb
const styles = theme=>({
hidden:{
display:'none'
}
});
class StudentAdd extends React.Component{
constructor(props){
super(props);
this.state={
st_Code:'',
//st_Name:'',
//st_Id:'',
st_Major:'',
st_Midscore:'',
st_Finalscore:'',
st_Assignscore:'',
st_Attendscore:'',
st_Score:'',
open:false
}
}
handleFormSubmit = (e) => {
e.preventDefault()
this.addStudent()
.then((response) => {
console.log(response.data);
this.props.stateRefresh();
})
this.setState({
st_Code:'',
//st_Name:'',
//st_Id:'',
st_Major:'',
st_Midscore:'',
st_Finalscore:'',
st_Assignscore:'',
st_Attendscore:'',
st_Score:'',
open: false
})
}
handleValueChange = (e) => {
let nextState = {};
nextState[e.target.name]=e.target.value;
this.setState(nextState);
}
addStudent = () =>{
const url ='/api/students';
const formData=new FormData();
formData.append('st_Code',this.state.st_Code);
//formData.append('st_Name',this.state.st_Name);
//formData.append('st_Id',this.state.st_Id);
formData.append('st_Major',this.state.st_Major);
formData.append('st_Midscore',this.state.st_Midscore);
formData.append('st_Finalscore',this.state.st_Finalscore);
formData.append('st_Assignscore',this.state.st_Assignscore);
formData.append('st_Attendscore',this.state.st_Attendscore);
formData.append('st_Score',this.state.st_Score);
const config = {
headers: {
'content-tupe': 'multipart/form-data'
}
}
return post(url, formData, config);
}
handleClickOpen = () => {
this.setState({
open:true
});
}
handleClose = () => {
this.setState({
st_Code:'',
//st_Name:'',
//st_Id:'',
st_Major:'',
st_Midscore:'',
st_Finalscore:'',
st_Assignscore:'',
st_Attendscore:'',
st_Score:'',
open: false
})
}
render(){
const{classes}=this.props;
return(
<div>
<Button variant="contained" color="primary" onClick={this.handleClickOpen}>
등수확인
</Button>
<Dialog open={this.state.open} onClose={this.handleClose}>
<DialogTitle>학생 추가</DialogTitle>
<DialogContent>
<Textfield label="코드 번호" type="text" name="st_Code" value={this.state.st_Code} onChange={this.handleValueChange}/><br/>
<Textfield label="전공" type="text" name="st_Major" value={this.state.st_Major} onChange={this.handleValueChange}/><br/>
<Textfield label="중간 점수" type="text" name="st_Midscore" value={this.state.st_Midscore} onChange={this.handleValueChange}/><br/>
<Textfield label="기말 점수" type="text" name="st_Finalscore" value={this.state.st_Finalscore} onChange={this.handleValueChange}/><br/>
<Textfield label="과제 점수" type="text" name="st_Assignscore" value={this.state.st_Assignscore} onChange={this.handleValueChange}/><br/>
<Textfield label="출석 점수" type="text" name="st_Attendscore" value={this.state.st_Attendscore} onChange={this.handleValueChange}/><br/>
<Textfield label="학점" type="text" name="st_Score" value={this.state.st_Score} onChange={this.handleValueChange}/><br/>
</DialogContent>
<DialogActions>
<Button varient="contained" color="primary" onClick={this.handleFormSubmit}>추가</Button>
<Button varient="outlined" color="primary" onClick={this.handleClose}>닫기</Button>
</DialogActions>
</Dialog>
</div>
)
}
}
export default withStyles(styles)(StudentAdd);
/*
<form onSubmit={this.handleFormSubmit}>
<h1>학생 추가</h1>
코드 번호 : <input type="text" name="st_Code" value={this.state.st_Code} onChange={this.handleValueChange}/><br/>
이름 : <input type="text" name="st_Name" value={this.state.st_Name} onChange={this.handleValueChange}/><br/>
학번 : <input type="text" name="st_Id" value={this.state.st_Id} onChange={this.handleValueChange}/><br/>
전공 : <input type="text" name="st_Major" value={this.state.st_Major} onChange={this.handleValueChange}/><br/>
중간 점수 : <input type="text" name="st_Midscore" value={this.state.st_Midscore} onChange={this.handleValueChange}/><br/>
기말 점수 : <input type="text" name="st_Finalscore" value={this.state.st_Finalscore} onChange={this.handleValueChange}/><br/>
과제 점수 : <input type="text" name="st_Assignscore" value={this.state.st_Assignscore} onChange={this.handleValueChange}/><br/>
출석 점수 : <input type="text" name="st_Attendscore" value={this.state.st_Attendscore} onChange={this.handleValueChange}/><br/>
학점 : <input type="text" name="st_Score" value={this.state.st_Score} onChange={this.handleValueChange}/><br/>
<button type="submit">추가하기</button>
</form>
*/