protected void btnSave_Click(object sender, EventArgs e) { List <string> results = new List <string>(); try { if (ValidateInput()) { string noticeFolder = AppConstant.NoticeFolder; if (string.IsNullOrEmpty(noticeFolder)) { throw new Exception("ไม่พบ NoticeFolder(ข้อมูลประกาศ) ใน File Config"); } string physicalPath = Server.MapPath(noticeFolder); results = NoticeBiz.InsertData(txtTopic.Text.Trim(), physicalPath, noticeFolder, fuImage.FileName, fuImage.PostedFile.ContentLength, fuAttachFile.FileName, (fuAttachFile.PostedFile != null ? fuAttachFile.PostedFile.ContentLength : 0), rbActive.Checked, HttpContext.Current.User.Identity.Name); string mainFolder = Path.Combine(physicalPath, results[0]); //results[0] = noticeId if (!Directory.Exists(mainFolder)) { Directory.CreateDirectory(mainFolder); } if (fuImage.HasFile && !string.IsNullOrEmpty(results[1])) { fuImage.SaveAs(results[1]); } if (fuAttachFile.HasFile && !string.IsNullOrEmpty(results[2])) { fuAttachFile.SaveAs(results[2]); } //ClearPopupControl(); //DoSearchNotice(0); //AppUtil.ClientAlert(Page, "บันทึกข้อมูลเรียบร้อย"); AppUtil.ClientAlertAndRedirect(Page, "บันทึกข้อมูลเรียบร้อย", "SLM_SCR_021.aspx"); } else { mpePopup.Show(); } } catch (Exception ex) { string message = ex.InnerException != null ? ex.InnerException.Message : ex.Message; _log.Debug(message); if (results.Count > 0 && !string.IsNullOrEmpty(results[0])) { NoticeBiz.DeleteData(int.Parse(results[0])); } AppUtil.ClientAlert(Page, message); } }
protected void imbEdit_Click(object sender, ImageClickEventArgs e) { try { var notice = NoticeBiz.GetNotice(((ImageButton)sender).CommandArgument); txtNoticeIdEdit.Text = notice.NoticeId.ToString(); txtTopicEdit.Text = notice.Topic; rbActiveEdit.Checked = notice.ActiveStatus == "Y" ? true : false; rbInactiveEdit.Checked = notice.ActiveStatus == "Y" ? false : true; txtEditAttachFileFlag.Text = ""; if (!string.IsNullOrEmpty(notice.ImageName)) { lbAttachImageEdit.Text = notice.ImageName; lbAttachImageEdit.OnClientClick = AppUtil.GetNoticeDownloadScript(Page, notice.ImageVirtualPath, "preview"); lbAttachImageEdit.CommandArgument = notice.ImagePhysicalPath; //เก็บไว้ใช้ตอนลบไฟล์ divImageInfoEdit.Style["display"] = "block"; divImageUploadEdit.Style["display"] = "none"; } else { divImageInfoEdit.Style["display"] = "none"; divImageUploadEdit.Style["display"] = "block"; } if (!string.IsNullOrEmpty(notice.FileName)) { lbAttachFileEdit.Text = notice.FileName; lbAttachFileEdit.OnClientClick = AppUtil.GetNoticeDownloadScript(Page, notice.FileVirtualPath, "downlaodfile"); lbAttachFileEdit.CommandArgument = notice.FilePhysicalPath; //เก็บไว้ใช้ตอนลบไฟล์ divFileInfoEdit.Style["display"] = "block"; divFileUploadEdit.Style["display"] = "none"; } else { divFileInfoEdit.Style["display"] = "none"; divFileUploadEdit.Style["display"] = "block"; txtEditAttachFileFlag.Text = "edit"; } mpePopupEdit.Show(); } catch (Exception ex) { string message = ex.InnerException != null ? ex.InnerException.Message : ex.Message; _log.Debug(message); AppUtil.ClientAlert(Page, message); } }
protected void lbNoticeShowAll_Click(object sender, EventArgs e) { try { gvNotice.DataSource = NoticeBiz.SearchNotice("", "", "", true, false); gvNotice.DataBind(); lblTotalNotice.Text = "ทั้งหมด <font class='hilightGreen'><b>" + gvNotice.Rows.Count.ToString("#,##0") + "</b></font> รายการ"; upNoticeAll.Update(); mpeNoticeAll.Show(); } catch (Exception ex) { string message = ex.InnerException != null ? ex.InnerException.Message : ex.Message; _log.Debug(message); AppUtil.ClientAlert(Page, message); } }
private void DisplayNotice() { try { Random rnd = new Random(); var list = NoticeBiz.GetNoticeIdList(); if (list.Count > 0) { int index = rnd.Next(0, list.Count); //creates a number between 0 and list.Count - 1 var notice = NoticeBiz.GetNotice(list[index].ToString()); lblNoticeTopic.Text = notice.Topic; imgNotice.ImageUrl = Page.ResolveUrl("~" + notice.ImageVirtualPath); if (!string.IsNullOrEmpty(notice.FileName)) { imbNoticeDownload.Visible = true; imbNoticeDownload.OnClientClick = AppUtil.GetNoticeDownloadScript(Page, notice.FileVirtualPath, "downloadfile"); //lbNoticeDownload.Text = notice.FileName; //lbNoticeDownload.OnClientClick = AppUtil.GetNoticeDownloadScript(Page, notice.FileVirtualPath, "downloadfile"); } else { imbNoticeDownload.Visible = false; //lbNoticeDownload.Text = "ไม่พบไฟล์เอกสาร"; //lbNoticeDownload.Enabled = false; } } else { trNoticeDownload.Visible = false; trNoticeDownloadAll.Visible = false; } } catch (Exception ex) { throw ex; } }
private void DoSearchNotice(int pageIndex) { try { string createDateFrom = ""; string createDateTo = ""; if (tdmCreateDateFrom.DateValue.Year != 1) { createDateFrom = tdmCreateDateFrom.DateValue.Year.ToString() + tdmCreateDateFrom.DateValue.ToString("-MM-dd"); } if (tdmCreateDateTo.DateValue.Year != 1) { createDateTo = tdmCreateDateTo.DateValue.Year.ToString() + tdmCreateDateTo.DateValue.ToString("-MM-dd"); } List <NoticeData> list = NoticeBiz.SearchNotice(txtTopicSearch.Text.Trim(), createDateFrom, createDateTo, cbActive.Checked, cbInActive.Checked); BindGridview(pcTop, list.ToArray(), pageIndex); } catch (Exception ex) { throw ex; } }
//================================= Popup Edit ===================================================== protected void btnSaveEdit_Click(object sender, EventArgs e) { try { if (ValidateEdit()) { string noticeFolder = AppConstant.NoticeFolder; if (string.IsNullOrEmpty(noticeFolder)) { throw new Exception("ไม่พบ NoticeFolder(ข้อมูลประกาศ) ใน File Config"); } string physicalPath = Server.MapPath(noticeFolder); //bool updateImage = divImageUploadEdit.Style["display"] == "block" ? true : false; //fuImageEdit.Visible; //bool updateFile = divFileUploadEdit.Style["display"] == "block" ? true : false; //fuAttachFileEdit.Visible; bool updateImage = fuImageEdit.HasFile; bool updateFile = txtEditAttachFileFlag.Text.Trim() == "edit" ? true : false; List <string> results = NoticeBiz.UpdateData(int.Parse(txtNoticeIdEdit.Text.Trim()), txtTopicEdit.Text.Trim(), physicalPath, noticeFolder , fuImageEdit.FileName, (fuImageEdit.HasFile ? fuImageEdit.PostedFile.ContentLength : 0) , fuAttachFileEdit.FileName, (fuAttachFileEdit.HasFile ? fuAttachFileEdit.PostedFile.ContentLength : 0), rbActiveEdit.Checked, HttpContext.Current.User.Identity.Name, updateImage, updateFile); //Delete ไฟล์เก่า if (updateImage && !string.IsNullOrEmpty(lbAttachImageEdit.CommandArgument)) { File.Delete(lbAttachImageEdit.CommandArgument); //ลบไฟล์เก่า } if (updateFile && !string.IsNullOrEmpty(lbAttachFileEdit.CommandArgument)) { File.Delete(lbAttachFileEdit.CommandArgument); //ลบไฟล์เก่า } //Save ไฟล์ใหม่ string mainFolder = Path.Combine(physicalPath, results[0]); //results[0] = noticeId if (!Directory.Exists(mainFolder)) { Directory.CreateDirectory(mainFolder); } if (updateImage && fuImageEdit.HasFile && !string.IsNullOrEmpty(results[1])) { fuImageEdit.SaveAs(results[1]); } if (updateFile && fuAttachFileEdit.HasFile && !string.IsNullOrEmpty(results[2])) { fuAttachFileEdit.SaveAs(results[2]); } //ClearPopupEditControl(); //DoSearchNotice(0); //AppUtil.ClientAlert(Page, "บันทึกข้อมูลเรียบร้อย"); AppUtil.ClientAlertAndRedirect(Page, "บันทึกข้อมูลเรียบร้อย", "SLM_SCR_021.aspx"); } else { mpePopupEdit.Show(); } } catch (Exception ex) { string message = ex.InnerException != null ? ex.InnerException.Message : ex.Message; _log.Debug(message); AppUtil.ClientAlert(Page, message); } }