ddready – แพ็ครวม django + bootstrap4 + crispy form + docker พร้อมใช้งาน

สำหรับใครที่อยากจะลองพัฒนา Web Application ด้วย django web framework ผมได้รวบรวมเป็นชุดเริ่มต้น ซึ่งจะสามารถสร้าง Responsive Web และ มีแบบฟอร์มที่สวยงามด้วย crispy form มาเรียบร้อย ใช้งานได้ทั้ง แบบ Python บนเครื่อง และ แบบ Docker ลองทำตามดูได้ครับ Repository สามารถเปิด URL ต่อไปนี้ เพื่อไป Download หรือ จะใช้ git clone ก็ได้ https://github.com/nagarindkx/ddready.git https://gitlab.psu.ac.th/kanakorn.h/ddready.git จากนั้น ให้เปิด cmd ไปยังตำแหน่งที่ clone ลงมา สำหรับผู้ที่ติดตั้ง python อยู่แล้ว แล้วใช้คำสั่งต่อไปนี้ สำหรับผู้ที่จะใช้ Docker บน Windows ใช้คำสั่งต่อไปนี้ ทดสอบใช้งาน http://localhost:8080 ในตอนต่อไป จะแนะนำวิธีการสร้าง แบบสอบถาม ทดแทนการใช้ Google Forms ครับ

Read More »

Download multiple files as Zip Archive (Compressed) file in ASP.Net MVC

ในบทความนี้จะขอกล่าวถึงการ  download file ครั้งละหลายๆไฟล์ โดยมีการระบุว่าต้องการ   download file ใดบ้าง โดย  ผู้ใช้สามารถกดเลือกได้ทั้งละหลายๆไฟล์ หรือไฟล์เดียว แล้วแต่ความต้องการของผู้ใช้งาน โดยหลังจากที่มีการกดปุ่มแล้วระบบจะทำการ zip ไฟล์รวมเป็น 1 ไฟล์ โดยในบทความนี้จะขอเสนอวิธีการพัฒนาโดยใช้ ASP.NET  ในรูปแบบ MVC ค่ะ     ในส่วนของ java script function DownloadFiles() { var items = []; $(“input:checkbox[name=chkThis]:checked”).each(function () { items.push($(this).val());   });   if (items.length <= 0) { alert(‘กรุณาเลือกข้อมูลที่ต้องการ Download ด้วยค่ะ/ครับ!!’); } else { $.ajax({ type: ‘POST’, contentType: ‘application/json; charset=utf-8’, url: ‘@Url.Action(“DownloadAndZipFile”, “NoteUpload”)’, data: JSON.stringify({ fileItemsAll: items }), success: function (resultDownload) { //window.location = ‘/NoteUpload/Download?fileGuid=’ + resultDownload.FileGuid //                   + ‘&filename=’ + resultDownload.FileName; window.location = ‘/NoteUpload/Download?fileGuid=’ + resultDownload.FileGuid; }, error: function (data) { alert(data); } }); } //   return items; } ในส่วนของ controller public ActionResult DownloadAndZipFile(IEnumerable<int> fileItemsAll) { if (!(ViewBag.IsAuthorized = (azResult = azService.Authorize(AccountingOperation.NoteUploadReader, this).Result).IsAuthorize)) { Danger(string.Format(“ไม่มีสิทธิ์ใช้งานในส่วนนี้: {0} ({1})”, azResult.Operation.OP_NAME, Convert.ToString(azResult.OperationEnum))); return View(); }   string handle = Guid.NewGuid().ToString(); MemoryStream output = new MemoryStream();   var zipMs = new MemoryStream(); string strZipName = “Accounting” + DateTime.Now.ToString(“yyyyMMdd”);   TempData[handle] = fileItemsAll;   var resultDownload = new { FileGuid = handle, FileName = strZipName + “.zip” }; return this.Json(resultDownload, JsonRequestBehavior.AllowGet); }   public FileResult Download(string fileGuid) { if (!(ViewBag.IsAuthorized = (azResult = azService.Authorize(AccountingOperation.NoteUploadReader, this).Result).IsAuthorize)) { Danger(string.Format(“ไม่มีสิทธิ์ใช้งานในส่วนนี้: {0} ({1})”, azResult.Operation.OP_NAME, Convert.ToString(azResult.OperationEnum))); return null; }   var zipMs = new MemoryStream(); string zipFisYear, zipPeriod, fileC, FileF, FileFinance,

Read More »