You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
251 lines
7.0 KiB
251 lines
7.0 KiB
|
|
define(function (require, exports, module) {
|
|
var BaseWindow = require('system/views/pages/window');
|
|
var tpl = require('text!./scriptwin3.tpl');
|
|
require('css!./scriptwin3.css');
|
|
|
|
function Window(args) {
|
|
this.options = {
|
|
title: args.dbType + '脚本查看器',
|
|
content: tpl,
|
|
width: 800,
|
|
height: 600,
|
|
modal: true,
|
|
closed: true,
|
|
closable: true,
|
|
data: null
|
|
}
|
|
|
|
this.args = args;
|
|
BaseWindow.call(this, this.options);
|
|
|
|
this.dsMaster = new DataSource();
|
|
this.dsMaster.uiObjCode = 'tFrmEnumValue';
|
|
this.dsMaster.fixQuery['EnumType'] = args.dataRow['EnumType'];
|
|
}
|
|
|
|
inherits(Window, BaseWindow);
|
|
|
|
Window.prototype.init = function () {
|
|
var self = this;
|
|
}
|
|
|
|
Window.prototype.select = function () {
|
|
this.close();
|
|
};
|
|
|
|
Window.prototype.doOp = function (opCode) {
|
|
var isHandled = false;
|
|
switch (opCode) {
|
|
case 'ok':
|
|
this.select();
|
|
break;
|
|
case 'exit':
|
|
this.$txtScript.select();
|
|
break;
|
|
case 'refresh':
|
|
this.refresh();
|
|
break;
|
|
case 'export':
|
|
this.exportScript();
|
|
break;
|
|
}
|
|
};
|
|
|
|
Window.prototype.refresh = function () {
|
|
var self = this;
|
|
this.dsMaster.search();
|
|
};
|
|
|
|
Window.prototype.customerize = function ($container) {
|
|
var self = this;
|
|
this.$txtScript = this.getElement('.txtscript');
|
|
this.$scriptNameInput = this.getElement('.edp-frd-script-name-input');
|
|
var $btnOk = this.getElement('.btn-script-ok');
|
|
if ($btnOk) {
|
|
$btnOk.on('click', function () {
|
|
self.doOp('ok');
|
|
});
|
|
}
|
|
|
|
var $btnCancel = this.getElement('.btn-script-cancel');
|
|
if ($btnCancel) {
|
|
$btnCancel.click(function () {
|
|
self.doOp('exit');
|
|
});
|
|
}
|
|
var $btnExport = this.getElement('.btn-script-export');
|
|
if ($btnExport) {
|
|
$btnExport.click(function() {
|
|
self.doOp('export');
|
|
});
|
|
}
|
|
this.$scriptNameInput.val(this.scriptName);
|
|
|
|
self.loadScript();
|
|
};
|
|
|
|
|
|
Window.prototype.open = function () {
|
|
var self = this;
|
|
|
|
var code = self.dsMaster.uiObjCode;
|
|
var post_data = {
|
|
funcCode: '',
|
|
uiObjCodes: code
|
|
}
|
|
self.makeScriptName();
|
|
Store.services.getUiObjSchema(post_data, function (isOk, data) {
|
|
if (isOk) {
|
|
self.dsMaster.initUIObj(data[code]);
|
|
BaseWindow.prototype.open.call(self);
|
|
}
|
|
});
|
|
};
|
|
|
|
Window.prototype.makeScriptName = function() {
|
|
this.scriptName = Store.dbScriptsProjectNo + '07_XX' +
|
|
'_预置枚举值' + this.args.dataRow['EnumType'] + '.sql';
|
|
};
|
|
|
|
Window.prototype.exportScript = function() {
|
|
var self = this,
|
|
scriptContent = self.$txtScript.val(),
|
|
scriptName = self.$scriptNameInput.val(),
|
|
blob = new Blob(
|
|
[scriptContent],
|
|
{type: "text/plain;charset=" + document.characterSet}
|
|
),
|
|
url = window.URL.createObjectURL(blob),
|
|
download_link = $('.export-script')[0];
|
|
|
|
Store.services.fileExport({
|
|
filename: scriptName,
|
|
content: scriptContent
|
|
}, function (isok, data) {
|
|
if (isok) {
|
|
download_link.href = Store.host + data.path;
|
|
download_link.download = scriptName;
|
|
download_link.click();
|
|
window.URL.revokeObjectURL(url);
|
|
}
|
|
})
|
|
};
|
|
|
|
|
|
Window.prototype.loadScript = function () {
|
|
var self = this;
|
|
|
|
//数据脚本特殊处理
|
|
self.dsMaster.search(function (isOk, ds) {
|
|
if (isOk) {
|
|
self.createDictScript()
|
|
}
|
|
});
|
|
|
|
|
|
};
|
|
|
|
function getSpace(num) {
|
|
var str = '';
|
|
for (var i = 0; i < num; i++) {
|
|
str += ' ';
|
|
}
|
|
;
|
|
return str;
|
|
}
|
|
|
|
|
|
Window.prototype.createDictScript = function () {
|
|
var self = this;
|
|
var dictScriptTpl = require('text!./dictScript3.tpl');
|
|
if (self.args.dbType === 'mysql') {
|
|
dictScriptTpl = require('text!./dictScript3MySql.tpl');
|
|
}
|
|
|
|
//主表相关脚本
|
|
var objRow = self.args.dataRow;
|
|
var sqlObj = ["INSERT INTO tFrmEnum ("];
|
|
var sqlObjValues = [""];
|
|
for (var i = 0; i < objRow.dataSrc.columns.length; i++) {
|
|
var col = objRow.dataSrc.columns[i];
|
|
if (col.isCalc) {
|
|
continue;
|
|
}
|
|
appendStr(sqlObj, col.fieldName);
|
|
appendStr(sqlObjValues, getSqlValue(col, objRow));
|
|
}
|
|
removeComma(sqlObj);
|
|
removeComma(sqlObjValues);
|
|
appendStr(sqlObj, ") VALUES (", true);
|
|
appendStr(sqlObj, sqlObjValues[0], true);
|
|
appendStr(sqlObj, ");", true);
|
|
|
|
//明细脚本
|
|
var sqlProps = "";
|
|
var sqlPropHeader = ["INSERT INTO tFrmEnumValue ("];
|
|
var props = [];
|
|
for (var k = 0; k < self.dsMaster.columns.length; k++) {
|
|
var col = self.dsMaster.columns[k];
|
|
if (col.isCalc) {
|
|
continue;
|
|
}
|
|
appendStr(sqlPropHeader, col.fieldName);
|
|
props.push(col);
|
|
}
|
|
removeComma(sqlPropHeader);
|
|
appendStr(sqlPropHeader, ") VALUES (", true);
|
|
|
|
for (var j = 0; j < self.dsMaster.rows.length; j++) {
|
|
var row = self.dsMaster.rows[j];
|
|
var sqlProp = [sqlPropHeader[0]];
|
|
for (var h = 0; h < props.length; h++) {
|
|
appendStr(sqlProp, getSqlValue(props[h], row));
|
|
}
|
|
;
|
|
|
|
removeComma(sqlProp);
|
|
sqlProp[0] += ");";
|
|
|
|
sqlProps += "\n";
|
|
sqlProps += sqlProp[0];
|
|
}
|
|
;
|
|
|
|
//合成最后的脚本
|
|
var dictScript = dictScriptTpl.replace(/#ENUMTYPE/g, objRow['EnumType']);
|
|
dictScript = dictScript.replace('#MASTER', sqlObj);
|
|
dictScript = dictScript.replace('#DETAIL', sqlProps);
|
|
self.$txtScript.val(dictScript);
|
|
};
|
|
|
|
//获取数据库值的字符串
|
|
function getSqlValue(col, row) {
|
|
if (col.dataType == Store.Enums.DataType.STRING || Store.Enums.DataType.TEXT) {
|
|
return "'" + row[col.fieldName] + "'";
|
|
}
|
|
|
|
if (col.dataType == Store.Enums.DataType.DATETIME) {
|
|
return "sysdate";
|
|
}
|
|
|
|
return row[col.fieldName];
|
|
};
|
|
|
|
function removeComma(str) {
|
|
var len = str[0].length;
|
|
if (str[0][len - 1] == ',') {
|
|
str[0] = str[0].slice(0, -1);
|
|
}
|
|
};
|
|
|
|
|
|
function appendStr(src, str, noDot) {
|
|
src[0] = src[0] + str;
|
|
if (!noDot) {
|
|
src[0] += ',';
|
|
}
|
|
};
|
|
|
|
return Window;
|
|
}) |