Thursday, October 15, 2015

Date Overlap Logic And How to Use Array And loop iterations for tabular form rows validation:-

public void Apply()
    {
       
        JegPaBillRatesVOImpl vo=getJegPaBillRatesVO();
        Date StartDate = (Date)vo.getCurrentRow().getAttribute("EffectiveEndDate");
        int flag=0;
    Date EndtDate = (Date)vo.getCurrentRow().getAttribute("EffectiveEndDate");
        System.out.println("StartDate= "+StartDate);

           
       /* if(StartDate.dateValue().getTime() == EndtDate.dateValue().getTime())
        {
        System.out.println("Inside date validation and throw error messages");
        }*/
       
       
        //VO Instance
        JegPaBillRatesDtlVOImpl vo1= getJegPaBillRatesDtlVO();              
     int Total_rows = vo1.getFetchedRowCount();         
        System.out.println("Tatal line rows "+Total_rows);
       
     
 //Row Instance
   JegPaBillRatesDtlVORowImpl row=null;        
        if(Total_rows>0)
        {
            System.out.println("Tatal rows greter than 0 is "+Total_rows);           
            //Array Declaration
            String sequence1[] = new String[Total_rows];
             Date  StartDate3[] = new Date[Total_rows];
             Date  EndDate3[] = new Date[Total_rows];                     
            // Loop Code For Tabular Rows Validations        
//RowSetIterator Instanc
           RowSetIterator Iter = vo1.createRowSetIterator("Iter");
//Set row range to zero, to traverse from beginning of VO rows collection
            Iter.setRangeStart(0); 
            Iter.setRangeSize(Total_rows);
                   
            for (int i = 0; i < Total_rows; i++)
             {
//Insert Data In To Array

                    row = (JegPaBillRatesDtlVORowImpl)Iter.getRowAtRangeIndex(i);                
                          sequence1[i] = row.getId1().toString();
                          StartDate3[i] = (Date)row.getEffectiveStartDate();
                          EndDate3[i] = (Date)row.getEffectiveEndDate();                          
                         
                          System.out.println(" Outside Exception  StartDate: "+StartDate3[i]);
                          System.out.println(" Outside Exception  EndDate: "+EndDate3[i]);
                          System.out.println(" Outside Exception  sequence1: "+sequence1[i]);
                                  
             }
            //Close row set iterator.           
             Iter.closeRowSetIterator();  
                     
            for (int i = 0; i < Total_rows; i++)
              {
                   for (int j = i + 1; j < Total_rows; j++)
                       {
                            java.sql.Date javaSqlDate;                             
                            javaSqlDate  = EndDate3[i].dateValue();
                           
                              if ((!sequence1[i].equals(sequence1[j])) &&
                                     (StartDate3[j].dateValue().getTime() <= EndDate3[i].dateValue().getTime() )     
                                 )
                                 { 
                                     flag ++;
                                     System.out.println("Dates are wrong ");
                                 }
                          }
              }
                      
                     
         

                   
        }
       
        if (flag!= 0 )
           {
         
           throw new OAException("Date Cannot be Overlap. Please reenter.",
                                                (byte)0);
            }
          else
           {
                    getTransaction().commit();
             
           }
       
     

    } // End of Apply Method

No comments:

Post a Comment