?? frmsfxm.java
字號:
package myprojects.FrmSFXM;
import org.eclipse.swt.events.*;
import org.eclipse.swt.*;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;
import java.sql.*;
import java.text.*;
import db.FrmSFXMDb.*;
import myprojects.FrmMenu.*;
public class FrmSFXM
{
//*************變量聲明****************************
private Shell shell;
private Display display;
private FrmSFXMDb db=new FrmSFXMDb();
private String RootLabel = "B";
private Tree tree;
private static Text txtSffl;
private Composite cps1Sfbz;
private Text txtSfxm;
private Text txtSfsr;
private Text txtSfdj;
private Combo cmbJjdw;
private Button btnSave;
private Button btnAbor;
private Text txtZfbl;
private Text txtSfwm;
private Text txtBz;
private static Text txtSfnm;
private Table tblXxsj;
private TableItem itemlSf;
private TableItem[] itemsSF;
private MessageBox messageBoxpyx;
// *************** 創建主函數 *********************************
public static void main()
{
Display display = new Display ();
FrmSFXM frmsfxm= new FrmSFXM ();
//創建整體框架
frmsfxm.createshell();
frmsfxm.returnsfnm();
while( !frmsfxm.shell.isDisposed())
{
if(!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
// *************** 創建SHELL **********************************
public void createshell()
{
shell = new Shell (display);
shell.setText("醫療服務收費標準");
shell.setSize(640,480);
//設置布局方式
GridLayout gridLayout = new GridLayout();
//shell分成5格
gridLayout.numColumns = 4;
shell.setLayout(gridLayout);
//調用各方法、創建整體界面
createWidgets();
createTable();
createTree();
createGroup();
createButton();
shell.open();////////////////////
}
//*************** 設置頭標簽與輸入框 ******************************
private void createWidgets()
{
//設置組件對齊方式
GridData gridData0 = new GridData(GridData.HORIZONTAL_ALIGN_END);
GridData gridData1 = new GridData(GridData.FILL_HORIZONTAL);
GridData gridData2 = new GridData(GridData.HORIZONTAL_ALIGN_END);
GridData gridData3 = new GridData(GridData.FILL_HORIZONTAL);
//創建標簽
Label lblSfnm = new Label(shell,SWT.None);
lblSfnm.setText("收費標準內部代碼 ");
lblSfnm.setLayoutData(gridData0);
txtSfnm = new Text(shell,SWT.BORDER | SWT.READ_ONLY);
txtSfnm.setFocus();
txtSfnm.setLayoutData(gridData1);
//添加監聽器
txtSfnm.addFocusListener(new FocusAdapter()
{
public void focusLost(FocusEvent e)
{
btnSave.setEnabled(true);
btnAbor.setEnabled(true);
txtSffl.setEditable(true);
}
});
//添加監聽器
txtSfnm.addMouseListener(new MouseAdapter()
{
public void mouseDoubleClick(MouseEvent e)
{
tblXxsj.setVisible(true);
tblXxsj.setFocus();
Filltable();
}
});
/*try
{
db.getConnection();
txtSfbznbdm.setText(db.getSfnm());
}
catch(Exception e)
{
System.err.println(e.getMessage());
}*/
Label lblSffl = new Label(shell,SWT.None);
lblSffl.setText("收費標準分類 ");
lblSffl.setLayoutData(gridData2);
txtSffl = new Text(shell,SWT.BORDER );
txtSffl.setEditable(false);
txtSffl.setLayoutData(gridData3);
//添加監聽器
txtSffl.addMouseListener(new MouseAdapter()
{
public void mouseDoubleClick(MouseEvent e)
{
tree.setVisible(true);
tree.setFocus();
}
});
}
//返回數據庫連接錯誤
private void returnsfnm()
{
try
{
if(db.getConnection()==false)
{
MessageBox msgBox=new MessageBox(shell,SWT.OK|SWT.ICON_ERROR);
msgBox.setText("錯誤");
msgBox.setMessage("連接數據庫失敗");
msgBox.open();
return;
}
else
{
creatTreeItem();
txtSfnm.setText(db.getSfnm());
}
}
catch(Exception e)
{
System.out.print(e.getMessage());
e.printStackTrace();
}
}
//********************* 定義表格 **************************************
private void createTable()
{
tblXxsj = new Table(shell,SWT.SINGLE | SWT.MULTI | SWT.BORDER | SWT.FULL_SELECTION);
tblXxsj.setVisible(false);
tblXxsj.addFocusListener(new FocusAdapter()
{
public void focusLost(FocusEvent e)
{
tblXxsj.setVisible(false);
}
});
tblXxsj.setHeaderVisible(true);
tblXxsj.setLinesVisible(true);
//設置表格顯示格式
GridData gridData4 = new GridData(GridData.FILL_BOTH);
gridData4.horizontalSpan = 3;
gridData4.widthHint=425;
tblXxsj.setLayoutData(gridData4);
//定義表格列名
String[] ssname={"收費標準內部代碼",
"標準名稱",
"輸入用代碼",
"收費單價",
"計價單位",
"自費比例",
"分類代碼",
"外部銜接代碼",
"備注"
};
//添加表格第一列
TableColumn colXxsj1 = new TableColumn(tblXxsj,SWT.LEFT);
colXxsj1.setText(ssname[0]);
colXxsj1.setWidth(140);
//添加表格第2列
TableColumn colXxsj2 = new TableColumn(tblXxsj,SWT.LEFT);
colXxsj2.setText(ssname[1]);
colXxsj2.setWidth(100);
//添加表格第3列
TableColumn colXxsj3 = new TableColumn(tblXxsj,SWT.LEFT);
colXxsj3.setText(ssname[2]);
colXxsj3.setWidth(120);
//添加表格第4列
TableColumn colXxsj4 = new TableColumn(tblXxsj,SWT.LEFT);
colXxsj4.setText(ssname[3]);
colXxsj4.setWidth(100);
//添加表格第5列
TableColumn colXxsj5 = new TableColumn(tblXxsj,SWT.LEFT);
colXxsj5.setText(ssname[4]);
colXxsj5.setWidth(100);
//添加表格第6列
TableColumn colXxsj6 = new TableColumn(tblXxsj,SWT.LEFT);
colXxsj6.setText(ssname[5]);
colXxsj6.setWidth(100);
//添加表格第7列
TableColumn colXxsj7 = new TableColumn(tblXxsj,SWT.LEFT);
colXxsj7.setText(ssname[6]);
colXxsj7.setWidth(100);
//添加表格第8列
TableColumn colXxsj8 = new TableColumn(tblXxsj,SWT.LEFT);
colXxsj8.setText(ssname[7]);
colXxsj8.setWidth(140);
//添加表格第9列
TableColumn colXxsj9 = new TableColumn(tblXxsj,SWT.LEFT);
colXxsj9.setText(ssname[8]);
colXxsj9.setWidth(80);
Filltable();
}
//*********************** 定義表格查找 ********************************8
public void Filltable()
{
try
{
db.getSfxmData();
while (db.prs.next())
{
itemlSf = new TableItem(tblXxsj,0);
itemlSf.setText(new String[]
{ db. prs.getString ("SFNM"),
db. prs.getString ("SFXM"),
db. prs.getString ("SFSR"),
db. prs.getString ("SFDJ"),
db. prs.getString ("JJDW"),
db. prs.getString ("ZFBL"),
db. prs.getString ("SFFL"),
db. prs.getString ("SFWM"),
db. prs.getString ("BZ"),
});
}
}
catch(Exception e)
{
System.err.println(e.getMessage());
}
//添加監聽器
tblXxsj.addSelectionListener(new SelectionAdapter()
{
public void widgetDefaultSelected(SelectionEvent e)
{
//獲得當前的選中行
itemsSF = tblXxsj.getSelection();
if (itemsSF.length == 0) return;
//取得當前選中行的信息
txtSfnm.setText(itemsSF[0].getText(0));
txtSffl.setText(itemsSF[0].getText(6));
txtSfxm.setText(itemsSF[0].getText(1));
txtSfsr.setText(itemsSF[0].getText(2));
txtSfdj.setText(itemsSF[0].getText(3));
cmbJjdw.setText(itemsSF[0].getText(4));
txtZfbl.setText(itemsSF[0].getText(5));
txtSfwm.setText(itemsSF[0].getText(7));
txtBz.setText(itemsSF[0].getText(8));
tblXxsj.setVisible(false);
}
});
}
//*************************** 生成樹 **************************
private void createTree()
{
GridData griddata5 = new GridData(GridData.FILL_BOTH);
griddata5.horizontalSpan = 1;
//生成tree
tree = new Tree(shell,SWT.MULTI |SWT.SINGLE|SWT.BORDER);//////////////////////
tree.setVisible(false);
tree.addFocusListener(new FocusAdapter()
{
public void focusLost(FocusEvent e)
{
tree.setVisible(false);
}
});
//添加雙擊節點的監聽器
tree.addSelectionListener(new SelectionAdapter()
{
public void widgetDefaultSelected(SelectionEvent e)
{
TreeItem itemsSF = tree.getSelection()[0];
//獲得當前節點的分類代碼
String fldm = itemsSF.getData("FLDM").toString();
String flms = itemsSF.getText();
txtSffl.setText(fldm);
txtSfxm.setText(flms);
tree.setVisible(false);
}
});
}
//********************** 設置樹節點 ****************************
private void creatTreeItem()
{
try
{
db.getTreeItemData(RootLabel);
String lsNowDM;//存儲當前節點代碼
TreeItem rootNode;//根節點
TreeItem L1Node;//第一層子節點
TreeItem L2Node;//第二層子節點
rootNode = new TreeItem(tree,SWT.NULL);
L1Node=rootNode;
tree.removeAll();
while(db.prs.next())
{
lsNowDM = db.prs.getString("FLDM").trim();
switch(lsNowDM.length())
{
case 3:
rootNode = new TreeItem(tree,SWT.NULL);
rootNode.setText(db.prs.getString("FLMS"));
rootNode.setData("FLDM",lsNowDM);
break;
case 5:
L1Node = new TreeItem(rootNode,SWT.NULL);
L1Node.setText(db.prs.getString("FLMS"));
L1Node.setData("FLDM",lsNowDM);
break;
case 7:
L2Node = new TreeItem(L1Node,SWT.NULL);
L2Node.setText(db.prs.getString("FLMS"));
L2Node.setData("FLDM",lsNowDM);
break;
default://先不作處理
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -