📄 goodnotequaldatainjpanel.java
字号:
package file1;
/*
* @Author:
* Create Time:2008-2-22
* Description:货品损益记录的数据录入界面
*/
import javax.swing.*;
import java.util.*;
import java.awt.*;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import tools.StringToInsertToDBFilter;
public class GoodNotEqualDataInJPanel extends JPanel implements ItemListener {
private GetDate getD = new GetDate();// 格式化录入的日期
private JLabel goodType = new JLabel("货品类型:");
private JComboBox goodTypeBox = new JComboBox();
private JLabel goodName = new JLabel("货品名称:");
private JComboBox goodNameBox = new JComboBox();
private JLabel checkTime = new JLabel("损益发生时间:");
private JTextField checkTimeTF = new JTextField(10);
private JLabel notEqualNumber = new JLabel("损益数量:");
private JTextField notEqualNumberTF = new JTextField(10);
private JLabel notEqualState = new JLabel("损益状态:");
private JComboBox notEqualStateBox = new JComboBox(new String[] { "增加",
"减少" });
private JLabel notEqualReason = new JLabel("损益原因");
private JTextArea notEqualReasonTA = new JTextArea(5, 10);
private String[] goodIDs = null;// 存储所有货品id的变量数组
private String[] typeIDs = null;// 存储所有货品类型记录的变量数组
public GoodNotEqualDataInJPanel() {
getAllGoodTypes();// 初始化货品类型下拉框
this.setLayout(new FlowLayout(FlowLayout.LEADING, 5, 0));
this.add(goodType);
this.add(goodTypeBox);
this.add(goodName);
this.add(goodNameBox);
this.add(checkTime);
this.add(checkTimeTF);
this.add(notEqualNumber);
this.add(notEqualNumberTF);
this.add(notEqualState);
this.add(notEqualStateBox);
this.add(notEqualReason);
this.add(notEqualReasonTA);
goodTypeBox.addItemListener(this);
}
private void getAllGoodTypes() {// 初始化货品类型下拉框
if (goodTypeBox.getItemCount() > 0) {
goodTypeBox.removeAllItems();
}
GoodType goodType = new GoodType();
goodType.setID(0);
GoodTypeOperate goodTypeOperate = new GoodTypeOperate();
ArrayList valuesGet = goodTypeOperate.selectFromDB(goodType);// 从数据库中查询所有货品类型记录
int total = valuesGet.size();// total为记录货品类型总数变量
typeIDs = new String[total];
total = 0;// 从开始位置给数组赋值
Iterator it = valuesGet.iterator();
for (int i = 0; i < valuesGet.size(); i++) {
GoodType gType = (GoodType) valuesGet.get(i);
typeIDs[total++] = String.valueOf(gType.getID());
goodTypeBox.addItem(gType.getTypeName());
}
goodTypeBox.setSelectedIndex(-1);// 初始状态置为空
}
public void itemStateChanged(ItemEvent ie) {
if (ie.getSource() == goodTypeBox) {
if (goodNameBox.getItemCount() > 0) {
goodNameBox.removeAllItems();
}
int index = goodTypeBox.getSelectedIndex();
if (index == -1) {// 没有选择
return;
}
Good good = new Good();
good.setTypeID(Integer.valueOf(typeIDs[index]));
GoodOperate goodOperate = new GoodOperate();
ArrayList valuesGet = goodOperate.selectFromDB(good);// 从数据库中查询所有该类型的记录
int total = valuesGet.size();// total为记录总数变量
goodIDs = new String[total];
total = 0;// 计数重新置零
Iterator it = valuesGet.iterator();
for (int i = 0; i < valuesGet.size(); i++) {
Good goodTemp = (Good) valuesGet.get(i);
goodIDs[total++] = String.valueOf(goodTemp.getID());
goodNameBox.addItem(goodTemp.getGoodName());
}
goodNameBox.setSelectedIndex(-1);// 初始状态为空
}
}
public void GoodNotEqualRecordDataOut(GoodNotEqual goodNotEqual) {// 读取GoodNotEqual对象的数据显示到损益记录录入窗口
if (goodNotEqual != null) {
if (goodNotEqual.getProperty("typeName") != null) {
goodTypeBox.setSelectedItem(goodNotEqual
.getProperty("typeName"));
} else {
return;
}
if (goodNotEqual.getProperty("goodName") != null) {
goodNameBox.setSelectedItem(goodNotEqual
.getProperty("goodName"));
} else {
return;
}
if (goodNotEqual.getCheck_Time() != null) {
checkTimeTF.setText(goodNotEqual.getCheck_Time());
} else {
return;
}
if (goodNotEqual.getNot_Equal_Number() > 0) {
notEqualNumberTF.setText(String.valueOf(goodNotEqual
.getNot_Equal_Number()));
} else {
return;
}
if (goodNotEqual.getNot_Equal_State() != null) {
notEqualStateBox.setSelectedItem(goodNotEqual
.getNot_Equal_State());
} else {
return;
}
if (goodNotEqual.getNot_Equal_Reason() != null) {
notEqualReasonTA.setText(StringToInsertToDBFilter
.doReverseFilter(goodNotEqual.getNot_Equal_Reason()));
} else {
return;
}
}
}
public GoodNotEqual getGoodNotEqualRecordDataIn() {// 从货品损益记录录入窗口中读取货品损益记录数据
int index = goodNameBox.getSelectedIndex();
if (index == -1) {
JOptionPane.showMessageDialog(null, "发生损益的货品不能为空!", "",
JOptionPane.INFORMATION_MESSAGE);
return null;
}
String timeGet = getD.getDate(checkTimeTF.getText().trim());
if (timeGet == null) {
JOptionPane.showMessageDialog(null, "损益发生时间必须为如2008-2-17的格式!", "",
JOptionPane.INFORMATION_MESSAGE);
return null;
}
int numberNotEqual = -1;
try {
numberNotEqual = Integer.valueOf(notEqualNumberTF.getText().trim());
if (numberNotEqual <= 0) {
JOptionPane.showMessageDialog(null, "损益数量必须为大于零的整数!", "",
JOptionPane.INFORMATION_MESSAGE);
return null;
}
} catch (NumberFormatException nfe) {
JOptionPane.showMessageDialog(null, "损益数量必须大于零的整数!", "",
JOptionPane.INFORMATION_MESSAGE);
return null;
}
int indexState = notEqualStateBox.getSelectedIndex();
if (indexState == -1) {
JOptionPane.showMessageDialog(null, "损益状态不能为空!", "",
JOptionPane.INFORMATION_MESSAGE);
return null;
}
String notEqualState = (String) notEqualStateBox.getItemAt(indexState);
String notEqualReason = notEqualReasonTA.getText().trim();// 读取损益原因
// 初始化目标GoodNotEqual对象
GoodNotEqual goodNotEqual = new GoodNotEqual();
goodNotEqual.setGood_ID(Integer.valueOf(goodIDs[index]));
goodNotEqual.setCheck_Time(timeGet);
goodNotEqual.setNot_Equal_Number(numberNotEqual);
goodNotEqual.setNot_Equal_State(notEqualState);
goodNotEqual.setNot_Equal_Reason(StringToInsertToDBFilter
.doFilter(notEqualReason));// 过滤掉字符串中的'字符
return goodNotEqual;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -