📄 chooseastaff.java
字号:
package GUI;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Dialog;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import com.swtdesigner.SWTResourceManager;
import Staff.*;
import java.util.List;
import Dbprocess.*;
public class ChooseAStaff extends Dialog {
List staffs;
Staffmanage sm;
private Combo combo;
protected Object result;
protected Shell shell;
private String saleid;
/**
* Create the dialog
* @param parent
* @param style
*/
public ChooseAStaff(Shell parent, int style,Staffmanage sm) {
super(parent, style);
this.sm=sm;
staffs=sm.getStaffs();
}
/**
* Create the dialog
* @param parent
*/
public ChooseAStaff(Shell parent,Staffmanage sm) {
this(parent, SWT.NONE,sm);
}
/**
* Open the dialog
* @return the result
*/
public Object open() {
createContents();
shell.open();
shell.layout();
Display display = getParent().getDisplay();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
return result;
}
/**
* Create contents of the dialog
*/
protected void createContents() {
shell = new Shell(getParent(), SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
shell.setSize(570, 183);
shell.setText("请选择一个员工");
combo = new Combo(shell, SWT.NONE);
combo.setBounds(141, 84, 218, 20);
int i;
for(i=0;i<staffs.size();i++){
String str;
str="员工号:"+((Staff)staffs.get(i)).getStaffid()+",姓名:"+((Staff)staffs.get(i)).getName();
combo.add(str);
}
final Label label = new Label(shell, SWT.NONE);
label.setFont(SWTResourceManager.getFont("", 16, SWT.BOLD));
label.setText("一个外送定单已经全部完成,请选择一个送货员送货");
label.setBounds(10, 10, 544, 32);
final Label label_1 = new Label(shell, SWT.NONE);
label_1.setText("送货员");
label_1.setBounds(91, 87, 44, 12);
final Button button = new Button(shell, SWT.NONE);
button.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
try{
int i = combo.getSelectionIndex();
// String staffname = ((Staff)staffs.get(i)).getName();
String staffid = ((Staff)staffs.get(i)).getStaffid();
DBmanager dbm = new DBmanager();
/* Connection con = dbm.getCon();
String sql = "SELECT staffid FROM staff WHERE name like ?";
PreparedStatement pstate = con.prepareStatement(sql);
pstate.setString(1,staffname);
ResultSet resultSet = pstate.executeQuery();
resultSet.next();
String staffid = resultSet.getString("staffid");*/
dbm.insertDB(saleid, staffid);
shell.close();
}
catch(Exception e1){
e1.printStackTrace();
}
}
});
button.setText("确定");
button.setBounds(365, 82, 48, 22);
final Label label_2 = new Label(shell, SWT.NONE);
label_2.setText("销售ID");
label_2.setBounds(20, 48, 42, 12);
final Label label_3 = new Label(shell, SWT.NONE);
label_3.setBounds(68, 48, 67, 12);
label_3.setText(saleid);
//
}
public Staffmanage getSm() {
return sm;
}
public void setSm(Staffmanage sm) {
this.sm = sm;
}
public List getStaffs() {
return staffs;
}
public void setStaffs(List staffs) {
this.staffs = staffs;
}
public String getSaleid() {
return saleid;
}
public void setSaleid(String saleid) {
this.saleid = saleid;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -