?? frmypxm.java
字號:
package myprojects.FrmYPXM;
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.lang.*;
import org.eclipse.swt.events.*;
import myprojects.FrmMenu.*;
public class FrmYPXM{
String YPNM;
Shell shell;
//標簽顯示顏色
private static Color colBule,colRed;
private Myprojects.FrmYPXMDb.FrmYPXMDb Db = new Myprojects.FrmYPXMDb.FrmYPXMDb();
//表格
private Table table;
private Tree tree;
private Group group;
private Label labelA,labelB;
private Button buttonA,buttonB,buttonC;
private Text textYM;
private Text textYPDJ;
private Text txtYPNBDM;
private Text txtYPFN;
private Combo comboJJDW;
private Text textZFBL;
private Text textYPSR;
private Text textYPWM;
private Combo ComboJX;
private Text textGG;
private Combo ComboCD;
private Combo ComboCJ;
private Text textBZ;
private Button button1;
private Button button2;
private Button button3;
public static void main(){
Display display = new Display();
FrmYPXM YPJG = new FrmYPXM();
//設置字體顏色
colBule = new Color(display,0,0,255);
colRed = new Color(display,255,0,0);
//創(chuàng)建整體框架
YPJG.createShell();
YPJG.shell.open();
while(!YPJG.shell.isDisposed()){
if(!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
private void createShell(){
shell = new Shell();
shell.setBounds(200,200,800,400);
// shell.setSize(1024,768);
shell.setText("藥品價格");
//設置布局方式
GridLayout gridLayout = new GridLayout();
//將shell分為8列
gridLayout.numColumns = 8;
shell.setLayout(gridLayout);
//創(chuàng)建數(shù)據(jù)庫連接
if(!Db.getConnection())
{
MessageBox msBox = new MessageBox(shell,SWT.OK|SWT.ICON_ERROR);
msBox.setText("錯誤");
msBox.setMessage("數(shù)據(jù)庫連接出錯");
msBox.open();
return;
}
//調(diào)用各方法、創(chuàng)建整體界面
createWidgets();
createTable();
// editEntry();
fillTree();
createGroup();
createButton();
shell.open();
}
private void createWidgets(){
//設置組件對齊方式
GridData gridData0 = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
//gridData0.horizontalSpan = 2;
//創(chuàng)建標簽
Label lblYPNBDM = new Label(shell,SWT.None);
lblYPNBDM.setText(" 藥品內(nèi)部代碼 ");
lblYPNBDM.setLayoutData(gridData0);
//創(chuàng)建文本框
txtYPNBDM = new Text(shell,SWT.BORDER);
GridData gridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
gridData.widthHint = 60;
txtYPNBDM.setLayoutData(gridData);
getNumber();
txtYPNBDM.addKeyListener(new KeyAdapter(){
public void keyPressed(KeyEvent event)
{
if (event.keyCode == SWT.CR | event.keyCode == SWT.KEYPAD_CR) //判斷按下什么鍵
{
button1.setEnabled(true);
button2.setEnabled(true);
txtYPNBDM.setEditable(false); //當調(diào)用此方法查詢指定用戶
}
}
});
//雙擊文本框顯示表結(jié)構
txtYPNBDM.addMouseListener(new MouseAdapter() {
public void mouseDoubleClick(MouseEvent e) {
table.setVisible(true);
}
});
//雙擊文本框顯示提示信息
txtYPNBDM.addMouseListener(new MouseAdapter() {
public void mouseDoubleClick(MouseEvent e) {
labelA.setText("雙擊表格一行可以開始修改藥品信息");
}
});
Label Label2 = new Label(shell,SWT.None);
Label2.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
Label Label3 = new Label(shell,SWT.None);
Label3.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
Label Label4 = new Label(shell,SWT.None);
Label4.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
Label Label5 = new Label(shell,SWT.None);
Label5.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
Label lblYPFN = new Label(shell,SWT.None);
lblYPFN.setText(" 藥品分類 ");
txtYPFN = new Text(shell,SWT.BORDER);
txtYPFN.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));
//雙擊文本框顯示提示信息
txtYPFN.addMouseListener(new MouseAdapter() {
public void mouseDoubleClick(MouseEvent e) {
labelA.setText("雙擊選擇一個分類開始輸入 移開焦點將使分類選擇樹隱去");
}
});
//雙擊文本框顯示樹結(jié)構
txtYPFN.addMouseListener(new MouseAdapter() {
public void mouseDoubleClick(MouseEvent e) {
System.out.println("1111");
tree.setVisible(true);
}
});
}
private void getNumber()
{
try
{
int temp = Db.getNumber();
if(temp == 1)
{
if(Db.rs.next())
{
int i = Db.rs.getInt("NUMBER") + 1;
if(i>=100)
txtYPNBDM.setText("000" + String.valueOf(i));
else
txtYPNBDM.setText("0000" + String.valueOf(i));
}
}
else
{
System.out.println("Error!");
}
}
catch(Exception e)
{
System.err.println(e.getMessage());
e.printStackTrace();
}
}
private void createTable(){
//創(chuàng)建表格
table = new Table(shell,SWT.BORDER | SWT.FULL_SELECTION | SWT.H_SCROLL | SWT.V_SCROLL);
//設置表格表頭可見
table.setHeaderVisible(true);
//設置表框線可見
table.setLinesVisible(true);
table.setVisible(false);
//設置表格顯示格式
GridData gridData1 = new GridData(GridData.FILL_BOTH);
gridData1.horizontalSpan = 5;
gridData1.heightHint = 130;
gridData1.widthHint = 350;
table.setLayoutData(gridData1);
//定義表格列名
String[] columns={
"內(nèi)碼",
"藥名",
"規(guī)格",
"產(chǎn)地",
"廠家",
"輸入代用碼",
"計價單位",
"藥品單價",
"劑型",
"自費比例",
"藥品分類",
"外部銜接代碼",
"備注",
};
//添加表格第一列
TableColumn col1 = new TableColumn(table,SWT.LEFT);
col1.setText(columns[0]);
col1.setWidth(55);
//循環(huán)添加表格的后面各列
for(int i=1;i<13;i++){
TableColumn colTotal = new TableColumn(table,SWT.LEFT);
colTotal.setText(columns[i]);
colTotal.setWidth(55);
}
addTableData();
//添加雙擊行的監(jiān)聽器
table.addSelectionListener(new SelectionAdapter() {
public void widgetDefaultSelected(SelectionEvent e) {
txtYPNBDM.setEditable(false);
button1.setEnabled(true);
button2.setEnabled(true);
//獲得當前的選中行
TableItem[] items = table.getSelection();
if (items.length == 0) return;
txtYPNBDM.setText((items[0].getText(0)));
textYM.setText((items[0].getText(1)));
textGG.setText((items[0].getText(2)));
ComboCD.setText((items[0].getText(3)));
ComboCJ.setText((items[0].getText(4)));
textYPSR.setText((items[0].getText(5)));
comboJJDW.setText((items[0].getText(6)));
textYPDJ.setText((items[0].getText(7)));
ComboJX.setText((items[0].getText(8)));
textZFBL.setText((items[0].getText(9)));
textYPWM.setText((items[0].getText(11)));
textBZ.setText((items[0].getText(12)));
}
});
//////////////////////////////////////////////////////////////////////////
//鼠標離開表結(jié)構后,table自動消失
table.addMouseTrackListener(new MouseTrackAdapter() {
public void mouseExit(MouseEvent e) {
table.setVisible(false);
}
});
}
//向表格里添加數(shù)據(jù)
private void addTableData()
{
try {
//從藥品信息表中取得數(shù)據(jù)
Db.getData();
//移動動態(tài)集里的光標直至結(jié)束
while(Db.rs.next()){
//創(chuàng)建行
TableItem item1 = new TableItem(table,0);
//設置當前行的內(nèi)容 (取得當前行內(nèi)容為item1.getText())
item1.setText(new String[]{
Db.rs.getString("YPNM"),
Db.rs.getString("YM"),
Db.rs.getString("GG"),
Db.rs.getString("CD"),
Db.rs.getString("CJ"),
Db.rs.getString("YPSR"),
Db.rs.getString("JJDW"),
Db.rs.getString("YPDJ"),
Db.rs.getString("JX"),
Db.rs.getString("ZFBL"),
Db.rs.getString("YPFL"),
Db.rs.getString("YPWM"),
Db.rs.getString("BZ"),
});
}
}
catch(Exception e) {
System.err.println(e.getMessage());
}
}
//創(chuàng)建樹
private void fillTree() {
tree = new Tree(shell,SWT.SINGLE);
GridData griddata1 = new GridData(GridData.FILL_BOTH);
griddata1.horizontalSpan = 3;
tree.setLayoutData(griddata1);
tree.setVisible(false);
//鼠標離開樹結(jié)構后,tree自動消失
tree.addMouseTrackListener(new MouseTrackAdapter() {
public void mouseExit(MouseEvent e) {
tree.setVisible(false);
}
});
try
{
//分類代碼
String nowDM = "";
//字符長度
int nowLengh;
//取得醫(yī)藥分類表的數(shù)據(jù)
Db.getDataSFFL();
//移動光標
Db.rs.next();
//取得分類代碼
nowDM = Db.rs.getString("FLDM").trim();
//取得字符長度
nowLengh = nowDM.length();
//生成節(jié)點
final TreeItem item1 = new TreeItem(tree,SWT.None);
//設置內(nèi)容
item1.setText(Db.rs.getString("FLMS"));
//設置當前節(jié)點的分類代碼(它是數(shù)據(jù)表記錄關鍵字,以此作為一個節(jié)點數(shù)據(jù)的ID)
item1.setData("fldm index",nowDM);
TreeItem item; //臨時item
TreeItem item2F; //第二層
TreeItem item3F; //第三層
item = item1;
item2F = item1;
item3F = item1;
while (Db.rs.next()) {
nowDM = Db.rs.getString("FLDM").trim();
nowLengh = nowDM.length();
//判斷字符長度
if (nowLengh == 3) {
//指定上層為第一層
item = item1;
//生成子節(jié)點
final TreeItem item2 = new TreeItem(item,SWT.NULL);
//設置內(nèi)容
item2.setText(Db.rs.getString("FLMS"));
//設置當前節(jié)點的分類代碼(它是數(shù)據(jù)表記錄關鍵字,以此作為一個節(jié)點數(shù)據(jù)的ID)
item2.setData("fldm index",nowDM);
item2F = item2;
}
if (nowLengh == 5) {
//指定上層為第二層
item = item2F;
//生成子節(jié)點
final TreeItem item3 = new TreeItem(item,SWT.NULL);
//設置內(nèi)容
item3.setText(Db.rs.getString("FLMS"));
//設置當前節(jié)點的分類代碼(它是數(shù)據(jù)表記錄關鍵字,以此作為一個節(jié)點數(shù)據(jù)的ID)
item3.setData("fldm index",nowDM);
item3F = item3;
}
if (nowLengh == 7) {
//指定上層為第三層
item = item3F;
//生成子節(jié)點
final TreeItem item4 = new TreeItem(item,SWT.NULL);
//設置內(nèi)容
item4.setText(Db.rs.getString("FLMS"));
//設置當前節(jié)點的分類代碼(它是數(shù)據(jù)表記錄關鍵字,以此作為一個節(jié)點數(shù)據(jù)的ID)
item4.setData("fldm index",nowDM);
}
}
} catch(Exception e) {
System.err.println(e.getMessage());
}
//添加雙擊節(jié)點的監(jiān)聽器
tree.addSelectionListener(new SelectionAdapter() {
public void widgetDefaultSelected(SelectionEvent e) {
//獲得當前的選中節(jié)點
TreeItem[] items = tree.getSelection();
Object temp = items[0].getData("fldm index");
txtYPFN.setText(String.valueOf(temp));
}
});
}
private void createGroup(){
group = new Group(shell,SWT.SHADOW_ETCHED_IN);
//設置group顯示格式
GridData gridData0 = new GridData(GridData.FILL_BOTH);
gridData0.horizontalSpan=8;
group.setLayoutData(gridData0);
//設置group布局
GridLayout gridLayout = new GridLayout();
gridLayout.numColumns = 7;
group.setLayout(gridLayout);
//添加各組件到group
Label lblYM = new Label(group,SWT.None);
lblYM.setText(" 藥名 ");
textYM = new Text(group,SWT.BORDER);
textYM.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));
Label lblYPDJ = new Label(group,SWT.None);
lblYPDJ.setText(" 藥品單價 ");
textYPDJ = new Text(group,SWT.BORDER);
textYPDJ.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));
Label lblJJDW = new Label(group,SWT.None);
lblJJDW.setText(" 計價單位 ");
comboJJDW = new Combo(group,SWT.None);
getCmb(comboJJDW,"JJDW");
comboJJDW.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));
new Label(group,SWT.None);
Label lblZFBL = new Label(group,SWT.None);
lblZFBL.setText(" 自費比例 ");
textZFBL = new Text(group,SWT.BORDER);
textZFBL.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));
Label lblYPSR = new Label(group,SWT.None);
lblYPSR.setText(" 輸入用代碼 ");
textYPSR = new Text(group,SWT.BORDER);
textYPSR.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));
Label lblYPWM = new Label(group,SWT.None);
lblYPWM.setText(" 外部銜接代碼 ");
textYPWM = new Text(group,SWT.BORDER);
textYPWM.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));
new Label(group,SWT.None);
Label lblJX = new Label(group,SWT.None);
lblJX.setText(" 劑型 ");
ComboJX = new Combo(group,SWT.BORDER);
getCmb(ComboJX,"JX");
ComboJX.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));
Label lblGG = new Label(group,SWT.None);
lblGG.setText(" 規(guī)格 ");
textGG = new Text(group,SWT.BORDER);
textGG.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -