package epssms;
import epssms.articledocpane.ArticleDocPaneController;
import epssms.articlequerypane.ArticleQueryPaneController;
import epssms.backuppane.BackupPaneController;
import epssms.callbackpane.CallbackPaneController;
import epssms.customdocpane.CustomDocPaneController;
import epssms.dialog.authentication.AuthenticationController;
import epssms.purchasepane.PurchasePaneController;
import epssms.restorepane.RestorePaneController;
import epssms.sellpane.SellPaneController;
import epssms.stockpane.StockPaneController;
import epssms.supplierdocpane.SupplierDocPaneController;
import epssms.tasks.FetchArticleDocDBForArticleDocPaneTask;
import epssms.tasks.FetchArticleNameForSellPaneTask;
import epssms.tasks.FetchCustomDocDBForCustomDocPaneTask;
import epssms.tasks.FetchCustomNameForSellPaneTask;
import epssms.tasks.FetchPurchaseDetailDBForUndoPaneTask;
import epssms.tasks.FetchPurchaseMainDBForUndoPaneTask;
import epssms.tasks.FetchSellDetailDBForCallbackPaneTask;
import epssms.tasks.FetchSellMainDBForCallbackPaneTask;
import epssms.tasks.FetchStockForStockPaneTask;
import epssms.tasks.FetchSupplierDocDBForSupplierDocPaneTask;
import epssms.tasks.FetchSupplierNameForArticleDocPaneTask;
import epssms.tasks.FetchSupplierNameForPurchasePaneTask;
import epssms.undopane.UndoPaneController;
import epssms.util.Dao;
import epssms.util.DesktopApi;
import epssms.util.Panes;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.ResourceBundle;
import java.util.logging.Level;
import java.util.logging.Logger;
import javafx.animation.KeyFrame;
import javafx.animation.Timeline;
import javafx.application.Platform;
import javafx.beans.InvalidationListener;
import javafx.beans.Observable;
import javafx.concurrent.Task;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Cursor;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.MenuItem;
import javafx.scene.control.PasswordField;
import javafx.scene.control.ProgressBar;
import javafx.scene.control.TextField;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.StackPane;
import javafx.scene.text.Text;
import javafx.stage.Modality;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
import javafx.stage.WindowEvent;
import javafx.util.Duration;
public class MainFrameController implements Initializable {
private Node articleDocPane;
private Node articleQueryPane;
private Node callbackPane;
private Node customDocPane;
private Node purchasePane;
private Node sellPane;
private Node stockPane;
private Node supplierDocPane;
private Node undoPane;
public static Label user;
@FXML
private static StackPane grayLayer;
public static ProgressBar progressBar;
public static ProgressBar progressBar2;
public static Button refreshDBButton;
public static MenuItem restoreMI;
public static void displayInfo(String infoText) {
Label info = new Label();
info.setWrapText(true);
info.setText(infoText);
addToGrayLayer(info);
}
private static void addToGrayLayer(Node node) {
grayLayer.getChildren().clear();
grayLayer.getChildren().add(node);
grayLayer.setVisible(true);
}
@FXML
private Label currentWindow;
@FXML
private Label clock;
@FXML
private TextField userNameField;
@FXML
private PasswordField passwordField;
@FXML
private GridPane loginPane;
@FXML
private BorderPane borderPane;
@FXML
private void handlePFAction() {
grayLayer.getChildren().clear();
Task<Void> loginTask = new Task<Void>() {
@Override
protected Void call() throws Exception {
final String userName = userNameField.getText();
String password = passwordField.getText();
try {
try (Connection conn = Dao.getConnection(); Statement s = conn.createStatement(); ResultSet rs = s.executeQuery("SELECT * FROM USERLIST WHERE USERNAME='" + userName + "' AND PASSWORD='" + password + "'")) {
if (rs.next()) {
/*
* In particular, if the background thread is reading data from the database and updating the Customer object, and the
* Customer object is bound to scene graph nodes (such as UI controls), then there could be a violation of threading rules!
* For such cases, modify the Customer object from the FX Application Thread rather than from the background thread.
*/
Platform.runLater(new Runnable() {
@Override
public void run() {
loginPane.setVisible(false);
grayLayer.setVisible(false);
borderPane.setDisable(false);
user.setText(userName);
}
});
}
}
} catch (final SQLException e) {
Platform.runLater(new Runnable() {
@Override
public void run() {
displayLoginError(e.toString());
}
});
}
return null;
}
@Override
protected void running() {
super.running();
progressBar.setVisible(true);
}
@Override
protected void succeeded() {
super.succeeded();
progressBar.setVisible(false);
}
};
new Thread(loginTask).start();
}
@FXML
private void refreshDB() {
Node center = borderPane.getCenter();
if (center != null) {
switch ((Panes) center.getUserData()) {
case SUPPLIERDOCPANE:
new Thread(new FetchSupplierDocDBForSupplierDocPaneTask()).start();
break;
case ARTICLEDOCPANE:
new Thread(new FetchArticleDocDBForArticleDocPaneTask()).start();
new Thread(new FetchSupplierNameForArticleDocPaneTask()).start();
break;
case CUSTOMDOCPANE:
new Thread(new FetchCustomDocDBForCustomDocPaneTask()).start();
break;
case PURCHASEPANE:
new Thread(new FetchSupplierNameForPurchasePaneTask()).start();
break;
case UNDOPANE:
new Thread(new FetchPurchaseMainDBForUndoPaneTask()).start();
new Thread(new FetchPurchaseDetailDBForUndoPaneTask()).start();
break;
case SELLPANE:
new Thread(new FetchCustomNameForSellPaneTask()).start();
new Thread(new FetchArticleNameForSellPaneTask()).start();
break;
case CALLBACKPANE: