Advertisement
Guest User

Untitled

a guest
Mar 24th, 2016
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 18.67 KB | None | 0 0
  1. package mmm;
  2.  
  3.  
  4. import java.net.URL;
  5. import java.util.ResourceBundle;
  6. import javafx.event.ActionEvent;
  7. import javafx.fxml.FXML;
  8. import javafx.fxml.Initializable;
  9. import javafx.scene.control.ListView;
  10. import javafx.scene.control.TextField;
  11.  
  12. import java.sql.Connection;
  13. import java.sql.DriverManager;
  14. import java.sql.ResultSet;
  15. import java.sql.ResultSetMetaData;
  16. import java.sql.SQLException;
  17. import java.sql.Statement;
  18. import javafx.collections.ObservableList;
  19. import javafx.scene.control.DatePicker;
  20.  
  21. /**
  22. *
  23. * @author Sebastian
  24. *
  25. */
  26. public class FXMLDocumentController implements Initializable {
  27.  
  28. @FXML
  29. private TextField nazwa1,nazwa2,nazwa3,nazwa4,nazwa5,nazwa6,nazwa7,nazwa8,nazwa9,nazwa10;
  30. @FXML
  31. private TextField im1,im2,im3,im4,im5,im6,im7,im8,im9,im10;
  32. @FXML
  33. private TextField ilość1,ilość2,ilość3,ilość4,ilość5,ilość6,ilość7,ilość8,ilość9,ilość10;
  34. @FXML
  35. private TextField cena1,cena2,cena3,cena4,cena5,cena6,cena7,cena8,cena9,cena10;
  36. @FXML
  37. private TextField VAT1,VAT2,VAT3,VAT4,VAT5,VAT6,VAT7,VAT8,VAT9,VAT10;
  38. @FXML
  39. private ListView<String> produkty;
  40. @FXML
  41. private TextField rabat1,rabat2,rabat3,rabat4,rabat5,rabat6,rabat7rabat8,rabat9,rabat10;
  42. @FXML
  43. private TextField numer,nabywca1,sprzedawca1,adres1,adres2,nip1,nip2;
  44. @FXML
  45. private DatePicker terminplatnosci,datawystawienia;
  46.  
  47.  
  48.  
  49. @FXML
  50. public void plus1(ActionEvent event) {
  51. produkty.setVisible(true);
  52. }
  53. @FXML
  54. private ObservableList<ObservableList> data;
  55.  
  56. private Connection c;
  57. private Statement stmt;
  58. private ResultSet wyniki;
  59. private ResultSetMetaData meta;
  60. private int update;
  61. private String konsola;
  62. public String select(String zapytanie) throws SQLException, ClassNotFoundException {
  63. String url = "jdbc:sqlite:bazadanychfaktura.db3";
  64. Class.forName("org.sqlite.JDBC");
  65. Connection c = DriverManager.getConnection(url);
  66. Statement stmt = c.createStatement();
  67. ResultSet wyniki = stmt.executeQuery(zapytanie);
  68. ResultSetMetaData meta = wyniki.getMetaData();
  69. String produkty = "";
  70.  
  71. for (int i = 0; i < meta.getColumnCount(); i++) { // Wyswietlanie wynikow
  72. produkty = produkty + meta.getColumnLabel(i + 1) + "t|t";
  73. }
  74. produkty = produkty + "n";
  75.  
  76. while (wyniki.next()) {
  77. for (int i = 0; i < meta.getColumnCount(); i++) {
  78. produkty = produkty + wyniki.getString(i + 1) + "t|t";
  79. }
  80. produkty = produkty + "n";
  81. }
  82. return produkty;
  83. }
  84.  
  85. public String update(String zapytanie) throws SQLException, ClassNotFoundException {
  86. String url = "jdbc:sqlite:bazadanychfaktura.db3";
  87. Class.forName("org.sqlite.JDBC");
  88. c = DriverManager.getConnection(url);
  89. stmt = c.createStatement();
  90. update = stmt.executeUpdate(zapytanie);
  91.  
  92. konsola = "Zaktualizowano " + update + " wierszy.";
  93.  
  94. return konsola;
  95. }
  96.  
  97.  
  98.  
  99. @FXML
  100. private void anulujAction(ActionEvent event) {
  101. System.exit(0);
  102.  
  103. }
  104.  
  105. @FXML
  106. private void ZatwierdźAction(ActionEvent event) throws ClassNotFoundException, SQLException {
  107.  
  108.  
  109. String b = ilość1.getText();
  110. String t = cena1.getText();
  111. String e = rabat1.getText();
  112. int d;
  113.  
  114. d = Integer.valueOf(b) * Integer.valueOf(t);
  115.  
  116.  
  117.  
  118. String[][] values
  119. = {{"1", "" + nazwa1.getText() + "", "" + im1.getText() + "", "" + ilość1.getText() + "", "" + cena1.getText() + "", ""+ rabat1.getText() +"", ""+ d +"", "7", "8"},
  120. {"2", "" + nazwa2.getText() + "", "" + im2.getText() + "", "" + ilość2.getText() + "", "" + cena2.getText() + "", "5", "6", "7", "8"},
  121. {"3", "" + nazwa3.getText() + "", "" + im3.getText() + "", "" + ilość3.getText() + "", "" + cena3.getText() + "", "5", "6", "7", "8"},
  122. {"4", "" + nazwa4.getText() + "", "" + im4.getText() + "", "" + ilość4.getText() + "", "" + cena4.getText() + "", "5", "6", "7", "8"},
  123. {"5", "" + nazwa5.getText() + "", "" + im5.getText() + "", "" + ilość5.getText() + "", "" + cena5.getText() + "", "5", "6", "7", "8"},
  124. {"6", "" + nazwa6.getText() + "", "" + im6.getText() + "", "" + ilość6.getText() + "", "" + cena6.getText() + "", "5", "6", "7", "8"},
  125. {"7", "" + nazwa7.getText() + "", "" + im7.getText() + "", "" + ilość7.getText() + "", "" + cena7.getText() + "", "5", "6", "7", "8"},
  126. {"8", "" + nazwa8.getText() + "", "" + im8.getText() + "", "" + ilość8.getText() + "", "" + cena8.getText() + "", "5", "6", "7", "8"},
  127. {"9", "" + nazwa9.getText() + "", "" + im9.getText() + "", "" + ilość9.getText() + "", "" + cena9.getText() + "", "5", "6", "7", "8"},
  128. {"10", "" + nazwa10.getText() + "", "" + im10.getText() + "", "" + ilość10.getText() + "", "" + cena10.getText() + "", "5", "6", "7", "8"},};
  129.  
  130. Creator pdf = new Creator(values, "" + sprzedawca1.getText() + "", nip2.getText(), "" + nip1.getText() + "", "" + numer.getText() + "",
  131. "" + adres2.getText() + "", "" + nabywca1.getText() + "", "" + terminplatnosci.getValue() + "", "" + adres1.getText() + "", "" + datawystawienia.getValue() + "");
  132. String update, update2, update3, update4, update5, update6, update7, update8, update9, update10;
  133.  
  134. update = "update Magazyn set ilość = (ilość - '" + ilość1.getText() + "') where Nazwa = '" + nazwa1.getText() + "'";
  135. update2 = "update Magazyn set ilość = (ilość - '" + ilość2.getText() + "') where Nazwa = '" + nazwa2.getText() + "'";
  136. update3 = "update Magazyn set ilość = (ilość - '" + ilość3.getText() + "') where Nazwa = '" + nazwa3.getText() + "'";
  137. update4 = "update Magazyn set ilość = (ilość - '" + ilość4.getText() + "') where Nazwa = '" + nazwa4.getText() + "'";
  138. update5 = "update Magazyn set ilość = (ilość - '" + ilość5.getText() + "') where Nazwa = '" + nazwa5.getText() + "'";
  139. update6 = "update Magazyn set ilość = (ilość - '" + ilość6.getText() + "') where Nazwa = '" + nazwa6.getText() + "'";
  140. update7 = "update Magazyn set ilość = (ilość - '" + ilość7.getText() + "') where Nazwa = '" + nazwa7.getText() + "'";
  141. update8 = "update Magazyn set ilość = (ilość - '" + ilość8.getText() + "') where Nazwa = '" + nazwa8.getText() + "'";
  142. update9 = "update Magazyn set ilość = (ilość - '" + ilość9.getText() + "') where Nazwa = '" + nazwa9.getText() + "'";
  143. update10 = "update Magazyn set ilość = (ilość - '" + ilość10.getText() + "') where Nazwa = '" + nazwa10.getText() + "'";
  144.  
  145. Zapytanie z6 = new Zapytanie();
  146. z6.update(update);
  147. z6.update(update2);
  148. z6.update(update3);
  149. z6.update(update4);
  150. z6.update(update5);
  151. z6.update(update6);
  152. z6.update(update7);
  153. z6.update(update8);
  154. z6.update(update9);
  155. z6.update(update10);
  156.  
  157. String z;
  158.  
  159. ResultSet rs = stmt.executeQuery("select ilość from Magazyn where Nazwa = '" + nazwa1.getText() + "'");
  160. if (rs.first()) {z=rs.getString("typ");
  161. if
  162. (z.equals("wartosc"))
  163. System.out.println("bład");
  164.  
  165. }}
  166. {
  167.  
  168.  
  169.  
  170. }
  171.  
  172. @Override
  173. public void initialize(URL url, ResourceBundle rb) {
  174. ilość1.setText("0");
  175. cena1.setText("0");
  176. rabat1.setText("0");
  177. }
  178. }
  179.  
  180. package mmm;
  181.  
  182. import com.itextpdf.text.BaseColor;
  183. import com.itextpdf.text.Document;
  184. import com.itextpdf.text.DocumentException;
  185. import com.itextpdf.text.Element;
  186. import com.itextpdf.text.Font;
  187. import com.itextpdf.text.PageSize;
  188. import com.itextpdf.text.Phrase;
  189. import com.itextpdf.text.Rectangle;
  190. import com.itextpdf.text.pdf.BaseFont;
  191. import com.itextpdf.text.pdf.PdfPCell;
  192. import com.itextpdf.text.pdf.PdfPTable;
  193. import com.itextpdf.text.pdf.PdfWriter;
  194. import java.awt.Desktop;
  195. import java.io.File;
  196. import java.io.FileOutputStream;
  197. import java.io.IOException;
  198. import java.util.logging.Level;
  199. import java.util.logging.Logger;
  200.  
  201. public class Creator {
  202.  
  203. public Creator(String[][] rekordy, String firma, String data,String miasto,String data2,String nip2,String adres,String nabywca ,String nip, String id) {
  204. try {
  205. CreateDocument Faktura = new CreateDocument();
  206. Faktura.CreateDocument(rekordy, firma,miasto,nip,nabywca,adres,nip2 ,id,data,data2);
  207. File plik;
  208.  
  209. plik = new File("C:/faktura.pdf");
  210.  
  211. Desktop.getDesktop().open(plik);
  212. } catch (IOException ex) {
  213. Logger.getLogger(Creator.class.getName()).log(Level.SEVERE, null, ex);
  214. }
  215.  
  216. }
  217.  
  218. Creator(String[] string, String string0, String string1, String string2, String string3, String string4, String string5, String string6, String string7) {
  219. throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
  220. }
  221. }
  222.  
  223. class CreateDocument {
  224.  
  225. public Document CreateDocument(String[][] rekordy, String firma, String data, String data2,String nip2,String nabywca,String adres,String miasto, String nip, String id) {
  226. Document document = new Document(PageSize.A4, 36, 20, 36, 20);
  227.  
  228.  
  229. try {
  230.  
  231. PdfWriter.getInstance(document, new FileOutputStream("C:/faktura.pdf"));
  232. document.open();
  233.  
  234. CreateTable obj = new CreateTable();
  235. Data objSeller = new Data();
  236. Font font = new Font(Font.FontFamily.COURIER, 12);
  237.  
  238. document.add(objSeller.createSeller(firma, nabywca,adres,nip2,data,data2 ,miasto, nip, id));
  239. document.add(obj.createHeader(id));
  240. document.add(obj.createData(rekordy));
  241. //document.add(obj.createResum());
  242. document.add(obj.createSum());
  243. } catch (Exception e) {
  244. // handle exception
  245. }
  246.  
  247. document.close();
  248. return document;
  249. }
  250. }
  251.  
  252. class CreateTable {
  253.  
  254. public PdfPTable createHeader(String id) {
  255. BaseFont bf = null;
  256. try {
  257. bf = BaseFont.createFont(BaseFont.TIMES_ROMAN, BaseFont.CP1250, BaseFont.CACHED);
  258. } catch (DocumentException ex) {
  259. Logger.getLogger(CreateTable.class.getName()).log(Level.SEVERE, null, ex);
  260. } catch (IOException ex) {
  261. Logger.getLogger(CreateTable.class.getName()).log(Level.SEVERE, null, ex);
  262. }
  263. Font f = new Font(bf, 9, Font.NORMAL);
  264.  
  265. float[] widths1 = {5, 30, 5, 5, 10, 10, 10, 10, 10};
  266. PdfPTable table1 = new PdfPTable(widths1);
  267. table1.setWidthPercentage(100f);
  268. PdfPCell header = new PdfPCell(new Phrase("Faktura końcowa "+id+""));
  269. header.setPadding(5);
  270. header.setColspan(9);
  271. table1.addCell(header);
  272. table1.getDefaultCell().setBackgroundColor(BaseColor.LIGHT_GRAY);
  273. table1.getDefaultCell().setPaddingBottom(3);
  274. table1.getDefaultCell().setPaddingTop(2);
  275. table1.getDefaultCell().setPaddingLeft(3);
  276. table1.getDefaultCell().setPaddingRight(3);
  277. table1.getDefaultCell().setBorderWidth(1);
  278.  
  279. Phrase lp = new Phrase("Lp.", f);
  280. Phrase nazwa_tow = new Phrase("Nazwa towaru/usługin(SWW/KU)", f);
  281. Phrase jm = new Phrase("J.m.", f);
  282. Phrase ilosc = new Phrase("Ilość", f);
  283. Phrase cena_netto = new Phrase("Cena j. netto [zł]", f);
  284. Phrase rabat = new Phrase("Rabat [zł]", f);
  285. Phrase wartosc_netto = new Phrase("Wartość netto [zł]", f);
  286. Phrase kwota_podatku = new Phrase("Kwota podatku [zł]", f);
  287. Phrase wartosc_brutto = new Phrase("Wartość brutto [zł]", f);
  288.  
  289. table1.addCell(lp);
  290. table1.addCell(nazwa_tow);
  291. table1.addCell(jm);
  292. table1.addCell(ilosc);
  293. table1.addCell(cena_netto);
  294. table1.addCell(rabat);
  295. table1.addCell(wartosc_netto);
  296. table1.addCell(kwota_podatku);
  297. table1.addCell(wartosc_brutto);
  298.  
  299. return table1;
  300. }
  301.  
  302. private float wartosc = 0;
  303. private float rabat = 0;
  304. private float netto = 0;
  305. private float podatek = 0;
  306.  
  307. public PdfPTable createData(String[][] rekordy) {
  308. float[] widths1 = {5, 30, 5, 5, 10, 10, 10, 10, 10};
  309. PdfPTable table = new PdfPTable(widths1);
  310. table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_RIGHT);
  311. table.getDefaultCell().setPaddingRight(4);
  312. table.setWidthPercentage(100f);
  313. for (int i = 0; i < rekordy.length; i++) {
  314. for (int k = 0; k < 9; k++) {
  315. table.addCell(String.valueOf(rekordy[i][k]));
  316. }
  317. this.wartosc += Float.parseFloat(rekordy[i][8]);
  318. this.podatek += Float.parseFloat(rekordy[i][7]);
  319. this.netto += Float.parseFloat(rekordy[i][6]);
  320. this.rabat += Float.parseFloat(rekordy[i][5]);
  321. }
  322. return table;
  323. }
  324.  
  325.  
  326. public PdfPTable createResum() {
  327. float[] widths1 = {15, 10, 10, 10, 10};
  328. PdfPTable table = new PdfPTable(widths1);
  329. table.getDefaultCell().setBorderWidth(1);
  330. table.getDefaultCell().setPadding(3);
  331. table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_RIGHT);
  332. table.setWidthPercentage(58);
  333. table.setHorizontalAlignment(Element.ALIGN_RIGHT);
  334. table.addCell(new Phrase("W tym:"));
  335. table.addCell(new Phrase("600"));
  336. table.addCell(new Phrase("0"));
  337. table.addCell(new Phrase("123,00"));
  338.  
  339. PdfPCell Suma = new PdfPCell(new Phrase("732,00"));
  340. Suma.setHorizontalAlignment(Element.ALIGN_RIGHT);
  341. Suma.setBackgroundColor(BaseColor.LIGHT_GRAY);
  342. table.addCell(Suma);
  343. return table;
  344. }
  345.  
  346. public PdfPTable createSum() {
  347. float[] widths1 = {15, 10, 10, 10, 10};
  348. PdfPTable table = new PdfPTable(widths1);
  349. table.getDefaultCell().setBorderWidth(1);
  350. table.getDefaultCell().setPadding(3);
  351. table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_RIGHT);
  352. table.setWidthPercentage(58);
  353. table.setHorizontalAlignment(Element.ALIGN_RIGHT);
  354. table.addCell(new Phrase("Razem:"));
  355. table.addCell(new Phrase(String.valueOf(this.rabat)));
  356. table.addCell(new Phrase(String.valueOf(this.netto)));
  357. table.addCell(new Phrase(String.valueOf(this.podatek)));
  358.  
  359. PdfPCell Suma = new PdfPCell(new Phrase(String.valueOf(this.wartosc)));
  360. Suma.setHorizontalAlignment(Element.ALIGN_RIGHT);
  361. Suma.setBackgroundColor(BaseColor.LIGHT_GRAY);
  362. table.addCell(Suma);
  363.  
  364. return table;
  365. }
  366. }
  367.  
  368. class Data {
  369.  
  370. public PdfPTable createSeller(String firma,String nabywca ,String data, String data2,String nip2,String adres,String miasto, String nip, String id) {
  371. BaseFont bf = null;
  372. try {
  373. bf = BaseFont.createFont(BaseFont.TIMES_ROMAN, BaseFont.CP1250, BaseFont.EMBEDDED);
  374. } catch (DocumentException ex) {
  375. Logger.getLogger(CreateTable.class.getName()).log(Level.SEVERE, null, ex);
  376. } catch (IOException ex) {
  377. Logger.getLogger(CreateTable.class.getName()).log(Level.SEVERE, null, ex);
  378. }
  379. Font f1 = new Font(bf, 9, Font.NORMAL);
  380. Font f2 = new Font(bf, 10, Font.BOLD);
  381.  
  382. Phrase desc = new Phrase("Sprzedawca:n", f1);
  383. Phrase seller = new Phrase(firma+"n"+data+"nNIP: "+nip+"", f2);
  384. desc.add(seller);
  385. desc.add(new Phrase("nnKupujacyn", f1));
  386. desc.add(new Phrase(nabywca+"n"+adres+"nNIP: "+ nip2 +"",f2));
  387.  
  388. Phrase info = new Phrase("Faktura "+id+"nnData wystawienia: "+miasto+", "+data+"nnTermin płatności: "+data2+"");
  389.  
  390. //float[] widths1 = {200};
  391. PdfPTable table = new PdfPTable(2);
  392. table.getDefaultCell().setBorder(0);
  393. table.getDefaultCell().setPadding(3);
  394.  
  395. table.setWidthPercentage(100f);
  396.  
  397. PdfPCell cell_seller = new PdfPCell(desc);
  398. cell_seller.setHorizontalAlignment(Element.ALIGN_LEFT);
  399. cell_seller.setBorder(Rectangle.NO_BORDER);
  400. cell_seller.setPaddingBottom(10);
  401.  
  402. PdfPCell cell_info = new PdfPCell(info);
  403. cell_info.setHorizontalAlignment(Element.ALIGN_RIGHT);
  404. cell_info.setBorder(Rectangle.NO_BORDER);
  405. cell_info.setPaddingBottom(10);
  406.  
  407. PdfPCell cell_emptor = new PdfPCell();
  408. cell_emptor.setHorizontalAlignment(Element.ALIGN_LEFT);
  409. cell_emptor.setPaddingBottom(40);
  410. cell_emptor.setBorder(Rectangle.NO_BORDER);
  411. cell_emptor.setPhrase(desc);
  412.  
  413. table.addCell(cell_seller);
  414. table.addCell(cell_info);
  415. table.addCell(cell_emptor);
  416. return table;
  417.  
  418. }
  419. }
  420.  
  421. package mmm;
  422.  
  423. import java.sql.*;
  424.  
  425. public class Zapytanie{
  426.  
  427. private Connection c;
  428. private Statement stmt;
  429. private ResultSet wyniki;
  430. private ResultSetMetaData meta;
  431. private int update;
  432. private String konsola;
  433.  
  434.  
  435. public String select(String zapytanie) throws SQLException, ClassNotFoundException {
  436. String url = "jdbc:sqlite:bazadanychfaktura.db3";
  437. Class.forName("org.sqlite.JDBC");
  438. c = DriverManager.getConnection(url);
  439. stmt = c.createStatement();
  440. wyniki = stmt.executeQuery(zapytanie);
  441. meta = wyniki.getMetaData();
  442. konsola = "";
  443.  
  444. for (int i = 0; i < meta.getColumnCount(); i++) { // Wyswietlanie wynikow
  445. konsola = konsola + meta.getColumnLabel(i + 1) + "t|t";
  446. }
  447. konsola = konsola + "n";
  448.  
  449. while (wyniki.next()) {
  450. for (int i = 0; i < meta.getColumnCount(); i++) {
  451. konsola = konsola + wyniki.getString(i + 1) + "t|t";
  452. }
  453. konsola = konsola + "n";
  454. }
  455. return konsola;
  456. }
  457.  
  458. public String update(String zapytanie) throws SQLException, ClassNotFoundException {
  459. String url = "jdbc:sqlite:bazadanychfaktura.db3";
  460. Class.forName("org.sqlite.JDBC");
  461. c = DriverManager.getConnection(url);
  462. stmt = c.createStatement();
  463. update = stmt.executeUpdate(zapytanie);
  464.  
  465. konsola = "Zaktualizowano " + update + " wierszy.";
  466.  
  467. return konsola;
  468. }
  469.  
  470. public String insert(String zapytanie) throws SQLException, ClassNotFoundException {
  471. String url = "jdbc:sqlite:bazadanychfaktura.db3";
  472. Class.forName("org.sqlite.JDBC");
  473. c = DriverManager.getConnection(url);
  474. stmt = c.createStatement();
  475. update = stmt.executeUpdate(zapytanie);
  476.  
  477. konsola = "Wstawiono " + update + " nowych wierszy.";
  478.  
  479. return konsola;
  480. }
  481.  
  482. public String delete(String zapytanie) throws SQLException, ClassNotFoundException {
  483. String url = "jdbc:sqlite:bazadanychfaktura.db3";
  484. Class.forName("org.sqlite.JDBC");
  485. c = DriverManager.getConnection(url);
  486. stmt = c.createStatement();
  487. update = stmt.executeUpdate(zapytanie);
  488.  
  489. konsola = "Usunięto " + update + " wierszy.";
  490.  
  491. return konsola;
  492. }
  493.  
  494. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement