@Override public void delThisPerson(String delAccount, String userIdentify) { if(Integer.parseInt(userIdentify)==0){ //删除学生 String sql = "DELETE FROM userteacher WHERE `userAccount` = '"+delAccount+"'"; Deal.deal(sql); sql = "DELETE FROM studenttask WHERE studentAccount = '"+delAccount+"'"; Deal.deal(sql); }else{ //删除老师 String sql = "DELETE FROM `studenttask` WHERE taskAccount IN (SELECT taskAccount FROM task WHERE teacherAccount='"+delAccount+"')"; Deal.deal(sql); sql = "DELETE FROM task WHERE teacherAccount = '"+delAccount+"'"; Deal.deal(sql); sql = "DELETE FROM userteacher WHERE teacherAccount = '"+delAccount+"'"; Deal.deal(sql); } String sql = "DELETE FROM person WHERE userAccount = '"+delAccount+"'"; Deal.deal(sql); } }
时间: 2024-04-28 13:19:38 浏览: 91
这段代码实现了 `ManageDao` 接口中的 `delThisPerson` 方法。该方法的作用是删除指定账号和身份类型的人员信息。具体实现如下:
1. 首先,通过传入的 `userIdentify` 参数判断账号身份类型。如果为 0,则表示学生账号,否则为教师账号。
2. 根据不同的身份类型,分别执行不同的删除操作。
3. 在删除操作完成后,最后执行一条语句删除 `person` 表中对应账号的记录。
需要注意的是,这里使用了 `Deal` 类的 `deal` 方法执行 SQL 语句,具体实现可能涉及到数据库连接等操作,这里无法确定。
相关问题
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ipEditText = findViewById(R.id.ipEditText); portEditText = findViewById(R.id.portEditText); Button connectButton = findViewById(R.id.connectButton); connectButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { String ip = ipEditText.getText().toString(); int port = Integer.parseInt(portEditText.getText().toString()); new ConnectTask().execute(ip, String.valueOf(port)); } }); Button sendMessageButton = findViewById(R.id.sendMessageButton); sendMessageButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { showSendMessageDialog(); } }); } private class ConnectTask extends AsyncTask<String, Void, Void> { @Override protected Void doInBackground(String... params) { String ip = params[0]; int port = Integer.parseInt(params[1]); try { socket = new Socket(ip, port); in = new BufferedReader(new InputStreamReader(socket.getInputStream())); out = new PrintWriter(socket.getOutputStream(), true); // 在 UI 线程中创建 SeekBar handler.post(new Runnable() { @Override public void run() { SeekBar progressBar = findViewById(R.id.progressBar); progressBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { // 计算百分比对应的数字 int number = progress * 10; // 在 UI 线程中更新 ProgressBar 的进度 handler.post(new Runnable() { @Override public void run() { seekBar.setProgress(number); } }); out.println(number); } @Override public void onStartTrackingTouch(SeekBar seekBar) {} @Override public void onStopTrackingTouch(SeekBar seekBar) {} }); } }); } catch (UnknownHostException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return null; } @Override protected void onPostExecute(Void aVoid) { // 在连接结束后做一些处理 // 比如关闭连接或者显示连接成功的提示 } }代码修改
这段代码中的 `ConnectTask` 使用了 `AsyncTask` 机制,将网络连接和数据读取操作放在了后台线程中,但是在 `doInBackground` 方法中创建了 UI 控件 `SeekBar`,并在其中更新了 UI,这是不允许的。正确的做法是将 `SeekBar` 的创建和更新放在 `onPostExecute` 方法中。修改后的代码如下:
```
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ipEditText = findViewById(R.id.ipEditText);
portEditText = findViewById(R.id.portEditText);
Button connectButton = findViewById(R.id.connectButton);
connectButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String ip = ipEditText.getText().toString();
int port = Integer.parseInt(portEditText.getText().toString());
new ConnectTask().execute(ip, String.valueOf(port));
}
});
Button sendMessageButton = findViewById(R.id.sendMessageButton);
sendMessageButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
showSendMessageDialog();
}
});
}
private class ConnectTask extends AsyncTask<String, Void, Void> {
@Override
protected Void doInBackground(String... params) {
String ip = params[0];
int port = Integer.parseInt(params[1]);
try {
socket = new Socket(ip, port);
in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
out = new PrintWriter(socket.getOutputStream(), true);
} catch (UnknownHostException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(Void aVoid) {
// 在连接结束后做一些处理
// 比如关闭连接或者显示连接成功的提示
SeekBar progressBar = findViewById(R.id.progressBar);
progressBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
// 计算百分比对应的数字
int number = progress * 10;
out.println(number);
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {}
});
}
}
```
@Override public void onClick(View v) { String ip = ipEditText.getText().toString(); int port = Integer.parseInt(portEditText.getText().toString()); new Thread(new Runnable() { @Override public void run() { try { socket = new Socket(ip, port); in = new BufferedReader(new InputStreamReader(socket.getInputStream())); out = new PrintWriter(socket.getOutputStream(), true); // 获取SeekBar对象 SeekBar progressBar = findViewById(R.id.progressBar); // 添加OnSeekBarChangeListener监听器 progressBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { // 计算百分比对应的数字 int number = progress * 10; out.println(number); } @Override public void onStartTrackingTouch(SeekBar seekBar) {} @Override public void onStopTrackingTouch(SeekBar seekBar) {} }); } catch (UnknownHostException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } }).start();这段代码主线程中设计网络的传输,能帮我移到子线程中吗
是的,这段代码中的网络传输操作是在主线程中进行的,如果需要将其移到子线程中,可以将网络传输操作放在新的线程中执行。可以将上面的代码块修改如下:
```
@Override
public void onClick(View v) {
String ip = ipEditText.getText().toString();
int port = Integer.parseInt(portEditText.getText().toString());
new Thread(new Runnable() {
@Override
public void run() {
try {
socket = new Socket(ip, port);
in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
out = new PrintWriter(socket.getOutputStream(), true);
} catch (UnknownHostException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}).start();
// 获取SeekBar对象
SeekBar progressBar = findViewById(R.id.progressBar);
// 添加OnSeekBarChangeListener监听器
progressBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
// 计算百分比对应的数字
int number = progress * 10;
new Thread(new Runnable() {
@Override
public void run() {
out.println(number);
}
}).start();
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {}
});
}
```
将网络传输操作的代码放在新的线程中执行,SeekBar 的监听器也放在主线程中执行,这样就可以避免在主线程中进行网络传输造成的阻塞问题。
阅读全文