1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672 |
- //�첽��������
- ReportAnsnFuncNum = 0;
- //�첽������ɸ���
- ReportAnsnDoneNum = 0;
- //��ѯͳ��ֵ���б� ȫ���ռ����б��һ�β�ѯ
- var TagStasticSearchInfoList = new Array();
- //��ѯ��ʷʱ��ֵ���б�ȫ���ռ����б��һ�β�ѯ
- var ReportTagHisValueSearchInfoList = new Array();
- //�Ƿ��Զ��幫ʽ
- function IsCustumFormula(fromStr) {
- var index = fromStr.indexOf("GetTagSnapShort(");
- if (index >= 0)
- return true;
- index = fromStr.indexOf("GetTagHisValue(");
- if (index >= 0)
- return true;
- index = fromStr.indexOf("GetTagHisInterval(");
- if (index >= 0)
- return true;
- index = fromStr.indexOf("GetTimeInterval(");
- if (index >= 0)
- return true;
- index = fromStr.indexOf("GetTimeStastic(");
- if (index >= 0)
- return true;
- index = fromStr.indexOf("GetTagTimeStasticValue(");
- if (index >= 0)
- return true;
- index = fromStr.indexOf("GetTagTimeStasticValue2(");
- if (index >= 0)
- return true;
- index = fromStr.indexOf("GetTimeDisplayStr(");
- if (index >= 0)
- return true;
- return false;
- }
- //�Ƿ��Զ����첽����
- function IsAnsnFunc(funcName) {
- index = funcName.indexOf("GetTagHisInterval(");
- if (index >= 0)
- return true;
- index = funcName.indexOf("GetTimeInterval(");
- if (index >= 0)
- return true;
- return false;
- }
- //�Ƿ��Զ���ͬ������
- function IsCustomNoAnsnFunc(funcName) {
- index = funcName.indexOf("GetTimeDisplayStr(");
- if (index >= 0)
- return true;
- return false;
- }
- //ע���Զ��庯��
- function ApplyCustomFunc(spread) {
- var sheet = spread.getSheet(0);
- GC.Spread.CalcEngine.Functions.defineGlobalCustomFunction("GETTAGSNAPSHORT", new goldenNameSpace.GetTagSnapShort());
- GC.Spread.CalcEngine.Functions.defineGlobalCustomFunction("GETTAGHISVALUE", new goldenNameSpace.GetTagHisValue());
- GC.Spread.CalcEngine.Functions.defineGlobalCustomFunction("GETTAGHISINTERVAL", new goldenNameSpace.GetTagHisInterval());
- GC.Spread.CalcEngine.Functions.defineGlobalCustomFunction("GETTIMEINTERVAL", new goldenNameSpace.GetTimeInterval());
- GC.Spread.CalcEngine.Functions.defineGlobalCustomFunction("GETTIMESTASTIC", new goldenNameSpace.GetTimeStastic());
- GC.Spread.CalcEngine.Functions.defineGlobalCustomFunction("GETTAGTIMESTASTICVALUE", new goldenNameSpace.GetTagTimeStasticValue());
- GC.Spread.CalcEngine.Functions.defineGlobalCustomFunction("GETTAGTIMESTASTICVALUE2", new goldenNameSpace.GetTagTimeStasticValue2());
- GC.Spread.CalcEngine.Functions.defineGlobalCustomFunction("GETTIMEDISPLAYSTR", new goldenNameSpace.GetTimeDisplayStr());
- /*
- var getTagSnapShort = new goldenNameSpace.GetTagSnapShort();
- sheet.addCustomFunction(getTagSnapShort);
-
- var getTagHisValue = new goldenNameSpace.GetTagHisValue();
- sheet.addCustomFunction(getTagHisValue);
-
- var getTagHisInterval = new goldenNameSpace.GetTagHisInterval();
- sheet.addCustomFunction(getTagHisInterval);
-
- var getTimeInterval = new goldenNameSpace.GetTimeInterval();
- sheet.addCustomFunction(getTimeInterval);
-
- var getTimeStastic= new goldenNameSpace.GetTimeStastic();
- sheet.addCustomFunction(getTimeStastic);
-
- var getTagTimeStasticValue= new goldenNameSpace.GetTagTimeStasticValue();
- sheet.addCustomFunction(getTagTimeStasticValue);
-
- var getTagTimeStasticValue2= new goldenNameSpace.GetTagTimeStasticValue2();
- sheet.addCustomFunction(getTagTimeStasticValue2);
-
- var getTimeDisplayStr= new goldenNameSpace.GetTimeDisplayStr();
- sheet.addCustomFunction(getTimeDisplayStr);
-
- var getTagHisValue= new goldenNameSpace.GetTagHisValue();
- sheet.addCustomFunction(getTagHisValue);*/
- }
- //ִ���Զ���ͬ������
- function DoCustomNoAnsnFunc(spread) {
- var sheet = spread.getSheet(0);
- //ApplyCustomFunc(spread);
- var colNum = sheet.getColumnCount();
- var rowNum = sheet.getRowCount();
- for (var i = 0; i < colNum; i++) {
- for (var j = 0; j < rowNum; j++) {
- var calcu = sheet.getFormula(j, i);
- if (calcu != null) {
- if (IsCustomNoAnsnFunc(calcu))
- sheet.setFormula(j, i, "=" + calcu);
- }
- }
- }
- }
- //ִ�з��Զ��庯��
- function DoNoCustomFunc(spread) {
- var sheet = spread.getSheet(0);
- //ApplyCustomFunc(spread);
- var colNum = sheet.getColumnCount();
- var rowNum = sheet.getRowCount();
- for (var i = 0; i < colNum; i++) {
- for (var j = 0; j < rowNum; j++) {
- var calcu = sheet.getFormula(j, i);
- if (calcu != null) {
- if (!IsCustumFormula(calcu))
- sheet.setFormula(j, i, "=" + calcu);
- }
- }
- }
- }
- //���¼��ʽ
- function ResetFormular(spread) {
- var sheet = spread.getSheet(0);
- //ApplyCustomFunc(spread);
- var colNum = sheet.getColumnCount();
- var rowNum = sheet.getRowCount();
- ReportAnsnFuncNum = 0;
- for (var i = 0; i < colNum; i++) {
- for (var j = 0; j < rowNum; j++) {
- var calcu = sheet.getFormula(j, i);
- if (calcu != null) {
- //if(IsCustumFormula(calcu))
- //sheet.setFormula(j,i, "="+calcu);
- if (IsAnsnFunc(calcu)) {
- ReportAnsnFuncNum++;
- }
- }
- /* var valueStr=sheet.getValue(j,i);
- if(!valueStr)
- continue;
- try
- {
- if(valueStr.indexOf("
")>=0)
- {
- var myCellType = new MyCellType();
- sheet.getCell(j,i).cellType(myCellType)
- }
- }
- catch(e)
- {
- }*/
- }
- //sheet.autoFitColumn(i);
- }
- }
- //б�߱�ͷ
- function MyCellType() {
- }
- MyCellType.prototype = new GC.Spread.Sheets.CellTypes.Text();
- MyCellType.prototype.paint = function (ctx, value, x, y, w, h, style, options) {
- //Paints a cell on the canvas.
- if (!ctx) {
- return;
- }
- ctx.save();
- ctx.beginPath();
- ctx.moveTo(x, y);
- ctx.lineTo(x + w, y + h);
- ctx.stroke();
- ctx.font = style.font;
- var text = value ? value.split(" ") : ["", ""];
- ctx.fillText(text[0].trim(), x + w * 7 / 8, y + h / 3);
- ctx.fillText(text[1].trim(), x + w / 2, y + h * 3 / 4);
- ctx.restore();
- };
- var goldenNameSpace = {};
- (function () {
- // �Զ��幫ʽ����ȡͳ��ʱ���ֵ2��----------------------------------------------------------------------
- function GetTagTimeStasticValue2() {
- this.name = 'GetTagTimeStasticValue2';
- this.maxArgs = 5;
- this.minArgs = 5;
- GC.Spread.CalcEngine.Functions.Function.apply(this, ["GetTagTimeStasticValue2", 0, 0]);
- this.typeName = "goldenNameSpace.GetTagTimeStasticValue2";
- }
- //ͬ����ʽ
- goldenNameSpace.GetTagTimeStasticValue2 = GetTagTimeStasticValue2;
- GetTagTimeStasticValue2.prototype = new GC.Spread.CalcEngine.Functions.Function();
- GetTagTimeStasticValue2.prototype.evaluateMode = function () {
- return 0;
- };
- GetTagTimeStasticValue2.prototype.evaluate = function (arg) {
- if (arguments.length >= 4) {
- var ReportTag = arguments[0];
- var ReportStartTime = arguments[1];
- var ReportEndTime = arguments[2];
- var ReportSelectType = arguments[3];
- ReportStartTime = window[ReportStartTime];//��ȡ�ؼ��еı���ֵ
- if (!ReportStartTime)
- return "";
- ReportEndTime = window[ReportEndTime];//��ȡ�ؼ��еı���ֵ
- if (!ReportEndTime)
- return "";
- }
- else
- return "";
- var TempStartTime = new Date(Date.parse(ReportStartTime));
- var TempEndTime = new Date(Date.parse(ReportEndTime));
- //��ȡͳ��ֵ
- var vv = GetTagStasticSearchValue(TempStartTime, TempEndTime, ReportTag, ReportSelectType);
- if (!vv) {
- return 0;
- }
- else
- return parseFloat(vv);
- }
- /* //�첽��ʽ
- GetTagTimeStasticValue2.prototype = new GC.Spread.CalcEngine.Functions.AsyncFunction();
- GetTagTimeStasticValue2.prototype.evaluateMode = function () {
- return 0;
- };
- goldenNameSpace.GetTagTimeStasticValue2=GetTagTimeStasticValue2;
- GetTagTimeStasticValue2.prototype.evaluateAsync = function (context)
- {
- if(arguments.length>=5)
- {
- var ReportTag=arguments[1];
- var ReportStartTime=arguments[2];
- var ReportEndTime=arguments[3];
- var ReportSelectType=arguments[4];
-
- ReportStartTime= window[ReportStartTime];//��ȡ�ؼ��еı���ֵ
- if(!ReportStartTime)
- {
- context.setAsyncResult(0);
- return;
- }
-
- ReportEndTime= window[ReportEndTime];//��ȡ�ؼ��еı���ֵ
- if(!ReportEndTime)
- {
- context.setAsyncResult(0);
- return;
- }
- }
- else
- {
- context.setAsyncResult(0);
- return;
- }
-
- var TempStartTime=new Date(Date.parse(ReportStartTime));
- var TempEndTime=new Date(Date.parse(ReportEndTime));
-
- //��ȡͳ��ֵ
- var vv=GetTagStasticSearchValue(TempStartTime,TempEndTime,ReportTag,ReportSelectType);
- if(!vv)
- {
- context.setAsyncResult(0);
- return;
- }
- else
- context.setAsyncResult(vv);
-
- } */
- // �Զ��幫ʽ����ȡͳ��ʱ���ֵ��----------------------------------------------------------------------
- function GetTagTimeStasticValue() {
- this.name = 'GetTagTimeStasticValue';
- this.maxArgs = 4;
- this.minArgs = 4;
- GC.Spread.CalcEngine.Functions.Function.apply(this, ["GetTagTimeStasticValue", 0, 0]);
- this.typeName = "goldenNameSpace.GetTagTimeStasticValue";
- }
- GetTagTimeStasticValue.prototype = new GC.Spread.CalcEngine.Functions.Function();
- GetTagTimeStasticValue.prototype.evaluateMode = function () {
- return 0;
- };
- goldenNameSpace.GetTagTimeStasticValue = GetTagTimeStasticValue;
- GetTagTimeStasticValue.prototype.evaluate = function (context) {
- if (arguments.length >= 4) {
- ReportTag = arguments[0];
- ReportSelectTime = arguments[1];
- ReportTimeType = arguments[2];
- ReportSelectType = arguments[3];
- ReportSelectTime = window[ReportSelectTime];//��ȡ�ؼ��еı���ֵ
- if (!ReportSelectTime)
- return "";
- }
- else
- return "";
- var TempStartTime = new Date(Date.parse(ReportSelectTime));
- var TempEndTime = new Date(Date.parse(ReportSelectTime));
- if (ReportTimeType == 'd' || ReportTimeType == 'D') {
- TempStartTime.setHours(0);
- TempStartTime.setMinutes(0);
- TempStartTime.setSeconds(0);
- TempEndTime.setHours(23);
- TempEndTime.setMinutes(59);
- TempEndTime.setSeconds(59);
- }
- else if (ReportTimeType == 'm' || ReportTimeType == 'M') {
- TempStartTime.setDate(1);
- TempStartTime.setHours(0);
- TempStartTime.setMinutes(0);
- TempStartTime.setSeconds(0);
- TempEndTime.setMonth(TempEndTime.getMonth() + 1);
- TempEndTime.setDate(0);
- TempEndTime.setHours(23);
- TempEndTime.setMinutes(59);
- TempEndTime.setSeconds(59);
- }
- else if (ReportTimeType == 'y' || ReportTimeType == 'Y') {
- TempStartTime.setMonth(0);
- TempStartTime.setDate(1);
- TempStartTime.setHours(0);
- TempStartTime.setMinutes(0);
- TempStartTime.setSeconds(0);
- var year = TempEndTime.getYear();
- TempEndTime.setYear(year + 1 + 1900);
- TempEndTime.setMonth(0);
- TempEndTime.setDate(0);
- TempEndTime.setHours(23);
- TempEndTime.setMinutes(59);
- TempEndTime.setSeconds(59);
- }
- //��ȡͳ��ֵ
- var vv = GetTagStasticSearchValue(TempStartTime, TempEndTime, ReportTag, ReportSelectType);
- if (!vv) {
- return 0;
- }
- else
- return parseFloat(vv);
- }
- // �Զ��幫ʽ����ȡͳ��ʱ���ʱ��ֵ��----------------------------------------------------------------------
- function GetTimeDisplayStr() {
- this.name = 'GetTimeDisplayStr';
- this.maxArgs = 2;
- this.minArgs = 2;
- GC.Spread.CalcEngine.Functions.Function.apply(this, ["GetTimeDisplayStr", 0, 0]);
- this.typeName = "goldenNameSpace.GetTimeDisplayStr";
- }
- goldenNameSpace.GetTimeDisplayStr = GetTimeDisplayStr;
- GetTimeDisplayStr.prototype = new GC.Spread.CalcEngine.Functions.Function();
- GetTagTimeStasticValue2.prototype.evaluateMode = function () {
- return 0;
- };
- /*GetTimeDisplayStr.prototype.evaluateMode = function () {
- return 0;
- };*/
- GetTimeDisplayStr.prototype.evaluate = function (context) {
- //context.setAsyncResult("");
- //return;
- if (arguments.length >= 2) {
- ReportSelectTime = arguments[0];
- ReportTimeFormat = arguments[1];
- ReportSelectTime = window[ReportSelectTime];//��ȡ�ؼ��еı���ֵ
- if (!ReportSelectTime) {
- return "δ�ҵ�ʱ�����!";
- }
- }
- else {
- return "������������!";
- return;
- }
- ReportSelectTime = new Date(Date.parse(ReportSelectTime));
- var ReportSelectTimeStr = ReportSelectTime.Format(ReportTimeFormat);
- return ReportSelectTimeStr + "";
- }
- // �Զ��幫ʽ����ȡͳ��ʱ���ֵ��----------------------------------------------------------------------
- // �Զ��幫ʽ����ȡͳ��ʱ���ʱ��ֵ��----------------------------------------------------------------------
- function GetTimeStastic() {
- this.name = 'GetTimeStastic';
- this.maxArgs = 4;
- this.minArgs = 4;
- GC.Spread.CalcEngine.Functions.Function.apply(this, ["GetTimeStastic", 0, 0]);
- this.typeName = "goldenNameSpace.GetTimeStastic";
- }
- goldenNameSpace.GetTimeStastic = GetTimeStastic;
- GetTimeStastic.prototype = new GC.Spread.CalcEngine.Functions.AsyncFunction();
- GetTimeStastic.prototype.evaluateMode = function () {
- return 0;
- };
- GetTimeStastic.prototype.evaluateAsync = function (context) {
- if (arguments.length >= 5) {
- ReportSelectTime = arguments[1];
- ReportTimeType = arguments[2];
- ReportSelectType = arguments[3];
- ReportTimeFormat = arguments[4];
- ReportSelectTime = window[ReportSelectTime];//��ȡ�ؼ��еı���ֵ
- }
- else {
- context.setAsyncResult("error!");
- return;
- }
- ReportSelectTime = new Date(Date.parse(ReportSelectTime));
- if (ReportTimeType == 'd') {
- if (ReportSelectType == "start") {
- ReportSelectTime.setHours(0);
- ReportSelectTime.setMinutes(0);
- ReportSelectTime.setSeconds(0);
- }
- else {
- ReportSelectTime.setHours(23);
- ReportSelectTime.setMinutes(59);
- ReportSelectTime.setSeconds(59);
- }
- }
- else if (ReportTimeType == 'm') {
- if (ReportSelectType == "start") {
- ReportSelectTime.setSeconds(0);
- }
- else {
- ReportSelectTime.setSeconds(59);
- }
- }
- else if (ReportTimeType == 'h') {
- if (ReportSelectType == "start") {
- ReportSelectTime.setMinutes(0);
- ReportSelectTime.setSeconds(0);
- }
- else {
- ReportSelectTime.setMinutes(59);
- ReportSelectTime.setSeconds(59);
- }
- }
- else if (ReportTimeType == 'M') {
- if (ReportSelectType == "start") {
- ReportSelectTime.setDate(1);
- ReportSelectTime.setHours(0);
- ReportSelectTime.setMinutes(0);
- ReportSelectTime.setSeconds(0);
- }
- else {
- ReportSelectTime.setMonth(ReportSelectTime.getMonth() + 1);
- ReportSelectTime.setDate(0);
- ReportSelectTime.setHours(23);
- ReportSelectTime.setMinutes(59);
- ReportSelectTime.setSeconds(59);
- }
- }
- else if (ReportTimeType == 'y') {
- if (ReportSelectType == "start") {
- ReportSelectTime.setMonth(0);
- ReportSelectTime.setDate(1);
- ReportSelectTime.setHours(0);
- ReportSelectTime.setMinutes(0);
- ReportSelectTime.setSeconds(0);
- }
- else {
- var year = ReportSelectTime.getYear();
- ReportSelectTime.setYear(year + 1 + 1900);
- ReportSelectTime.setMonth(0);
- ReportSelectTime.setDate(0);
- ReportSelectTime.setHours(23);
- ReportSelectTime.setMinutes(59);
- ReportSelectTime.setSeconds(59);
- }
- }
- var ReportSelectTimeStr = ReportSelectTime.Format(ReportTimeFormat);
- context.setAsyncResult(ReportSelectTimeStr);
- }
- // �Զ��幫ʽ����ȡͳ��ʱ���ʱ��ֵ��----------------------------------------------------------------------
- // �Զ��幫ʽ����ȡʱ��εĵȼ����ʾ��----------------------------------------------------------------------
- function GetTimeInterval() {
- this.name = 'GetTimeInterval';
- this.maxArgs = 6;
- this.minArgs = 6;
- GC.Spread.CalcEngine.Functions.Function.apply(this, ["GetTimeInterval", 0, 0]);
- this.typeName = "goldenNameSpace.GetTimeInterval";
- }
- GetTimeInterval.prototype = new GC.Spread.CalcEngine.Functions.AsyncFunction();
- GetTimeInterval.prototype.defaultValue = function () { return 'loading' };
- GetTimeInterval.prototype.evaluateMode = function () {
- return 0;
- };
- goldenNameSpace.GetTimeInterval = GetTimeInterval;
- //��ȡ��ʷ�ȼ������
- GetTimeInterval.prototype.evaluateAsync = function (context) {
- var args = arguments;
- var curCol = context.col;
- var curRow = context.row;
- if (args.length >= 6) {
- var ReportStartTime = args[1];
- var ReportEndTime = args[2];
- var ReportInterval = args[3];
- var ReportIntervalType = args[4];
- var ReportTimeFormat = args[5];
- var ReportVH = args[6];
- ReportStartTime = window[ReportStartTime];
- ReportEndTime = window[ReportEndTime];
- if (ReportStartTime == "")
- return;
- if (ReportEndTime == "")
- return;
- //ReportInterval= window[ReportInterval];
- //ReportIntervalType = window[ReportIntervalType];
- }
- else {
- context.setAsyncResult(0);
- return;
- }
- //清除原数据
- var clearNum = 0;
- var sheet = context.ctx.source;
- if (ReportIntervalType == 'd') {
- clearNum = 31;
- }
- else if (ReportIntervalType == 'm') {
- clearNum = 60;
- }
- else if (ReportIntervalType == 'h') {
- clearNum = 24;
- }
- var sheet = context.ctx.source;
- for (var kk = 0; kk < clearNum; kk++) {
- if (ReportVH == "v") {
- if (curRow + kk < sheet.getRowCount() && curCol < sheet.getColumnCount())
- sheet.setValue(curRow + kk, curCol, "");
- }
- else if (ReportVH == "h") {
- if (curRow < sheet.getRowCount() && curCol + kk < sheet.getColumnCount())
- sheet.setValue(curRow, curCol + kk, "");
- }
- }
- var tempDateTime = new Date(Date.parse(ReportStartTime));
- var tempEndTime = new Date(Date.parse(ReportEndTime));
- var sheet = context.ctx.source;
- for (var i = 0; i < 200; i++) {
- var tempDateStr = tempDateTime.Format(ReportTimeFormat);
- if (i == 0) {
- context.setAsyncResult(tempDateStr);
- //sheet.setValue(curRow,curCol,tempDateStr);
- }
- else if (ReportVH == "v") {
- if (curRow + i < sheet.getRowCount() && curCol < sheet.getColumnCount())
- sheet.setValue(curRow + i, curCol, tempDateStr);
- }
- else if (ReportVH == "h") {
- if (curRow < sheet.getRowCount() && curCol + i < sheet.getColumnCount())
- sheet.setValue(curRow, curCol + i, tempDateStr);
- }
- if (ReportIntervalType == 's') {
- tempDateTime.setSeconds(tempDateTime.getSeconds() + ReportInterval);
- }
- else if (ReportIntervalType == 'm') {
- tempDateTime.setMinutes(tempDateTime.getMinutes() + ReportInterval);
- }
- else if (ReportIntervalType == 'h') {
- tempDateTime.setHours(tempDateTime.getHours() + ReportInterval);
- }
- else if (ReportIntervalType == 'd') {
- tempDateTime.setDate(tempDateTime.getDate() + ReportInterval);
- }
- else if (ReportIntervalType == 'M') {
- tempDateTime.setMonth(tempDateTime.getMonth() + ReportInterval);
- }
- else if (ReportIntervalType == 'y') {
- tempDateTime.setYear(tempDateTime.getYear() + ReportInterval);
- }
- if (tempDateTime >= tempEndTime)
- break;
- }
- ReportAnsnDoneNum++;
- //tempDateTime=new Date(Date.parse(ReportStartTime));
- //tempDateStr=tempDateTime.Format(ReportTimeFormat);
- //context.setAsyncResult(tempDateStr);
- }
- // �Զ��幫ʽ����ȡʱ��εĵȼ����ʾ��----------------------------------------------------------------------
- // �Զ��幫ʽ����ȡ��ȡ��ʷ�ȼ�����ݣ�----------------------------------------------------------------------
- function GetTagHisInterval() {
- this.name = 'GetTagHisInterval';
- this.maxArgs = 6;
- this.minArgs = 6;
- GC.Spread.CalcEngine.Functions.Function.apply(this, ["GetTagHisInterval", 0, 0]);
- this.typeName = "goldenNameSpace.GetTagHisInterval";
- }
- goldenNameSpace.GetTagHisInterval = GetTagHisInterval;
- GetTagHisInterval.prototype = new GC.Spread.CalcEngine.Functions.AsyncFunction();
- GetTagHisInterval.prototype.defaultValue = function () { return 'loading' };
- GetTagHisInterval.prototype.evaluateMode = function () {
- return 0;
- };
- GetTagHisInterval.prototype.interval = function () {
- return 1000;
- };
- //��ȡ��ʷ�ȼ������
- GetTagHisInterval.prototype.evaluateAsync = function (context) {
- var args = arguments;
- var curCol = context.col;
- var curRow = context.row;
- var ReportIntervalSumType = "snap";
- var valueCount = 0;
- if (args.length >= 5) {
- var Reporttag = args[1];
- var ReportStartTime = args[2];
- var ReportEndTime = args[3];
- var ReportInterval = args[4];
- var ReportIntervalType = args[5];
- ReportIntervalSumType = args[6]; //ͳ������ ��min,max
- var ReportVH = args[7];
- ReportStartTime = window[ReportStartTime];
- ReportEndTime = window[ReportEndTime];
- if (ReportStartTime == "")
- {ReportAnsnDoneNum++;
- return;
- }
- if (ReportEndTime == "")
- {ReportAnsnDoneNum++;
- return;
- }
- //ReportInterval= window[ReportInterval];
- //ReportIntervalType= "0";// window[ReportIntervalType];
- }
- else
- {
- ReportAnsnDoneNum++;
- context.setAsyncResult(0);
- return;
- }
- var TempEndTime = new Date(Date.parse(ReportEndTime));
- var TempStartTime = new Date(Date.parse(ReportStartTime));
- var ReportIntervalSumTypeStr = "0";
- if (ReportIntervalSumType == "snap") {
- ReportIntervalSumTypeStr = "0";
- }
- else if (ReportIntervalSumType == "max") {
- ReportIntervalSumTypeStr = "1";
- }
- else if (ReportIntervalSumType == "min") {
- ReportIntervalSumTypeStr = "2";
- }
- else if (ReportIntervalSumType == "avg") {
- ReportIntervalSumTypeStr = "3";
- }
- else if (ReportIntervalSumType == "total") {
- ReportIntervalSumTypeStr = "4";
- }
- else {
- ReportIntervalSumTypeStr = "0";
- }
- if (ReportIntervalType == "m")//����
- {
- ReportInterval = ReportInterval * 60;
- valueCount = (TempEndTime.getTime() - TempStartTime.getTime()) / 1000 / 60;
- }
- else if (ReportIntervalType == "h")//Сʱ
- {
- ReportInterval = ReportInterval * 3600;
- valueCount = (TempEndTime.getTime() - TempStartTime.getTime()) / 1000 / 3600;
- }
- else if (ReportIntervalType == "d")//��
- {
- ReportInterval = ReportInterval * 3600 * 24;
- valueCount = (TempEndTime.getTime() - TempStartTime.getTime()) / 1000 / 24 / 3600;
- TempStartTime.setSeconds(TempStartTime.getSeconds() + 86399);//取每天23:59:59秒值
- }
- var urlStr = "http://" + webServiceIP + ":" + webServicePort + "/api/HistoryInterval?tagName="; //+ cmdStr;
- pageIndex = 1;
- if (valueCount < 200)
- tagsCount = parseInt(valueCount + 0.5);
- else
- tagsCount = 200;
- urlStr += createSearchStr(Reporttag, TempStartTime, ReportEndTime, ReportInterval, ReportIntervalSumTypeStr, ReportInterval)
- + '&pageIndex=' + pageIndex + '&pageSize=' + tagsCount;
- // getTableHisData(shotTablePane,url,shotTableTableModel,shotTablecolumns,shotTablerows);
- $.ajax({
- type: 'GET',
- url: urlStr,
- dataType: 'json',
- cache: false,
- error:function(data)
- {
- ReportAnsnDoneNum++;
- return;
- },
- success: function (data) {
- if (!data.Datas && !data) {
- context.setAsyncResult("not find!");
- ReportAnsnDoneNum++;
- return;
- }
- var arr;
- if (data.Datas)
- arr = data.Datas;
- else if (data)
- arr = data;
- //清除原数据
- var clearNum = 0;
- if (ReportIntervalType == 'd') {
- clearNum = 31;
- }
- else if (ReportIntervalType == 'm') {
- clearNum = 60;
- }
- else if (ReportIntervalType == 'h') {
- clearNum = 24;
- }
- var sheet = context.ctx.source;
- for (var kk = 0; kk < clearNum; kk++) {
- if (ReportVH == "v") {
- if (curRow + kk < sheet.getRowCount() && curCol < sheet.getColumnCount())
- sheet.setValue(curRow + kk, curCol, "");
- }
- else if (ReportVH == "h") {
- if (curRow < sheet.getRowCount() && curCol + kk < sheet.getColumnCount())
- sheet.setValue(curRow, curCol + kk, "");
- }
- }
- for (var key in arr) {
- var tagData = arr[key];
- if (!tagData)
- continue;
- if (tagData.length > 0) {
- var showCount = 200;
- if (tagData.length < showCount)
- showCount = tagData.length;
- var actVal = 0;
- if (ReportIntervalSumType == "snap")
- actVal = GetDital(tagData[0].Value, 3);
- else if (ReportIntervalSumType == "min")
- actVal = GetDital(tagData[0].Min, 3);
- else if (ReportIntervalSumType == "max")
- actVal = GetDital(tagData[0].Max, 3);
- else if (ReportIntervalSumType == "avg")
- actVal = GetDital(tagData[0].CalcAvg, 3);
- else if (ReportIntervalSumType == "total")
- actVal = GetDital(tagData[0].Total, 3);
- context.setAsyncResult(actVal);
- for (var i = 0; i < showCount; i++) {
- if (ReportIntervalSumType == "snap")
- actVal = GetDital(tagData[i].Value, 3);
- else if (ReportIntervalSumType == "min")
- actVal = GetDital(tagData[i].Min, 3);
- else if (ReportIntervalSumType == "max")
- actVal = GetDital(tagData[i].Max, 3);
- else if (ReportIntervalSumType == "avg")
- actVal = GetDital(tagData[i].CalcAvg, 3);
- else if (ReportIntervalSumType == "total")
- actVal = GetDital(tagData[i].Total, 3);
- if (ReportVH == "v") {
- if (curRow + i < sheet.getRowCount() && curCol < sheet.getColumnCount())
- sheet.setValue(curRow + i, curCol, actVal);
- }
- else if (ReportVH == "h") {
- if (curRow < sheet.getRowCount() && curCol + i < sheet.getColumnCount())
- sheet.setValue(curRow, curCol + i, actVal);
- }
- }
- //sheet.autoFitColumn(curCol);
- ReportAnsnDoneNum++;
- sheet.refresh();
- return;
- }
- else {
- context.setAsyncResult("not find!");
- ReportAnsnDoneNum++;
- return;
- }
- break;
- }
- var sheet = context.ctx.source;
- sheet.refresh();
- ReportAnsnDoneNum++;
- }
- })
- }
- //�����ȼ����ʷ��ѯ�IJ�ѯ�ַ���
- function createSearchStr(tagNameStr, beginTime, endTime, interval, valueType, count) {
- beginTime = moment(new Date(beginTime)).format("YYYY-MM-DD H:mm:ss");
- endTime = moment(new Date(endTime)).format("YYYY-MM-DD H:mm:ss");
- interval = interval || 10;
- //valueType = valueType || 1;
- count = Math.floor((new Date(endTime) - new Date(beginTime)) / interval / 1000);
- var result = '';
- var tagsInfo = encodeURIComponent(tagNameStr);
- result = tagsInfo + '&beginTime=' + beginTime + '&endTime=' + endTime + '&interval=' + interval + '&count=' + count;
- if (valueType !== '0') {
- result += '&valueType=' + valueType;
- }
- return result;
- }
- // �Զ��幫ʽ����ȡ��ȡ��ʷ�ȼ�����ݣ�----------------------------------------------------------------------
- // �Զ��幫ʽ����ȡ����ֵ��----------------------------------------------------------------------
- function GetTagSnapShort() {
- this.name = 'GETTAGSNAPSHORT';
- this.maxArgs = 2;
- this.minArgs = 2;
- GC.Spread.CalcEngine.Functions.Function.apply(this, ["GetTagSnapShort", 0, 0]);
- this.typeName = "goldenNameSpace.GetTagSnapShort";
- }
- goldenNameSpace.GetTagSnapShort = GetTagSnapShort;
- GetTagSnapShort.prototype = new GC.Spread.CalcEngine.Functions.AsyncFunction();
- GetTagSnapShort.prototype.defaultValue = function () { return 'loading' };
- GetTagSnapShort.prototype.evaluateMode = function () {
- return 0;
- };
- GetTagSnapShort.prototype.interval = function () {
- return 1000;
- };
- GetTagSnapShort.prototype.evaluateAsync = function (context) {
- var args = arguments;
- if (args.length > 1)
- tag = args[1];
- else {
- context.setAsyncResult(0);
- return;
- }
- var str = "http://" + webServiceIP + ":" + webServicePort + "/api/Snapshot?tagName=";
- var para = tag;
- str = str + encodeURIComponent(para);
- $.ajax({
- url: str,
- type: 'GET',
- dataType: 'json',
- cache: false,
-
- success: function (data) {
- if (data === null) return;
- var snapshots = eval(data);
- //�жϿ����Ƿ�Ϊ��
- if (snapshots != null) {
- var value = 0;
- if (snapshots.length > 0)
- value = snapshots[0].Value;
- var actVal = GetDital(value, 3);
- context.setAsyncResult(actVal);
- }
- },
- complete: function (XHR, TS) {
- XHR = null;
- }
- }
- );
- }
- // �Զ��幫ʽ����ȡ����ֵ��----------------------------------------------------------------------
- // �Զ��幫ʽ����ȡ��ʷʱ��ֵ��----------------------------------------------------------------------
- function GetTagHisValue() {
- this.name = 'GETTAGHISVALUE';
- this.maxArgs = 3;
- this.minArgs = 2;
- GC.Spread.CalcEngine.Functions.Function.apply(this, ["GetTagHisValue", 0, 0]);
- this.typeName = "goldenNameSpace.GetTagHisValue";
- }
- goldenNameSpace.GetTagHisValue = GetTagHisValue;
- //ͬ����ʽ
- GetTagHisValue.prototype = new GC.Spread.CalcEngine.Functions.Function();
- GetTagHisValue.prototype.defaultValue = function () { return 'loading' };
- GetTagHisValue.prototype.evaluateMode = function () {
- return 0;
- };
- GetTagHisValue.prototype.interval = function () {
- return 1000;
- };
- GetTagHisValue.prototype.evaluate = function (context) {
- var args = arguments;
- var tag = "";
- var hisTimeStr = "";
- if (args.length > 1) {
- tag = args[0];
- if (tag.indexOf("WT1.") >= 0) {
- var ssssss = 1;
- }
- hisTimeStr = args[1];
- if (!hisTimeStr) {
- //context.setAsyncResult(0);
- return 0;
- }
- hisTimeStr = window[hisTimeStr];
- if (!hisTimeStr) {
- // context.setAsyncResult(0);
- return 0;
- }
- var tempTime = new Date(Date.parse(hisTimeStr));
- if (!tempTime) {
- // context.setAsyncResult(0);
- return 0;
- }
-
- //偏移秒
- var addSec=0;
- if(args.length>=3)
- {
- addSec=parseInt(args[2]);
- tempTime.setSeconds( tempTime.getSeconds()+addSec);
- }
- var vv = GetReportTagHisValue(tempTime, tag);
- if (!vv) {
- //context.setAsyncResult(0);
- return 0;
- }
- else {
- // context.setAsyncResult( vv);
- return parseFloat(vv);
- }
- }
- else {
- // context.setAsyncResult(0);
- return 0;
- }
- }
- /* �첽��ʽ
- GetTagHisValue.prototype = new GC.Spread.CalcEngine.Functions.AsyncFunction();
- GetTagHisValue.prototype.defaultValue = function () {return 'loading'};
- GetTagHisValue.prototype.evaluateMode = function () {
- return 0;
- };
- GetTagHisValue.prototype.interval = function () {
- return 1000;
- };
- GetTagHisValue.prototype.evaluateAsync = function (context)
- {
- var args = arguments;
- var tag="";
- var hisTimeStr="";
- if(args.length>1)
- {
- tag=args[1];
-
- if(tag.indexOf("WT1.")>=0)
- {
- var ssssss=1;
- }
- hisTimeStr=args[2];
- if(!hisTimeStr)
- {
- context.setAsyncResult(0);
- return;
- }
- hisTimeStr=window[hisTimeStr];
- if(!hisTimeStr)
- {
- context.setAsyncResult(0);
- return;
- }
- var tempTime=new Date(Date.parse(hisTimeStr));
- if(!tempTime)
- {
- context.setAsyncResult(0);
- return;
- }
-
- var vv=GetReportTagHisValue(tempTime,tag);
- if(!vv)
- {
- context.setAsyncResult(0);
- return;
- }
- else
- context.setAsyncResult( vv);
- }
- else
- {
- context.setAsyncResult(0);
- return;
- }
- }*/
- })();
- // ��Date����չ���� Date ת��Ϊָ����ʽ��String
- // ��(M)����(d)��Сʱ(h)����(m)����(s)������(q) ������ 1-2 ��ռλ����
- // ��(y)������ 1-4 ��ռλ��������(S)ֻ���� 1 ��ռλ��(�� 1-3 λ������)
- // ���ӣ�
- // (new Date()).Format("yyyy-MM-dd hh:mm:ss.S") ==> 2006-07-02 08:09:04.423
- // (new Date()).Format("yyyy-M-d h:m:s.S") ==> 2006-7-2 8:9:4.18
- Date.prototype.Format = function (fmt) { //author: meizz
- var o = {
- "M+": this.getMonth() + 1, //�·�
- "d+": this.getDate(), //��
- "h+": this.getHours(), //Сʱ
- "m+": this.getMinutes(), //��
- "s+": this.getSeconds(), //��
- "q+": Math.floor((this.getMonth() + 3) / 3), //����
- "S": this.getMilliseconds() //����
- };
- if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
- for (var k in o)
- if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
- return fmt;
- }
- //��Ҫ��ѯ��ʱ��ֵ
- function TagHisValueInfo() {
- var time = "";
- var tagArray = new Array();
- }
- //��ǩ�ṹ
- function ReportTagHisValueObj() {
- var tag = "";
- var val = 0;
- }
- //��Ҫ��ѯ��ͳ����Ϣ
- function TagStasticSearchInfo() {
- var startTime;
- var endTime;
- var tagArray = new Array();
- }
- //��ǩ�ṹ
- function ReportTagStasticObj() {
- var tag = "";
- var Min = "";
- var Max = "";
- var Diff = "";
- var Avg = "";
- var Total = "";
- var CalcTotal = "";//算术求和
- }
- //��ȡ��ʷʱ��ֵ
- function GetReportTagHisValue(tTime, tagstr) {
- for (var i = 0; i < ReportTagHisValueSearchInfoList.length; i++) {
- var tagInfo = ReportTagHisValueSearchInfoList[i];
- if (tagInfo.time.getTime() == tTime.getTime())//ʱ����ͬ
- {
- var ttTag = tagInfo.tagArray[tagstr];
- if (!ttTag)
- return "";
- return ttTag.val;
- }
- }
- }
- //��ȡͳ��ֵ
- function GetTagStasticSearchValue(sTime, eTime, tag, tagType) {
- for (var i = 0; i < TagStasticSearchInfoList.length; i++) {
- var tagInfo = TagStasticSearchInfoList[i];
- if (tagInfo.startTime.getTime() == sTime.getTime() && tagInfo.endTime.getTime() == eTime.getTime()) {
- var tempTag = tag;
- var dayNum = (tagInfo.endTime.getTime() - tagInfo.startTime.getTime()) / 1000 / 24 / 3600;//����
- //if((tagInfo.endTime.getTime()-tagInfo.startTime.getTime())/1000/24/3600>0.5&&
- if (tagType == "min" || tagType == "max" || tagType == "avg" || tagType == "total") //����2�죬��ȡ��С�����ƽ��ȡͳ��ֵ
- {
- tempTag = tempTag.replace(".", "_");
- tempTag = "report." + tempTag + "_" + tagType;
- }
- else if (tagType == "dif" || tagType == "diff" || tagType == "sub") //��ֵ
- {
- tempTag = tempTag.replace(".", "_");
- tempTag = "report." + tempTag + "_diff";
- }
- var ttTag = tagInfo.tagArray[tempTag];
- if (!ttTag)
- return "";
- if (ttTag.tag == tempTag) {
- if (tagType == "min")
- return ttTag.Min;
- else if (tagType == "max")
- return ttTag.Max;
- else if (tagType == "diff")
- return ttTag.CalcTotal;//ƽ��ֵ*��������ʾÿ���ֵ�ĺͣ���Ϊ�ܲ�ֵ
- else if (tagType == "sub")
- return ttTag.CalcTotal;
- else if (tagType == "dif")
- return ttTag.CalcTotal;
- else
- return ttTag.Avg;
- }
- }
- }
- return "";
- }
- //��Ӱ�ʱ��ֵ��ѯ����
- function AddToTagHisValueArray(time, tag) {
- if (!time)
- return;
- if (!tag)
- return;
- for (var i = 0; i < ReportTagHisValueSearchInfoList.length; i++) {
- var tagInfo = ReportTagHisValueSearchInfoList[i];
- if (tagInfo.time.getTime() == time.getTime())//ʱ����ͬ
- {
- var tagObj = tagInfo.tagArray[tag];
- if (!tagObj) {
- var tagObj = new ReportTagHisValueObj();
- tagObj.tag = tag;
- tagObj.val = 0;
- tagInfo.tagArray[tag] = tagObj;
- }
- return;
- }
- }
- var tempInfo = new TagHisValueInfo();
- tempInfo.time = time;
- tempInfo.tagArray = new Array();
- ReportTagHisValueSearchInfoList.push(tempInfo);
- var tagObj = new ReportTagHisValueObj();
- tagObj.tag = tag;
- tempInfo.tagArray[tag] = tagObj;
- }
- //��Ӳ�ѯ��Ϣ ��������ʼʱ�䣬����ʱ�䣬��ǩ��
- function AddToTagStasticSearchArray(sTime, eTime, tag) {
- for (var i = 0; i < TagStasticSearchInfoList.length; i++) {
- var tagInfo = TagStasticSearchInfoList[i];
- if (tagInfo.startTime.getTime() == sTime.getTime() && tagInfo.endTime.getTime() == eTime.getTime()) {
- var tagObj = tagInfo.tagArray[tag];
- if (!tagObj) {
- var tagObj = new ReportTagStasticObj();
- tagObj.tag = tag;
- tagObj.Min = 0;
- tagObj.Max = 0;
- tagObj.Avg = 0;
- tagObj.Total = 0;
- tagObj.Diff = 0;
- tagInfo.tagArray[tag] = tagObj;
- }
- return;
- }
- }
- var tempInfo = new TagStasticSearchInfo();
- tempInfo.startTime = sTime;
- tempInfo.endTime = eTime;
- tempInfo.tagArray = new Array();
- TagStasticSearchInfoList.push(tempInfo);
- var tagObj = new ReportTagStasticObj();
- tagObj.tag = tag;
- tempInfo.tagArray[tag] = tagObj;
- }
- //�������й�ʽ����ӵ����Ե��б�
- function AnalysisAllFunc(funcArray) {
- if (!funcArray)
- return;
- for (var i = 0; i < funcArray.length; i++) {
- var calcu = funcArray[i];
- if (!calcu)
- continue;
- if (calcu.funcName == "GetTagHisValue")//ͳ��ʱ��ֵ������
- {
- var parmArray = calcu.parmList;
- if (!parmArray)
- continue;
- if (parmArray.length >= 2) {
- var tagStr = parmArray[0];
- var timeStr = parmArray[1];
-
- var ReportTime = window[timeStr];
- if (!ReportTime)
- continue;
- var tempTime = new Date(Date.parse(ReportTime));
- if (!tempTime)
- continue;
-
- //偏移秒
- var addSec=0;
- if(parmArray.length>=3)
- {
- addSec=parseInt(parmArray[2]);
- tempTime.setSeconds( tempTime.getSeconds()+addSec);
- }
- AddToTagHisValueArray(tempTime, tagStr);
- }
- }
- else if (calcu.funcName == "GetTagTimeStasticValue")//ͳ��ʱ���ֵ����,���£����꣬����ʱ���
- {
- var parmArray = calcu.parmList;
- if (!parmArray)
- continue;
- if (parmArray.length >= 4) {
- var tagStr = parmArray[0];
- var timeStr = parmArray[1];
- var ReportTimeType = parmArray[2];
- var tagType = parmArray[3];
- var ReportTime = window[timeStr];
- if (!ReportTime)
- return 0;
- var tempStartTime = new Date(Date.parse(ReportTime));;
- var tempEndTime = new Date(Date.parse(ReportTime));;
- if (ReportTimeType == 'd' || ReportTimeType == 'D') {
- tempStartTime.setHours(0);
- tempStartTime.setMinutes(0);
- tempStartTime.setSeconds(0);
- tempEndTime.setHours(23);
- tempEndTime.setMinutes(59);
- tempEndTime.setSeconds(59);
- }
- else if (ReportTimeType == 'm' || ReportTimeType == 'M') {
- tempStartTime.setDate(1);
- tempStartTime.setHours(0);
- tempStartTime.setMinutes(0);
- tempStartTime.setSeconds(0);
- tempEndTime.setMonth(tempEndTime.getMonth() + 1);
- tempEndTime.setDate(0);
- tempEndTime.setHours(23);
- tempEndTime.setMinutes(59);
- tempEndTime.setSeconds(59);
- }
- else if (ReportTimeType == 'y' || ReportTimeType == 'Y') {
- tempStartTime.setMonth(0);
- tempStartTime.setDate(1);
- tempStartTime.setHours(0);
- tempStartTime.setMinutes(0);
- tempStartTime.setSeconds(0);
- var year = tempEndTime.getYear();
- tempEndTime.setYear(year + 1 + 1900);
- tempEndTime.setMonth(0);
- tempEndTime.setDate(0);
- tempEndTime.setHours(23);
- tempEndTime.setMinutes(59);
- tempEndTime.setSeconds(59);
- }
- if (tagType == "min" || tagType == "max" || tagType == "avg" || tagType == "total") //��С�����ƽ��ȡͳ��ֵ
- {
- tagStr = tagStr.replace(".", "_");
- tagStr = "report." + tagStr + "_" + tagType;
- AddToTagStasticSearchArray(tempStartTime, tempEndTime, tagStr);
- }
- else if (tagType == "dif" || tagType == "diff" || tagType == "sub") //��ֵ
- {
- tagStr = tagStr.replace(".", "_");
- tagStr = "report." + tagStr + "_diff";
- AddToTagStasticSearchArray(tempStartTime, tempEndTime, tagStr);
- }
- }
- }
- else if (calcu.funcName == "GetTagTimeStasticValue2")//ͳ��ʱ���ֵ����
- {
- var parmArray = calcu.parmList;
- if (!parmArray)
- continue;
- if (parmArray.length >= 4) {
- var tagStr = parmArray[0];
- var startTimeStr = parmArray[1];
- var endTimeStr = parmArray[2];
- var tagType = parmArray[3];
- tagStr = tagStr.replace("\"", "");
- startTimeStr = startTimeStr.replace("\"", "");
- endTimeStr = endTimeStr.replace("\"", "");
- tagType = tagType.replace("\"", "");
- tagStr = tagStr.replace("\"", "");
- startTimeStr = startTimeStr.replace("\"", "");
- endTimeStr = endTimeStr.replace("\"", "");
- tagType = tagType.replace("\"", "");
- var ReportStartTime = window[startTimeStr];
- var ReportEndTime = window[endTimeStr];
- var tempStartTime = new Date(Date.parse(ReportStartTime));
- var tempEndTime = new Date(Date.parse(ReportEndTime));
- //if((tempEndTime.getTime()-tempStartTime.getTime())/1000/24/3600>0.5&&
- if (tagType == "min" || tagType == "max" || tagType == "avg" || tagType == "total") //��С�����ƽ��ȡͳ��ֵ
- {
- tagStr = tagStr.replace(".", "_");
- tagStr = "report." + tagStr + "_" + tagType;
- AddToTagStasticSearchArray(tempStartTime, tempEndTime, tagStr);
- }
- else if (tagType == "dif" || tagType == "diff" || tagType == "sub") //��ֵ
- {
- tagStr = tagStr.replace(".", "_");
- tagStr = "report." + tagStr + "_diff";
- AddToTagStasticSearchArray(tempStartTime, tempEndTime, tagStr);
- }
- }
- }
- }
- }
- //����spread��ʽ
- function resetSpread(spread) {
- var sheet = spread.getSheet(0);
- sheet.options.colHeaderVisible = false;
- sheet.options.rowHeaderVisible = false;
- spread.options.newTabVisible = false;
- spread.options.tabStripVisible = false;
- spread.options.showHorizontalScrollbar = true;
- //���ݱ�����������ʾ����������ֻ�ܻ�����β
- spread.options.scrollbarMaxAlign = true;
- //spread.options.scrollbarShowMax=true;
- spread.verticalScrollBarWidth = 10;
- }
- //���뱨���json����
- function importJSON(spread, jsonData) {
- if (!spread)
- return;
- var start = new Date();
- spread.suspendPaint();
- //ApplyCustomFunc(spread);
- ApplyCustomFunc(spread);
- spread.fromJSON(jsonData);
- //var json = spread.toJSON();
- //spread.fromJSON(json);
- resetSpread(spread);
- spread.resumePaint();
- //ResetFormular(spread);
- var useTime = (new Date() - start);
- console.log("import use time:" + useTime);
- }
- //ˢ�±���
- function FreshReport(spread, exportFileName, isWhiteBackBlackFont, jsonFuncData) {
- if (!spread)
- return;
- var fStartTime = new Date();
- var curSheet = spread.getActiveSheet();
- if (!curSheet)
- return;
- TagStasticSearchInfoList = new Array();//����б�
- ReportTagHisValueSearchInfoList = new Array();////����б�
- ReportAnsnDoneNum = 0;
- setInterval(function()//����첽����ȫ����ɺ�ִ�з��Զ���ļ���
- {
- if(parseInt(ReportAnsnDoneNum)>=parseInt(ReportAnsnFuncNum))//����ȫ�����
- {
- ReportAnsnDoneNum=0;
- DoNoCustomFunc(spread);
- }
- },1000);
- //spread.resumeCalcService();//ˢ�±�����ִ�����к�����
- //GetAllTag(spread);//�����ѵĽ��������ٶ�,2018-1-27���ģ�������ʱ����������õ��ĺ���
- //DoCustomNoAnsnFunc(spread);
- //������ʽ������
- AnalysisAllFunc(jsonFuncData);
- //û��ͳ�Ʋ�ѯʱ
- if (TagStasticSearchInfoList.length <= 0 && ReportTagHisValueSearchInfoList.length <= 0) {
- spread.resumeCalcService();//ˢ�±�����ִ�����к�����
- ResetFormular(spread)
- spread.repaint();
- if (exportFileName)
- SpreadExport(spread, exportFileName);
- isExporting = false;
- return;
- }
- //�ܵIJ�ѯ����
- var TotalSearchNum = TagStasticSearchInfoList.length + ReportTagHisValueSearchInfoList.length;
- var ReceiveNum = 0;
- //��ȡʱ���ͳ��ֵ������
- var midTime = new Date();
- console.log("analysis func use time:" + (midTime - fStartTime));
- for (var i = 0; i < TagStasticSearchInfoList.length; i++)
- {
- (function ()//将请求和返回放入一个函数,保证变量对应
- {
- var tagSearch1 = TagStasticSearchInfoList[i];
- if (!tagSearch1)
- return;
- var ssTime = tagSearch1.startTime;
- var eeTime = tagSearch1.endTime;
- var tagStr = "";
- for (var key in tagSearch1.tagArray) {
- tagStr += key + ",";
- }
- var urlStr = "http://" + webServiceIP + ":" + webServicePort + "/api/HistorySummary?tagName=";
- urlStr += tagStr + "&beginTime=" + ssTime.Format("yyyy-MM-dd hh:mm:ss") + "&endTime=" + eeTime.Format("yyyy-MM-dd hh:mm:ss") + "&dataType=snap";
- $.ajax({
- type: 'GET',
- url: urlStr,
- dataType: 'json',
- cache: true,
- error: function (data) {
- console.log("HistorySummary error!");
- },
- success: function (data) {
- if (!data)
- return;
- for (var key in data) {
- //console.log("answer:"+key);
- var tagData = data[key];
- if (!tagData)
- continue;
- var ttTag = tagSearch1.tagArray[key];
- if (!ttTag)
- continue;
- if (ttTag.tag == key) {
- ttTag.Min = GetDital(tagData.Min, 3);
- ttTag.Max = GetDital(tagData.Max, 3);
- ttTag.Avg = GetDital(tagData.CalcAvg, 3);
- ttTag.Diff = GetDital(tagData.Difference, 3);
- ttTag.Total = GetDital(tagData.Total, 3);
- ttTag.CalcTotal = GetDital(tagData.CalcTotal, 3);
- }
- }
- ReceiveNum++;
- if (ReceiveNum >= TotalSearchNum)//ȫ�����غ�ˢ��ҳ������
- {
- spread.resumeCalcService();//ˢ�±�����ִ�����к�����
- ResetFormular(spread)
- spread.repaint();
- midTime = new Date();
- console.log("get data use time:" + (midTime - fStartTime));
- console.log("-----------------------------------");
- if (exportFileName)
- SpreadExport(spread, exportFileName, isWhiteBackBlackFont);
- isExporting = false;
- }
- }
- });
- }());
- }
- //��ȡ��ʷʱ��ֵ
- for (var i = 0; i < ReportTagHisValueSearchInfoList.length; i++) {
- (function ()//将请求和返回放入一个函数,保证变量对应
- {
- var tagSearch = ReportTagHisValueSearchInfoList[i];
- if (!tagSearch)
- return;
- var ssTime = tagSearch.time;
- var tagStr = "";
- for (var keys in tagSearch.tagArray) {
- tagStr += keys + ",";
- }
- var urlStr = "http://" + webServiceIP + ":" + webServicePort + "/api/History?tagName=";
- urlStr += tagStr + "&time=" + ssTime.Format("yyyy-MM-dd hh:mm:ss");
- $.ajax({
- type: 'GET',
- url: urlStr,
- dataType: 'json',
- cache: true,
- error: function (data) {
- console.log("HistorySummary error!");
- },
- success: function (data) {
- if (!data)
- return;
- for (var key in data) {
- //console.log("answer:"+key);
- var tagData = data[key];
- if (!tagData)
- return;
- var ttTag = tagSearch.tagArray[key];
- if (!ttTag)
- return;
- if (ttTag.tag == key) {
- ttTag.val = GetDital(tagData.Value, 3);
- }
- }
- ReceiveNum++;
- if (ReceiveNum >= TotalSearchNum)//ȫ�����غ�ˢ��ҳ������
- {
- spread.resumeCalcService();//ˢ�±�����ִ�����к�����
- ResetFormular(spread)
- spread.repaint();
- midTime = new Date();
- console.log("get data use time:" + (midTime - fStartTime));
- console.log("-----------------------------------");
- if (exportFileName)
- SpreadExport(spread, exportFileName, isWhiteBackBlackFont);
- isExporting = false;
- }
- }
- });
- }());
- }
- var doneFreshTime = new Date();
- console.log("done fresh report use time:" + (doneFreshTime - fStartTime));
- }
- function SpreadExport(spread, exportFileName, isChangeBackFont) {
- var fileName = exportFileName + '.xlsx';
- if (fileName.substr(-5, 5) !== '.xlsx') {
- fileName += '.xlsx';
- }
- var json = spread.toJSON();
- sheet1 = spread.getActiveSheet();
- var spread2 = new GC.Spread.Sheets.Workbook();
- spread2.fromJSON(json);
- var sheet2 = spread2.getActiveSheet();
- var array = sheet1.getArray(0, 0, sheet1.getRowCount(), sheet1.getColumnCount(), false);
- sheet2.clear(0, 0, sheet2.getRowCount(), sheet2.getColumnCount(), GC.Spread.Sheets.SheetArea.viewport, GC.Spread.Sheets.StorageType.data);
- sheet2.setArray(0, 0, array, false);
- //����ǿ�ư���
- if (parseInt(isChangeBackFont) > 0) {
- var colNum = sheet2.getColumnCount();
- var rowNum = sheet2.getRowCount();
- spread2.options.backColor = "#ffffff";
- sheet2.options.colHeaderVisible = true;
- sheet2.options.rowHeaderVisible = true;
- //spread2.options.grayAreaBackColor="#ffffff";
- var rowstyle = new GC.Spread.Sheets.Style();
- rowstyle.backColor = 'white';
- rowstyle.foreColor = 'black';
- rowstyle.borderColor = 'black';
- for (var ii = 0; ii < rowNum; ii++) {
- sheet2.setStyle(ii, -1, rowstyle, GC.Spread.Sheets.SheetArea.viewport);
- }
- sheet2.getRange(0, 0, rowNum, colNum, GC.Spread.Sheets.SheetArea.viewport).backColor("white");
- sheet2.getRange(0, 0, rowNum, colNum, GC.Spread.Sheets.SheetArea.viewport).setBorder(new GC.Spread.Sheets.LineBorder("#aaaaaa", GC.Spread.Sheets.LineStyle.thin), { all: true }, 1);
- sheet2.options.gridline = { color: "#aaaaaa", showVerticalGridline: false, showHorizontalGridline: false };
- sheet2.getRange(0, 0, rowNum, colNum, GC.Spread.Sheets.SheetArea.viewport).foreColor('black');
- }
- //sheet2.options.gridline = {color:"#000000", showVerticalGridline: true, showHorizontalGridline: true};
- ResetFormular(spread2);
- json = spread2.toJSON();
- // here is excel IO API
- excelIo = new GC.Spread.Excel.IO();
- excelIo.save(json, function (blob) {
- saveAs(blob, fileName);
- }, function (e) {
- // process error
- alert(e.message);
- });
- }
|