Lab4 comm

This commit is contained in:
Arklightning 2023-05-14 13:05:00 +04:00
commit 7933a8aff7
22 changed files with 4962 additions and 0 deletions

73
build.xml Normal file
View File

@ -0,0 +1,73 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- You may freely edit this file. See commented blocks below for -->
<!-- some examples of how to customize the build. -->
<!-- (If you delete it and reopen the project it will be recreated.) -->
<!-- By default, only the Clean and Build commands use this build script. -->
<!-- Commands such as Run, Debug, and Test only use this build script if -->
<!-- the Compile on Save feature is turned off for the project. -->
<!-- You can turn off the Compile on Save (or Deploy on Save) setting -->
<!-- in the project's Project Properties dialog box.-->
<project name="JavaApplication1" default="default" basedir=".">
<description>Builds, tests, and runs the project JavaApplication1.</description>
<import file="nbproject/build-impl.xml"/>
<!--
There exist several targets which are by default empty and which can be
used for execution of your tasks. These targets are usually executed
before and after some main targets. They are:
-pre-init: called before initialization of project properties
-post-init: called after initialization of project properties
-pre-compile: called before javac compilation
-post-compile: called after javac compilation
-pre-compile-single: called before javac compilation of single file
-post-compile-single: called after javac compilation of single file
-pre-compile-test: called before javac compilation of JUnit tests
-post-compile-test: called after javac compilation of JUnit tests
-pre-compile-test-single: called before javac compilation of single JUnit test
-post-compile-test-single: called after javac compilation of single JUunit test
-pre-jar: called before JAR building
-post-jar: called after JAR building
-post-clean: called after cleaning build products
(Targets beginning with '-' are not intended to be called on their own.)
Example of inserting an obfuscator after compilation could look like this:
<target name="-post-compile">
<obfuscate>
<fileset dir="${build.classes.dir}"/>
</obfuscate>
</target>
For list of available properties check the imported
nbproject/build-impl.xml file.
Another way to customize the build is by overriding existing main targets.
The targets of interest are:
-init-macrodef-javac: defines macro for javac compilation
-init-macrodef-junit: defines macro for junit execution
-init-macrodef-debug: defines macro for class debugging
-init-macrodef-java: defines macro for class execution
-do-jar: JAR building
run: execution of project
-javadoc-build: Javadoc generation
test-report: JUnit report generation
An example of overriding the target for project execution could look like this:
<target name="run" depends="JavaApplication1-impl.jar">
<exec dir="bin" executable="launcher.exe">
<arg file="${dist.jar}"/>
</exec>
</target>
Notice that the overridden target depends on the jar target and not only on
the compile target as the regular run target does. Again, for a list of available
properties which you can use, check the target you are overriding in the
nbproject/build-impl.xml file.
-->
</project>

3
manifest.mf Normal file
View File

@ -0,0 +1,3 @@
Manifest-Version: 1.0
X-COMMENT: Main-Class will be added automatically by build

1771
nbproject/build-impl.xml Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,8 @@
build.xml.data.CRC32=3569ad16
build.xml.script.CRC32=360ae6d5
build.xml.stylesheet.CRC32=f85dc8f2@1.106.0.48
# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
nbproject/build-impl.xml.data.CRC32=3569ad16
nbproject/build-impl.xml.script.CRC32=53035f8f
nbproject/build-impl.xml.stylesheet.CRC32=12e0a6c2@1.106.0.48

View File

@ -0,0 +1,98 @@
annotation.processing.enabled=true
annotation.processing.enabled.in.editor=false
annotation.processing.processors.list=
annotation.processing.run.all.processors=true
annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output
application.title=JavaApplication1
application.vendor=oleg
build.classes.dir=${build.dir}/classes
build.classes.excludes=**/*.java,**/*.form
# This directory is removed when the project is cleaned:
build.dir=build
build.generated.dir=${build.dir}/generated
build.generated.sources.dir=${build.dir}/generated-sources
# Only compile against the classpath explicitly listed here:
build.sysclasspath=ignore
build.test.classes.dir=${build.dir}/test/classes
build.test.results.dir=${build.dir}/test/results
# Uncomment to specify the preferred debugger connection transport:
#debug.transport=dt_socket
debug.classpath=\
${run.classpath}
debug.modulepath=\
${run.modulepath}
debug.test.classpath=\
${run.test.classpath}
debug.test.modulepath=\
${run.test.modulepath}
# Files in build.classes.dir which should be excluded from distribution jar
dist.archive.excludes=
# This directory is removed when the project is cleaned:
dist.dir=dist
dist.jar=${dist.dir}/JavaApplication1.jar
dist.javadoc.dir=${dist.dir}/javadoc
dist.jlink.dir=${dist.dir}/jlink
dist.jlink.output=${dist.jlink.dir}/JavaApplication1
endorsed.classpath=
excludes=
includes=**
jar.compress=false
javac.classpath=\
${libs.PostgreSQLDriver.classpath}
# Space-separated list of extra javac options
javac.compilerargs=
javac.deprecation=false
javac.external.vm=true
javac.modulepath=
javac.processormodulepath=
javac.processorpath=\
${javac.classpath}
javac.source=18
javac.target=18
javac.test.classpath=\
${javac.classpath}:\
${build.classes.dir}
javac.test.modulepath=\
${javac.modulepath}
javac.test.processorpath=\
${javac.test.classpath}
javadoc.additionalparam=
javadoc.author=false
javadoc.encoding=${source.encoding}
javadoc.html5=false
javadoc.noindex=false
javadoc.nonavbar=false
javadoc.notree=false
javadoc.private=false
javadoc.splitindex=true
javadoc.use=true
javadoc.version=false
javadoc.windowtitle=
# The jlink additional root modules to resolve
jlink.additionalmodules=
# The jlink additional command line parameters
jlink.additionalparam=
jlink.launcher=true
jlink.launcher.name=JavaApplication1
main.class=javaapplication1.MainFrame
manifest.file=manifest.mf
meta.inf.dir=${src.dir}/META-INF
mkdist.disabled=false
platform.active=default_platform
run.classpath=\
${javac.classpath}:\
${build.classes.dir}
# Space-separated list of JVM arguments used when running the project.
# You may also define separate properties like run-sys-prop.name=value instead of -Dname=value.
# To set system properties for unit tests define test-sys-prop.name=value:
run.jvmargs=
run.modulepath=\
${javac.modulepath}
run.test.classpath=\
${javac.test.classpath}:\
${build.test.classes.dir}
run.test.modulepath=\
${javac.test.modulepath}
source.encoding=UTF-8
src.dir=src
test.src.dir=test

15
nbproject/project.xml Normal file
View File

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://www.netbeans.org/ns/project/1">
<type>org.netbeans.modules.java.j2seproject</type>
<configuration>
<data xmlns="http://www.netbeans.org/ns/j2se-project/3">
<name>JavaApplication1</name>
<source-roots>
<root id="src.dir"/>
</source-roots>
<test-roots>
<root id="test.src.dir"/>
</test-roots>
</data>
</configuration>
</project>

View File

@ -0,0 +1,17 @@
package javaapplication1;
import java.sql.*;
public class DBConnection {
public static Connection getConnection() throws SQLException {
Connection connection = null;
try {
Class.forName("org.postgresql.Driver");
connection = DriverManager.getConnection(
"jdbc:postgresql://192.168.1.44:5432/hotel", "hotel_admin", "1");
System.out.println("Connected to PostgreSQL database!");
} catch (ClassNotFoundException | SQLException e) {
e.printStackTrace();
}
return connection;
}
}

View File

@ -0,0 +1,84 @@
<?xml version="1.0" encoding="UTF-8" ?>
<Form version="1.3" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JFrameFormInfo">
<Properties>
<Property name="defaultCloseOperation" type="int" value="3"/>
</Properties>
<SyntheticProperties>
<SyntheticProperty name="formSizePolicy" type="int" value="1"/>
<SyntheticProperty name="generateCenter" type="boolean" value="false"/>
</SyntheticProperties>
<AuxValues>
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
<AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
</AuxValues>
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Component id="jScrollPane1" min="-2" pref="375" max="-2" attributes="0"/>
<EmptySpace pref="13" max="32767" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Component id="jScrollPane1" min="-2" pref="301" max="-2" attributes="0"/>
<EmptySpace pref="13" max="32767" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
</Layout>
<SubComponents>
<Container class="javax.swing.JScrollPane" name="jScrollPane1">
<AuxValues>
<AuxValue name="autoScrollPane" type="java.lang.Boolean" value="true"/>
</AuxValues>
<Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/>
<SubComponents>
<Component class="javax.swing.JTable" name="jTable1">
<Properties>
<Property name="model" type="javax.swing.table.TableModel" editor="org.netbeans.modules.form.editors2.TableModelEditor">
<Table columnCount="2" rowCount="4">
<Column editable="true" title="id" type="java.lang.Integer"/>
<Column editable="true" title="fullname" type="java.lang.String"/>
</Table>
</Property>
<Property name="columnModel" type="javax.swing.table.TableColumnModel" editor="org.netbeans.modules.form.editors2.TableColumnModelEditor">
<TableColumnModel selectionModel="0">
<Column maxWidth="-1" minWidth="-1" prefWidth="-1" resizable="true">
<Title/>
<Editor/>
<Renderer/>
</Column>
<Column maxWidth="-1" minWidth="-1" prefWidth="-1" resizable="true">
<Title/>
<Editor/>
<Renderer/>
</Column>
</TableColumnModel>
</Property>
<Property name="tableHeader" type="javax.swing.table.JTableHeader" editor="org.netbeans.modules.form.editors2.JTableHeaderEditor">
<TableHeader reorderingAllowed="true" resizingAllowed="true"/>
</Property>
</Properties>
<Events>
<EventHandler event="mouseClicked" listener="java.awt.event.MouseListener" parameters="java.awt.event.MouseEvent" handler="jTable1MouseClicked"/>
</Events>
</Component>
</SubComponents>
</Container>
</SubComponents>
</Form>

View File

