//********私有,根据新的数据计算每类商品的价值及全部商品的总价 function Calculate(){ for($i=0;$i<$this->SortCount;$i++){ $this->Cost[$i]=$this->Price[$i]*$this->Count[$i]; $this->TotalCost += $this->Cost[$i]; } }
//**************以下为接口函数
//*** 加一件商品 // 判断是否蓝中已有,如有,加count,否则加一个新商品 //首先都是改session的值,然后再调用update() and calculate()来更新成员变量 function AddOne($id,$na,$pr){ global $sId,$sName,$sPrice,$sCount;
//改变商品的个数 function ModifyCount($i,$ncount){ global $sCount;
$sCount[$i]=$ncount;
$this->Update(); $this->Calculate();
}
//清空一种商品 function EmptyOne($i){ global $sCount;
$sCount[$i]=0;
$this->Update(); $this->Calculate(); }
/*************************** 清空所有的商品
因为在win里PHP不支持session_destroy()函数,所以这个清空函数不完善, 只是把每种商品的个数置为0。 如果是在linux下,可以直接用session_destroy()来做。 *****************************/ function EmptyAll(){ global $sId,$sName,$sPrice,$sCount;