- import com.kingdee.eas.hr.emp.client.PhotoPanel;
- import java.awt.p_w_picpath.BufferedImage;
- public class RentVehicleEditUI extends AbstractRentVehicleEditUI {
- private static final Logger logger = CoreUIObject
- .getLogger(RentVehicleEditUI.class);
- // 用于存放当前修改的记录的number,方便判断用户修改过number没有
- String tempNumber = "";
- // 作用同上,存放×××号码
- String tempIdentityNo = "";
- PhotoPanel photoPanel = new PhotoPanel();
- BufferedImage bufferedImage = null;
- /**
- * output class constructor
- */
- public RentVehicleEditUI() throws Exception {
- super();
- }
- /**
- * output loadFields method
- */
- public void loadFields() {
- super.loadFields();
- // 将当前打开的信息的number记录下来,方便后面判断是否改过该记录
- tempNumber = this.editData.getNumber();
- tempIdentityNo = this.editData.getIdentityNo();
- this.initPhotoPanel();// 初始化图片显示区
- if (this.oprtState.equals(OprtState.ADDNEW)) {
- photoPanel.setSelectImage(null);
- photoPanel.repaint();
- } else {
- try {
- this.loadImage();// 加载图片
- } catch (Exception e) {
- // MsgBox.showWarning("加载图像失败!");
- e.printStackTrace();
- }
- }
- }
- // 初始化图片显示区
- private void initPhotoPanel() {
- photoPanel.setOprtStat("ADD");
- photoPanel.setBounds(627, 117, 169, 150);
- photoPanel.setBackground(Color.ORANGE);
- this.add(photoPanel);
- }
- // 在非新增状态下加载已经存储的图片
- private void loadImage() throws Exception {
- IRentVehicle irentVehicle = RentVehicleFactory.getRemoteInstance();
- RentVehicleInfo rentVehicleInfo = null;
- try {
- rentVehicleInfo = irentVehicle
- .getRentVehicleInfo("select driverPhoto where id =" + "'"
- + this.editData.getId() + "'"); // select
- // DriverPhoto
- } catch (ObjectNotFoundException e) {
- MsgBox.showInfo("照片不存在");
- SysUtil.abort();
- }
- if (!rentVehicleInfo.isEmpty()) {
- byte[] byteArray = rentVehicleInfo.getDriverPhoto();
- ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(
- byteArray);
- bufferedImage = ImageIO.read(byteArrayInputStream);
- photoPanel.setSelectImage(bufferedImage);
- byteArrayInputStream.close();
- photoPanel.repaint();
- }
- }
- // 图片转化为二进制文件
- public byte[] p_w_picpathToBytes(File file) {
- if (this.oprtState.equals(OprtState.ADDNEW)) {
- // if(file==null){
- // MsgBox.showWarning("没有添加司机照片!");
- // }
- }
- if (file != null) {
- int size = (int) file.length();
- FileInputStream fin = null;
- try {
- fin = new FileInputStream(file);
- } catch (FileNotFoundException e) {
- e.printStackTrace();
- }
- byte[] bts = null;
- if (size > 0) {
- bts = new byte[size];
- try {
- fin.read(bts);
- } catch (IOException e) {
- e.printStackTrace();
- }
- return bts;
- }
- }
- return null;
- }
另外,在实体中新增该属性,类型为ByteArray
对应的表中的字段类型为BLOB。
转载于:https://blog.51cto.com/huqianhao/955297