[VB.NET] Time difference and summation of time


Description
       this article will help you you , how to summation of time and time diference between 2 time, of course you can modified based on what you need. this example below using 12h format, but will return 24h format.

HowTo
time 1 : 09:30:30 AM (it's string use textbox) as lowtime
time 2 : 07:15:15 PM (it's string use textbox) as hightime

Here's the function for time difference

    Public Function timeDifference(ByVal lowtime As Date, ByVal hightime As Date)
        Dim hours, minutes, seconds
        hours = CStr(Math.Floor((hightime - lowtime).TotalHours)).PadLeft(2, "0")
        minutes = CStr(Math.Floor(((hightime - lowtime).TotalMinutes) Mod 60)).PadLeft(2, "0")
        seconds = CStr(Math.Floor(((hightime - lowtime).TotalSeconds) Mod 60)).PadLeft(2, "0")
        MsgBox(hours & ":" & minutes & ":" & seconds)
    End Function


Here's the function for summation of time

    Public Function summationOfTime(ByVal lowtime As String, ByVal hightime As String)
        Dim timespanLowtime, timespanHightime, timespanSum As TimeSpan
        timespanLowtime = TimeSpan.Parse(lowtime)
        timespanHightime = TimeSpan.Parse(hightime)
        timespanSum = timespanLowtime + timespanHightime
        MsgBox(timespanSum.ToString)
    End Function

don't worry , the function above is well format :D

[Cakephp] Component

Description
      What is component ? component is a separate class or function from cakephp that define by user. it's very usefull if you have class that you want to include in cakephp.

How To
1. Create file component in : app/controller/component/[your files here].
the rules : - name file same as name class
               - the class must extend "component"
               - outside class must be define : App::uses('Component', 'Controller');

for example i want to create custom function for ACL (access control list) :
[1]. create file with name : AclComponent.php
    // the path : app/controller/component/AclComponent.php
[2]. copy paste the code below :
 <?php   
 App::uses('Component', 'Controller');  
 class AclComponent extends Component {  
   public function authorization($role)   
   {  
     switch($role)  
     {  
     case 'ADMIN':   
       return true;  
       break;   
     case 'ROLE1':  
       return false;  
       break;   
     case 'ROLE2':   
       return false;  
       break;  
     }       
   }  
 }  
 ?>  

2. Include your custom class (component) on variable $components, make sure $components declare on app controller , so you not always declare $components in every controller.
 public $components = array('Acl','DebugKit.Toolbar','Session',......);  

3. Now you can access components in any controller , for example because we create ACL we can validate every user from the role they have in beforeFilter function. here's my custom code using for ACL.

 public function beforeFilter(){  
     parent::beforeFilter();  
     // ACL Function based on role  
     if($this->Acl->authorization('YOUR ROLE HERE'))  
     {  
       //if true then do nothing or bypass  
     }  
     else  
     {  
       // if false then force to logout (user attempt hijack from URL)  
       $this->redirect(array('controller'=>'auth','action'=>'logout'));  
     }  
   }  

done , that's all how to create a component using cakephp

[Cakephp-Template] Template Header using Bootstrap


Description
     this template is use for me :D

How to

CSS
#header
{
    padding:12px 0px 12px 0px;
    border: 2px 0px 0px 0px inset white;
    background-color: #296f87;
}

#headerLogo
{
    display: inline-block;
    color:white;
    font-weight: bolder;
    font-size: 16px;
}



HTML
<div id="header">
    <div style="width:87%;margin:auto">
        <div id="headerLogo">LOGO - </div>
        <div id="headerLogo">Traffic Promo Non Air Time Consume</div>
    </div>
</div>

<div class="navbar navbar-default" role="navigation" style="margin:0px">
    <div style="width:87%;margin:auto">
        <div class="navbar-header">
          <a class="navbar-brand" href="#">NATC</a>
        </div>

        <nav style="margin:auto" >
             <ul id="navbar-id" class="nav navbar-nav">
                <li id="index" class="active"><a href="<?php echo $this->Html->url(array('controller'=>'main','action'=>'index')) ?>"><span class="glyphicon glyphicon-home" aria-hidden="true"></span> Home</a></li>
                <li id="search"><a href="<?php echo $this->Html->url(array('controller'=>'main','action'=>'search')) ?>"><span class="glyphicon glyphicon-search" aria-hidden="true"></span> Search Data</a></li>
                <li id="master"><a href="<?php echo $this->Html->url(array('controller'=>'master','action'=>'index')) ?>"><span class="glyphicon glyphicon-hdd" aria-hidden="true"></span> Master Data</a></li>
                <li id="admin"><a href="<?php echo $this->Html->url(array('controller'=>'admin','action'=>'index')) ?>"><span class="glyphicon glyphicon-wrench" aria-hidden="true"></span> Administrator</a></li>
              </ul>
        </nav>

        <ul class="nav navbar-nav navbar-right">
            <li>
                <div style="padding-top:9%;height:50px">
                    <button onclick="logout()" type="button" class="btn btn-danger">
                        <span class="glyphicon glyphicon-off" aria-hidden="true"></span>
                        Logout
                    </button>
                </div>
            </li>
        </ul>
    </div>
</div>

[Cakephp-Template] table pagination + Jquery + bootstrap

Description
       this template is use for me :)

How to

CSS
tr
{ /* make sure change cursor when over row , it looks like profesional LOL */
    cursor: pointer;
    cursor: hand;
}

#rowtable:hover
{
    background:#a0dfff;
}

#rowtable.clicked
{ /*it means id='rowtable' class='clicked'*/
    background:#00bfff;
}



Javascript
$().ready(function(){
    $('tr').click(function() {
               $(this).removeClass("clicked");
               $(this).addClass("clicked").siblings().removeClass("clicked");
   });
});

HTML
<div id="container">
          <h2 class="page-header">View User</h2>
          <div class="pagination pagination-large">
            <ul class="pagination">
                <?php
                    echo $this->Paginator->prev(__('prev'), array('tag' => 'li'), null, array('tag' => 'li','class' => 'disabled','disabledTag' => 'a'));
                    echo $this->Paginator->numbers(array('separator' => '','currentTag' => 'a', 'currentClass' => 'active','tag' => 'li','first' => 1));
                    echo $this->Paginator->next(__('next'), array('tag' => 'li','currentClass' => 'disabled'), null, array('tag' => 'li','class' => 'disabled','disabledTag' => 'a'));
                ?>
            </ul>
          </div>
          <table style="margin:0 auto" class="table table-bordered">
              <tr>
                  <th>Username</th>
                  <th>Fullname</th>
                  <th>Role</th>
                  <th>Last Login</th>
                  <th>Login IP Address</th>
                  <th>Status</th>
                  <th>Action</th>
              </tr>
           
              <tr id="rowtable">
                  <td>Admin</td>
                  <td>Mahendra M.W.</td>
                  <td>Administrator</td>
                  <td>10-12-2014</td>
                  <td>xx.xx.xx.xx</td>
                  <td>Aktif</td>
                  <td style="text-align:center">
                      <a class="btn btn-primary" style="width:80px;">Edit</a>
                      <a class="btn btn-primary" style="width:80px;">Disabled</a>
                  </td>
              </tr>
           
              <tr>
                  <th colspan="16" style="text-align:left">
                      <?php echo 'Page '.$this->Paginator->counter(array(
                      'separator' => ' of '
                      ));?>
                  </th>
              </tr>
           </table>
           <?php echo $this->Js->writeBuffer(); ?>
      </div>