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(); }
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 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 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 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; } } } }