@ -0,0 +1,149 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/GUIForms/JFrame.java to edit this template
*/
package javaapplication1;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
/**
*
* @author oleg
*/
public class GuestToRoom extends javax.swing.JFrame {
private Statement stmt;
private Connection conn;
private int roomid;
/**
* Creates new form NewRoomEdit
*/
public GuestToRoom(int rid) {
initComponents();
roomid = rid;
try {
conn = DBConnection.getConnection();
stmt = conn.createStatement();
} catch (SQLException e) {
e.printStackTrace();
}
refreshTable();
setVisible(true);
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
private void refreshTable() {
try {
ResultSet rs = stmt.executeQuery("SELECT id, fullname FROM guests ORDER BY id ASC;");
DefaultTableModel model = new DefaultTableModel(new Object[]{"ID", "Full Name"}, 0){
@Override
public boolean isCellEditable(int i, int i1) {
return false;
}
};
while (rs.next()) {
model.addRow(new Object[]{rs.getInt("id"), rs.getString("fullname")});
}
jTable1.setModel(model);
} catch (SQLException e) {
e.printStackTrace();
}
}
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
jScrollPane1 = new javax.swing.JScrollPane();
jTable1 = new javax.swing.JTable();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jTable1.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
{null, null},
{null, null},
{null, null},
{null, null}
},
new String [] {
"id", "fullname"
}
) {
Class[] types = new Class [] {
java.lang.Integer.class, java.lang.String.class
};
public Class getColumnClass(int columnIndex) {
return types [columnIndex];
}
});
jTable1.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
jTable1MouseClicked(evt);
}
});
jScrollPane1.setViewportView(jTable1);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 375, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(13, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 301, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(13, Short.MAX_VALUE))
);
pack();
}// </editor-fold>//GEN-END:initComponents
private void jTable1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTable1MouseClicked
if (evt.getClickCount() == 2) { // обработка двойного клика
JTable target = (JTable)evt.getSource();
int row = target.getSelectedRow(); // получаем номер строки
Object[] rowData = new Object[target.getColumnCount()];
// получаем значения ячеек выбранной строки
for (int i = 0; i < target.getColumnCount(); i++) {
rowData[i] = target.getValueAt(row, i);
}
int guestid = (int) target.getModel().getValueAt(row, 0);
try {
stmt.executeUpdate("INSERT INTO settlement (guestid, roomid) VALUES (" + guestid + ", " + roomid + ")");
refreshTable();
} catch (SQLException ex) {
ex.printStackTrace();
}
// String fullname = (String) target.getModel().getValueAt(row, 1);
dispose();
}
}//GEN-LAST:event_jTable1MouseClicked
/**
* @param args the command line arguments
*/
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTable jTable1;
// End of variables declaration//GEN-END:variables
}

View File

@ -0,0 +1,162 @@
<?xml version="1.0" encoding="UTF-8" ?>
<Form version="1.5" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JFrameFormInfo">
<Properties>
<Property name="defaultCloseOperation" type="int" value="3"/>
</Properties>
<SyntheticProperties>
<SyntheticProperty name="formSizePolicy" type="int" value="1"/>
<SyntheticProperty name="generateCenter" type="boolean" value="false"/>
</SyntheticProperties>
<AuxValues>
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
<AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
</AuxValues>
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Component id="jScrollPane1" pref="609" max="32767" attributes="0"/>
</Group>
<Group type="102" alignment="0" attributes="0">
<EmptySpace min="-2" pref="65" max="-2" attributes="0"/>
<Component id="AddButton" min="-2" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="71" max="-2" attributes="0"/>
<Component id="UpdateButton" min="-2" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="70" max="-2" attributes="0"/>
<Component id="RefreshButton" min="-2" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="71" max="-2" attributes="0"/>
<Component id="CloseButton" min="-2" max="-2" attributes="0"/>
<EmptySpace min="0" pref="0" max="32767" attributes="0"/>
</Group>
</Group>
<EmptySpace max="-2" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Component id="jScrollPane1" min="-2" pref="302" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="27" max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="AddButton" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="UpdateButton" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="CloseButton" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="RefreshButton" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace pref="52" max="32767" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
</Layout>
<SubComponents>
<Container class="javax.swing.JScrollPane" name="jScrollPane1">
<AuxValues>
<AuxValue name="autoScrollPane" type="java.lang.Boolean" value="true"/>
</AuxValues>
<Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/>
<SubComponents>
<Component class="javax.swing.JTable" name="jTable1">
<Properties>
<Property name="model" type="javax.swing.table.TableModel" editor="org.netbeans.modules.form.editors2.TableModelEditor">
<Table columnCount="6" rowCount="0">
<Column editable="true" title="id" type="java.lang.Integer"/>
<Column editable="true" title="fullname" type="java.lang.String"/>
<Column editable="true" title="sex" type="java.lang.String"/>
<Column editable="true" title="address" type="java.lang.String"/>
<Column editable="true" title="birthdate" type="java.lang.Integer"/>
<Column editable="true" title="passport_number" type="java.lang.String"/>
</Table>
</Property>
<Property name="columnModel" type="javax.swing.table.TableColumnModel" editor="org.netbeans.modules.form.editors2.TableColumnModelEditor">
<TableColumnModel selectionModel="0">
<Column maxWidth="-1" minWidth="-1" prefWidth="-1" resizable="true">
<Title/>
<Editor/>
<Renderer/>
</Column>
<Column maxWidth="-1" minWidth="-1" prefWidth="-1" resizable="true">
<Title/>
<Editor/>
<Renderer/>
</Column>
<Column maxWidth="-1" minWidth="-1" prefWidth="-1" resizable="true">
<Title/>
<Editor/>
<Renderer/>
</Column>
<Column maxWidth="-1" minWidth="-1" prefWidth="-1" resizable="true">
<Title/>
<Editor/>
<Renderer/>
</Column>
<Column maxWidth="-1" minWidth="-1" prefWidth="-1" resizable="true">
<Title/>
<Editor/>
<Renderer/>
</Column>
<Column maxWidth="-1" minWidth="-1" prefWidth="-1" resizable="true">
<Title/>
<Editor/>
<Renderer/>
</Column>
</TableColumnModel>
</Property>
<Property name="tableHeader" type="javax.swing.table.JTableHeader" editor="org.netbeans.modules.form.editors2.JTableHeaderEditor">
<TableHeader reorderingAllowed="true" resizingAllowed="true"/>
</Property>
</Properties>
<Events>
<EventHandler event="mouseClicked" listener="java.awt.event.MouseListener" parameters="java.awt.event.MouseEvent" handler="jTable1MouseClicked"/>
</Events>
</Component>
</SubComponents>
</Container>
<Component class="javax.swing.JButton" name="AddButton">
<Properties>
<Property name="label" type="java.lang.String" value="Add"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="AddButtonActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JButton" name="UpdateButton">
<Properties>
<Property name="label" type="java.lang.String" value="Update"/>
</Properties>
<Events>
<EventHandler event="mouseClicked" listener="java.awt.event.MouseListener" parameters="java.awt.event.MouseEvent" handler="UpdateButtonMouseClicked"/>
</Events>
</Component>
<Component class="javax.swing.JButton" name="CloseButton">
<Properties>
<Property name="label" type="java.lang.String" value="Delete"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="CloseButtonActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JButton" name="RefreshButton">
<Properties>
<Property name="label" type="java.lang.String" value="Refresh"/>
</Properties>
<Events>
<EventHandler event="mouseClicked" listener="java.awt.event.MouseListener" parameters="java.awt.event.MouseEvent" handler="RefreshButtonMouseClicked"/>
</Events>
</Component>
</SubComponents>
</Form>

View File

@ -0,0 +1,337 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/GUIForms/JFrame.java to edit this template
*/
package javaapplication1;
import javax.swing.*;
import javax.swing.table.DefaultTableModel;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
/**
*
* @author oleg
*/
public class GuestsPanel extends javax.swing.JFrame {
private Statement stmt;
private Connection conn;
/**
* Creates new form NewJFrame1
*/
public GuestsPanel() {
initComponents();
try {
conn = DBConnection.getConnection();
stmt = conn.createStatement();
} catch (SQLException e) {
e.printStackTrace();
}
refreshTable();
setVisible(true);
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
jScrollPane1 = new javax.swing.JScrollPane();
jTable1 = new javax.swing.JTable();
AddButton = new javax.swing.JButton();
UpdateButton = new javax.swing.JButton();
CloseButton = new javax.swing.JButton();
RefreshButton = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jTable1.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
},
new String [] {
"id", "fullname", "sex", "address", "birthdate", "passport_number"
}
) {
Class[] types = new Class [] {
java.lang.Integer.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.Integer.class, java.lang.String.class
};
public Class getColumnClass(int columnIndex) {
return types [columnIndex];
}
});
jTable1.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
jTable1MouseClicked(evt);
}
});
jScrollPane1.setViewportView(jTable1);
AddButton.setLabel("Add");
AddButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
AddButtonActionPerformed(evt);
}
});
UpdateButton.setLabel("Update");
UpdateButton.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
UpdateButtonMouseClicked(evt);
}
});
CloseButton.setLabel("Delete");
CloseButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
CloseButtonActionPerformed(evt);
}
});
RefreshButton.setLabel("Refresh");
RefreshButton.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
RefreshButtonMouseClicked(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 609, Short.MAX_VALUE))
.addGroup(layout.createSequentialGroup()
.addGap(65, 65, 65)
.addComponent(AddButton)
.addGap(71, 71, 71)
.addComponent(UpdateButton)
.addGap(70, 70, 70)
.addComponent(RefreshButton)
.addGap(71, 71, 71)
.addComponent(CloseButton)
.addGap(0, 0, Short.MAX_VALUE)))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 302, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(27, 27, 27)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(AddButton)
.addComponent(UpdateButton)
.addComponent(CloseButton)
.addComponent(RefreshButton))
.addContainerGap(52, Short.MAX_VALUE))
);
pack();
}// </editor-fold>//GEN-END:initComponents
private void AddButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_AddButtonActionPerformed
try {
String fullname = JOptionPane.showInputDialog("Enter room Full Name:");
String sex = JOptionPane.showInputDialog("Enter Sex:");
String address = JOptionPane.showInputDialog("Enter Address:");
String datestr = JOptionPane.showInputDialog("Enter Birth Date:");
DateFormat format = new SimpleDateFormat("yyyy-mm-dd");
Date birthdate = format.parse(datestr);
String passport_Number = JOptionPane.showInputDialog("Enter Passport Number:");
stmt.executeUpdate("INSERT INTO guests (fullname, sex, address, birthdate, passport_number) VALUES ('" + fullname + "', '" + sex + "', '" + address + "', " + birthdate + ", '" + passport_Number + "')");
refreshTable();
} catch (SQLException | ParseException ex) {
ex.printStackTrace();
}
// обновление таблицы
updateTable();
refreshTable();
}//GEN-LAST:event_AddButtonActionPerformed
private void UpdateButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_UpdateButtonMouseClicked
updateTable();
}//GEN-LAST:event_UpdateButtonMouseClicked
private void refreshTable() {
try {
ResultSet rs = stmt.executeQuery("SELECT * FROM guests ORDER BY id ASC;");
DefaultTableModel model = new DefaultTableModel(new Object[]{"ID", "Full Name", "Sex", "Address", "Birthdate", "Passport Number"}, 0){
@Override
public boolean isCellEditable(int i, int i1) {
return false;
}
};
while (rs.next()) {
model.addRow(new Object[]{rs.getInt("id"), rs.getString("fullname"), rs.getString("sex"), rs.getString("address"), rs.getDate("birthdate"), rs.getString("passport_number")});
}
jTable1.setModel(model);
} catch (SQLException e) {
e.printStackTrace();
}
}
private void updateTable() {
try {
String query = "SELECT * FROM guests";
ResultSet resultSet = stmt.executeQuery(query);
// очистка модели таблицы
DefaultTableModel model = (DefaultTableModel) jTable1.getModel();
model.setRowCount(0);
// заполнение модели таблицы данными из базы данных
while (resultSet.next()) {
int id = resultSet.getInt("id");
int fullname = resultSet.getInt("fullname");
int sex = resultSet.getInt("sex");
int address = resultSet.getInt("address");
int birthdate = resultSet.getInt("birthdate");
int passport_number = resultSet.getInt("passport_number");
Object[] row = {id, fullname, sex, address, birthdate, passport_number};
model.addRow(row);
}
resultSet.close();
} catch (SQLException ex) {
ex.printStackTrace();
}
}
private void CloseButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_CloseButtonActionPerformed
int row = jTable1.getSelectedRow();
if (row >= 0) {
try {
int id = (int) jTable1.getModel().getValueAt(row, 0);
stmt.executeUpdate("DELETE FROM guests WHERE id=" + id);
refreshTable();
} catch (SQLException e) {
e.printStackTrace();
}
} else {
JOptionPane.showMessageDialog(this, "Please select a guest to delete.");
}
}//GEN-LAST:event_CloseButtonActionPerformed
private void RefreshButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_RefreshButtonMouseClicked
refreshTable();
}//GEN-LAST:event_RefreshButtonMouseClicked
private void jTable1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTable1MouseClicked
if (evt.getClickCount() == 2) { // обработка двойного клика
JTable target = (JTable)evt.getSource();
int row = target.getSelectedRow(); // получаем номер строки
Object[] rowData = new Object[target.getColumnCount()];
// получаем значения ячеек выбранной строки
for (int i = 0; i < target.getColumnCount(); i++) {
rowData[i] = target.getValueAt(row, i);
}
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
JPanel panel = new JPanel(new GridLayout(6, 2));
JTextField FullNameTextField = new JTextField();
JLabel FullNameLabel = new JLabel("Full Name: ");
FullNameTextField.setText(rowData[1].toString());
JTextField SexTextField = new JTextField();
JLabel SexLabel = new JLabel("Sex: ");
SexTextField.setText(rowData[2].toString());
JTextField AddressTextField = new JTextField();
JLabel AddressLabel = new JLabel("Address: ");
AddressTextField.setText(rowData[3].toString());
JTextField BirthdateTextField = new JTextField();
JLabel BirthdateLabel = new JLabel("Birthdate: ");
BirthdateTextField.setText(rowData[4].toString());
JTextField PassportNumberTextField = new JTextField();
JLabel PassportNumberLabel = new JLabel("Passport Number: ");
PassportNumberTextField.setText(rowData[5].toString());
panel.add(FullNameLabel);
panel.add(FullNameTextField);
panel.add(SexLabel);
panel.add(SexTextField);
panel.add(AddressLabel);
panel.add(AddressTextField);
panel.add(BirthdateLabel);
panel.add(BirthdateTextField);
panel.add(PassportNumberLabel);
panel.add(PassportNumberTextField);
JButton okButton = new JButton("Ок");
okButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
// передаем значения ячеек в модель данных таблицы
try {
int id = (int) target.getModel().getValueAt(row, 0);
target.setValueAt(FullNameTextField.getText(), row, 1);
String FullName = FullNameTextField.getText();
target.setValueAt(SexTextField.getText(), row, 2);
String Sex = SexTextField.getText();
target.setValueAt(AddressTextField.getText(), row, 3);
String Address = (AddressTextField.getText());
target.setValueAt(BirthdateTextField.getText(), row, 4);
DateFormat format = new SimpleDateFormat("yyyy-mm-dd");
String dateString = BirthdateTextField.getText();
Date Birthdate = format.parse(dateString);
target.setValueAt(PassportNumberTextField.getText(), row, 5);
String PassportNumber = (PassportNumberTextField.getText());
stmt.executeUpdate("UPDATE guests SET fullname='" + FullName + "', sex='" + Sex + "', address='" + Address + "', birthdate='" + Birthdate + "', passport_number='" + PassportNumber + "' WHERE id=" + id);
frame.dispose(); // закрываем форму
} catch (SQLException | ParseException ev) {
ev.printStackTrace();
}
}
});
panel.add(okButton);
frame.add(panel);
frame.pack();
frame.setVisible(true);
// передаем значения ячеек в модель данных таблицы
}
}//GEN-LAST:event_jTable1MouseClicked
/**
* @param args the command line arguments
*/
public String str = new String();
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton AddButton;
private javax.swing.JButton CloseButton;
private javax.swing.JButton RefreshButton;
private javax.swing.JButton UpdateButton;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTable jTable1;
// End of variables declaration//GEN-END:variables
}

View File

@ -0,0 +1,82 @@
<?xml version="1.0" encoding="UTF-8" ?>
<Form version="1.3" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JFrameFormInfo">
<NonVisualComponents>
<Menu class="javax.swing.JMenuBar" name="jMenuBar1">
<SubComponents>
<Menu class="javax.swing.JMenu" name="jMenu1">
<Properties>
<Property name="label" type="java.lang.String" value="Form1"/>
</Properties>
<Events>
<EventHandler event="mouseClicked" listener="java.awt.event.MouseListener" parameters="java.awt.event.MouseEvent" handler="jMenu1MouseClicked"/>
</Events>
</Menu>
<Menu class="javax.swing.JMenu" name="jMenu2">
<Properties>
<Property name="label" type="java.lang.String" value="Form2"/>
</Properties>
<Events>
<EventHandler event="mouseClicked" listener="java.awt.event.MouseListener" parameters="java.awt.event.MouseEvent" handler="jMenu2MouseClicked"/>
</Events>
</Menu>
<Menu class="javax.swing.JMenu" name="jMenu3">
<Properties>
<Property name="label" type="java.lang.String" value="Form3"/>
</Properties>
<Events>
<EventHandler event="mouseClicked" listener="java.awt.event.MouseListener" parameters="java.awt.event.MouseEvent" handler="jMenu3MouseClicked"/>
</Events>
</Menu>
<Menu class="javax.swing.JMenu" name="jMenu4">
<Properties>
<Property name="label" type="java.lang.String" value="Form4"/>
</Properties>
<Events>
<EventHandler event="mouseClicked" listener="java.awt.event.MouseListener" parameters="java.awt.event.MouseEvent" handler="jMenu4MouseClicked"/>
</Events>
</Menu>
<Menu class="javax.swing.JMenu" name="jMenu5">
<Properties>
<Property name="text" type="java.lang.String" value="Form5"/>
</Properties>
<Events>
<EventHandler event="mouseClicked" listener="java.awt.event.MouseListener" parameters="java.awt.event.MouseEvent" handler="jMenu5MouseClicked"/>
</Events>
</Menu>
</SubComponents>
</Menu>
</NonVisualComponents>
<Properties>
<Property name="defaultCloseOperation" type="int" value="3"/>
</Properties>
<SyntheticProperties>
<SyntheticProperty name="menuBar" type="java.lang.String" value="jMenuBar1"/>
<SyntheticProperty name="formSizePolicy" type="int" value="1"/>
<SyntheticProperty name="generateCenter" type="boolean" value="false"/>
</SyntheticProperties>
<AuxValues>
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
<AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
</AuxValues>
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<EmptySpace min="0" pref="373" max="32767" attributes="0"/>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<EmptySpace min="0" pref="277" max="32767" attributes="0"/>
</Group>
</DimensionLayout>
</Layout>
</Form>

View File

@ -0,0 +1,234 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/GUIForms/JFrame.java to edit this template
*/
package javaapplication1;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
/**
*
* @author oleg
*/
public class MainFrame extends javax.swing.JFrame {
/**
* Creates new form MainFrame
*/
public MainFrame() {
initComponents();
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
jMenuBar1 = new javax.swing.JMenuBar();
jMenu1 = new javax.swing.JMenu();
jMenu2 = new javax.swing.JMenu();
jMenu3 = new javax.swing.JMenu();
jMenu4 = new javax.swing.JMenu();
jMenu5 = new javax.swing.JMenu();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jMenu1.setLabel("Form1");
jMenu1.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
jMenu1MouseClicked(evt);
}
});
jMenuBar1.add(jMenu1);
jMenu2.setLabel("Form2");
jMenu2.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
jMenu2MouseClicked(evt);
}
});
jMenuBar1.add(jMenu2);
jMenu3.setLabel("Form3");
jMenu3.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
jMenu3MouseClicked(evt);
}
});
jMenuBar1.add(jMenu3);
jMenu4.setLabel("Form4");
jMenu4.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
jMenu4MouseClicked(evt);
}
});
jMenuBar1.add(jMenu4);
jMenu5.setText("Form5");
jMenu5.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
jMenu5MouseClicked(evt);
}
});
jMenuBar1.add(jMenu5);
setJMenuBar(jMenuBar1);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 373, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 277, Short.MAX_VALUE)
);
pack();
}// </editor-fold>//GEN-END:initComponents
private void jMenu1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jMenu1MouseClicked
RoomsPanel form1 = new RoomsPanel();
form1.setVisible(true);
form1.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
form1.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
int confirm = JOptionPane.showOptionDialog(form1,
"Close?", "Exit", JOptionPane.YES_NO_OPTION,
JOptionPane.QUESTION_MESSAGE, null, null, null);
if (confirm == JOptionPane.YES_OPTION) {
//System.exit(1);
form1.dispose();
}
}
});
}//GEN-LAST:event_jMenu1MouseClicked
private void jMenu2MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jMenu2MouseClicked
GuestsPanel form2 = new GuestsPanel();
form2.setVisible(true);
form2.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
form2.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
int confirm = JOptionPane.showOptionDialog(form2,
"Close?", "Exit", JOptionPane.YES_NO_OPTION,
JOptionPane.QUESTION_MESSAGE, null, null, null);
if (confirm == JOptionPane.YES_OPTION) {
//System.exit(1);
form2.dispose();
}
}
});
}//GEN-LAST:event_jMenu2MouseClicked
private void jMenu3MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jMenu3MouseClicked
ServicePanel form3 = new ServicePanel();
form3.setVisible(true);
form3.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
form3.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
int confirm = JOptionPane.showOptionDialog(form3,
"Close?", "Exit", JOptionPane.YES_NO_OPTION,
JOptionPane.QUESTION_MESSAGE, null, null, null);
if (confirm == JOptionPane.YES_OPTION) {
//System.exit(1);
form3.dispose();
}
}
});
}//GEN-LAST:event_jMenu3MouseClicked
private void jMenu4MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jMenu4MouseClicked
/*
GuestToRoom form4 = new GuestToRoom();
form4.setVisible(true);
form4.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
form4.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
int confirm = JOptionPane.showOptionDialog(form4,
"Close?", "Exit", JOptionPane.YES_NO_OPTION,
JOptionPane.QUESTION_MESSAGE, null, null, null);
if (confirm == JOptionPane.YES_OPTION) {
//System.exit(1);
form4.dispose();
}
}
});
*/
}//GEN-LAST:event_jMenu4MouseClicked
private void jMenu5MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jMenu5MouseClicked
SettlementPanel form5 = new SettlementPanel();
form5.setVisible(true);
form5.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
form5.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
int confirm = JOptionPane.showOptionDialog(form5,
"Close?", "Exit", JOptionPane.YES_NO_OPTION,
JOptionPane.QUESTION_MESSAGE, null, null, null);
if (confirm == JOptionPane.YES_OPTION) {
//System.exit(1);
form5.dispose();
}
}
});
}//GEN-LAST:event_jMenu5MouseClicked
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(MainFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(MainFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(MainFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(MainFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new MainFrame().setVisible(true);
}
});
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JMenu jMenu1;
private javax.swing.JMenu jMenu2;
private javax.swing.JMenu jMenu3;
private javax.swing.JMenu jMenu4;
private javax.swing.JMenu jMenu5;
private javax.swing.JMenuBar jMenuBar1;
// End of variables declaration//GEN-END:variables
}

View File

@ -0,0 +1,172 @@
<?xml version="1.0" encoding="UTF-8" ?>
<Form version="1.5" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JFrameFormInfo">
<Properties>
<Property name="defaultCloseOperation" type="int" value="3"/>
</Properties>
<SyntheticProperties>
<SyntheticProperty name="formSizePolicy" type="int" value="1"/>
<SyntheticProperty name="generateCenter" type="boolean" value="false"/>
</SyntheticProperties>
<AuxValues>
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
<AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
</AuxValues>
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" attributes="0">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Component id="jScrollPane1" pref="653" max="32767" attributes="0"/>
</Group>
<Group type="102" alignment="0" attributes="0">
<EmptySpace min="-2" pref="65" max="-2" attributes="0"/>
<Component id="AddButton" min="-2" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="71" max="-2" attributes="0"/>
<Component id="UpdateButton" min="-2" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="70" max="-2" attributes="0"/>
<Component id="RefreshButton" min="-2" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="71" max="-2" attributes="0"/>
<Component id="CloseButton" min="-2" max="-2" attributes="0"/>
<EmptySpace min="0" pref="0" max="32767" attributes="0"/>
</Group>
</Group>
<EmptySpace max="-2" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Component id="jScrollPane1" min="-2" pref="302" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="27" max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="AddButton" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="UpdateButton" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="CloseButton" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="RefreshButton" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace pref="14" max="32767" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
</Layout>
<SubComponents>
<Container class="javax.swing.JScrollPane" name="jScrollPane1">
<AuxValues>
<AuxValue name="autoScrollPane" type="java.lang.Boolean" value="true"/>
</AuxValues>
<Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/>
<SubComponents>
<Component class="javax.swing.JTable" name="jTable1">
<Properties>
<Property name="model" type="javax.swing.table.TableModel" editor="org.netbeans.modules.form.editors2.TableModelEditor">
<Table columnCount="7" rowCount="0">
<Column editable="true" title="id" type="java.lang.Integer"/>
<Column editable="true" title="room_num" type="java.lang.Integer"/>
<Column editable="true" title="floor" type="java.lang.Integer"/>
<Column editable="true" title="number_of_places" type="java.lang.Integer"/>
<Column editable="true" title="nulloccupied_places" type="java.lang.Integer"/>
<Column editable="true" title="room_price_per_day" type="java.lang.Integer"/>
<Column editable="false" title="Guest" type="java.lang.Object"/>
</Table>
</Property>
<Property name="columnModel" type="javax.swing.table.TableColumnModel" editor="org.netbeans.modules.form.editors2.TableColumnModelEditor">
<TableColumnModel selectionModel="0">
<Column maxWidth="-1" minWidth="-1" prefWidth="-1" resizable="true">
<Title/>
<Editor/>
<Renderer/>
</Column>
<Column maxWidth="-1" minWidth="-1" prefWidth="-1" resizable="true">
<Title/>
<Editor/>
<Renderer/>
</Column>
<Column maxWidth="-1" minWidth="-1" prefWidth="-1" resizable="true">
<Title/>
<Editor/>
<Renderer/>
</Column>
<Column maxWidth="-1" minWidth="-1" prefWidth="-1" resizable="true">
<Title/>
<Editor/>
<Renderer/>
</Column>
<Column maxWidth="-1" minWidth="-1" prefWidth="-1" resizable="true">
<Title/>
<Editor/>
<Renderer/>
</Column>
<Column maxWidth="-1" minWidth="-1" prefWidth="-1" resizable="true">
<Title/>
<Editor/>
<Renderer/>
</Column>
<Column maxWidth="-1" minWidth="-1" prefWidth="-1" resizable="true">
<Title/>
<Editor/>
<Renderer/>
</Column>
</TableColumnModel>
</Property>
<Property name="tableHeader" type="javax.swing.table.JTableHeader" editor="org.netbeans.modules.form.editors2.JTableHeaderEditor">
<TableHeader reorderingAllowed="true" resizingAllowed="true"/>
</Property>
</Properties>
<Events>
<EventHandler event="mouseClicked" listener="java.awt.event.MouseListener" parameters="java.awt.event.MouseEvent" handler="jTable1MouseClicked"/>
</Events>
</Component>
</SubComponents>
</Container>
<Component class="javax.swing.JButton" name="AddButton">
<Properties>
<Property name="label" type="java.lang.String" value="Add"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="AddButtonActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JButton" name="UpdateButton">
<Properties>
<Property name="label" type="java.lang.String" value="Update"/>
</Properties>
<AccessibilityProperties>
<Property name="AccessibleContext.accessibleName" type="java.lang.String" value="Edit"/>
</AccessibilityProperties>
<Events>
<EventHandler event="mouseClicked" listener="java.awt.event.MouseListener" parameters="java.awt.event.MouseEvent" handler="UpdateButtonMouseClicked"/>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="UpdateButtonActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JButton" name="CloseButton">
<Properties>
<Property name="label" type="java.lang.String" value="Delete"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="CloseButtonActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JButton" name="RefreshButton">
<Properties>
<Property name="label" type="java.lang.String" value="Refresh"/>
</Properties>
<Events>
<EventHandler event="mouseClicked" listener="java.awt.event.MouseListener" parameters="java.awt.event.MouseEvent" handler="RefreshButtonMouseClicked"/>
</Events>
</Component>
</SubComponents>
</Form>

View File

@ -0,0 +1,438 @@
package javaapplication1;
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/GUIForms/JFrame.java to edit this template
*/
import javax.swing.*;
import javax.swing.table.DefaultTableModel;
import java.awt.*;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
/**
*
* @author oleg
*/
public class RoomsPanel extends javax.swing.JFrame {
private Statement stmt;
private Connection conn;
public int nameid;
/**
* Creates new form NewJFrame
*/
public RoomsPanel() {
initComponents();
try {
conn = DBConnection.getConnection();
stmt = conn.createStatement();
} catch (SQLException e) {
e.printStackTrace();
}
JPopupMenu popupMenu = new JPopupMenu();
JMenuItem freeRoomMenuItem = new JMenuItem("Освободить комнату");
popupMenu.add(freeRoomMenuItem);
jTable1.setComponentPopupMenu(popupMenu);
freeRoomMenuItem.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent ev) {
// Получаем выбранную строку
// int selectedRow = jTable1.getSelectedRow();
// int roomId = (int) jTable1.getValueAt(selectedRow, 0);
// try {
// String sql = "DELETE FROM settlement WHERE roomid = " + roomId;
// stmt.executeUpdate(sql);
// refreshTable();
// } catch (SQLException ex) {
// ex.printStackTrace();
// }
}
});
JMenuItem populateRoomMenuItem = new JMenuItem("Заселить комнату");
popupMenu.add(populateRoomMenuItem);
jTable1.setComponentPopupMenu(popupMenu);
populateRoomMenuItem.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent ev) {
// Получаем выбранную строку
int selectedRow = jTable1.getSelectedRow();
int roomid = (int) jTable1.getValueAt(selectedRow, 0);
GuestToRoom form4 = new GuestToRoom(roomid);
form4.setVisible(true);
form4.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
/*
try {
String sql = "DELETE FROM settlement WHERE roomid = " + roomId;
stmt.executeUpdate(sql);
refreshTable();
} catch (SQLException ex) {
ex.printStackTrace();
}
*/
}
});
refreshTable();
setVisible(true);
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
jScrollPane1 = new javax.swing.JScrollPane();
jTable1 = new javax.swing.JTable();
AddButton = new javax.swing.JButton();
UpdateButton = new javax.swing.JButton();
CloseButton = new javax.swing.JButton();
RefreshButton = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jTable1.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
},
new String [] {
"id", "room_num", "floor", "number_of_places", "nulloccupied_places", "room_price_per_day", "Guest"
}
) {
Class[] types = new Class [] {
java.lang.Integer.class, java.lang.Integer.class, java.lang.Integer.class, java.lang.Integer.class, java.lang.Integer.class, java.lang.Integer.class, java.lang.Object.class
};
boolean[] canEdit = new boolean [] {
true, true, true, true, true, true, false
};
public Class getColumnClass(int columnIndex) {
return types [columnIndex];
}
public boolean isCellEditable(int rowIndex, int columnIndex) {
return canEdit [columnIndex];
}
});
jTable1.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
jTable1MouseClicked(evt);
}
});
jScrollPane1.setViewportView(jTable1);
AddButton.setLabel("Add");
AddButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
AddButtonActionPerformed(evt);
}
});
UpdateButton.setLabel("Update");
UpdateButton.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
UpdateButtonMouseClicked(evt);
}
});
UpdateButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
UpdateButtonActionPerformed(evt);
}
});
CloseButton.setLabel("Delete");
CloseButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
CloseButtonActionPerformed(evt);
}
});
RefreshButton.setLabel("Refresh");
RefreshButton.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
RefreshButtonMouseClicked(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 653, Short.MAX_VALUE))
.addGroup(layout.createSequentialGroup()
.addGap(65, 65, 65)
.addComponent(AddButton)
.addGap(71, 71, 71)
.addComponent(UpdateButton)
.addGap(70, 70, 70)
.addComponent(RefreshButton)
.addGap(71, 71, 71)
.addComponent(CloseButton)
.addGap(0, 0, Short.MAX_VALUE)))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 302, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(27, 27, 27)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(AddButton)
.addComponent(UpdateButton)
.addComponent(CloseButton)
.addComponent(RefreshButton))
.addContainerGap(14, Short.MAX_VALUE))
);
UpdateButton.getAccessibleContext().setAccessibleName("Edit");
pack();
}// </editor-fold>//GEN-END:initComponents
private void CloseButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_CloseButtonActionPerformed
int row = jTable1.getSelectedRow();
if (row >= 0) {
try {
int id = (int) jTable1.getModel().getValueAt(row, 0);
stmt.executeUpdate("DELETE FROM room WHERE id=" + id);
refreshTable();
} catch (SQLException e) {
e.printStackTrace();
}
} else {
JOptionPane.showMessageDialog(this, "Please select a room to delete.");
}
}//GEN-LAST:event_CloseButtonActionPerformed
private void AddButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_AddButtonActionPerformed
int roomNum = Integer.parseInt(JOptionPane.showInputDialog("Enter room number:"));
int floor = Integer.parseInt(JOptionPane.showInputDialog("Enter floor:"));
int numberOfPlaces = Integer.parseInt(JOptionPane.showInputDialog("Enter number of places:"));
int occupiedPlaces = Integer.parseInt(JOptionPane.showInputDialog("Enter occupied places:"));
int roomPricePerDay = Integer.parseInt(JOptionPane.showInputDialog("Enter room price per day:"));
try {
stmt.executeUpdate("INSERT INTO room (room_num, floor, number_of_places, occupied_places, room_price_per_day) VALUES (" + roomNum + ", " + floor + ", " + numberOfPlaces + ", " + occupiedPlaces + ", " + roomPricePerDay + ")");
refreshTable();
} catch (SQLException ex) {
ex.printStackTrace();
}
// обновление таблицы
updateTable();
refreshTable();
}//GEN-LAST:event_AddButtonActionPerformed
private void RefreshButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_RefreshButtonMouseClicked
refreshTable();
}//GEN-LAST:event_RefreshButtonMouseClicked
private void UpdateButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_UpdateButtonMouseClicked
updateTable();
}//GEN-LAST:event_UpdateButtonMouseClicked
private void UpdateButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_UpdateButtonActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_UpdateButtonActionPerformed
public String str = new String();
private void jTable1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTable1MouseClicked
// TODO add your handling code here:
// TODO add your handling code here:
if (evt.getClickCount() == 2) { // обработка двойного клика
JTable target = (JTable)evt.getSource();
int row = target.getSelectedRow(); // получаем номер строки
Object[] rowData = new Object[target.getColumnCount()];
// получаем значения ячеек выбранной строки
for (int i = 0; i < target.getColumnCount(); i++) {
rowData[i] = target.getValueAt(row, i);
}
// создаем отрывшуюся форму и передаем значения ячеек в текстовые поля
// NewRoomEdit editframe = new NewRoomEdit();
// editframe.setVisible(true);
// editframe.jTextField1.setText(rowData[1].toString());
// target.setValueAt(str, row, 1);
// target.setValueAt(str, row, 1);
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
JPanel panel = new JPanel(new GridLayout(6, 2));
JTextField RoomNumTextField = new JTextField();
JLabel RoomNumLabel = new JLabel("Room Number: ");
RoomNumTextField.setText(rowData[1].toString());
JTextField FloorNumTextField = new JTextField();
JLabel FloorNumLabel = new JLabel("Floor Number: ");
FloorNumTextField.setText(rowData[2].toString());
JTextField NumberOfPlacesTextField = new JTextField();
JLabel NumberOfPlacesLabel = new JLabel("NumberOfPlaces: ");
NumberOfPlacesTextField.setText(rowData[3].toString());
JTextField OccupiedPlacesTextField = new JTextField();
JLabel OccupiedPlacesLabel = new JLabel("OccupiedPlaces: ");
OccupiedPlacesTextField.setText(rowData[4].toString());
JTextField RoomPricePerDayTextField = new JTextField();
JLabel RoomPricePerDayLabel = new JLabel("RoomPricePerDay: ");
RoomPricePerDayTextField.setText(rowData[5].toString());
panel.add(RoomNumLabel);
panel.add(RoomNumTextField);
panel.add(FloorNumLabel);
panel.add(FloorNumTextField);
panel.add(NumberOfPlacesLabel);
panel.add(NumberOfPlacesTextField);
panel.add(OccupiedPlacesLabel);
panel.add(OccupiedPlacesTextField);
panel.add(RoomPricePerDayLabel);
panel.add(RoomPricePerDayTextField);
JButton okButton = new JButton("Ок");
okButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
// передаем значения ячеек в модель данных таблицы
try {
int id = (int) target.getModel().getValueAt(row, 0);
target.setValueAt(RoomNumTextField.getText(), row, 1);
int RoomNum = Integer.parseInt(RoomNumTextField.getText());
target.setValueAt(FloorNumTextField.getText(), row, 2);
int FloorNum = Integer.parseInt(FloorNumTextField.getText());
target.setValueAt(NumberOfPlacesTextField.getText(), row, 3);
int NumberOfPlaces = Integer.parseInt(NumberOfPlacesTextField.getText());
target.setValueAt(OccupiedPlacesTextField.getText(), row, 4);
int OccupiedPlaces = Integer.parseInt(OccupiedPlacesTextField.getText());
target.setValueAt(RoomPricePerDayTextField.getText(), row, 5);
int RoomPricePerDay = Integer.parseInt(RoomPricePerDayTextField.getText());
stmt.executeUpdate("UPDATE room SET room_num=" + RoomNum + ", floor=" + FloorNum + ", number_of_places=" + NumberOfPlaces + ", occupied_places=" + OccupiedPlaces + ", room_price_per_day=" + RoomPricePerDay + " WHERE id=" + id);
frame.dispose(); // закрываем форму
} catch (SQLException ev) {
ev.printStackTrace();
}
}
});
panel.add(okButton);
frame.add(panel);
frame.pack();
frame.setVisible(true);
// передаем значения ячеек в модель данных таблицы
}
}//GEN-LAST:event_jTable1MouseClicked
private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void refreshTable() {
try {
// ResultSet rs = statement.executeQuery("SELECT * FROM room ORDER BY id ASC;");
// ResultSet rs1 = statement.executeQuery();
ResultSet rs = stmt.executeQuery("SELECT room.*, CASE WHEN settlement.guestid IS NULL THEN 'free' ELSE guests.fullname END AS fullname FROM room LEFT JOIN settlement ON room.id = settlement.roomid LEFT JOIN guests ON settlement.guestid = guests.id;");
DefaultTableModel model = new DefaultTableModel(new Object[]{"ID", "Room_Number", "Floor", "Number of places", "Occupied places", "Price per day", "Guest"}, 0){
@Override
public boolean isCellEditable(int i, int i1) {
return false;
}
};
while (rs.next()) {
model.addRow(new Object[]{rs.getInt("id"), rs.getInt("room_num"), rs.getInt("floor"), rs.getInt("number_of_places"), rs.getInt("occupied_places"), rs.getInt("room_price_per_day"), rs.getString("fullname")});
}
jTable1.setModel(model);
/*
JPopupMenu popupMenu = new JPopupMenu();
JMenuItem freeRoomMenuItem = new JMenuItem("Освободить комнату");
popupMenu.add(freeRoomMenuItem);
jTable1.setComponentPopupMenu(popupMenu);
freeRoomMenuItem.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent ev) {
// Получаем выбранную строку
int selectedRow = jTable1.getSelectedRow();
int roomId = (int) jTable1.getValueAt(selectedRow, 0);
try {
Connection conn = DBConnection.getConnection();
Statement stmt = conn.createStatement();
String sql = "DELETE FROM settlement WHERE roomid = " + roomId;
stmt.executeUpdate(sql);
} catch (SQLException ex) {
ex.printStackTrace();
}
}
});
*/
} catch (SQLException e) {
e.printStackTrace();
}
}
private void updateTable() {
try {
String query = "SELECT * FROM room";
ResultSet resultSet = stmt.executeQuery(query);
// очистка модели таблицы
DefaultTableModel model = (DefaultTableModel) jTable1.getModel();
model.setRowCount(0);
// заполнение модели таблицы данными из базы данных
while (resultSet.next()) {
int id = resultSet.getInt("id");
int room_num = resultSet.getInt("room_num");
int floor = resultSet.getInt("floor");
int numberOfPlaces = resultSet.getInt("number_of_places");
int occupiedPlaces = resultSet.getInt("occupied_places");
int pricePerDay = resultSet.getInt("room_price_per_day");
Object[] row = {id, room_num, floor, numberOfPlaces, occupiedPlaces, pricePerDay};
model.addRow(row);
}
//resultSet.close();
//statement.close();
//connection.close();
} catch (SQLException ex) {
ex.printStackTrace();
}
}
/**
* @param args the command line arguments
*/
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton AddButton;
private javax.swing.JButton CloseButton;
private javax.swing.JButton RefreshButton;
private javax.swing.JButton UpdateButton;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTable jTable1;
// End of variables declaration//GEN-END:variables
}

View File

@ -0,0 +1,147 @@
<?xml version="1.0" encoding="UTF-8" ?>
<Form version="1.3" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JFrameFormInfo">
<Properties>
<Property name="defaultCloseOperation" type="int" value="3"/>
</Properties>
<SyntheticProperties>
<SyntheticProperty name="formSizePolicy" type="int" value="1"/>
<SyntheticProperty name="generateCenter" type="boolean" value="false"/>
</SyntheticProperties>
<AuxValues>
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
<AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
</AuxValues>
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Component id="jScrollPane1" max="32767" attributes="0"/>
</Group>
<Group type="102" alignment="0" attributes="0">
<EmptySpace min="-2" pref="65" max="-2" attributes="0"/>
<Component id="AddButton" min="-2" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="71" max="-2" attributes="0"/>
<Component id="UpdateButton" min="-2" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="70" max="-2" attributes="0"/>
<Component id="RefreshButton" min="-2" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="71" max="-2" attributes="0"/>
<Component id="CloseButton" min="-2" max="-2" attributes="0"/>
<EmptySpace min="0" pref="0" max="32767" attributes="0"/>
</Group>
</Group>
<EmptySpace max="-2" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Component id="jScrollPane1" min="-2" pref="302" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="27" max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="AddButton" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="UpdateButton" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="CloseButton" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="RefreshButton" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="32767" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
</Layout>
<SubComponents>
<Component class="javax.swing.JButton" name="UpdateButton">
<Properties>
<Property name="label" type="java.lang.String" value="Update"/>
</Properties>
<Events>
<EventHandler event="mouseClicked" listener="java.awt.event.MouseListener" parameters="java.awt.event.MouseEvent" handler="UpdateButtonMouseClicked"/>
</Events>
</Component>
<Component class="javax.swing.JButton" name="CloseButton">
<Properties>
<Property name="label" type="java.lang.String" value="Delete"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="CloseButtonActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JButton" name="RefreshButton">
<Properties>
<Property name="label" type="java.lang.String" value="Refresh"/>
</Properties>
<Events>
<EventHandler event="mouseClicked" listener="java.awt.event.MouseListener" parameters="java.awt.event.MouseEvent" handler="RefreshButtonMouseClicked"/>
</Events>
</Component>
<Container class="javax.swing.JScrollPane" name="jScrollPane1">
<AuxValues>
<AuxValue name="autoScrollPane" type="java.lang.Boolean" value="true"/>
</AuxValues>
<Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/>
<SubComponents>
<Component class="javax.swing.JTable" name="jTable1">
<Properties>
<Property name="model" type="javax.swing.table.TableModel" editor="org.netbeans.modules.form.editors2.TableModelEditor">
<Table columnCount="4" rowCount="0">
<Column editable="true" title="id" type="java.lang.Integer"/>
<Column editable="true" title="number_of_services" type="java.lang.Integer"/>
<Column editable="true" title="guestid" type="java.lang.Integer"/>
<Column editable="true" title="serviceid" type="java.lang.Integer"/>
</Table>
</Property>
<Property name="columnModel" type="javax.swing.table.TableColumnModel" editor="org.netbeans.modules.form.editors2.TableColumnModelEditor">
<TableColumnModel selectionModel="0">
<Column maxWidth="-1" minWidth="-1" prefWidth="-1" resizable="true">
<Title/>
<Editor/>
<Renderer/>
</Column>
<Column maxWidth="-1" minWidth="-1" prefWidth="-1" resizable="true">
<Title/>
<Editor/>
<Renderer/>
</Column>
<Column maxWidth="-1" minWidth="-1" prefWidth="-1" resizable="true">
<Title/>
<Editor/>
<Renderer/>
</Column>
<Column maxWidth="-1" minWidth="-1" prefWidth="-1" resizable="true">
<Title/>
<Editor/>
<Renderer/>
</Column>
</TableColumnModel>
</Property>
<Property name="tableHeader" type="javax.swing.table.JTableHeader" editor="org.netbeans.modules.form.editors2.JTableHeaderEditor">
<TableHeader reorderingAllowed="true" resizingAllowed="true"/>
</Property>
</Properties>
</Component>
</SubComponents>
</Container>
<Component class="javax.swing.JButton" name="AddButton">
<Properties>
<Property name="label" type="java.lang.String" value="Add"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="AddButtonActionPerformed"/>
</Events>
</Component>
</SubComponents>
</Form>

View File

@ -0,0 +1,263 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/GUIForms/JFrame.java to edit this template
*/
package javaapplication1;
import javax.swing.*;
import javax.swing.table.DefaultTableModel;
import java.awt.*;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
/**
*
* @author oleg
*/
public class ServiceListPanel extends javax.swing.JFrame {
private Statement stmt;
private Connection conn;
/**
* Creates new form ServiceListPanel
*/
public ServiceListPanel() {
initComponents();
try {
conn = DBConnection.getConnection();
stmt = conn.createStatement();
} catch (SQLException e) {
e.printStackTrace();
}
refreshTable();
setVisible(true);
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
UpdateButton = new javax.swing.JButton();
CloseButton = new javax.swing.JButton();
RefreshButton = new javax.swing.JButton();
jScrollPane1 = new javax.swing.JScrollPane();
jTable1 = new javax.swing.JTable();
AddButton = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
UpdateButton.setLabel("Update");
UpdateButton.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
UpdateButtonMouseClicked(evt);
}
});
CloseButton.setLabel("Delete");
CloseButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
CloseButtonActionPerformed(evt);
}
});
RefreshButton.setLabel("Refresh");
RefreshButton.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
RefreshButtonMouseClicked(evt);
}
});
jTable1.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
},
new String [] {
"id", "number_of_services", "guestid", "serviceid"
}
) {
Class[] types = new Class [] {
java.lang.Integer.class, java.lang.Integer.class, java.lang.Integer.class, java.lang.Integer.class
};
public Class getColumnClass(int columnIndex) {
return types [columnIndex];
}
});
jScrollPane1.setViewportView(jTable1);
AddButton.setLabel("Add");
AddButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
AddButtonActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jScrollPane1))
.addGroup(layout.createSequentialGroup()
.addGap(65, 65, 65)
.addComponent(AddButton)
.addGap(71, 71, 71)
.addComponent(UpdateButton)
.addGap(70, 70, 70)
.addComponent(RefreshButton)
.addGap(71, 71, 71)
.addComponent(CloseButton)
.addGap(0, 0, Short.MAX_VALUE)))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 302, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(27, 27, 27)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(AddButton)
.addComponent(UpdateButton)
.addComponent(CloseButton)
.addComponent(RefreshButton))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
pack();
}// </editor-fold>//GEN-END:initComponents
private void UpdateButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_UpdateButtonMouseClicked
updateTable();
}//GEN-LAST:event_UpdateButtonMouseClicked
private void refreshTable() {
try {
Connection connection = DBConnection.getConnection();
Statement statement = connection.createStatement();
ResultSet rs = statement.executeQuery("SELECT * FROM service_list ORDER BY id ASC;");
DefaultTableModel model = new DefaultTableModel(new Object[]{"ID", "number_of_services", "guestid", "serviceid"}, 0);
while (rs.next()) {
model.addRow(new Object[]{rs.getInt("id"), rs.getString("number_of_services"), rs.getInt("guestid"), rs.getInt("serviceid")});
}
jTable1.setModel(model);
} catch (SQLException e) {
e.printStackTrace();
}
}
private void updateTable() {
try {
Connection connection = DBConnection.getConnection();
String query = "SELECT * FROM service_list";
Statement statement = connection.createStatement();
ResultSet resultSet = statement.executeQuery(query);
// очистка модели таблицы
DefaultTableModel model = (DefaultTableModel) jTable1.getModel();
model.setRowCount(0);
// заполнение модели таблицы данными из базы данных
while (resultSet.next()) {
int id = resultSet.getInt("id");
int numberOfServices = resultSet.getInt("number_of_services");
int guestid = resultSet.getInt("guestid");
int serviceid = resultSet.getInt("serviceid");
Object[] row = {id, numberOfServices, guestid, serviceid};
model.addRow(row);
}
resultSet.close();
statement.close();
connection.close();
} catch (SQLException ex) {
ex.printStackTrace();
}
}
private void CloseButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_CloseButtonActionPerformed
try {
stmt.close();
conn.close();
} catch (SQLException e){
e.printStackTrace();
}
dispose(); // закрыть только эту форму
}//GEN-LAST:event_CloseButtonActionPerformed
private void RefreshButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_RefreshButtonMouseClicked
refreshTable();
}//GEN-LAST:event_RefreshButtonMouseClicked
private void AddButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_AddButtonActionPerformed
int number_of_services = Integer.parseInt(JOptionPane.showInputDialog("Enter service number:"));
int guestid = Integer.parseInt(JOptionPane.showInputDialog("Enter floor:"));
int serviceid = Integer.parseInt(JOptionPane.showInputDialog("Enter floor:"));
try {
stmt.executeUpdate("INSERT INTO service_list (service_name, service_price) VALUES (" + number_of_services + ", " + guestid + ", " + serviceid + ")");
refreshTable();
} catch (SQLException ex) {
ex.printStackTrace();
}
// обновление таблицы
updateTable();
refreshTable();
}//GEN-LAST:event_AddButtonActionPerformed
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(ServiceListPanel.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(ServiceListPanel.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(ServiceListPanel.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(ServiceListPanel.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new ServiceListPanel().setVisible(true);
}
});
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton AddButton;
private javax.swing.JButton CloseButton;
private javax.swing.JButton RefreshButton;
private javax.swing.JButton UpdateButton;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTable jTable1;
// End of variables declaration//GEN-END:variables
}

View File

@ -0,0 +1,144 @@
<?xml version="1.0" encoding="UTF-8" ?>
<Form version="1.5" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JFrameFormInfo">
<Properties>
<Property name="defaultCloseOperation" type="int" value="3"/>
</Properties>
<SyntheticProperties>
<SyntheticProperty name="formSizePolicy" type="int" value="1"/>
<SyntheticProperty name="generateCenter" type="boolean" value="false"/>
</SyntheticProperties>
<AuxValues>
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
<AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
</AuxValues>
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Component id="jScrollPane1" max="32767" attributes="0"/>
</Group>
<Group type="102" alignment="0" attributes="0">
<EmptySpace min="-2" pref="65" max="-2" attributes="0"/>
<Component id="AddButton" min="-2" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="71" max="-2" attributes="0"/>
<Component id="UpdateButton" min="-2" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="70" max="-2" attributes="0"/>
<Component id="RefreshButton" min="-2" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="71" max="-2" attributes="0"/>
<Component id="CloseButton" min="-2" max="-2" attributes="0"/>
<EmptySpace min="0" pref="0" max="32767" attributes="0"/>
</Group>
</Group>
<EmptySpace max="-2" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Component id="jScrollPane1" min="-2" pref="302" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="27" max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="AddButton" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="UpdateButton" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="CloseButton" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="RefreshButton" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="32767" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
</Layout>
<SubComponents>
<Container class="javax.swing.JScrollPane" name="jScrollPane1">
<AuxValues>
<AuxValue name="autoScrollPane" type="java.lang.Boolean" value="true"/>
</AuxValues>
<Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/>
<SubComponents>
<Component class="javax.swing.JTable" name="jTable1">
<Properties>
<Property name="model" type="javax.swing.table.TableModel" editor="org.netbeans.modules.form.editors2.TableModelEditor">
<Table columnCount="3" rowCount="0">
<Column editable="true" title="id" type="java.lang.Integer"/>
<Column editable="true" title="service_name" type="java.lang.String"/>
<Column editable="true" title="service_price" type="java.lang.Integer"/>
</Table>
</Property>
<Property name="columnModel" type="javax.swing.table.TableColumnModel" editor="org.netbeans.modules.form.editors2.TableColumnModelEditor">
<TableColumnModel selectionModel="0">
<Column maxWidth="-1" minWidth="-1" prefWidth="-1" resizable="true">
<Title/>
<Editor/>
<Renderer/>
</Column>
<Column maxWidth="-1" minWidth="-1" prefWidth="-1" resizable="true">
<Title/>
<Editor/>
<Renderer/>
</Column>
<Column maxWidth="-1" minWidth="-1" prefWidth="-1" resizable="true">
<Title/>
<Editor/>
<Renderer/>
</Column>
</TableColumnModel>
</Property>
<Property name="tableHeader" type="javax.swing.table.JTableHeader" editor="org.netbeans.modules.form.editors2.JTableHeaderEditor">
<TableHeader reorderingAllowed="true" resizingAllowed="true"/>
</Property>
</Properties>
<Events>
<EventHandler event="mouseClicked" listener="java.awt.event.MouseListener" parameters="java.awt.event.MouseEvent" handler="jTable1MouseClicked"/>
</Events>
</Component>
</SubComponents>
</Container>
<Component class="javax.swing.JButton" name="AddButton">
<Properties>
<Property name="label" type="java.lang.String" value="Add"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="AddButtonActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JButton" name="UpdateButton">
<Properties>
<Property name="label" type="java.lang.String" value="Update"/>
</Properties>
<Events>
<EventHandler event="mouseClicked" listener="java.awt.event.MouseListener" parameters="java.awt.event.MouseEvent" handler="UpdateButtonMouseClicked"/>
</Events>
</Component>
<Component class="javax.swing.JButton" name="CloseButton">
<Properties>
<Property name="label" type="java.lang.String" value="Delete"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="CloseButtonActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JButton" name="RefreshButton">
<Properties>
<Property name="label" type="java.lang.String" value="Refresh"/>
</Properties>
<Events>
<EventHandler event="mouseClicked" listener="java.awt.event.MouseListener" parameters="java.awt.event.MouseEvent" handler="RefreshButtonMouseClicked"/>
</Events>
</Component>
</SubComponents>
</Form>

View File

@ -0,0 +1,347 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/GUIForms/JFrame.java to edit this template
*/
package javaapplication1;
import javax.swing.*;
import javax.swing.table.DefaultTableModel;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
/**
*
* @author oleg
*/
public class ServicePanel extends javax.swing.JFrame {
private Statement stmt;
private Connection conn;
/**
* Creates new form ServicePaanel
*/
public ServicePanel() {
initComponents();
try {
conn = DBConnection.getConnection();
stmt = conn.createStatement();
} catch (SQLException e) {
e.printStackTrace();
}
refreshTable();
setVisible(true);
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
jScrollPane1 = new javax.swing.JScrollPane();
jTable1 = new javax.swing.JTable();
AddButton = new javax.swing.JButton();
UpdateButton = new javax.swing.JButton();
CloseButton = new javax.swing.JButton();
RefreshButton = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jTable1.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
},
new String [] {
"id", "service_name", "service_price"
}
) {
Class[] types = new Class [] {
java.lang.Integer.class, java.lang.String.class, java.lang.Integer.class
};
public Class getColumnClass(int columnIndex) {
return types [columnIndex];
}
});
jTable1.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
jTable1MouseClicked(evt);
}
});
jScrollPane1.setViewportView(jTable1);
AddButton.setLabel("Add");
AddButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
AddButtonActionPerformed(evt);
}
});
UpdateButton.setLabel("Update");
UpdateButton.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
UpdateButtonMouseClicked(evt);
}
});
CloseButton.setLabel("Delete");
CloseButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
CloseButtonActionPerformed(evt);
}
});
RefreshButton.setLabel("Refresh");
RefreshButton.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
RefreshButtonMouseClicked(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jScrollPane1))
.addGroup(layout.createSequentialGroup()
.addGap(65, 65, 65)
.addComponent(AddButton)
.addGap(71, 71, 71)
.addComponent(UpdateButton)
.addGap(70, 70, 70)
.addComponent(RefreshButton)
.addGap(71, 71, 71)
.addComponent(CloseButton)
.addGap(0, 0, Short.MAX_VALUE)))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 302, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(27, 27, 27)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(AddButton)
.addComponent(UpdateButton)
.addComponent(CloseButton)
.addComponent(RefreshButton))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
pack();
}// </editor-fold>//GEN-END:initComponents
private void AddButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_AddButtonActionPerformed
char service_name = (char) Integer.parseInt(JOptionPane.showInputDialog("Enter room number:"));
int service_price = Integer.parseInt(JOptionPane.showInputDialog("Enter floor:"));
try {
stmt.executeUpdate("INSERT INTO service (service_name, service_price) VALUES (" + service_name + ", " + service_price + ")");
refreshTable();
} catch (SQLException ex) {
ex.printStackTrace();
}
// обновление таблицы
updateTable();
refreshTable();
}//GEN-LAST:event_AddButtonActionPerformed
private void UpdateButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_UpdateButtonMouseClicked
updateTable();
}//GEN-LAST:event_UpdateButtonMouseClicked
private void refreshTable() {
try {
Connection connection = DBConnection.getConnection();
Statement statement = connection.createStatement();
ResultSet rs = statement.executeQuery("SELECT * FROM service ORDER BY id ASC;");
DefaultTableModel model = new DefaultTableModel(new Object[]{"ID", "Service_Name", "Service_Price"}, 0){
@Override
public boolean isCellEditable(int i, int i1) {
return false;
}
};
while (rs.next()) {
model.addRow(new Object[]{rs.getInt("id"), rs.getString("service_name"), rs.getInt("service_price")});
}
jTable1.setModel(model);
} catch (SQLException e) {
e.printStackTrace();
}
}
private void updateTable() {
try {
Connection connection = DBConnection.getConnection();
String query = "SELECT * FROM service";
Statement statement = connection.createStatement();
ResultSet resultSet = statement.executeQuery(query);
// очистка модели таблицы
DefaultTableModel model = (DefaultTableModel) jTable1.getModel();
model.setRowCount(0);
// заполнение модели таблицы данными из базы данных
while (resultSet.next()) {
int id = resultSet.getInt("id");
int servicename = resultSet.getInt("servicename");
int serviceprice = resultSet.getInt("serviceprice");
Object[] row = {id, servicename, serviceprice};
model.addRow(row);
}
resultSet.close();
statement.close();
connection.close();
} catch (SQLException ex) {
ex.printStackTrace();
}
}
private void CloseButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_CloseButtonActionPerformed
int row = jTable1.getSelectedRow();
if (row >= 0) {
try {
int id = (int) jTable1.getModel().getValueAt(row, 0);
stmt.executeUpdate("DELETE FROM service WHERE id=" + id);
refreshTable();
} catch (SQLException e) {
e.printStackTrace();
}
} else {
JOptionPane.showMessageDialog(this, "Please select a service to delete.");
}
}//GEN-LAST:event_CloseButtonActionPerformed
private void RefreshButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_RefreshButtonMouseClicked
refreshTable();
}//GEN-LAST:event_RefreshButtonMouseClicked
private void jTable1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTable1MouseClicked
// TODO add your handling code here:
// TODO add your handling code here:
if (evt.getClickCount() == 2) { // обработка двойного клика
JTable target = (JTable)evt.getSource();
int row = target.getSelectedRow(); // получаем номер строки
Object[] rowData = new Object[target.getColumnCount()];
// получаем значения ячеек выбранной строки
for (int i = 0; i < target.getColumnCount(); i++) {
rowData[i] = target.getValueAt(row, i);
}
// создаем отрывшуюся форму и передаем значения ячеек в текстовые поля
// NewRoomEdit editframe = new NewRoomEdit();
// editframe.setVisible(true);
// editframe.jTextField1.setText(rowData[1].toString());
// target.setValueAt(str, row, 1);
// target.setValueAt(str, row, 1);
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
JPanel panel = new JPanel(new GridLayout(6, 2));
JTextField ServiceNameTextField = new JTextField();
JLabel ServiceNameLabel = new JLabel("Service Name: ");
ServiceNameTextField.setText(rowData[1].toString());
JTextField ServicePriceTextField = new JTextField();
JLabel ServicePriceLabel = new JLabel("Service Price: ");
ServicePriceTextField.setText(rowData[2].toString());
panel.add(ServiceNameLabel);
panel.add(ServiceNameTextField);
panel.add(ServicePriceLabel);
panel.add(ServicePriceTextField);
JButton okButton = new JButton("Ок");
okButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
// передаем значения ячеек в модель данных таблицы
try {
int id = (int) target.getModel().getValueAt(row, 0);
target.setValueAt(ServiceNameTextField.getText(), row, 1);
String ServiceName =(ServiceNameTextField.getText());
target.setValueAt(ServicePriceTextField.getText(), row, 2);
int ServicePrice = Integer.parseInt(ServicePriceTextField.getText());
stmt.executeUpdate("UPDATE service SET service_name= '" + ServiceName + "', service_price=" + ServicePrice + " WHERE id=" + id);
frame.dispose(); // закрываем форму
} catch (SQLException ev) {
ev.printStackTrace();
}
}
});
panel.add(okButton);
frame.add(panel);
frame.pack();
frame.setVisible(true);
// передаем значения ячеек в модель данных таблицы
}
}//GEN-LAST:event_jTable1MouseClicked
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(ServicePanel.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(ServicePanel.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(ServicePanel.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(ServicePanel.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new ServicePanel().setVisible(true);
}
});
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton AddButton;
private javax.swing.JButton CloseButton;
private javax.swing.JButton RefreshButton;
private javax.swing.JButton UpdateButton;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTable jTable1;
// End of variables declaration//GEN-END:variables
}

View File

@ -0,0 +1,153 @@
<?xml version="1.0" encoding="UTF-8" ?>
<Form version="1.3" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JFrameFormInfo">
<Properties>
<Property name="defaultCloseOperation" type="int" value="3"/>
</Properties>
<SyntheticProperties>
<SyntheticProperty name="formSizePolicy" type="int" value="1"/>
<SyntheticProperty name="generateCenter" type="boolean" value="false"/>
</SyntheticProperties>
<AuxValues>
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
<AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
</AuxValues>
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Component id="jScrollPane1" max="32767" attributes="0"/>
</Group>
<Group type="102" alignment="0" attributes="0">
<EmptySpace min="-2" pref="65" max="-2" attributes="0"/>
<Component id="AddButton" min="-2" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="71" max="-2" attributes="0"/>
<Component id="UpdateButton" min="-2" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="70" max="-2" attributes="0"/>
<Component id="RefreshButton" min="-2" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="71" max="-2" attributes="0"/>
<Component id="CloseButton" min="-2" max="-2" attributes="0"/>
<EmptySpace min="0" pref="0" max="32767" attributes="0"/>
</Group>
</Group>
<EmptySpace max="-2" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Component id="jScrollPane1" min="-2" pref="302" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="27" max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="AddButton" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="UpdateButton" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="CloseButton" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="RefreshButton" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="32767" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
</Layout>
<SubComponents>
<Component class="javax.swing.JButton" name="UpdateButton">
<Properties>
<Property name="label" type="java.lang.String" value="Update"/>
</Properties>
<Events>
<EventHandler event="mouseClicked" listener="java.awt.event.MouseListener" parameters="java.awt.event.MouseEvent" handler="UpdateButtonMouseClicked"/>
</Events>
</Component>
<Component class="javax.swing.JButton" name="CloseButton">
<Properties>
<Property name="label" type="java.lang.String" value="Delete"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="CloseButtonActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JButton" name="RefreshButton">
<Properties>
<Property name="label" type="java.lang.String" value="Refresh"/>
</Properties>
<Events>
<EventHandler event="mouseClicked" listener="java.awt.event.MouseListener" parameters="java.awt.event.MouseEvent" handler="RefreshButtonMouseClicked"/>
</Events>
</Component>
<Container class="javax.swing.JScrollPane" name="jScrollPane1">
<AuxValues>
<AuxValue name="autoScrollPane" type="java.lang.Boolean" value="true"/>
</AuxValues>
<Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/>
<SubComponents>
<Component class="javax.swing.JTable" name="jTable1">
<Properties>
<Property name="model" type="javax.swing.table.TableModel" editor="org.netbeans.modules.form.editors2.TableModelEditor">
<Table columnCount="5" rowCount="0">
<Column editable="true" title="id" type="java.lang.Integer"/>
<Column editable="true" title="guestid" type="java.lang.Integer"/>
<Column editable="true" title="roomid" type="java.lang.Integer"/>
<Column editable="true" title="date_in" type="java.lang.Integer"/>
<Column editable="true" title="date_out" type="java.lang.Integer"/>
</Table>
</Property>
<Property name="columnModel" type="javax.swing.table.TableColumnModel" editor="org.netbeans.modules.form.editors2.TableColumnModelEditor">
<TableColumnModel selectionModel="0">
<Column maxWidth="-1" minWidth="-1" prefWidth="-1" resizable="true">
<Title/>
<Editor/>
<Renderer/>
</Column>
<Column maxWidth="-1" minWidth="-1" prefWidth="-1" resizable="true">
<Title/>
<Editor/>
<Renderer/>
</Column>
<Column maxWidth="-1" minWidth="-1" prefWidth="-1" resizable="true">
<Title/>
<Editor/>
<Renderer/>
</Column>
<Column maxWidth="-1" minWidth="-1" prefWidth="-1" resizable="true">
<Title/>
<Editor/>
<Renderer/>
</Column>
<Column maxWidth="-1" minWidth="-1" prefWidth="-1" resizable="true">
<Title/>
<Editor/>
<Renderer/>
</Column>
</TableColumnModel>
</Property>
<Property name="tableHeader" type="javax.swing.table.JTableHeader" editor="org.netbeans.modules.form.editors2.JTableHeaderEditor">
<TableHeader reorderingAllowed="true" resizingAllowed="true"/>
</Property>
</Properties>
</Component>
</SubComponents>
</Container>
<Component class="javax.swing.JButton" name="AddButton">
<Properties>
<Property name="label" type="java.lang.String" value="Add"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="AddButtonActionPerformed"/>
</Events>
</Component>
</SubComponents>
</Form>

View File

@ -0,0 +1,265 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/GUIForms/JFrame.java to edit this template
*/
package javaapplication1;
import javax.swing.*;
import javax.swing.table.DefaultTableModel;
import java.awt.*;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
/**
*
* @author oleg
*/
public class SettlementPanel extends javax.swing.JFrame {
private Statement stmt;
private Connection conn;
/**
* Creates new form SettlementPanel
*/
public SettlementPanel() {
initComponents();
try {
conn = DBConnection.getConnection();
stmt = conn.createStatement();
} catch (SQLException e) {
e.printStackTrace();
}
refreshTable();
setVisible(true);
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
UpdateButton = new javax.swing.JButton();
CloseButton = new javax.swing.JButton();
RefreshButton = new javax.swing.JButton();
jScrollPane1 = new javax.swing.JScrollPane();
jTable1 = new javax.swing.JTable();
AddButton = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
UpdateButton.setLabel("Update");
UpdateButton.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
UpdateButtonMouseClicked(evt);
}
});
CloseButton.setLabel("Delete");
CloseButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
CloseButtonActionPerformed(evt);
}
});
RefreshButton.setLabel("Refresh");
RefreshButton.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
RefreshButtonMouseClicked(evt);
}
});
jTable1.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
},
new String [] {
"id", "guestid", "roomid", "date_in", "date_out"
}
) {
Class[] types = new Class [] {
java.lang.Integer.class, java.lang.Integer.class, java.lang.Integer.class, java.lang.Integer.class, java.lang.Integer.class
};
public Class getColumnClass(int columnIndex) {
return types [columnIndex];
}
});
jScrollPane1.setViewportView(jTable1);
AddButton.setLabel("Add");
AddButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
AddButtonActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jScrollPane1))
.addGroup(layout.createSequentialGroup()
.addGap(65, 65, 65)
.addComponent(AddButton)
.addGap(71, 71, 71)
.addComponent(UpdateButton)
.addGap(70, 70, 70)
.addComponent(RefreshButton)
.addGap(71, 71, 71)
.addComponent(CloseButton)
.addGap(0, 0, Short.MAX_VALUE)))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 302, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(27, 27, 27)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(AddButton)
.addComponent(UpdateButton)
.addComponent(CloseButton)
.addComponent(RefreshButton))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
pack();
}// </editor-fold>//GEN-END:initComponents
private void UpdateButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_UpdateButtonMouseClicked
updateTable();
}//GEN-LAST:event_UpdateButtonMouseClicked
private void refreshTable() {
try {
Connection connection = DBConnection.getConnection();
Statement statement = connection.createStatement();
ResultSet rs = statement.executeQuery("SELECT * FROM settlement ORDER BY id ASC;");
DefaultTableModel model = new DefaultTableModel(new Object[]{"ID", "guestid", "room_id", "date_in", "dateout"}, 0);
while (rs.next()) {
model.addRow(new Object[]{rs.getInt("id"), rs.getInt("guestid"), rs.getInt("roomid"), rs.getDate("date_in"), rs.getDate("date_out")});
}
jTable1.setModel(model);
} catch (SQLException e) {
e.printStackTrace();
}
}
private void updateTable() {
try {
Connection connection = DBConnection.getConnection();
String query = "SELECT * settlement";
Statement statement = connection.createStatement();
ResultSet resultSet = statement.executeQuery(query);
// очистка модели таблицы
DefaultTableModel model = (DefaultTableModel) jTable1.getModel();
model.setRowCount(0);
// заполнение модели таблицы данными из базы данных
while (resultSet.next()) {
int id = resultSet.getInt("id");
int guestid = resultSet.getInt("guestid");
int roomid = resultSet.getInt("roomid");
int datein = resultSet.getInt("date_in");
int dateout = resultSet.getInt("date_out");
Object[] row = {id, guestid, roomid, datein, dateout};
model.addRow(row);
}
resultSet.close();
statement.close();
connection.close();
} catch (SQLException ex) {
ex.printStackTrace();
}
}
private void CloseButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_CloseButtonActionPerformed
try {
stmt.close();
conn.close();
} catch (SQLException e){
e.printStackTrace();
}
dispose(); // закрыть только эту форму
}//GEN-LAST:event_CloseButtonActionPerformed
private void RefreshButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_RefreshButtonMouseClicked
refreshTable();
}//GEN-LAST:event_RefreshButtonMouseClicked
private void AddButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_AddButtonActionPerformed
int guestid = Integer.parseInt(JOptionPane.showInputDialog("Enter service number:"));
int roomid = Integer.parseInt(JOptionPane.showInputDialog("Enter floor:"));
int datein = Integer.parseInt(JOptionPane.showInputDialog("Enter floor:"));
int dateout = Integer.parseInt(JOptionPane.showInputDialog("Enter floor:"));
try {
stmt.executeUpdate("INSERT INTO settlement (guestid, roomid, date_in, date_out) VALUES (" + guestid + ", " + roomid + ", " + datein + ", " + dateout + ")");
refreshTable();
} catch (SQLException ex) {
ex.printStackTrace();
}
// обновление таблицы
updateTable();
refreshTable();
}//GEN-LAST:event_AddButtonActionPerformed
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(SettlementPanel.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(SettlementPanel.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(SettlementPanel.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(SettlementPanel.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new SettlementPanel().setVisible(true);
}
});
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton AddButton;
private javax.swing.JButton CloseButton;
private javax.swing.JButton RefreshButton;
private javax.swing.JButton UpdateButton;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTable jTable1;
// End of variables declaration//GEN-END:variables
}

Binary file not shown.