SWT_

package com.net.ui;

import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CLabel;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

import com.net.dao.DBHelper_new;
import com.net.utils.Encrypt;
import com.net.utils.Params;
import com.net.utils.SWTUtil;
import com.swtdesigner.SWTResourceManager;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.DisposeListener;
import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;

public class Login_C {

	protected Shell shlLogin;
	private Text text;
	private Text text_1;

	/**
	 * Launch the application.
	 * @param args
	 */
	public static void main(String[] args) {
		try {
			Login_C window = new Login_C();
			window.open();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * Open the window.
	 */
	public void open() {
		Display display = Display.getDefault();
		createContents();
		
		//居中显示窗口
		SWTUtil swtUtil = new SWTUtil();
		swtUtil.centerShell(display, shlLogin);
		
		Group group = new Group(shlLogin, SWT.NONE);
		group.setBackgroundImage(SWTResourceManager.getImage(Login_C.class, "/images/Login_background.png"));
		group.setFont(SWTResourceManager.getFont("宋体", 16, SWT.NORMAL));
		group.setText("登陆");
		group.setBackgroundMode(SWT.INHERIT_FORCE);
		group.setBounds(0, 0, 394, 274);
		
		Label label = new Label(group, SWT.NONE);
		label.setForeground(SWTResourceManager.getColor(SWT.COLOR_LIST_SELECTION));
		label.setFont(SWTResourceManager.getFont("方正舒体", 16, SWT.NORMAL));
		label.setBounds(10, 196, 130, 62);
		label.setText("酒店管理系统\n      登陆");
		
		text = new Text(group, SWT.BORDER);
		text.setBounds(167, 68, 137, 21);
		
		text_1 = new Text(group, SWT.BORDER | SWT.PASSWORD);
		text_1.setBounds(167, 137, 137, 21);
		
		Label label_1 = new Label(group, SWT.NONE);
		label_1.setFont(SWTResourceManager.getFont("黑体", 12, SWT.NORMAL));
		label_1.setBounds(167, 47, 61, 15);
		label_1.setText("用户名");
		
		Label label_2 = new Label(group, SWT.NONE);
		label_2.setFont(SWTResourceManager.getFont("黑体", 12, SWT.NORMAL));
		label_2.setBounds(167, 116, 61, 15);
		label_2.setText("密码");
		
		Button button = new Button(group, SWT.NONE);
		button.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				//先取用户名text,密码 text_1
				String rname = text.getText().trim().toString();
				String rpwd = text_1.getText().trim().toString();
				//使用DBHelper 查询数据库
				// sql语句:select * from resadmin where rname = ? and rpwd=?;
				String sql = "select * from resadmin where rname = ? and rpwd=?";
				DBHelper_new db = new DBHelper_new();
				List<Object> params = new ArrayList<Object>();
				params.add(rname);
				params.add(Encrypt.md5(rpwd));
				List<Map<String, String>> list;
				try {
					list = db.find(sql, params);
					if(list == null || list.size() <=0) {
						SWTUtil.showMessageBox(shlLogin, "登陆成功","用户名或密码错误,请确认后重新登录");
					}else {
						SWTUtil.showMessageBox(shlLogin, "登陆成功", "欢迎您" + rname);
						
						//保存登陆的用户信息到静态变量中
						Map<String, String> user = list.get(0);
						Params.rid = user.get("RID");
						Params.rname = user.get("RNAME");
						Params.rpwd = rpwd;
						
						
						
						Login_C.this.shlLogin.setVisible(false);  //这个只是隐藏而已
						//可以彻底关闭
						//Login.this.shell.dispose();
						Main main = new Main();
						main.open();
					}
				} catch (SQLException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				} catch (IOException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
			
				
			}
		});
		button.setBounds(120, 222, 122, 39);
		button.setText("登陆");
		
		Button button_1 = new Button(shlLogin, SWT.NONE);
		button_1.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				MessageBox mb = new MessageBox(shlLogin,SWT.YES|SWT.NO);
				mb.setText("提示!");
				mb.setMessage("确定要退出吗?");
				int result = mb.open();
					if( result == SWT.YES)   //这里实际上是64,no 是128
						System.exit(0);
					
			}
		});
		button.setFont(SWTResourceManager.getFont("微软雅黑", 10, SWT.NORMAL));
		button.setBounds(194, 195, 85, 29);
		button.setText("登陆");
		
		Label label_3 = new Label(group, SWT.NONE);
		label_3.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseDown(MouseEvent e) {
				MessageBox mb = new MessageBox(shlLogin,SWT.YES|SWT.NO|SWT.ICON_QUESTION);
				mb.setText("提示!");
				mb.setMessage("确定要退出吗?");
				int result = mb.open();
					if( result == SWT.YES)   //这里实际上是64,no 是128
						System.exit(0);
			}
		});
		label_3.setBounds(361, 253, 33, 21);
		label_3.setText("退出");
		
		
		shlLogin.open();
		shlLogin.layout();
		while (!shlLogin.isDisposed()) {
			if (!display.readAndDispatch()) {
				display.sleep();
			}
		}
	}

	/**
	 * Create contents of the window.
	 */
	protected void createContents() {
		shlLogin = new Shell(SWT.BORDER);
		shlLogin.setBackgroundMode(SWT.INHERIT_FORCE);
		shlLogin.setBackgroundImage(SWTResourceManager.getImage(Login_C.class, "/com/net/ui/Login_background.png"));
		shlLogin.setImage(SWTResourceManager.getImage(Login_C.class, "/images/login.png"));
		shlLogin.setSize(400, 280);
		shlLogin.setText("Login");

	}
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值