⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jticketsbagrestaurantres.java

📁 是一个专门设计用于触摸屏的POS(point of sales)应用软件
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
//    Tina POS is a point of sales application designed for touch screens.
//    Copyright (C) 2005 Adrian Romero Corchado.
//    http://sourceforge.net/projects/tinapos
//
//    This program is free software; you can redistribute it and/or modify
//    it under the terms of the GNU General Public License as published by
//    the Free Software Foundation; either version 2 of the License, or
//    (at your option) any later version.
//
//    This program is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//    GNU General Public License for more details.
//
//    You should have received a copy of the GNU General Public License
//    along with this program; if not, write to the Free Software
//    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

package net.adrianromero.tpv.panelsales.restaurant;

import java.awt.BorderLayout;
import java.beans.*;
import java.util.*;

import net.adrianromero.beans.*;
import net.adrianromero.data.gui.*;
import net.adrianromero.data.loader.*;
import net.adrianromero.data.user.*;

import net.adrianromero.tpv.forms.AppLocal;
import net.adrianromero.tpv.forms.AppView;
import net.adrianromero.format.Formats;
import net.adrianromero.basic.BasicException;
import net.adrianromero.tpv.forms.SentenceContainer;
import net.adrianromero.tpv.panelsales.*;

public class JTicketsBagRestaurantRes extends javax.swing.JPanel implements EditorRecord {

    private AppView m_App;
    private JTicketsBagRestaurantMap m_restaurantmap;
    
    private DirtyManager m_Dirty;
    private Integer m_iID;
    private JTimePanel m_timereservation;
    private boolean m_bReceived;
    private BrowsableEditableData m_bd;
        
    private Date m_dcurrentday;
    
    private JCalendarPanel m_datepanel;    
    private JTimePanel m_timepanel;
    private boolean m_bpaintlock = false;

    // private Date dinitdate = new GregorianCalendar(1900, 0, 0, 12, 0).getTime();
    
    /** Creates new form JPanelReservations */
    public JTicketsBagRestaurantRes(AppView oApp, JTicketsBagRestaurantMap restaurantmap) {
        
        m_App = oApp;        
        m_restaurantmap = restaurantmap;
        
        m_dcurrentday = null;
        
        initComponents();
        
        m_datepanel = new JCalendarPanel();
        jPanelDate.add(m_datepanel, BorderLayout.CENTER);
        m_datepanel.addPropertyChangeListener("Date", new DateChangeCalendarListener());
        
        m_timepanel = new JTimePanel(null, JTimePanel.BUTTONS_HOUR);
        m_timepanel.setPeriod(3600000L); // Los milisegundos que tiene una hora.
        jPanelTime.add(m_timepanel, BorderLayout.CENTER);
        m_timepanel.addPropertyChangeListener("Date", new DateChangeTimeListener());
        
        m_timereservation = new JTimePanel(null, JTimePanel.BUTTONS_MINUTE);
        m_jPanelTime.add(m_timereservation, BorderLayout.CENTER);
        
        SentenceList sentload = new StaticSentence(oApp.getSession()
            , "SELECT ID, DATENEW, TITLE, CHAIRS, ISDONE, DESCRIPTION FROM RESERVATIONS WHERE DATENEW >= ? AND DATENEW < ?"
            , new SerializerWriteBasic(new Datas[] {Datas.TIMESTAMP, Datas.TIMESTAMP})
            , new SerializerReadBasic(new Datas[] {Datas.INT, Datas.TIMESTAMP, Datas.STRING, Datas.INT, Datas.BOOLEAN, Datas.STRING}));            
            
        TableDefinition treservations = new TableDefinition(oApp.getSession(),
            "RESERVATIONS"
            , new int[] {0}
            , new String[] {"ID", "DATENEW", "TITLE", "CHAIRS", "ISDONE", "DESCRIPTION"}
            , new Datas[] {Datas.INT, Datas.TIMESTAMP, Datas.STRING, Datas.INT, Datas.BOOLEAN, Datas.STRING}
            , new Formats[] {Formats.NULL, Formats.TIME, Formats.STRING}
            , new Formats[] {Formats.NULL, Formats.TIME, Formats.STRING}
        );     
        
        m_jtxtTitle.addEditorKeys(m_jKeys);
        m_jtxtChairs.addEditorKeys(m_jKeys);
        m_jtxtDescription.addEditorKeys(m_jKeys);

        m_Dirty = new DirtyManager();
        m_timereservation.addPropertyChangeListener("Date", m_Dirty);
        m_jtxtTitle.addPropertyChangeListener("Text", m_Dirty);
        m_jtxtChairs.addPropertyChangeListener("Text", m_Dirty);
        m_jtxtDescription.addPropertyChangeListener("Text", m_Dirty);
        
        writeValueEOF();
        
        ListProvider lpr = new ListProviderCreator(sentload, new MyDateFilter());            
        SaveProvider spr = new SaveProvider(treservations);        
        
        m_bd = new BrowsableEditableData(lpr, spr, new CompareReservations(), this);           
        
        JListNavigator nl = new JListNavigator(m_bd, true);
        nl.setCellRenderer(new JCalendarItemRenderer());  
        m_jPanelList.add(nl, BorderLayout.CENTER);
        
        // La Toolbar
        m_jToolbar.add(new JLabelDirty(m_Dirty));
        m_jToolbar.add(new JCounter(m_bd));
        m_jToolbar.add(new JNavigator(m_bd));
        m_jToolbar.add(new JSaver(m_bd));       
    }
    
    private class MyDateFilter implements EditorCreator {
        public Object createValue() throws BasicException {           
            return new Object[] {m_dcurrentday, new Date(m_dcurrentday.getTime() + 3600000L)};   // m_dcurrentday ya no tiene ni minutos, ni segundos.             
        }
    }
    
    public void activate() {
        reload(DateUtils.getTodayHours(new Date()));
    }
    
    public boolean deactivate() {
        try {
            return m_bd.actionClosingForm(this);
        } catch (BasicException eD) {
            MessageInf msg = new MessageInf(MessageInf.SGN_NOTICE, AppLocal.getIntString("message.CannotMove"), eD);
            msg.show(this);
            return false;
        }
    }
    
    public void writeValueEOF() {
        m_iID = null;
        m_timereservation.setDate(null);
        m_jtxtTitle.reset();
        m_jtxtChairs.reset();
        m_bReceived = false;
        m_jtxtDescription.reset();
        m_timereservation.setEnabled(false);
        m_jtxtTitle.setEnabled(false);
        m_jtxtChairs.setEnabled(false);
        m_jtxtDescription.setEnabled(false);
        m_jKeys.setEnabled(false);
        
        m_jbtnReceive.setEnabled(false);
    }    
    public void writeValueInsert() {
        m_iID = null;
        m_timereservation.setCheckDates(m_dcurrentday, new Date(m_dcurrentday.getTime() + 3600000L));
        m_timereservation.setDate(m_dcurrentday);
        m_jtxtTitle.reset();
        m_jtxtChairs.setValueInteger(2);
        m_bReceived = false;
        m_jtxtDescription.reset();
        m_timereservation.setEnabled(true);
        m_jtxtTitle.setEnabled(true);
        m_jtxtChairs.setEnabled(true);
        m_jtxtDescription.setEnabled(true);
        m_jKeys.setEnabled(true);
        
        m_jbtnReceive.setEnabled(true);
        
        m_jtxtTitle.activate();
    }
    public void writeValueDelete(Object value) {
        Object[] res = (Object[]) value;
        m_iID = (Integer) res[0];
        m_timereservation.setCheckDates(m_dcurrentday, new Date(m_dcurrentday.getTime() + 3600000L));
        m_timereservation.setDate((Date) res[1]);
        m_jtxtTitle.setText(Formats.STRING.formatValue(res[2]));
        m_jtxtChairs.setValueInteger(((Integer)res[3]).intValue());
        m_bReceived = ((Boolean)res[4]).booleanValue();
        m_jtxtDescription.setText(Formats.STRING.formatValue(res[5]));
        m_timereservation.setEnabled(false);
        m_jtxtTitle.setEnabled(false);
        m_jtxtChairs.setEnabled(false);
        m_jtxtDescription.setEnabled(false);
        m_jKeys.setEnabled(false);
        
        m_jbtnReceive.setEnabled(false); 
    }  
    public void writeValueEdit(Object value) {
        Object[] res = (Object[]) value;
        m_iID = (Integer) res[0];
        m_timereservation.setCheckDates(m_dcurrentday, new Date(m_dcurrentday.getTime() + 3600000L));
        m_timereservation.setDate((Date) res[1]);
        m_jtxtTitle.setText(Formats.STRING.formatValue(res[2]));
        m_jtxtChairs.setValueInteger(((Integer)res[3]).intValue());
        m_bReceived = ((Boolean)res[4]).booleanValue();
        m_jtxtDescription.setText(Formats.STRING.formatValue(res[5]));
        m_timereservation.setEnabled(true);
        m_jtxtTitle.setEnabled(true);
        m_jtxtChairs.setEnabled(true);
        m_jtxtDescription.setEnabled(true);
        m_jKeys.setEnabled(true);

        m_jbtnReceive.setEnabled(!m_bReceived); // se habilita si no se ha recibido al cliente

        m_jtxtTitle.activate();
    }    

    public Object createValue() throws BasicException {
        
        Object[] res = new Object[6];
        
        res[0] = m_iID == null ? m_App.lookupDataLogic(SentenceContainer.class).getNextReservation() : m_iID; // si casca que suba la excepcion hacia arriba.
        res[1] = m_timereservation.getDate();
        res[2] = m_jtxtTitle.getText();
        res[3] = new Integer(m_jtxtChairs.getValueInteger());
        res[4] = new Boolean(m_bReceived);
        res[5] = m_jtxtDescription.getText();

        return res;
    }    
    
    public DirtyManager getDirtyManager() {
        return m_Dirty;
    }        
    
    private static class CompareReservations implements Comparator {
        public int compare(Object o1, Object o2) {
            Object[] a1 = (Object[]) o1;
            Object[] a2 = (Object[]) o2;
            Date d1 = (Date) a1[1];

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -