-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAddAuthor.java
More file actions
53 lines (43 loc) · 2.18 KB
/
AddAuthor.java
File metadata and controls
53 lines (43 loc) · 2.18 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
package com.example.android.break2;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;
import java.sql.SQLException;
public class AddAuthor extends AppCompatActivity {
EditText Fname_ET, Lname_ET, BirthDate_ET, Brief_ET, Stlye_ET;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_add_author);
}
public void AddAuthorClick(View view) throws SQLException {
Fname_ET = findViewById(R.id.authorFN);
Lname_ET = findViewById(R.id.authorLN);
BirthDate_ET = findViewById(R.id.authorBD);
Brief_ET = findViewById(R.id.authorBrief);
Stlye_ET = findViewById(R.id.authorStyle);
String name = Fname_ET.getText().toString() + " " + Lname_ET.getText().toString();
String birthDate = BirthDate_ET.getText().toString();
String brief = Brief_ET.getText().toString();
String style = Stlye_ET.getText().toString();
if (name.isEmpty() || birthDate.isEmpty() || brief.isEmpty() || style.isEmpty()) {
Toast.makeText(AddAuthor.this, "Adding failed. Please re-check your input information ", Toast.LENGTH_SHORT).show();
} else {
Controller c = new Controller();
int res = c.InsertAuthor(name, birthDate, brief, style);
if (res == 1) {
Toast.makeText(AddAuthor.this, "Author. " + name + " has been added successfully ", Toast.LENGTH_SHORT).show();
} else {
if (res == 1) {
Toast.makeText(AddAuthor.this, name + " added successfully as an author.", Toast.LENGTH_SHORT).show();
} else if (res == 404) {
Toast.makeText(AddAuthor.this, " Adding failed this author is already added before.", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(AddAuthor.this, "Adding failed something gone wrong please check your data.", Toast.LENGTH_SHORT).show();
}
}
}
}
}