Π‘ΠΏΠΈΡΠΎΠΊ ΠΈΡΠΏΠΎΠ»ΡΠ·ΠΎΠ²Π°Π½Π½ΡΡ ΠΈΡΡΠΎΡΠ½ΠΈΠΊΠΎΠ²
TeachersTableModel ttm = new TeachersTableModel (new String{" Π€ΠΠ ΡΡΠΈΡΠ΅Π»Ρ", «ΠΡΠ΅Π΄ΠΌΠ΅Ρ», «ΠΠ΅Π΄Π΅Π»ΡΠ½Π°Ρ Π½Π°Π³ΡΡΠ·ΠΊΠ°» }); PupilsTimeTableModel pttm = new PupilsTimeTableModel (new String{" ΠΠ»Π°ΡΡ", «Π£ΡΠΎΠΊ», «ΠΠΎΠ½Π΅Π΄Π΅Π»ΡΠ½ΠΈΠΊ», «ΠΡΠΎΡΠ½ΠΈΠΊ» ,. Π ΠΈΡΡΠ½ΠΎΠΊ Π.3 — «ΠΠ΅ΠΊΠΎΠΌΠΏΠΎΠ·ΠΈΡΠΈΡ Π±Π»ΠΎΠΊΠ° Π‘ΠΎΡΡΠ°Π²ΠΈΡΡ ΡΠ°ΡΠΏΠΈΡΠ°Π½ΠΈΠ΅ Π΄Π»Ρ ΡΡΠΈΡΠ΅Π»Π΅ΠΉ». Π ΠΈΡΡΠ½ΠΎΠΊ Π.4 — «ΠΠ΅ΠΊΠΎΠΌΠΏΠΎΠ·ΠΈΡΠΈΡ Π±Π»ΠΎΠΊΠ° ΠΡΠΎΠ²Π΅ΡΠΈΡΡ ΠΏΡΠ°Π²ΠΈΠ»ΡΠ½ΠΎΡΡΡ». Public void Connect () throws IOException… Π§ΠΈΡΠ°ΡΡ Π΅ΡΡ >
Π‘ΠΏΠΈΡΠΎΠΊ ΠΈΡΠΏΠΎΠ»ΡΠ·ΠΎΠ²Π°Π½Π½ΡΡ ΠΈΡΡΠΎΡΠ½ΠΈΠΊΠΎΠ² (ΡΠ΅ΡΠ΅ΡΠ°Ρ, ΠΊΡΡΡΠΎΠ²Π°Ρ, Π΄ΠΈΠΏΠ»ΠΎΠΌ, ΠΊΠΎΠ½ΡΡΠΎΠ»ΡΠ½Π°Ρ)
1. Java. ΠΠ΅ΡΠΎΠ΄Ρ ΠΏΡΠΎΠ³ΡΠ°ΠΌΠΌΠΈΡΠΎΠ²Π°Π½ΠΈΡ. ΠΠ»ΠΈΠ½ΠΎΠ² Π. Π., Π ΠΎΠΌΠ°Π½ΡΠΈΠΊ Π. Π‘. — ΠΠΈΠ½ΡΠΊ: ΠΠ·Π΄Π°ΡΠ΅Π»ΡΡΡΠ²ΠΎ «Π§Π΅ΡΡΡΠ΅ ΡΠ΅ΡΠ²Π΅ΡΡΠΈ», 2013.
ΠΠ ΠΠΠΠΠΠΠΠ―
ΠΡΠΈΠ»ΠΎΠΆΠ΅Π½ΠΈΠ΅ Π
(ΠΎΠ±ΡΠ·Π°ΡΠ΅Π»ΡΠ½ΠΎΠ΅)
Π€ΡΠ½ΠΊΡΠΈΠΎΠ½Π°Π»ΡΠ½Π°Ρ ΠΌΠΎΠ΄Π΅Π»Ρ ΡΠ°Π·ΡΠ°Π±ΠΎΡΠΊΠΈ ΡΠ°ΡΠΏΠΈΡΠ°Π½ΠΈΡ Π·Π°Π½ΡΡΠΈΠΉ
Π ΠΈΡΡΠ½ΠΎΠΊ Π.1 — «ΠΠΎΠ½ΡΠ΅ΠΊΡΡΠ½Π°Ρ Π΄ΠΈΠ°Π³ΡΠ°ΠΌΠΌΠ°».
Π ΠΈΡΡΠ½ΠΎΠΊ Π.2 — «ΠΠ΅ΠΊΠΎΠΌΠΏΠΎΠ·ΠΈΡΠΈΡ ΠΊΠΎΠ½ΡΠ΅ΠΊΡΡΠ½ΠΎΠΉ Π΄ΠΈΠ°Π³ΡΠ°ΠΌΠΌΡ».
ΠΡΠΎΠ΄ΠΎΠ»ΠΆΠ΅Π½ΠΈΠ΅ ΠΏΡΠΈΠ»ΠΎΠΆΠ΅Π½ΠΈΡ Π.
Π ΠΈΡΡΠ½ΠΎΠΊ Π.3 — «ΠΠ΅ΠΊΠΎΠΌΠΏΠΎΠ·ΠΈΡΠΈΡ Π±Π»ΠΎΠΊΠ° Π‘ΠΎΡΡΠ°Π²ΠΈΡΡ ΡΠ°ΡΠΏΠΈΡΠ°Π½ΠΈΠ΅ Π΄Π»Ρ ΡΡΠΈΡΠ΅Π»Π΅ΠΉ».
Π ΠΈΡΡΠ½ΠΎΠΊ Π.4 — «ΠΠ΅ΠΊΠΎΠΌΠΏΠΎΠ·ΠΈΡΠΈΡ Π±Π»ΠΎΠΊΠ° ΠΡΠΎΠ²Π΅ΡΠΈΡΡ ΠΏΡΠ°Π²ΠΈΠ»ΡΠ½ΠΎΡΡΡ».
ΠΡΠΈΠ»ΠΎΠΆΠ΅Π½ΠΈΠ΅ Π
ΠΠΈΡΡΠΈΠ½Π³ ΠΊΠΎΠ΄Π° ΠΊΠ»ΡΡΠ΅Π²ΡΡ ΠΊΠ»Π°ΡΡΠΎΠ²
public class ClientConnector {.
//static ServerSocket variable.
private static ServerSocket server;
//socket server port on which it will listen.
// private static int port;
public ClientConnector () throws IOException {.
/**.
* Reading info about port from file*/.
BufferedReader fis = new BufferedReader (new InputStreamReader (new FileInputStream («port.txt»)));
String line = fis. readLine ();
fis.close ();
server = new ServerSocket (Integer.parseInt (line));
}.
public void Connect () throws IOException, ClassNotFoundException, InterruptedException, SQLException {.
while (true){.
System.out.println («Waiting for client request…»);
//creating socket and waiting for client connection.
Socket socket = server. accept ();
//read from socket to ObjectInputStream object.
ObjectInputStream ois = new ObjectInputStream (socket.getInputStream ());
ObjectOutputStream oos = new ObjectOutputStream (socket.getOutputStream ());
oos.writeObject («Server connected»);
while (true){.
String str = (String) ois. readObject ();
if (str.equals («sending school»)) {.
System.out.println (str);
School school;
school = (School) ois. readObject ();
ObjectOutputStream out = new ObjectOutputStream (new FileOutputStream («school.txt»));
out.writeObject (school);
}.
if (str.equals («send call table»)) {.
System.out.println (str);
CallTableModel ctm = new CallTableModel (new String[]{" Π£ΡΠΎΠΊ", «ΠΠ°ΡΠ°Π»ΠΎ», «ΠΠΎΠ½Π΅Ρ» });
CallTableOperation cto = new CallTableOperation ();
ctm = cto. initRows (ctm);
oos.writeObject (ctm);
}.
if (str.equals («Client connected»)).
System.out.println (str);
if (str.equals («update call table»)).
{.
System.out.println (str);
CallTableModel ctm;
ctm = (CallTableModel) ois. readObject ().
CallTableOperation cto = new CallTableOperation ();
cto.update (ctm);
}.
if (str.equals («send teachers table»)){.
System.out.println (str);
TeachersTableModel ttm = new TeachersTableModel (new String[]{" Π€ΠΠ ΡΡΠΈΡΠ΅Π»Ρ", «ΠΡΠ΅Π΄ΠΌΠ΅Ρ», «ΠΠ΅Π΄Π΅Π»ΡΠ½Π°Ρ Π½Π°Π³ΡΡΠ·ΠΊΠ°» });
TeachersTableOperation tto = new TeachersTableOperation ();
ttm = tto. initRows (ttm);
oos.writeObject (ttm);
}.
if (str.equals («update teachers table»)).
{.
System.out.println (str);
TeachersTableModel ttm;
ttm = (TeachersTableModel) ois. readObject ();
TeachersTableOperation tto = new TeachersTableOperation ();
tto.update (ttm);
}.
if (str.equals («send classes table»)){.
System.out.println (str);
ClassesTableModel ctm = new ClassesTableModel (new String[]{" ΠΠ°ΡΠ°Π»Π»Π΅Π»Ρ", «ΠΡΠΊΠ²Π°» });
ClassesTableOperation cto = new ClassesTableOperation ();
ctm = cto. init (ctm);
oos.writeObject (ctm);
}.
if (str.equals («update classes table»)).
{.
System.out.println (str);
ClassesTableModel ctm;
ctm = (ClassesTableModel) ois. readObject ();
ClassesTableOperation cto = new ClassesTableOperation ();
cto.update (ctm);
}.
if (str.equals («exit»)){.
break;
}.
if (str.equals («send school»)) {.
System.out.println (str);
ObjectInputStream in = new ObjectInputStream (new FileInputStream («school.txt»));
School school = (School)in.readObject ();
oos.writeObject (school);
}.
if (str.equals («sending teacherstimetable»)) {.
System.out.println (str);
TeachersTimeTableModel tttm;
TeachersTimeTableOperation ttto = new TeachersTimeTableOperation ();
tttm = (TeachersTimeTableModel) ois. readObject ();
ttto.update (tttm);
}.
if (str.equals («send teacherstimetable»)) {.
System.out.println (str);
TeachersTimeTableModel tttm = new TeachersTimeTableModel (new String[]{" Π£ΡΠΈΡΠ΅Π»Ρ", «ΠΡΠ΅ΠΌΡ», «ΠΠΎΠ½Π΅Π΄Π΅Π»ΡΠ½ΠΈΠΊ», «ΠΡΠΎΡΠ½ΠΈΠΊ» ,.
Π‘ΡΠ΅Π΄Π°", «Π§Π΅ΡΠ²Π΅ΡΠ³», «ΠΡΡΠ½ΠΈΡΠ°», «Π‘ΡΠ±Π±ΠΎΡΠ°» });
TeachersTimeTableOperation ttto = new TeachersTimeTableOperation ();
tttm = ttto. init (tttm);
oos.writeObject (tttm);
}.
ois.close ();
oos.close ();
socket.close ();
public class MySQLConnector {.
private static final String URL = «jdbc:mysql://localhost:3306/timetable» ;
private static final String USERNAME = «root» ;
private static final String PASSWORD = «root» ;
private Connection connection;
public Connection getConnection () {.
return connection;
}.
public MySQLConnector (){.
try {.
Driver driver = new FabricMySQLDriver ();
DriverManager.registerDriver (driver);
connection = DriverManager. getConnection (URL, USERNAME, PASSWORD);
}.
catch (SQLException e){.
e.printStackTrace ();
}.
}.
public ResultSet executeQuery (String query) throws SQLException {.
Statement statement = this. getConnection ().createStatement ();
ResultSet res = statement. executeQuery (query);
return res;
}.
public class GeneratePupilsTable {.
public GeneratePupilsTable (){}.
public Object replaceTeachersAndSubjects (Object object) throws ClassNotFoundException, UnsupportedLookAndFeelException, InstantiationException, IllegalAccessException, IOException {.
TeachersTableModel ttm;
ServerConnector connector = new ServerConnector ();
connector.setOnlineMode ();
connector.sendToServer («send teachers table»);
ttm = (TeachersTableModel) connector. receive (connector.getOis ());
connector.setOffLineMode ();
for (int i = 0; i < ttm. getRowCount (); i++) {.
if (ttm.getValueAt (i, 0).equals (object)) {.
object = String. valueOf (ttm.getValueAt (i, 1));
break;
}.
}.
return object;
}.
public List returnLessons () throws ClassNotFoundException, UnsupportedLookAndFeelException, InstantiationException, IllegalAccessException, IOException {.
CallTableModel ctm;
ServerConnector connector = new ServerConnector ();
connector.setOnlineMode ();
connector.sendToServer («send call table»);
ctm = (CallTableModel) connector. receive (connector.getOis ());
connector.setOffLineMode ();
String element;
List list = new ArrayList ();
for (int i = 0; i < ctm. getRowCount (); i++) {.
element = String. valueOf (ctm.getValueAt (i, 0));
list.add (i, element);
}.
return list;
}.
public List returnClasses () throws ClassNotFoundException, UnsupportedLookAndFeelException, InstantiationException, IllegalAccessException, IOException {.
assesTableModel ctm;
ServerConnector connector = new ServerConnector ();
connector.setOnlineMode ();
connector.sendToServer («send classes table»);
ctm = (ClassesTableModel) connector. receive (connector.getOis ());
connector.setOffLineMode ();
String element;
List list = new ArrayList ();
for (int i = 0; i < ctm. getRowCount (); i++) {.
String part1 = String. valueOf (ctm.getValueAt (i, 0));
String part2 = String. valueOf (ctm.getValueAt (i, 1));
element = part1 + part2;
list.add (i, element);
}.
return list;
}.
public PupilsTimeTableModel generatePupilsTimeTable () throws IOException, ClassNotFoundException, UnsupportedLookAndFeelException, InstantiationException, IllegalAccessException {.
ServerConnector connector = new ServerConnector ();
connector.setOnlineMode ();
connector.sendToServer («send teacherstimetable»);
TeachersTimeTableModel tttm = (TeachersTimeTableModel) connector. receive (connector.getOis ());
connector.setOffLineMode ();
PupilsTimeTableModel pttm = new PupilsTimeTableModel (new String[]{" ΠΠ»Π°ΡΡ", «Π£ΡΠΎΠΊ», «ΠΠΎΠ½Π΅Π΄Π΅Π»ΡΠ½ΠΈΠΊ», «ΠΡΠΎΡΠ½ΠΈΠΊ» ,.
" Π‘ΡΠ΅Π΄Π°", «Π§Π΅ΡΠ²Π΅ΡΠ³», «ΠΡΡΠ½ΠΈΡΠ°», «Π‘ΡΠ±Π±ΠΎΡΠ°» });
List classes = this. returnClasses ();
List lessons = this. returnLessons ();
for (int i = 0; i < classes. size (); i++).
for (int j = 0; j < lessons. size (); j++).
pttm.addRow (new String[] {classes.get (i), lessons. get (j), «», «», «», «», «», «» });
for (int i = 0; i < tttm. getRowCount (); i++).
for (int j = 2; j < tttm. getColumnCount (); j++).
{.
String element = String. valueOf (tttm.getValueAt (i, j));
for (int k = 0; k < pttm. getRowCount (); k++).
{.
if (pttm.getValueAt (k, 0).equals (element)){.
int q = i%lessons.size ();
pttm.setValueAt (replaceTeachersAndSubjects (tttm.getValueAt (i, 0)), (q+k), j);
break;
return pttm;