BemsWebApplication.AlarmSetting = function (params, viewInfo) { 'use strict'; var now = new Date(); var row_btn = false; var enroll_btn = false; var visiblePopup = ko.observable(false); var loadvisiblePopup = ko.observable(false); var popupInit = false; var ControlPoint_temp = 0; var virtualFacility = 99; var gridData = new Array(); var upperLimitCnt = 0; var lowerLimitCnt = 0; var alarmYNCnt = 0; var smsYNCnt = 0; var emailYNCnt = 0; var ControlPoint = 0; var FacilityCode = 0; var FacilityName = ""; var facilityTypeId = 0; var FormulaId = 0; var LowerLimit = ""; var UpperLimit = ""; var PropertyId = 0; var UseSMS = false; var UseEmail = false; var UseAlarm = false; var UseLowerLimit = false; var UseUpperLimit = false; var Point_Type_Id = ""; var Content = ""; var AlarmGroupName = ""; var changed = false; 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 FacilityCode_id_temp = 0; var facility_type = ko.observableArray(); var facility_id = ko.observableArray(); var setDataSource1, alarmgroup; var allowedChars = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '.']; var treeViewData = [ { id: 1, text: "성능분석", items: [], visualFlag: false }, { id: 2, text: "가상 시설", items: [], visualFlag: false }, { id: 3, text: "일반 시설", items: [], visualFlag: false } ]; var excnt = 0; var facilityTypeId_fin = 0, facilityCode_fin = 0, parentId_fin = 0, propertyId_fin = 0, facilityName_fin = "", formulaId_fin = 0, controlPoint_fin = ""; var UpperLimit_ONOFF_value = false, LowerLimit_ONOFF_value = false, AlarmYN_Id_value = false, EmailYN_Id_Id_value = false, SMSYN_Id_Id_value = false, Users_Id_text = "", text_Id_text = ""; var LowerLimit_Id_text = "", UpperLimit_Id_text = ""; var selectData = { FacilityTypeId: 0, FacilityCode: 0, PropertyId: 0, FormulaId: 0, FacilityName: "", PointTypeId: "", ControlPoint: "", UpperLimit_ONOFF: false, UpperLimit: 0, LowerLimit_ONOFF: false, LowerLimit: 0, UseAlarm: false, UseSMS: false, UseEmail: false, AlarmGroupId: 0, text: "" } //권한설정 var hasnotModificationPermission = ko.observable(true); function GetPopupTreeViewData() { treeViewData = [ { id: 1, text: "성능분석", items: [], visualFlag: false }, { id: 2, text: "가상 시설", items: [], visualFlag: false }, { id: 3, text: "일반 시설", items: [], visualFlag: false } ]; excnt = 4; var facilityIdIndex = 4; var dataSource = new DevExpress.data.DataSource({ store: { type: "odata", url: endpointSelector + "/BemsFacilityType", }, requireTotalCount: true, pageSize: 100 }); dataSource.sort({ getter: "FacilityTypeId", asc: true }); dataSource.load() .done(function (result) { for (var i = 0; i < result.length; i++) { if (result[i].FacilityTypeId < 100) { //성능분석 if (result[i].FacilityTypeId != virtualFacility) { treeViewData[0].items.push({ id: facilityIdIndex, facilityTypeId: result[i].FacilityTypeId, text: result[i].Name, items: [], visualFlag: false }); facilityIdIndex++; excnt++; } } } for (var i = 0; i < result.length; i++) { if (result[i].FacilityTypeId < 100) { //가상 if (result[i].FacilityTypeId != virtualFacility) { treeViewData[2].items.push({ id: facilityIdIndex, facilityTypeId: result[i].FacilityTypeId, text: result[i].Name, items: [], visualFlag: false }); facilityIdIndex++; } else { //일반 treeViewData[1].items.push({ id: facilityIdIndex, facilityTypeId: result[i].FacilityTypeId, text: result[i].Name, items: [], visualFlag: false }); facilityIdIndex++; } } } var dataSource2 = new DevExpress.data.DataSource({ store: { type: "odata", url: endpointSelector + "/CmFacility", }, requireTotalCount: true, pageSize: 5000 }); dataSource2.filter([ ["SiteId", "=", BWA.UserInfo.SiteId()] ]); dataSource2.sort({ getter: "Name", asc: true }); dataSource2.load() .done(function (result2) { for (var i = 0; i < result2.length; i++) { for (var j = 0; j < treeViewData[0].items.length; j++) { if (treeViewData[0].items[j].facilityTypeId == result2[i].FacilityTypeId) { treeViewData[0].items[j].items.push({ id: facilityIdIndex, facilityTypeId: result2[i].FacilityTypeId, facilityCode: result2[i].FacilityCode, text: result2[i].Name, visualFlag: true, parentId: 0 }); facilityIdIndex++; treeViewData[2].items[j].items.push({ id: facilityIdIndex, facilityTypeId: result2[i].FacilityTypeId, facilityCode: result2[i].FacilityCode, text: result2[i].Name, visualFlag: true, parentId: 2 }); facilityIdIndex++; break; } } if (result2[i].FacilityTypeId == virtualFacility) { treeViewData[1].items[0].items.push({ id: facilityIdIndex, facilityTypeId: result2[i].FacilityTypeId, facilityCode: result2[i].FacilityCode, text: result2[i].Name, visualFlag: true, parentId: 1 }); facilityIdIndex++; } } }) .fail(function (error) { utils.toast.show(error); }); }) .fail(function (error) { utils.toast.show(error); }); } function GetPopupGridData(facilityTypeId, facilityCode, parentId) { if (parentId != 0) { var dataSource = new DevExpress.data.DataSource({ store: { type: "odata", url: endpointSelector + "/BemsMonitoringPointConfig", }, requireTotalCount: true, pageSize: 5000, expand: ["BemsMonitoringPoint"] }); dataSource.filter([ ["SiteId", "=", BWA.UserInfo.SiteId()], "and", ["FacilityTypeId", "=", facilityTypeId], "and", ["FacilityCode", "=", facilityCode] ]); dataSource.sort({ getter: "BemsMonitoringPoint/PropertyId", asc: true }); dataSource.load() .done(function (result) { setDataSource1 = new Array(); for (var i = 0; i < result.length; i++) { var setData = { "ControlPoint": "", "FuelType": 0, "FacilityTypeId": 0, "FacilityCode": 0, "PropertyId": 0, "FormulaId": 0 }; setData.ControlPoint = result[i].BemsMonitoringPoint.Name; var fuelName = result[i].BemsMonitoringPoint.FuelTypeId; if (fuelName == 0) { fuelName = "-"; } else if (fuelName == 1) { fuelName = "전기"; } else if (fuelName == 2) { fuelName = "가스"; } else { fuelName = "수도"; } setData.FuelType = fuelName; setData.FacilityTypeId = result[i].FacilityTypeId; setData.FacilityCode = result[i].FacilityCode; setData.PropertyId = result[i].PropertyId; setDataSource1.push(setData); } $("#Control_Id").dxSelectBox('instance').option('value', null);// 텍스트 클리어 $("#Control_Id").dxSelectBox({// 두번째 콤보 바인딩 placeholder: "관제점 이름", dataSource: setDataSource1, displayExpr: "ControlPoint", valueExpr: "PropertyId", onValueChanged: function () { var value = $("#Control_Id").dxSelectBox('instance').option('value'); if (value != null) { for (var i = 0; i < setDataSource1.length; i++) { if (setDataSource1[i].PropertyId == value) { propertyId_fin = setDataSource1[i].PropertyId; controlPoint_fin = setDataSource1[i].ControlPoint; formulaId_fin = setDataSource1[i].FormulaId; break; } } } } }); if (changed) { $("#Facility_Id").dxSelectBox('instance').option('value', FacilityCode_id_temp); $("#UpperLimit_ONOFF").dxSwitch('instance').option('value', UseUpperLimit); $("#UpperLimit_Id").dxTextBox('instance').option('value', UpperLimit); $("#LowerLimit_ONOFF").dxSwitch('instance').option('value', UseLowerLimit); $("#LowerLimit_Id").dxTextBox('instance').option('value', LowerLimit); $("#AlarmYN_Id").dxSwitch('instance').option('value', UseAlarm); $("#SMSYN_Id").dxSwitch('instance').option('value', UseSMS); $("#EmailYN_Id").dxSwitch('instance').option('value', UseEmail); $("#text_Id").dxTextArea('instance').option('value', Content); var group = true; for (i = 0; i < alarmgroup.length; i++) { if (AlarmGroupName == alarmgroup[i].Name) { $("#Users_Id").dxSelectBox('instance').option('value', alarmgroup[i].Name); group = false; break; } } if (group) { $("#Users_Id").dxSelectBox('instance').option('value', null); } if (setDataSource1 == "") { changed = true; } else { for (var i = 0; i <= setDataSource1.length; i++) { if (FormulaId == 0) { if (setDataSource1[i].PropertyId == PropertyId) { $("#Control_Id").dxSelectBox('instance').option('value', setDataSource1[i].PropertyId); break; } } else { if (setDataSource1[i].FormulaId == FormulaId) { $("#Control_Id").dxSelectBox('instance').option('value', setDataSource1[i].FormulaId); break; } } } changed = false; } } }) .fail(function (error) { utils.toast.show(error); }); } else { var dataSource = new DevExpress.data.DataSource({ store: { type: "odata", url: endpointSelector + "/BemsFormula", }, requireTotalCount: true, pageSize: 5000, expand: ["BemsFormulaBase"] }); dataSource.filter([ ["SiteId", "=", BWA.UserInfo.SiteId()], "and", ["FacilityTypeId", "=", facilityTypeId], "and", ["FacilityCode", "=", facilityCode] ]); dataSource.sort({ getter: "BemsFormulaBase/Name", asc: true }); dataSource.load() .done(function (result) { setDataSource1 = new Array(); for (var i = 0; i < result.length; i++) { var setData = { "ControlPoint": "", "FuelType": 0, "FacilityTypeId": 0, "FacilityCode": 0, "PropertyId": 0, "FormulaId": 0 }; setData.ControlPoint = result[i].BemsFormulaBase.Name; setData.FuelType = "-"; setData.FacilityTypeId = result[i].FacilityTypeId; setData.FacilityCode = result[i].FacilityCode; setData.FormulaId = result[i].FormulaId; setDataSource1.push(setData); } $("#Control_Id").dxSelectBox('instance').option('value', null);// 텍스트 클리어 $("#Control_Id").dxSelectBox({// 두번째 콤보 바인딩 placeholder: "관제점 이름", dataSource: setDataSource1, displayExpr: "ControlPoint", valueExpr: "FormulaId", onValueChanged: function () { var value = $("#Control_Id").dxSelectBox('instance').option('value'); if (value != null) { for (var i = 0; i < setDataSource1.length; i++) { if (setDataSource1[i].FormulaId == value) { propertyId_fin = setDataSource1[i].PropertyId; controlPoint_fin = setDataSource1[i].ControlPoint; formulaId_fin = setDataSource1[i].FormulaId; break; } } } } }); if (changed) { $("#Facility_Id").dxSelectBox('instance').option('value', FacilityCode_id_temp); $("#UpperLimit_Id").dxTextBox('instance').option('value', UpperLimit); $("#LowerLimit_Id").dxTextBox('instance').option('value', LowerLimit); $("#UpperLimit_ONOFF").dxSwitch('instance').option('value', UseUpperLimit); $("#LowerLimit_ONOFF").dxSwitch('instance').option('value', UseLowerLimit); $("#AlarmYN_Id").dxSwitch('instance').option('value', UseAlarm); $("#SMSYN_Id").dxSwitch('instance').option('value', UseSMS); $("#EmailYN_Id").dxSwitch('instance').option('value', UseEmail); $("#text_Id").dxTextArea('instance').option('value', Content); var group = true; for (i = 0; i < alarmgroup.length; i++) { if (AlarmGroupName == alarmgroup[i].Name) { $("#Users_Id").dxSelectBox('instance').option('value', alarmgroup[i].Name); group = false; break; } } if (group) { $("#Users_Id").dxSelectBox('instance').option('value', null); } if (setDataSource1 == "") { changed = true; } else { for (var i = 0; i < setDataSource1.length; i++) { if (FormulaId == 0) { if (setDataSource1[i].PropertyId == PropertyId) { $("#Control_Id").dxSelectBox('instance').option('value', setDataSource1[i].PropertyId); break; } } else { if (setDataSource1[i].FormulaId == FormulaId) { $("#Control_Id").dxSelectBox('instance').option('value', setDataSource1[i].FormulaId); break; } } } changed = false; } } }) .fail(function (error) { utils.toast.show(error); }); } } function AddSelectPoint() { //초기화 selectData.FacilityTypeId = 0; selectData.FacilityCode = 0; selectData.PropertyId = 0; selectData.FormulaId = 0; selectData.FacilityName = ""; selectData.ControlPoint = ""; selectData.LowerLimit_ONOFF = false; selectData.LowerLimit = ""; selectData.UpperLimit_ONOFF = false; selectData.UpperLimit = 0; selectData.UseAlarm = false; selectData.UseSMS = false; selectData.UseEmail = false; selectData.AlarmGroupName = ""; selectData.text = ""; //입력 selectData.FacilityTypeId = facilityTypeId_fin; selectData.FacilityCode = facilityCode_fin; selectData.PropertyId = propertyId_fin; selectData.FormulaId = formulaId_fin; if (selectData.FormulaId == null) { selectData.FormulaId = 0; } selectData.FacilityName = facilityName_fin; selectData.ControlPoint = controlPoint_fin; selectData.LowerLimit_ONOFF = LowerLimit_ONOFF_value; LowerLimit_Id_text = $("#LowerLimit_Id").dxTextBox('instance').option('value'); if (LowerLimit_Id_text == "") selectData.LowerLimit = 0; else selectData.LowerLimit = parseFloat(LowerLimit_Id_text); selectData.UpperLimit_ONOFF = UpperLimit_ONOFF_value; UpperLimit_Id_text = $("#UpperLimit_Id").dxTextBox('instance').option('value'); if (UpperLimit_Id_text == "") selectData.UpperLimit = 0; else selectData.UpperLimit = parseFloat(UpperLimit_Id_text); selectData.UseAlarm = AlarmYN_Id_value; selectData.UseSMS = SMSYN_Id_Id_value; selectData.UseEmail = EmailYN_Id_Id_value; selectData.AlarmGroupName = Users_Id_text; selectData.text = text_Id_text; if (selectData.length == 0) { utils.toast.show("선택된 데이터가 없습니다.", 'error'); return; } if (selectData.FacilityTypeId == 0 || selectData.FacilityCode == 0 || selectData.FacilityName == "" || selectData.ControlPoint == "" || selectData.AlarmGroupName == "" || selectData.AlarmGroupName == null) { utils.toast.show("필수 데이터가 부족합니다.", 'error'); return; } if (gridData.length != 0) { for (var i = 0; i < gridData.length; i++) { if (gridData[i].FacilityTypeId == selectData.FacilityTypeId && gridData[i].FacilityCode == selectData.FacilityCode && gridData[i].PropertyId == selectData.PropertyId && gridData[i].FormulaId == selectData.FormulaId) { utils.toast.show("선택한 목록 중 이미 추가되어 있는 항목이 있습니다.", 'error'); return; } } } if (selectData.UpperLimit_ONOFF == true) { if (selectData.UpperLimit == 0) { utils.toast.show("0은 상한값이 될수 없습니다.", 'error'); //visiblePopup(false); return; } } if (selectData.LowerLimit_ONOFF == true) { if (selectData.LowerLimit == 0) { utils.toast.show("0은 하한값이 될수 없습니다.", 'error'); //visiblePopup(false); return; } } var dataSource = new DevExpress.data.DataSource({ store: { type: "odata", url: endpointSelector + "/CmFacility", }, requireTotalCount: true, pageSize: 1, }); dataSource.filter([ ["SiteId", "=", BWA.UserInfo.SiteId()], "and", ["FacilityTypeId", "=", selectData.FacilityTypeId], "and", ["FacilityCode", "=", selectData.FacilityCode] ]); dataSource.load() .done(function (result) { if (selectData.FacilityTypeId == result[0].FacilityTypeId && selectData.FacilityCode == result[0].FacilityCode) { selectData.FacilityName = result[0].Name; var store = new DevExpress.data.ODataStore({ url: endpointSelector + "/BemsAlarmSetting", key: ["SiteId", "FacilityTypeId", "FacilityCode", "PropertyId", "FormulaId"], keyType: { SiteId: "Int32", FacilityTypeId: "Int32", FacilityCode: "Int32", PropertyId: "Int32", FormulaId: "Int32" } }); var insertData = { SiteId: BWA.UserInfo.SiteId(), FacilityTypeId: selectData.FacilityTypeId, FacilityCode: selectData.FacilityCode, PropertyId: selectData.PropertyId, FormulaId: selectData.FormulaId, FacilityName: selectData.FacilityName, PointName: selectData.ControlPoint, UseUpperLimit: selectData.UpperLimit_ONOFF, UpperLimit: selectData.UpperLimit, UseLowerLimit: selectData.LowerLimit_ONOFF, LowerLimit: selectData.LowerLimit, UseAlarm: selectData.UseAlarm, UseSMS: selectData.UseSMS, UseEmail: selectData.UseEmail, AlarmGroupName: selectData.AlarmGroupName, Content: selectData.text }; store.insert(insertData) .done(function (values, key) { setTimeout(function () { utils.toast.show("저장 되었습니다."); GetGridData(); visiblePopup(false); }, 1500); }) .fail(function (error) { }); } }) } function GetGridData() { gridData = new Array(); var dataSource = new DevExpress.data.DataSource({ store: { type: "odata", url: endpointSelector + "/BemsAlarmSetting", }, requireTotalCount: true, pageSize: 9999, }); dataSource.filter([ ["SiteId", "=", BWA.UserInfo.SiteId()] ]); dataSource.sort({ getter: "FacilityTypeId", asc: true }); dataSource.load() .done(function (result) { for (var i = 0; i < result.length; i++) { var cnt = 0; upperLimitCnt = 0; lowerLimitCnt = 0; alarmYNCnt = 0; smsYNCnt = 0; emailYNCnt = 0; var setData = { "PointTypeId": "", "FacilityTypeId": 0, "FacilityCode": 0, "PropertyId": 0, "FormulaId": 0, "FacilityName": "", "ControlPoint": "", "UseUpperLimit": "N", "UseLowerLimit": "N", "UpperLimit": "", "LowerLimit": "", "UseAlarm": "N", "UseSMS": "N", "UseEmail": "N", "AlarmGroupName": "", "Content": "" }; setData.FacilityTypeId = result[i].FacilityTypeId; setData.FacilityCode = result[i].FacilityCode; setData.PropertyId = result[i].PropertyId; setData.FormulaId = result[i].FormulaId; if (setData.FormulaId != 0) { setData.PointTypeId = "성능분석"; } else { if (setData.FacilityTypeId == 99) setData.PointTypeId = "가상 시설"; else setData.PointTypeId = "일반 시설"; } setData.FormulaId = result[i].FormulaId; setData.FacilityName = result[i].FacilityName; setData.ControlPoint = result[i].PointName; setData.UseUpperLimit = result[i].UseUpperLimit; if (setData.UseUpperLimit == 0) setData.UseUpperLimit = "N"; else setData.UseUpperLimit = "Y"; setData.UpperLimit = result[i].UpperLimit; setData.UseLowerLimit = result[i].UseLowerLimit; if (setData.UseLowerLimit == 0) setData.UseLowerLimit = "N"; else setData.UseLowerLimit = "Y"; setData.LowerLimit = result[i].LowerLimit; setData.UseAlarm = result[i].UseAlarm; if (setData.UseAlarm == 0) setData.UseAlarm = "N"; else setData.UseAlarm = "Y"; setData.UseSMS = result[i].UseSMS; if (setData.UseSMS == 0) setData.UseSMS = "N"; else setData.UseSMS = "Y"; setData.UseEmail = result[i].UseEmail; if (setData.UseEmail == 0) setData.UseEmail = "N"; else setData.UseEmail = "Y"; for (var j = 0; j < alarmgroup.length; j++) { if (result[i].AlarmGroupName == alarmgroup[j].Name) { setData.AlarmGroupName = result[i].AlarmGroupName; break; } else { cnt++; } if (cnt == alarmgroup.length) { setData.AlarmGroupName = "없음"; } } setData.Content = result[i].Content; gridData.push(setData); } $("#dataGrid").dxDataGrid("instance").option('dataSource', gridData); var dg = $("#dataGrid").dxDataGrid("instance"); dg.refresh(); }) .fail(function (error) { utils.toast.show(error); }); } function UpdateGridData() { var dg = $("#dataGrid").dxDataGrid("instance"); var store = new DevExpress.data.ODataStore({ url: endpointSelector + "/BemsAlarmSetting", key: ["SiteId", "FacilityTypeId", "FacilityCode", "PropertyId", "FormulaId"], keyType: { SiteId: "Int32", FacilityTypeId: "Int32", FacilityCode: "Int32", PropertyId: "Int32", FormulaId: "Int32" } }); selectData.FacilityTypeId = 0; selectData.FacilityCode = 0; selectData.PropertyId = 0; selectData.FormulaId = 0; selectData.FacilityName = ""; selectData.ControlPoint = ""; selectData.UpperLimit_ONOFF = false; selectData.UpperLimit = ""; selectData.LowerLimit_ONOFF = false; selectData.LowerLimit = ""; selectData.UseAlarm = false; selectData.UseSMS = false; selectData.UseEmail = false; selectData.AlarmGroupName = ""; selectData.text = ""; //입력 selectData.FacilityTypeId = facilityTypeId_fin; selectData.FacilityCode = facilityCode_fin; selectData.PropertyId = propertyId_fin; selectData.FormulaId = formulaId_fin; if (selectData.FormulaId == null) { selectData.FormulaId = 0; } selectData.FacilityName = facilityName_fin; selectData.ControlPoint = controlPoint_fin; UpperLimit_ONOFF_value = $("#UpperLimit_ONOFF").dxSwitch('instance').option('value'); selectData.UpperLimit_ONOFF = UpperLimit_ONOFF_value; UpperLimit_Id_text = $("#UpperLimit_Id").dxTextBox('instance').option('value'); if (UpperLimit_Id_text == "") selectData.UpperLimit = 0; else selectData.UpperLimit = parseFloat(UpperLimit_Id_text); LowerLimit_ONOFF_value = $("#LowerLimit_ONOFF").dxSwitch('instance').option('value'); selectData.LowerLimit_ONOFF = LowerLimit_ONOFF_value; LowerLimit_Id_text = $("#LowerLimit_Id").dxTextBox('instance').option('value'); if (LowerLimit_Id_text == "") selectData.LowerLimit = 0; else selectData.LowerLimit = parseFloat(LowerLimit_Id_text); selectData.UseAlarm = AlarmYN_Id_value; selectData.UseSMS = SMSYN_Id_Id_value; selectData.UseEmail = EmailYN_Id_Id_value; selectData.AlarmGroupName = Users_Id_text; selectData.text = text_Id_text; if (selectData.length == 0) { utils.toast.show("선택된 데이터가 없습니다.", 'error'); return; } if (selectData.FacilityTypeId == 0 || selectData.FacilityCode == 0 || selectData.FacilityName == "" || selectData.ControlPoint == "" || selectData.AlarmGroupName == "" || selectData.AlarmGroupName == null) { utils.toast.show("필수 데이터가 부족합니다.", 'error'); return; } if (selectData.UpperLimit_ONOFF == true) { if (selectData.UpperLimit == 0) { utils.toast.show("0은 상한값이 될수 없습니다.", 'error'); //visiblePopup(false); return; } } if (selectData.LowerLimit_ONOFF == true) { if (selectData.LowerLimit == 0) { utils.toast.show("0은 하한값이 될수 없습니다.", 'error'); //visiblePopup(false); return; } } store.update({ SiteId: BWA.UserInfo.SiteId(), FacilityTypeId: selectData.FacilityTypeId, FacilityCode: selectData.FacilityCode, PropertyId: selectData.PropertyId, FormulaId: selectData.FormulaId }, { FacilityName: selectData.FacilityName, PointName: selectData.ControlPoint, UseUpperLimit: selectData.UpperLimit_ONOFF, UpperLimit: selectData.UpperLimit, UseLowerLimit: selectData.LowerLimit_ONOFF, LowerLimit: selectData.LowerLimit, UseAlarm: selectData.UseAlarm, UseSMS: selectData.UseSMS, UseEmail: selectData.UseEmail, AlarmGroupName: selectData.AlarmGroupName, Content: selectData.text }) .done(function (values, key) { utils.toast.show("수정 되었습니다."); setTimeout(function () { visiblePopup(false); }, 1000); }) .fail(function (error) { utils.toast.show(error); }); } function DeleteGridData() { var store = new DevExpress.data.ODataStore({ url: endpointSelector + "/BemsAlarmSetting", key: ["SiteId", "FacilityTypeId", "FacilityCode", "PropertyId", "FormulaId"], keyType: { SiteId: "Int32", FacilityTypeId: "Int32", FacilityCode: "Int32", PropertyId: "Int32", FormulaId: "Int32" } }); //초기화 selectData.FacilityTypeId = 0; selectData.FacilityCode = 0; selectData.PropertyId = 0; selectData.FormulaId = 0; //입력 selectData.FacilityTypeId = facilityTypeId_fin; selectData.FacilityCode = facilityCode_fin; selectData.PropertyId = propertyId_fin; selectData.FormulaId = formulaId_fin; if (selectData.FormulaId == null) { selectData.FormulaId = 0; } var removeData = { SiteId: BWA.UserInfo.SiteId(), FacilityTypeId: selectData.FacilityTypeId, FacilityCode: selectData.FacilityCode, PropertyId: selectData.PropertyId, FormulaId: selectData.FormulaId }; store.remove(removeData) .done(function (values, key) { utils.toast.show("삭제 되었습니다."); setTimeout(function () { visiblePopup(false); }, 1000); }) .fail(function (error) { utils.toast.show(error); }); } function handleViewShowing() { //권한설정 hasnotModificationPermission(!BWA.UserInfo.hasPermissionOfModification(viewInfo.viewName)); $("#large-indicator").dxLoadIndicator({ height: 60, width: 60 }); var AlarmGroup = new DevExpress.data.DataSource({ store: { type: "odata", url: endpointSelector + "/BemsAlarmGroup", }, requireTotalCount: true, pageSize: 5000 }); AlarmGroup.filter([ ["SiteId", "=", BWA.UserInfo.SiteId()] ]); AlarmGroup.sort({ getter: "AlarmGroupId", asc: true }); AlarmGroup.load() .done(function (result2) { alarmgroup = new Array(); for (var i = 0; i < result2.length; i++) { var setData = { "AlarmGroupId": 0, "Name": "" }; setData.AlarmGroupId = result2[i].AlarmGroupId; setData.Name = result2[i].Name; alarmgroup.push(setData); } }) .fail(function (error) { utils.toast.show(error); }); GetPopupTreeViewData(); } function handleViewShown() { $("#updateSaveBtn").dxButton({ visible: false }); $("#delBtn").dxButton({ visible: false }); $("#selectSaveBtn").dxButton({ visible: false }); $("#dataGrid").dxDataGrid({ paging: { pageSize: 17, enabled: true } }); GetGridData(); } var searchViewOptions = { } function PopupChange(data) { } function handleSearchInSearchView() { } var viewModel = $.extend(BWA.CommonView.create(params, viewInfo, searchViewOptions, ko.observable(null), handleViewShown, null, handleSearchInSearchView), { viewShowing: handleViewShowing, dataGrid: utils.datagrid.defaultOptions({ selection: { mode: 'single' }, height: 660, columns: [ { dataField: 'PointTypeId', width: 120, caption: "타입", alignment: 'center' }, { dataField: 'FacilityName', width: 200, caption: "설비 이름", alignment: 'center' } , { dataField: 'ControlPoint', width: 200, caption: "관제점(분석요소)", alignment: 'center', } , { dataField: 'UseUpperLimit', width: 120, caption: "기준 상한값 설정", alignment: 'center' } , { dataField: 'UpperLimit', width: 120, caption: "기준 상한값", alignment: 'center' } , { dataField: 'UseLowerLimit', width: 120, caption: "기준 하한값 설정", alignment: 'center' } , { dataField: 'LowerLimit', width: 120, caption: "기준 하한값", alignment: 'center' } , { dataField: 'UseAlarm', width: 90, caption: "경보 여부", alignment: 'center' } , { dataField: 'UseSMS', width: 90, caption: "SMS 여부", alignment: 'center' } , { dataField: 'UseEmail', width: 90, caption: "Email 여부", alignment: 'center' } , { dataField: 'AlarmGroupName', width: 90, caption: "발송 그룹", alignment: 'center' }, { dataField: 'FacilityTypeId', visible: false }, { dataField: 'FacilityCode', visible: false }, { dataField: 'PropertyId', visible: false }, { dataField: 'FormulaId', visible: false } ], // 2019.04.17 엑셀 출력 기능 추가 ~~~ "export": { enabled: true, fileName: '알람 설정 내역' }, // ~~~ 2019.04.17 엑셀 출력 기능 추가 rowClick: function (row) { loadvisiblePopup(true); row_btn = true; var data = row.data; Point_Type_Id = data.PointTypeId; facilityTypeId = data.FacilityTypeId; FacilityCode = data.FacilityCode; PropertyId = data.PropertyId; FormulaId = data.FormulaId; FacilityName = data.FacilityName; ControlPoint = data.ControlPoint; if (data.UseUpperLimit == "N") { UseUpperLimit = false; $("#UpperLimit_Id").dxTextBox({ disabled: true }); } else { UseUpperLimit = true; $("#UpperLimit_Id").dxTextBox({ disabled: false }); } UpperLimit = data.UpperLimit; if (data.UseLowerLimit == "N") { UseLowerLimit = false; $("#LowerLimit_Id").dxTextBox({ disabled: true }); } else { UseLowerLimit = true; $("#LowerLimit_Id").dxTextBox({ disabled: false }); } LowerLimit = data.LowerLimit; if (data.UseAlarm == "N") UseAlarm = false; else UseAlarm = true; if (data.UseSMS == "N") UseSMS = false; else UseSMS = true; if (data.UseEmail == "N") UseEmail = false; else UseEmail = true; AlarmGroupName = data.AlarmGroupName; Content = data.Content; changed = true; setTimeout(function () { visiblePopup(true); loadvisiblePopup(false); }, 500); }, }), selectDataGrid: { selection: { mode: 'multiple', allowSelectAll: true, }, columns: [ { dataField: 'ControlPoint', width: 340, caption: "관제점 이름", alignment: 'center', } , { dataField: 'FuelType', width: 140, caption: "에너지원", alignment: 'center' } , { dataField: 'FacilityTypeId', visible: false }, { dataField: 'FacilityCode', visible: false }, { dataField: 'PropertyId', visible: false }, { dataField: 'FormulaId', visible: false } ] //, paging: { pageSize: 20, enabled: true } }, updateButtonClicked: function () { UpdateGridData(); setTimeout(function () { GetGridData(); }, 1000); }, delButtonClicked: function () { DeleteGridData(); setTimeout(function () { GetGridData(); }, 1000); }, selectButtonClicked: function () { enroll_btn = true; facilityTypeId_fin = 0, facilityCode_fin = 0, parentId_fin = 0, propertyId_fin = 0, facilityName_fin = "", formulaId_fin = 0, controlPoint_fin = ""; UpperLimit_ONOFF_value = false, LowerLimit_ONOFF_value = false, AlarmYN_Id_value = false, EmailYN_Id_Id_value = false, SMSYN_Id_Id_value = false, Users_Id_text = "", text_Id_text = ""; LowerLimit_Id_text = "", UpperLimit_Id_text = ""; $("#Point_Type_Id").dxSelectBox({ placeholder: "관제점 타입", dataSource: treeViewData, displayExpr: "text", valueExpr: "id" }); $("#Facility_Type_Id").dxSelectBox({ placeholder: "설비 타입" }); $("#Facility_Id").dxSelectBox({ placeholder: "설비 이름" }); $("#Control_Id").dxSelectBox({ placeholder: "관제점 이름" }); $("#UpperLimit_Id").dxTextBox({ placeholder: "기준 상한값" }); $("#LowerLimit_Id").dxTextBox({ placeholder: "기준 하한값" }); $("#UpperLimit_ONOFF").dxSwitch({ onText: 'On', offText: 'Off', value: false }); $("#LowerLimit_ONOFF").dxSwitch({ onText: 'On', offText: 'Off', value: false }); $("#AlarmYN_Id").dxSwitch({ onText: 'On', offText: 'Off', value: false }); $("#SMSYN_Id").dxSwitch({ onText: 'On', offText: 'Off', value: false }); $("#EmailYN_Id").dxSwitch({ onText: 'On', offText: 'Off', value: false }); $("#Users_Id").dxSelectBox({ placeholder: "발송 그룹", dataSource: alarmgroup, displayExpr: "Name", valueExpr: "Name" }); $("#text_Id").dxTextArea({ placeholder: "조치 방법" }); if ($("#Point_Type_Id").dxSelectBox('instance') != null) $("#Point_Type_Id").dxSelectBox('instance').option('value', null);// 관제점 타입 클리어 if ($("#Facility_Type_Id").dxSelectBox('instance') != null) $("#Facility_Type_Id").dxSelectBox('instance').option('value', null);// 설비 타입 클리어 if ($("#Facility_Id").dxSelectBox('instance') != null) $("#Facility_Id").dxSelectBox('instance').option('value', null);// 설비 이름 클리어 if ($("#Control_Id").dxSelectBox('instance') != null) $("#Control_Id").dxSelectBox('instance').option('value', null);// 관제점 이름 클리어 if ($("#UpperLimit_Id").dxTextBox('instance') != null) $("#UpperLimit_Id").dxTextBox('instance').option('value', "");// 기준 상한값 클리어 if ($("#LowerLimit_Id").dxTextBox('instance') != null) $("#LowerLimit_Id").dxTextBox('instance').option('value', "");// 기준 하한값 클리어 if ($("#Users_Id").dxSelectBox('instance') != null) $("#Users_Id").dxSelectBox('instance').option('value', null);// 발송그룹 클리어 if ($("#text_Id").dxTextArea('instance') != null) $("#text_Id").dxTextArea('instance').option('value', "");// 조치방법 클리어 visiblePopup(true); }, selectSaveButtonClicked: function () { AddSelectPoint(); } }); viewModel.loadpopupOptions = { width: 300, height: 140, contentTemplate: "info", showTitle: false, title: "작업중", visible: loadvisiblePopup, dragEnabled: false, shading: false, closeOnOutsideClick: false }; viewModel.popupOptions = { width: 680, height: 630, visible: visiblePopup, dragEnabled: true, shading: true, closeOnOutsideClick: true, shadingColor: 'transparent', showTitle: true, title: "항목 선택", showCloseButton: true, onShowing: function () { }, onShown: function (t, tt) { popupInit = true; facility_type = ""; facility_id = ""; $("#Point_Type_Id").dxSelectBox({ placeholder: "관제점 타입", dataSource: treeViewData, displayExpr: "text", valueExpr: "id" }); $("#Facility_Type_Id").dxSelectBox({ placeholder: "설비 타입" }); $("#Facility_Id").dxSelectBox({ placeholder: "설비 이름" }); $("#Control_Id").dxSelectBox({ placeholder: "관제점 이름" }); $("#UpperLimit_Id").dxTextBox({ placeholder: "기준 상한값", onValueChanged: function (e) { var temp = e.value; if (temp.length == null) { } else { var total = 0; for (var i = 0; i < temp.length; i++) { for (var j = 0; j < allowedChars.length; j++) { if (temp[i] == allowedChars[j]) { total++; } } } if (total != temp.length) { utils.toast.show("숫자와 소수점만 입력가능합니다.", 'error'); $("#UpperLimit_Id").dxTextBox('instance').option('value', ""); return; } } if ($("#UpperLimit_ONOFF").dxSwitch('instance').option('value') == true) { if ($("#LowerLimit_ONOFF").dxSwitch('instance').option('value') == true) { if ($("#LowerLimit_Id").dxTextBox('instance').option('value') <= e.value) { UpperLimit_Id_text = e.value; $("#UpperLimit_Id").dxTextBox('instance').option('value', UpperLimit_Id_text); } else { utils.toast.show("기준 상한값은 기준 하한값보다 작을수 없습니다.", 'error'); $("#UpperLimit_Id").dxTextBox('instance').option('value', ""); return; } } else { UpperLimit_Id_text = e.value; $("#UpperLimit_Id").dxTextBox('instance').option('value', UpperLimit_Id_text); } } } }); $("#LowerLimit_Id").dxTextBox({ placeholder: "기준 하한값", onValueChanged: function (e) { var temp = e.value; if (temp.length == null) { } else { var total = 0; for (var i = 0; i < temp.length; i++) { for (var j = 0; j < allowedChars.length; j++) { if (temp[i] == allowedChars[j]) { total++; } } } if (total != temp.length) { utils.toast.show("숫자와 소수점만 입력가능합니다.", 'error'); $("#LowerLimit_Id").dxTextBox('instance').option('value', ""); return; } } if ($("#UpperLimit_ONOFF").dxSwitch('instance').option('value') == true) { if ($("#LowerLimit_ONOFF").dxSwitch('instance').option('value') == true) { if ($("#UpperLimit_Id").dxTextBox('instance').option('value') >= e.value) { LowerLimit_Id_text = e.value; $("#LowerLimit_Id").dxTextBox('instance').option('value', LowerLimit_Id_text); } else { utils.toast.show("기준 하한값은 기준 상한값보다 클수 없습니다.", 'error'); $("#LowerLimit_Id").dxTextBox('instance').option('value', ""); return; } } else { LowerLimit_Id_text = e.value; $("#LowerLimit_Id").dxTextBox('instance').option('value', LowerLimit_Id_text); } } } }); $("#UpperLimit_ONOFF").dxSwitch({ onText: 'On', offText: 'Off', value: false, onValueChanged: function (e) { if (e.value == true) { $("#UpperLimit_Id").dxTextBox({ disabled: false }); if ($("#UpperLimit_ONOFF").dxSwitch('instance').option('value') == true && $("#LowerLimit_ONOFF").dxSwitch('instance').option('value') == true) { if ($("#UpperLimit_Id").dxTextBox('instance').option('value') >= $("#LowerLimit_Id").dxTextBox('instance').option('value')) { } else { utils.toast.show("기준 상한값은 기준 하한값보다 작을수 없습니다.", 'error'); $("#UpperLimit_Id").dxTextBox('instance').option('value', ""); return; } } } else { $("#UpperLimit_Id").dxTextBox({ disabled: true }); } UpperLimit_ONOFF_value = e.value; } }); $("#LowerLimit_ONOFF").dxSwitch({ onText: 'On', offText: 'Off', value: false, onValueChanged: function (e) { LowerLimit_ONOFF_value = e.value; if (e.value == true) { $("#LowerLimit_Id").dxTextBox({ disabled: false }); if ($("#UpperLimit_ONOFF").dxSwitch('instance').option('value') == true && $("#LowerLimit_ONOFF").dxSwitch('instance').option('value') == true) { if ($("#UpperLimit_Id").dxTextBox('instance').option('value') >= $("#LowerLimit_Id").dxTextBox('instance').option('value')) { } else { utils.toast.show("기준 하한값은 기준 상한값보다 클수 없습니다.", 'error'); $("#LowerLimit_Id").dxTextBox('instance').option('value', ""); return; } } } else { $("#LowerLimit_Id").dxTextBox({ disabled: true }); } } }); $("#AlarmYN_Id").dxSwitch({ onText: 'On', offText: 'Off', value: false, onValueChanged: function (e) { AlarmYN_Id_value = e.value; } }); $("#SMSYN_Id").dxSwitch({ onText: 'On', offText: 'Off', value: false, onValueChanged: function (e) { SMSYN_Id_Id_value = e.value; } }); $("#EmailYN_Id").dxSwitch({ onText: 'On', offText: 'Off', value: false, onValueChanged: function (e) { EmailYN_Id_Id_value = e.value; } }); $("#Users_Id").dxSelectBox({ placeholder: "발송 그룹", dataSource: alarmgroup, displayExpr: "Name", valueExpr: "Name", onValueChanged: function (e) { var value = $("#Users_Id").dxSelectBox('instance').option('value'); Users_Id_text = value; } }); $("#text_Id").dxTextArea({ placeholder: "조치 방법", onValueChanged: function (e) { text_Id_text = e.value; } }); $("#Point_Type_Id").dxSelectBox({ onValueChanged: function () { facility_type = ""; facility_id = ""; setDataSource1 = ""; var value = $("#Point_Type_Id").dxSelectBox('instance').option('value'); if (value == null) facility_type = ""; else facility_type = treeViewData[value - 1].items; $("#Facility_Type_Id").dxSelectBox('instance').option('value', null);// 텍스트 클리어 $("#Facility_Type_Id").dxSelectBox({// 두번째 콤보 바인딩 placeholder: "설비 타입", dataSource: facility_type, displayExpr: "text", valueExpr: "id" }); $("#Facility_Id").dxSelectBox('instance').option('value', null);// 텍스트 클리어 $("#Facility_Id").dxSelectBox({// 두번째 콤보 바인딩 placeholder: "설비 이름", dataSource: facility_id, displayExpr: "text", valueExpr: "id" }); $("#Control_Id").dxSelectBox('instance').option('value', null);// 텍스트 클리어 $("#Control_Id").dxSelectBox({// 두번째 콤보 바인딩 placeholder: "관제점 이름", dataSource: setDataSource1, displayExpr: "ControlPoint", valueExpr: "FormulaId" }); } }); $("#Facility_Type_Id").dxSelectBox({ onValueChanged: function () { if (facility_type == "") { var value1 = $("#Point_Type_Id").dxSelectBox('instance').option('value'); if (value1 == null) facility_type = ""; else facility_type = treeViewData[value1 - 1].items; } facility_id = ""; setDataSource1 = ""; var Pointtype = $("#Point_Type_Id").dxSelectBox('instance').option('value'); var value = $("#Facility_Type_Id").dxSelectBox('instance').option('value'); if (Pointtype == 1)//성능분석 { if (value != null) { facility_id = facility_type[value - 4].items; } } else if (Pointtype == 2) { //가상 if (value != null) { facility_id = facility_type[0].items; } } else { //일반 if (value != null) { facility_id = facility_type[value - excnt].items; } } $("#Facility_Id").dxSelectBox('instance').option('value', null);// 텍스트 클리어 $("#Facility_Id").dxSelectBox({// 두번째 콤보 바인딩 placeholder: "설비 이름", dataSource: facility_id, displayExpr: "text", valueExpr: "id" }); $("#Control_Id").dxSelectBox('instance').option('value', null);// 텍스트 클리어 $("#Control_Id").dxSelectBox({// 두번째 콤보 바인딩 placeholder: "관제점 이름", dataSource: setDataSource1, displayExpr: "ControlPoint", valueExpr: "FormulaId" }); } }); $("#Facility_Id").dxSelectBox({ onValueChanged: function () { if (facility_id == "") { if (facility_type == "") { var value1 = $("#Point_Type_Id").dxSelectBox('instance').option('value'); if (value1 == null) facility_type = ""; else facility_type = treeViewData[value1 - 1].items; } var Pointtype = $("#Point_Type_Id").dxSelectBox('instance').option('value'); var value = $("#Facility_Type_Id").dxSelectBox('instance').option('value'); if (Pointtype == 1)//성능분석 { if (value != null) { facility_id = facility_type[value - 4].items; } } else if (Pointtype == 2) { //가상 if (value != null) { facility_id = facility_type[0].items; } } else { //일반 if (value != null) { facility_id = facility_type[value - excnt].items; } } } setDataSource1 = ""; var value = $("#Facility_Id").dxSelectBox('instance').option('value'); facilityTypeId_fin = 0, facilityCode_fin = 0, parentId_fin = 0; if (value != null) { for (var i = 0; i < facility_id.length; i++) { if (facility_id[i].id == value) { facilityTypeId_fin = facility_id[i].facilityTypeId; facilityCode_fin = facility_id[i].facilityCode; parentId_fin = facility_id[i].parentId; facilityName_fin = facility_id[i].text; break; } } GetPopupGridData(facilityTypeId_fin, facilityCode_fin, parentId_fin); } $("#Control_Id").dxSelectBox('instance').option('value', null);// 텍스트 클리어 $("#Control_Id").dxSelectBox({// 두번째 콤보 바인딩 placeholder: "관제점 이름", dataSource: setDataSource1, displayExpr: "ControlPoint", valueExpr: "FormulaId", }); } }); $("#Control_Id").dxSelectBox({ onValueChanged: function () { var value = $("#Control_Id").dxSelectBox('instance').option('text'); if (value != null) { for (var i = 0; i < setDataSource1.length; i++) { if (setDataSource1[i].ControlPoint == value) { propertyId_fin = setDataSource1[i].PropertyId; controlPoint_fin = setDataSource1[i].ControlPoint; formulaId_fin = setDataSource1[i].FormulaId; break; } } } } }); var j = 0; if (changed) { var Point_Type_Id_temp = 0; for (var i = 0; i < treeViewData.length; i++) { if (treeViewData[i].text == Point_Type_Id) { Point_Type_Id_temp = treeViewData[i].id; break; } } $("#Point_Type_Id").dxSelectBox('instance').option('value', Point_Type_Id_temp); var facility_type_Id_temp = 0; for (j = 0; j < treeViewData[Point_Type_Id_temp - 1].items.length; j++) { if (treeViewData[Point_Type_Id_temp - 1].items[j].facilityTypeId == facilityTypeId) { facility_type_Id_temp = treeViewData[Point_Type_Id_temp - 1].items[j].id; break; } } $("#Facility_Type_Id").dxSelectBox('instance').option('value', facility_type_Id_temp); var FacilityCode_temp = 0; var facilityTypeId_temp = 0; var parentId_temp = 0; FacilityCode_id_temp = 0; if (Point_Type_Id_temp == 1) { var delete_value = 4; } else if (Point_Type_Id_temp == 2) { delete_value = facility_type_Id_temp; } else { delete_value = excnt; } for (var k = 0; k < treeViewData[Point_Type_Id_temp - 1].items[facility_type_Id_temp - delete_value].items.length; k++) { if (treeViewData[Point_Type_Id_temp - 1].items[facility_type_Id_temp - delete_value].items[k].facilityCode == FacilityCode) { FacilityCode_id_temp = treeViewData[Point_Type_Id_temp - 1].items[facility_type_Id_temp - delete_value].items[k].id; FacilityCode_temp = treeViewData[Point_Type_Id_temp - 1].items[facility_type_Id_temp - delete_value].items[k].facilityCode; facilityTypeId_temp = treeViewData[Point_Type_Id_temp - 1].items[facility_type_Id_temp - delete_value].items[k].facilityTypeId; parentId_temp = treeViewData[Point_Type_Id_temp - 1].items[facility_type_Id_temp - delete_value].items[k].parentId; break; } } GetPopupGridData(facilityTypeId_temp, FacilityCode_temp, parentId_temp); } if (row_btn) { $("#updateSaveBtn").dxButton({ visible: true }); $("#delBtn").dxButton({ visible: false }); $("#selectSaveBtn").dxButton({ visible: false }); $("#Point_Type_Id").dxSelectBox({ disabled: true }); $("#Facility_Type_Id").dxSelectBox({ disabled: true }); $("#Facility_Id").dxSelectBox({ disabled: true }); $("#Control_Id").dxSelectBox({ disabled: true }); row_btn = false; } if (enroll_btn) { $("#Point_Type_Id").dxSelectBox({ disabled: false }); $("#Facility_Type_Id").dxSelectBox({ disabled: false }); $("#Facility_Id").dxSelectBox({ disabled: false }); $("#Control_Id").dxSelectBox({ disabled: false }); $("#updateSaveBtn").dxButton({ visible: false }); $("#delBtn").dxButton({ visible: false }); $("#selectSaveBtn").dxButton({ visible: true }); enroll_btn = false; } }, onHidden: function () { }, hasnotModificationPermission: hasnotModificationPermission //권한설정 }; return viewModel; };