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 Administration_NewUser : 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;
        // ¨S¦³Åv­­
        if (!SES_Common.Authorize(Request.Url.ToString(), Profile.UserName)) {
            Response.Redirect("/SEST/Common/NoAuthorization.aspx");
        }
    }
    protected void Page_Load(object sender, EventArgs e) {
    }


    protected void Page_PreRender(object sender, EventArgs e) {
        if (ddlEmployeeName.SelectedValue != "") {
            string sEmployeeName = ddlEmployeeName.SelectedValue;
            DataTable dt = new HR_EmployeesData().SelectExcludeLeave("*", "Name='" + sEmployeeName.Trim() + "'");
            if (dt != null &&  dt.Rows.Count == 1) {
                if (CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("UserName") != null)
                    ((TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("UserName")).Text = dt.Rows[0]["FirstName"].ToString();
                if (CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("Password") != null)
                    ((TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("Password")).Text = dt.Rows[0]["FirstName"].ToString();
                if (CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("ConfirmPassword") != null)
                    ((TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("ConfirmPassword")).Text = dt.Rows[0]["FirstName"].ToString();
                if (CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("EMail") != null)
                    ((TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("EMail")).Text = dt.Rows[0]["EMail"].ToString();
            }
        }
    }
    
    protected void CreateUserWizard1_CreatedUser(object sender, EventArgs e) {
    }
    protected void CreateUserWizard1_Load(object sender, EventArgs e) {
    }
    protected void CreateUserWizard1_CreatedUser1(object sender, EventArgs e) {
        new HR_EmployeesData().Update("Account='" + ((TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("UserName")).Text.Trim() + "'", "Name='" + ddlEmployeeName.SelectedValue + "'");
    }
    protected void CreateUserWizard1_ContinueButtonClick(object sender, EventArgs e) {
        Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "Back", SES_Common.BackScript(Request.Url.ToString(), -1));
    }
}
