📄 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.setLayoutData(griddata5);
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 + -