浏览代码

移除非設計圖項次 修改預設顯示資料數

steve07s 3 年之前
父节点
当前提交
38e07a6306
共有 6 个文件被更改,包括 217 次插入28 次删除
  1. 11 2
      Upload.html
  2. 124 0
      edit.html
  3. 9 8
      index.php
  4. 26 0
      script/css/form.css
  5. 30 18
      script/js/jstreeAJAX.js
  6. 17 0
      script/php/importTool/updateProject.php

+ 11 - 2
Upload.html

@@ -12,6 +12,7 @@
     <link rel="stylesheet" href="./assets/vendor/font-awesome/css/font-awesome.css" />
     <script src="./assets/vendor/jquery/jquery.js"></script>
 </head>
+<a href="./edit.html" class="go-to-editor" target="_self">進入至編輯工具</a>
 <form method="post" enctype="multipart/form-data" action="./script/php/importTool/uploadExcel.php">
 
     <h1><strong>MAA</strong> 設計群匯入工具</h1>
@@ -40,13 +41,14 @@
         </div>
     </div>
 
-    <div class="form-group">
+    <div class="form-group center">
         <p><strong>注意事項:</strong>Excel檔名請用計畫編號命名。 (例:15032.xlsx)</p>
         <button type="submit">上傳檔案</button>
+        <button id="reset" type="button">清除表單</button>
     </div>
 
 </form>
-<a href="./index.php" class="back-to-article" target="_blank">返回至查詢工具</a>
+<a href="./index.php" class="back-to-article" target="_self">返回至查詢工具</a>
 
 <script type="text/javascript">
     var projectTable;
@@ -112,6 +114,13 @@
                 $('#page0').addClass('in active')
             });
     }
+
+    $("#reset").click(function(){
+        $("#projectId").val('')
+        $("#projectName").val('')
+        $('#category').val(1);
+        $("#excel").val('')
+    })
 </script>
 
 </html>

+ 124 - 0
edit.html

@@ -0,0 +1,124 @@
+<!DOCTYPE html>
+<html>
+
+<head>
+    <title>設計群編輯工具</title>
+    <meta charset="utf-8">
+    <link rel="shortcut icon" href="./assets/images/favicon.ico" />
+    <meta name="viewport" content="width=device-width, initial-scale=1">
+    <link rel="stylesheet" href="./script/css/form.css" />
+    <link href='https://fonts.googleapis.com/css?family=Lato:100,200,300,400,500,600,700' rel='stylesheet'
+        type='text/css'>
+    <link rel="stylesheet" href="./assets/vendor/font-awesome/css/font-awesome.css" />
+    <script src="./assets/vendor/jquery/jquery.js"></script>
+</head>
+<a href="./upload.html" class="go-to-editor" target="_self">進入至匯入工具</a>
+<form id="form" method="post" enctype="multipart/form-data" action="./script/php/importTool/updateProject.php">
+
+    <h1><strong>MAA</strong> 設計群編輯工具</h1>
+
+    <div class="form-group">
+        <label for="projectId">計畫編號 </label>
+        <input type="text" name="projectId" id="projectId" class="form-controll" required="required" />
+    </div>
+    <div class="form-group">
+        <label for="projectName">計畫名稱 </label>
+        <input type="text" name="projectName" id="projectName" class="form-controll" required="required" />
+    </div>
+    <div class="form-group">
+        <label for="category">工程類別</label>
+        <select name="category" id="category" class="form-controll" required="required">
+        </select>
+    </div>
+
+    <div class="form-group center">
+        <p><strong>使用說明:</strong>輸入計畫編號後,再修改計畫名稱或工程類別。</p>
+        <button id="submit" type="submit">儲存修改</button>
+        <button id="reset" type="button">清除表單</button>
+    </div>
+
+</form>
+<a href="./index.php" class="back-to-article" target="_self">返回至查詢工具</a>
+
+<script type="text/javascript">
+    var projectTable;
+    var projectName;
+    $(document).ready(function () {
+        getCategory();
+
+        var url_href = window.location.href;
+        var url = new URL(url_href);
+        var status = url.searchParams.get("status");
+        if (status != null) {
+            switch (status) {
+                case "success":
+                    alert("匯入成功!");
+                    break;
+                case "postFailed":
+                    alert("匯入失敗!");
+                    break;
+                case "dbFailed":
+                    alert("連接資料庫失敗!");
+                    break;
+            }
+        }
+
+        $("#projectId").change(function () {
+            const find = projectTable.find(element => element[0] == this.value);
+            if (find != null) {
+                projectName = find[1];
+                category = find[2];
+                $("#projectName").val(projectName);
+                $("#projectName").css("color", "#fff");
+                $('#category').val(category);
+                $('#submit').prop('disabled', false);
+                $("#submit").css("cursor", "point");
+            } else {
+                $("#projectName").val("查無此計畫名稱!");
+                $("#projectName").css("color", "red");
+                $('#category').val(1);
+                $('#submit').prop('disabled', true);
+                $("#submit").css("cursor", "not-allowed");
+            }
+
+        });
+    });
+
+    jQuery(function ($) {
+        $('form').bind('submit', function () {
+            $(this).find(':input').prop('disabled', false);
+        });
+    });
+
+    function getCategory() {
+
+        $.ajax({
+                url: "./script/php/importTool/getConstructionCategory.php",
+                async: false,
+                contentType: "application/json",
+                dataType: "json",
+                type: "GET",
+            })
+            .success(function (response) {
+                projectTable = response["project"];
+                for (i = 0; i < response["category"].length; i++) {
+                    $('#category').append(
+                        `<option value='${response["category"][i][0]}'>${response["category"][i][1]}</option>`);
+                }
+            })
+            .error(function (error) {
+                console.log(error);
+            })
+            .complete(function () {
+                $('#page0').addClass('in active')
+            });
+    }
+
+    $("#reset").click(function () {
+        $("#projectId").val('')
+        $("#projectName").val('')
+        $('#category').val(1);
+    })
+</script>
+
+</html>

+ 9 - 8
index.php

@@ -561,16 +561,17 @@ if (!isset($_SESSION['loggedin'])) {
 		var userName = 'maabim';
 
 
-		jQuery(window).load(function() {
-			var searchURL = window.location.search;
-			searchURL = searchURL.substring(1, searchURL.length);
-			if (searchURL.includes("=")) {
-				projectId = decodeURIComponent(searchURL.split("&")[0].split("=")[1]);
+		jQuery(window).load(function() {			
+			var url_href = window.location.href;
+			var url = new URL(url_href);
+			var type = url.searchParams.get("type");
+			var projectId = url.searchParams.get("projectId");
+			if (projectId != null) {
 				var projectNode = $(".jstree-anchor").filter(function() {
 					return $(this).text().includes(projectId);
 				});
-				var projectId = projectNode[0].attributes.id.value;
-				$('#treeAjaxHTML').jstree("select_node", projectId);
+				let nodeId = projectNode[0].attributes.id.value;
+				$('#treeAjaxHTML').jstree("select_node", nodeId);
 				$("#treeAjaxHTML").jstree("close_all");
 			}
 		});
@@ -591,7 +592,7 @@ if (!isset($_SESSION['loggedin'])) {
 				<span class="separator"></span>
 				<ul class="notifications">
 					<li>
-					<a href="/DataBase/script/php/importTool/upload.php" class="notification-icon" data-toggle="tooltip" title="匯入工具" data-placement="bottom">
+						<a href="./upload.html" class="notification-icon" data-toggle="tooltip" title="匯入工具" data-placement="bottom">
 							<i class="fa fa-upload"></i>
 						</a>
 						<a href="/Front-Page/home.php" class="notification-icon" data-toggle="tooltip" title="綜合登入入口" data-placement="bottom">

+ 26 - 0
script/css/form.css

@@ -113,6 +113,11 @@ button {
     border: 0;
     text-shadow: 0 1px 2px #fff;
     cursor: pointer;
+    margin-left: 15px;
+    margin-right: 15px;
+}
+button:disabled {
+    background: rgba(150, 150, 150, 0.9);
 }
 .form-group {
     max-width: 500px;
@@ -137,7 +142,28 @@ button {
     opacity: 1;
     background: rgba(0, 0, 0, 0.8);
 }
+.go-to-editor {
+    color: #fff;
+    text-transform: uppercase;
+    font-size: 12px;
+    position: absolute;
+    left: 20px;
+    top: 20px;
+    text-decoration: none;
+    display: inline-block;
+    background: rgba(0, 0, 0, 0.6);
+    padding: 10px 18px;
+    transition: all 0.3s ease-in-out;
+    opacity: 0.6;
+}
+.go-to-editor:hover {
+    opacity: 1;
+    background: rgba(0, 0, 0, 0.8);
+}
 
 option{
     background: rgba(54, 102, 152);
+}
+.center{
+    text-align: center;
 }

+ 30 - 18
script/js/jstreeAJAX.js

@@ -115,8 +115,8 @@ $(document).ready(function () {
         }).error(function (error) {
             console.log(error);
         });
-    
-    displayDetail(false);
+
+    displayDetail(false, true);
 
 
 
@@ -140,10 +140,10 @@ $(document).ready(function () {
         },
         'plugins': ['types', 'search', 'wholerow']
     }).bind("loaded.jstree", function (event, data) {
-        var searchURL = window.location.search;
-        searchURL = searchURL.substring(1, searchURL.length);
-        if (searchURL.includes("=")) {
-            type = decodeURIComponent(searchURL.split("&")[1].split("=")[1]);
+        var url_href = window.location.href;
+        var url = new URL(url_href);
+        var projectId = url.searchParams.get("projectId");
+        if (projectId != null) {
             $(this).jstree("open_all");
         }
 
@@ -154,7 +154,7 @@ $(document).ready(function () {
             if (data.node.text.includes("-")) {
                 $("#reset").prop("disabled", false);
                 $("#header").empty();
-                displayDetail(false);
+                displayDetail(false, true);
                 project_id = data.node.text.split("-")[0];
                 project_name = data.node.text.split("-")[1];
                 project = data.node.text;
@@ -164,7 +164,7 @@ $(document).ready(function () {
 
                 var span = $('<span>' + project + ' > </span>');
                 span.on("click", function (e) {
-                    displayDetail(false);
+                    displayDetail(false, true);
                     is_blueprint2 = false;
                     for (var k = folderPath.length - 1; k > 0; k--) {
                         $("#header").children().eq(k).remove();
@@ -216,7 +216,7 @@ $(document).ready(function () {
             } else {
                 data.instance.toggle_node(data.node);
             }
-            displayDetail(false);
+            displayDetail(false, true);
         });
 
     $('#btn-search').click(function () {
@@ -235,7 +235,7 @@ $(document).ready(function () {
                 type: "GET",
             })
             .success(function (response) {
-                displayDetail(true);
+                displayDetail(true, true);
                 table.clear().draw();
                 $("#tableDetail td").empty();
                 response.forEach(function (data) {
@@ -285,7 +285,7 @@ $(document).ready(function () {
                 });
             }
             $("#tableDetail td").empty();
-            displayDetail(false);
+            displayDetail(false, true);
         }
 
     });
@@ -302,7 +302,7 @@ $(document).ready(function () {
         }
         let project_id = data[5].split("-")[0];
         let SN = data[0];
-        let is_blueprint = data[1] == "設計圖" || data[1] == "成果圖"? true : false;
+        let is_blueprint = data[1] == "設計圖" || data[1] == "成果圖" ? true : false;
         let note = notes.includes(data[1]) ? data[1] : '';
         if (data[2] == 'null') {
             $("#tableDetail td").empty();
@@ -369,8 +369,9 @@ $(document).ready(function () {
 
     });
 
-    function displayDetail(status) {
-        if (status) {
+    function displayDetail(isFile, isBlueprint) {
+        if (isFile) {
+            table.column(0).visible(isBlueprint);
             table.column(2).visible(true);
             table.column(3).visible(true);
             table.column(4).visible(false);
@@ -378,6 +379,7 @@ $(document).ready(function () {
             $("#SN").text("圖號");
             $("#name").text("圖名");
             $('.nav-tabs a[href="#pdfTab"]').tab('show');
+
         } else {
             table.column(2).visible(false);
             table.column(3).visible(false);
@@ -385,7 +387,11 @@ $(document).ready(function () {
             $(".table-responsive").hide();
             $("#SN").text("項次");
             $("#name").text("類別");
-            table.page.len(7).draw();
+            if(isBlueprint){
+                table.page.len(-1).draw();
+            }else{
+                table.page.len(7).draw();
+            }            
             $('.nav-tabs a[href="#arcgisTab"]').tab('show');
         }
 
@@ -416,13 +422,18 @@ $(document).ready(function () {
     function addTable(data, notes, response, SN, path) {
 
         table.clear().draw();
-        table.page.len(10).draw();
         if (data[1] != "設計圖" && data[1] != "成果圖") {
-            displayDetail(true);
 
             if (notes.includes(data[1])) {
                 is_blueprint2 = true;
+                displayDetail(true, true);
+                table.page.len(10).draw();
+            } else {
+                displayDetail(true, false);
+                table.page.len(-1).draw();
             }
+            
+            
             for (i = 0; i < response.length; i++) {
                 table.row.add([
                     response[i]["SN"],
@@ -439,9 +450,10 @@ $(document).ready(function () {
                 ])
                 table.draw();
             }
+            
 
         } else {
-            displayDetail(false);
+            displayDetail(false, true);
             blueprint_SN = SN;
             blueprint_path = path;
             tempTable2 = [];

+ 17 - 0
script/php/importTool/updateProject.php

@@ -0,0 +1,17 @@
+<?php
+include("../sql.php");
+$connectionInfo = array("Database" => "$dbname", "UID" => "$username", "PWD" => "$password", "CharacterSet" => "UTF-8");
+$conn = sqlsrv_connect($hostname, $connectionInfo);
+if ($conn === false) {
+    die(print_r(sqlsrv_errors(), true));
+    header("Location: ../../../edit.html?status=dbFailed");
+}
+
+if(isset($_POST["projectId"]) && isset($_POST["projectName"]) && isset($_POST["category"])){
+    $sql =  "UPDATE [Project_Table] SET [project_name] = ?,[category_id] = ? WHERE [project_id] = ?";
+    $stmt = sqlsrv_query($conn, $sql, array($_POST["projectName"], $_POST["category"],$_POST["projectId"]));
+    header("Location: ../../../edit.html?status=success");
+}else{
+    header("Location: ../../../edit.html?status=postFailed");
+}
+sqlsrv_close($conn);