Advertisement
Guest User

Post

a guest
Apr 27th, 2018
1,165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.22 KB | None | 0 0
  1. package login;
  2.  
  3. import javax.inject.Named;
  4. import javax.enterprise.context.SessionScoped;
  5. import java.io.Serializable;
  6. import java.sql.Connection;
  7. import java.sql.DriverManager;
  8. import java.sql.ResultSet;
  9. import java.sql.SQLException;
  10. import java.sql.Statement;
  11. import java.sql.Time;
  12. import java.time.LocalTime;
  13. import java.util.ArrayList;
  14.  
  15. @Named(value = "post")
  16. @SessionScoped
  17. public class Post implements Serializable {
  18.  
  19.     String text;
  20.     String imge = "";
  21.     String sound = "";
  22.     String video = "";
  23.     String Name = "";
  24.  
  25.     public String getName() {
  26.         Variable v = new Variable();
  27.         return v.Name;
  28.     }
  29.  
  30.     public void setName(String Name) {
  31.         Variable v = new Variable();
  32.         this.Name = v.Name;
  33.     }
  34.  
  35.     public String getText() {
  36.         return text;
  37.     }
  38.  
  39.     public void setText(String text) {
  40.         this.text = text;
  41.     }
  42.  
  43.     public void addposts(String User) {
  44.         try {
  45.             Class.forName("com.mysql.jdbc.Driver").newInstance();
  46.             Connection MC = DriverManager.getConnection("jdbc:mysql://localhost/test", "root", "1234");
  47.             Statement STF = MC.createStatement();
  48.             String R = "Insert into post(User,Text,time) VALUES ('" + User + "','" + text + "','" + Time.valueOf(LocalTime.now()) + "')";
  49.             STF.executeUpdate(R);
  50.             text = "";
  51.         } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | SQLException E) {
  52.             System.out.println(E);
  53.         }
  54.     }
  55.  
  56.     ArrayList<poster> Cas = new ArrayList<>();
  57.     public static ArrayList<poster> Cluster = new ArrayList<>();
  58.     public static int pageIndexs = 0;
  59.     int pageIndex = 1;
  60.     int pages = 1;
  61.  
  62.     public void prev() {
  63.         if (pageIndexs > 1) {
  64.             pageIndexs--;
  65.             pageIndex = pageIndexs;
  66.             int i = 1;
  67.             Cas.clear();
  68.             for (poster r : Cluster) {
  69.                 if (i >= pageIndexs * 8 && i < (pageIndexs * 8) + 8) {
  70.                     Cas.add(r);
  71.                 }
  72.                 i++;
  73.             }
  74.         }
  75.     }
  76.  
  77.     public void next() {
  78.         if (pageIndexs < pages) {
  79.             pageIndexs++;
  80.             pageIndex = pageIndexs;
  81.             int i = 1;
  82.             Cas.clear();
  83.             for (poster r : Cluster) {
  84.                 if (i >= pageIndexs * 8 && i < (pageIndexs * 8) + 8) {
  85.                     Cas.add(r);
  86.                 }
  87.                 i++;
  88.             }
  89.         }
  90.     }
  91.  
  92.     public void getallposts(String User) {
  93.         Cas.clear();
  94.         Cluster.clear();
  95.         try {
  96.             Class.forName("com.mysql.jdbc.Driver").newInstance();
  97.             Connection MC = DriverManager.getConnection("jdbc:mysql://localhost/test", "root", "1234");
  98.             Statement STF = MC.createStatement();
  99.             ResultSet R = STF.executeQuery("Select * from post where User='" + User + "'");
  100.             while (R.next()) {
  101.                 poster p = new poster();
  102.                 p.postes = R.getString("Text");
  103.                 p.Times = R.getTime("time");
  104.                 p.Sounds = R.getString("Sound");
  105.                 p.Videos = R.getString("video");
  106.                 p.Imges = R.getString("Imge");
  107.                 if (Cas.size() < 8) {
  108.                     Cas.add(p);
  109.                 }
  110.                 Cluster.add(p);
  111.             }
  112.             if (Cluster.size() % 8 > 0) {
  113.                 int g = Cluster.size() % 8;
  114.                 pages = (Cluster.size() - g) / 8;
  115.                 pages++;
  116.             } else {
  117.                 pages = Cluster.size() / 8;
  118.             }
  119.         } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | SQLException E) {
  120.             System.out.println(E);
  121.         }
  122.     }
  123.  
  124.     public Post() {
  125.     }
  126.  
  127.     public int getPageIndex() {
  128.         return pageIndex;
  129.     }
  130.  
  131.     public void setPageIndex(int pageIndex) {
  132.         this.pageIndex = pageIndex;
  133.     }
  134.  
  135.     public int getPages() {
  136.         return pages;
  137.     }
  138.  
  139.     public void setPages(int pages) {
  140.         this.pages = pages;
  141.     }
  142.  
  143.     public ArrayList<poster> getCas() {
  144.         return Cas;
  145.     }
  146.  
  147.     public void setCas(ArrayList<poster> Cas) {
  148.         this.Cas = Cas;
  149.     }
  150.  
  151. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement