⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 datagridtest.js

📁 Bindows 1.01 完全版 Bindows 框架提供给你: 基于类的面向对象 API; 一个完整的窗口系统
💻 JS
字号:
// define constructorfunction DataGridTest() {	var win = application.getWindow();	var leftPane = new BiComponent;	var label = new BiLabel("Enter an SQL statement:");	var ta = new BiTextArea;	var b = new BiButton("Execute");	var g = new BiGrid;	var splitPane = new BiSplitPane("horizontal", leftPane, g)	var statusBar = new BiStatusBar;	var status = new BiStatusBarPanel("Ready");	var timeStatus = new BiStatusBarPanel;	var sizeStatus = new BiStatusBarPanel;	var xmlDataSet = new BiXmlDataSet;	var xmlLoader = new BiXmlLoader;	var cb = new BiComboBox(["select * from categories", "show tables"]);	label.setMnemonic("s");	label.setLabelFor(ta);	b.setMnemonic("x");	ta.setTabIndex(1);	b.setTabIndex(2);	g.setTabIndex(3);	cb.setTabIndex(3);	splitPane.setDividerLocation( 200 );	xmlLoader.setAsync(true);	timeStatus.setAlign("right");	sizeStatus.setAlign("right");	leftPane.add(label);	leftPane.add(ta);	leftPane.add(cb);	leftPane.add(b);	win.add(splitPane);	statusBar.add(status);	statusBar.add(timeStatus);	statusBar.add(sizeStatus);	win.add(statusBar);	splitPane.setLocation(0,0);	splitPane.setRight(0);	splitPane.setBottom( statusBar.getHeight() );	label.setLocation(5,5);	label.setRight(5);	ta.setLocation(4, 21);	ta.setRight(1);	ta.setBottom(65);	cb.setLeft(4);	cb.setRight(1);	cb.setBottom(40);	b.setBottom(5);	status.setLeft(0);	status.setRight(100);	timeStatus.setWidth(48);	timeStatus.setRight(50);	sizeStatus.setWidth(48);	sizeStatus.setRight(0);	this._textArea = ta;	this._historyCombo = cb;	this._executeButton = b	this._grid = g;	this._status = status;	this._timeStatus = timeStatus;	this._sizeStatus = sizeStatus;	this._xmlDataSet = xmlDataSet;	this._xmlLoader = xmlLoader;	this._uiTimer = new BiTimer(10);	this._uiTimer2 = new BiTimer(10);	this._uiTimer.addEventListener("tick", this._onUiTimerTick, this);	this._uiTimer2.addEventListener("tick", this._onUiTimer2Tick, this);	leftPane.addEventListener( "resize" , this.centerButton, this);	this._xmlLoader.addEventListener("load", this._onXmlDocLoaded, this);	this._executeButton.addEventListener( "action", this.executeQuery, this);	cb.addEventListener( "change", this.onHistoryChange, this);	ta.setAccessKey("s");	b.setAccessKey("x");	// we need to position the button now	this.centerButton();	cb.setSelectedIndex(0);}DataGridTest.BASE_URI = "../../../services/sql.aspx?q=";//DataGridTest.BASE_URI = "http://www.bindows.net/services/sql.aspx?q=";// define static main methodDataGridTest.main = function () {	new DataGridTest();};DataGridTest.prototype.centerButton = function () {	var w = this._executeButton.getWidth();	var aw = this._executeButton.getParent().getClientWidth();	this._executeButton.setLeft( (aw - w) / 2 )};DataGridTest.prototype.executeQuery = function () {	this._textArea.setEnabled(false);	this._executeButton.setEnabled(false);	this._historyCombo.setEnabled(false);	this._grid.setEnabled(false);	this._xmlLoader.setUri( DataGridTest.BASE_URI +						    encodeURIComponent( this._textArea.getText() ) );	this._xmlLoader.load();	// update combo	var v = this._textArea.getText();	var s = v.replace(/\n|(\r\n)/g, " ");	var item = this._historyCombo.findStringExact( s );	if (item) {		this._historyCombo.remove(item);	}	else {		item = new BiComboBoxItem(s, v);	}	this._historyCombo.add(item);	item.setSelected(true);	// update status	this._status.setText( "Executing query and loading result..." );	this._timeStatus.setText("");	this._sizeStatus.setText("");	this._startLoadTime = new Date;};DataGridTest.prototype._onXmlDocLoaded = function (e) {	var loadTime = new Date - this._startLoadTime;	this._timeStatus.setText( Math.round(loadTime / 100) / 10 + "s" );	this._status.setText( "Data loaded..." );	if ( this._xmlLoader.getError() ) {		this._status.setText( "Error executing result..." );		this._timeStatus.setText( Math.round(loadTime / 100) / 10 + "s" );		this._sizeStatus.setText("");		this.restoreUi();	}	else {		var doc = this._xmlLoader.getDocument();		this._xmlDataSet.fromXmlNode( doc );		this._uiTimer.start();	}};DataGridTest.prototype._onUiTimerTick = function (e) {	this._uiTimer.setEnabled(false);	var loadTime = new Date - this._startLoadTime;	this._timeStatus.setText( Math.round(loadTime / 100) / 10 + "s" );	this._status.setText( "Data Set Created..." );	this._sizeStatus.setText( this._xmlDataSet.getTables()[0].getColumns().length +							  "x" + this._xmlDataSet.getTables()[0].getRows().length );	this._uiTimer2.start();};DataGridTest.prototype._onUiTimer2Tick = function (e) {	this._uiTimer2.setEnabled(false);	this._grid.setDataSource( this._xmlDataSet );	this._grid.dataBind();	var loadTime = new Date - this._startLoadTime;	this._timeStatus.setText( Math.round(loadTime / 100) / 10 + "s" );	this._status.setText( "Result succesfully executed and loaded" );	this.restoreUi();};DataGridTest.prototype.restoreUi = function () {	this._textArea.setEnabled(true);	this._executeButton.setEnabled(true);	this._historyCombo.setEnabled(true);	this._grid.setEnabled(true);	var loadTime = new Date - this._startLoadTime;	this._timeStatus.setText( Math.round(loadTime / 100) / 10 + "s" );	this._textArea.selectAll();	this._textArea.setFocused(true);};DataGridTest.prototype.onHistoryChange = function (e) {	var item = this._historyCombo.getSelectedItem();	if (item)		this._textArea.setText( item.getValue() || item.getText() );};

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -