Guest User

Untitled

a guest
Nov 23rd, 2017
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.84 KB | None | 0 0
  1. import ...
  2.  
  3. // Контроллер для Главного окна
  4. public class Controller {
  5.  
  6. private CollectionEditable passbookimpl = new CollectionEditable();
  7.  
  8. private Stage mainStage;
  9.  
  10. @FXML
  11. private Button addButton;
  12. @FXML
  13. private Button changeButton;
  14. @FXML
  15. private Button delButton;
  16. @FXML
  17. private TableView tablePassBook;
  18. @FXML
  19. private TableColumn<Website, String> columnSite;
  20. @FXML
  21. private TableColumn<Website, String> columnSiteLogin;
  22. @FXML
  23. private TableColumn<Website, String> columnSitePass;
  24. @FXML
  25. private TableColumn<Website, String> columnFtp;
  26. @FXML
  27. private TableColumn<Website, String> columnFtpLogin;
  28. @FXML
  29. private TableColumn<Website, String> columnFtpPass;
  30. @FXML
  31. private TableColumn<Website, String> columnPort;
  32. @FXML
  33. private TableColumn<Website, String> columnPerson;
  34. @FXML
  35. private TableColumn<Website, String> columnPersonEmail;
  36. @FXML
  37. private TableColumn<Website, String> columnPersonPass;
  38. @FXML
  39. private TableColumn<Website, String> columnPersonPhone;
  40. @FXML
  41. private TableColumn<Website, String> columnDbName;
  42. @FXML
  43. private TableColumn<Website, String> columnDbUser;
  44. @FXML
  45. private TableColumn<Website, String> columnDbPass;
  46. @FXML
  47. private TableColumn<Website, String> columnDbHost;
  48. @FXML
  49. private TableColumn<Website, String> columnHostingUrl;
  50. @FXML
  51. private TableColumn<Website, String> columnHostingLogin;
  52. @FXML
  53. private TableColumn<Website, String> columnHostingPass;
  54. @FXML
  55. private TableColumn<Website, String> columnProviderUrl;
  56. @FXML
  57. private TableColumn<Website, String> columnProviderLogin;
  58. @FXML
  59. private TableColumn<Website, String> columnProviderPass;
  60. @FXML
  61. private TableColumn<Website, String> columnOtherUrl;
  62. @FXML
  63. private TableColumn<Website, String> columnOtherLogin;
  64. @FXML
  65. private TableColumn<Website, String> columnOtherPass;
  66. @FXML
  67. private TableColumn<Website, String> columnNotes;
  68. @FXML
  69. private TextField filterField;
  70.  
  71. private static Statement stat;
  72. private static Connection c;
  73.  
  74. @FXML
  75. private void initialize() {
  76.  
  77. columnSite.setCellValueFactory(new PropertyValueFactory<Website, String>("site"));
  78. columnSiteLogin.setCellValueFactory(new PropertyValueFactory<Website, String>("siteLogin"));
  79. columnSitePass.setCellValueFactory(new PropertyValueFactory<Website, String>("sitePass"));
  80. columnFtp.setCellValueFactory(new PropertyValueFactory<Website, String>("ftp"));
  81. columnFtpLogin.setCellValueFactory(new PropertyValueFactory<Website, String>("ftpLogin"));
  82. columnFtpPass.setCellValueFactory(new PropertyValueFactory<Website, String>("ftpPass"));
  83. columnPort.setCellValueFactory(new PropertyValueFactory<Website, String>("port"));
  84. columnPerson.setCellValueFactory(new PropertyValueFactory<Website, String>("person"));
  85. columnPersonEmail.setCellValueFactory(new PropertyValueFactory<Website, String>("personEmail"));
  86. columnPersonPass.setCellValueFactory(new PropertyValueFactory<Website, String>("personPass"));
  87. columnPersonPhone.setCellValueFactory(new PropertyValueFactory<Website, String>("personPhone"));
  88. columnDbName.setCellValueFactory(new PropertyValueFactory<Website, String>("dbName"));
  89. columnDbUser.setCellValueFactory(new PropertyValueFactory<Website, String>("dbUser"));
  90. columnDbPass.setCellValueFactory(new PropertyValueFactory<Website, String>("dbPass"));
  91. columnDbHost.setCellValueFactory(new PropertyValueFactory<Website, String>("dbHost"));
  92. columnHostingUrl.setCellValueFactory(new PropertyValueFactory<Website, String>("hostingUrl"));
  93. columnHostingLogin.setCellValueFactory(new PropertyValueFactory<Website, String>("hostingLogin"));
  94. columnHostingPass.setCellValueFactory(new PropertyValueFactory<Website, String>("hostingPass"));
  95. columnProviderUrl.setCellValueFactory(new PropertyValueFactory<Website, String>("providerUrl"));
  96. columnProviderLogin.setCellValueFactory(new PropertyValueFactory<Website, String>("providerLogin"));
  97. columnProviderPass.setCellValueFactory(new PropertyValueFactory<Website, String>("providerPass"));
  98. columnOtherUrl.setCellValueFactory(new PropertyValueFactory<Website, String>("otherUrl"));
  99. columnOtherLogin.setCellValueFactory(new PropertyValueFactory<Website, String>("otherLogin"));
  100. columnOtherPass.setCellValueFactory(new PropertyValueFactory<Website, String>("otherPass"));
  101. columnNotes.setCellValueFactory(new PropertyValueFactory<Website, String>("notes"));
  102.  
  103. .........
  104.  
  105. try {
  106. fxmlLoader.setLocation(getClass().getResource("/addmodal/addpassw.fxml"));
  107. fxmlEdit = fxmlLoader.load();
  108. addpassw = fxmlLoader.getController();
  109.  
  110. }catch (IOException e){
  111. e.printStackTrace();
  112. }
  113.  
  114.  
  115. }
  116.  
  117.  
  118. public void actionButtonPressed(ActionEvent actionEvent) {
  119.  
  120. Object source = actionEvent.getSource();
  121.  
  122. if (! (source instanceof Button)) {
  123. return;
  124. }
  125.  
  126. Button clickedButton = (Button) source;
  127. Website selectedWebsite = (Website)tablePassBook.getSelectionModel().getSelectedItem();
  128. Window parentWindow = ((Node) actionEvent.getSource()).getScene().getWindow();
  129.  
  130. switch (clickedButton.getId()) {
  131. case "addButton":
  132. addpassw.setWebsite(new Website());
  133. showDialog();
  134. passbookimpl.add(addpassw.getWebsite());
  135. break;
  136. case "changeButton":
  137.  
  138. addpassw.setWebsite((Website)tablePassBook.getSelectionModel().getSelectedItem());
  139. showDialog();
  140. break;
  141. case "delButton":
  142. passbookimpl.delete((Website) tablePassBook.getSelectionModel().getSelectedItem());
  143. try {
  144. PreparedStatement statement = c.prepareStatement("DELETE FROM data WHERE id = ?");
  145. statement.setInt(1, selectedWebsite.getId());
  146. statement.executeUpdate();
  147. } catch(SQLException ex) {
  148. //System.out.println("Не удалось удалить запись");
  149. ex.printStackTrace();
  150. }
  151. break;
  152. }
  153. }
  154.  
  155.  
  156. public void sqlupdate(int id, String site, String siteLogin, String sitePass, String ftp, String ftpLogin, String ftpPass, String port, String person, String personEmail, String personPass, String personPhone, String dbName, String dbUser, String dbPass, String dbHost, String hostingUrl, String hostingLogin, String hostingPass, String providerUrl, String providerLogin, String providerPass, String otherUrl, String otherLogin, String otherPass, String notes ) {
  157. String updatesql = "UPDATE data SET site = ? , " + "siteLogin = ? ," + "sitePass = ? ," + "ftp = ?," + "ftpLogin = ?," + "ftpPass = ?," + "port = ?," + "person = ?," + "personEmail = ?," + "personPass = ?," + "personPhone = ?," + "dbName = ?," + "dbUser = ?," + "dbPass = ?," + "dbHost = ?," + "hostingUrl = ?," + "hostingLogin = ?," + "hostingPass = ?," + "providerUrl = ?," + "providerLogin = ?," + "providerPass = ?," + "otherUrl = ?," + "otherLogin = ?," + "otherPass = ?," + "notes = ? "
  158. + "WHERE id = ?";
  159. try {
  160. SQLiteConfig config = new SQLiteConfig();
  161. c = DriverManager.getConnection("jdbc:sqlite:c:\Users\Phoenix\IdeaProjects\PasswordKeeper\passwkeeper.db");
  162. //stat = c.createStatement();
  163. PreparedStatement pstmt = c.prepareStatement(updatesql);
  164. pstmt.setString(1, site);
  165. pstmt.setString(2, siteLogin);
  166. pstmt.setString(3, sitePass);
  167. pstmt.setString(4, ftp);
  168. pstmt.setString(5, ftpLogin);
  169. pstmt.setString(6, ftpPass);
  170. pstmt.setString(7, port);
  171. pstmt.setString(8, person);
  172. pstmt.setString(9, personEmail);
  173. pstmt.setString(10, personPass);
  174. pstmt.setString(11, personPhone);
  175. pstmt.setString(12, dbName);
  176. pstmt.setString(13, dbUser);
  177. pstmt.setString(14, dbPass);
  178. pstmt.setString(15, dbHost);
  179. pstmt.setString(16, hostingUrl);
  180. pstmt.setString(17, hostingLogin);
  181. pstmt.setString(18, hostingPass);
  182. pstmt.setString(19, providerUrl);
  183. pstmt.setString(20, providerLogin);
  184. pstmt.setString(21, providerPass);
  185. pstmt.setString(22, otherUrl);
  186. pstmt.setString(23, otherLogin);
  187. pstmt.setString(24, otherPass);
  188. pstmt.setString(25, notes);
  189.  
  190. // update
  191. pstmt.executeUpdate();
  192.  
  193. } catch (SQLException ex) {
  194. ex.printStackTrace();
  195. }
  196. }
  197.  
  198.  
  199. }
  200.  
  201. public class Website {
  202. //ID
  203.  
  204. private SimpleIntegerProperty id = new SimpleIntegerProperty();
  205. //Website
  206. private SimpleStringProperty site = new SimpleStringProperty("");
  207. private SimpleStringProperty siteLogin = new SimpleStringProperty("");
  208. private SimpleStringProperty sitePass = new SimpleStringProperty("");
  209.  
  210. //FTP
  211. private SimpleStringProperty ftp = new SimpleStringProperty("");
  212. private SimpleStringProperty ftpLogin = new SimpleStringProperty("");
  213. private SimpleStringProperty ftpPass = new SimpleStringProperty("");
  214. private SimpleStringProperty port = new SimpleStringProperty("");
  215.  
  216. //Owner
  217. private SimpleStringProperty person = new SimpleStringProperty("");
  218. private SimpleStringProperty personEmail = new SimpleStringProperty("");
  219. private SimpleStringProperty personPass = new SimpleStringProperty("");
  220. private SimpleStringProperty personPhone = new SimpleStringProperty("");
  221.  
  222. //DB
  223. private SimpleStringProperty dbName = new SimpleStringProperty("");
  224. private SimpleStringProperty dbUser = new SimpleStringProperty("");
  225. private SimpleStringProperty dbPass = new SimpleStringProperty("");
  226. private SimpleStringProperty dbHost = new SimpleStringProperty("");
  227. // Hosting
  228. private SimpleStringProperty hostingUrl = new SimpleStringProperty("");
  229. private SimpleStringProperty hostingLogin = new SimpleStringProperty("");
  230. private SimpleStringProperty hostingPass = new SimpleStringProperty("");
  231. // Domain
  232. private SimpleStringProperty providerUrl = new SimpleStringProperty("");
  233. private SimpleStringProperty providerLogin = new SimpleStringProperty("");
  234. private SimpleStringProperty providerPass = new SimpleStringProperty("");
  235. //Other Accounts
  236. private SimpleStringProperty otherUrl = new SimpleStringProperty("");
  237. private SimpleStringProperty otherLogin = new SimpleStringProperty("");
  238. private SimpleStringProperty otherPass = new SimpleStringProperty("");
  239.  
  240. //Notes
  241. private SimpleStringProperty notes = new SimpleStringProperty("");
Add Comment
Please, Sign In to add comment