Exemplo n.º 1
0
	app.controller('ProductController',function($scope,$state,AuthService,TimeService){
		$scope.pageSize = DEFAULT_PAGE_SIZE;
		$scope.pageIndex = 0;
		$scope.pages = [];
		$scope.totalCount = 0;
		$scope.isEdit=true;
		$scope.uid=AuthService.getUser();
		$scope.yearNew=TimeService.yearNew;
		$scope.timePrototype=TimeService.timePrototype;
		
		
		
		$scope.option_productTypes=[
		                  		       {name:'期货',value:'1'},
		                  		       {name:'期权',value:'2'},
		                  	     ];
		$scope.option_productStatuss=[
		                  		       {name:'待审核',value:'1'},
		                  		       {name:'未上市',value:'2'},
		                  		       {name:'上市',value:'3'},
		                  		       {name:'退市',value:'4'},
		                  	     ];
		
		$scope.option_marketIds=[
		                  		       {name:'Foreign_Exchange',value:'Foreign_Exchange'},
		                  		       {name:'Equity',value:'Equity'},
		                  		       {name:'Interest_Rate',value:'Interest_Rate'},
		                  		       {name:'Other',value:'Other'},
		                  	     ];
		$scope.option_currencys=[
		                  		       {name:'人民币',value:'CNY'},
		                  		       {name:'美元',value:'USD'},
		                  		       {name:'欧元',value:'EUR'},
		                  		       {name:'日元',value:'JPY'},
		                  		       {name:'澳元',value:'AUD'},
		                  		       {name:'英镑',value:'GBP'},
		                  		       {name:'港币',value:'HKD'},
		                  		       {name:'澳门币',value:'MOP'},
		                  		       {name:'韩元',value:'KRW'},
		                  		       {name:'瑞士法郎',value:'CHF'},
		                  		       {name:'加拿大元',value:'CAD'},
		                  		       {name:'其他',value:'OTH'},
		                  		   ];   
		$scope.option_priceModes=[
		                  		       {name:'价格',value:'0'},
		                  		       {name:'收益率',value:'1'},
		                  		       {name:'波动率',value:'2'},
		                  	     ];
		$scope.option_positionTypes=[
		                  		       {name:'净持仓',value:'1'},
		                  		       {name:'综合持仓',value:'2'},
		                  	     ];
		$scope.option_execTypes=[
		                  		       {name:'美式',value:'0'},
		                  		       {name:'欧式',value:'1'},
		                  		       {name:'Null',value:'2'},
		                  	     ];
		$scope.option_delivTypes=[
		                  		       {name:'滚动交割',value:'0'},
		                  		       {name:'集中交割',value:'1'},
		                  		       {name:'混合交割',value:'2'},
		                  	     ];
		$scope.option_delivModes=[
		                  		       {name:'现金',value:'1'},
		                  		       {name:'实物',value:'2'},
		                  	     ];
		$scope.option_underlyingTypes=[
		                  		       {name:'股票指数',value:'1'},
		                  		       {name:'利率',value:'2'},
		                  		       {name:'汇率',value:'3'},
		                  		       {name:'波动率指数',value:'4'},
		                  		       {name:'ETF',value:'5'},
		                  		       {name:'期货',value:'6'},
		                  	     ];
		$scope.option_cycleTypes=[
		                  		       {name:'日',value:'0'},
		                  		       {name:'周',value:'1'},
		                  		       {name:'月',value:'2'},
		                  	     ];
		$scope.countMinRange = function() {
			return $scope.totalCount == 0 ? 0 : $scope.pageSize*$scope.pageIndex+1;
		};
		$scope.countMaxRange = function() {
			return Math.min($scope.pageSize*($scope.pageIndex+1), $scope.totalCount);
		};

		$scope.todos = [];
		$scope.currTodoIndex = -1;
		$scope.currTodo = {
				    productId:'',
					productName:'',
					productType:'',
					marketId:'',
					currency:'',
					priceMode:'',
					productStatus:'',
					delivSeriesNum:'',
					cycleType:'',
					volumeMultiple:'',
					qtyUnit:'',
					positionType:'',
					delivMode:'',
					delivType:'',
					execType:'',
					underlyingId:'',
					underlyingName:'',
					underlyingType:'',
					hedgeId:'',
					operDate:'',
					operTime:'',
					operId:''
				};
		
		$scope.searchKeyword = '';
		$scope.sortByProductIdDESC = true;

		
		RemoteRetriver.constructor('TProductRepository', $scope.pageSize, true);
		RemoteCreater.constructor('TProductRepository', true);
		RemoteUpdater.constructor('TProductRepository', true);
		RemoteDeleter.constructor('TProductRepository', true);

		getTodos();

		$scope.onRefreshClick = function() {
			getTodos();
		};
		$scope.cancelClick=function(){
			$scope.currTodoIndex = -1;
			$scope.isEdit=true;
			$scope.currTodo = {
					    productId:'',
						productName:'',
						productType:'1',
						marketId:'Interest_Rate',
						currency:'CNY',
						priceMode:'0',
						productStatus:'3',
						delivSeriesNum:'',
						cycleType:'2',
						volumeMultiple:'',
						qtyUnit:'',
						positionType:'2',
						delivMode:'2',
						delivType:'1',
						execType:'2',
						underlyingId:'',
						underlyingName:'',
						underlyingType:'6',
						hedgeId:'',
						operDate:'',
						operTime:'',
						operId:''
					};
			$scope.currTodo.operDate=$scope.yearNew;
			$scope.currTodo.operTime=$scope.timePrototype;
			$scope.currTodo.operId=$scope.uid;
		}
		$scope.onAddClick = function() {
			$scope.currTodoIndex = -1;
			$scope.isEdit=false;
			$scope.currTodo = {
					    productId:'',
						productName:'',
						productType:'1',
						marketId:'Interest_Rate',
						currency:'CNY',
						priceMode:'0',
						productStatus:'3',
						delivSeriesNum:'',
						cycleType:'2',
						volumeMultiple:'',
						qtyUnit:'',
						positionType:'2',
						delivMode:'2',
						delivType:'1',
						execType:'2',
						underlyingId:'',
						underlyingName:'',
						underlyingType:'6',
						hedgeId:'',
						operDate:'',
						operTime:'',
						operId:''
					};
			$scope.currTodo.operDate=$scope.yearNew;
			$scope.currTodo.operTime=$scope.timePrototype;
			$scope.currTodo.operId=$scope.uid;
		};

		$scope.onSearchClick = function() {
			$scope.pageIndex = 0;
			getTodos();
		};

		$scope.onSortByProductIdASC = function() {
			$scope.sortByProductIdASC = !$scope.sortByProductIdASC;
			if($scope.pageIndex != 0) {
				$scope.pageIndex = 0;
			} else {
				getTodos();
			}
		};

		$scope.onItemClick = function(index) {
			$scope.isEdit=false;
			$scope.currTodoIndex = index;
			if(index >= 0 && index < $scope.todos.length) {
				$scope.currTodo = JSON.parse(JSON.stringify($scope.todos[index]));
			}
		};
		
		$scope.onSaveClick = function() {
			if($scope.currTodoIndex == -1) {
				RemoteCreater.create($scope.currTodo, function(errCode, errMsg) {
					if(errCode == 0) {
						alert('创建产品成功');
						$scope.currTodoIndex = -1;
						$scope.currTodo = {
								  productId:'',
									productName:'',
									productType:'',
									marketId:'',
									currency:'',
									priceMode:'',
									productStatus:'',
									delivSeriesNum:'',
									cycleType:'',
									volumeMultiple:'',
									qtyUnit:'',
									positionType:'',
									delivMode:'',
									delivType:'',
									execType:'',
									underlyingId:'',
									underlyingName:'',
									underlyingType:'',
									hedgeId:'',
									operDate:'',
									operTime:'',
									operId:''
								};
						$scope.currTodo.operDate=$scope.yearNew;
						$scope.currTodo.operTime=$scope.timePrototype;
						$scope.$apply();
						getTodos();
						$scope.cancelClick();
					} else {
						alert('ERROR: ' + errMsg);
					}
				});
			} else {
				RemoteUpdater.update($scope.currTodo.productId, $scope.currTodo, function(errCode, errMsg) {
					if(errCode == 0) {
						alert('更新产品成功');
						$scope.todos[$scope.currTodoIndex] = $scope.currTodo;
						$scope.cancelClick();
						$scope.$apply();
					} else {
						alert('ERROR: ' + errMsg);
					}
				});
			}
		};		

		$scope.onPartUpdateClick = function() {
			RemoteUpdater.partUpdate($scope.currTodo.productId, {content:$scope.currTodo.productName}, function(errCode, errMsg) {
				if(errCode == 0) {
					alert('更新产品成功');
					$scope.todos[$scope.currTodoIndex] = $scope.currTodo;
					$scope.$apply();
				} else {
					alert('ERROR: ' + errMsg);
				}
			});
		}

		$scope.onDeleteClick = function() {
			RemoteDeleter.deleter($scope.currTodo.productId, function(errCode, errMsg) {
				if(errCode == 0) {
					alert('删除产品成功');
					$scope.todos.splice($scope.currTodoIndex, 1);
					$scope.currTodoIndex = -1;
					$scope.currTodo = {
							    productId:'',
								productName:'',
								productType:'',
								marketId:'',
								currency:'',
								priceMode:'',
								productStatus:'',
								delivSeriesNum:'',
								cycleType:'',
								volumeMultiple:'',
								qtyUnit:'',
								positionType:'',
								delivMode:'',
								delivType:'',
								execType:'',
								underlyingId:'',
								underlyingName:'',
								underlyingType:'',
								hedgeId:'',
								operDate:'',
								operTime:'',
								operId:''
							};
					$scope.cancelClick();
					$scope.$apply();
					
				} else {
					alert('ERROR: ' + errMsg);
				}
			});
		};

		$scope.onPrevPageClick = function() {
			if($scope.pageIndex > 0) {
				$scope.pageIndex--;
			}
		};
		$scope.onNextPageClick = function() {
			if($scope.pageIndex < $scope.pages.indexOf($scope.pages.length-1)) {
				$scope.pageIndex++;
			}
		};
		$scope.onFirstPageClick = function() {
			if($scope.pages.length > 1) {
				$scope.pageIndex = 0;
			}
		};
		$scope.onLastPageClick = function() {
			if($scope.pages.length > 1) {
				$scope.pageIndex = $scope.pages.indexOf($scope.pages.length-1);
			}
		};

		$scope.$watch('pageSize', function(newVal, oldVal) {
			newVal = parseInt(newVal);
			if(newVal != oldVal) {
				$scope.pageSize = newVal;
				$scope.pageIndex = 0;
				getTodos();
			}
		});
		
		$scope.$watch('pageIndex', function(newVal, oldVal) {
			newVal = parseInt(newVal);
			if(newVal != oldVal) {
				$scope.pageIndex = newVal;
				getTodos();
			}
		});

		function getTodos() {
			RemoteRetriver.setPageSize($scope.pageSize);
			RemoteRetriver.clearSortFileds();
			RemoteRetriver.addSortFiled('productId', $scope.sortByProductIdASC ? RemoteRetriver.SORT_TYPE_DESC : RemoteRetriver.SORT_TYPE_ASC);
			if($scope.searchKeyword == '') {
				RemoteRetriver.query('findAll', [], $scope.pageIndex, retriveHandler);
			} else {
				RemoteRetriver.query('findByProductIdContaining', [$scope.searchKeyword], $scope.pageIndex, retriveHandler);
			}
		}
		function retriveHandler(errCode, errMsg, list, totalCount, pageCount) {
			if(errCode == 0) {
				$scope.todos = list;
				$scope.totalCount = totalCount;
				if($scope.pages.length != pageCount) {
					$scope.pages.splice(0, $scope.pages.length);
					for(var i = 0; i < pageCount; i++) {
						$scope.pages.push(i);
					}
				}
				$scope.$apply();
			} else {
				alert('ERROR: ' + errMsg);
				$state.go('logon.enter');
			}
		}
	}); 
    app.controller("MarkerStrategyController", function ($rootScope, $scope, UtilService, $state,AuthService) {
        var DEFAULT_PAGE_SIZE = 10;
        $scope.userId = AuthService.getUser();
        $scope.pageSize = DEFAULT_PAGE_SIZE;
        $scope.pageIndex = 0;
        $scope.pages = [];
        $scope.totalCount = 0;
        $scope.todos = [];

        $scope.countMinRange = function () {
            return $scope.totalCount == 0 ? 0 : $scope.pageSize * $scope.pageIndex + 1;
        };
        $scope.countMaxRange = function () {
            return Math.min($scope.pageSize * ($scope.pageIndex + 1), $scope.totalCount);
        };


        $scope.currTodoIndex = -1;
        $scope.currTodo = {
        		instrumentId : '',  
    			userId:'',
    			autoOffer:'',
    			autoRespAsking : '',
    			stepId : '',
    			offerType : '',
    			bidTrade:'',
    			askTrade:'',
    			bidAmount : '',
    			askAmount : '',
    			bidMax : '',
    			askMax : '',
    			spreadType:'',
    			bidOffset:'',
    			askOffset:'',
    			isActive : '',
    			remark : ''
        };
        $scope.searchKeyword = '';
        $scope.sortByInstrumentIdDESC = true;

        RemoteRetriver.constructor('MarkerStrategyRepository', $scope.pageSize, true);
        RemoteCreater.constructor('MarkerStrategyRepository', true);
        RemoteUpdater.constructor('MarkerStrategyRepository', true);
        RemoteDeleter.constructor('MarkerStrategyRepository', true);

        getTodos();


        $scope.onRefreshClick = function () {
            getTodos();
        };

        $scope.onAddClick = function () {
            $scope.currTodoIndex = -1;
            $scope.currTodo = {
            		instrumentId : '',
        			userId:AuthService.getUser(),
        			autoOffer:'',
        			autoRespAsking : '',
        			stepId : '',
        			offerType : '',
        			bidTrade:'',
        			askTrade:'',
        			bidAmount : '',
        			askAmount : '',
        			bidMax : '',
        			askMax : '',
        			spreadType:'',
        			bidOffset:'',
        			askOffset:'',
        			isActive : '',
        			remark : ''
            };
        };

        $scope.onSearchClick = function () {
            $scope.pageIndex = 0;
            getTodos();
        };

        $scope.onSortByInstrumentIdASC = function () {
            $scope.sortByInstrumentIdASC = !$scope.sortByInstrumentIdASC;
            if ($scope.pageIndex != 0) {
                $scope.pageIndex = 0;
            } else {
                getTodos();
            }
        };

        $scope.onItemClick = function (index) {
            $scope.currTodoIndex = index;
            if (index >= 0 && index < $scope.todos.length) {
                $scope.currTodo = JSON.parse(JSON.stringify($scope.todos[index]));
            }
        };

        $scope.onSaveClick = function () {
            if ($scope.currTodoIndex == -1) {
                RemoteCreater.create($scope.currTodo, function (errCode, errMsg) {
                    if (errCode == 0) {
                        alert('创建策略成功');
                        $scope.currTodoIndex = -1;
                        $scope.currTodo = {
                        		instrumentId : '',
                    			userId:AuthService.getUser(),
                    			autoOffer:'',
                    			autoRespAsking : '',
                    			stepId : '',
                    			offerType : '',
                    			bidTrade:'',
                    			askTrade:'',
                    			bidAmount : '',
                    			askAmount : '',
                    			bidMax : '',
                    			askMax : '',
                    			spreadType:'',
                    			bidOffset:'',
                    			askOffset:'',
                    			isActive : '',
                    			remark : ''
                        };
                        $scope.$apply();
                        getTodos();
                    } else {
                        alert('ERROR: ' + errMsg);
                    }
                });
            } else {
                RemoteUpdater.update($scope.currTodo.instrumentId, $scope.currTodo, function (errCode, errMsg) {
                    if (errCode == 0) {
                        var tmp = errCode;
                        $scope.todos[$scope.currTodoIndex] = $scope.currTodo;
                        $scope.$apply();
                        return tmp;
                    } else {
                        alert('ERROR: ' + errMsg);
                    }
                });
            }
        };

        $scope.onPartUpdateClick = function () {
            RemoteUpdater.partUpdate($scope.currTodo.instrumentId, {content: $scope.currTodo.instrumentName}, function (errCode, errMsg) {
                if (errCode == 0) {
                    alert('更新策略成功');
                    $scope.todos[$scope.currTodoIndex] = $scope.currTodo;
                    $scope.$apply();
                } else {
                    alert('ERROR: ' + errMsg);
                }
            });
        }

        $scope.onDeleteClick = function () {
            RemoteDeleter.deleter($scope.currTodo.instrumentId, function (errCode, errMsg) {
                if (errCode == 0) {
                    alert('删除策略成功');
                    $scope.todos.splice($scope.currTodoIndex, 1);
                    $scope.currTodoIndex = -1;
                    $scope.currTodo = {
                    		instrumentId : '',
                			userId:AuthService.getUser(),
                			autoOffer:'',
                			autoRespAsking : '',
                			stepId : '',
                			offerType : '',
                			bidTrade:'',
                			askTrade:'',
                			bidAmount : '',
                			askAmount : '',
                			bidMax : '',
                			askMax : '',
                			spreadType:'',
                			bidOffset:'',
                			askOffset:'',
                			isActive : '',
                			remark : ''
                    };
                    $scope.$apply();
                } else {
                    alert('ERROR: ' + errMsg);
                }
            });
        };
        {
        }

        $scope.onPrevPageClick = function () {
            if ($scope.pageIndex > 0) {
                $scope.pageIndex--;
            }
        };
        $scope.onNextPageClick = function () {
            if ($scope.pageIndex < $scope.pages.indexOf($scope.pages.length - 1)) {
                $scope.pageIndex++;
            }
        };
        $scope.onFirstPageClick = function () {
            if ($scope.pages.length > 1) {
                $scope.pageIndex = 0;
            }
        };
        $scope.onLastPageClick = function () {
            if ($scope.pages.length > 1) {
                $scope.pageIndex = $scope.pages.indexOf($scope.pages.length - 1);
            }
        };

        $scope.$watch('pageSize', function (newVal, oldVal) {
            newVal = parseInt(newVal);
            if (newVal != oldVal) {
                $scope.pageSize = newVal;
                $scope.pageIndex = 0;
                getTodos();
            }
        });

        $scope.$watch('pageIndex', function (newVal, oldVal) {
            newVal = parseInt(newVal);
            if (newVal != oldVal) {
                $scope.pageIndex = newVal;
                getTodos();
            }
        });
        function getTodos() {
            RemoteRetriver.setPageSize($scope.pageSize);
            RemoteRetriver.clearSortFileds();
            RemoteRetriver.addSortFiled('instrumentId', $scope.sortByInstrumentIdASC ? RemoteRetriver.SORT_TYPE_DESC : RemoteRetriver.SORT_TYPE_ASC);
            if ($scope.searchKeyword == '') {
                RemoteRetriver.query('findAll', [], $scope.pageIndex, retriveHandler);
            } else {
                RemoteRetriver.query('findByInstrumentIdContaining', [$scope.searchKeyword], $scope.pageIndex, retriveHandler);
            }
        }

        function retriveHandler(errCode, errMsg, list, totalCount, pageCount) {
            if (errCode == 0) {
                if ($scope.userId!=''){
                    $scope.todos = [];
                    for (var x in list){
                        if (list[x].userId==AuthService.getUser()){
                            $scope.todos.push(list[x]);
                        };
                    };
                } else {
                    $scope.todos =list;
                };
                $scope.totalCount = totalCount;
                if ($scope.pages.length != pageCount) {
                    $scope.pages.splice(0, $scope.pages.length);
                    for (var i = 0; i < pageCount; i++) {
                        $scope.pages.push(i);
                    }
                }
                $scope.$apply();
            } else {
                alert('ERROR: ' + errMsg);
                $state.go('logon.enter');

            }
        }
    });
Exemplo n.º 3
0
	app.controller('InstrumentController',function($scope,$state,TimeService,AuthService){
				var DEFAULT_PAGE_SIZE =5;
				$scope.yearNew=TimeService.yearNew;
				$scope.timePrototype=TimeService.timePrototype;
				$scope.uid=AuthService.getUser();
				$scope.isEdit=true;
				
				$scope.pageSizes=[
				       					{name:'5',value:'5'},
				       					{name:'10',value:'10'},
				       					{name:'20',value:'20'},
				       			 ];
				$scope.pageSize =DEFAULT_PAGE_SIZE;
				$scope.pageIndex = 0;
				$scope.pages = [];
				$scope.totalCount = 0;
				
				$scope.countMinRange = function() {
					return $scope.totalCount == 0 ? 0 : $scope.pageSize*$scope.pageIndex+1;
				};
				$scope.countMaxRange = function() {
					return Math.min($scope.pageSize*($scope.pageIndex+1), $scope.totalCount);
				};

				$scope.todos = [];
				$scope.currTodoIndex = -1;
				$scope.currTodo = {
					instrumentId:'',
					instrumentName:'',
					productId:'',
					productName:'',
					productType:'',
					createDate:'',
					openDate:'',
					endTradingDay:'',
					expireDate:'',
					startDelivDate:'',
					endDelivDate:'',
					optionSeriesId:'',
					optionType:'',
					strikePrice:'',
					instrumentStatus:'',
					basisPrice:'',
					isTrading:'',
					priceTick:'',
					operDate:'',
					operTime:'',
					operId:'',
				};
				$scope.option_optionTypes=[
					{name:'非期权',value:'0'},
					{name:'看涨期权',value:'1'},
					{name:'看跌期权',value:'2'},
				];
				$scope.option_productTypes=[
					{name:'期货',value:'1'},
					{name:'期权',value:'2'},
				];
				$scope.option_isTradings=[
					{name:'否',value:'0'},
					{name:'是',value:'1'},
				];
				$scope.option_instrumentStatuss=[
					{name:'未上市',value:'0'},
					{name:'上市',value:'1'},
					{name:'停牌',value:'2'},
					{name:'下市',value:'3'},
					{name:'终止',value:'4'},
				];
				$scope.desc=0;
				$scope.title='currTodo.openDate'
				$scope.searchKeyword = '';
				$scope.sortByInstrumentIdDESC = true;
				$scope.testText="hello";
				
				RemoteRetriver.constructor('TInstrumentRepository', $scope.pageSize, true);
			
				RemoteCreater.constructor('TInstrumentRepository', true);
				
				RemoteUpdater.constructor('TInstrumentRepository', true);
			
				RemoteDeleter.constructor('TInstrumentRepository', true);
				

				getTodos();
				function getTodos() {
					RemoteRetriver.setPageSize($scope.pageSize);
					RemoteRetriver.clearSortFileds();
					RemoteRetriver.addSortFiled('instrumentId', $scope.sortByInstrumentIdASC ? RemoteRetriver.SORT_TYPE_DESC : RemoteRetriver.SORT_TYPE_ASC);
					if($scope.searchKeyword == '') {
						RemoteRetriver.query('findAll', [], $scope.pageIndex, retriveHandler);
					} else {
						RemoteRetriver.query('findByInstrumentIdContaining', [$scope.searchKeyword], $scope.pageIndex, retriveHandler);
					}
				}

				$scope.onRefreshClick = function() {
					getTodos();
				};
				$scope.cancelClick=function(){
					$scope.isEdit=true;
					$scope.currTodoIndex = -1;
					$scope.currTodo = {
						instrumentId:'',
						instrumentName:'',
						productId:'',
						productName:'',
						productType:'1',
						createDate:'',
						openDate:'',
						endTradingDay:'',
						expireDate:'',
						startDelivDate:'',
						endDelivDate:'',
						optionSeriesId:'',
						optionType:'0',
						strikePrice:'',
						instrumentStatus:'1',
						basisPrice:'',
						isTrading:'1',
						priceTick:'',
						operDate:'',
						operTime:'',
						operId:'',
					};
					$scope.currTodo.operDate=$scope.yearNew;
					$scope.currTodo.operTime=$scope.timePrototype;
					$scope.currTodo.operId=$scope.uid;
				}
				$scope.onAddClick = function() {
					$scope.isEdit=false;
					$scope.currTodoIndex = -1;
					$scope.currTodo = {
						instrumentId:'',
						instrumentName:'',
						productId:'',
						productName:'',
						productType:'1',
						createDate:'',
						openDate:'',
						endTradingDay:'',
						expireDate:'',
						startDelivDate:'',
						endDelivDate:'',
						optionSeriesId:'',
						optionType:'0',
						strikePrice:'',
						instrumentStatus:'1',
						basisPrice:'',
						isTrading:'1',
						priceTick:'',
						operDate:'',
						operTime:'',
						operId:'',
					};
					$scope.currTodo.operDate=$scope.yearNew;
					$scope.currTodo.operTime=$scope.timePrototype;
					$scope.currTodo.operId=$scope.uid;
				};

				$scope.onSearchClick = function() {
					$scope.pageIndex = 0;
					getTodos();
				};

				$scope.onSortByInstrumentIdASC = function() {
					$scope.sortByInstrumentIdASC = !$scope.sortByInstrumentASC;
					if($scope.pageIndex != 0) {
						$scope.pageIndex = 0;
					} else {
						getTodos();
					}
				};

				$scope.onItemClick = function(index) {
					$scope.isEdit=false;
					$scope.currTodoIndex = index;
					if(index >= 0 && index < $scope.todos.length) {
						$scope.currTodo = JSON.parse(JSON.stringify($scope.todos[index]));
					}
				};

				$scope.onSaveClick = function() {
					if($scope.currTodoIndex == -1) {
						RemoteCreater.create($scope.currTodo, function(errCode, errMsg) {
							if(errCode == 0) {
								alert('创建合约成功');
								$scope.currTodoIndex = -1;
								$scope.currTodo = {
									instrumentId:'',
									instrumentName:'',
									productId:'',
									productName:'',
									productType:'',
									createDate:'',
									openDate:'',
									endTradingDay:'',
									expireDate:'',
									startDelivDate:'',
									endDelivDate:'',
									optionSeriesId:'',
									optionType:'',
									strikePrice:'',
									instrumentStatus:'',
									basisPrice:'',
									isTrading:'',
									priceTick:'',
									operDate:'',
									operTime:'',
									operId:'',
								};
								$scope.currTodo.operDate=$scope.yearNew;
								$scope.currTodo.operTime=$scope.timePrototype;
								$scope.cancelClick();
								$scope.$apply();
								getTodos();
							} else {
								alert('ERROR: ' + errMsg);
							}
						});
					} else {
						RemoteUpdater.update($scope.currTodo.instrumentId, $scope.currTodo, function(errCode, errMsg) {
							if(errCode == 0) {
								alert('更新合约成功');
								$scope.todos[$scope.currTodoIndex] = $scope.currTodo;
								$scope.cancelClick();
								$scope.$apply();
							} else {
								alert('ERROR: ' + errMsg);
							}
						});
					}
				};

				$scope.onPartUpdateClick = function() {
					RemoteUpdater.partUpdate($scope.currTodo.instrumentId, {content:$scope.currTodo.instrumentName}, function(errCode, errMsg) {
						if(errCode == 0) {
							alert('更新合约成功');
							$scope.todos[$scope.currTodoIndex] = $scope.currTodo;
							$scope.$apply();
						} else {
							alert('ERROR: ' + errMsg);
						}
					});
				}

				$scope.onDeleteClick = function() {
					RemoteDeleter.deleter($scope.currTodo.instrumentId, function(errCode, errMsg) {
						if(errCode == 0) {
							alert('删除合约成功');
							$scope.todos.splice($scope.currTodoIndex, 1);
							$scope.currTodoIndex = -1;
							$scope.currTodo = {
								instrumentId:'',
								instrumentName:'',
								productId:'',
								productName:'',
								productType:'',
								createDate:'',
								openDate:'',
								endTradingDay:'',
								expireDate:'',
								startDelivDate:'',
								endDelivDate:'',
								optionSeriesId:'',
								optionType:'',
								strikePrice:'',
								instrumentStatus:'',
								basisPrice:'',
								isTrading:'',
								priceTick:'',
								operDate:'',
								operTime:'',
								operId:'',
							};
							$scope.cancelClick();
							$scope.$apply();
						} else {
							alert('ERROR: ' + errMsg);
						}
					});
				};
				
				$scope.onPrevPageClick = function() {
					if($scope.pageIndex > 0) {
						$scope.pageIndex--;
					}
				};
				$scope.onNextPageClick = function() {
					if($scope.pageIndex < $scope.pages.indexOf($scope.pages.length-1)) {
						$scope.pageIndex++;
					}
				};
				$scope.onFirstPageClick = function() {
					if($scope.pages.length > 1) {
						$scope.pageIndex = 0;
					}
				};
				$scope.onLastPageClick = function() {
					if($scope.pages.length > 1) {
						$scope.pageIndex = $scope.pages.indexOf($scope.pages.length-1);
					}
				};

				$scope.$watch('pageSize', function(newVal, oldVal) {
					newVal = parseInt(newVal);
					if(newVal != oldVal) {
						$scope.pageSize = newVal;
						$scope.pageIndex = 0;
						getTodos();
					}
				});

				$scope.$watch('pageIndex', function(newVal, oldVal) {
					newVal = parseInt(newVal);
					if(newVal != oldVal) {
						$scope.pageIndex = newVal;
						getTodos();
					}
				});


				function retriveHandler(errCode, errMsg, list, totalCount, pageCount) {
					if(errCode == 0) {
						$scope.todos = list;
						$scope.totalCount = totalCount;
						if($scope.pages.length != pageCount) {
							$scope.pages.splice(0, $scope.pages.length);
							for(var i = 0; i < pageCount; i++) {
								$scope.pages.push(i);
							}
						}
						$scope.$apply();
					} else {
						alert('ERROR: ' + errMsg);
						$state.go('logon.enter');
					}
				}
			});