using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Common_AnnouncementDetail : System.Web.UI.Page {
    //the function code for localization on this page
    protected override void InitializeCulture() {
        ProfileCommon p = (ProfileCommon)this.Context.Profile;

        if (Request.Form.Get("ctl00$selLanguage") != null)
            p.lang = Request.Form.Get("ctl00$selLanguage").ToString();
        if (p.lang == String.Empty)
            p.lang = Session["Localization"].ToString();

        if (p.lang.Length > 0) {
            this.Culture = p.lang;
            this.UICulture = System.Globalization.CultureInfo.CreateSpecificCulture(p.lang).Name;
        }
    }
    //select theme
    protected void Page_PreInit(object sender, EventArgs e) {
        Page.Theme = Profile.UI.Theme;

        // 沒有權限
        if (!SES_Common.Authorize(Request.Url.ToString(), Profile.UserName)) {
            Response.Redirect("/SEST/Common/NoAuthorization.aspx");
        }
    }

    
    
    protected void btnBack_Click(object sender, EventArgs e) {
        Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "Back", SES_Common.BackScript(-2));
    }
    protected void DetailsView1_DataBound(object sender, EventArgs e) {
        DataTable dt = new Common_AnnouncementData().Select(DateTime.Today);
        HyperLink hl = null;
        ((Label)DetailsView1.FindControl("lblContents")).Text = ((Label)DetailsView1.FindControl("lblContents")).Text.Replace("\r\n","<br>");
        string sAnnouncementID = Request["AnnouncementID"].ToString();
        // 有附加檔案
        DataTable dtFiles = new Common_FilesStorageData().Select("Announcement", sAnnouncementID);
        for (int iFiles = 0; iFiles < dtFiles.Rows.Count; iFiles++) {
            hl = new HyperLink();
            hl.ImageUrl = @"~\imanges\more.gif";
            hl.Text = dtFiles.Rows[iFiles]["FileName"].ToString();
            hl.NavigateUrl = dtFiles.Rows[iFiles]["PhysicalPath"].ToString().Replace(
                ConfigurationManager.ConnectionStrings["FilesStoragePath"].ConnectionString,
                ConfigurationManager.ConnectionStrings["FilesStorageURL"].ConnectionString.Replace("60.251.203.79", Request.Url.DnsSafeHost)).Replace(@"\", "/");
            ((Panel)DetailsView1.FindControl("pnlFiles")).Controls.Add(hl);
        }
    }
}
