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);
            }
        }
    }
    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;
                }
            }
        }
    }
    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();
        }
    }
Esempio n. 4
0
    /// <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);
    }