108 lines
3.1 KiB
JavaScript
108 lines
3.1 KiB
JavaScript
/*
|
|
const { trusted } = require('mongoose');
|
|
const sql = require('mssql');
|
|
const { stringify } = require('uuid');
|
|
|
|
var config = {
|
|
server: 'KLELECTROSERVER', //update me
|
|
authentication: {
|
|
type: 'default',
|
|
options: {
|
|
userName: 'nodes', //update me
|
|
password: 'Nincsis12345678' //update me
|
|
}
|
|
},
|
|
options: {
|
|
// If you are on Microsoft Azure, you need encryption:
|
|
encrypt: false,
|
|
database: 'Cegmenedzser K-L Electro Bt', //update me
|
|
rowCollectionOnRequestCompletion:true
|
|
}
|
|
};
|
|
var Connection = require('tedious').Connection;
|
|
|
|
exports.sqlGetnewWork=function(wk,callback){
|
|
if (!connection)
|
|
var connection = new Connection(config);
|
|
|
|
|
|
connection.on('connect', function(err) {
|
|
if (err){
|
|
console.log('SQL ERROR.');
|
|
return 0;
|
|
}
|
|
// If no error, then good to proceed.
|
|
console.log("Connected");
|
|
executeStatement(connection,wk,function(err,dd){
|
|
connection.close();
|
|
|
|
});
|
|
|
|
});
|
|
connection.on('error',function(err){
|
|
console.log('SQL ERROR.');
|
|
connection.close;
|
|
return 0;
|
|
})
|
|
connection.connect();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
var Request = require('tedious').Request;
|
|
var TYPES = require('tedious').TYPES;
|
|
|
|
function executeStatement(connection1,workn,callback) {
|
|
var jsonArray = [];
|
|
if (!workn) return;
|
|
var worknumber=workn.workNumber.replace('/','0');
|
|
var request = new Request("SELECT TOP (100) [RendAzon] ,[Rogzites],[SzallDatum],[Megjegyzes],[SzamlNev],[Projekt],[Megjegyzes2],[Megnevezes],[KulsoRendSzam]\
|
|
FROM [Cegmenedzser K-L Electro Bt].[dbo].[Vevorendeles_fej]\
|
|
where ISnumeric(SUBSTRING(Replace([Megjegyzes],'/','0'),1,9))=1 AND SUBSTRING(Replace([Megjegyzes],'/','0'),1,9) >'"+worknumber+"'\
|
|
Order By [RendAzon] DESC",function(err,rowCounts,rows)
|
|
{
|
|
if (err)
|
|
{
|
|
console.log(err);
|
|
callback(err,null);
|
|
}
|
|
else
|
|
{
|
|
console.log(rowCounts + " rows returned");
|
|
|
|
|
|
|
|
//Now parse the data from each of the row and populate the array.
|
|
for(var i=0; i < rowCounts; i++)
|
|
{
|
|
var singleRowData = rows[i];
|
|
var rowObject= {};
|
|
//console.log(singleRowData.length);
|
|
for(var j =0; j < singleRowData.length; j++)
|
|
{
|
|
var tempColName = singleRowData[j].metadata.colName;
|
|
var tempColData = singleRowData[j].value;
|
|
rowObject[tempColName] = tempColData;
|
|
}
|
|
if (singleRowData.length>3)
|
|
{
|
|
var s=singleRowData[3].value;
|
|
rowObject['Munkaszam KL']=s.substring(0,9);
|
|
}
|
|
jsonArray.push(rowObject);
|
|
}
|
|
//This line will print the array of JSON object.
|
|
console.log(jsonArray);
|
|
callback(null,jsonArray);
|
|
}
|
|
});
|
|
request.on('requestCompleted', function () {console.log("Fasza") });
|
|
connection1.execSql(request);
|
|
}
|
|
|
|
|
|
|
|
|
|
*/ |