现在的位置: 首页 > 综合 > 正文

ATM系统实现[10]——转帐窗口[00原创]

2012年05月22日 ⁄ 综合 ⁄ 共 7063字 ⁄ 字号 评论关闭
package cn.edu.ynu.sei.atm.client.ui;

import cn.edu.ynu.sei.atm.interfaceDef.IAvailableAccount;
import cn.edu.ynu.sei.atm.interfaceDef.IDataFormatChecker;
import cn.edu.ynu.sei.atm.interfaceDef.ITransaction;
import java.rmi.Naming;
import java.rmi.RemoteException;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.swt.widgets.Text;

/**
 * 转帐窗口
 * 
@author 88250
 
*/
public class TransferAccountComposite extends Composite
{
    
/**
     * 返回按钮
     
*/
    
private Button returnBtn = null;

    /**
     * 状态显示标签
     
*/
    
private Label stateShowLbl = null;

    /**
     * 源帐户标签
     
*/
    
private Label sourceAccountLbl = null;

    /**
     * 取款数额标签
     
*/
    
private Label amountLbl = null;

    /**
     * 目标帐户标签
     
*/
    
private Label targetAccountLbl = null;

    /**
     * 状态提示标签
     
*/
    
private Label stateLbl = null;

    /**
     * 转帐金额输入域
     
*/
    
private Text amountText = null;

    /**
     * 目标帐户组合框
     
*/
    
private Combo targetCombo = null;

    /**
     * 源帐户组合框
     
*/
    
private Combo sourceCombo = null;

    /**
     * 可用帐户实例
     
*/
    
private IAvailableAccount availableAccount = null;

    /**
     * 交易事务服务接口
     
*/
    
private ITransaction transaction = null;

    /**
     * 输入数据合法性验证接口
     
*/
    
private IDataFormatChecker dataFormatChecker = null;

    /**
     * 父窗口容器
     
*/
    
private Composite parent = null;
    
    
/**
     * 创建转帐窗口
     * 
@param parent 父窗口容器
     
*/
    
public TransferAccountComposite(Composite parent)
    {
    
super(parent, SWT.NONE);
    
this.parent = parent;
    
    
try
    {
        availableAccount 
= (IAvailableAccount) Naming
            .lookup(LoginInterface.serviceAddr 
+ "AvailableAccount");

        transaction = (ITransaction) Naming
            .lookup(LoginInterface.serviceAddr 
+ "Transaction");
        dataFormatChecker 
= (IDataFormatChecker) Naming
            .lookup(LoginInterface.serviceAddr 
+ "DataFormatChecker");
    }
    
catch (RemoteException re)
    {
        re.printStackTrace();
        MessageBox exitDlg 
= new MessageBox(parent.getShell());
        exitDlg.setText(
"网络连接出现问题....");
        exitDlg.setMessage(
"不能连接到服务器,系统将退出!");
        exitDlg.open();
        System.exit(
0);
    }
    
catch (Exception e)
    {
        e.printStackTrace();
    }
    createContents();

    final Button comfirmBtn = new Button(this, SWT.NONE);
    comfirmBtn.addMouseListener(
new MouseAdapter()
    {
        
public void mouseDown(MouseEvent arg0)
        {
        
try
        {
            
float amount = 0;
            
try
            {
if (!dataFormatChecker.checkAmount(amountText.getText()))
            {
            amount 
= 0;
            }
            
else
            {
            amount 
= Float.parseFloat(amountText.getText());
            }
            }
            
catch (NumberFormatException nfe)
            {
            stateShowLbl.setText(nfe.getMessage());
            }
            AccountSelectComposite.account.setAmount(amount);
            
float balance = AccountSelectComposite.account.getBalance()
                
- AccountSelectComposite.account.getAmount()
                
- (float) (AccountSelectComposite.account
                    .getAmount() 
* 1.0 / 100.0);

            if (balance < 0)
            {
// 余额不足
            stateShowLbl.setText("余额不足!");
            
return;
            }

            if (AccountSelectComposite.account.getAmount() > 10000)
            {
// 转帐金额大于10000元
            stateShowLbl.setText("转帐金额不能大于10000元!");
            
return;
            }
            transaction.transfer((Integer.parseInt(sourceCombo
                .getText())), Integer.parseInt(targetCombo
                .getText()), AccountSelectComposite.account
                .getAmount());
            stateShowLbl.setText(
"转帐成功!");
        }
        
catch (RemoteException re)
        {
            re.printStackTrace();   
        }
        
catch (Exception ex)
        {
            ex.printStackTrace();
        }
        }
    });
    comfirmBtn.setText(
"确定");
    comfirmBtn.setBounds(
751014030);
    }

    /**
     * 创建转帐窗口内含控件
     * 
     
*/
    
private void createContents()
    {
    sourceCombo 
= new Combo(this, SWT.DROP_DOWN | SWT.READ_ONLY);
    sourceCombo.setBounds(
75812125);

    targetCombo = new Combo(this, SWT.DROP_DOWN | SWT.READ_ONLY);
    targetCombo.setBounds(
753811925);

    amountText = new Text(this, SWT.BORDER);
    amountText.setBounds(
75709525);

    sourceAccountLbl = new Label(this, SWT.NONE);
    sourceAccountLbl.setText(
"源帐户:");
    sourceAccountLbl.setBounds(
21155520);

    targetAccountLbl = new Label(this, SWT.NONE);
    targetAccountLbl.setText(
"目标帐户:");
    targetAccountLbl.setBounds(
9436520);

    amountLbl = new Label(this, SWT.NONE);
    amountLbl.setText(
"转帐数额:");
    amountLbl.setBounds(
7727025);

    stateLbl = new Label(this, SWT.NONE);
    stateLbl.setText(
"状态:");
    stateLbl.setBounds(
381394020);

    stateShowLbl = new Label(this, SWT.NONE);
    stateShowLbl.setBounds(
791369720);

    returnBtn = new Button(this, SWT.NONE);
    returnBtn.setBackground(Display.getCurrent().getSystemColor(
        SWT.COLOR_WHITE));
    returnBtn.setText(
"返回");
    returnBtn.setBounds(
1311024030);

    setAccountCombo();
    }

    /**
     * 设置可用的帐户列表到帐户选择组合框里
     
*/
    
private void setAccountCombo()
    {
    sourceCombo.removeAll();
    targetCombo.removeAll();
    
try
    {
        
if (availableAccount.getCurID() != 0)
        {
// 活期帐户可用
        sourceCombo.add(Integer.toString(availableAccount.getCurID()));
        targetCombo.add(Integer.toString(availableAccount.getCurID()));
        }

        if (availableAccount.getDepID() != 0)
        {
// 定期帐户可用
        sourceCombo.add(Integer.toString(availableAccount.getDepID()));
        targetCombo.add(Integer.toString(availableAccount.getDepID()));
        }

        if (availableAccount.getCredID() != 0)
        {
// 信用卡帐户可用
        sourceCombo.add(Integer.toString(availableAccount.getCredID()));
        targetCombo.add(Integer.toString(availableAccount.getCredID()));
        }

    }
    catch (RemoteException re)
    {
        MessageBox exitDlg 
= new MessageBox(parent.getShell());
        exitDlg.setText(
"网络连接出现问题....");
        exitDlg.setMessage(
"不能连接到服务器,系统将退出!");
        exitDlg.open();
        System.exit(
0);
        re.printStackTrace();
    }
    
catch (Exception e)
    {
        e.printStackTrace();
    }
    }
    
    
public void setVisible(boolean b)
    {
    clearHistory();
    
super.setVisible(b);
    }
    
    
/**
     * 清除用户上一次的操作记录
     
*/
    
private void clearHistory()
    {
    setAccountCombo();
    amountText.setText(
"");
    stateShowLbl.setText(
"");
    }

    /**
     * 取得返回按钮
     * 
@return 返回按钮
     
*/
    
public Button getReturnLbl()
    {
    
return returnBtn;
    }

    @Override
    public void dispose()
    {
    
super.dispose();
    }

    @Override
    protected void checkSubclass()
    {
    
// Disable the check that prevents subclassing of SWT components
    }

}

 

抱歉!评论已关闭.