1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588 |
- BemsWebApplication.PlanConsumePrediction = function (params, viewInfo) {
- 'use strict';
- var endpointSelector = "";
- if (BemsWebApplication.config.mode == "production") {
- endpointSelector = new DevExpress.EndpointSelector(BemsWebApplication.config.endpoints).config.db.production;
- } else {
- endpointSelector = new DevExpress.EndpointSelector(BemsWebApplication.config.endpoints).config.db.local;
- }
- ////// 전역 변수 설정 부
- var m3calValue;
- var applyonoff = false;
- var visiblePopup = ko.observable(false);
- var dailyvisiblePopup = ko.observable(false);
- var monthvisiblePopup = ko.observable(false);
- var pastvisiblePopup = ko.observable(false);
- var TodayAdd = new Date();
- var DailyData = [{ daily: "일" }, { daily: "월" }, { daily: "화" }, { daily: "수" }, { daily: "목" }, { daily: "금" }, { daily: "토" }, { daily: "합계" }];
- var DailyDataID = [{ id: 1, daily: "일" }, { id: 2, daily: "월" }, { id: 3, daily: "화" }, { id: 4, daily: "수" }, { id: 5, daily: "목" }, { id: 6, daily: "금" }, { id: 7, daily: "토" }];
- var MonthDataID = [{ id: 1, month: "1월" }, { id: 2, month: "2월" }, { id: 3, month: "3월" }, { id: 4, month: "4월" }, { id: 5, month: "5월" }, { id: 6, month: "6월" }, { id: 7, month: "7월" }, { id: 8, month: "8월" }, { id: 9, month: "9월" }, { id: 10, month: "10월" }, { id: 11, month: "11월" }, { id: 12, month: "12월" }];
- var FuelTypeArray = [{ FuelTypeId: 1, FacilityTypeId: 100, FormulaId: 1 }, { FuelTypeId: 2, FacilityTypeId: 101, FormulaId: 1 }, { FuelTypeId: 3, FacilityTypeId: 102, FormulaId: 1 }]
- var SiteId = BWA.UserInfo.SiteId();
- var temppaststart;
- var temppastend;
- var YearDayCnt;
- var resultarray;
- ////// 전역 변수 설정 부
- function GetGridData() {
- var gridData = new Array();
- var temp_search_day = $("#Search_Day").dxDateBox("instance").option('value');
- var GridSource = new DevExpress.data.DataSource({
- store: {
- type: "odata",
- url: endpointSelector + "/BemsEnergyDaily"
- },
- requireTotalCount: true,
- pageSize: 1100
- });
- GridSource.filter([
- ["SiteId", "=", SiteId], //사이트 아이디
- "and",
- ["ServiceTypeId", "=", 1], //사이트 아이디
- "and",
- ["CreatedDate", ">=", new Date(temp_search_day.getFullYear(), 0, 1, 0, 0, 0)],
- "and",
- ["CreatedDate", "<=", new Date(temp_search_day.getFullYear(), 11, 31, 23, 59, 59)]
- ]);
- GridSource.sort({ getter: "CreatedDate", desc: true }, { getter: "FuelTypeId", ASC: true });
- GridSource.load()
- .done(function (result) {
- if (result.length != 0) {
- var setData = {
- "DateTime": null,
- "week": null,
- "PowerValue": null,
- "GasValue": null,
- "WaterValue": null
- };
- for (var i = 0; i < result.length; i++) {
- if (result[i].FuelTypeId == 1) {
- var tempday = DailyData[result[i].CreatedDate.getDay()].daily;
- setData.week = tempday;
- setData.DateTime = result[i].CreatedDate;
- if (result[i].Prediction == null)
- setData.PowerValue = 0;
- else
- setData.PowerValue = numberup(result[i].Prediction);
- }
- else if (result[i].FuelTypeId == 2) {
- if (result[i].Prediction == null)
- setData.GasValue = 0;
- else
- setData.GasValue = numberup(result[i].Prediction / m3calValue);
- }
- else {
- if (result[i].Prediction == null)
- setData.WaterValue = 0;
- else
- setData.WaterValue = numberup(result[i].Prediction);
- }
- if (setData.PowerValue != null && setData.GasValue != null && setData.WaterValue != null) {
- gridData.push(setData);
- setData = {
- "DateTime": null,
- "week": null,
- "PowerValue": null,
- "GasValue": null,
- "WaterValue": null
- };
- }
- }
- $("#dataGrid").dxDataGrid("instance").option('dataSource', gridData);
- var dg = $("#dataGrid").dxDataGrid("instance");
- dg.refresh();
- }
- else {
- for (var i = 1; i < 13; i++) {
- var lastDay = (new Date(temp_search_day.getFullYear(), i, 0)).getDate();
- for (var j = 1; j <= lastDay; j++) {
- var setData = {
- "DateTime": new Date(temp_search_day.getFullYear(), i - 1, j, 0, 0, 0),
- "PowerValue": 0,
- "GasValue": 0,
- "WaterValue": 0
- };
- gridData.push(setData);
- }
- }
- $("#dataGrid").dxDataGrid("instance").option('dataSource', gridData);
- var dg = $("#dataGrid").dxDataGrid("instance");
- dg.refresh();
- }
- })
- .fail(function (error) {
- utils.toast.show(error);
- });
- }
- function MonthGetGridData() {
- var MonthgridData = new Array();
- $("#Search_Day_Month").dxSelectBox("instance").option('value', "");
- $("#Power_Month_txt").dxTextBox("instance").option('value', "");
- $("#Gas_Month_txt").dxTextBox("instance").option('value', "");
- $("#Water_Month_txt").dxTextBox("instance").option('value', "");
- var Month_Day = $("#Search_Month_Day").dxDateBox("instance").option('value');
- var MonthGridSource = new DevExpress.data.DataSource({
- store: {
- type: "odata",
- url: endpointSelector + "/BemsEnergyConfigPercentMonth"
- },
- requireTotalCount: true,
- pageSize: 12
- });
- MonthGridSource.filter([
- ["SiteId", "=", SiteId], //사이트 아이디
- "and",
- ["Year", "=", Month_Day.getFullYear()]
- ]);
- MonthGridSource.sort({ getter: "Month", asc: true });
- MonthGridSource.load()
- .done(function (result) {
- if (result.length != 0) {
- var tempower = 0, tempgas = 0, tempwater = 0;
- for (var i = 0; i < result.length; i++) {
- tempower += result[i].Electricity;
- tempgas += result[i].Gas;
- tempwater += result[i].Water;
- var MonthsetData =
- {
- "MonthDateTime": (i + 1),
- "PowerMonthValue": result[i].Electricity,
- "GasMonthValue": result[i].Gas,
- "WaterMonthValue": result[i].Water
- };
- MonthgridData.push(MonthsetData);
- }
- var MonthsetData =
- {
- "MonthDateTime": "합계",
- "PowerMonthValue": parseFloat(tempower.toFixed(2)),
- "GasMonthValue": parseFloat(tempgas.toFixed(2)),
- "WaterMonthValue": parseFloat(tempwater.toFixed(2))
- };
- MonthgridData.push(MonthsetData);
- $("#MonthdataGrid").dxDataGrid("instance").option('dataSource', MonthgridData);
- var dg = $("#MonthdataGrid").dxDataGrid("instance");
- dg.refresh();
- }
- else {
- for (var i = 0; i < 12; i++) {
- var MonthsetData =
- {
- "MonthDateTime": (i + 1),
- "PowerMonthValue": 0,
- "GasMonthValue": 0,
- "WaterMonthValue": 0
- };
- MonthgridData.push(MonthsetData);
- }
- var MonthsetData =
- {
- "MonthDateTime": "합계",
- "PowerMonthValue": 0,
- "GasMonthValue": 0,
- "WaterMonthValue": 0
- };
- MonthgridData.push(MonthsetData);
- $("#MonthdataGrid").dxDataGrid("instance").option('dataSource', MonthgridData);
- var dg = $("#MonthdataGrid").dxDataGrid("instance");
- dg.refresh();
- }
- })
- .fail(function (error) {
- utils.toast.show(error);
- });
- }
- function numberup(num) {
- return Math.round(num * 100) / 100.0;
- }
- function DailyGetGridData() {
- var DailygridData = new Array();
- $("#Search_Day_Daily").dxSelectBox("instance").option('value', "");
- $("#Power_Daily_txt").dxTextBox("instance").option('value', "");
- $("#Gas_Daily_txt").dxTextBox("instance").option('value', "");
- $("#Water_Daily_txt").dxTextBox("instance").option('value', "");
- var Daily_Day = $("#Search_Daily_Day").dxDateBox("instance").option('value');
- var DailyGridSource = new DevExpress.data.DataSource({
- store: {
- type: "odata",
- url: endpointSelector + "/BemsEnergyConfigPercentWeek"
- },
- requireTotalCount: true,
- pageSize: 7
- });
- DailyGridSource.filter([
- ["SiteId", "=", SiteId], //사이트 아이디
- "and",
- ["Year", "=", Daily_Day.getFullYear()]
- ]);
- DailyGridSource.sort({ getter: "Week", asc: true });
- DailyGridSource.load()
- .done(function (result) {
- if (result.length != 0) {
- var tempower = 0, tempgas = 0, tempwater = 0;
- for (var i = 0; i < result.length; i++) {
- tempower += result[i].Electricity;
- tempgas += result[i].Gas;
- tempwater += result[i].Water;
- var DailysetData =
- {
- "DailyDateTime": DailyData[i].daily,
- "PowerDailyValue": result[i].Electricity,
- "GasDailyValue": result[i].Gas,
- "WaterDailyValue": result[i].Water
- };
- DailygridData.push(DailysetData);
- }
- var DailysetData =
- {
- "DailyDateTime": "합계",
- "PowerDailyValue": parseFloat(tempower.toFixed(2)),
- "GasDailyValue": parseFloat(tempgas.toFixed(2)),
- "WaterDailyValue": parseFloat(tempwater.toFixed(2))
- };
- DailygridData.push(DailysetData);
- $("#DailydataGrid").dxDataGrid("instance").option('dataSource', DailygridData);
- var dg = $("#DailydataGrid").dxDataGrid("instance");
- dg.refresh();
- }
- else {
- for (var i = 0; i < 7; i++) {
- var DailysetData =
- {
- "DailyDateTime": DailyData[i].daily, "PowerDailyValue": 0, "GasDailyValue": 0, "WaterDailyValue": 0
- };
- DailygridData.push(DailysetData);
- }
- var DailysetData =
- {
- "DailyDateTime": "합계", "PowerDailyValue": 0, "GasDailyValue": 0, "WaterDailyValue": 0
- };
- DailygridData.push(DailysetData);
- $("#DailydataGrid").dxDataGrid("instance").option('dataSource', DailygridData);
- var dg = $("#DailydataGrid").dxDataGrid("instance");
- }
- })
- .fail(function (error) {
- utils.toast.show(error);
- });
- }
- function handleViewShowing() {
- var getTOEDataSource = new DevExpress.data.DataSource({
- store: {
- type: "odata",
- url: endpointSelector + "/BemsFactorToe"
- },
- requireTotalCount: true,
- pageSize: 3
- });
- getTOEDataSource.load()
- .done(function (Result) {
- var powertoe, gastoe;
- if (Result.length != 0) {
- for (var i = 0; i < Result.length; i++) {
- if (Result[i].FuelTypeId == 1) {
- powertoe = Result[i].TotalFactor;
- }
- if (Result[i].FuelTypeId == 2) {
- gastoe = Result[i].TotalFactor;
- }
- }
- if (powertoe != null && gastoe != null)
- m3calValue = gastoe / powertoe;
- }
- else {
- utils.toast.show("[BemsFactorToe] 데이터가 없습니다.");
- }
- })
- .fail(function (error) {
- utils.toast.show("[BemsFactorToe] 데이터를 불러오는데 실패 하였습니다.");
- });
- }
- function handleViewShown() {
- $("#Search_Day").dxDateBox({
- value: TodayAdd,
- maxZoomLevel: 'decade',
- formatString: "yyyy년",
- onValueChanged: function () {
- GetGridData();
- }
- });
- $("#Prediction_Btn").dxButton({
- text: "사용량 예측 설정",
- onClick: function () {
- $("#Past_Btn").dxButton({
- text: "조회",
- onClick: function () {
- applyonoff = false;
- pastvisiblePopup(true);
- }
- });
- $("#Month_Btn").dxButton({
- text: "설정",
- onClick: function () {
- monthvisiblePopup(true);
- }
- });
- $("#Day_Btn").dxButton({
- text: "설정",
- onClick: function () {
- dailyvisiblePopup(true);
- }
- });
- visiblePopup(true);
- }
- });
- $("#dataGrid").dxDataGrid({
- paging: {
- pageSize: 16
- }
- });
- GetGridData();
- }
- var searchViewOptions = {
- }
- function handleSearchInSearchView() {
- }
- function Get_Energy_Data(fueltypeid) {
- if (fueltypeid == 1) {
- var metaDataSource = new DevExpress.data.DataSource({
- store: {
- type: "odata",
- url: endpointSelector + "/BemsFormulaParameter"
- },
- map: function (itemData) {
- return {
- SiteId: itemData.SiteId,
- FacilityTypeId: itemData.FacilityTypeId,
- FormulaId: itemData.FormulaId,
- ParameterFacilityCode: itemData.ParameterFacilityCode,
- ParameterPropertyId: itemData.ParameterPropertyId
- }
- },
- requireTotalCount: true,
- pageSize: 20
- });
- metaDataSource.filter([
- ["SiteId", "=", SiteId],
- "and",
- ["FacilityTypeId", "=", FuelTypeArray[0].FacilityTypeId],
- "and",
- ["FormulaId", "=", FuelTypeArray[0].FormulaId]
- ]);
- metaDataSource.sort({ getter: "ParameterPropertyId", asc: true });
- metaDataSource.load()
- .done(function (metaResult) {
- var power = 0, total_cnt = 0, cnt = 0;
- if (metaResult.length != 0) {
- for (var j = 0; j < metaResult.length; j++) {
- var FuelDataSource = new DevExpress.data.DataSource({
- store: {
- type: "odata",
- url: endpointSelector + "/BemsMonitoringPointHistoryDaily"
- },
- requireTotalCount: true,
- pageSize: 366
- });
- FuelDataSource.filter([
- ["SiteId", "=", SiteId],
- "and",
- ["FacilityCode", "=", metaResult[j].ParameterFacilityCode],
- "and",
- ["PropertyId", "=", metaResult[j].ParameterPropertyId],
- "and",
- ["CreatedDateTime", ">=", new Date(temppaststart.getFullYear(), temppaststart.getMonth(), temppaststart.getDate(), 0, 0, 0)],
- "and",
- ["CreatedDateTime", "<=", new Date(temppastend.getFullYear(), temppastend.getMonth(), temppastend.getDate(), 23, 59, 59)]
- ]);
- FuelDataSource.sort({ getter: "CreatedDateTime", asc: true });
- FuelDataSource.load()
- .done(function (result) {
- total_cnt += result.length;
- for (var k in result) {
- power += result[k].DailyValue;
- cnt++
- }
- if (total_cnt == cnt && total_cnt != 0)
- $("#Power_txt").dxTextBox("instance").option('value', power.toFixed(0));
- })
- .fail(function (error) {
- utils.toast.show("전력사용량 데이터를 불러오는데 실패 하였습니다.");
- });
- }
- }
- else {
- utils.toast.show("전력사용량 데이터가 없습니다.");
- }
- })
- .fail(function (error) {
- utils.toast.show("메타 데이터를 불러오는데 실패 하였습니다.");
- });
- }
- else if (fueltypeid == 2) {
- var metaDataSource = new DevExpress.data.DataSource({
- store: {
- type: "odata",
- url: endpointSelector + "/BemsFormulaParameter"
- },
- map: function (itemData) {
- return {
- SiteId: itemData.SiteId,
- FacilityTypeId: itemData.FacilityTypeId,
- FormulaId: itemData.FormulaId,
- ParameterFacilityCode: itemData.ParameterFacilityCode,
- ParameterPropertyId: itemData.ParameterPropertyId
- }
- },
- requireTotalCount: true,
- pageSize: 20
- });
- metaDataSource.filter([
- ["SiteId", "=", SiteId],
- "and",
- ["FacilityTypeId", "=", FuelTypeArray[1].FacilityTypeId],
- "and",
- ["FormulaId", "=", FuelTypeArray[1].FormulaId]
- ]);
- metaDataSource.sort({ getter: "ParameterPropertyId", asc: true });
- metaDataSource.load()
- .done(function (metaResult) {
- var gas = 0, total_cnt = 0, cnt = 0;
- if (metaResult.length != 0) {
- for (var j = 0; j < metaResult.length; j++) {
- var FuelDataSource = new DevExpress.data.DataSource({
- store: {
- type: "odata",
- url: endpointSelector + "/BemsMonitoringPointHistoryDaily"
- },
- requireTotalCount: true,
- pageSize: 366
- });
- FuelDataSource.filter([
- ["SiteId", "=", SiteId],
- "and",
- ["FacilityCode", "=", metaResult[j].ParameterFacilityCode],
- "and",
- ["PropertyId", "=", metaResult[j].ParameterPropertyId],
- "and",
- ["CreatedDateTime", ">=", new Date(temppaststart.getFullYear(), temppaststart.getMonth(), temppaststart.getDate(), 0, 0, 0)],
- "and",
- ["CreatedDateTime", "<=", new Date(temppastend.getFullYear(), temppastend.getMonth(), temppastend.getDate(), 23, 59, 59)]
- ]);
- FuelDataSource.sort({ getter: "CreatedDateTime", asc: true });
- FuelDataSource.load()
- .done(function (result) {
- total_cnt += result.length;
- for (var k in result) {
- gas += result[k].DailyValue;
- cnt++
- }
- if (total_cnt == cnt && total_cnt != 0)
- $("#Gas_txt").dxTextBox("instance").option('value', gas.toFixed(0));
- })
- .fail(function (error) {
- utils.toast.show("가스사용량 데이터를 불러오는데 실패 하였습니다.");
- });
- }
- }
- else {
- utils.toast.show("가스사용량 데이터가 없습니다.");
- }
- })
- .fail(function (error) {
- utils.toast.show("메타 데이터를 불러오는데 실패 하였습니다.");
- });
- }
- else {
- var metaDataSource = new DevExpress.data.DataSource({
- store: {
- type: "odata",
- url: endpointSelector + "/BemsFormulaParameter"
- },
- map: function (itemData) {
- return {
- SiteId: itemData.SiteId,
- FacilityTypeId: itemData.FacilityTypeId,
- FormulaId: itemData.FormulaId,
- ParameterFacilityCode: itemData.ParameterFacilityCode,
- ParameterPropertyId: itemData.ParameterPropertyId
- }
- },
- requireTotalCount: true,
- pageSize: 20
- });
- metaDataSource.filter([
- ["SiteId", "=", SiteId],
- "and",
- ["FacilityTypeId", "=", FuelTypeArray[2].FacilityTypeId],
- "and",
- ["FormulaId", "=", FuelTypeArray[2].FormulaId]
- ]);
- metaDataSource.sort({ getter: "ParameterPropertyId", asc: true });
- metaDataSource.load()
- .done(function (metaResult) {
- var water = 0, total_cnt = 0, cnt = 0;
- if (metaResult.length != 0) {
- for (var j = 0; j < metaResult.length; j++) {
- var FuelDataSource = new DevExpress.data.DataSource({
- store: {
- type: "odata",
- url: endpointSelector + "/BemsMonitoringPointHistoryDaily"
- },
- requireTotalCount: true,
- pageSize: 366
- });
- FuelDataSource.filter([
- ["SiteId", "=", SiteId],
- "and",
- ["FacilityCode", "=", metaResult[j].ParameterFacilityCode],
- "and",
- ["PropertyId", "=", metaResult[j].ParameterPropertyId],
- "and",
- ["CreatedDateTime", ">=", new Date(temppaststart.getFullYear(), temppaststart.getMonth(), temppaststart.getDate(), 0, 0, 0)],
- "and",
- ["CreatedDateTime", "<=", new Date(temppastend.getFullYear(), temppastend.getMonth(), temppastend.getDate(), 23, 59, 59)]
- ]);
- FuelDataSource.sort({ getter: "CreatedDateTime", asc: true });
- FuelDataSource.load()
- .done(function (result) {
- total_cnt += result.length;
- for (var k in result) {
- water += result[k].DailyValue;
- cnt++
- }
- if (total_cnt == cnt && total_cnt != 0)
- $("#Water_txt").dxTextBox("instance").option('value', water.toFixed(0));
- })
- .fail(function (error) {
- utils.toast.show("수도사용량 데이터를 불러오는데 실패 하였습니다.");
- });
- }
- }
- else {
- utils.toast.show("수도사용량 데이터가 없습니다.");
- }
- })
- .fail(function (error) {
- utils.toast.show("메타 데이터를 불러오는데 실패 하였습니다.");
- });
- }
- }
- function numberWithCommas(x) {
- return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
- }
- var viewModel = $.extend(BWA.CommonView.create(params, viewInfo, searchViewOptions, ko.observable(null), handleViewShown, null, handleSearchInSearchView),
- {
- viewShowing: handleViewShowing,
- dataGrid: utils.datagrid.defaultOptions({
- width: 1200,
- height: 610,
- columns: [
- {
- dataField: 'DateTime',
- width: '20%',
- caption: "날짜",
- alignment: 'center',
- dataType: 'date',
- format: 'yyyy-MM-dd',
- sortOrder: 'asc',
- },
- {
- dataField: 'week',
- width: '5%',
- caption: "요일",
- alignment: 'center'
- },
- {
- dataField: 'PowerValue',
- width: '25%',
- caption: "전기(kWh)",
- alignment: 'center',
- format: {
- type: "fixedPoint",
- precision: 2
- },
- },
- {
- dataField: 'GasValue',
- width: '25%',
- caption: "가스(m3)",
- alignment: 'center',
- format: {
- type: "fixedPoint",
- precision: 2
- },
- },
- {
- dataField: 'WaterValue',
- width: '25%',
- caption: "수도(m3)",
- alignment: 'center',
- format: {
- type: "fixedPoint",
- precision: 2
- },
- }
- ]
- }),
- MonthdataGrid: utils.datagrid.defaultOptions({
- width: 640,
- height: 445,
- columns: [
- {
- dataField: 'MonthDateTime',
- width: '25%',
- caption: "월",
- alignment: 'center',
- },
- {
- dataField: 'PowerMonthValue',
- width: '25%',
- caption: "전기(%)",
- alignment: 'center',
- format: {
- type: "fixedPoint",
- precision: 2
- },
- },
- {
- dataField: 'GasMonthValue',
- width: '25%',
- caption: "가스(%)",
- alignment: 'center',
- format: {
- type: "fixedPoint",
- precision: 2
- },
- },
- {
- dataField: 'WaterMonthValue',
- width: '25%',
- caption: "수도(%)",
- alignment: 'center',
- format: {
- type: "fixedPoint",
- precision: 2
- },
- }
- ],
- pager: {
- visible: false
- }
- }),
- DailydataGrid: utils.datagrid.defaultOptions({
- width: 640,
- height: 290,
- columns: [
- {
- dataField: 'DailyDateTime',
- width: '25%',
- caption: "날짜",
- alignment: 'center',
- },
- {
- dataField: 'PowerDailyValue',
- width: '25%',
- caption: "전기(%)",
- alignment: 'center',
- format: {
- type: "fixedPoint",
- precision: 2
- },
- },
- {
- dataField: 'GasDailyValue',
- width: '25%',
- caption: "가스(%)",
- alignment: 'center',
- format: {
- type: "fixedPoint",
- precision: 2
- },
- },
- {
- dataField: 'WaterDailyValue',
- width: '25%',
- caption: "수도(%)",
- alignment: 'center',
- format: {
- type: "fixedPoint",
- precision: 2
- },
- }
- ],
- pager: {
- visible: false
- }
- })
- });
- viewModel.popupOptions = {
- width: 500,
- height: 200,
- visible: visiblePopup,
- dragEnabled: true,
- shading: true,
- closeOnOutsideClick: true,
- shadingColor: 'transparent',
- showTitle: true,
- title: "항목 선택",
- showCloseButton: true,
- onShowing: function () {
- },
- onShown: function (t, tt) {
- $("#Past_Btn").dxButton({
- text: "조회",
- onClick: function () {
- pastvisiblePopup(true);
- $("#Power_txt").dxTextBox("instance").option('value', null);
- $("#Gas_txt").dxTextBox("instance").option('value', null);
- $("#Water_txt").dxTextBox("instance").option('value', null);
- $("#Power_db_txt").dxTextBox("instance").option('value', null);
- $("#Gas_db_txt").dxTextBox("instance").option('value', null);
- $("#Water_db_txt").dxTextBox("instance").option('value', null);
- }
- });
- $("#Month_Btn").dxButton({
- text: "설정",
- onClick: function () {
- monthvisiblePopup(true);
- }
- });
- $("#Day_Btn").dxButton({
- text: "설정",
- onClick: function () {
- dailyvisiblePopup(true);
- }
- });
- },
- onHidden: function () {
- }
- };
- viewModel.pastpopupOptions = {
- width: 630,
- height: 280,
- visible: pastvisiblePopup,
- dragEnabled: true,
- shading: true,
- closeOnOutsideClick: true,
- shadingColor: 'transparent',
- showTitle: true,
- title: "과거 사용량 조회 및 일별 사용량 예측",
- showCloseButton: true,
- onShowing: function () {
- },
- onShown: function (t, tt) {
- $("#Search_Day_Past_Start").dxDateBox({
- value: new Date(TodayAdd.getFullYear(), 0, 1)
- });
- $("#Search_Day_Past_End").dxDateBox({
- value: TodayAdd
- });
- $("#Search_Past_Btn").dxButton({
- text: "조회",
- onClick: function () {
- temppaststart = $("#Search_Day_Past_Start").dxDateBox("instance").option('value');
- temppastend = $("#Search_Day_Past_End").dxDateBox("instance").option('value');
- for (var i = 1; i < 4; i++)
- Get_Energy_Data(i);
- }
- });
- $("#Power_txt").dxTextBox({
- placeholder: "전력합산",
- });
- $("#Gas_txt").dxTextBox({
- placeholder: "가스합산"
- });
- $("#Water_txt").dxTextBox({
- placeholder: "수도합산"
- });
- $("#Search_Day_Past_Year").dxDateBox({
- value: TodayAdd,
- maxZoomLevel: 'decade',
- formatString: "yyyy년",
- onValueChanged: function (data) {
- var tempdate = data.value;
- if (tempdate.getFullYear() > (TodayAdd.getFullYear() + 1)) {
- utils.toast.show("선택 연도가 내년보다 클 수 없습니다.");
- $("#Search_Day_Past_Year").dxDateBox("instance").option('value', TodayAdd);
- }
- }
- });
- $("#Power_db_txt").dxTextBox({
- placeholder: "전력합산"
- });
- $("#Gas_db_txt").dxTextBox({
- placeholder: "가스합산"
- });
- $("#Water_db_txt").dxTextBox({
- placeholder: "수도합산"
- });
- $("#LoadPanel_save").dxLoadPanel({
- message: '저장 중...',
- showIndicator: true,
- visible: false
- });
- $("#Apply_Btn").dxButton({
- text: "적용",
- onClick: function () {
- var temp_Day = $("#Search_Day_Past_Year").dxDateBox("instance").option('value');
- YearDayCnt = ((((((new Date(temp_Day.getFullYear() + 1, 0, 1).getTime()) - (new Date(temp_Day.getFullYear(), 0, 1).getTime())) / 1000) / 60) / 60) / 24);
- resultarray = new Array(YearDayCnt);
- var temp_Power = $("#Power_db_txt").dxTextBox("instance").option('value');
- var temp_Gas = $("#Gas_db_txt").dxTextBox("instance").option('value');
- temp_Gas = temp_Gas * m3calValue;
- var temp_Water = $("#Water_db_txt").dxTextBox("instance").option('value');
- if (temp_Power == "") {
- utils.toast.show("전력 입력 정보가 잘못되었습니다.");
- return;
- }
- if (temp_Gas == "") {
- utils.toast.show("가스 입력 정보가 잘못되었습니다.");
- return;
- }
- if (temp_Water == "") {
- utils.toast.show("수도 입력 정보가 잘못되었습니다.");
- return;
- }
- var temp_monthrate_array = new Array(12);
- var temp_monthdata_array = new Array(12);
- for (var i = 0; i < 12; i++) {
- temp_monthrate_array[i] = new Array(3);
- temp_monthdata_array[i] = new Array(3);
- }
- var MonthGridSource = new DevExpress.data.DataSource({
- store: {
- type: "odata",
- url: endpointSelector + "/BemsEnergyConfigPercentMonth"
- },
- requireTotalCount: true,
- pageSize: 12
- });
- MonthGridSource.filter([
- ["SiteId", "=", SiteId], //사이트 아이디
- "and",
- ["Year", "=", temp_Day.getFullYear()]
- ]);
- MonthGridSource.sort({ getter: "Month", asc: true });
- MonthGridSource.load()
- .done(function (result) {
- if (result.length != 0) {
- for (var k = 0; k < result.length; k++) {
- temp_monthrate_array[k][0] = result[k].Electricity;
- temp_monthrate_array[k][1] = result[k].Gas;
- temp_monthrate_array[k][2] = result[k].Water;
- }
- for (var k = 0; k < result.length; k++) {
- temp_monthdata_array[k][0] = parseFloat(temp_Power) * temp_monthrate_array[k][0] / 100;
- temp_monthdata_array[k][1] = parseFloat(temp_Gas) * temp_monthrate_array[k][1] / 100;
- temp_monthdata_array[k][2] = parseFloat(temp_Water) * temp_monthrate_array[k][2] / 100;
- }
- for (var k = 0; k < result.length; k++) {
- temp_monthdata_array[k][0] = parseFloat(temp_monthdata_array[k][0].toFixed(2));
- temp_monthdata_array[k][1] = parseFloat(temp_monthdata_array[k][1].toFixed(2));
- temp_monthdata_array[k][2] = parseFloat(temp_monthdata_array[k][2].toFixed(2));
- }
- temp_Power = 0, temp_Gas = 0, temp_Water = 0;
- for (var k = 0; k < result.length; k++) {
- temp_Power += temp_monthdata_array[k][0];
- temp_Gas += temp_monthdata_array[k][1];
- temp_Water += temp_monthdata_array[k][2];
- }
- //$("#Power_db_txt").dxTextBox("instance").option('value', temp_Power);
- //$("#Gas_db_txt").dxTextBox("instance").option('value', temp_Gas / m3calValue);
- //$("#Water_db_txt").dxTextBox("instance").option('value', temp_Water);
- var temp_dailyrate_array = new Array(7);
- var temp_dailydata_array = new Array(7);
- for (var i = 0; i < 7; i++) {
- temp_dailyrate_array[i] = new Array(3);
- temp_dailydata_array[i] = new Array(3);
- }
- var DailyGridSource = new DevExpress.data.DataSource({
- store: {
- type: "odata",
- url: endpointSelector + "/BemsEnergyConfigPercentWeek"
- },
- requireTotalCount: true,
- pageSize: 7
- });
- DailyGridSource.filter([
- ["SiteId", "=", SiteId], //사이트 아이디
- "and",
- ["Year", "=", temp_Day.getFullYear()]
- ]);
- DailyGridSource.sort({ getter: "Week", asc: true });
- DailyGridSource.load()
- .done(function (result) {
- if (result.length != 0) {
- var tempweek = new Array(12);
- for (var i = 0; i < 12; i++) {
- tempweek[i] = new Array(7);
- }
- for (var i = 0; i < 12; i++) {
- for (var j = 0; j < 7; j++) {
- tempweek[i][j] = 0;
- }
- }
- for (var t = 0; t < result.length; t++) {
- temp_dailyrate_array[t][0] = result[t].Electricity;
- temp_dailyrate_array[t][1] = result[t].Gas;
- temp_dailyrate_array[t][2] = result[t].Water;
- }
- for (var t = 0; t < 12; t++) {
- var lastDay = (new Date(temp_Day.getFullYear(), t + 1, 0));
- for (var h = 1; h <= lastDay.getDate() ; h++) {
- var searchDay = (new Date(temp_Day.getFullYear(), t, h));
- switch (searchDay.getDay()) {
- case 0: tempweek[t][0]++; break;
- case 1: tempweek[t][1]++; break;
- case 2: tempweek[t][2]++; break;
- case 3: tempweek[t][3]++; break;
- case 4: tempweek[t][4]++; break;
- case 5: tempweek[t][5]++; break;
- case 6: tempweek[t][6]++; break;
- }
- }
- }
- for (var t = 0; t < result.length; t++) {
- temp_dailyrate_array[t][0] = parseFloat(temp_dailyrate_array[t][0].toFixed(2));
- temp_dailyrate_array[t][1] = parseFloat(temp_dailyrate_array[t][1].toFixed(2));
- temp_dailyrate_array[t][2] = parseFloat(temp_dailyrate_array[t][2].toFixed(2));
- }
- var totalPower = 0, totalGas = 0, totalWater = 0;
- var cnt = 0;
- for (i = 0; i < YearDayCnt; i++) {
- resultarray[i] = {
- "DateTime": null,
- "PowerValue": null,
- "GasValue": null,
- "WaterValue": null
- };
- }
- // 2019.04.22 로직 수정
- for (var i = 0; i < 12; i++) {
- var lastDay = (new Date(temp_Day.getFullYear(), i + 1, 0));
- var DailyRateTotal_power = 0;
- var DailyRateTotal_gas = 0;
- var DailyRateTotal_water = 0;
- for (var j = 1; j <= lastDay.getDate() ; j++) {
- var date = new Date(temp_Day.getFullYear(), i, j, 0, 0, 0);
- var day = date.getDay();
- DailyRateTotal_power += temp_dailyrate_array[day][0];
- DailyRateTotal_gas += temp_dailyrate_array[day][1];
- DailyRateTotal_water += temp_dailyrate_array[day][2];
- }
- for (var j = 1; j <= lastDay.getDate() ; j++) {
- var date = new Date(temp_Day.getFullYear(), i, j, 0, 0, 0);
- var month = date.getMonth();
- var day = date.getDay();
- var week = date.getDay();
- //var power = (temp_Power * (temp_monthrate_array[month][0] / 100) * (temp_dailyrate_array[day][0] / 100)) / tempweek[i][week];
- //var gas = (temp_Gas * (temp_monthrate_array[month][1] / 100) * (temp_dailyrate_array[day][1] / 100)) / tempweek[i][week];
- //var water = (temp_Water * (temp_monthrate_array[month][2] / 100) * (temp_dailyrate_array[day][2] / 100)) / tempweek[i][week];
- /******************************************************************************************************************************/
- var alpha_power = (temp_Power * (temp_monthrate_array[month][0] / 100)) / (DailyRateTotal_power / 100);
- var power = alpha_power * (temp_dailyrate_array[day][0] / 100);
- var alpha_gas = (temp_Gas * (temp_monthrate_array[month][1] / 100)) / (DailyRateTotal_gas / 100);
- var gas = alpha_gas * (temp_dailyrate_array[day][1] / 100);
- var alpha_water = (temp_Water * (temp_monthrate_array[month][2] / 100)) / (DailyRateTotal_water / 100);
- var water = alpha_water * (temp_dailyrate_array[day][2] / 100);
- /******************************************************************************************************************************/
- // 2019.04.22 로직 수정
- var temppower = numberup(power);
- var tempgas = numberup(gas);
- var tempwater = numberup(water);
- resultarray[cnt] = {
- "DateTime": date,
- "PowerValue": temppower,
- "GasValue": tempgas,
- "WaterValue": tempwater
- };
- totalPower += temppower;
- totalGas += tempgas;
- totalWater += tempwater;
- cnt++;
- }
- }
- $("#Power_db_txt").dxTextBox("instance").option('value', totalPower.toFixed(2));
- $("#Gas_db_txt").dxTextBox("instance").option('value', (totalGas / m3calValue).toFixed(2));
- $("#Water_db_txt").dxTextBox("instance").option('value', totalWater.toFixed(2));
- applyonoff = true;
- utils.toast.show("일별 사용량 예측이 적용 되었습니다.");
- }
- else {
- utils.toast.show("요일별 비율 데이터가 없습니다.");
- return;
- }
- })
- .fail(function (error) {
- utils.toast.show(error);
- });
- }
- else {
- utils.toast.show("월별 비율 데이터가 없습니다.");
- return;
- }
- })
- .fail(function (error) {
- utils.toast.show(error);
- });
- }
- });
- $("#Save_Btn").dxButton({
- text: "저장",
- onClick: function () {
- if (applyonoff == false) {
- utils.toast.show("적용 버튼을 먼저 눌러주시기 바랍니다.");
- return;
- }
- $("#LoadPanel_save").dxLoadPanel('instance').option('visible', true);
- var temp_Day = $("#Search_Day_Past_Year").dxDateBox("instance").option('value');
- var GridSource = new DevExpress.data.DataSource({
- store: {
- type: "odata",
- url: endpointSelector + "/BemsEnergyDaily"
- },
- requireTotalCount: true,
- pageSize: 1100
- });
- GridSource.filter([
- ["SiteId", "=", SiteId], //사이트 아이디
- "and",
- ["ServiceTypeId", "=", 1],
- "and",
- ["CreatedDate", ">=", new Date(temp_Day.getFullYear(), 0, 1, 0, 0, 0)],
- "and",
- ["CreatedDate", "<=", new Date(temp_Day.getFullYear(), 11, 31, 23, 59, 59)]
- ]);
- GridSource.sort({ getter: "CreatedDate", asc: true }, { getter: "FuelTypeId", ASC: true });
- GridSource.load()
- .done(function (result) {
- if (result.length != 0) {
- var savecnt = 0;
- for (var i = 0; i < YearDayCnt; i++) {//
- var temp_date = new Date(resultarray[i].DateTime);
- var temp_UTC = Date.UTC(temp_date.getFullYear(), temp_date.getMonth(), temp_date.getDate(), 0, 0, 0);
- var temp_date_UTC = new Date(temp_UTC);
- for (var j = 1; j <= 3; j++) {
- var temp_fuel = 0;
- var temp_value = 0;
- switch (j) {
- case 1: //전기
- temp_fuel = 1;
- temp_value = resultarray[i].PowerValue;
- break;
- case 2://가스
- temp_fuel = 2;
- temp_value = resultarray[i].GasValue;
- break;
- case 3: //수도
- temp_fuel = 3;
- temp_value = resultarray[i].WaterValue;
- break;
- }
- BWA.api.post('BemsEnergyDaily/UpdatePart', { //UpdatePart
- SiteId: SiteId,
- BuildingId: 1,
- ServiceTypeId: 1,
- FuelTypeId: temp_fuel,
- CreatedDate: temp_date_UTC,
- Prediction: temp_value.toFixed(2)
- }).done(function () {
- savecnt++;
- if (savecnt == YearDayCnt * 3) {
- utils.toast.show("DB에 저장이 되었습니다.");
- applyonoff = false;
- $("#LoadPanel_save").dxLoadPanel('instance').option('visible', false);
- GetGridData();
- }
- }).fail(function (error) {
- $("#LoadPanel_save").dxLoadPanel('instance').option('visible', false);
- utils.toast.show("DB에 저장이 실패하였습니다.");
- });
- }
- }
- }
- else {
- var savecnt = 0;
- for (var i = 0; i < YearDayCnt; i++) {//YearDayCnt
- var temp_date = new Date(resultarray[i].DateTime);
- var temp_UTC = Date.UTC(temp_date.getFullYear(), temp_date.getMonth(), temp_date.getDate(), 0, 0, 0);
- var temp_date_UTC = new Date(temp_UTC);
- for (var j = 1; j <= 3; j++) {
- var temp_fuel = 0;
- var temp_value = 0;
- switch (j) {
- case 1: //전기
- temp_fuel = 1;
- temp_value = resultarray[i].PowerValue;
- break;
- case 2://가스
- temp_fuel = 2;
- temp_value = resultarray[i].GasValue;
- break;
- case 3: //수도
- temp_fuel = 3;
- temp_value = resultarray[i].WaterValue;
- break;
- }
- BWA.api.post('BemsEnergyDaily/InsertPart', {
- SiteId: SiteId,
- BuildingId: 1,
- ServiceTypeId: 1,
- FuelTypeId: temp_fuel,
- CreatedDate: temp_date_UTC,
- Prediction: temp_value.toFixed(2)
- }).done(function () {
- savecnt++;
- var temp = i;
- if (savecnt == YearDayCnt * 3) {
- utils.toast.show("DB에 저장이 되었습니다.");
- applyonoff = false;
- $("#LoadPanel_save").dxLoadPanel('instance').option('visible', false);
- GetGridData();
- }
- }).fail(function (error) {
- utils.toast.show("DB에 저장이 실패하였습니다.");
- $("#LoadPanel_save").dxLoadPanel('instance').option('visible', false);
- });
- }
- }
- }
- })
- .fail(function (error) {
- utils.toast.show(error);
- $("#LoadPanel_save").dxLoadPanel('instance').option('visible', false);
- });
- }
- });
- },
- onHidden: function () {
- }
- };
- viewModel.monthpopupOptions = {
- width: 690,
- height: 600,
- visible: monthvisiblePopup,
- dragEnabled: true,
- shading: true,
- closeOnOutsideClick: true,
- shadingColor: 'transparent',
- showTitle: true,
- title: "월별 비율 설정",
- showCloseButton: true,
- onShowing: function () {
- },
- onShown: function (t, tt) {
- $("#Search_Month_Day").dxDateBox({
- value: TodayAdd,
- maxZoomLevel: 'decade',
- formatString: "yyyy년",
- onValueChanged: function (data) {
- //var tmpDate = data.value;
- //if (tmpDate.getFullYear() > TodayAdd.getFullYear()) {
- // utils.toast.show("조회 연도가 올해보다 클 수 없습니다.");
- // $("#Search_Month_Day").dxDateBox("instance").option('value', TodayAdd);
- //}
- }
- });
- $("#Apply_Month_Day").dxDateBox({
- value: TodayAdd,
- maxZoomLevel: 'decade',
- formatString: "yyyy년",
- onValueChanged: function (data) {
- var tmpDate = data.value;
- if (tmpDate.getFullYear() > TodayAdd.getFullYear() + 1) {
- utils.toast.show("적용 연도가 내년보다 클 수 없습니다.");
- $("#Apply_Month_Day").dxDateBox("instance").option('value', TodayAdd);
- }
- //if (tmpDate.getFullYear() < TodayAdd.getFullYear()) {
- // utils.toast.show("적용 연도가 올해보다 작을수 없습니다.");
- // $("#Apply_Month_Day").dxDateBox("instance").option('value', TodayAdd);
- //}
- }
- });
- $("#Search_Month_Btn").dxButton({
- text: "조회",
- onClick: function () {
- MonthGetGridData();
- }
- });
- $("#Apply_Month_Btn").dxButton({
- text: "전체 적용",
- onClick: function () {
- var temp = $("#MonthdataGrid").dxDataGrid("instance").option('dataSource');
- var Apply_Month = $("#Apply_Month_Day").dxDateBox("instance").option('value');
- if (temp[12].PowerMonthValue != 100) {
- utils.toast.show("전기 합계는 100이 되어야 합니다.");
- return;
- }
- if (temp[12].GasMonthValue != 100) {
- utils.toast.show("가스 합계는 100이 되어야 합니다.");
- return;
- }
- if (temp[12].WaterMonthValue != 100) {
- utils.toast.show("수도 합계는 100이 되어야 합니다.");
- return;
- }
- var MonthGridSource = new DevExpress.data.DataSource({
- store: {
- type: "odata",
- url: endpointSelector + "/BemsEnergyConfigPercentMonth"
- },
- requireTotalCount: true,
- pageSize: 12
- });
- MonthGridSource.filter([
- ["SiteId", "=", SiteId], //사이트 아이디
- "and",
- ["Year", "=", Apply_Month.getFullYear()]
- ]);
- MonthGridSource.sort({ getter: "Month", asc: true });
- MonthGridSource.load()
- .done(function (result) {
- if (result.length != 0) {
- var cnt = 0;
- for (var i = 0; i < 12; i++) {
- BWA.api.post('BemsEnergyConfigPercentMonth/Update', {
- SiteId: SiteId,
- Year: Apply_Month.getFullYear(),
- Month: temp[i].MonthDateTime,
- Electricity: (temp[i].PowerMonthValue),
- Gas: (temp[i].GasMonthValue),
- Water: (temp[i].WaterMonthValue)
- }).done(function () {
- cnt++;
- if (cnt == 12)
- utils.toast.show("월별 비율 설정을 성공하였습니다.");
- }).fail(function (error) {
- utils.toast.show("월별 비율 설정을 실패하였습니다.");
- });
- }
- }
- else {
- var cnt = 0;
- for (var i = 0; i < 12; i++) {
- BWA.api.post('BemsEnergyConfigPercentMonth/Insert', {
- SiteId: SiteId,
- Year: Apply_Month.getFullYear(),
- Month: temp[i].MonthDateTime,
- Electricity: (temp[i].PowerMonthValue),
- Gas: (temp[i].GasMonthValue),
- Water: (temp[i].WaterMonthValue)
- }).done(function () {
- cnt++;
- if (cnt == 12)
- utils.toast.show("월별 비율 설정을 성공하였습니다.");
- }).fail(function (error) {
- utils.toast.show("월별 비율 설정을 실패하였습니다.");
- });
- }
- }
- })
- .fail(function (error) {
- utils.toast.show(error);
- });
- }
- });
- $("#MonthdataGrid").dxDataGrid({
- });
- $("#Search_Day_Month").dxSelectBox({
- dataSource: MonthDataID,
- displayExpr: "month",
- valueExpr: "id",
- });
- $("#Power_Month_txt").dxTextBox({
- });
- $("#Gas_Month_txt").dxTextBox({
- });
- $("#Water_Month_txt").dxTextBox({
- });
- $("#Change_Month_Btn").dxButton({
- text: "비율변경",
- onClick: function () {
- var afpower = 0, afgas = 0, afwater = 0;
- var month = $("#Search_Day_Month").dxSelectBox("instance").option('value');
- month = month - 1;
- var expower = parseFloat($("#Power_Month_txt").dxTextBox("instance").option('value'));
- var exgas = parseFloat($("#Gas_Month_txt").dxTextBox("instance").option('value'));
- var exwater = parseFloat($("#Water_Month_txt").dxTextBox("instance").option('value'));
- if (month == -1) {
- utils.toast.show("월 선택이 없습니다.");
- return;
- }
- if (expower > 100 || $("#Power_Month_txt").dxTextBox("instance").option('value') == "") {
- utils.toast.show("전력 입력 정보가 잘못되었습니다.");
- return;
- }
- if (exgas > 100 || $("#Gas_Month_txt").dxTextBox("instance").option('value') == "") {
- utils.toast.show("가스 입력 정보가 잘못되었습니다.");
- return;
- }
- if (exwater > 100 || $("#Water_Month_txt").dxTextBox("instance").option('value') == "") {
- utils.toast.show("수도 입력 정보가 잘못되었습니다.");
- return;
- }
- $("#Power_Month_txt").dxTextBox("instance").option('value', expower.toFixed(2));
- $("#Gas_Month_txt").dxTextBox("instance").option('value', exgas.toFixed(2));
- $("#Water_Month_txt").dxTextBox("instance").option('value', exwater.toFixed(2));
- var temp = $("#MonthdataGrid").dxDataGrid("instance").option('dataSource');
- temp[month].PowerMonthValue = parseFloat(expower.toFixed(2));
- temp[month].GasMonthValue = parseFloat(exgas.toFixed(2));
- temp[month].WaterMonthValue = parseFloat(exwater.toFixed(2));
- for (var i = 0; i < 12; i++) {
- afpower += (temp[i].PowerMonthValue);
- afgas += (temp[i].GasMonthValue);
- afwater += (temp[i].WaterMonthValue);
- }
- temp[12].PowerMonthValue = parseFloat(afpower.toFixed(2));
- temp[12].GasMonthValue = parseFloat(afgas.toFixed(2));
- temp[12].WaterMonthValue = parseFloat(afwater.toFixed(2));
- $("#MonthdataGrid").dxDataGrid("instance").option('dataSource', temp);
- var dg = $("#MonthdataGrid").dxDataGrid("instance");
- dg.refresh();
- }
- });
- MonthGetGridData();
- },
- onHidden: function () {
- }
- };
- viewModel.dailypopupOptions = {
- width: 690,
- height: 450,
- visible: dailyvisiblePopup,
- dragEnabled: true,
- shading: true,
- closeOnOutsideClick: true,
- shadingColor: 'transparent',
- showTitle: true,
- title: "요일별 비율 설정",
- showCloseButton: true,
- onShowing: function () {
- },
- onShown: function (t, tt) {
- $("#Search_Daily_Day").dxDateBox({
- value: TodayAdd,
- maxZoomLevel: 'decade',
- formatString: "yyyy년",
- onValueChanged: function (data) {
- // var tmpDate = data.value;
- // if (tmpDate.getFullYear() > TodayAdd.getFullYear()) {
- // utils.toast.show("조회 연도가 올해보다 클 수 없습니다.");
- // $("#Search_Daily_Day").dxDateBox("instance").option('value', TodayAdd);
- // }
- }
- });
- $("#Apply_Daily_Day").dxDateBox({
- value: TodayAdd,
- maxZoomLevel: 'decade',
- formatString: "yyyy년",
- onValueChanged: function (data) {
- var tmpDate = data.value;
- if (tmpDate.getFullYear() > TodayAdd.getFullYear() + 1) {
- utils.toast.show("적용 연도가 내년보다 클 수 없습니다.");
- $("#Apply_Daily_Day").dxDateBox("instance").option('value', TodayAdd);
- }
- //if (tmpDate.getFullYear() < TodayAdd.getFullYear()) {
- // utils.toast.show("적용 연도가 올해보다 작을수 없습니다.");
- // $("#Apply_Daily_Day").dxDateBox("instance").option('value', TodayAdd);
- //}
- }
- });
- $("#Search_Daily_Btn").dxButton({
- text: "조회",
- onClick: function () {
- DailyGetGridData();
- }
- });
- $("#Apply_Daily_Btn").dxButton({
- text: "전체 적용",
- onClick: function () {
- var temp = $("#DailydataGrid").dxDataGrid("instance").option('dataSource');
- var Apply_Daily = $("#Apply_Daily_Day").dxDateBox("instance").option('value');
- if (temp[7].PowerDailyValue != 100) {
- utils.toast.show("전기 합계는 100이 되어야 합니다.");
- return;
- }
- if (temp[7].GasDailyValue != 100) {
- utils.toast.show("가스 합계는 100이 되어야 합니다.");
- return;
- }
- if (temp[7].WaterDailyValue != 100) {
- utils.toast.show("수도 합계는 100이 되어야 합니다.");
- return;
- }
- var DailyGridSource = new DevExpress.data.DataSource({
- store: {
- type: "odata",
- url: endpointSelector + "/BemsEnergyConfigPercentWeek"
- },
- requireTotalCount: true,
- pageSize: 7
- });
- DailyGridSource.filter([
- ["SiteId", "=", SiteId], //사이트 아이디
- "and",
- ["Year", "=", Apply_Daily.getFullYear()]
- ]);
- DailyGridSource.sort({ getter: "Week", asc: true });
- DailyGridSource.load()
- .done(function (result) {
- if (result.length != 0) {
- var cnt = 0;
- for (var i = 0; i < 7; i++) {
- BWA.api.post('BemsEnergyConfigPercentWeek/Update', {
- SiteId: SiteId,
- Year: Apply_Daily.getFullYear(),
- Week: i,
- Electricity: temp[i].PowerDailyValue,
- Gas: temp[i].GasDailyValue,
- Water: temp[i].WaterDailyValue
- }).done(function () {
- cnt++;
- if (cnt == 7)
- utils.toast.show("요일별 비율 설정을 성공하였습니다.");
- }).fail(function (error) {
- utils.toast.show("요일별 비율 설정을 실패하였습니다.");
- });
- }
- }
- else {
- var cnt = 0;
- for (var i = 0; i < 7; i++) {
- BWA.api.post('BemsEnergyConfigPercentWeek/Insert', {
- SiteId: SiteId,
- Year: Apply_Daily.getFullYear(),
- Week: i,
- Electricity: temp[i].PowerDailyValue,
- Gas: temp[i].GasDailyValue,
- Water: temp[i].WaterDailyValue
- }).done(function () {
- cnt++;
- if (cnt == 7)
- utils.toast.show("요일별 비율 설정을 성공하였습니다.");
- }).fail(function (error) {
- utils.toast.show("요일별 비율 설정을 실패하였습니다.");
- });
- }
- }
- })
- .fail(function (error) {
- utils.toast.show(error);
- });
- }
- });
- $("#DailydataGrid").dxDataGrid({
- });
- $("#Search_Day_Daily").dxSelectBox({
- dataSource: DailyDataID,
- displayExpr: "daily",
- valueExpr: "id",
- onValueChanged: function () {
- }
- });
- $("#Power_Daily_txt").dxTextBox({
- });
- $("#Gas_Daily_txt").dxTextBox({
- });
- $("#Water_Daily_txt").dxTextBox({
- });
- $("#Change_Daily_Btn").dxButton({
- text: "비율변경",
- onClick: function () {
- var afpower = 0, afgas = 0, afwater = 0;
- var daily = $("#Search_Day_Daily").dxSelectBox("instance").option('value');
- daily = daily - 1;
- var expower = parseFloat($("#Power_Daily_txt").dxTextBox("instance").option('value'));
- var exgas = parseFloat($("#Gas_Daily_txt").dxTextBox("instance").option('value'));
- var exwater = parseFloat($("#Water_Daily_txt").dxTextBox("instance").option('value'));
- if (daily == -1) {
- utils.toast.show("요일 선택이 없습니다.");
- return;
- }
- if (expower > 100 || $("#Power_Daily_txt").dxTextBox("instance").option('value') == "") {
- utils.toast.show("전력 입력 정보가 잘못되었습니다.");
- return;
- }
- if (exgas > 100 || $("#Gas_Daily_txt").dxTextBox("instance").option('value') == "") {
- utils.toast.show("가스 입력 정보가 잘못되었습니다.");
- return;
- }
- if (exwater > 100 || $("#Water_Daily_txt").dxTextBox("instance").option('value') == "") {
- utils.toast.show("수도 입력 정보가 잘못되었습니다.");
- return;
- }
- $("#Power_Daily_txt").dxTextBox("instance").option('value', expower.toFixed(2));
- $("#Gas_Daily_txt").dxTextBox("instance").option('value', exgas.toFixed(2));
- $("#Water_Daily_txt").dxTextBox("instance").option('value', exwater.toFixed(2));
- var temp = $("#DailydataGrid").dxDataGrid("instance").option('dataSource');
- temp[daily].PowerDailyValue = parseFloat(expower.toFixed(2));
- temp[daily].GasDailyValue = parseFloat(exgas.toFixed(2));
- temp[daily].WaterDailyValue = parseFloat(exwater.toFixed(2));
- for (var i = 0; i < 7; i++) {
- afpower += (temp[i].PowerDailyValue);
- afgas += (temp[i].GasDailyValue);
- afwater += (temp[i].WaterDailyValue);
- }
- temp[7].PowerDailyValue = parseFloat(afpower.toFixed(2));
- temp[7].GasDailyValue = parseFloat(afgas.toFixed(2));
- temp[7].WaterDailyValue = parseFloat(afwater.toFixed(2));
- $("#DailydataGrid").dxDataGrid("instance").option('dataSource', temp);
- var dg = $("#DailydataGrid").dxDataGrid("instance");
- dg.refresh();
- }
- });
- DailyGetGridData();
- },
- onHidden: function () {
- }
- };
- return viewModel;
- };
|