📄 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);
//创建整体框架
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);
//创建数据库连接
if(!Db.getConnection())
{
MessageBox msBox = new MessageBox(shell,SWT.OK|SWT.ICON_ERROR);
msBox.setText("错误");
msBox.setMessage("数据库连接出错");
msBox.open();
return;
}
//调用各方法、创建整体界面
createWidgets();
createTable();
// editEntry();
fillTree();
createGroup();
createButton();
shell.open();
}
private void createWidgets(){
//设置组件对齐方式
GridData gridData0 = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
//gridData0.horizontalSpan = 2;
//创建标签
Label lblYPNBDM = new Label(shell,SWT.None);
lblYPNBDM.setText(" 药品内部代码 ");
lblYPNBDM.setLayoutData(gridData0);
//创建文本框
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); //当调用此方法查询指定用户
}
}
});
//双击文本框显示表结构
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("双击选择一个分类开始输入 移开焦点将使分类选择树隐去");
}
});
//双击文本框显示树结构
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(){
//创建表格
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={
"内码",
"药名",
"规格",
"产地",
"厂家",
"输入代用码",
"计价单位",
"药品单价",
"剂型",
"自费比例",
"药品分类",
"外部衔接代码",
"备注",
};
//添加表格第一列
TableColumn col1 = new TableColumn(table,SWT.LEFT);
col1.setText(columns[0]);
col1.setWidth(55);
//循环添加表格的后面各列
for(int i=1;i<13;i++){
TableColumn colTotal = new TableColumn(table,SWT.LEFT);
colTotal.setText(columns[i]);
colTotal.setWidth(55);
}
addTableData();
//添加双击行的监听器
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)));
}
});
//////////////////////////////////////////////////////////////////////////
//鼠标离开表结构后,table自动消失
table.addMouseTrackListener(new MouseTrackAdapter() {
public void mouseExit(MouseEvent e) {
table.setVisible(false);
}
});
}
//向表格里添加数据
private void addTableData()
{
try {
//从药品信息表中取得数据
Db.getData();
//移动动态集里的光标直至结束
while(Db.rs.next()){
//创建行
TableItem item1 = new TableItem(table,0);
//设置当前行的内容 (取得当前行内容为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());
}
}
//创建树
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);
//鼠标离开树结构后,tree自动消失
tree.addMouseTrackListener(new MouseTrackAdapter() {
public void mouseExit(MouseEvent e) {
tree.setVisible(false);
}
});
try
{
//分类代码
String nowDM = "";
//字符长度
int nowLengh;
//取得医药分类表的数据
Db.getDataSFFL();
//移动光标
Db.rs.next();
//取得分类代码
nowDM = Db.rs.getString("FLDM").trim();
//取得字符长度
nowLengh = nowDM.length();
//生成节点
final TreeItem item1 = new TreeItem(tree,SWT.None);
//设置内容
item1.setText(Db.rs.getString("FLMS"));
//设置当前节点的分类代码(它是数据表记录关键字,以此作为一个节点数据的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;
//生成子节点
final TreeItem item2 = new TreeItem(item,SWT.NULL);
//设置内容
item2.setText(Db.rs.getString("FLMS"));
//设置当前节点的分类代码(它是数据表记录关键字,以此作为一个节点数据的ID)
item2.setData("fldm index",nowDM);
item2F = item2;
}
if (nowLengh == 5) {
//指定上层为第二层
item = item2F;
//生成子节点
final TreeItem item3 = new TreeItem(item,SWT.NULL);
//设置内容
item3.setText(Db.rs.getString("FLMS"));
//设置当前节点的分类代码(它是数据表记录关键字,以此作为一个节点数据的ID)
item3.setData("fldm index",nowDM);
item3F = item3;
}
if (nowLengh == 7) {
//指定上层为第三层
item = item3F;
//生成子节点
final TreeItem item4 = new TreeItem(item,SWT.NULL);
//设置内容
item4.setText(Db.rs.getString("FLMS"));
//设置当前节点的分类代码(它是数据表记录关键字,以此作为一个节点数据的ID)
item4.setData("fldm index",nowDM);
}
}
} catch(Exception e) {
System.err.println(e.getMessage());
}
//添加双击节点的监听器
tree.addSelectionListener(new SelectionAdapter() {
public void widgetDefaultSelected(SelectionEvent e) {
//获得当前的选中节点
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(" 规格 ");
textGG = new Text(group,SWT.BORDER);
textGG.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -