Advertisement
Guest User

Untitled

a guest
Jun 25th, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.70 KB | None | 0 0
  1. $(document).ready(function() {
  2. console.log("Machine loaded");
  3. $("#BtnSend").on("click", function() {
  4. AddMachine();
  5. });
  6. GetListMachine(0);
  7. HideInput();
  8. });
  9.  
  10. window.onscroll = function() {
  11. FunctionSticky()
  12. };
  13.  
  14. var navbar = document.getElementById("navbar");
  15. var sticky = navbar.offsetTop;
  16.  
  17. function FunctionSticky() {
  18. if (window.pageYOffset > sticky) {
  19. navbar.classList.add("sticky")
  20. // console.log(window.pageYOffset +"-"+sticky)
  21. } else {
  22. navbar.classList.remove("sticky");
  23. }
  24. }
  25.  
  26. function AddMachine() {
  27. if ($("#NumberHousehold").val()
  28. && $("#Name").val()
  29. && $("#Lifetime").val()
  30. && $("#PurchasePrice").val()
  31. && (($("#BuyFreshOrPay").val() == "ผ่อนจ่าย"
  32. && $("#TotalInstallments").val() && $("#YearPayment").val()
  33. && $("#DownPayment").val() && $("#PayperYear").val()) || $(
  34. "#BuyFreshOrPay").val() == "ซื้อสด")) {
  35.  
  36. $.ajax({
  37. url : "process/MachineProcess.php",
  38. method : "POST",
  39. data : {
  40. CMD : "ADD-Machine",
  41. NumberHousehold : $("#NumberHousehold").val(),
  42. Name : $("#Name").val(),
  43. Lifetime : $("#Lifetime").val(),
  44. PurchasePrice : $("#PurchasePrice").val(),
  45. BuyFreshOrPay : $("#BuyFreshOrPay").val(),
  46. TotalInstallments : $("#TotalInstallments").val(),
  47. YearPayment : $("#YearPayment").val(),
  48. DownPayment : $("#DownPayment").val(),
  49. PayperYear : $("#PayperYear").val()
  50. },
  51. success : function(result) {
  52. console.log(result);
  53. $("#Log").html(result);
  54. var obj = JSON.parse(result);
  55. if (obj.Success == 1 && obj.Error == 0) {
  56. $("#NumberHousehold").val("");
  57. $("#Name").val("");
  58. $("#Lifetime").val("");
  59. $("#PurchasePrice").val("");
  60. $("#BuyFreshOrPay").val("ซื้อสดหรือผ่อนจ่าย");
  61. $("#TotalInstallments").val("");
  62. $("#YearPayment").val("");
  63. $("#DownPayment").val("");
  64. $("#PayperYear").val("");
  65. HideInput();
  66. GetListMachine(1);
  67. } else if (obj.Success == 0 && obj.Error == 0) {
  68. swal("ไม่มีรหัสครัวเรือนนี้", "คลิก OK เพื่อออก", "error");
  69. } else {
  70. swal("การเพิ่มข้อมูลมีบางอย่างผิดพลาด", "คลิก OK เพื่อออก",
  71. "error");
  72. }
  73. },
  74. error : function(_jqXHR, _textStatus, _errorThrown) {
  75. console.log("Error Machine");
  76. swal("Ajax Error", "คลิก OK เพื่อออก", "error");
  77. }
  78. });
  79. } else {
  80. swal("กรุณากรอกขอมูลให้ครบถ้วน", "คลิก OK เพื่อออก", "error");
  81. }
  82. }
  83.  
  84. function DeleteMachine(IdMachine) {
  85. $.ajax({
  86. url : "process/MachineProcess.php",
  87. method : "POST",
  88. data : {
  89. CMD : "DELETE-Machine",
  90. IdMachine : IdMachine
  91. },
  92. success : function(result) {
  93. console.log(result);
  94. $("#Log").html(result);
  95. var obj = JSON.parse(result);
  96. if (obj.Error == 0) {
  97. GetListMachine(3);
  98. } else {
  99. swal("การลบข้อมูลมีบางอย่างผิดพลาด", "คลิก OK เพื่อออก",
  100. "error");
  101. }
  102. },
  103. error : function(_jqXHR, _textStatus, _errorThrown) {
  104. console.log("Error Delerte Machine")
  105. swal("Ajax Error", "คลิก OK เพื่อออก", "error");
  106. }
  107. });
  108. }
  109.  
  110. function EditMachine(IdMachine) {
  111. if ($("#NameModal").val()
  112. && $("#LifetimeModal").val()
  113. && $("#PurchasePriceModal").val()
  114. && (($("#BuyFreshOrPayModal").val() == "ผ่อนจ่าย"
  115. && $("#TotalInstallmentsModal").val()
  116. && $("#YearPaymentModal").val()
  117. && $("#DownPaymentModal").val() && $("#PayperYearModal")
  118. .val()) || $("#BuyFreshOrPayModal").val() == "ซื้อสด")) {
  119. $.ajax({
  120. url : "process/MachineProcess.php",
  121. method : "POST",
  122. data : {
  123. CMD : "EDIT-Machine",
  124. Name : $("#NameModal").val(),
  125. Lifetime : $("#LifetimeModal").val(),
  126. PurchasePrice : $("#PurchasePriceModal").val(),
  127. BuyFreshOrPay : $("#BuyFreshOrPayModal").val(),
  128. TotalInstallments : $("#TotalInstallmentsModal").val(),
  129. YearPayment : $("#YearPaymentModal").val(),
  130. DownPayment : $("#DownPaymentModal").val(),
  131. PayperYear : $("#PayperYearModal").val(),
  132. IdMachine : IdMachine
  133. },
  134. success : function(result) {
  135. console.log(result);
  136. $("#Log").html(result);
  137. var obj = JSON.parse(result);
  138. console.log("Error = " + obj.Error);
  139. if (obj.Error == 0) {
  140. GetListMachine(2);
  141. } else {
  142. swal("การแก้ไขข้อมูลมีบางอย่างผิดพลาด", "คลิก OK เพื่อออก",
  143. "error");
  144. }
  145. },
  146. error : function(_jqXHR, _textStatus, _errorThrown) {
  147. console.log("Error Edit Machine");
  148. swal("Ajax Error", "คลิก OK เพื่อออก", "error");
  149. }
  150. });
  151. } else {
  152. swal("กรุณากรอกขอมูลให้ครบถ้วน", "คลิก OK เพื่อออก", "error");
  153. }
  154. }
  155.  
  156. function GetListMachine(Numberfunction) {
  157.  
  158. $.ajax({
  159. url : "process/MachineProcess.php",
  160. method : "POST",
  161. data : {
  162. CMD : "GET-LIST-Machine"
  163. },
  164. success : function(result) {
  165. console.log(result);
  166. var obj = JSON.parse(result);
  167. console.log("Error = " + obj.Error);
  168. $("#Log").html(result);
  169. if (obj.Error == 0) {
  170. $("#Log").html("เพิ่มข้อมูลสำเร็จ");
  171. console.log(obj.Data[0]);
  172. if (typeof (table) != "undefined") {
  173. table.destroy();
  174. }
  175. table = $('#machinelist').DataTable({
  176. data : obj.Data,
  177. columns : [ {
  178. title : "Action"
  179. }, {
  180. tit
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement