1/* å ±ç¨js */ 2//æ¯å¦é¡¯ç¤ºconsole.log 3var _showConsole = true; 4 5/** 6 * 妿å³å ¥å¼çº nullãempty æ undefined, ååå³ true; åä¹, åå³ false 7 * @param {any} obj 8 */ 9this.isNullOrEmpty = function (obj) { 10 11 // null and undefined are "empty" 12 if (obj == null) return true; 13 if (typeof obj == undefined) return true; 14 15 // Assume if it has a length property with a non-zero value 16 // that that property is correct. 17 if (obj.length > 0) return false; 18 if (obj.length === 0) return true; 19 20 // Otherwise, does it have any properties of its own? 21 // Note that this doesn't handle 22 // toString and valueOf enumeration bugs in IE < 9 23 for (var key in obj) { 24 if (hasOwnProperty.call(obj, key)) return false; 25 } 26 27 // Assume if it is time 28 if (new Date(obj)) return false; 29 30 return true; 31}; 32 33/** 34 * å¯å¨Javascriptä¸ä½¿ç¨å¦åC#ä¸çstring.format 35 * ä½¿ç¨æ¹å¼ : var fullName = String.format('Hello. My name is {0} {1}.', 'FirstName', 'LastName'); 36 */ 37String.format = function () { 38 var s = arguments[0]; 39 if (s == null) return ""; 40 for (var i = 0; i < arguments.length - 1; i++) { 41 var reg = getStringFormatPlaceHolderRegEx(i); 42 s = s.replace(reg, (arguments[i + 1] == null ? "" : arguments[i + 1])); 43 } 44 return cleanStringFormatResult(s); 45} 46 47/** 48 * å¯å¨Javascriptä¸ä½¿ç¨å¦åC#ä¸çstring.format (å°jQuery Stringçæ´å æ¹æ³) 49 * ä½¿ç¨æ¹å¼ : var fullName = 'Hello. My name is {0} {1}.'.format('FirstName', 'LastName'); 50 */ 51String.prototype.format = function () { 52 var txt = this.toString(); 53 for (var i = 0; i < arguments.length; i++) { 54 var exp = getStringFormatPlaceHolderRegEx(i); 55 txt = txt.replace(exp, (arguments[i] == null ? "" : arguments[i])); 56 } 57 return cleanStringFormatResult(txt); 58} 59 60 61 62/** 63 * å¯å¨Javascriptä¸ä½¿ç¨padleftå·¦å´è£åå (å°jQuery Stringçæ´å æ¹æ³) 64 * ä½¿ç¨æ¹å¼ : padleft(a, '0', 2); 65 * @param {string} str åå串 66 * @param {string}
66 char è¦æå ¥çåå 67 * @param {int} number ç¸½å ±é·åº¦ 68 * @returns {string} è£åå å®çå串 69 */ 70function padleft(str, char, number) { 71 var ret = ""; 72 for (var i = 0; i < number; i++) { 73 ret += char; 74 } 75 ret += str; 76 ret = ret.substr(ret.length - number, number); 77 78 return ret; 79} 80 81 82 83//èªè¨console.log 84function Console(value) { 85 if (_showConsole) { 86 console.log(value); 87 } 88} 89 90/** 91 * èªè¨è¨æ¯å½è·³è¨æ¯è¦çª 92 * @param {string} msg 93 */ 94function SuccessMessage(msg) { 95 $.alert({ 96 title: "è¨æ¯", 97 type: "green", 98 content: msg, 99 theme: "bootstrap", 100 icon: 'glyphicon glyphicon-ok-sign', 101 buttons: { 102 close: { 103 text: "éé" 104 } 105 } 106 }); 107} 108 109/** 110 * èªè¨è¨æ¯å½è·³è¨æ¯è¦çª 111 * @param {string} msg 112 * @param {object} call 113 */ 114function InfoMessage(msg, call) { 115 116 if (call !== undefined) { 117 $.alert({ 118 title: "è¨æ¯", 119 type: "blue", 120 content: msg, 121 theme: "bootstrap", 122 icon: 'glyphicon glyphicon-info-sign', 123 buttons: { 124 close: { 125 text: "éé", 126 action: function () { 127 call(); 128 } 129 } 130 } 131 }); 132 } 133 else { 134 $.alert({ 135 title: "è¨æ¯", 136 type: "blue", 137 content: msg, 138 theme: "bootstrap", 139 icon: 'glyphicon glyphicon-info-sign', 140 buttons: { 141 close: { 142 text: "éé" 143 } 144 } 145 }); 146 } 147 148 149} 150 151/** 152 * èªè¨è¨æ¯å½è·³è¨æ¯è¦çª 153 * @param {string} msg 154 */ 155function ErrorMessage(msg) { 156 $.alert({ 157 title: "é¯èª¤", 158 type: "red", 159 content: msg, 160 theme: "bootstrap", 161 icon: 'glyphicon glyphicon-exclamation-sign', 162 buttons: { 163 close: { 164 text: "éé" 165 } 166 } 167 }); 168 169 //$("#msgModal").find("#msgContent").html(msg); 170 //$("#msgModal").modal("show"); 171} 172 173/** 174 * èªè¨è¨æ¯å½è·³ç¢ºèªè¦çª 175 * @param {string} msg 176 * @param {object} call1 177 * @param {object} call2 178 */ 179function ConfirmMessage(msg, call1, call2) { 180 $.confirm({ 181 title: '確èª', 182 content: msg, 183 icon: 'glyphicon glyphicon-question-sign', 184 buttons: { 185 confirm: { 186 text: '確å®', 187 btnClass: 'btn-primary', 188 action: function () { 189 call1(); 190 } 191 }, 192 cancel: { 193 text: 'åæ¶', 194 action: function () { 195 Console(call2); 196 197 if (call2 !== undefined) 198 call2(); 199 200 } 201 } 202 } 203 }); 204 205} 206 207/** 208 * åå³å¤é¸çå¤ 209 * @param {object} value 210 */ 211function getfSelectVal(value) { 212 Console(value); 213 var r = ''; 214 if (value !== null) 215 r = value.join(); 216 return r; 217} 218 219/** 220 * è¨å®ç¶è·æéåç¨/åç¨ 221 * @param {string} value 222 */ 223function setManagerBtn(value) { 224 Console("setManagerBtn"); 225 Console(value); 226 if (value=="True") { 227 $("#btn_Add").removeAttr("disabled"); 228 $("#btn_Save").removeAttr("disabled"); 229 } 230 else { 231 $("#btn_Add").attr("disabled", "disabled"); 232 $("#btn_Save").attr("disabled", "disabled"); 233 } 234} 235 236/** 237 * è¨å®æ»é¼ 滾輪åç¨Y/åç¨N 238 * @param {string} enabled 239 */ 240function setMouseWheelEnabled(enabled) { 241 if (checkBrowserIE()) { 242 if (enabled == "Y") { 243 $(window).unbind('wheel'); 244 } 245 else { 246 //å·å°top 247 $('html, body').scrollTop(0); 248 $(window).on('wheel', function () { 249 return false; 250 }); 251 } 252 } 253 254 255} 256 257/** 258 * 檢æ¥èº«åèè碼çé輯è¦å, ééåå³true, 失æåå³false 259 * @param {string} value 260 */ 261function checkIDRule(value) { 262 value = value.toUpperCase(); 263 var resultL1 = value.match(/[A-Z]{1}[1-2]{1}[0-9]{8}/g); 264 265 if (resultL1 !== null) { 266 var esum = 0; 267 var nsum = 0; 268 var count = 0; 269 var city = ["A", "B", "C", "D", "E", "F", "G", "H", "J", "K", "L", "M", "N", "P", "Q", "R", "S", "T", "U", "V", "X", "Y", "W", "Z", "I", "O"]; 270 for (var index = 0; index < city.length; index++) { 271 if (value.substr(0, 1) === city[index]) { 272 //console.log(city[index]); 273 index += 10; 274 esum = ((index % 10) * 9) + Math.floor(index / 10); 275 break; 276 } 277 } 278 for (var i = 1; i < 9; i++) { 279 nsum += (value.substr(i, 1) - 0) * (9 - i); 280 } 281 count = esum + nsum + (value.substr(9, 1) - 0); 282 283 if ((count % 10) === 0) { 284 return true; 285 } 286 else { 287 return false; 288 } 289 } 290 else { 291 return false; 292 } 293} 294 295/** 296 * 檢æ¥çè¦½å¨æ¯å¦IE, æ¯åå³true, å¦åå³false 297 */ 298function checkBrowserIE() { 299 var ua = window.navigator.userAgent; 300 var msie = ua.indexOf("MSIE "); 301 if (msie > 0 || !!navigator.userAgent.match(/Trident.*rv\:11\./)) { 302 return true; 303 } 304 else { 305 return false; 306 } 307} 308 309//======================================================================================= 310//bootstrap table èªè¨æåº 311//======================================================================================= 312/** 313 * èæ¸åèçèªè¨æåº(æ·åå串ä¸çæ¸åå奿åºï¼å æç¬¬ä¸ååæç¬¬äºï¼ä»¥æ¤é¡æ¨) 314 * @param {string} x 315 * @param {string} y 316 */ 317function customSort(x, y) { 318 var ax = getNumFromStr(x); 319 var ay = getNumFromStr(y); 320 321 322 if (ax !== null && ay !== null) { 323 if (ax.length == ay.length) { 324 for (var i = 0; i < ax.length; i++) { 325 var axi = ax[i] - 0; 326 var ayi = ay[i] - 0; 327 328 if (axi > ayi) { 329 return 1; 330 } 331 else if (axi < ayi) { 332 return -1; 333 } 334 335 336 } 337 return 0; 338 } 339 else if (ax.length > ay.length) { 340 return 1; 341 } 342 else { 343 return -1; 344 } 345 } 346 else if (ax == null) { 347 return -1; 348 } 349 else { 350 return 1; 351 } 352 353 //return 1; 354} 355/** 356 * æ·ååºåä¸²çæ¸å 357 * @param {string} str 358 */ 359function getNumFromStr(str) { 360 return str.match(/\d+/g); 361} 362 363//======================================================================================= 364//æ¥ææé 365//======================================================================================= 366/** 367 * è¨å®æéçå ä»¶ 368 * @param {any} id -æ¬ä½å稱 369 */ 370function setTimeCtrl(id) { 371 var d1 = $.Deferred(); 372 $("#txt_" + id).hide(); 373 //hour 374 var divHour = $("<div>").addClass("input-group"); 375 var hour = $("<select>").attr("id", "sel_Hour" + id).addClass("form-control").addClass("form-time"); 376 for (var i = 0; i < 24; i++) { 377 hour.append($("<option>").val(padleft(i, '0', 2)).text(padleft(i, '0', 2))); 378 } 379 var spanHour = $("<span>").html("æ").addClass("input-group-addon"); 380 381 divHour.append(hour).append(spanHour); 382 $("#txt_" + id).after(divHour); 383 //min 384 var divMin = $("<div>").addClass("input-group"); 385 var min = $("<select>").attr("id", "sel_Min" + id).addClass("form-control").addClass("form-time"); 386 for (i = 0; i < 60; i++) { 387 min.append($("<option>").val(padleft(i, '0', 2)).text(padleft(i, '0', 2))); 388 } 389 var spanMin = $("<span>").html("å").addClass("input-group-addon"); 390 391 divMin.append(min).append(spanMin);
392 divHour.after(divMin); 393 //sec 394 var divSec = $("<div>").addClass("input-group"); 395 var sec = $("<select>").attr("id", "sel_Sec" + id).addClass("form-control").addClass("form-time"); 396 for (i = 0; i < 60; i++) { 397 sec.append($("<option>").val(padleft(i, '0', 2)).text(padleft(i, '0', 2))); 398 } 399 var spanSec = $("<span>").html("ç§").addClass("input-group-addon"); 400 401 divSec.append(sec).append(spanSec); 402 divMin.after(divSec); 403} 404/** 405 * æéè¨å®æé è¨å¤ 406 * @param {any} id -æ¬ä½å稱 407 * @param {string} type -æéèµ·è¿: Sèµ·/Eè¿ 408 */ 409function setTimeDefault(id, type) { 410 if (type == "S") { 411 $("#div_Query").find("#sel_Hour" +id).val("00"); 412 $("#div_Query").find("#sel_Min" + id).val("00"); 413 $("#div_Query").find("#sel_Sec" + id).val("00"); 414 } 415 if (type == "E") { 416 Console("go setTimeDefault E"); 417 $("#div_Query").find("#sel_Hour" + id).val("23"); 418 $("#div_Query").find("#sel_Min" + id).val("59"); 419 $("#div_Query").find("#sel_Sec" + id).val("59"); 420 } 421} 422 423/** 424 * å徿éçå¤(æååæ ) 425 * @param {any} id -æ¬ä½å稱 426 */ 427function getTimeVal(id) { 428 var ret = ""; 429 ret = $("#sel_Hour" + id).val() + ":" + $("#sel_Min" + id).val() + ":" + $("#sel_Sec" + id).val(); 430 $("#txt_" + id).val(ret); 431 return ret; 432} 433 434/** 435 * åå¾ å°æçå ä»¶ 436 * @param {any} id -æ¬ä½å稱 437 */ 438function setHourCtrl(id) { 439 for (var i = 0; i < 24; i++) { 440 $("#" + id).append($("<option>").val(padleft(i, '0', 2)).text(padleft(i, '0', 2))); 441 } 442} 443/** 444 * åå¾ åç§çå ä»¶ 445 * @param {any} id -æ¬ä½å稱 446 */ 447function setMinSecCtrl(id) { 448 for (var i = 0; i < 60; i++) { 449 $("#" + id).append($("<option>").val(padleft(i, '0', 2)).text(padleft(i, '0', 2))); 450 } 451} 452 453 454/** 455 * åå¾ æä»½çå ä»¶ 456 * @param {any} name -æ¬ä½å稱 457 */ 458function setMonthCtrl(name) { 459 460 for (var i = 1; i < 13; i++) { 461 $("#" + name).append($("<option>").val(i).text(i)); 462 } 463 464} 465 466/** 467 * è¨å®æ¥æå¯å 許çæå¤§æ¥ 468 */ 469function setCustomDayCrl() { 470 $("#sel_YearPrefix").change(function () { 471 if ($("#txt_Year").val() != "" && $("#sel_Month").val() != "") { 472 var maxday = new Date($("#sel_YearPrefix").val() - 0 + $("#txt_Year").val() - 0 + 1911, $("#sel_Month").val() - 0, 0).getDate(); 473 $("#txt_Day").prop("max", maxday); 474 Console(maxday); 475 } 476 }); 477 $("#txt_Year").change(function () { 478 if ($("#txt_Year").val() != "" && $("#sel_Month").val() != "") { 479 var maxday = new Date($("#sel_YearPrefix").val() - 0 + $("#txt_Year").val() - 0 + 1911, $("#sel_Month").val() - 0, 0).getDate(); 480 $("#txt_Day").prop("max", maxday); 481 Console(maxday); 482 } 483 }); 484 $("#sel_Month").change(function () { 485 if ($("#txt_Year").val() != "" && $("#sel_Month").val() != "") { 486 var maxday = new Date($("#sel_YearPrefix").val() - 0 + $("#txt_Year").val() - 0 + 1911, $("#sel_Month").val() - 0, 0).getDate(); 487 $("#txt_Day").prop("max", maxday); 488 Console(maxday); 489 } 490 }); 491} 492//======================================================================================= 493//ç §çç¸é 494//======================================================================================= 495/** 496 * ç §çäºä»¶ 497 * @param {string} url -ImageçPartialView 498 */ 499function imageEvent(url) { 500 $("#div_Image0").click(function () { 501 $.confirm({ 502 title: 'ç §ç', 503 columnClass: 'medium', 504 content: url, 505 icon: 'glyphicon glyphicon-pencil', 506 onContentReady: function () { 507 var pic1 = $("#div_AddEdit").find("#txt_PicpathStr1").val(); 508 //var pic2 = $("#div_AddEdit").find("#txt_PicpathStr2").val(); 509 if (pic1 !== null && pic1 !== "") { 510 pic1 = htmlEncode(pic1); 511 512 $("#div_Image1").empty(); 513 showPreviewImage(pic1, "", 1); 514 } 515 else { 516 $(".image-div").find("#btn_ImageUpload1").hide(); 517 $(".image-div").find("#btn_ImageDelete1").hide(); 518 } 519 //if (pic2 !== null && pic2 !== "") { 520 // pic1 = htmlEncode(pic2); 521 522 // $("#div_Image2").empty(); 523 // showPreviewImage(pic2, "", 2); 524 //} 525 //else { 526 // $(".image-div").find("#btn_ImageUpload2").hide(); 527 // $(".image-div").find("#btn_ImageDelete2").hide(); 528 //} 529 }, 530 buttons: { 531 confirm: { 532 text: '確å®', 533 btnClass: 'btn-primary', 534 action: function () { 535 $("#div_Image0").addClass("image-base-border"); 536 537 if ($(".image-div").find(".active").length > 0) { 538 $("#div_Image0").removeClass("image-base-border"); 539 540 var image = $(".image-div").find(".active").find("img"); 541 542 $("#div_Image0").empty(); 543 showPreviewImage(image.attr("src"), "", 0); 544 $("#div_AddEdit").find("#txt_PicpathStr1").val(image.attr("src")); 545 546 //var imgNum = $(".image-div").find(".image-pic-exist:not(.active)").length; 547 //Console("imgNum=" + imgNum); 548 //if (imgNum == 1) { 549 // var image2 = $(".image-div").find(".image-pic-exist:not(.active)").find("img"); 550 // $("#div_AddEdit").find("#txt_PicpathStr2").val(image2.attr("src")); 551 //} 552 //else { 553 // $("#div_AddEdit").find("#txt_PicpathStr2").val(""); 554 //} 555 } 556 else { 557 $("#div_Image0").empty(); 558 var imgNum = $(".image-div").find(".image-pic-exist").length; 559 if (imgNum == 1) { 560 $("#div_Image0").removeClass("image-base-border"); 561 var image = $(".image-div").find(".image-pic-exist").find("img"); 562 $("#div_AddEdit").find("#txt_PicpathStr1").val(image.attr("src")); 563 //$("#div_AddEdit").find("#txt_PicpathStr2").val(""); 564 showPreviewImage(image.attr("src"), "", 0); 565 } 566 else if (imgNum == 2) { 567 $("#div_Image0").removeClass("image-base-border"); 568 var image1 = $(".image-div").find("#div_Image1").find("img"); 569 //var image2 = $(".image-div").find("#div_Image2").find("img"); 570 $("#div_AddEdit").find("#txt_PicpathStr1").val(image1.attr("src")); 571 //$("#div_AddEdit").find("#txt_PicpathStr2").val(image2.attr("src")); 572 showPreviewImage(image1.attr("src"), "", 0); 573 } 574 else { 575 $("#div_AddEdit").find("#txt_PicpathStr1").val(""); 576 //$("#div_AddEdit").find("#txt_PicpathStr2").val(""); 577 } 578 } 579 580 } 581 }, 582 cancel: { 583 text: 'åæ¶' 584 } 585 } 586 }); 587 });
588} 589 590/** 591 * å¨é é¢ä¸æ°å¢<img> 592 * @param {string} src -Base64å串 593 * @param {string} fileName -åçæªå 594 * @param {string} num -åçå¹¾ 595 */ 596function showPreviewImage(src, fileName, num) { 597 var id = "div_Image" + num; 598 var width = $("#" + id).width(); 599 Console("width=" + width); 600 var img_height; 601 602 let image = new Image(width); // è¨å®å¯¬ 603 image.name = fileName; 604 image.id = "img_" + num; 605 image.src = src; // <img>ä¸src屬æ§é¤äºæ¥urlå¤ä¹å¯ä»¥ç´æ¥æ¥Base64å串 606 607 608 image.onload = function () { 609 Console("height=" + this.height); 610 img_height = this.height; 611 612 613 614 if (num != 0) { 615 resize("img_" + num, 194); 616 } 617 else { 618 if (img_height > width) { 619 if (img_height > 214) { 620 resize("img_" + num, 214); 621 } 622 else { 623 resize("img_" + num, img_height); 624 } 625 } 626 else { 627 resize("img_" + num, width); 628 } 629 630 } 631 632 } 633 634 635 $("#" + id).append(image); 636 637 if (num != 0) { 638 Console("num="+num); 639 $("#btn_ImageUpload" + num).show(); 640 $("#btn_ImageDelete" + num).show(); 641 $("#" + id).removeClass("image-pic-none"); 642 $("#" + id).addClass("image-pic-exist"); 643 } 644} 645 646/** 647 * <img>調æ´å°ºå¯¸ 648 * @param {string} id -img id 649 * @param {number} max -æå¤§é·å¯¬ 650 */ 651function resize(id, max) { 652 var maxWidth = max; // Max width for the image 653 var maxHeight = max; // Max height for the image 654 var ratio = 0; // Used for aspect ratio 655 var width = $("#" + id).width(); // Current image width 656 var height = $("#" + id).height(); // Current image height 657 658 // Check if the current width is larger than the max 659 if (width > maxWidth) { 660 ratio = maxWidth / width; // get ratio for scaling image 661 $("#" + id).css("width", maxWidth); // Set new width 662 $("#" + id).css("height", height * ratio); // Scale height based on ratio 663 height = height * ratio; // Reset height to match scaled image 664 width = width * ratio; // Reset width to match scaled image 665 } 666 667 // Check if current height is larger than max 668 if (height > maxHeight) { 669 ratio = maxHeight / height; // get ratio for scaling image 670 $("#" + id).css("height", maxHeight); // Set new height 671 $("#" + id).css("width", width * ratio); // Scale width based on ratio 672 width = width * ratio; // Reset width to match scaled image 673 height = height * ratio; // Reset height to match scaled image 674 } 675} 676 677// 建ç«ä¸åæ«åçdivå ç´ ï¼ä¸¦ä½¿ç¨text()å°å §å®¹åæhtml編碼æåå¾åç¨html()ååº 678function htmlEncode(value) { 679 return $('<div/>').text(value).html(); 680} 681 682/** 683 * æª¢æ ¸ç §ç大å°(Base64Stringé·åº¦) 684 * @param {string} str -Base64String 685 * @returns {boolean} -ok true / else false 686 */ 687function vaildateImgSize(str) { 688 var ret = true; 689 if (str !== null) { 690 if (str.length > 2804360) { 691 ret = false; 692 // Console("Image Length="+str.length); 693 } 694 } 695 696 return ret; 697} 698//======================================================================================= 699//æ¥è©¢ãæ°å¢ãä¿®æ¹ãåªé¤å ±ç¨ 700//======================================================================================= 701//模å¼ä¸ 702//======================================================================================= 703//æ¸ é¤æ°å¢/ä¿®æ¹é é¢ 704function setPageAEini() { 705 resetAE(); 706 hideAllPage(); 707} 708//é±èææé é¢ 709function hideAllPage() { 710 $("#div_PageQ").hide(); 711 $("#div_PageAE").hide(); 712} 713// 714function setInitial() { 715 //é è¨é é¢ 716 hideAllPage(); 717 $("#div_PageQ").show(); 718 $("#btn_ShowQuery").hide(); 719} 720// 721function setEvent() { 722 //便¢ä»¶æ¥è©¢ 723 $("#btn_Search").click(function () { 724 search(); 725 });
726 //æ¸ é¤æ¥è©¢æ¢ä»¶ 727 $("#btn_Reset").click(function () { 728 resetQ(); 729 }); 730 731 //åæå°æ°å¢é é¢ 732 $("#btn_Add").click(function () { 733 $("#btn_Save").data("type", "Insert"); 734 setPageAEini(); 735 736 if (typeof preAdd !== "undefined") { 737 preAdd();//æ°å¢çæºå,èªè¡å¢å çç¨å¼å¯æ¾éè£¡é¢ 738 } 739 $("#div_PageAE").show(); 740 //$("#h3_AE").html("æ°å¢"); 741 $(".span-hide").hide(); 742 }); 743 //åæå°é è¨é é¢ 744 $("#btn_Cancel").click(function () { 745 hideAllPage(); 746 $("#div_PageQ").show(); 747 $(".span-hide").show(); 748 }); 749 750 //æ°å¢/ä¿®æ¹æé 751 $('#form_AddEdit').validator().on('submit', function (e) { 752 if (e.isDefaultPrevented()) { 753 // handle the invalid form... 754 } else { 755 // everything looks good! 756 save(); 757 } 758 e.preventDefault(); // 鲿¢åå§ form æäº¤è¡¨å 759 }); 760 761 //顯示é±èæ¥è©¢æ¬ä½ 762 $("#btn_HideQuery").click(function () { 763 $("#div_Query").find(".panel-body").hide(); 764 $("#btn_HideQuery").hide(); 765 $("#btn_ShowQuery").show(); 766 }); 767 $("#btn_ShowQuery").click(function () { 768 $("#div_Query").find(".panel-body").show(); 769 $("#btn_HideQuery").show(); 770 $("#btn_ShowQuery").hide(); 771 }); 772} 773//======================================================================================= 774//模å¼äº 775//======================================================================================= 776function setInitial2() { 777 //é è¨é é¢ 778 resetAE(); 779 $("#div_AddEdit").hide(); 780 $("#btn_ShowQuery").hide(); 781} 782function setEvent2() { 783 //便¢ä»¶æ¥è©¢ 784 $("#btn_Search").click(function () { 785 search(); 786 }); 787 //æ¸ é¤æ¥è©¢æ¢ä»¶ 788 $("#btn_Reset").click(function () { 789 resetQ(); 790 }); 791 792 //åæå°æ°å¢é é¢ 793 $("#btn_Add").click(function () { 794 resetAE(); 795 796 if (typeof preAdd !== "undefined") { 797 preAdd();//æ°å¢çæºå,èªè¡å¢å çç¨å¼å¯æ¾éè£¡é¢ 798 } 799 $("#div_AddEdit").show(); 800 $("#btn_Save").data("type", "Insert"); 801 }); 802 //åæå°é è¨é é¢ 803 $("#btn_Cancel").click(function () { 804 setInitial2(); 805 }); 806 807 //æ°å¢/ä¿®æ¹æé 808 $('#form_AddEdit').validator().on('submit', function (e) { 809 if (e.isDefaultPrevented()) { 810 // handle the invalid form... 811 } else { 812 // everything looks good! 813 save(); 814 } 815 e.preventDefault(); // 鲿¢åå§ form æäº¤è¡¨å 816 }); 817 818 //顯示é±èæ¥è©¢æ¬ä½ 819 $("#btn_HideQuery").click(function () { 820 $("#div_Query").find(".panel-body").hide(); 821 $("#btn_HideQuery").hide(); 822 $("#btn_ShowQuery").show(); 823 }); 824 $("#btn_ShowQuery").click(function () { 825 $("#div_Query").find(".panel-body").show(); 826 $("#btn_HideQuery").show(); 827 $("#btn_ShowQuery").hide(); 828 }); 829} 830 831 832//======================================================================================= 833//è·¨ç¨å¼å³é忏ç¸é 834//======================================================================================= 835/** 836 * å²åæ«åæ¥è©¢å¾å¸«ID 837 * @param {string} id 838 */ 839function setCacheID(id) { 840 var obj = {}; 841 obj.Fields = { "ID" : id }; 842 843 $.ajax({
844 url: $("#SetCache").data('url'), 845 data: obj, 846 type: 'Post', 847 dataType: 'json', 848 success: function (data) { 849 850 if (data == null || data.state == "ERROR") { 851 ErrorMessage(data.message); 852 } 853 }, 854 error: function (xhr, ajaxOptions, thrownError) { 855 ErrorMessage(thrownError); 856 } 857 }); 858} 859 860 861/** 862 * å徿«åæ¥è©¢å¾å¸«ID並æ¥è©¢ 863 * @param {string} textID å¾å¸«çIDæ¥è©¢æ¬ä½çhtmlå ç´ id 864 * @param {object} par å ¶é¤è¦å³éç忏, æ ¼å¼[{"key": "keyvalue", "id": "idvalue"}] 865 */ 866function defaultSearch(textID, par) { 867 868 $.ajax({ 869 url: $("#GetCache").data('url'), 870 type: 'Post', 871 dataType: 'json', 872 success: function (data) { 873 //Console(data); 874 875 if (data == null || data.state == "ERROR") { 876 ErrorMessage(data.message); 877 } 878 else { 879 var record = data.data; 880 881 if (record != null && record["ID"] != null && record["ID"] != "") { 882 if (typeof par !== "undefined") { 883 par.forEach(function (e) { 884 $("#" + e.id).val(record[e.key]); 885 }); 886 } 887 888 $("#div_Query").find("#" + textID).val(record["ID"]); 889 search(); 890 $("#div_Query").find("#" + textID).val(""); 891 } 892 } 893 }, 894 error: function (xhr, ajaxOptions, thrownError) { 895 ErrorMessage(thrownError); 896 } 897 }); 898 899 900} 901 902 903 904/** 905 * èªè¨è·¨ç¨å¼åæ¸ 906 * @param {object} value å³å ¥æ ¼å¼{ "key1":"value1", "key2":"value2" } 907 * @param {object} call å¾çºè¦åçäº 908 */ 909function setCache(value, call) { 910 var obj = {}; 911 obj.Fields = value; 912 913 $.ajax({
914 url: $("#SetCache").data('url'), 915 data: obj, 916 type: 'Post', 917 dataType: 'json', 918 success: function (data) { 919 920 if (data == null || data.state == "ERROR") { 921 ErrorMessage(data.message); 922 } 923 else if(call !== undefined) { 924 call(); 925 } 926 }, 927 error: function (xhr, ajaxOptions, thrownError) { 928 ErrorMessage(thrownError); 929 } 930 }); 931} 932 933/** 934 * ååºèªè¨è·¨ç¨å¼åæ¸ 935 * @param {object} key ååºçkey 936 * @param {object} textID åæ¾ä½ç½®çtext id 937 */ 938 function getCache(key, textID) { 939 $.ajax({ 940 url: $("#GetCache").data('url'), 941 type: 'Post', 942 dataType: 'json', 943 success: function (data) { 944 if (data === null || data.state === "ERROR") { 945 ErrorMessage(data.message); 946 } 947 else { 948 var record = data.data; 949 //Console(record); 950 951 //if (typeof session !== "undefined") { 952 // session = record; 953 //} 954 955 if (record != null && record[key] != null && record[key] != "") { 956 Console("getCache"); 957 Console(record[key]); 958 $("#" + textID).val(record[key]); 959 } 960 961 962 } 963 }, 964 error: function (xhr, ajaxOptions, thrownError) { 965 ErrorMessage(thrownError); 966 } 967 }); 968} 969 970//======================================================================================= 971//èªè¨function 972//======================================================================================= 973 974/** 975 * å°å¾ç«¯Serializeå¾çobjectå串è½åobject 976 * @param {any} inputJson 977 */ 978function JsonToObject(inputJson) { 979 980 inputJson = inputJson.replace(/"/g, '"'); 981 if (!inputJson) jsonFavShow = "{}"; 982 983 return JSON.parse(inputJson); 984} 985 986function HtmlEncode(s) { 987 var div = document.createElement('div'); 988 div.appendChild(document.createTextNode(s)); 989 return div.innerHTML; 990} 991function EtmlDecode(s) { 992 var div = document.createElement('div'); 993 div.innerHTML = s; 994 return div.innerText || div.textContent; 995} 996 997//æ¸ ç©ºform 998function ResetForm(formId) { 999 1000 let form = document.getElementById(formId); 1001 1002 //æ¸ é¤keyinè³æ 1003 //document.getElementById(formId).reset(); 1004 $(form).trigger("reset"); 1005 1006 //æ¸ é¤selectpickerè³æ 1007 //$(form).find('.selectpicker').val(''); 1008 $(form).find('.selectpicker').selectpicker('val', ''); 1009 $(form).find('.selectpicker').selectpicker('refresh'); 1010 1011 //#region æ¸ é¤valueæ¬èº«è³æ 1012 // clearing inputs 1013 var inputs = form.getElementsByTagName('input'); 1014 for (var i = 0; i < inputs.length; i++) { 1015 switch (inputs[i].type) { 1016 case 'hidden': 1017 inputs[i].value = ''; 1018 break; 1019 case 'text': 1020 inputs[i].value = ''; 1021 break; 1022 case 'radio': 1023 case 'checkbox': 1024 inputs[i].checked = false; 1025 } 1026 } 1027 1028 // clearing selects 1029 var selects = form.getElementsByTagName('select'); 1030 for (var i = 0; i < selects.length; i++) 1031 selects[i].selectedIndex = 0; 1032 1033 // clearing textarea 1034 var text = form.getElementsByTagName('textarea'); 1035 for (var i = 0; i < text.length; i++) 1036 text[i].innerHTML = ''; 1037 1038 //#endregion 1039 1040 return false; 1041} 1042 1043//å°è±¡é¡å¥ä¸æé¸å®åæ æ§å¶ 1044function SetC1IDListChangeAction(C3ItemJson) { 1045 1046 var C3Item = JsonToObject(C3ItemJson); 1047 1048 //編輯é é¢ä¾ä¿è·å¸å¸/åå°æª¢æ´æ°å°è±¡é¡å¥ä¸æé¸å® 1049 $("[id$=c1Value]").change(function () { 1050 1051 var c1ID = $(this).attr('ID'); 1052 var c3ID = ''; 1053 if (c1ID == 'c1Value') { 1054 c3ID = 'c3Value'; 1055 } 1056 if (c1ID == 'qc1Value') { 1057 c3ID = 'qc3Value'; 1058 } 1059 1060 //Console(c1ID+' '+c3ID); 1061 1062 //æ¸ ç©ºä¸æé¸å® 1063 $('#' + c3ID + ' option:not(.bs-title-option)').remove(); 1064 1065 //æ°å¢é¸å®é ç® 1066 var c1Selected = this.value; 1067 $.each(C3Item, function (index, value) { 1068 if (c1Selected == value.C1ID) { 1069 $('#' + c3ID + ' .bs-title-option').after("<option value='" + value.C3ID + "'>" + value.C3Name + "</option>") 1070 } 1071 }); 1072 1073 if ($('#' + c3ID + ' option:not(.bs-title-option)').length == 0) { 1074 $('#' + c3ID).selectpicker({ title: '--è«å 鏿ä¿è·å¸/åå°æª¢--' }); 1075 } else { 1076 //ç·¨è¼¯çæ add emptyitem 1077 if (c1ID == 'qc1Value') { 1078 $('#' + c3ID + ' .bs-title-option').after("<option value=''>--è«é¸æ--</option>") 1079 } 1080 1081 $('#' + c3ID).selectpicker({ title: '--è«é¸æ--' });
1082 } 1083 1084 //refresh 1085 $('#' + c3ID).selectpicker('refresh'); 1086 1087 }); 1088} 1089 1090//secure random 1091function SecurRandom() { 1092 var array = new Uint32Array(1) 1093 var crypto = window.crypto || window.msCrypto; 1094 crypto.getRandomValues(array); 1095 return array[0] / (0xFFFFFFFF + 1); 1096}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.