Advertisement
Guest User

Untitled

a guest
May 19th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 12.61 KB | None | 0 0
  1. ///////////////MySQL.CLass//////////////////////
  2. package helloworld.hello;
  3.  
  4.  
  5. import java.sql.Connection;
  6. import java.sql.DriverManager;
  7. import java.sql.ResultSet;
  8. import java.sql.SQLException;
  9. import java.sql.Statement;
  10. import java.util.*;
  11.  
  12.  
  13. import com.mysql.jdbc.PreparedStatement;
  14. import com.mysql.jdbc.ResultSetMetaData;
  15.  
  16. public class MySQL {
  17.    
  18.     public static void insertComponent(String name){
  19.         Connection con=null;
  20.        
  21.         try{
  22.             Class.forName("com.mysql.jdbc.Driver");
  23.             con=DriverManager.getConnection("jdbc:mysql://localhost:3306/Collabsoft","root","");
  24.             Statement st = con.createStatement();
  25.             st.executeUpdate("insert into component (name) values ('"+name+"')");
  26.         }
  27.        
  28.         catch(Exception e){
  29.             e.printStackTrace();
  30.         }
  31.        
  32.         finally{
  33.             try{
  34.                 if(con != null)
  35.                     con.close();
  36.             }
  37.             catch(Exception e){
  38.         }
  39.     }
  40.  
  41. }
  42.    
  43.     public static void insertSprint(String name, java.sql.Date start, java.sql.Date end,long duration, int proj_ID){
  44.        
  45.         Connection con=null;
  46.         PreparedStatement pstmt = null;
  47.        
  48.         try{
  49.             Class.forName("com.mysql.jdbc.Driver");
  50.             con=DriverManager.getConnection("jdbc:mysql://localhost:3306/Collabsoft","root","");
  51.             String query ="Insert into sprints (Title,Start_Date,End_Date,Duration,Proj_ID) values (?,?,?,?,?)";
  52.             pstmt = (PreparedStatement) con.prepareStatement(query);
  53.               pstmt.setString(1, name); // set input parameter 1
  54.               pstmt.setDate(2, start); // set input parameter 2
  55.               pstmt.setDate(3, end);
  56.               pstmt.setLong(4, duration); // set input parameter 3
  57.               pstmt.setInt(5, proj_ID);
  58.               pstmt.executeUpdate();
  59.            
  60.         }
  61.        
  62.         catch(Exception e){
  63.             e.printStackTrace();
  64.         }
  65.        
  66.         finally{
  67.             try{
  68.                 if(con != null)
  69.                     con.close();
  70.             }
  71.             catch(Exception e){
  72.         }
  73.     }
  74.  
  75. }
  76.    
  77.     public static void EditProject(String name, String objective, String framework, int effort_Estimation){
  78.         Connection con=null;
  79.         PreparedStatement pstmt = null;
  80.         try{
  81.             Class.forName("com.mysql.jdbc.Driver");
  82.             con=DriverManager.getConnection("jdbc:mysql://localhost:3306/Collabsoft","root","");
  83.             String query ="Update project Set Objective=?, Framework=?, Effort_estimation=? where Title=? ";
  84.             pstmt = (PreparedStatement) con.prepareStatement(query);
  85.               pstmt.setString(1, objective); // set input parameter 1
  86.               pstmt.setString(2, framework); // set input parameter 2
  87.               pstmt.setInt(3, effort_Estimation);
  88.               pstmt.setString(4, name); // set input parameter 3
  89.               pstmt.executeUpdate();
  90.            
  91.         }
  92.        
  93.         catch(Exception e){
  94.             e.printStackTrace();
  95.         }
  96.        
  97.         finally{
  98.             try{
  99.                 if(con != null)
  100.                     con.close();
  101.             }
  102.             catch(Exception e){
  103.         }
  104.     }
  105.  
  106. }
  107.  
  108.     public static boolean CheckProject (String name){
  109.         Connection con=null;
  110.         PreparedStatement pstmt = null;
  111.         try{
  112.             Class.forName("com.mysql.jdbc.Driver");
  113.             con=DriverManager.getConnection("jdbc:mysql://localhost:3306/Collabsoft","root","");
  114.             String query ="Select Title from project ";
  115.             pstmt = (PreparedStatement) con.prepareStatement(query);
  116.             ResultSet rs = pstmt.executeQuery();
  117.             while (rs.next())
  118.             {
  119.                 String s=rs.getString(1);
  120.            
  121.                 if(s.equals(name))
  122.                 {
  123.                     return true;
  124.                    
  125.                    
  126.                 }
  127.                
  128.             }
  129.            
  130.         }
  131.        
  132.         catch(Exception e){
  133.             e.printStackTrace();
  134.         }
  135.        
  136.         finally{
  137.             try{
  138.                 if(con != null)
  139.                     con.close();
  140.             }
  141.             catch(Exception e){
  142.         }
  143.     }
  144.         return false;
  145. }
  146.     public static void insertSprints(String name, int proj_Id){
  147.        
  148.         Connection con=null;
  149.         PreparedStatement pstmt = null;
  150.        
  151.         try{
  152.             Class.forName("com.mysql.jdbc.Driver");
  153.             con=DriverManager.getConnection("jdbc:mysql://localhost:3306/Collabsoft","root","");
  154.             String query ="Insert into sprints (Title,Proj_ID) values (?,?)";
  155.             pstmt = (PreparedStatement) con.prepareStatement(query);
  156.               pstmt.setString(1, name); // set input parameter 1
  157.               pstmt.setInt(2, proj_Id);
  158.               pstmt.executeUpdate();
  159.            
  160.         }
  161.        
  162.         catch(Exception e){
  163.             e.printStackTrace();
  164.         }
  165.        
  166.         finally{
  167.             try{
  168.                 if(con != null)
  169.                     con.close();
  170.             }
  171.             catch(Exception e){
  172.         }
  173.     }
  174.  
  175. }  
  176.    
  177.     public static boolean CheckSprint (String name){
  178.         Connection con=null;
  179.         PreparedStatement pstmt = null;
  180.         try{
  181.             Class.forName("com.mysql.jdbc.Driver");
  182.             con=DriverManager.getConnection("jdbc:mysql://localhost:3306/Collabsoft","root","");
  183.             String query ="Select Title from sprints ";
  184.             pstmt = (PreparedStatement) con.prepareStatement(query);
  185.             ResultSet rs = pstmt.executeQuery();
  186.             while (rs.next())
  187.             {
  188.                 String s=rs.getString(1);
  189.            
  190.                 if(s.equals(name))
  191.                 {
  192.                     return true;
  193.                    
  194.                    
  195.                 }
  196.                
  197.             }
  198.            
  199.         }
  200.        
  201.         catch(Exception e){
  202.             e.printStackTrace();
  203.         }
  204.        
  205.         finally{
  206.             try{
  207.                 if(con != null)
  208.                     con.close();
  209.             }
  210.             catch(Exception e){
  211.         }
  212.     }
  213.         return false;
  214. }
  215.    
  216.     public static void UpdateSprint(String name, java.sql.Date start, java.sql.Date end,long duration){
  217.        
  218.         Connection con=null;
  219.         PreparedStatement pstmt = null;
  220.        
  221.         try{
  222.             Class.forName("com.mysql.jdbc.Driver");
  223.             con=DriverManager.getConnection("jdbc:mysql://localhost:3306/Collabsoft","root","");
  224.             String query ="Update sprints set Start_date=?, End_Date=?, Duration=? where Title = ?";
  225.             pstmt = (PreparedStatement) con.prepareStatement(query);
  226.               pstmt.setString(4,name ); // set input parameter 1
  227.               pstmt.setDate(1, start); // set input parameter 2
  228.               pstmt.setDate(2, end);
  229.               pstmt.setLong(3, duration); // set input parameter 3
  230.               System.out.println(pstmt);
  231.               pstmt.executeUpdate();
  232.              
  233.            
  234.         }
  235.        
  236.         catch(Exception e){
  237.             e.printStackTrace();
  238.         }
  239.        
  240.         finally{
  241.             try{
  242.                 if(con != null)
  243.                     con.close();
  244.             }
  245.             catch(Exception e){
  246.         }
  247.     }
  248.  
  249. }
  250. }
  251.  
  252.  
  253.  
  254. ////////////////////////////////////////ShowSprint.class/////////////////////////////////
  255. package helloworld.hello;
  256.  
  257. import java.sql.Connection;
  258. import java.sql.DriverManager;
  259. import java.sql.ResultSet;
  260. import java.sql.Statement;
  261. import java.util.ArrayList;
  262. import java.util.List;
  263.  
  264.  
  265.  
  266. public class ShowSprint {
  267.    
  268.     static List entries;
  269.     static Connection con=null;
  270.     public static ShowSprint x= new ShowSprint();
  271.    
  272.     static{
  273.         try{
  274.         Class.forName("com.mysql.jdbc.Driver");
  275.         con=DriverManager.getConnection("jdbc:mysql://localhost:3306/Collabsoft","root","");
  276.         Statement st = con.createStatement();
  277.         ResultSet rs=st.executeQuery("Select * from sprints");
  278.         while(rs.next())
  279.         {
  280.             x.addEntry(new Sprint(rs.getString(2),rs.getString(3),rs.getString(4),rs.getString(5)));
  281.         }
  282.         }
  283.         catch(Exception e){
  284.             e.printStackTrace();
  285.         }
  286.        
  287.         finally{
  288.             try{
  289.                 if(con != null)
  290.                     con.close();
  291.             }
  292.             catch(Exception e){}
  293.         }
  294.     }
  295.    
  296.    
  297.     public ShowSprint(){
  298.         entries=new ArrayList();
  299.     }
  300.    
  301.     public static ShowSprint getSprints() {
  302.         return x;
  303.         }
  304.    
  305.     public static void addEntry(Sprint entry){
  306.         entries.add(entry);
  307.     }
  308.    
  309.     public List getEntries(){
  310.         return entries;
  311.     }
  312.  
  313.     }
  314.  
  315.  
  316.  
  317.  
  318. /////////////////////////////////Sprint.class///////////////////////////////////////////
  319.  
  320. package helloworld.hello;
  321.  
  322. public class Sprint {
  323.     private String title;
  324.     private String start_Date;
  325.     private String end_Date;
  326.     private String duration;
  327.    
  328.     public Sprint(String title, String start_Date, String end_Date, String duration)
  329.     {
  330.        
  331.         this.title = title;
  332.         this.start_Date = start_Date;
  333.         this.end_Date = end_Date;
  334.         this.duration = duration;
  335.     }
  336.    
  337.  
  338.     public String getTitle()
  339.     {
  340.         return title;
  341.     }
  342.    
  343.     public String getStart_Date()
  344.     {
  345.         return start_Date;
  346.     }
  347.  
  348.     public String getEnd_Date()
  349.     {
  350.         return end_Date;
  351.     }
  352.    
  353.     public String getDuration()
  354.     {
  355.         return duration;
  356.     }
  357. }
  358.  
  359.  
  360.  
  361. ///////////////////////////EditSprint.class////////////////////////////
  362. package helloworld.hello;
  363.  
  364. import java.sql.Date;
  365. import java.util.Calendar;
  366.  
  367. import org.apache.wicket.AttributeModifier;
  368. import org.apache.wicket.extensions.yui.calendar.DatePicker;
  369. import org.apache.wicket.markup.html.WebPage;
  370. import org.apache.wicket.markup.html.basic.Label;
  371. import org.apache.wicket.markup.html.form.Form;
  372. import org.apache.wicket.markup.html.form.TextField;
  373. import org.apache.wicket.markup.html.list.ListItem;
  374. import org.apache.wicket.markup.html.list.ListView;
  375. import org.apache.wicket.markup.html.panel.FeedbackPanel;
  376. import org.apache.wicket.model.CompoundPropertyModel;
  377. import org.apache.wicket.model.Model;
  378.  
  379. public class EditSprint extends WebPage {
  380.     private Model sprint;
  381.     private Model start_Date;
  382.     private Model end_Date;
  383.    
  384.     public EditSprint(){
  385.         ListView eachEntry = new ListView("eachEntry",
  386.                 ShowSprint.getSprints().getEntries()) {
  387.                 protected void populateItem(ListItem item) {
  388.                 item.setModel(new CompoundPropertyModel(item.getModelObject()));
  389.                 item.add(new AttributeModifier("class", true, new Model(item
  390.                         .getIndex() % 2 == 0 ? "even" : "odd")));
  391.                 item.add(new Label("title"));
  392.                 item.add(new Label("start_Date"));
  393.                 item.add(new Label("end_Date"));
  394.                 item.add(new Label("duration"));
  395.                 }
  396.                 };
  397.         FeedbackPanel feedback = new FeedbackPanel("msgs");
  398.         add(feedback);
  399.         Form form = new Form("f"){
  400.             protected void onSubmit()
  401.             {
  402.                 String s_Name=(String)sprint.getObject();
  403.                 java.sql.Date s_Date=(java.sql.Date)start_Date.getObject();
  404.                 java.sql.Date e_Date=(java.sql.Date)end_Date.getObject();
  405.                 long diff = e_Date.getTime()-s_Date.getTime();
  406.                 long days = diff/(1000 * 60 * 60 * 24);
  407.                 int proj_id=1;
  408.  
  409.                 if(s_Date.getTime()>e_Date.getTime())
  410.                 {
  411.                     error("You can't end the sprint before it starts");
  412.                 }
  413.  
  414.                 else if(s_Name==null)
  415.                 {
  416.                     error("Please fill the required fields");
  417.                 }
  418.                
  419.                 else if(MySQL.CheckSprint(s_Name)==false)
  420.                 {
  421.                     error("No Sprint with this name");
  422.                 }
  423.                
  424.                 else
  425.                 {
  426.                     MySQL.UpdateSprint(s_Name, s_Date, e_Date, days);
  427.                     SprintResult sprintResult = new SprintResult(s_Name,days);
  428.                     setResponsePage(sprintResult);
  429.                    
  430.                 }
  431.                
  432.                
  433.             }
  434.         };
  435.         Calendar cal = Calendar.getInstance();
  436.         sprint= new Model("");
  437.         TextField s = new TextField("title",sprint);
  438.         start_Date = new Model(cal.getTime());
  439.         TextField start = new TextField("Start Date",start_Date,Date.class);
  440.         end_Date = new Model(cal.getTime());
  441.         TextField end = new TextField("End Date",end_Date, Date.class);
  442.  
  443.         start.add(new DatePicker());
  444.         end.add(new DatePicker());
  445.         form.add(s);
  446.         form.add(start);
  447.         form.add(end);
  448.         add(eachEntry);
  449.         add(form);
  450.        
  451.     }
  452.  
  453. }
  454.  
  455.  
  456. //////////////////////////////////EditSprint.html//////////////////////
  457. <html>
  458. <head></head>
  459. <body>
  460.  
  461. <div style="position: absolute; width: 632px; height: 22px; z-index: 4; left: 20px; top: 155px" id="layer10">
  462. <head>
  463. <style type="text/css">
  464. tr.odd {background-color: Grey}
  465. tr.even {background-color: Red}
  466. </style>
  467. </head>
  468. <body>
  469. <table border="1" width="632" bordercolorlight="#000000" bordercolordark="#000000" style="border-collapse: collapse">
  470. <tr><th>Title</th><th>Start Date</th><th>End Date</th><th>Duration</th></tr>
  471.  
  472. <tr wicket:id="eachEntry">
  473. <td wicket:id="title">1</td>
  474. <td wicket:id="start_Date">Britney</td>
  475. <td wicket:id="end_Date">Spears</td>
  476. <td wicket:id="duration">376926</td>
  477. </tr>
  478. </table></body></div>
  479.  
  480. <div style="position: absolute; width: 237px; height: 22px; z-index: 4; left: 347px; top: 324px" id="layer5">
  481. <span wicket:id="msgs"></span></div>
  482. <form wicket:id="f">
  483. &nbsp;
  484. <body bgcolor="#C0C0C0"></body>
  485. <div style="position: absolute; width: 61px; height: 25px; z-index: 8; left: 268px; top: 454px" id="layer9">
  486.     End Date</div>
  487. <div style="position: absolute; width: 183px; height: 24px; z-index: 7; left: 364px; top: 454px" id="layer8">
  488. <input type="text" wicket:id="End Date" name="T2" size="20">
  489. &nbsp;</div>
  490. <div style="position: absolute; width: 83px; height: 35px; z-index: 6; left: 268px; top: 416px" id="layer7">
  491.     Start Date</div>
  492. <div style="position: absolute; width: 191px; height: 26px; z-index: 5; left: 361px; top: 418px" id="layer6">
  493. &nbsp;<input type="text" wicket:id="Start Date">
  494. &nbsp;</div>
  495. <div style="position: absolute; width: 571px; height: 22px; z-index: 4; left: 24px; top: 55px" id="layer4">
  496.     <font size="6" color="#FF0000">Edit Start Date and End Date of a Sprint</font></div>
  497. <div style="position: absolute; width: 43px; height: 22px; z-index: 3; left: 271px; top: 371px" id="layer3">
  498.     Title:</div>
  499. <div style="position: absolute; width: 38px; height: 26px; z-index: 2; left: 707px; top: 500px" id="layer2">
  500. <input type="submit" value="Edit"></div>
  501. <div style="position: absolute; width: 145px; height: 20px; z-index: 1; left: 364px; top: 372px" id="layer1">
  502. <input type="text" wicket:id="title" name="T1" size="27"></div>
  503. </form>
  504. </body>
  505. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement