Repository navigation
Expand file tree
/
Copy pathUser.java
More file actions
123 lines (103 loc) · 3.16 KB
/
Copy pathUser.java
File metadata and controls
123 lines (103 loc) · 3.16 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
package javaSystem;
import java.io.IOException;
import java.io.*;
import java.sql.SQLException;
import java.util.Enumeration;
import java.util.Scanner;
import exceptionBao.BaseException;
import exceptionBao.DaoException;
import sqlService.SQLForDoc;
import sqlService.SQLForUser;
public abstract class User implements Serializable {
private String name;//用户名
private String password;//密码
private String role;//用于标识三种不同的角色
User(String name,String password,String role){
this.name=name;
this.password=password;
this.role=role;
}
User(){
name="";
password="";
role="";
}
public boolean changeSelfInfo(User currentUser , String newCode) throws SQLException, DaoException{
//写用户信息到存储
// if (DataProcessing.update(currentUser.getName(), newCode, currentUser.getRole())){
// currentUser.setPassword(newCode);
// System.out.println("修改成功");
// DataProcessing.saveAll();
// return true;
// }else
// return false;
SQLForUser sqlUser=new SQLForUser();
currentUser.setPassword(newCode);
if(sqlUser.update(currentUser)!=null) {
return true;
}
else return false;
}
public boolean downloadFile(String fileID,String path) throws IOException, SQLException, BaseException {
// Scanner scan=new Scanner(System.in);
// System.out.print("请输入需要下载的文件id:");
// String fileID=scan.next();
// Doc downFile=DataProcessing.searchDoc(fileID);
// if(downFile==null) { System.out.println("系统中未包含该文件"); return false;}
// double ranValue=Math.random();
// if (ranValue>0.5)
// throw new IOException( "Error in accessing file" );
//System.out.println("下载文件... ...");
SQLForDoc sql =new SQLForDoc();
Doc downFile = sql.findById(fileID);
File f2=new File(downFile.getFilename());
FileInputStream fileIn=new FileInputStream(f2);//此时的getFilename获取的是带文件储存位置的文件名
File f=new File(path);//存入指定位置,并创建同名文件
FileOutputStream fileOut=new FileOutputStream(f,true);
int i;
while((i=fileIn.read())!=-1) {
fileOut.write((byte)i);
}
System.out.println("下载成功");
fileIn.close();
fileOut.close();
return true;
}
public void showFileList() throws SQLException{
double ranValue=Math.random();
if (ranValue>0.5)
throw new SQLException( "Error in accessing file DB" );
System.out.println("列表... ...");
Enumeration<Doc> enumeration=DataProcessing.getAllDocs();
while(enumeration.hasMoreElements()) {
Doc doc= enumeration.nextElement();
System.out.printf("%s:%-20s","文件名",Doc.getFileName(doc.getFilename()));
System.out.printf("%s:%-26s","文件描述",doc.getDescription());
System.out.printf("%s:%-12s","文件上传者",doc.getCreator());
System.out.printf("%s:%-8s","文件ID",doc.getID());
System.out.println();
}
}
public void exitSystem(){
System.out.println("系统退出, 谢谢使用 ! ");
System.exit(0);
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getRole() {
return role;
}
public void setRole(String role) {
this.role = role;
}
}