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; } }
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 AddBranchNode(PDFEntities entities, List <TreeViewVirtualNode> children) { var branchs = entities.tblDM_Branch.Where(x => x.IsEnable == true); foreach (var branch in branchs) { TreeViewVirtualNode childNode = new TreeViewVirtualNode("B_" + branch.BranchID, branch.BranchName); childNode.IsLeaf = false; childNode.Image.IconID = BranchImageIcon; children.Add(childNode); } }
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); } }
private void AddTypeNode(PDFEntities entities, List <TreeViewVirtualNode> children, string branch, bool isQL = true) { string groupID = Session["GroupID"].ToString(); var types = entities.tblPDF_FileData.Where(z => z.BranchID == branch && (isQL || z.GroupAccess.Contains(groupID))).Select(x => x.TypeID).Distinct(); foreach (var type in types) { TreeViewVirtualNode childNode = new TreeViewVirtualNode(branch + "_" + type, entities.tblDM_Type.Single(x => x.TypeID == type).TypeName); childNode.IsLeaf = false; childNode.Image.IconID = TypeImageIcon; children.Add(childNode); } }
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); } }
private void AddBranchNode1(PDFEntities entities, List <TreeViewVirtualNode> children) { string branchU = Session["BranchID"].ToString(); string groupID = Session["GroupID"].ToString(); var branchs = entities.tblPDF_FileData.Where(z => z.BranchID == branchU || z.GroupAccess.Contains(groupID)).Select(x => x.BranchID).Distinct(); foreach (var branch in branchs) { TreeViewVirtualNode childNode = new TreeViewVirtualNode("B_" + branch, entities.tblDM_Branch.FirstOrDefault(z => z.BranchID == branch).BranchName); childNode.IsLeaf = false; childNode.Image.IconID = BranchImageIcon; children.Add(childNode); } }
private void AddFileNode(PDFEntities entities, List <TreeViewVirtualNode> children, string branch_type, bool isQL = true) { string groupID = Session["GroupID"].ToString(); //string type = branch_type.Substring(branch_type.IndexOf('_') + 1); //string branch = branch_type.Substring(0, branch_type.IndexOf('_')); var files = entities.tblPDF_FileData.Where(x => (x.BranchID + "_" + x.TypeID) == branch_type && (isQL || x.GroupAccess.Contains(groupID)) && x.IsClose == false).OrderByDescending(z => z.UpdatedDate); foreach (var file in files) { TreeViewVirtualNode childNode = new TreeViewVirtualNode(file.ID.ToString(), file.UpdatedDate.ToShortDateString() + " - " + file.FileName); childNode.IsLeaf = true; childNode.Image.IconID = PDFImageIcon; children.Add(childNode); } }
public static tblDM_User SignIn(string userName, string password) { using (PDFEntities entities = new PDFEntities()) { string passMd5 = GetMD5(password); tblDM_User user = entities.tblDM_User.FirstOrDefault(z => z.UserName == userName && z.Pass == passMd5 && z.IsLock == false); HttpContext.Current.Session["User"] = user; if (user != null) { HttpContext.Current.Session["UserName"] = user.UserName; HttpContext.Current.Session["GroupID"] = user.GroupID; HttpContext.Current.Session["BranchID"] = user.BranchID; } return(user); } }
protected void GridView_CustomCallback(object sender, ASPxGridViewCustomCallbackEventArgs e) { if (e.Parameters == "ResetPass") { string userName = GridView.GetRowValues(GridView.FocusedRowIndex, "UserName").ToString(); using (PDFEntities entities = new PDFEntities()) { tblDM_User user = entities.tblDM_User.SingleOrDefault(x => x.UserName == userName); user.Pass = AuthHelper.GetMD5("123456"); entities.SaveChanges(); } GridView.DataBind(); throw new Exception("Reset thành công!"); } }
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 (txtPass1.Text != txtPass2.Text) { Show("Mật khẩu mới và nhập lại mật khẩu không khớp"); return; } tblDM_User user = Session["User"] as tblDM_User; using (PDFEntities entities = new PDFEntities()) { tblDM_User UserUpdate = entities.tblDM_User.SingleOrDefault(x => x.UserName == user.UserName); UserUpdate.Pass = AuthHelper.GetMD5(txtPass1.Text); entities.SaveChanges(); } Show("Đổi mật khẩu thành công!"); popChangePass.ShowOnPageLoad = false; }
protected void treeView_VirtualModeCreateChildren(object sender, TreeViewVirtualModeCreateChildrenEventArgs e) { List <TreeViewVirtualNode> children = new List <TreeViewVirtualNode>(); using (PDFEntities entities = new PDFEntities()) { if (Session["GroupID"].ToString() != "QL") { if (e.NodeName == null) { AddBranchNode1(entities, children); } else if (e.NodeName.Substring(0, 2) == "B_") { AddTypeNode(entities, children, e.NodeName.Substring(2), false); } else { AddFileNode(entities, children, e.NodeName); } } else { if (e.NodeName == null) { AddBranchNode(entities, children); } else if (e.NodeName.Substring(0, 2) == "B_") { AddTypeNode(entities, children, e.NodeName.Substring(2)); } else { AddFileNode(entities, children, e.NodeName); } } } e.Children = children; }
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 btnPrintAll_Click(object sender, EventArgs e) { int fileID = Convert.ToInt32(Session["FileID"]); string filePath = Server.MapPath("Files/" + Session["FileID"] + ".pdf"); string tempPath = filePath.Replace(".pdf", "_" + Session["UserName"] + ".pdf"); string yKienPath = filePath.Replace(".pdf", "_" + Session["UserName"] + "_YKien.pdf"); //Ý kién System.IO.FileStream output = new System.IO.FileStream(yKienPath, FileMode.Create); using (PDFEntities entities = new PDFEntities()) { var file = entities.tblPDF_FileData.Where(x => x.ID == fileID).ToList(); //branchName = entities.tblDM_Branch.SingleOrDefault(x => x.BranchID == file.BranchID).BranchName; //typeName = entities.tblDM_Type.SingleOrDefault(x => x.TypeID == file.TypeID).TypeName; VerticalGrid.DataSource = file; VerticalGrid.DataBind(); VerticalGrid.ExportToPdf(output); output.Close(); PdfDocument pdfyKien = new PdfDocument(new PdfReader(yKienPath)); File.Copy(filePath, tempPath, true); PdfDocument pdf = new PdfDocument(new PdfReader(filePath), new PdfWriter(tempPath)); pdfyKien.CopyPagesTo(1, 1, pdf); pdf.Close(); Response.ContentType = "Application/pdf"; Response.AppendHeader("content-disposition", "attachment; filename=" + file[0].FileName.Replace(" ", "_")); Response.WriteFile(tempPath); Response.End(); } //PdfDocument pdfyKien = new PdfDocument(new PdfReader(yKienPath)); //File.Copy(filePath, tempPath, true); //PdfDocument pdf = new PdfDocument(new PdfReader(filePath), new PdfWriter(tempPath)); ////int index = pdf.GetNumberOfPages(); ////PageSize ps = new PageSize(pdf.GetFirstPage().GetPageSize()); ////PdfPage page = pdf.AddNewPage(index + 1, ps); //pdfyKien.CopyPagesTo(1,1, pdf); //pdf.Close(); //if (txtIdeas.Text.Length > 0) //{ // PdfDocument pdf = new PdfDocument(new PdfReader(filePath), new PdfWriter(tempPath)); // int index = pdf.GetNumberOfPages(); // PageSize ps = new PageSize(pdf.GetFirstPage().GetPageSize()); // PdfPage page = pdf.AddNewPage(index + 1, ps); // PdfCanvas canvas = new PdfCanvas(page); // string text = txtIdeas.Text; // //PdfFont font = PdfFontFactory.CreateFont(StandardFonts.TIMES_ROMAN); // //PdfFont bold = PdfFontFactory.CreateFont(StandardFonts.TIMES_BOLD); // //Paragraph p = new Paragraph().Add(text); // PdfFont font = PdfFontFactory.CreateFont(Environment.GetEnvironmentVariable("windir") + @"\fonts\ARIAL.TTF", PdfEncodings.IDENTITY_H, true); // int size = Convert.ToInt32(Math.Round(ps.GetWidth() / 600)) * 12; // float leading = size * 1.2f; // canvas.ConcatMatrix(1, 0, 0, 1, 0, ps.GetHeight()); // canvas.BeginText().SetFontAndSize(font, size).SetLeading(leading).MoveText(70, -40); // canvas.NewlineShowText("Danh sách các ý kiến: "); // foreach (var item in text.Split(new string[1] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries)) // { // if (item.Length > 90) // { // string items = item.Replace(",", ", "); // foreach (var texts in WordWrap(items, 90)) // { // canvas.NewlineShowText(texts); // } // } // else // { // canvas.NewlineShowText(item); // } // } // canvas.EndText(); // pdf.Close(); //using (PDFEntities entities = new PDFEntities()) //{ // tblPDF_FileData file = entities.tblPDF_FileData.SingleOrDefault(x => x.ID == fileID); // Response.ContentType = "Application/pdf"; // Response.AppendHeader("content-disposition", // "attachment; filename=" + file.FileName.Replace(" ","_")); // Response.WriteFile(tempPath); // Response.End(); //} //} }
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; } } } }
protected void btnPrintIdea_Click(object sender, EventArgs e) { int fileID = Convert.ToInt32(Session["FileID"]); string filePath = Server.MapPath("Files/" + Session["FileID"] + "_YKien.pdf"); //tblPDF_FileData file = null; //string branchName = ""; //string typeName = ""; using (PDFEntities entities = new PDFEntities()) { var file = entities.tblPDF_FileData.Where(x => x.ID == fileID).ToList(); //branchName = entities.tblDM_Branch.SingleOrDefault(x => x.BranchID == file.BranchID).BranchName; //typeName = entities.tblDM_Type.SingleOrDefault(x => x.TypeID == file.TypeID).TypeName; VerticalGrid.DataSource = file; VerticalGrid.DataBind(); VerticalGrid.ExportPdfToResponse("YKien.pdf", true); } //PdfDocument pdfDoc = new PdfDocument(new PdfWriter(filePath)); //Document doc = new Document(pdfDoc); //Table table = new Table(UnitValue.CreatePercentArray(2)).UseAllAvailableWidth(); //PdfFont font = PdfFontFactory.CreateFont(Environment.GetEnvironmentVariable("windir") + @"\fonts\ARIAL.TTF", PdfEncodings.IDENTITY_H, true); //table.SetFont(font); //// The complete cell is a link: //Cell cell11 = new Cell().Add(new Paragraph("Tên tệp: ")); //cell11.SetWidth(UnitValue.CreatePercentValue(30)); //table.AddCell(cell11); //Cell cell12 = new Cell().Add(new Paragraph(file.FileName)); //cell12.SetWidth(UnitValue.CreatePercentValue(70)); //table.AddCell(cell12); //Cell cell21 = new Cell().Add(new Paragraph("Đơn vị: ")); //cell21.SetWidth(UnitValue.CreatePercentValue(30)); //table.AddCell(cell21); //Cell cell22 = new Cell().Add(new Paragraph(branchName)); //cell22.SetWidth(UnitValue.CreatePercentValue(70)); //table.AddCell(cell22); //Cell cell31 = new Cell().Add(new Paragraph("Loại dữ liệu: ")); //cell31.SetWidth(UnitValue.CreatePercentValue(30)); //table.AddCell(cell31); //Cell cell32 = new Cell().Add(new Paragraph(typeName)); //cell32.SetWidth(UnitValue.CreatePercentValue(70)); //table.AddCell(cell32); //Cell cell41 = new Cell().Add(new Paragraph("Ngày cập nhật: ")); //cell41.SetWidth(UnitValue.CreatePercentValue(30)); //table.AddCell(cell41); //Cell cell42 = new Cell().Add(new Paragraph(file.UpdatedDate.ToShortDateString())); //cell42.SetWidth(UnitValue.CreatePercentValue(70)); //table.AddCell(cell42); //Cell cell51 = new Cell().Add(new Paragraph("Người cập nhật: ")); //cell51.SetWidth(UnitValue.CreatePercentValue(30)); //table.AddCell(cell51); //Cell cell52 = new Cell().Add(new Paragraph(file.UpdatedUser)); //cell52.SetWidth(UnitValue.CreatePercentValue(70)); //table.AddCell(cell52); //Cell cell61 = new Cell().Add(new Paragraph("Các ý kiến: ")); //cell61.SetWidth(UnitValue.CreatePercentValue(30)); //table.AddCell(cell61); //Cell cell62 = new Cell().Add(new Paragraph(file.Idea)); //cell62.SetWidth(UnitValue.CreatePercentValue(70)); //table.AddCell(cell62); //doc.Add(table); //doc.Close(); //Response.ContentType = "Application/pdf"; //Response.AppendHeader("content-disposition", // "attachment; filename=YKien.pdf"); //Response.WriteFile(filePath); //Response.End(); }