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 SubPages_FABs : 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;
    }



    protected void Page_Load(object sender, EventArgs e) {
        int iRowCount = 5, iCount = 0;
        if (Request["DialogClientID"] != null) {
            string sParentID = Request["DialogClientID"].ToString().Trim();
            
            //// 080508: 不會自動帶入, 所以會依不同的 JobNo 去找出 FAB -------------------
            //if (Request["JobNo"] == null || Request["JobNo"].ToString().Length == 0) {
            //    Response.Write("<script language='javascript'>window.close();</script>");
            //    return;
            //}

            string sJobNo = Request["JobNo"].ToString();
            // 有對應的機台 ( JWL or JW or TW)
            string[] arDistinctName = null;
            if (!string.IsNullOrEmpty(sJobNo) && (sJobNo.Substring(0, 2) == "JW" || (sJobNo.Substring(0, 2) == "TW" && sJobNo.Substring(0, 3) != "TWl")))
            {
                arDistinctName = new Customer_FABData().SelectFABs(sJobNo);
            }
            // 沒有對應的機台 ( AJW, AZZ, TWL)
            else {
                arDistinctName = new Customer_FABData().SelectDistinct("FABID", null);     // data source
            }
            // -----------------------------------------------------------------------------


            // 判斷是否有找到資料, 沒有則return 
            if (arDistinctName.Length <= 0) {
                Label lbl = new Label();
                lbl.Text = Resources.Universal.Msg_NotFindData;
                this.form1.Controls.Add(lbl);
                return;
            }
            // show data with table
            Table tblDisplay = new Table();
            tblDisplay.GridLines = System.Web.UI.WebControls.GridLines.Both;
            //tblDisplay.Width = System.Web.UI.WebControls.Unit.Pixel(500);
            tblDisplay.ForeColor = System.Drawing.Color.White;
            tblDisplay.Font.Bold = true;
            tblDisplay.BackColor = System.Drawing.Color.SkyBlue;
            TableRow tableRow = null;
            for (int i = 0; i < arDistinctName.Length; i++) {
                string sName = arDistinctName[i];
                if ((iCount % iRowCount) == 0)
                    tableRow = new TableRow();
                TableCell tableCell = new TableCell();
                Label lbl = new Label();
                lbl.Text = sName;
                //lbl.Attributes.Add("onclick", "window.opener.document.getElementById('" + sParentID + "').value ='" + sName + "'; window.close();");
                lbl.Attributes.Add("onclick", "AssingValueToParent( '" + sParentID + "', '" + sName + "')");
                lbl.Attributes.Add("style", "cursor:hand");
                tableCell.Controls.Add(lbl);
                tableRow.Controls.Add(tableCell);
                if (((iCount + 1) % iRowCount) == 0)
                    tblDisplay.Controls.Add(tableRow);
                iCount++;
            }
            if ((iCount % iRowCount) != 0)
                tblDisplay.Controls.Add(tableRow);
            this.form1.Controls.Add(tblDisplay);
            Button btn = new Button();
            btn.Text = Resources.Universal.Msg_Close;
            btn.Attributes.Add("onclick", "window.close();");
            this.form1.Controls.Add(btn);
        }
    }
}
