MyLoginDialog.java
上传用户:flow_meter
上传日期:2022-03-21
资源大小:40k
文件大小:3k
- package sql_lab;
- import org.eclipse.jface.dialogs.Dialog;
- import org.eclipse.jface.dialogs.MessageDialog;
- import org.eclipse.swt.SWT;
- import org.eclipse.swt.widgets.*;
- import org.eclipse.swt.layout.*;
- import java.sql.*;
- /**对话框由对话框区域和按钮条组成
- * 创建自定义对话框的步骤是:
- * 覆盖以下方法
- * Control createDialogArea(Composite parent)创建对话框的各种控件
- * void createButtonForButtonBar(Composite parent) 创建对话框按钮
- * void buttonPressed(int buttonID)处理按钮单击事件
- * @author guo
- *
- */
- public class MyLoginDialog extends Dialog {
- public static final int LOGIN_ID=0;
- public static final int LOGOUT_ID=1;
- public static final String LOGIN_LABEL="登陆";
- public static final String LOGOUT_LABEL="退出";
- private Text userName;
- private Text password;
-
- public MyLoginDialog(Shell parentShell){
- super(parentShell);
- }
- protected void configureShell(Shell shell){
- super.configureShell(shell);
- shell.setText("系统登陆");
- }
- protected Control createDialogArea(Composite parent){
- Composite composite=(Composite)super.createDialogArea(parent);
- Group group=new Group(composite,SWT.NONE);
- group.setText("登陆系统");
- GridLayout grid=new GridLayout();
- grid.marginHeight=20;
- grid.marginWidth=20;
- grid.numColumns=2;
- group.setLayout(grid);
- new Label(group,SWT.NONE).setText("用户名");
- userName=new Text(group,SWT.BORDER|SWT.SINGLE);
- new Label(group,SWT.NONE).setText("密码");
- password=new Text(group,SWT.BORDER|SWT.SINGLE);
- password.setEchoChar('*');
- return parent;
- }
- protected void createButtonsForButtonBar(Composite parent){
- //创建按钮必须通过父类的createButton来创建
- createButton(parent,MyLoginDialog.LOGIN_ID,MyLoginDialog.LOGIN_LABEL,true);
- createButton(parent,MyLoginDialog.LOGOUT_ID,MyLoginDialog.LOGOUT_LABEL,true);
- }
- protected void buttonPressed(int buttonID){
- if(MyLoginDialog.LOGIN_ID==buttonID){//进行登陆验证
- sqlManager sql=sqlManager.getSqlManager();
-
- String str="select * from "+sqlManager.tb_user+" where user_id='"+userName.getText().toString()
- +"' and user_password='"+password.getText().toString()+"'";
- MainWindow.log=false;
- ResultSet set=sql.executeQuery(str);
- try{
- while(set.next())//登陆成功
- {
- if((userName.getText().toString().equals(set.getString(1)))&&
- (password.getText().toString().equals(set.getString(2)))){
- MainWindow.user=set.getString(1);
- MainWindow.password=set.getString(2);
- MainWindow.level=set.getInt(3);
- MainWindow.log=true;
- System.out.println("here");
- this.close();
- }
- }
-
- }catch(SQLException e){
- e.printStackTrace();
- }
- if(MainWindow.log==false)
- MessageDialog.openConfirm(Display.getCurrent().getActiveShell(), "提示对话框", "登陆失败,请重新登陆");
- }
- else if(MyLoginDialog.LOGOUT_ID==buttonID)
- this.close();
- }
- }