dbbfabdc83fa1acc65eac008eec951d3be4516de.svn-base 75 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486
  1. BemsWebApplication.SimulatorIceStorage = function (params, viewInfo) {
  2. "use strict";
  3. var endpointSelector = "";
  4. if (BemsWebApplication.config.mode == "production") {
  5. endpointSelector = new DevExpress.EndpointSelector(BemsWebApplication.config.endpoints).config.db.production;
  6. } else {
  7. endpointSelector = new DevExpress.EndpointSelector(BemsWebApplication.config.endpoints).config.db.local;
  8. }
  9. var BemsIceThermalStorageDataSource = BemsWebApplication.db.createDataSource('BemsIceThermalStorageSimulation');
  10. var timeBoxForSearch = BWA.SearchView.createDateTimeBox($G.TimeTypesForDayOnly);
  11. var visibleConfigPopup = ko.observable(false);
  12. var timer;
  13. var initialized = false;
  14. var initializedforPopUp = false;
  15. var iceThermalStorage_SimulationValueGet = new BWA.Chart.IceThermalStorage_SimulationValueGet(BWA.UserInfo.SiteId());
  16. var chart = BWA.Chart.Instance('chartIS', 'dxChart');
  17. // 그리드 도표 작업 : 팝업창 추가
  18. // 팝업창뷰 보이기 속성 제어용 변수 선언
  19. var DataGridPopup_Visible = ko.observable(false);
  20. // 그래프 출력 이후 엑셀출력을 위한 팝업창을 위해 임시 저장용 배열 선언
  21. var dataArrayresult = ko.observableArray();
  22. // 그리드 도표 작업 : 팝업창 추가
  23. var dataArrayforPopup = []; // 도표에 들어갈 변수
  24. var visibleHourGlassPopup = ko.observable(false);
  25. var visibleEditButton = ko.observable(true); // 수정 버튼 활성화 여부 플래그
  26. var hasnotModificationPermission = ko.observable(false); // 수정버튼 비활성화 플래그
  27. var isEditModeInPopup = ko.observable(false); // 저장버튼 활성화 플래그
  28. var isNotModifyMode = ko.observable(true); // 저장버튼 비활성화 플래그
  29. var visibleCancelButton = ko.observable(false); // 취소버튼 활성화 플래그
  30. var simulatoricestoragePopupToolbarItems = [
  31. { location: 'before', text: '사용자 시뮬레이터 변수 설정' },
  32. { location: 'after', widget: 'button', options: { text: $G('edit'), icon: 'edit', visible: visibleEditButton, disabled: hasnotModificationPermission, clickAction: handlePopupButtonEdit } },
  33. { location: 'after', widget: 'button', options: { text: $G('cancel'), icon: 'cancel', visible: visibleCancelButton, clickAction: handlePopupButtonCancel } },
  34. { location: 'after', widget: 'button', options: { text: $G('save'), icon: 'save', visible: isEditModeInPopup, disabled: isNotModifyMode, clickAction: handlePopupButtonSave } },
  35. { location: 'after', widget: 'button', options: { text: $G('close'), icon: 'close', visible: true, disabled: false, clickAction: PopupButtonClose } }
  36. ];
  37. var CurrntRowStatusAsSave = 1; // 저장했을때 최종 row 인덱스 (취소, 닫기했을때 이전 최종 행 위치를 알기 위함)
  38. // 편집 중인 행과 활성화 여부 플래그
  39. var EditingFirstRow = ko.observable(true);
  40. var EditingSecondRow = ko.observable(false);
  41. var EditingThirdRow = ko.observable(false);
  42. var EditingFourthRow = ko.observable(false);
  43. var EditingFifthRow = ko.observable(false);
  44. var isSecondRow = ko.observable(false);
  45. var isThirdRow = ko.observable(false);
  46. var isFourthRow = ko.observable(false);
  47. var isFifthRow = ko.observable(false);
  48. //Initial Date는 지금 시점 이후부터 입력(initialDate와 finalDate는 기준 시작, 종료 일시)
  49. var initialDate = new Date();
  50. initialDate.setMinutes((parseInt(initialDate.getMinutes() / 15)) * 15);
  51. var finalDate = new Date();
  52. if (finalDate.getHours() < 21) {
  53. finalDate.setHours(0)
  54. finalDate.setMinutes(45);
  55. finalDate.setSeconds(0);
  56. finalDate = moment(finalDate).add(20, 'hours').toDate();
  57. }
  58. else {
  59. finalDate.setHours(0)
  60. finalDate.setMinutes(45);
  61. finalDate.setSeconds(0);
  62. finalDate = moment(finalDate).add(1, 'days').toDate();
  63. finalDate = moment(finalDate).add(20, 'hours').toDate();
  64. }
  65. // 행 추가, 제거시 기억할 변수 선언
  66. var initDate_prev = new Array();
  67. var finalDate_prev = new Array();
  68. var operationMode_prev = new Array();
  69. var ref1Status_prev = new Array();
  70. var ref2Status_prev = new Array();
  71. // 저장시 기억할 변수 선언 (~_asSave)
  72. var initDate_asSave = new Array(new Date(initialDate), new Date(initialDate), new Date(initialDate), new Date(initialDate), new Date(initialDate));
  73. var finalDate_asSave = new Array(new Date(finalDate), new Date(finalDate), new Date(finalDate), new Date(finalDate), new Date(finalDate));
  74. var operationMode_asSave = new Array(null, null, null, null, null);
  75. var ref1Status_asSave = new Array(null, null, null, null, null);
  76. var ref2Status_asSave = new Array(null, null, null, null, null);
  77. var treeOperationMode = [
  78. {
  79. id: 0,
  80. text: "OFF",
  81. value: 0
  82. },
  83. {
  84. id: 1,
  85. text: "제빙운전",
  86. value: 10
  87. },
  88. {
  89. id: 2,
  90. text: "축단운전",
  91. value: 20
  92. },
  93. {
  94. id: 3,
  95. text: "병렬운전",
  96. value: 30
  97. },
  98. {
  99. id: 4,
  100. text: "냉단운전",
  101. value: 40
  102. }
  103. ];
  104. // 현재시점에 최종 수정 row 플래그
  105. function EditingRowArrange() {
  106. var Edit_idx = [false, false, false, false, false];
  107. var EnDis_idx = [false, false, false, false, false];
  108. Edit_idx[CurrntRowStatusAsSave - 1] = true;
  109. for (var i = 0; i < CurrntRowStatusAsSave; i++) {
  110. EnDis_idx[i] = true;
  111. }
  112. EditingFirstRow(Edit_idx[0]);
  113. EditingSecondRow(Edit_idx[1]);
  114. EditingThirdRow(Edit_idx[2]);
  115. EditingFourthRow(Edit_idx[3]);
  116. EditingFifthRow(Edit_idx[4]);
  117. isSecondRow(EnDis_idx[1]);
  118. isThirdRow(EnDis_idx[2]);
  119. isFourthRow(EnDis_idx[3]);
  120. isFifthRow(EnDis_idx[4]);
  121. }
  122. // 팝업뜰 때마다 호출 (수정모드 템플릿)
  123. function InitializedTemplate() {
  124. visibleEditButton(true);
  125. hasnotModificationPermission(false);
  126. isEditModeInPopup(false);
  127. isNotModifyMode(true);
  128. visibleCancelButton(false);
  129. EditingRowArrange(); // 현재시점에 최종 수정 row 플래그
  130. // 팝업뜰때는 수정모드가 아니므로 모두 disabled
  131. for (var i = 0; i < 5; i++) {
  132. EnableDisableRow(i + 1, true);
  133. }
  134. }
  135. //초기 데이터 initialize
  136. function InitializedData() {
  137. var initialDate_ = new Date();
  138. initialDate_.setMinutes((parseInt(initialDate_.getMinutes() / 15)) * 15); // 15분 단위 맞춰주기 위함
  139. initialDate_.setSeconds(0);
  140. var finalDate_ = new Date();
  141. if (finalDate_.getHours() < 21) {
  142. finalDate_.setHours(0)
  143. finalDate_.setMinutes(45);
  144. finalDate_.setSeconds(0);
  145. finalDate_ = moment(finalDate_).add(20, 'hours').toDate();
  146. }
  147. else {
  148. finalDate_.setHours(0)
  149. finalDate_.setMinutes(45);
  150. finalDate_.setSeconds(0);
  151. finalDate_ = moment(finalDate_).add(1, 'days').toDate();
  152. finalDate_ = moment(finalDate_).add(20, 'hours').toDate();
  153. }
  154. for (var i = 0; i < 5; i++) {
  155. BoxInitialize(i + 1, initialDate_, finalDate_);
  156. EnableDisableRow(i + 1, true); // 초기는 수정모드가 아니므로 모두 disabled
  157. }
  158. }
  159. // 수정 버튼 클릭시 호출 함수
  160. function handlePopupButtonEdit() {
  161. visibleEditButton(false);
  162. hasnotModificationPermission(true);
  163. isEditModeInPopup(true);
  164. isNotModifyMode(false);
  165. visibleCancelButton(true);
  166. EditingRowArrange(); // 현재시점에 최종 수정 row 플래그
  167. EnableDisableRow(CurrntRowStatusAsSave, false); // 현재시점에 최종 수정 row 활성화
  168. }
  169. // ~_prev 변수 입력
  170. function prevDataWrite(row_num) {
  171. $("#InitialDate" + (row_num).toString()).dxDateBox('instance').option('value', initDate_prev[row_num - 1]);
  172. $("#InitialTime" + (row_num).toString()).dxDateBox('instance').option('value', initDate_prev[row_num - 1]);
  173. $("#FinalDate" + (row_num).toString()).dxDateBox('instance').option('value', finalDate_prev[row_num - 1]);
  174. $("#FinalTime" + (row_num).toString()).dxDateBox('instance').option('value', finalDate_prev[row_num - 1]);
  175. $("#OperationMode" + (row_num).toString()).dxSelectBox('instance').option('value', operationMode_prev[row_num - 1]);
  176. $("#Ref1_Status" + (row_num).toString()).dxSwitch('instance').option('value', ref1Status_prev[row_num - 1]);
  177. $("#Ref2_Status" + (row_num).toString()).dxSwitch('instance').option('value', ref2Status_prev[row_num - 1]);
  178. }
  179. function DeleteRow() {
  180. var now_ = new Date();
  181. var finalDate_ = new Date(now_.getFullYear(), now_.getMonth(), now_.getDate(), 20, 45, 0);
  182. if (now_.getHours() >= 21) {
  183. finalDate_ = moment(finalDate_).add(1, 'days').toDate();
  184. }
  185. if (EditingFirstRow() === true) {
  186. $("#FinalDate1").dxDateBox('instance').option('value', finalDate_);
  187. $("#FinalTime1").dxDateBox('instance').option('value', finalDate_);
  188. $("#OperationMode1").dxSelectBox('instance').option('value', null);// 운전 모드 클리어
  189. $("#Ref1_Status1").dxSwitch('instance').option('value', false);// 냉동기1 운전 모드 클리어
  190. $("#Ref2_Status1").dxSwitch('instance').option('value', false);// 냉동기2 운전 모드 클리어
  191. }
  192. else if (EditingSecondRow() === true) {
  193. $("#FinalDate2").dxDateBox('instance').option('value', finalDate_);
  194. $("#FinalTime2").dxDateBox('instance').option('value', finalDate_);
  195. $("#OperationMode2").dxSelectBox('instance').option('value', null);// 운전 모드 클리어
  196. $("#Ref1_Status2").dxSwitch('instance').option('value', false);// 냉동기1 운전 모드 클리어
  197. $("#Ref2_Status2").dxSwitch('instance').option('value', false);// 냉동기2 운전 모드 클리어
  198. EnableDisableRow(1, false);
  199. EditingFirstRow(true);
  200. EditingSecondRow(false);
  201. isSecondRow(false);
  202. prevDataWrite(1); // 행 삭제시 이전 행의 변수 초기화로 다시 쓰기
  203. }
  204. else if (EditingThirdRow() === true) {
  205. $("#FinalDate3").dxDateBox('instance').option('value', finalDate_);
  206. $("#FinalTime3").dxDateBox('instance').option('value', finalDate_);
  207. $("#OperationMode3").dxSelectBox('instance').option('value', null);// 운전 모드 클리어
  208. $("#Ref1_Status3").dxSwitch('instance').option('value', false);// 냉동기1 운전 모드 클리어
  209. $("#Ref2_Status3").dxSwitch('instance').option('value', false);// 냉동기2 운전 모드 클리어
  210. EnableDisableRow(2, false);
  211. EditingSecondRow(true);
  212. EditingThirdRow(false);
  213. isThirdRow(false);
  214. prevDataWrite(2); // 행 삭제시 이전 행의 변수 초기화로 다시 쓰기
  215. }
  216. else if (EditingFourthRow() === true) {
  217. $("#FinalDate4").dxDateBox('instance').option('value', finalDate_);
  218. $("#FinalTime4").dxDateBox('instance').option('value', finalDate_);
  219. $("#OperationMode4").dxSelectBox('instance').option('value', null);// 운전 모드 클리어
  220. $("#Ref1_Status4").dxSwitch('instance').option('value', false);// 냉동기1 운전 모드 클리어
  221. $("#Ref2_Status4").dxSwitch('instance').option('value', false);// 냉동기2 운전 모드 클리어
  222. EnableDisableRow(3, false);
  223. EditingThirdRow(true);
  224. EditingFourthRow(false);
  225. isFourthRow(false);
  226. prevDataWrite(3); // 행 삭제시 이전 행의 변수 초기화로 다시 쓰기
  227. }
  228. else if (EditingFifthRow() === true) {
  229. $("#FinalDate5").dxDateBox('instance').option('value', finalDate_);
  230. $("#FinalTime5").dxDateBox('instance').option('value', finalDate_);
  231. $("#OperationMode5").dxSelectBox('instance').option('value', null);// 운전 모드 클리어
  232. $("#Ref1_Status5").dxSwitch('instance').option('value', false);// 냉동기1 운전 모드 클리어
  233. $("#Ref2_Status5").dxSwitch('instance').option('value', false);// 냉동기2 운전 모드 클리어
  234. EnableDisableRow(4, false);
  235. EditingFourthRow(true);
  236. EditingFifthRow(false);
  237. isFifthRow(false);
  238. prevDataWrite(4); // 행 삭제시 이전 행의 변수 초기화로 다시 쓰기
  239. }
  240. }
  241. function FilledRow(row_num) {
  242. $("#InitialDate" + row_num.toString()).dxDateBox('instance').option('value', initDate_asSave[row_num - 1]);
  243. $("#InitialTime" + row_num.toString()).dxDateBox('instance').option('value', initDate_asSave[row_num - 1]);
  244. $("#FinalDate" + row_num.toString()).dxDateBox('instance').option('value', finalDate_asSave[row_num - 1]);
  245. $("#FinalTime" + row_num.toString()).dxDateBox('instance').option('value', finalDate_asSave[row_num - 1]);
  246. $("#OperationMode" + row_num.toString()).dxSelectBox('instance').option('value', operationMode_asSave[row_num - 1]);
  247. $("#Ref1_Status" + row_num.toString()).dxSwitch('instance').option('value', ref1Status_asSave[row_num - 1]);
  248. $("#Ref2_Status" + row_num.toString()).dxSwitch('instance').option('value', ref2Status_asSave[row_num - 1]);
  249. }
  250. // 취소 버튼 클릭시 호출 함수
  251. function handlePopupButtonCancel() {
  252. // 전체 열에 대해서 모두 삭제하고 저장된 열들만 다시 채워준다
  253. for (var i = 0; i < 5; i++) {
  254. DeleteRow();
  255. }
  256. for (var i = 0; i < 5; i++) {
  257. if (operationMode_asSave[i] != null) {
  258. FilledRow(i + 1);
  259. }
  260. }
  261. visibleEditButton(true);
  262. hasnotModificationPermission(false);
  263. isEditModeInPopup(false);
  264. isNotModifyMode(true);
  265. visibleCancelButton(false);
  266. EditingRowArrange(); // 현재시점에 최종 수정 row 플래그
  267. for (var i = 0; i < 5; i++) {
  268. EnableDisableRow(i + 1, true);
  269. }
  270. }
  271. // 데이터 DB 입력 함수
  272. function insert(postData) {
  273. BemsIceThermalStorageDataSource.filter([
  274. ["SiteId", "=", BWA.UserInfo.SiteId()],
  275. "and",
  276. ["FacilityCode", "=", postData.FacilityCode],
  277. "and",
  278. ["PropertyId", "=", postData.PropertyId],
  279. "and",
  280. ["SimulationCase", "=", postData.SimulationCase],
  281. "and",
  282. ["TargetDateTime", "=", postData.TargetDateTime]
  283. ]);
  284. //BemsIceThermalStorageDataSource.sort({ getter: "TargetDateTime", desc: true });
  285. BemsIceThermalStorageDataSource.load()
  286. .done(function (result) {
  287. var store = new DevExpress.data.ODataStore({
  288. url: endpointSelector + "/BemsIceThermalStorageSimulation",
  289. key: ["SiteId", "FacilityCode", "PropertyId", "CreatedDateTime", "TargetDateTime", "SimulationCase"],
  290. keyType: {
  291. SiteId: "Int32", FacilityCode: "Int32", PropertyId: "Int32", CreatedDateTime: "DateTime", TargetDateTime: "DateTime", SimulationCase: "Int32"
  292. }
  293. });
  294. if (result.length != 0) {
  295. var removeData = {
  296. SiteId: result[0].SiteId(),
  297. FacilityTypeId: result[0].FacilityTypeId(),
  298. FacilityCode: result[0].FacilityCode(),
  299. PropertyId: result[0].PropertyId(),
  300. CreatedDateTime: new Date(result[0].CreatedDateTime()),
  301. TargetDateTime: new Date(result[0].TargetDateTime()),
  302. SimulationValue: result[0].SimulationValue(),
  303. SimulationCase: result[0].SimulationCase()
  304. };
  305. store.remove(removeData).done(function (values, key) {
  306. store.insert(postData).done(function (key, result) {
  307. //utils.toast.show($G('successDatabaseInsertionMsg'));
  308. visibleConfigPopup(false);
  309. })
  310. .fail(function (error) {
  311. utils.toast.show(error, 'error');
  312. });
  313. })
  314. .fail(function (error) {
  315. utils.toast.show(error, 'error');
  316. });
  317. }
  318. else {
  319. store.insert(postData).done(function (key, result) {
  320. //utils.toast.show($G('successDatabaseInsertionMsg'));
  321. visibleConfigPopup(false);
  322. })
  323. .fail(function (error) {
  324. utils.toast.show(error, 'error');
  325. });
  326. }
  327. });
  328. }
  329. function DataArrange(initialDate_, finalDate_, facilityTypeId, facilityCode, propertyId, value, simulationCase) {
  330. var now_date = new Date();
  331. var comparedDate = new Date(initialDate_.getFullYear(), initialDate_.getMonth(), initialDate_.getDate(), initialDate_.getHours(), initialDate_.getMinutes(), 0);
  332. while (comparedDate <= finalDate_) {
  333. //insert
  334. var nowDate_tmp = new Date(now_date.getFullYear(), now_date.getMonth(), now_date.getDate(), now_date.getHours(), now_date.getMinutes(), now_date.getSeconds());
  335. var tmpDate = new Date(comparedDate.getFullYear(), comparedDate.getMonth(), comparedDate.getDate(), comparedDate.getHours(), comparedDate.getMinutes(), 0);
  336. var postViewModel = new BemsWebApplication.BemsIceThermalStorageSimulationViewModel();
  337. postViewModel.SiteId(BWA.UserInfo.SiteId());
  338. postViewModel.FacilityTypeId(facilityTypeId);
  339. postViewModel.FacilityCode(facilityCode);
  340. postViewModel.PropertyId(propertyId);
  341. postViewModel.CreatedDateTime(nowDate_tmp);
  342. postViewModel.TargetDateTime(tmpDate);
  343. postViewModel.SimulationValue(value);
  344. postViewModel.SimulationCase(simulationCase);
  345. var postData = postViewModel.toJS();
  346. insert(postData);
  347. comparedDate.setMinutes(comparedDate.getMinutes() + 15);
  348. }
  349. }
  350. function DataExtract(row_num) {
  351. var islastRow = false;
  352. if (EditingFirstRow() == true && row_num == 1) { islastRow = true; }
  353. else if (EditingSecondRow() == true && row_num == 2) { islastRow = true; }
  354. else if (EditingThirdRow() == true && row_num == 3) { islastRow = true; }
  355. else if (EditingFourthRow() == true && row_num == 4) { islastRow = true; }
  356. else if (EditingFifthRow() == true && row_num == 5) { islastRow = true; }
  357. // 데이터 저장
  358. // 현재 활성화된 마지막 행만 ~_prev 데이터에 저장하고 DB 입력을 위한 부분, 이전행은 '행 추가' 버튼 클릭시 저장됨
  359. if (islastRow) {
  360. var tmp_initDate_ = $("#InitialTime" + (row_num).toString()).dxDateBox('instance').option('value');
  361. initDate_prev[row_num - 1] = new Date(tmp_initDate_.getFullYear(), tmp_initDate_.getMonth(), tmp_initDate_.getDate(), tmp_initDate_.getHours(), tmp_initDate_.getMinutes(), 0);
  362. initDate_asSave[row_num - 1] = new Date(tmp_initDate_.getFullYear(), tmp_initDate_.getMonth(), tmp_initDate_.getDate(), tmp_initDate_.getHours(), tmp_initDate_.getMinutes(), 0);
  363. var tmp_finalDate_ = $("#FinalTime" + (row_num).toString()).dxDateBox('instance').option('value');
  364. finalDate_prev[row_num - 1] = new Date(tmp_finalDate_.getFullYear(), tmp_finalDate_.getMonth(), tmp_finalDate_.getDate(), tmp_finalDate_.getHours(), tmp_finalDate_.getMinutes(), 0);
  365. finalDate_asSave[row_num - 1] = new Date(tmp_finalDate_.getFullYear(), tmp_finalDate_.getMonth(), tmp_finalDate_.getDate(), tmp_finalDate_.getHours(), tmp_finalDate_.getMinutes(), 0);
  366. operationMode_prev[row_num - 1] = $("#OperationMode" + (row_num).toString()).dxSelectBox('instance').option('value');
  367. operationMode_asSave[row_num - 1] = $("#OperationMode" + (row_num).toString()).dxSelectBox('instance').option('value');
  368. ref1Status_prev[row_num - 1] = $("#Ref1_Status" + (row_num).toString()).dxSwitch('instance').option('value');
  369. ref1Status_asSave[row_num - 1] = $("#Ref1_Status" + (row_num).toString()).dxSwitch('instance').option('value');
  370. ref2Status_prev[row_num - 1] = $("#Ref2_Status" + (row_num).toString()).dxSwitch('instance').option('value');
  371. ref2Status_asSave[row_num - 1] = $("#Ref2_Status" + (row_num).toString()).dxSwitch('instance').option('value');
  372. if (ref1Status_prev[row_num - 1]) { var ref1Status_int = 1; } else { var ref1Status_int = 0; }
  373. if (ref2Status_prev[row_num - 1]) { var ref2Status_int = 1; } else { var ref2Status_int = 0; }
  374. DataArrange(initDate_prev[row_num - 1], finalDate_prev[row_num - 1], 3, 4478, 16, parseInt(operationMode_prev[row_num - 1] * 10), 1); // 0: OFF, 10: 제빙, 20: 축단, 30:병렬, 40: 냉단
  375. DataArrange(initDate_prev[row_num - 1], finalDate_prev[row_num - 1], 2, 4479, 15, ref1Status_int, 1);
  376. DataArrange(initDate_prev[row_num - 1], finalDate_prev[row_num - 1], 2, 4480, 15, ref2Status_int, 1);
  377. }
  378. else {
  379. // 날짜 박스에서 불러올 경우 enable된 열의 날짜를 불러오기때문에 ~_prev 변수에서 불러옴
  380. var initDate_ = initDate_prev[row_num - 1];
  381. var finalDate_ = finalDate_prev[row_num - 1];
  382. initDate_asSave[row_num - 1] = initDate_prev[row_num - 1];
  383. finalDate_asSave[row_num - 1] = finalDate_prev[row_num - 1];
  384. var operationMode = $("#OperationMode" + (row_num).toString()).dxSelectBox('instance').option('value');
  385. operationMode_asSave[row_num - 1] = $("#OperationMode" + (row_num).toString()).dxSelectBox('instance').option('value');
  386. var ref1Status = $("#Ref1_Status" + (row_num).toString()).dxSwitch('instance').option('value');
  387. ref1Status_asSave[row_num - 1] = $("#Ref1_Status" + (row_num).toString()).dxSwitch('instance').option('value');
  388. var ref2Status = $("#Ref2_Status" + (row_num).toString()).dxSwitch('instance').option('value');
  389. ref2Status_asSave[row_num - 1] = $("#Ref2_Status" + (row_num).toString()).dxSwitch('instance').option('value');
  390. if (ref1Status) { var ref1Status_int = 1; } else { var ref1Status_int = 0; }
  391. if (ref2Status) { var ref2Status_int = 1; } else { var ref2Status_int = 0; }
  392. DataArrange(initDate_, finalDate_, 3, 4478, 16, parseInt(operationMode * 10), 1); // 0: OFF, 10: 제빙, 20: 축단, 30:병렬, 40: 냉단
  393. DataArrange(initDate_, finalDate_, 2, 4479, 15, ref1Status_int, 1);
  394. DataArrange(initDate_, finalDate_, 2, 4480, 15, ref2Status_int, 1);
  395. }
  396. }
  397. function handlePopupButtonSave() {
  398. var now_date = new Date();
  399. if (now_date.getHours() != 0 && now_date.getMinutes() % 15 == 1 && now_date.getSeconds() > 0 && now_date.getSeconds() < 40) {
  400. utils.toast.show('데이터 모델이 업데이트 중입니다. 잠시후 다시 시도해주세요. (약 40초 소요 예정)', 'error');
  401. }
  402. else {
  403. // 0, 4, 8, 12 ...초 시간에만 동작
  404. visibleHourGlassPopup(true); // 모래시계 팝업 활성화
  405. while (1) {
  406. var now_ = new Date();
  407. if (now_.getSeconds() % 4 == 0) { break; }
  408. else { setTimeout(function () { }, 1000); }
  409. }
  410. if (EditingFirstRow() === true) {
  411. if (enabledDateRange(1, "save")) {
  412. initDate_asSave = new Array(new Date(initialDate), new Date(initialDate), new Date(initialDate), new Date(initialDate), new Date(initialDate));
  413. finalDate_asSave = new Array(new Date(finalDate), new Date(finalDate), new Date(finalDate), new Date(finalDate), new Date(finalDate));
  414. operationMode_asSave = new Array(null, null, null, null, null);
  415. ref1Status_asSave = new Array(null, null, null, null, null);
  416. ref2Status_asSave = new Array(null, null, null, null, null);
  417. DataExtract(1);
  418. $("#LoadPanel").dxLoadPanel('instance').option('visible', true);
  419. visibleHourGlassPopup(true); // 모래시계 팝업 활성화
  420. // Python에서 데이터 처리하고 DB에서 데이터 불러오는 시간 고려
  421. setTimeout(function () {
  422. $("#LoadPanel").dxLoadPanel('instance').option('visible', false);
  423. visibleHourGlassPopup(false);
  424. handleSearchInSearchView();
  425. }, 12000);
  426. CurrntRowStatusAsSave = 1;
  427. }
  428. }
  429. else if (EditingSecondRow() === true) {
  430. if (enabledDateRange(2, "save")) {
  431. initDate_asSave = new Array(new Date(initialDate), new Date(initialDate), new Date(initialDate), new Date(initialDate), new Date(initialDate));
  432. finalDate_asSave = new Array(new Date(finalDate), new Date(finalDate), new Date(finalDate), new Date(finalDate), new Date(finalDate));
  433. operationMode_asSave = new Array(null, null, null, null, null);
  434. ref1Status_asSave = new Array(null, null, null, null, null);
  435. ref2Status_asSave = new Array(null, null, null, null, null);
  436. DataExtract(1);
  437. DataExtract(2);
  438. $("#LoadPanel").dxLoadPanel('instance').option('visible', true);
  439. visibleHourGlassPopup(true); // 모래시계 팝업 활성화
  440. // Python에서 데이터 처리하고 DB에서 데이터 불러오는 시간 고려
  441. setTimeout(function () {
  442. $("#LoadPanel").dxLoadPanel('instance').option('visible', false);
  443. visibleHourGlassPopup(false);
  444. handleSearchInSearchView();
  445. }, 12000);
  446. CurrntRowStatusAsSave = 2;
  447. }
  448. }
  449. else if (EditingThirdRow() === true) {
  450. if (enabledDateRange(3, "save")) {
  451. initDate_asSave = new Array(new Date(initialDate), new Date(initialDate), new Date(initialDate), new Date(initialDate), new Date(initialDate));
  452. finalDate_asSave = new Array(new Date(finalDate), new Date(finalDate), new Date(finalDate), new Date(finalDate), new Date(finalDate));
  453. operationMode_asSave = new Array(null, null, null, null, null);
  454. ref1Status_asSave = new Array(null, null, null, null, null);
  455. ref2Status_asSave = new Array(null, null, null, null, null);
  456. DataExtract(1);
  457. DataExtract(2);
  458. DataExtract(3);
  459. $("#LoadPanel").dxLoadPanel('instance').option('visible', true);
  460. visibleHourGlassPopup(true); // 모래시계 팝업 활성화
  461. // Python에서 데이터 처리하고 DB에서 데이터 불러오는 시간 고려
  462. setTimeout(function () {
  463. $("#LoadPanel").dxLoadPanel('instance').option('visible', false);
  464. visibleHourGlassPopup(false);
  465. handleSearchInSearchView();
  466. }, 12000);
  467. CurrntRowStatusAsSave = 3;
  468. }
  469. }
  470. else if (EditingFourthRow() === true) {
  471. if (enabledDateRange(4, "save")) {
  472. initDate_asSave = new Array(new Date(initialDate), new Date(initialDate), new Date(initialDate), new Date(initialDate), new Date(initialDate));
  473. finalDate_asSave = new Array(new Date(finalDate), new Date(finalDate), new Date(finalDate), new Date(finalDate), new Date(finalDate));
  474. operationMode_asSave = new Array(null, null, null, null, null);
  475. ref1Status_asSave = new Array(null, null, null, null, null);
  476. ref2Status_asSave = new Array(null, null, null, null, null);
  477. DataExtract(1);
  478. DataExtract(2);
  479. DataExtract(3);
  480. DataExtract(4);
  481. $("#LoadPanel").dxLoadPanel('instance').option('visible', true);
  482. visibleHourGlassPopup(true); // 모래시계 팝업 활성화
  483. // Python에서 데이터 처리하고 DB에서 데이터 불러오는 시간 고려
  484. setTimeout(function () {
  485. $("#LoadPanel").dxLoadPanel('instance').option('visible', false);
  486. visibleHourGlassPopup(false);
  487. handleSearchInSearchView();
  488. }, 12000);
  489. CurrntRowStatusAsSave = 4;
  490. }
  491. }
  492. else if (EditingFifthRow() === true) {
  493. if (enabledDateRange(5, "save")) {
  494. initDate_asSave = new Array(new Date(initialDate), new Date(initialDate), new Date(initialDate), new Date(initialDate), new Date(initialDate));
  495. finalDate_asSave = new Array(new Date(finalDate), new Date(finalDate), new Date(finalDate), new Date(finalDate), new Date(finalDate));
  496. operationMode_asSave = new Array(null, null, null, null, null);
  497. ref1Status_asSave = new Array(null, null, null, null, null);
  498. ref2Status_asSave = new Array(null, null, null, null, null);
  499. DataExtract(1);
  500. DataExtract(2);
  501. DataExtract(3);
  502. DataExtract(4);
  503. DataExtract(5);
  504. $("#LoadPanel").dxLoadPanel('instance').option('visible', true);
  505. visibleHourGlassPopup(true); // 모래시계 팝업 활성화
  506. // Python에서 데이터 처리하고 DB에서 데이터 불러오는 시간 고려
  507. setTimeout(function () {
  508. $("#LoadPanel").dxLoadPanel('instance').option('visible', false);
  509. visibleHourGlassPopup(false);
  510. handleSearchInSearchView();
  511. }, 12000);
  512. CurrntRowStatusAsSave = 5;
  513. }
  514. }
  515. }
  516. visibleHourGlassPopup(false); // 모래시계 팝업 비활성화
  517. }
  518. // 데이터 범위 및 필수 입력사항 체크 함수
  519. function enabledDateRange(row_num, mode) {
  520. var now_ = new Date();
  521. var finalDate_ = new Date(now_.getFullYear(), now_.getMonth(), now_.getDate(), 20, 45, 0);
  522. if (now_.getHours() >= 21) {
  523. finalDate_ = moment(finalDate_).add(1, 'days').toDate();
  524. }
  525. var BoxInitDate_tmp = $("#InitialDate" + (row_num).toString()).dxDateBox('instance').option('value');
  526. var BoxInitTime_tmp = $("#InitialTime" + (row_num).toString()).dxDateBox('instance').option('value');
  527. var BoxFinalDate_tmp = $("#FinalDate" + (row_num).toString()).dxDateBox('instance').option('value');
  528. var BoxFinalTime_tmp = $("#FinalTime" + (row_num).toString()).dxDateBox('instance').option('value');
  529. var input_inialDateTime = new Date(BoxInitDate_tmp.getFullYear(), BoxInitDate_tmp.getMonth(), BoxInitDate_tmp.getDate(), BoxInitTime_tmp.getHours(), BoxInitTime_tmp.getMinutes(), 0);
  530. var input_finalDateTime = new Date(BoxFinalDate_tmp.getFullYear(), BoxFinalDate_tmp.getMonth(), BoxFinalDate_tmp.getDate(), BoxFinalTime_tmp.getHours(), BoxFinalTime_tmp.getMinutes(), 0);
  531. var comparedDate = new Date(now_.getFullYear(), now_.getMonth(), now_.getDate(), 20, 45, 0);
  532. if (now_.getHours() >= 21) {
  533. comparedDate = moment(comparedDate).add(1, 'days').toDate();
  534. }
  535. var BoxDate_tmp = $("#FinalTime" + (row_num).toString()).dxDateBox('instance').option('value');
  536. var BoxDate = new Date(BoxDate_tmp.getFullYear(), BoxDate_tmp.getMonth(), BoxDate_tmp.getDate(), BoxDate_tmp.getHours(), BoxDate_tmp.getMinutes(), 0);
  537. if ($("#OperationMode" + (row_num).toString()).dxSelectBox('instance').option('value') == null) {
  538. utils.toast.show('항목이 모두 입력되지 않았습니다.', 'error');
  539. return false;
  540. }
  541. else if (BoxDate.getTime() == finalDate_.getTime() && mode == "edit") {
  542. utils.toast.show('마지막 종료시점이 시뮬레이션 허용 마지막 시간(당일 21시 혹은 익일 21시)이므로 행 추가가 불가합니다.', 'error');
  543. return false;
  544. }
  545. else if (BoxDate.getTime() != finalDate_.getTime() && mode == "save") {
  546. utils.toast.show('마지막 행의 종료 시점이 시뮬레이션 마지막 시간(21시)과 일치하지 않습니다.', 'error');
  547. return false;
  548. }
  549. else if (input_finalDateTime.getTime() > comparedDate.getTime()) {
  550. utils.toast.show("입력 최대 기간(당일 21시 혹은 익일 21시)을 초과하였습니다.", 'error');
  551. $("#FinalTime" + (row_num).toString()).dxDateBox("instance").option('value', comparedDate);
  552. return false;
  553. }
  554. else if (input_finalDateTime.getTime() < input_inialDateTime.getTime()) {
  555. utils.toast.show("마지막 행의 종료 시간이 시작 시간보다 빠릅니다.", 'error');
  556. $("#FinalTime" + (row_num).toString()).dxDateBox("instance").option('value', comparedDate);
  557. return false;
  558. }
  559. else {
  560. return true;
  561. }
  562. }
  563. function handlePopupButtonAdd() {
  564. // 행추가시 기존 제어 변수 입력 열에 미입력 사항이 있는지 확인하는 기능
  565. var now_ = new Date();
  566. var finalDate_ = new Date(now_.getFullYear(), now_.getMonth(), now_.getDate(), 20, 45, 0);
  567. if (now_.getHours() >= 21) {
  568. finalDate_ = moment(finalDate_).add(1, 'days').toDate();
  569. }
  570. if (EditingFirstRow() === true) {
  571. if (enabledDateRange(1, "edit")) {
  572. var InitDate_tmp = $("#InitialTime1").dxDateBox('instance').option('value');
  573. var BoxDate_tmp = $("#FinalTime1").dxDateBox('instance').option('value');
  574. var BoxDate = new Date(BoxDate_tmp.getFullYear(), BoxDate_tmp.getMonth(), BoxDate_tmp.getDate(), BoxDate_tmp.getHours(), BoxDate_tmp.getMinutes(), 0);
  575. initDate_prev[0] = new Date(InitDate_tmp.getFullYear(), InitDate_tmp.getMonth(), InitDate_tmp.getDate(), InitDate_tmp.getHours(), InitDate_tmp.getMinutes(), 0);
  576. finalDate_prev[0] = new Date(BoxDate_tmp.getFullYear(), BoxDate_tmp.getMonth(), BoxDate_tmp.getDate(), BoxDate_tmp.getHours(), BoxDate_tmp.getMinutes(), 0);
  577. operationMode_prev[0] = $("#OperationMode1").dxSelectBox('instance').option('value');;
  578. ref1Status_prev[0] = $("#Ref1_Status1").dxSwitch("instance").option('value');
  579. ref2Status_prev[0] = $("#Ref2_Status1").dxSwitch("instance").option('value');
  580. EnableDisableRow(1, true);
  581. EnableDisableRow(2, false);
  582. EditingFirstRow(false);
  583. EditingSecondRow(true);
  584. isSecondRow(true);
  585. BoxDate.setMinutes(BoxDate.getMinutes() + 15);
  586. $("#InitialDate2").dxDateBox('instance').option('value', BoxDate);
  587. $("#InitialTime2").dxDateBox('instance').option('value', BoxDate);
  588. $("#FinalDate2").dxDateBox('instance').option('value', finalDate_);
  589. $("#FinalTime2").dxDateBox('instance').option('value', finalDate_);
  590. }
  591. else {
  592. return;
  593. }
  594. }
  595. else if (EditingSecondRow() === true) {
  596. if (enabledDateRange(2, "edit")) {
  597. var InitDate_tmp = $("#InitialTime2").dxDateBox('instance').option('value');
  598. var BoxDate_tmp = $("#FinalTime2").dxDateBox('instance').option('value');
  599. var BoxDate = new Date(BoxDate_tmp.getFullYear(), BoxDate_tmp.getMonth(), BoxDate_tmp.getDate(), BoxDate_tmp.getHours(), BoxDate_tmp.getMinutes(), 0);
  600. initDate_prev[1] = new Date(InitDate_tmp.getFullYear(), InitDate_tmp.getMonth(), InitDate_tmp.getDate(), InitDate_tmp.getHours(), InitDate_tmp.getMinutes(), 0);
  601. finalDate_prev[1] = new Date(BoxDate_tmp.getFullYear(), BoxDate_tmp.getMonth(), BoxDate_tmp.getDate(), BoxDate_tmp.getHours(), BoxDate_tmp.getMinutes(), 0);
  602. operationMode_prev[1] = $("#OperationMode2").dxSelectBox('instance').option('value');;
  603. ref1Status_prev[1] = $("#Ref1_Status2").dxSwitch("instance").option('value');
  604. ref2Status_prev[1] = $("#Ref2_Status2").dxSwitch("instance").option('value');
  605. EnableDisableRow(2, true);
  606. EnableDisableRow(3, false);
  607. EditingSecondRow(false);
  608. EditingThirdRow(true);
  609. isThirdRow(true);
  610. BoxDate.setMinutes(BoxDate.getMinutes() + 15);
  611. $("#InitialDate3").dxDateBox('instance').option('value', BoxDate);
  612. $("#InitialTime3").dxDateBox('instance').option('value', BoxDate);
  613. $("#FinalDate3").dxDateBox('instance').option('value', finalDate_);
  614. $("#FinalTime3").dxDateBox('instance').option('value', finalDate_);
  615. }
  616. }
  617. else if (EditingThirdRow() === true) {
  618. if (enabledDateRange(3, "edit")) {
  619. var InitDate_tmp = $("#InitialTime3").dxDateBox('instance').option('value');
  620. var BoxDate_tmp = $("#FinalTime3").dxDateBox('instance').option('value');
  621. var BoxDate = new Date(BoxDate_tmp.getFullYear(), BoxDate_tmp.getMonth(), BoxDate_tmp.getDate(), BoxDate_tmp.getHours(), BoxDate_tmp.getMinutes(), 0);
  622. initDate_prev[2] = new Date(InitDate_tmp.getFullYear(), InitDate_tmp.getMonth(), InitDate_tmp.getDate(), InitDate_tmp.getHours(), InitDate_tmp.getMinutes(), 0);
  623. finalDate_prev[2] = new Date(BoxDate_tmp.getFullYear(), BoxDate_tmp.getMonth(), BoxDate_tmp.getDate(), BoxDate_tmp.getHours(), BoxDate_tmp.getMinutes(), 0);
  624. operationMode_prev[2] = $("#OperationMode3").dxSelectBox('instance').option('value');;
  625. ref1Status_prev[2] = $("#Ref1_Status3").dxSwitch("instance").option('value');
  626. ref2Status_prev[2] = $("#Ref2_Status3").dxSwitch("instance").option('value');
  627. EnableDisableRow(3, true);
  628. EnableDisableRow(4, false);
  629. EditingThirdRow(false);
  630. EditingFourthRow(true);
  631. isFourthRow(true);
  632. BoxDate.setMinutes(BoxDate.getMinutes() + 15);
  633. $("#InitialDate4").dxDateBox('instance').option('value', BoxDate);
  634. $("#InitialTime4").dxDateBox('instance').option('value', BoxDate);
  635. $("#FinalDate4").dxDateBox('instance').option('value', finalDate_);
  636. $("#FinalTime4").dxDateBox('instance').option('value', finalDate_);
  637. }
  638. }
  639. else if (EditingFourthRow() === true) {
  640. if (enabledDateRange(4, "edit")) {
  641. var InitDate_tmp = $("#InitialTime4").dxDateBox('instance').option('value');
  642. var BoxDate_tmp = $("#FinalTime4").dxDateBox('instance').option('value');
  643. var BoxDate = new Date(BoxDate_tmp.getFullYear(), BoxDate_tmp.getMonth(), BoxDate_tmp.getDate(), BoxDate_tmp.getHours(), BoxDate_tmp.getMinutes(), 0);
  644. initDate_prev[3] = new Date(InitDate_tmp.getFullYear(), InitDate_tmp.getMonth(), InitDate_tmp.getDate(), InitDate_tmp.getHours(), InitDate_tmp.getMinutes(), 0);
  645. finalDate_prev[3] = new Date(BoxDate_tmp.getFullYear(), BoxDate_tmp.getMonth(), BoxDate_tmp.getDate(), BoxDate_tmp.getHours(), BoxDate_tmp.getMinutes(), 0);
  646. operationMode_prev[3] = $("#OperationMode4").dxSelectBox('instance').option('value');;
  647. ref1Status_prev[3] = $("#Ref1_Status4").dxSwitch("instance").option('value');
  648. ref2Status_prev[3] = $("#Ref2_Status4").dxSwitch("instance").option('value');
  649. EnableDisableRow(4, true);
  650. EnableDisableRow(5, false);
  651. EditingFourthRow(false);
  652. EditingFifthRow(true);
  653. isFifthRow(true);
  654. BoxDate.setMinutes(BoxDate.getMinutes() + 15);
  655. $("#InitialDate5").dxDateBox('instance').option('value', BoxDate);
  656. $("#InitialTime5").dxDateBox('instance').option('value', BoxDate);
  657. $("#FinalDate5").dxDateBox('instance').option('value', finalDate_);
  658. $("#FinalTime5").dxDateBox('instance').option('value', finalDate_);
  659. }
  660. }
  661. else if (EditingFifthRow() === true) {
  662. utils.toast.show('최대 행 추가 수는 5개입니다.', 'error');
  663. return;
  664. }
  665. }
  666. // 열 삭제
  667. function handlePopupButtonDelete() {
  668. if (EditingFirstRow() === true) {
  669. utils.toast.show('최소 1개 이상 행을 입력해야합니다.', 'error');
  670. }
  671. else {
  672. DeleteRow(); // 현재 열 삭제
  673. }
  674. return;
  675. }
  676. function EnableDisableRow(row_num, disabled) {
  677. // 모든 행의 시작일은 고정
  678. $("#InitialDate" + (row_num).toString()).dxDateBox("instance").option('disabled', true);
  679. $("#InitialTime" + (row_num).toString()).dxDateBox("instance").option('disabled', true);
  680. $("#FinalDate" + (row_num).toString()).dxDateBox("instance").option('disabled', disabled);
  681. $("#FinalTime" + (row_num).toString()).dxDateBox("instance").option('disabled', disabled);
  682. $("#OperationMode" + (row_num).toString()).dxSelectBox("instance").option('disabled', disabled);
  683. if ($("#OperationMode" + (row_num).toString()).dxSelectBox('instance').option('value') == 0
  684. || $("#OperationMode" + (row_num).toString()).dxSelectBox('instance').option('value') == 2) {
  685. $("#Ref1_Status" + (row_num).toString()).dxSwitch("instance").option('disabled', true);
  686. $("#Ref2_Status" + (row_num).toString()).dxSwitch("instance").option('disabled', true);
  687. }
  688. else {
  689. $("#Ref1_Status" + (row_num).toString()).dxSwitch("instance").option('disabled', disabled);
  690. $("#Ref2_Status" + (row_num).toString()).dxSwitch("instance").option('disabled', disabled);
  691. }
  692. }
  693. // 닫기버튼
  694. function PopupButtonClose() {
  695. visibleConfigPopup(false);
  696. // 전체 열에 대해서 모두 삭제하고 저장된 열들만 다시 채워준다
  697. for (var i = 0; i < 5; i++) {
  698. DeleteRow();
  699. }
  700. for (var i = 0; i < 5; i++) {
  701. if (operationMode_asSave[i] != null) {
  702. FilledRow(i + 1);
  703. }
  704. }
  705. visibleEditButton(true);
  706. hasnotModificationPermission(false);
  707. isEditModeInPopup(false);
  708. isNotModifyMode(true);
  709. visibleCancelButton(false);
  710. if (EditingFirstRow() == true) {
  711. EnableDisableRow(1, false);
  712. }
  713. else if (EditingSecondRow() == true) {
  714. EnableDisableRow(2, false);
  715. }
  716. else if (EditingThirdRow() == true) {
  717. EnableDisableRow(3, false);
  718. }
  719. else if (EditingFourthRow() == true) {
  720. EnableDisableRow(4, false);
  721. }
  722. else if (EditingFifthRow() == true) {
  723. EnableDisableRow(5, false);
  724. }
  725. }
  726. function SetPointer() {
  727. var now = new Date();
  728. var target_date;
  729. var isRecentData = ko.observable(false);
  730. if (now.getHours() < 21) {
  731. target_date = now
  732. }
  733. else {
  734. target_date = now.setDate(now.getDate() - 1);
  735. }
  736. var dataSource = new DevExpress.data.DataSource({
  737. store: {
  738. type: "odata",
  739. url: endpointSelector + "/BemsMonitoringPointWeatherForecasted",
  740. },
  741. requireTotalCount: true,
  742. pageSize: 99,
  743. });
  744. dataSource.filter([
  745. ["SiteId", "=", BWA.UserInfo.SiteId()],
  746. "and",
  747. ["nx", "=", 89],
  748. "and",
  749. ["ny", "=", 91]
  750. ]);
  751. dataSource.sort({ getter: "ForecastedDateTime", desc: true });
  752. dataSource.load()
  753. .done(function (WeatherForecasted) {
  754. if (WeatherForecasted.length != 0) {
  755. var WFTemperature_tmp = new Array();
  756. var WFHumidity_tmp = new Array();
  757. for (var i = 0; i < 16; i++) { // 예보데이터는 3시간 단위로 8포인트씩 2세트(기온, 습도)이므로
  758. if (WeatherForecasted[i].ForecastedDateTime.getFullYear() == target_date.getFullYear()
  759. && WeatherForecasted[i].ForecastedDateTime.getMonth() == target_date.getMonth()
  760. && WeatherForecasted[i].ForecastedDateTime.getDate() == target_date.getDate()
  761. && WeatherForecasted[i].Category == 'Temperature') {
  762. WFTemperature_tmp.push(WeatherForecasted[i].ForecastedValue);
  763. }
  764. if (WeatherForecasted[i].ForecastedDateTime.getFullYear() == target_date.getFullYear()
  765. && WeatherForecasted[i].ForecastedDateTime.getMonth() == target_date.getMonth()
  766. && WeatherForecasted[i].ForecastedDateTime.getDate() == target_date.getDate()
  767. && WeatherForecasted[i].Category == 'Humidity') {
  768. WFHumidity_tmp.push(WeatherForecasted[i].ForecastedValue);
  769. }
  770. }
  771. if (WFTemperature_tmp.length != 0) {
  772. $('#pointerText1').text("익일 예상 최고 기온 : " + Math.max.apply(null, WFTemperature_tmp).toFixed(2).toString() + " °C, ");
  773. $('#pointerText2').text("익일 예상 최저 기온 : " + Math.min.apply(null, WFTemperature_tmp).toFixed(2).toString() + " °C, ");
  774. }
  775. else {
  776. $('#pointerText1').text("익일 예상 최고 기온 : ? °C, ");
  777. $('#pointerText2').text("익일 예상 최저 기온 : ? °C, ");
  778. utils.toast.show("데이터가 없습니다. (익일 기상 예보 데이터 - 기온)", 'error');
  779. }
  780. if (WFHumidity_tmp.length != 0) {
  781. $('#pointerText3').text("익일 예상 최고 습도 : " + Math.max.apply(null, WFHumidity_tmp).toFixed(2).toString() + " %, ");
  782. $('#pointerText4').text("익일 예상 최저 습도 : " + Math.min.apply(null, WFHumidity_tmp).toFixed(2).toString() + " %, ");
  783. }
  784. else {
  785. $('#pointerText3').text("익일 예상 최고 습도 : ? %, ");
  786. $('#pointerText4').text("익일 예상 최저 습도 : ? %, ");
  787. utils.toast.show("데이터가 없습니다. (익일 기상 예보 데이터 - 습도)", 'error');
  788. }
  789. }
  790. else {
  791. $('#pointerText1').text("익일 예상 최고 기온 : ? °C, ");
  792. $('#pointerText2').text("익일 예상 최저 기온 : ? °C, ");
  793. $('#pointerText3').text("익일 예상 최고 습도 : ? %, ");
  794. $('#pointerText4').text("익일 예상 최저 습도 : ? %, ");
  795. utils.toast.show("데이터가 없습니다. (익일 기상 예보 데이터 - 기온, 습도)", 'error');
  796. }
  797. })
  798. .fail(function (error) {
  799. utils.toast.show(error);
  800. });
  801. var dataSource = new DevExpress.data.DataSource({
  802. store: {
  803. type: "odata",
  804. url: endpointSelector + "/BemsMonitoringPointForecastingDayAhead",
  805. },
  806. requireTotalCount: true,
  807. pageSize: 99,
  808. });
  809. dataSource.filter([
  810. ["SiteId", "=", BWA.UserInfo.SiteId()],
  811. "and",
  812. ["PropertyId", "=", 0]
  813. ]);
  814. dataSource.sort({ getter: "TargetDateTime", desc: true });
  815. dataSource.load()
  816. .done(function (PredictedDeicing) {
  817. if (PredictedDeicing.length != 0
  818. && PredictedDeicing[0].TargetDateTime.getFullYear() == target_date.getFullYear()
  819. && PredictedDeicing[0].TargetDateTime.getMonth() == target_date.getMonth()
  820. && PredictedDeicing[0].TargetDateTime.getDate() == target_date.getDate()) {
  821. $('#pointerText5').text("익일 예상 방냉량 : " + PredictedDeicing[0].ForecastedValue.toFixed(2).toString() + "%");
  822. }
  823. else {
  824. $('#pointerText5').text("익일 예상 방냉량 : 0%");
  825. utils.toast.show("데이터가 없습니다. (익일 예상 방냉량)", 'error');
  826. }
  827. })
  828. .fail(function (error) {
  829. utils.toast.show(error);
  830. });
  831. var now_15min = new Date();
  832. now_15min.setMinutes(parseInt(now_15min.getMinutes() / 15) * 15); // 15분 단위 맞춰주기 위함
  833. var now_15min_ = new Date(now_15min.getFullYear(), now_15min.getMonth(), now_15min.getDate(), now_15min.getHours(), now_15min.getMinutes(), 0);
  834. var finalDate_ = new Date(now_15min_.getFullYear(), now_15min_.getMonth(), now_15min_.getDate(), 20, 45, 0);
  835. if (now_15min.getHours() >= 21) {
  836. finalDate_ = moment(finalDate_).add(1, 'days').toDate();
  837. }
  838. // 추천 가동 시간 로드
  839. var dataSource = new DevExpress.data.DataSource({
  840. store: {
  841. type: "odata",
  842. url: endpointSelector + "/BemsIceThermalStorageSimulation",
  843. },
  844. requireTotalCount: true,
  845. pageSize: 99,
  846. });
  847. dataSource.sort({ getter: "TargetDateTime", desc: true });
  848. dataSource.filter([
  849. ["SiteId", "=", BWA.UserInfo.SiteId()],
  850. "and",
  851. ["FacilityTypeId", "=", 3],
  852. "and",
  853. ["PropertyId", "=", 16],
  854. "and",
  855. ["SimulationCase", "=", 0], // recommend
  856. "and",
  857. ["TargetDateTime", ">=", now_15min_],
  858. "and",
  859. ["TargetDateTime", "<=", finalDate_],
  860. ]);
  861. dataSource.load()
  862. .done(function (Recommended) {
  863. if (Recommended.length != 0) {
  864. var isRecommended = false;
  865. var RecommendedTime = new Date(now_15min.getFullYear(), now_15min.getMonth(), now_15min.getDate(), 0, 0, 0); // 추천 축열조 운영 모드 (제빙 모드)
  866. for (var i = 0; i < Recommended.length; i++) {
  867. if (Recommended[i].SimulationValue == 10) {
  868. RecommendedTime.settMinutes(RecommendedTime.getMinutes() + 15);
  869. isRecommended = true;
  870. }
  871. }
  872. if (isRecommended == true) {
  873. $('#RecommendedTime').text("추천 가동 시간(제빙모드) : " + RecommendedTime.getHours().toString() + "시간 " + RecommendedTime.getMinutes().toString() + "분,");
  874. }
  875. else {
  876. $('#RecommendedTime').text("추천 가동 시간 : 현재 익일 예상 방냉량 초과 저장,");
  877. }
  878. }
  879. else {
  880. $('#RecommendedTime').text("추천 가동 시간 : ?,");
  881. utils.toast.show("데이터가 없습니다. (추천 가동 시간)", 'error');
  882. }
  883. })
  884. .fail(function (error) {
  885. utils.toast.show(error);
  886. });
  887. // 냉동기1,2 전력량 로드
  888. var dataSource = new DevExpress.data.DataSource({
  889. store: {
  890. type: "odata",
  891. url: endpointSelector + "/BemsIceThermalStorageSimulation",
  892. },
  893. requireTotalCount: true,
  894. pageSize: 99,
  895. });
  896. dataSource.sort({ getter: "TargetDateTime", desc: true });
  897. dataSource.filter([
  898. ["SiteId", "=", BWA.UserInfo.SiteId()],
  899. "and",
  900. ["FacilityTypeId", "=", 2],
  901. "and",
  902. ["PropertyId", "=", 11],
  903. "and",
  904. ["SimulationCase", "=", 1], // simulation
  905. "and",
  906. ["TargetDateTime", ">=", now_15min_],
  907. "and",
  908. ["TargetDateTime", "<=", finalDate_],
  909. ]);
  910. dataSource.load()
  911. .done(function (RefPowerConsume) {
  912. if (RefPowerConsume.length != 0) {
  913. var RefPowerConsumeSum = 0; // 냉동기 전력량 합계 (시뮬레이션 모드)
  914. for (var i = 0; i < RefPowerConsume.length; i++) {
  915. RefPowerConsumeSum += RefPowerConsume[i].SimulationValue;
  916. }
  917. if (RefPowerConsumeSum == 0) {
  918. $('#RefPowerConsume').text("냉동기 계산 전력량(시뮬레이션 모드) : 0 kWh");
  919. }
  920. else {
  921. $('#RefPowerConsume').text("냉동기 계산 전력량(시뮬레이션 모드) : " + RefPowerConsumeSum.toFixed(2).toString() + " kWh");
  922. }
  923. }
  924. else {
  925. $('#RefPowerConsume').text("냉동기 계산 전력량(시뮬레이션 모드) : ?");
  926. utils.toast.show("데이터가 없습니다. (냉동기 계산 전력량)", 'error');
  927. }
  928. })
  929. .fail(function (error) {
  930. utils.toast.show(error);
  931. });
  932. }
  933. function handleViewShown() {
  934. $("#LoadPanel").dxLoadPanel({
  935. message: '로딩 중...',
  936. showIndicator: true,
  937. visible: false
  938. });
  939. $("#LoadPanel").dxLoadPanel('instance').option('visible', true);
  940. visibleHourGlassPopup(true);
  941. // 초기 화면에서 기존 사용자 제어변수 삭제
  942. RemoveData(3, 4478, 16, 1); // 운전모드
  943. RemoveData(2, 4479, 15, 1); // 냉동기1 상태
  944. RemoveData(2, 4480, 15, 1); // 냉동기2 상태
  945. RemoveData(2, 4479, 11, 1); // 냉동기1 전력량
  946. RemoveData(2, 4480, 11, 1); // 냉동기2 전력량
  947. RemoveData(3, 4478, 2, 1); // 축열량
  948. if (initialized === false) {
  949. setTimeout(function () {
  950. chart = chart(BWA.ChartOptions.SimulatorIceStorage.getChartOptions());
  951. initialized = true;
  952. // 날짜 초기화 (오늘)
  953. timeBoxForSearch.setDefaultDateToday();
  954. handleSearchInSearchView();
  955. }, 4000);
  956. }
  957. else {
  958. setTimeout(function () {
  959. // 날짜 초기화 (오늘)
  960. timeBoxForSearch.setDefaultDateToday();
  961. handleSearchInSearchView();
  962. // 저장 변수 초기화
  963. initDate_asSave = new Array(new Date(initialDate), new Date(initialDate), new Date(initialDate), new Date(initialDate), new Date(initialDate));
  964. finalDate_asSave = new Array(new Date(finalDate), new Date(finalDate), new Date(finalDate), new Date(finalDate), new Date(finalDate));
  965. operationMode_asSave = new Array(null, null, null, null, null);
  966. ref1Status_asSave = new Array(null, null, null, null, null);
  967. ref2Status_asSave = new Array(null, null, null, null, null);
  968. }, 4000);
  969. }
  970. timer = setInterval(function () {
  971. //alert('timer'); // For Debugging
  972. var now = new Date();
  973. //if ((now.getMinutes() == 1 && now.getSeconds() == 30) || (now.getMinutes() == 5 && now.getSeconds() == 30)) {
  974. if (now.getMinutes() % 15 == 2 && now.getSeconds() == 30) {
  975. handleSearchInSearchView();
  976. }
  977. }, 1000);
  978. $("#UserCfgBtn").dxButton({
  979. text: "시뮬레이터 변수 설정",
  980. onClick: function () {
  981. visibleConfigPopup(true);
  982. }
  983. });
  984. }
  985. function handleViewHidden() {
  986. $SearchView.visibleObservable(false); // hcLee 2015 03 23
  987. visibleConfigPopup(false);
  988. clearInterval(timer); // hcLee 2015 06 12
  989. }
  990. function RemoveData(facilityTypeId, facilityCode, propertyId, simulationCase) {
  991. var now_15min = new Date();
  992. now_15min.setMinutes(parseInt(now_15min.getMinutes() / 15) * 15); // 15분 단위 맞춰주기 위함
  993. var targetDate_ = new Date(now_15min.getFullYear(), now_15min.getMonth(), now_15min.getDate(), now_15min.getHours(), now_15min.getMinutes(), 0);
  994. var finalDate_ = new Date(now_15min.getFullYear(), now_15min.getMonth(), now_15min.getDate(), 20, 45, 0);
  995. if (now_15min.getHours() >= 21) {
  996. finalDate_ = moment(finalDate_).add(1, 'days').toDate();
  997. }
  998. BemsIceThermalStorageDataSource.filter([
  999. ["SiteId", "=", BWA.UserInfo.SiteId()],
  1000. "and",
  1001. ["FacilityCode", "=", facilityCode],
  1002. "and",
  1003. ["PropertyId", "=", propertyId],
  1004. "and",
  1005. ["SimulationCase", "=", simulationCase],
  1006. "and",
  1007. ["TargetDateTime", ">=", targetDate_],
  1008. "and",
  1009. ["TargetDateTime", "<=", finalDate_]
  1010. ]);
  1011. BemsIceThermalStorageDataSource.load()
  1012. .done(function (result) {
  1013. var store = new DevExpress.data.ODataStore({
  1014. url: endpointSelector + "/BemsIceThermalStorageSimulation",
  1015. key: ["SiteId", "FacilityCode", "PropertyId", "CreatedDateTime", "TargetDateTime", "SimulationCase"],
  1016. keyType: {
  1017. SiteId: "Int32", FacilityCode: "Int32", PropertyId: "Int32", CreatedDateTime: "DateTime", TargetDateTime: "DateTime", SimulationCase: "Int32"
  1018. }
  1019. });
  1020. if (result.length != 0) {
  1021. for (var i = 0; i < result.length; i++) {
  1022. var removeData = {
  1023. SiteId: result[i].SiteId(),
  1024. FacilityTypeId: result[i].FacilityTypeId(),
  1025. FacilityCode: result[i].FacilityCode(),
  1026. PropertyId: result[i].PropertyId(),
  1027. CreatedDateTime: new Date(result[i].CreatedDateTime()),
  1028. TargetDateTime: new Date(result[i].TargetDateTime()),
  1029. SimulationValue: result[i].SimulationValue(),
  1030. SimulationCase: result[i].SimulationCase()
  1031. };
  1032. store.remove(removeData).done(function (values, key) {
  1033. })
  1034. .fail(function (error) {
  1035. utils.toast.show(error, 'error');
  1036. });
  1037. }
  1038. }
  1039. });
  1040. }
  1041. // 다른 페이지 갔다 들어오면 시뮬레이션 데이터 및 팝업 초기화
  1042. function handleViewShowing() {
  1043. SetPointer();
  1044. initializedforPopUp = false;
  1045. CurrntRowStatusAsSave = 1;
  1046. }
  1047. function refreshList() {
  1048. }
  1049. var searchViewOptions = {
  1050. searchViewItems: [
  1051. //{ id: 'TimeTypeId', defaultValue: 0, value: timeTypeIdForSearch, dataSource: timeTypesForSearch },
  1052. //{ id: 'DateForHour', type: 'dateRange', isOnlyDate: true },
  1053. ],
  1054. };
  1055. function handleSearchInSearchView() {
  1056. $("#LoadPanel").dxLoadPanel('instance').option('visible', true);
  1057. visibleHourGlassPopup(true);
  1058. var dataArray = [];
  1059. dataArrayforPopup = [];
  1060. var date = timeBoxForSearch.getDate();
  1061. var start_date = moment(date.startDate).add(-3, 'hours').toDate();
  1062. var end_date = moment(date.endDate).add(-3, 'hours').toDate();
  1063. SetPointer();
  1064. var commonParameters = {
  1065. TimeIntervalType: $Code.TimeIntervalType.QUARTERMIN,
  1066. StartDate: start_date,
  1067. EndDate: end_date
  1068. };
  1069. var IceThermalStorageParameters_obs = {
  1070. FacilityTypeId: 3,
  1071. FacilityCode: 4478,
  1072. PropertyId: 2,
  1073. SimulationCase: 0 // observed and recommended schedule
  1074. };
  1075. var IceThermalStorageParameters_sim = {
  1076. FacilityTypeId: 3,
  1077. FacilityCode: 4478,
  1078. PropertyId: 2,
  1079. SimulationCase: 1 // simulated schedule
  1080. };
  1081. var now_sub = new Date();
  1082. now_sub.setMinutes(now_sub.getMinutes() - 15); // 15분까지 데이터 확인 가능
  1083. $.when(
  1084. iceThermalStorage_SimulationValueGet.apiGet(_.extend(IceThermalStorageParameters_obs, commonParameters)),
  1085. iceThermalStorage_SimulationValueGet.apiGet(_.extend(IceThermalStorageParameters_sim, commonParameters))
  1086. ).done(function (Candidate_obs, Candidate_sim) {
  1087. if (Candidate_obs.length == 0) {
  1088. utils.toast.show("[BemsIceThermalStorageSimulation] 데이터가 없습니다.", 'error');
  1089. $("#LoadPanel").dxLoadPanel('instance').option('visible', false);
  1090. }
  1091. else {
  1092. if (Candidate_obs.length != 0) {
  1093. _.each(Candidate_obs[0][0], function (x) {
  1094. if (moment(x.DateTime).toDate() < now_sub) {
  1095. dataArray.push({
  1096. DateTime: moment(x.DateTime).toDate(),
  1097. ObservedValue: x.Value
  1098. });
  1099. }
  1100. });
  1101. // 2017.09.08 : 그리드 도표 작업 : 팝업창 추가
  1102. _.each(Candidate_obs[0][0], function (x) {
  1103. if (moment(x.DateTime).toDate() < now_sub) {
  1104. dataArrayforPopup.push({
  1105. DateTime: BWA.Chart.getCustermTimeArgumentAxisString($Code.TimeType.QUARTERMIN, moment(x.DateTime).toDate()),
  1106. Value: x.Value,
  1107. Case: 'Obs'
  1108. });
  1109. }
  1110. });
  1111. }
  1112. if (Candidate_sim.length != 0) {
  1113. _.each(Candidate_sim[0][0], function (x) {
  1114. if (moment(x.DateTime).toDate() >= now_sub) {
  1115. dataArray.push({
  1116. DateTime: moment(x.DateTime).toDate(),
  1117. SimulationValue: x.Value
  1118. });
  1119. }
  1120. });
  1121. // 2017.09.08 : 그리드 도표 작업 : 팝업창 추가
  1122. _.each(Candidate_sim[0][0], function (x) {
  1123. if (moment(x.DateTime).toDate() >= now_sub) {
  1124. dataArrayforPopup.push({
  1125. DateTime: BWA.Chart.getCustermTimeArgumentAxisString($Code.TimeType.QUARTERMIN, moment(x.DateTime).toDate()),
  1126. Value: x.Value,
  1127. Case: 'Sim'
  1128. });
  1129. }
  1130. });
  1131. }
  1132. // 2017.09.08 : 그리드 도표 작업 : 팝업창 추가
  1133. var options = BWA.ChartOptions.SimulatorIceStorage.getSeriesOptions();
  1134. if (!_.isNull(start_date) && !_.isNull(end_date)) {
  1135. options.argumentAxis.min = start_date;
  1136. options.argumentAxis.max = end_date;
  1137. }
  1138. chart().option('argumentAxis', null); // 2015 05 21 결국 이 코드가 필요 함 (시간 축 에러 해결)
  1139. options.dataSource = dataArray;
  1140. chart().option(options);
  1141. }
  1142. $("#LoadPanel").dxLoadPanel('instance').option('visible', false);
  1143. visibleHourGlassPopup(false);
  1144. })
  1145. .fail(function (error) {
  1146. utils.toast.show("데이터를 불러오는데 실패 하였습니다.", 'error');
  1147. $("#LoadPanel").dxLoadPanel('instance').option('visible', false);
  1148. visibleConfigPopup(false);
  1149. $("#LoadPanel").dxLoadPanel('instance').option('visible', false);
  1150. visibleHourGlassPopup(false);
  1151. });
  1152. }
  1153. // 2017.09.08 : 그리드 도표 작업 : 팝업창 추가
  1154. function DataGridPopup_ButtonClick() {
  1155. DataGridPopup_Visible(true);
  1156. }
  1157. function handlePopupShown() {
  1158. // 도표 컬럼명 업데이트
  1159. viewModel.SimulatorIceStorageDataGridOptions.columns[0].caption = "날짜";
  1160. viewModel.SimulatorIceStorageDataGridOptions.columns[1].caption = "실/계산 축열량";
  1161. // 도표 데이터소스 업데이트
  1162. $("#SimulatorIceStorageDataGrid_Container").dxDataGrid("instance").option("dataSource", dataArrayforPopup);
  1163. // 도표 팝업창 갱신
  1164. //DataGridPopup_Visible(true);
  1165. }
  1166. // Box Initialize
  1167. function BoxInitialize(row_num, initial_Date, final_Date) {
  1168. $("#InitialDate" + (row_num).toString()).dxDateBox({
  1169. value: initial_Date,
  1170. maxZoomLevel: 'month',
  1171. formatString: "yyyy-MM-dd",
  1172. onValueChanged: function (data) {
  1173. initial_Date.setFullYear(data.value.getFullYear());
  1174. initial_Date.setMonth(data.value.getMonth());
  1175. initial_Date.setDate(data.value.getDate());
  1176. $("#InitialDate" + (row_num).toString()).dxDateBox('instance').option('value', initial_Date);
  1177. $("#InitialTime" + (row_num).toString()).dxDateBox('instance').option('value', initial_Date);
  1178. }
  1179. });
  1180. $("#InitialTime" + (row_num).toString()).dxDateBox({
  1181. value: initial_Date,
  1182. format: "time",
  1183. formatString: "HH:mm",
  1184. onValueChanged: function (data) {
  1185. initial_Date.setHours(data.value.getHours());
  1186. initial_Date.setMinutes(data.value.getMinutes());
  1187. $("#InitialDate" + (row_num).toString()).dxDateBox('instance').option('value', initial_Date);
  1188. $("#InitialTime" + (row_num).toString()).dxDateBox('instance').option('value', initial_Date);
  1189. }
  1190. });
  1191. $("#FinalDate" + (row_num).toString()).dxDateBox({
  1192. value: final_Date,
  1193. maxZoomLevel: 'month',
  1194. formatString: "yyyy-MM-dd",
  1195. min: new Date(moment().add(-1, 'd')),
  1196. max: new Date(moment().add(1, 'd')),
  1197. onValueChanged: function (data) {
  1198. final_Date.setFullYear(data.value.getFullYear());
  1199. final_Date.setMonth(data.value.getMonth());
  1200. final_Date.setDate(data.value.getDate());
  1201. $("#InitialDate" + (row_num).toString()).dxDateBox('instance').option('value', initial_Date);
  1202. $("#InitialTime" + (row_num).toString()).dxDateBox('instance').option('value', initial_Date);
  1203. $("#FinalDate" + (row_num).toString()).dxDateBox('instance').option('value', final_Date);
  1204. $("#FinalTime" + (row_num).toString()).dxDateBox('instance').option('value', final_Date);
  1205. }
  1206. });
  1207. $("#FinalTime" + (row_num).toString()).dxDateBox({
  1208. value: final_Date,
  1209. format: "time",
  1210. formatString: "HH:mm",
  1211. onValueChanged: function (data) {
  1212. final_Date.setHours(data.value.getHours());
  1213. final_Date.setMinutes(data.value.getMinutes());
  1214. $("#InitialDate" + (row_num).toString()).dxDateBox('instance').option('value', initial_Date);
  1215. $("#InitialTime" + (row_num).toString()).dxDateBox('instance').option('value', initial_Date);
  1216. $("#FinalDate" + (row_num).toString()).dxDateBox('instance').option('value', final_Date);
  1217. $("#FinalTime" + (row_num).toString()).dxDateBox('instance').option('value', final_Date);
  1218. }
  1219. });
  1220. $("#OperationMode" + (row_num).toString()).dxSelectBox({
  1221. placeholder: "운전 모드",
  1222. dataSource: treeOperationMode,
  1223. displayExpr: "text",
  1224. valueExpr: "id",
  1225. onValueChanged: function (data) {
  1226. $("#OperationMode" + (row_num).toString()).dxSelectBox('instance').option('value', data.value);
  1227. // OFF, 축단운전시 냉동기 모두 OFF
  1228. if (data.value == 0 || data.value == 2) {
  1229. $("#Ref1_Status" + (row_num).toString()).dxSwitch('instance').option('value', false);
  1230. $("#Ref2_Status" + (row_num).toString()).dxSwitch('instance').option('value', false);
  1231. $("#Ref1_Status" + (row_num).toString()).dxSwitch("instance").option('disabled', true);
  1232. $("#Ref2_Status" + (row_num).toString()).dxSwitch("instance").option('disabled', true);
  1233. }
  1234. else {
  1235. $("#Ref1_Status" + (row_num).toString()).dxSwitch("instance").option('disabled', false);
  1236. $("#Ref2_Status" + (row_num).toString()).dxSwitch("instance").option('disabled', false);
  1237. }
  1238. }
  1239. });
  1240. $("#Ref1_Status" + (row_num).toString()).dxSwitch({
  1241. onText: $G('use'),
  1242. offText: $G('nonUse'),
  1243. onValueChanged: function (data) {
  1244. $("#Ref1_Status" + (row_num).toString()).dxSwitch('instance').option('value', data.value);
  1245. }
  1246. });
  1247. $("#Ref2_Status" + (row_num).toString()).dxSwitch({
  1248. onText: $G('use'),
  1249. offText: $G('nonUse'),
  1250. onValueChanged: function (data) {
  1251. $("#Ref2_Status" + (row_num).toString()).dxSwitch('instance').option('value', data.value);
  1252. }
  1253. });
  1254. // 초기 시작 시점은 고정
  1255. $("#InitialDate" + (row_num).toString()).dxDateBox("instance").option('disabled', true);
  1256. $("#InitialTime" + (row_num).toString()).dxDateBox("instance").option('disabled', true);
  1257. $("#OperationMode" + (row_num).toString()).dxSelectBox('instance').option('value', null);// 운전 모드 클리어
  1258. $("#Ref1_Status" + (row_num).toString()).dxSwitch('instance').option('value', false);// 냉동기1 운전 모드 클리어
  1259. $("#Ref2_Status" + (row_num).toString()).dxSwitch('instance').option('value', false);// 냉동기2 운전 모드 클리어
  1260. initDate_prev[row_num - 1] = new Date(initial_Date);
  1261. finalDate_prev[row_num - 1] = new Date(final_Date);
  1262. operationMode_prev[row_num - 1] = null;
  1263. ref1Status_prev[row_num - 1] = false;
  1264. ref2Status_prev[row_num - 1] = false;
  1265. return 0;
  1266. }
  1267. var viewModel = $.extend(BWA.CommonView.create(
  1268. params, viewInfo, searchViewOptions, ko.observable(null), handleViewShown, null,
  1269. handleSearchInSearchView), {
  1270. refreshList: refreshList,
  1271. viewShowing: handleViewShowing,
  1272. viewHidden: handleViewHidden, // hcLee 2015 03 23
  1273. //viewDisposing: handleViewHidden, // hcLee 2015 03 23
  1274. //locationEnableForSearch: locationEnableForSearch,
  1275. // 그리드 도표 작업 : 팝업창 추가
  1276. SimulatorIceStorageDataGridPopup_ButtonClicked: DataGridPopup_ButtonClick
  1277. // 그리드 도표 작업 : 팝업창 추가
  1278. });
  1279. viewModel.SimulatorIceStoragePopupOptions = {
  1280. width: 1500,//1250,
  1281. height: 350,
  1282. visible: visibleConfigPopup,
  1283. dragEnabled: true,
  1284. shading: true,
  1285. closeOnOutsideClick: false,
  1286. shadingColor: 'transparent',
  1287. showTitle: true,
  1288. //title: "사용자 시뮬레이터 변수 설정",
  1289. showCloseButton: true,
  1290. onShowing: function () {
  1291. if (initializedforPopUp === false) {
  1292. setTimeout(function () {
  1293. var initialDate_ = new Date();
  1294. initialDate_.setMinutes((parseInt(initialDate_.getMinutes() / 15)) * 15); // 15분 단위 맞춰주기 위함
  1295. initialDate_.setSeconds(0);
  1296. var finalDate_ = new Date(finalDate);
  1297. for (var i = 0; i < 5; i++) {
  1298. BoxInitialize(i + 1, initialDate_, finalDate_);
  1299. }
  1300. InitializedTemplate();
  1301. InitializedData();
  1302. initializedforPopUp = true;
  1303. }, 100);
  1304. }
  1305. else {
  1306. InitializedTemplate();
  1307. }
  1308. },
  1309. onShown: function () {
  1310. },
  1311. onHidden: function () {
  1312. }
  1313. }
  1314. // 2020.08.03 : 그리드 도표 작업 : 팝업창 추가
  1315. // 그래프 도표 팝업창
  1316. viewModel.SimulatorIceStorageDataGridPopupOptions = {
  1317. width: '480px',
  1318. height: '830px', // cyim 2017.05.30 : 테스트 결과 Devextreme 버그임. px 로 지정하면 초기 출력시 정확하게 가운데에 있지만, auto 설정시 화면아래에 위치하게 됨
  1319. contentTemplate: "content",
  1320. showTitle: true,
  1321. title: "도표",
  1322. visible: DataGridPopup_Visible,
  1323. dragEnabled: true,
  1324. closeOnOutsideClick: true,
  1325. shownAction: handlePopupShown,
  1326. animation: window.utils.popup.createAnimation(),
  1327. shading: false
  1328. };
  1329. // 2020.08.03 : 그리드 도표 작업 : 팝업창 추가
  1330. // 2020.08.03 : 그리드 도표 작업 : 팝업창 추가
  1331. viewModel.SimulatorIceStorageDataGridOptions = {
  1332. dataSource: dataArrayforPopup,
  1333. columns: [
  1334. { dataField: 'DateTime', width: '40%', alignment: 'center' },// dataType: 'date', format: 'yyyy-MM-dd HH:mm' },
  1335. { dataField: 'Value', width: '60%', alignment: 'center', format: 'fixedPoint', precision: 2 }
  1336. //{ dataField: 'ObservedValue', width: '30%', alignment: 'center', format: 'fixedPoint', precision: 2 },
  1337. //{ dataField: 'SimulationValue', width: '30%', alignment: 'center', format: 'fixedPoint', precision: 2 }
  1338. ],
  1339. rowPrepared: function (rowElement, rowInfo) {
  1340. if (rowInfo.rowType == 'data') {
  1341. var data = rowInfo.data;
  1342. if (data['Case'] == 'Sim') {
  1343. //rowElement.css('background-color', 'rgba(255,0,0,0.1)');
  1344. rowElement.css('background-color', 'rgba(153,102,255,0.1)');
  1345. }
  1346. }
  1347. },
  1348. // 엑셀 출력
  1349. "export": {
  1350. enabled: true,
  1351. fileName: '축열량 시뮬레이션 결과'
  1352. }
  1353. };
  1354. /// 2020.08.03 : 그리드 도표 작업 : 팝업창 추가
  1355. viewModel.simulatoricestoragePopupToolbarItems = simulatoricestoragePopupToolbarItems;
  1356. viewModel.timeBoxForSearch = timeBoxForSearch;
  1357. viewModel.handlePopupButtonAdd = handlePopupButtonAdd;
  1358. viewModel.handlePopupButtonDelete = handlePopupButtonDelete;
  1359. viewModel.isSecondRow = isSecondRow;
  1360. viewModel.isThirdRow = isThirdRow;
  1361. viewModel.isFourthRow = isFourthRow;
  1362. viewModel.isFifthRow = isFifthRow;
  1363. viewModel.visibleHourGlassPopup = visibleHourGlassPopup;
  1364. viewModel.isEditModeInPopup = isEditModeInPopup;
  1365. return viewModel;
  1366. };