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 Maintenance_TEC_Tools : 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 btnSearch_Click(object sender, EventArgs e) {
        //取得條件的字串
        string sWhereCondi = "";
        try {
            if (txtSelConditionStartDate.Text.Trim() != "")
                DateTime.Parse(txtSelConditionStartDate.Text.Trim());
            if (txtSelConditionEndDate.Text.Trim() != "")
                DateTime.Parse(txtSelConditionEndDate.Text.Trim());
        }
        catch {
            Response.Redirect("/SEST/Common/ErrorPage.aspx?BackPageCount=-1&ErrorMessage=" + Resources.Universal.Err_DateFormatIncorrect);
            return;
        }
        if (txtSelConditionFABID.Text != "")
            sWhereCondi += " And FABID like '%" + txtSelConditionFABID.Text.Trim() + "%'";
        if (txtSelConditionToolNo.Text != "")
            sWhereCondi += " And SES_ToolNo like '%" + txtSelConditionToolNo.Text.Trim() + "%'";
        if (txtSelConditionStartDate.Text != "")
            sWhereCondi += " And InstallDate >= '" + txtSelConditionStartDate.Text.Trim() + "'";
        if (txtSelConditionEndDate.Text != "")
            sWhereCondi += " And InstallDate <= '" + txtSelConditionEndDate.Text.Trim() + "'";

        if ( sWhereCondi.Length > 0)
            sWhereCondi = sWhereCondi.Substring(4).Replace("--", "").Replace("''", "");

        // 利用 SelectParameters 的方式呼叫另一個有 Condition 的 Select 函數
        while (ObjectDataSource1.SelectParameters.Count > 0) {
            ObjectDataSource1.SelectParameters.RemoveAt(0);
        }

        ObjectDataSource1.SelectParameters.Add("Condition", sWhereCondi);
        GridView1.EditIndex = -1;
    }
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) {
        if (e.Row.Cells.Count >= 8) {
            if (e.Row.Cells[e.Row.Cells.Count - 1].Controls.Count > 0) {
                HyperLink hl = (HyperLink)e.Row.Cells[8].Controls[0];
                hl.NavigateUrl = SES_Common.ReplaceURLString(hl.NavigateUrl, false, false, false);
            }
        }
    }
    protected void GridView1_DataBound(object sender, EventArgs e) {

    }
}
