สอนทำเว็บไซต์

Management System : DeleteData

โมดูลลบข้อมูล

ManageTreat.php

<?php include_once("checklogin.php"); ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Lekjew.com</title> <?php include_once("include/style.php"); ?> <style> /*suggestion*/ .ui-front{ z-index: 2051 !important;} .selecthead{background-color:#f2f2f2 !important;color:#555 !important; text-align:right !important;font:normal 1em 'Sarabun', sans-serif; padding-top:5px; padding-right:10px;vertical-align: text-bottom !important;z-index:1003 !important;} </style> </head> <body class="adminbody"> <?php include_once("include/header_login.php"); ?> <div id="main" > <?php include_once("leftmenu.php"); ?> <div class="content-page"> <div class="content"> <div class="col-md-12"> <div class="card pd-10"> <div class="col-md-12"><div class="row"> <div class="col-md-11"><h3>Manage Treat</h3></div> <div class="col-md-1 text-center"><button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#ModalA" onclick="ResetFrom();">Add</button></div> </div></div> <div class="col-md-12"> <table id="tableA" class="table table-bordered tablec" cellspacing="0" cellpadding="0" border="1" > <thead> <tr> <th>#</th> <th>#</th> <th>ลำดับที่</th> <th>ชื่อผู้เข้ารับการรักษา</th> <th>แผนก</th> <th>วันที่เข้ารับการรักษา</th> <th>อาการ</th> <th>หมอ/แพทย์</th> <th>สถานะ</th> </tr> <tr> <td>#</td> <td>#</td> <td>ลำดับที่</td> <td>ชื่อผู้เข้ารับการรักษา</td> <td>แผนก</td> <td>วันที่เข้ารับการรักษา</td> <td>อาการ</td> <td>หมอ/แพทย์</td> <td>สถานะ</td> </tr> </thead> <tbody id="showtableA"> <tr> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> </tr> </tbody> <tfoot class='hide'> <tr> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> </tr> </tfoot> </table> </div> </div> </div> </div> </div> </div> </body> </html> <div id="ModalA" class="modal fade" id="kt_modal_1"> <div class="modal-dialog modal-lg" style="z-index:150;"> <div class="modal-content"> <div class="modal-header"> <h5 class="modal-title">ซักประวัติ/อาการ</h5> <button type="button" class="btn btn-dark" data-bs-dismiss="modal" id="closeModalA"><i class='fa fa-times'></i> Close</button></button> </div> <div class="modal-body"> <div class="input-group mb-3"> <span class="input-group-text front1" id="">ชื่อผู้ป่วย</span> <input type="text" id="patient" name="patient" class="form-control" onKeyDown="Suggestion('patient');" > </div> <div class="input-group mb-3"> <span class="input-group-text front1" id="">เคส</span> <select id="case" name="case" class="form-select selectpicker bgw" data-live-search="true" > <option value='0' selected disabled>-- Select --</option> <option value='ปกติ'>ปกติ</option> <option value='ฉุกเฉิน'>ฉุกเฉิน</option> </select> </div> <div class="input-group mb-3"> <span class="input-group-text front1" id="">เข้าตรวจแผนก</span> <select id="treat" name="treat" class="form-select selectpicker" data-live-search="true" onchange="CallDataDoctor(this.value);"> <option value='0' selected disabled>-- Select --</option> </select> </div> <div class="input-group mb-3"> <span class="input-group-text front1" id="">แพทย์</span> <select id="doctor_code" name="doctor_code" class="form-select selectpicker" data-live-search="true" > <option value='0' selected disabled>-- Select --</option> </select> </div> <div class="input-group mb-3"> <span class="input-group-text front1" id="">อาการ</span> <input type="text" id="t_case" class="form-control" aria-describedby="basic-addon1"> </div> </div> <div class='text-danger' id='showerr'></div> <div class="modal-footer"> <button type="button" class="btn btn-primary" onclick="TreatSave();"><i class='fa fa-save'></i> Save</button> </div> </div> </div> </div> <div id="EditModalA" class="modal fade" id="kt_modal_2"> <div class="modal-dialog modal-lg" style="z-index:150;"> <div class="modal-content"> <div class="modal-header"> <h5 class="modal-title">แก้ไขข้อมูล ซักประวัติ/อาการ</h5> <button type="button" class="btn btn-dark" data-bs-dismiss="modal" id="closeModalAEdit"><i class='fa fa-times'></i> Close</button></button> </div> <div class="modal-body"> <input type="hidden" id="Edit_t_no" name="Edit_t_no" class="form-control" disabled > <div class="input-group mb-3"> <span class="input-group-text front1" id="">ชื่อผู้ป่วย</span> <input type="text" id="Edit_patient" name="patient" class="form-control" onKeyDown="Suggestion('patient');" > </div> <div class="input-group mb-3"> <span class="input-group-text front1" id="">เคส</span> <select id="Edit_case" name="case" class="form-select selectpicker bgw" data-live-search="true" > <option value='0' selected disabled>-- Select --</option> <option value='ปกติ'>ปกติ</option> <option value='ฉุกเฉิน'>ฉุกเฉิน</option> </select> </div> <div class="input-group mb-3"> <span class="input-group-text front1" id="">เข้าตรวจแผนก</span> <select id="Edit_treat" name="treat" class="form-select selectpicker" data-live-search="true" onchange="CallDataDoctor(this.value);"> <option value='0' selected disabled>-- Select --</option> </select> </div> <div class="input-group mb-3"> <span class="input-group-text front1" id="">แพทย์</span> <select id="Edit_doctor_code" name="doctor_code" class="form-select selectpicker" data-live-search="true" > <option value='0' selected disabled>-- Select --</option> </select> </div> <div class="input-group mb-3"> <span class="input-group-text front1" id="">อาการ</span> <input type="text" id="Edit_t_case" class="form-control" aria-describedby="basic-addon1"> </div> </div> <div class='text-danger' id='showerrEdit'></div> <div class="modal-footer"> <button type="button" class="btn btn-primary" onclick="TreatEditSave();"><i class='fa fa-save'></i> Save</button> </div> </div> </div> </div> <div id="DeleteModalA" class="modal fade" id="kt_modal_3"> <div class="modal-dialog modal-lg" style="z-index:150;"> <div class="modal-content"> <div class="modal-header"> <h5 class="modal-title">ยืนยันการลบข้อมูล</h5> <button type="button" class="btn btn-dark" data-bs-dismiss="modal" id="closeModalADelete"><i class='fa fa-times'></i> Close</button></button> </div> <div class="modal-body"> <input type="hidden" id="Delete_t_no" name="Delete_t_no" class="form-control" disabled > <div class="input-group mb-3"> <span class="input-group-text front1">ชื่อผู้ป่วย</span> <span id="Delete_patient"></span> </div> <div class="input-group mb-3"> <span class="input-group-text front1">เคส</span> <span id="Delete_case"></span> </div> <div class="input-group mb-3"> <span class="input-group-text front1">เข้าตรวจแผนก</span> <span id="Delete_treat"></span> </div> <div class="input-group mb-3"> <span class="input-group-text front1">แพทย์</span> <span id="Delete_doctor_code"></span> </div> <div class="input-group mb-3"> <span class="input-group-text front1">อาการ</span> <span id="Delete_t_case"></span> </div> </div> <div class='text-danger' id='showerrDelete'></div> <div class="modal-footer"> <button type="button" class="btn btn-primary" onclick="TreatDeleteSave();"><i class='fa fa-save'></i> Confirm Delete</button> </div> </div> </div> </div> <div class="alert alert-success" id="success-alert" style="position:absolute; z-index:3025; bottom:40%; left:45%; width:350px; display:none; "> <div class="text-center m-top-20"><h4 id="resultalert"></h4></div><br> </div> <div class="alert alert-danger" id="fail-alert" style="position:absolute; z-index:3025; bottom:40%; left:45%; width:350px; display:none; "> <div class="text-center m-top-20"><h4 id="resultfailalert"></h4></div><br> </div> <?php include_once("include/js.php"); ?> <script type="text/javascript"> $(function(){ $('.selectpicker').selectpicker(); }); CallDataGroup(); RefreshTable(); CallData(); function CallData(){ $.ajax({ url: "ManageTreat_data.php", async: false, cache: false, contentType: false, processData: false, type: 'post', success: function(data) { var tr =""; var JsonData = JSON.parse(data); var resL = JsonData.length; for (var i = 0; i < resL; i++) { tr=tr+"<tr>" ; tr=tr+"<td><span class='btn btn-info btn-sm' data-bs-toggle='modal' data-bs-target='#EditModalA' onclick=\"CalldataEdit('"+JsonData[i]["t_no"]+"');\"><i class='fa fa-pencil-square-o'></i></span></td>"; tr=tr+"<td><span class='btn btn-danger btn-sm' data-bs-toggle='modal' data-bs-target='#DeleteModalA' onclick=\"CalldataDelete('"+JsonData[i]["t_no"]+"', '"+JsonData[i]["t_name"]+"', '"+JsonData[i]["t_treat"]+"', '"+JsonData[i]["t_case"]+"', '"+JsonData[i]["t_doctor"]+"', '"+JsonData[i]["t_status"]+"');\"><i class='fa fa-trash'></i></span></td>"; tr=tr+"<td>"; tr = tr + JsonData[i]["t_no"]; tr=tr+"</td>"; tr=tr+"<td>"; tr = tr + JsonData[i]["t_name"]; tr=tr+"</td>"; tr=tr+"<td>"; tr = tr + JsonData[i]["t_treat"]; tr=tr+"</td>"; tr=tr+"<td>"; tr = tr + JsonData[i]["t_datetime"]; tr=tr+"</td>"; tr=tr+"<td>"; tr = tr + JsonData[i]["t_case"]; tr=tr+"</td>"; tr=tr+"<td>"; tr = tr + JsonData[i]["t_doctor"]; tr=tr+"</td>"; tr=tr+"<td>"; tr = tr + JsonData[i]["t_status"]; tr=tr+"</td>"; tr=tr+"</tr>" ; } $('#showtableA').html(''); $('#tableA').DataTable().destroy(); $('#showtableA').html(tr); RefreshTable(); }, error: function(data){ $('#showtableA').html(data); } }); } function RefreshTable(){ $('#tableA thead tr:eq(0) th').empty(); $('#tableA thead tr:eq(0) th').each( function (i) { if(i>1){ var title = $(this).text(); $(this).html( '<input type="text" class="form-control search'+i+' section-no-print">' ); $( 'input', this ).on( 'keyup change', function () { if ( table.column(i).search() !== this.value ) { table .column(i) .search( this.value ) .draw(); } }); } }); var table = $('#tableA').DataTable( { dom: "<'row'<'col-md-1'<'pull-left'>><'col-md-3'<'pull-left'>><'col-md-8'><'col-sm-12'tr>>", searching: true, ordering: false, lengthMenu: [[10, 25, 50, -1], [10, 25, 50, "All"]], iDisplayLength: -1, scrollY: "450px", scrollCollapse: true, scrollX: true, responsive: true, "pagingType": "full_numbers", "fnInitComplete": function (oSettings) { $('.select_broker_wrapper').find('.tblBroker_head').hide(); } }); $('#tableA thead tr:eq(0)').empty(); $('#tableA thead tr:eq(0)').empty(); $('#tableA tfoot tr:eq(0)').empty(); $('.dataTables_scrollBody #tableA tr:eq(0) ').empty(); } function CallDataGroup(){ $.ajax({ url: "ManageTreat_treat_group_data.php", async: false, cache: false, contentType: false, processData: false, type: 'post', success: function(data) { var option =""; var JsonData = JSON.parse(data); var resL = JsonData.length; for (var i = 0; i < resL; i++) { option=option+"<option value='"+JsonData[i]["treat_group_code"]+"'>"+JsonData[i]["treat_group_name"]+"</option>" ; } $('#treat').html(''); $('#treat').html("<option value='0' selected disabled>-- Select --</option>"+option); $('#treat').selectpicker('destroy'); $('#treat').selectpicker('render'); }, error: function(data){ $('#treat').html("<option value='0' selected disabled>-- Select --</option>"); $('#treat').selectpicker('destroy'); $('#treat').selectpicker('render'); } }); } function CallDataDoctor(sector){ $('#doctor_code').html(''); var form_data = new FormData(); form_data.append("treat_group", sector); $.ajax({ url: "ManageTreat_doctor_data.php", async: false, cache: false, contentType: false, processData: false, data: form_data, type: 'post', success: function(data) { var option =""; var JsonData = JSON.parse(data); var resL = JsonData.length; for (var i = 0; i < resL; i++) { option=option+"<option value='"+JsonData[i]["doctor_code"]+"'>"+JsonData[i]["doctor_name"] +"</option>" ; } if(resL>0){ $('#doctor_code').html("<option value='0' selected disabled>-- Select --</option>"+option); }else{ $('#doctor_code').html("<option value='0' selected disabled>-- Select --</option>"); } $('#doctor_code').selectpicker('destroy'); $('#doctor_code').selectpicker('render'); }, error: function(data){ $('#doctor_code').html("<option value='0' selected disabled>-- Select --</option>"); $('#doctor_code').selectpicker('destroy'); $('#doctor_code').selectpicker('render'); } }); } function Suggestion(){ var valsearch = $('#patient').val(); var form_data = new FormData(); form_data.append("SEARCHVALUE", valsearch); $.ajax({ url: 'ManageTreat_patient_data.php', cache: false, contentType: false, processData: false, dataType: 'text', data: form_data, type: 'post', success: function (data) { var JsonData = JSON.parse(data); var patient_name = ""; var sugguest = []; var resL = JsonData['result'].length; if(resL>0){ for (var i = 0; i < resL; i++) { if(typeof JsonData['result'][i]['patient_name'] !== "undefined" && JsonData['result'][i]['patient_name'] !== null ){ patient_name = JsonData['result'][i]['patient_name']; } sugguest.push(patient_name); } $( '#patient').autocomplete({ source: sugguest }); } }, error: function (data) { alert(data); return false; } }); } function TreatSave(){ var patient = $('#patient').val(); var t_case = $('#t_case').val(); var tcase = $('#case option:selected').val(); var treatcode = $('#treat option:selected').val(); var treat = $('#treat option:selected').text(); var doctor_code = $('#doctor_code option:selected').val(); var t_doctor = $('#doctor_code option:selected').text(); var form_data = new FormData(); form_data.append("condition", "AddTreat"); form_data.append("patient", patient); form_data.append("t_treat_code", treatcode); form_data.append("treat", treat); form_data.append("tcase", tcase); form_data.append("t_case", t_case); form_data.append("doctor_code", doctor_code); form_data.append("t_doctor", t_doctor); form_data.append("CREATE_BY", "<?php echo $username; ?>"); if(patient!="" && tcase!="0" && doctor_code!="0" && treatcode!="0"){ $.ajax({ url: "ManageTreat_save.php", contentType: false, processData: false, data: form_data, dataType: "text", type: 'post', success: function(data) { $('#showerr').html(''); var j = 0; var err = ""; var JsonData = JSON.parse(data); var resL = JsonData['result'].length; for(var i =0; i< resL; i++){ if(typeof JsonData['result'][i]['ERR']!=="undefined" && JsonData['result'][i]['ERR']!==null ){ err = err + JsonData['result'][i]['ERR']; j++; } } if(j>0){ $('#showerr').html(err); }else{ ResetFrom(); $('#closeModalA').click(); CallData(); } } }); }else{ if(patient == ""){ showFailAlert("กรุณาใส่ชื่อผู้ป่วย"); } if(tcase=="0"){ showFailAlert("กรุณาเลือกเคส"); } if(doctor_code=="0"){ showFailAlert("กรุราเลือกแพทย์"); } if(treatcode=="0"){ showFailAlert("กรุณาเลือกแผนก"); } } } function ResetFrom(){ $('#patient').val(''); $('#case').val('0'); $('#treat').val('0'); $('#doctor_code').val('0'); $('#t_case').val(''); } function showSuccessAlert(data) { $('#resultalert').html(data); $("#success-alert").fadeTo(2000, 300).slideUp(300, function(){ $("#success-alert").slideUp(300); } ); } function showFailAlert(data) { $('#resultfailalert').html(data); $("#fail-alert").fadeTo(2000, 300).slideUp(300, function(){ $("#fail-alert").slideUp(300); }); } function CalldataEdit(t_no){ $('#showerrEdit').html(''); var form_data = new FormData(); form_data.append("t_no", t_no); $('#Edit_t_no').val(t_no); $.ajax({ url: "ManageTreat_data_tno.php", cache: false, contentType: false, processData: false, dataType: 'text', data: form_data, type: 'post', success: function(data) { data = jQuery.parseJSON(data); $.each(data, function(index, value) { if(typeof value.t_name !== "undefined" && value.t_name !== null && value.t_name != "" ){ $('#Edit_patient').val(value.t_name); } if(typeof value.t_groupcase !== "undefined" && value.t_groupcase !== null && value.t_groupcase != "" ){ $('#Edit_case').val(value.t_groupcase); $('#Edit_case').selectpicker('destroy'); $('#Edit_case').selectpicker('render'); } CallEditDataGroup(); if(typeof value.t_treat_code !== "undefined" && value.t_treat_code !== null && value.t_treat_code != "" ){ $('#Edit_treat').val(value.t_treat_code); $('#Edit_treat').selectpicker('destroy'); $('#Edit_treat').selectpicker('render'); CallEditDataDoctor(value.t_treat_code); } if(typeof value.doctor_code !== "undefined" && value.doctor_code !== null && value.doctor_code != "" ){ $('#Edit_doctor_code').val(value.doctor_code); $('#Edit_doctor_code').selectpicker('destroy'); $('#Edit_doctor_code').selectpicker('render'); } if(typeof value.t_case !== "undefined" && value.t_case !== null && value.t_case != "" ){ $('#Edit_t_case').val(value.t_case); } }); }, error: function(data){ showFailAlert(data); } }); } function CallEditDataGroup(){ $.ajax({ url: "ManageTreat_treat_group_data.php", async: false, cache: false, contentType: false, processData: false, type: 'post', success: function(data) { var option =""; var JsonData = JSON.parse(data); var resL = JsonData.length; for (var i = 0; i < resL; i++) { option=option+"<option value='"+JsonData[i]["treat_group_code"]+"'>"+JsonData[i]["treat_group_name"]+"</option>" ; } $('#Edit_treat').html(''); $('#Edit_treat').html("<option value='0' selected disabled>-- Select --</option>"+option); $('#Edit_treat').selectpicker('destroy'); $('#Edit_treat').selectpicker('render'); }, error: function(data){ $('#Edit_treat').html("<option value='0' selected disabled>-- Select --</option>"); $('#Edit_treat').selectpicker('destroy'); $('#Edit_treat').selectpicker('render'); } }); } function CallEditDataDoctor(sector){ $('#doctor_code').html(''); var form_data = new FormData(); form_data.append("treat_group", sector); $.ajax({ url: "ManageTreat_doctor_data.php", async: false, cache: false, contentType: false, processData: false, data: form_data, type: 'post', success: function(data) { var option =""; var JsonData = JSON.parse(data); var resL = JsonData.length; for (var i = 0; i < resL; i++) { option=option+"<option value='"+JsonData[i]["doctor_code"]+"'>"+JsonData[i]["doctor_name"] +"</option>" ; } if(resL>0){ $('#Edit_doctor_code').html("<option value='0' selected disabled>-- Select --</option>"+option); }else{ $('#Edit_doctor_code').html("<option value='0' selected disabled>-- Select --</option>"); } $('#Edit_doctor_code').selectpicker('destroy'); $('#Edit_doctor_code').selectpicker('render'); }, error: function(data){ $('#Edit_doctor_code').html("<option value='0' selected disabled>-- Select --</option>"); $('#Edit_doctor_code').selectpicker('destroy'); $('#Edit_doctor_code').selectpicker('render'); } }); } function TreatEditSave(){ var t_no = $('#Edit_t_no').val(); var patient = $('#Edit_patient').val(); var t_case = $('#Edit_t_case').val(); var tcase = $('#Edit_case option:selected').val(); var treatcode = $('#Edit_treat option:selected').val(); var treat = $('#Edit_treat option:selected').text(); var doctor_code = $('#Edit_doctor_code option:selected').val(); var t_doctor = $('#Edit_doctor_code option:selected').text(); var form_data = new FormData(); form_data.append("condition", "EditTreat"); form_data.append("Edit_t_no", t_no); form_data.append("Edit_patient", patient); form_data.append("Edit_t_treat_code", treatcode); form_data.append("Edit_treat", treat); form_data.append("Edit_tcase", tcase); form_data.append("Edit_t_case", t_case); form_data.append("Edit_doctor_code", doctor_code); form_data.append("Edit_t_doctor", t_doctor); form_data.append("CREATE_BY", "<?php echo $username; ?>"); if(patient!="" && tcase!="0" && doctor_code!="0" && treatcode!="0"){ $.ajax({ url: "ManageTreat_save.php", contentType: false, processData: false, data: form_data, dataType: "text", type: 'post', success: function(data) { $('#showerr').html(''); var j = 0; var err = ""; var JsonData = JSON.parse(data); var resL = JsonData['result'].length; for(var i =0; i< resL; i++){ if(typeof JsonData['result'][i]['ERR']!=="undefined" && JsonData['result'][i]['ERR']!==null ){ err = err + JsonData['result'][i]['ERR']; j++; } } if(j>0){ $('#showerrEdit').html(err); showFailAlert("แก้ไขไม่สำเร็จกรุณาตรวจสอบ Error"); }else{ $('#Edit_t_no').val(''); $('#Edit_patient').val(''); $('#Edit_case').val('0'); $('#Edit_treat').val('0'); $('#Edit_doctor_code').val('0'); $('#Edit_t_case').val(''); $('#closeModalAEdit').click(); showSuccessAlert("แก้ไขสำเร็จ"); CallData(); } } }); }else{ if(patient == ""){ showFailAlert("กรุณาใส่ชื่อผู้ป่วย"); } if(tcase=="0"){ showFailAlert("กรุณาเลือกเคส"); } if(doctor_code=="0"){ showFailAlert("กรุราเลือกแพทย์"); } if(treatcode=="0"){ showFailAlert("กรุณาเลือกแผนก"); } } } function CalldataDelete(t_no, t_name, t_treat, t_case, t_doctor, t_status){ $('#Delete_t_no').val(t_no); // ใช้สำหรับใส่เงื่อนไข WHERE $('#Delete_patient').html(t_name); $('#Delete_treat').html(t_treat); $('#Delete_case').html(t_case); $('#Delete_doctor_code').html(t_doctor); $('#Delete_t_case').html(t_doctor); } function TreatDeleteSave(){ var t_no = $('#Delete_t_no').val(); var form_data = new FormData(); form_data.append("condition", "DeleteTreat"); form_data.append("Delete_t_no", t_no); $.ajax({ url: "ManageTreat_save.php", contentType: false, processData: false, data: form_data, dataType: "text", type: 'post', success: function(data) { $('#showerr').html(''); var j = 0; var err = ""; var JsonData = JSON.parse(data); var resL = JsonData['result'].length; for(var i =0; i< resL; i++){ if(typeof JsonData['result'][i]['ERR']!=="undefined" && JsonData['result'][i]['ERR']!==null ){ err = err + JsonData['result'][i]['ERR']; j++; } } if(j>0){ $('#showerrDelete').html(err); showFailAlert("ลบไม่สำเร็จกรุณาตรวจสอบ Error"); }else{ $('#Delete_t_no').val(''); $('#Delete_patient').html(''); $('#Delete_case').html(''); $('#Delete_treat').html(''); $('#Delete_doctor_code').html(''); $('#Delete_t_case').html(''); $('#closeModalADelete').click(); showSuccessAlert("ลบสำเร็จ"); CallData(); } } }); } </script>

ManageTreat_save.php

<?php header('Content-Type: application/json'); date_default_timezone_set("Asia/Bangkok"); include('connectDBMS.php'); $UPDATE_AT = date("Y-m-d H:i:s"); $result = array(); $ACTION = $_POST['condition']; $CREATE_BY = $_POST['CREATE_BY']; if ($ConnDB) { try { switch($ACTION){ case "AddTreat": $t_name = $_POST['patient']; $t_groupcase = $_POST['tcase']; //ปกติ, ฉุกเฉิน $t_treat_code = $_POST['t_treat_code']; $t_treat = $_POST['treat']; $t_case = $_POST['t_case']; $doctor_code = $_POST['doctor_code']; $t_doctor = $_POST['t_doctor']; $sqlrundoc = "SELECT (CASE WHEN max(t_no) is null THEN 1 ELSE max(t_no)+1 END) as t_no FROM treat "; $rsr = sqlsrv_query($ConnDB, $sqlrundoc); $rr = sqlsrv_fetch_object($rsr); $t_no = $rr->t_no; $INSTREAT = "INSERT INTO treat (t_no, t_name, t_groupcase, t_treat_code, t_treat, t_datetime, t_case, doctor_code, t_doctor, t_status) values ( '$t_no','$t_name', '$t_groupcase', '$t_treat_code', '$t_treat','$UPDATE_AT', '$t_case', '$doctor_code','$t_doctor', 'ซักประวัติ' )"; $RSINS = sqlsrv_prepare($ConnDB, $INSTREAT); if (!$RSINS) { throw new Exception($INSTREAT); $result[] = array("ERR" => $INSTREAT, "CSS" => "text-danger"); } if (!sqlsrv_execute($RSINS)) { throw new Exception( $INSTREAT); $result[] = array("ERR" => $INSTREAT, "CSS" => "text-danger"); } break; case "EditTreat": $t_no = $_POST['Edit_t_no']; $t_name = $_POST['Edit_patient']; $t_groupcase = $_POST['Edit_tcase']; //ปกติ, ฉุกเฉิน $t_treat_code = $_POST['Edit_t_treat_code']; $t_treat = $_POST['Edit_treat']; $t_case = $_POST['Edit_t_case']; $doctor_code = $_POST['Edit_doctor_code']; $t_doctor = $_POST['Edit_t_doctor']; $updtreat = "UPDATE treat SET t_name='$t_name', t_groupcase='$t_groupcase', t_treat_code='$t_treat_code', t_treat='$t_treat', t_case='$t_case' , doctor_code='$doctor_code' , t_doctor='$t_doctor' WHERE t_no ='$t_no' "; $rsupd = sqlsrv_query($ConnDB, $updtreat); if (!$rsupd) { throw new Exception($updtreat); $result[] = array("ERR" => $updtreat, "CSS" => "text-danger"); } break; case "DeleteTreat": $del_t_no = $_POST['Delete_t_no']; $deltreat = "DELETE FROM treat WHERE t_no='$del_t_no'"; $rsdel = sqlsrv_query($ConnDB, $deltreat); if (!$rsdel) { throw new Exception($deltreat); $result[] = array("ERR" => $deltreat, "CSS" => "text-danger"); } break; } } catch (Exception $ex) { $result[] = array("ERR" => $ex->getMessage(), "CSS" => "text-danger"); sqlsrv_rollback($ConnDB); sqlsrv_close($ConnDB); } sqlsrv_close($ConnDB); }else{ $result[] = array("ERR" =>"ERROR CONNECTION SQL", "CSS" => "text-danger"); } $json = array( 'result' => $result); echo json_encode($json, JSON_UNESCAPED_UNICODE); ?>

ManageTreat_data_tno.php

<?php include('connectDBMS.php'); $data = array(); $tno = $_POST['t_no']; $sql = "SELECT t_no ,t_name ,t_groupcase ,t_treat_code ,t_treat ,t_datetime ,t_case ,doctor_code ,t_doctor ,t_status FROM treat WHERE t_no = '$tno' order by t_no desc "; $rsc = sqlsrv_query($ConnDB, $sql); while($rowp = sqlsrv_fetch_object($rsc)) { $data[] = array( "t_no" => $rowp->t_no , "t_name" => $rowp->t_name , "t_groupcase" => $rowp->t_groupcase , "t_treat_code"=> $rowp->t_treat_code , "t_treat" => $rowp->t_treat , "t_datetime" => $rowp->t_datetime , "t_case" => $rowp->t_case , "doctor_code" => $rowp->doctor_code , "t_doctor" => $rowp->t_doctor , "t_status" => $rowp->t_status ); } echo json_encode($data, JSON_UNESCAPED_UNICODE); sqlsrv_close($ConnDB); ?>