DpsbTypeAction.class.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. class DpsbTypeAction extends CommonAction {
  3. const tableName = 'dpsb_type';
  4. const pkName = 'ID';
  5. function sys_list( ){
  6. $list = new \Jms\Gui\ClGrid();
  7. $list->right_filter = function($right,$type){
  8. $page = $_SERVER['PATH_INFO'];
  9. return \Jms\Ucenter\Right::defaultFilter($page,$right,$type);
  10. };
  11. $list->display($this);
  12. }
  13. function sys_addedit( ){
  14. $form = new \Jms\Gui\ClForm();
  15. $form->before_add = function(&$data){
  16. $data['TypeName'] = trim($data['TypeName']);
  17. $data['DeviceModel'] = trim($data['DeviceModel']);
  18. //检查设备型号是否重复
  19. $where = array('TypeName'=>$data['TypeName'],'DeviceModel'=>$data['DeviceModel']);
  20. $count = M('dpsb_type')->where($where)->count();
  21. if($count > 0){
  22. json_fail('设备型号已存在');
  23. }
  24. };
  25. $form->before_modify = function(&$data){
  26. $id = I('get.id');
  27. $data['TypeName'] = trim($data['TypeName']);
  28. $data['DeviceModel'] = trim($data['DeviceModel']);
  29. $where = array('TypeName'=>$data['TypeName'],'DeviceModel'=>$data['DeviceModel'],'ID'=>array('neq',$id));
  30. $count = M('dpsb_type')->where($where)->count();
  31. if($count > 0){
  32. json_fail('设备型号已存在');
  33. }
  34. };
  35. $form->display($this);
  36. }
  37. public function sys_del( ){
  38. $grid = new \Jiaruan\GridData();
  39. $grid->before_delete = function(&$data){
  40. $where = array('DeviceTypeId' => $data['ID']);//检查是否有设备存在
  41. $count = M('dpsb_device')->where($where)->count();
  42. if($count > 0){
  43. json_fail('该类型下有设备在使用,不能删除');
  44. }
  45. };
  46. $grid->deleteByPk($this);
  47. }
  48. }