/// <summary> /// Update existing {title}.xml file. /// </summary> /// <param name="oDocument"></param> /// <returns></returns> public bool BAL_Document_Update(MailDocument oDocument) { string DocumentPath = string.Empty; bool IsUpdateSuccess = false; try { DocumentPath = Path.Combine(oDocument.Documentpath, Convert.ToString(AppSessions.SchoolID)); using (XmlWriter writer = XmlWriter.Create(Path.Combine(DocumentPath, oDocument.Title + ".xml"))) { writer.WriteStartElement("Document"); writer.WriteElementString("title", oDocument.Title); writer.WriteElementString("body", oDocument.Body); writer.WriteEndElement(); writer.Flush(); } IsUpdateSuccess = true; } catch (Exception ex) { IsUpdateSuccess = false; } return(IsUpdateSuccess); }
protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { if (!string.IsNullOrEmpty(Request.QueryString["title"])) { oDocument_BLogic = new Document_BLogic(); oDocument = new MailDocument(); oDocument.Documentpath = Server.MapPath("~/Documents/AdmissionDocument"); oDocument.Title = Request.QueryString["title"]; ViewState["title"] = Request.QueryString["title"]; if (oDocument_BLogic.BAL_Document_CheckExists(oDocument)) { btnSubmit.Text = "Update"; lblTitle.Text = "Update Document"; DataTable oTable = oDocument_BLogic.BAL_Document_Select(oDocument); txttitle.Text = Convert.ToString(oTable.Rows[0]["title"]); txtmail.Content = Convert.ToString(oTable.Rows[0]["body"]); ViewState["Mode"] = "Update"; } else { ViewState["Mode"] = "Add"; } } else { ViewState["Mode"] = "Add"; } BindTagDropDown(); } }
protected void gvdocument_RowCommand(object sender, GridViewCommandEventArgs e) { BAL_Document = new Document_BLogic(); oDocument = new MailDocument(); oDocument.Documentpath = Server.MapPath("~/Documents/AdmissionDocument"); oDocument.Title = Convert.ToString(e.CommandArgument); if (e.CommandName == "documentedit") { Response.Redirect("AddDocument.aspx?title=" + Convert.ToString(e.CommandArgument) + ""); } else if (e.CommandName == "documentdelete") { bool status = BAL_Document.BAL_Document_Delete(oDocument); if (status) { ScriptManager.RegisterStartupScript(this, GetType(), "alertMessage", "alert('Document has been deleted successfully.');", true); BindGrid(); } else { ScriptManager.RegisterStartupScript(this, GetType(), "alertMessage", "alert('Document has been deleted failed.');", true); } } else if (e.CommandName == "documentview") { Response.Redirect("ViewDocument.aspx?title=" + Convert.ToString(e.CommandArgument) + ""); } }
protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { if (!string.IsNullOrEmpty(Request.QueryString["title"])) { oDocument_BLogic = new Document_BLogic(); oDocument = new MailDocument(); oDocument.Documentpath = Server.MapPath("~/Documents/AdmissionDocument"); oDocument.Title = Request.QueryString["title"]; ViewState["title"] = Request.QueryString["title"]; if (oDocument_BLogic.BAL_Document_CheckExists(oDocument)) { DataTable oTable = oDocument_BLogic.BAL_Document_Select(oDocument); txttitle.Text = Convert.ToString(oTable.Rows[0]["title"]); txttitle.Enabled = false; txtmail.Content = Convert.ToString(oTable.Rows[0]["body"]); txtmail.ActiveMode = AjaxControlToolkit.HTMLEditor.ActiveModeType.Preview; txtmail.Enabled = false; } } } }
private void BindGrid() { BAL_Document = new Document_BLogic(); oDocument = new MailDocument(); oDocument.Documentpath = Server.MapPath("~/Documents/AdmissionDocument"); gvdocument.DataSource = BAL_Document.BAL_Document_SelectALL(oDocument); gvdocument.DataBind(); }
protected void btnSubmit_Click(object sender, EventArgs e) { oDocument_BLogic = new Document_BLogic(); oDocument = new MailDocument(); oDocument.Documentpath = Server.MapPath("~/Documents/AdmissionDocument"); oDocument.Title = txttitle.Text; oDocument.Body = txtmail.Content; if (Convert.ToString(ViewState["Mode"]) == "Add") { if (!oDocument_BLogic.BAL_Document_CheckExists(oDocument)) { bool status = oDocument_BLogic.BAL_Document_Insert(oDocument); if (status) { Response.Redirect("ManageDocument.aspx"); } else { ScriptManager.RegisterStartupScript(this, GetType(), "alertMessage", "alert('Document has been added failed.');", true); } } else { ScriptManager.RegisterStartupScript(this, GetType(), "alertMessage", "alert('Document already exists.');", true); } } else if (Convert.ToString(ViewState["Mode"]) == "Update") { if (!oDocument_BLogic.BAL_Document_CheckExists(oDocument) || oDocument.Title == Convert.ToString(ViewState["title"])) { DeleteOldTemplate(); bool status = oDocument_BLogic.BAL_Document_Update(oDocument); if (status) { Response.Redirect("ManageDocument.aspx"); } else { ScriptManager.RegisterStartupScript(this, GetType(), "alertMessage", "alert('Document has been updated failed.');", true); } } else { ScriptManager.RegisterStartupScript(this, GetType(), "alertMessage", "alert('Document already exists.');", true); } } }
/// <summary> /// return true if {title}.xml file exists on document path /// </summary> /// <param name="oDocument"></param> /// <returns></returns> public bool BAL_Document_CheckExists(MailDocument oDocument) { string DocumentPath = Path.Combine(oDocument.Documentpath, Convert.ToString(AppSessions.SchoolID)); if (!Directory.Exists(DocumentPath)) { Directory.CreateDirectory(DocumentPath); } if (File.Exists(Path.Combine(DocumentPath, oDocument.Title + ".xml"))) { return(true); } else { return(false); } }
/// <summary> /// Delete {title}.xml file /// </summary> /// <param name="oDocument"></param> /// <returns></returns> public bool BAL_Document_Delete(MailDocument oDocument) { string DocumentPath = string.Empty; bool IsDeleteSuccess = false; try { DocumentPath = Path.Combine(oDocument.Documentpath, Convert.ToString(AppSessions.SchoolID)); if (File.Exists(Path.Combine(DocumentPath, oDocument.Title + ".xml"))) { File.Delete(Path.Combine(DocumentPath, oDocument.Title + ".xml")); } IsDeleteSuccess = true; } catch (Exception ex) { IsDeleteSuccess = false; } return(IsDeleteSuccess); }
/// <summary> /// Get List of All {title}.xml file from document path. /// </summary> /// <param name="oDocument"></param> /// <returns></returns> public DataTable BAL_Document_SelectALL(MailDocument oDocument) { string Templatepath = string.Empty; DataTable oTable = new DataTable(); oTable.Columns.Add("title", typeof(string)); oTable.Columns.Add("templetpath", typeof(string)); Templatepath = Path.Combine(oDocument.Documentpath, Convert.ToString(AppSessions.SchoolID)); if (!Directory.Exists(Templatepath)) { Directory.CreateDirectory(Templatepath); } foreach (string file in Directory.GetFiles(Templatepath, "*.xml", SearchOption.AllDirectories)) { oTable.Rows.Add(Path.GetFileNameWithoutExtension(file), file); } return(oTable); }
/// <summary> /// Select Document Datatable from {title}.xml file. /// </summary> /// <param name="oDocument"></param> /// <returns></returns> public DataTable BAL_Document_Select(MailDocument oDocument) { string Templatepath = string.Empty; DataTable oTable = new DataTable(); oTable.Columns.Add("title", typeof(string)); oTable.Columns.Add("body", typeof(string)); Templatepath = Path.Combine(oDocument.Documentpath, Convert.ToString(AppSessions.SchoolID)); XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(Path.Combine(Templatepath, oDocument.Title + ".xml")); XmlNode oNode = xmlDoc.DocumentElement; oTable.Rows.Add(oNode.SelectSingleNode("title").InnerText, oNode.SelectSingleNode("body").InnerText); return(oTable); }
/// <summary> /// Generate Document And Add it in list. /// </summary> /// <param name="documentList"></param> /// <param name="admissionId"></param> /// <returns></returns> private ArrayList GenerateDocument(ArrayList documentList, string admissionId) { ArrayList FileList = new ArrayList(); oAdmission = new Admission(); oAdmission_BLogic = new Admission_BLogic(); oAdmission.AdmissionId = admissionId; ViewState["AdmissionStudentData"] = oAdmission_BLogic.Admission_Select_ByAdmissionId(oAdmission); ViewState["TagMasterData"] = oAdmission_BLogic.AdmissionTagMaster_Select_All(); foreach (string filename in DocumentList) { oDocument_BLogic = new Document_BLogic(); oDocument = new MailDocument(); oDocument.Documentpath = Server.MapPath("~/Documents/AdmissionDocument"); oDocument.Title = Convert.ToString(filename); StringBuilder WordContent = new StringBuilder(); if (oDocument_BLogic.BAL_Document_CheckExists(oDocument)) { DataTable oTable = oDocument_BLogic.BAL_Document_Select(oDocument); string title = Convert.ToString(oTable.Rows[0]["title"]); string body = Convert.ToString(oTable.Rows[0]["body"]); body = ReplaceTag(body); WordContent.Append("<html " + "xmlns:o='urn:schemas-microsoft-com:office:office' " + "xmlns:w='urn:schemas-microsoft-com:office:word'" + "xmlns='http://www.w3.org/TR/REC-html40'>" + "<head><title>Time</title>"); WordContent.Append("<!--[if gte mso 9]>" + "<xml>" + "<w:WordDocument>" + "<w:View>Print</w:View>" + "<w:Zoom>90</w:Zoom>" + "<w:DoNotOptimizeForBrowser/>" + "</w:WordDocument>" + "</xml>" + "<![endif]-->"); WordContent.Append("<style>" + "<!-- /* Style Definitions */" + "@page Section1" + " {size:8.5in 11.0in; " + " margin:0.6in 0.6in 0.6in 0.6in ; " + " mso-header-margin:.1in; " + " mso-footer-margin:.1in; mso-paper-source:0;}" + " div.Section1" + " {page:Section1;}" + "-->" + "</style></head>"); WordContent.Append("<body lang=EN-US style='tab-interval:.5in'>" + "<div class=Section1>" + body + "</div></body></html>"); string AutoGenerateDocumentPath = Server.MapPath("~/Documents/AutoGeneratedAdmissionDocument"); using (TextWriter writer = File.CreateText(Path.Combine(AutoGenerateDocumentPath, title + "_" + admissionId + ".doc"))) { writer.Write(Convert.ToString(WordContent)); } FileList.Add(Path.Combine(AutoGenerateDocumentPath, title + "_" + admissionId + ".doc")); AutoGeneratedDocumentList.Add(string.Format("{0}/{1}", "../Documents/AutoGeneratedAdmissionDocument", title + "_" + admissionId + ".doc")); } } return(FileList); }