checking time overlap

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • narinas
    New Member
    • Jan 2012
    • 20

    #1

    checking time overlap

    Hello

    I have checked the overlapping of time by taking the values into an array and sorting them.
    here im unable to insert data into cells when the cells are empty!

    my code:
    Code:
    <script>
    function compare_row_time()
    {
      var all_times= new Array();
      var flag_check=false;
      var count_times=0;
      for(var i=0;i<mygrid.getRowsNum();i++)
      {
        var time_1=mygrid.cells2(i,1).getValue();//starttime value of i
        var time_2=mygrid.cells2(i,2).getValue();//endtime value of i
        all_times[count_times]=time_1;
        count_times++;
        all_times[count_times]=time_2;
        count_times++;
      }
      var sort_times= new Array();
      sort_times=all_times.sort();
      for(var j=0; j<sort_times.length;j++)
      {
        if(sort_times[j]==sort_times[j+1])
         {
           flag_check=true;//if false data is inserted even it is wrong.
         }
      }
       return flag_check;
    }   
    
    function save()
    {
      if(!compare_row_time())
       {
        myDataProcessor.sendData();//sending data to server
       }
      if(err_str!="")//error_msg
      alert(err_str);
       err_str="";
    }
    </script>
    1.Here in sort_times array if any duplicate values are present it will show error(this is only working when im checking with existing data in grid)
    2.If im inserting new values into empty rows im not able to send data(if i change flag_check to false in [sort_times array]im able to insert values but if i give duplicate values also the data is getting inserted.this condition is false)
    3.My pattern for time is user can enter time as 05:00 or 5:00 (if one row is having 5:00 & another row is having 05:00 it is not comparing; if the pattern is of same type it is checking for duplicates)
    4.How can i highlight the duplicates cells & provide a message for it.

    could anyone please reconstruct the above code without these errors.




    thank you.
    Regards
    Narina
  • narinas
    New Member
    • Jan 2012
    • 20

    #2
    i have checked the loop with counters and alerted the time_1 & time_2 values
    im getting as output as
    for loop j:
    counter from 0 to 7
    time_1 time_2
    6:00 undefined
    16:02 7:00
    8:00 16:30
    17:00 09:00
    18:02
    but actual data is

    time_1 time_2
    6:00 7:00
    16:02 16:30
    8:00 9:00
    17:00 18:02

    when im alerting message for overlapped cell its showing alert for last row every time,
    the problem is with setting flag_status=tru e;

    Comment

    Working...