protected void GridView_StartRowEditing(object sender, DevExpress.Web.Data.ASPxStartRowEditingEventArgs e) { int fileID = Convert.ToInt32(e.EditingKeyValue); Session["FileID"] = fileID; using (PDFEntities entities = new PDFEntities()) { tblPDF_FileData file = entities.tblPDF_FileData.SingleOrDefault(x => x.ID == fileID); if (file.IsLock || file.IsClose) { Show("File PDF đã khóa hoặc đóng, không thể chỉnh sửa!"); e.Cancel = true; return; } if (Session["GroupID"].ToString() != "QL" && Session["UserName"].ToString() != file.UpdatedUser) { Show("Bạn không phải người cập nhật hoặc không thuộc nhóm quản lý nên không thể chỉnh sửa!"); e.Cancel = true; return; } BindData(file); popFile.ShowOnPageLoad = true; e.Cancel = true; } }
private void BindData(tblPDF_FileData file) { cbbBranch.Value = file.BranchID; cbbType.Value = file.TypeID; txtNhom.Value = file.GroupAccess; txtShortContent.Text = file.ShortContent; cbbType.IsValid = txtNhom.IsValid = txtShortContent.IsValid = true; }
protected void btnSave_Click(object sender, EventArgs e) { tblPDF_FileData file = null; tblDM_User user = Session["User"] as tblDM_User; using (PDFEntities entities = new PDFEntities()) { if (Session["FileID"] == null) { file = new tblPDF_FileData(); } else { int fileID = Convert.ToInt32(Session["FileID"]); file = entities.tblPDF_FileData.SingleOrDefault(x => x.ID == fileID); } if (txtFile.UploadedFiles[0].FileName == "") { if (Session["FileID"] == null) { Show("Bạn phải chọn file pdf!"); return; } } else { file.FileName = txtFile.UploadedFiles[0].FileName; } file.BranchID = cbbBranch.Value.ToString(); file.TypeID = cbbType.Value.ToString(); file.ShortContent = txtShortContent.Text; file.GroupAccess = txtNhom.Value.ToString(); file.UpdatedUser = user.UserName; file.UpdatedDate = DateTime.Today; file.IsLock = false; file.IsClose = false; if (file.ID == 0) { entities.tblPDF_FileData.Add(file); } entities.SaveChanges(); if (txtFile.UploadedFiles[0].FileName != "") { txtFile.UploadedFiles[0].SaveAs(Server.MapPath("~/Files") + "\\" + file.ID + ".pdf"); } } // ResetForm(); popFile.ShowOnPageLoad = false; GridView.DataBind(); }
private void BindIdeas(int fileID) { using (PDFEntities entities = new PDFEntities()) { tblPDF_FileData file = entities.tblPDF_FileData.SingleOrDefault(x => x.ID == fileID); txtIdeas.Text = file.Idea; if (txtIdeas.Text.EndsWith("\n")) { txtIdeas.Text = txtIdeas.Text.Substring(0, txtIdeas.Text.Length - 1); } ConfigbtnLock(file.IsLock); } }
protected void btnLock_Click(object sender, EventArgs e) { int fileID = Convert.ToInt32(Session["FileID"]); using (PDFEntities entities = new PDFEntities()) { tblPDF_FileData file = entities.tblPDF_FileData.SingleOrDefault(x => x.ID == fileID); file.IsLock = !file.IsLock; file.LockDate = DateTime.Today; file.LockUser = (Session["User"] as tblDM_User).UserName; entities.SaveChanges(); ConfigbtnLock(file.IsLock); } }
protected void btnClose_Click(object sender, EventArgs e) { int fileID = Convert.ToInt32(Session["FileID"]); using (PDFEntities entities = new PDFEntities()) { tblPDF_FileData file = entities.tblPDF_FileData.SingleOrDefault(x => x.ID == fileID); file.IsClose = true; file.CloseDate = DateTime.Today; file.CLoseUser = (Session["User"] as tblDM_User).UserName; entities.SaveChanges(); } treeView.RefreshVirtualTree(); ltEmbed.Text = ""; Session["FileID"] = null; divContent.Visible = false; }
protected void Page_Load(object sender, EventArgs e) { if (Session["User"] == null) { if (Request.Params["DocID"] == null) { Response.Redirect("~/Account/SignIn.aspx"); } else { Response.Redirect("~/Account/SignIn.aspx?DocID=" + Request.Params["DocID"]); } } string groupID = Session["GroupID"].ToString(); btnLock.Visible = groupID == "QL"; btnClose.Visible = "QL,AD".Contains(groupID); if (!Page.IsPostBack) { if (Int32.TryParse(Request.Params["DocID"], out int docID)) { using (PDFEntities entities = new PDFEntities()) { tblPDF_FileData file = entities.tblPDF_FileData.SingleOrDefault(x => x.ID == docID); if ("QL,AD".Contains(groupID) || file.GroupAccess.Contains(Session["GroupID"].ToString())) { string embed = "<object data=\"{0}\" type=\"application/pdf\" width=\"100%\" height=\"450px\">"; embed += "Nếu bạn không thể xem file, bạn có thể tải file tại <a href = \"{0}\">đây</a>"; embed += " hoặc tải về <a target = \"_blank\" href = \"http://get.adobe.com/reader/\">Adobe PDF Reader</a> để xem file."; embed += "</object>"; ltEmbed.Text = string.Format(embed, ResolveUrl("~/Files/" + docID + ".pdf")); Session["FileID"] = docID; BindIdeas(docID); divContent.Visible = true; } else { ltEmbed.Text = "Bạn không có quyền truy cập file này!"; Session["FileID"] = null; divContent.Visible = false; } } } } }
protected void GridView_RowDeleting(object sender, DevExpress.Web.Data.ASPxDataDeletingEventArgs e) { int key = Convert.ToInt32(e.Keys[0]); using (PDFEntities entities = new PDFEntities()) { tblPDF_FileData file = entities.tblPDF_FileData.SingleOrDefault(x => x.ID == key); if (file.IsLock || file.IsClose) { e.Cancel = true; Show("File PDF đã khóa hoặc đóng, không thể xóa!"); } else if (Session["GroupID"].ToString() != "QL" && Session["UserName"].ToString() != file.UpdatedUser) { e.Cancel = true; Show("Bạn không phải người cập nhật hoặc không thuộc nhóm quản lý nên không thể xóa!"); } } }
protected void btnSave_Click(object sender, EventArgs e) { if (txtIdea.Text.Length + txtMailAddress.Text.Length == 0) { Show("Bạn phải nhập nội dung ý kiến hoặc địa chỉ mail!"); return; } try { if (txtIdea.Text.Length > 0) { using (PDFEntities entities = new PDFEntities()) { int fileID = Convert.ToInt32(Session["FileID"]); tblPDF_FileData file = entities.tblPDF_FileData.SingleOrDefault(x => x.ID == fileID); file.Idea = file.Idea + " - " + (Session["User"] as tblDM_User).UserName + " (" + DateTime.Now.ToString("dd/MM/yyyy hh:mm") + "): " + txtIdea.Text + "\n"; //tblPDF_Idea idea = new tblPDF_Idea(); //idea.FileID = Convert.ToInt32(Session["FileID"]); //idea.IdeaContent = txtIdea.Text; //idea.IdeaDate = DateTime.Now; //idea.IdeaUser = (Session["User"] as tblDM_User).UserName; //entities.tblPDF_Idea.Add(idea); entities.SaveChanges(); BindIdeas(Convert.ToInt32(Session["FileID"])); txtIdea.Text = ""; } } if (txtMailAddress.Text.Length > 0) { SendMail(); } } catch (Exception exx) { Show("Có lỗi xảy ra:" + exx.Message); } }
protected void SendMail() { MailAddress fromAddress = new MailAddress(ConfigurationManager.AppSettings["User"].ToString(), "Thông báo khu vực V"); string fromPassword = ConfigurationManager.AppSettings["Password"].ToString(); string host = ConfigurationManager.AppSettings["MailServer"].ToString(); int port = Convert.ToInt32(ConfigurationManager.AppSettings["Port"]); List <MailAddress> listMail = new List <MailAddress>(); string[] mails = txtMailAddress.Value.ToString().Split(','); foreach (string item in mails) { listMail.Add(new MailAddress(item)); } string subject = ""; string body = ""; int fileID = Convert.ToInt32(Session["FileID"]); using (PDFEntities entities = new PDFEntities()) { tblPDF_FileData file = entities.tblPDF_FileData.SingleOrDefault(x => x.ID == fileID); string branchName = entities.tblDM_Branch.SingleOrDefault(z => z.BranchID == file.BranchID).BranchName; subject = "Thông báo tài liệu: " + branchName; body = "Có thông báo từ văn bản " + branchName + "\\" + entities.tblDM_Type.SingleOrDefault(x => x.TypeID == file.TypeID).TypeName + "\\" + file.FileName + " - Ngày: " + DateTime.Now.ToString("dd/MM/yyy hh:mm") + "<br/> Nội dung tóm tắt: " + file.ShortContent + "<br/> Click vào <a href='" + (Request.Url.AbsoluteUri.Contains("?DocID")? Request.Url.AbsoluteUri.Substring(0, Request.Url.AbsoluteUri.IndexOf("?") + 1) : Request.Url.AbsoluteUri) + "?DocID=" + file.ID + "'> đây </a> để xem chi tiết file"; var smtp = new SmtpClient { Host = host, Port = port, EnableSsl = true, DeliveryMethod = SmtpDeliveryMethod.Network, UseDefaultCredentials = false, Credentials = new NetworkCredential(fromAddress.Address, fromPassword) }; using (var message = new MailMessage() { From = fromAddress, Subject = subject, Body = body, IsBodyHtml = true }) { try { foreach (var item in listMail) { message.To.Add(item); } smtp.Send(message); file.Idea = file.Idea + " - " + (Session["User"] as tblDM_User).UserName + " - " + txtMailAddress.Value + " - " + DateTime.Now.ToString("dd/MM/yyyy hh:mm") + "\n"; entities.SaveChanges(); BindIdeas(Convert.ToInt32(Session["FileID"])); Show("Gửi mail thành công!"); } catch (Exception ex) { throw ex; } } } }