using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace CheckSheet
{
    public partial class Default : System.Web.UI.Page
    {



        protected void Page_Load(object sender, EventArgs e)
        {






            //if (Page.Request.ServerVariables["SERVER_PORT"].ToString() == "80")
            //{
            //    string link = string.Format("https://{0}/", Page.Request.ServerVariables["HTTP_HOST"].ToString());

            //    Response.Redirect(link);
            //}
            //else if (Page.Request.ServerVariables["SERVER_PORT"].ToString() == "443")
            //{
            //    string link = string.Format("https://{0}/", Page.Request.ServerVariables["HTTP_HOST"].ToString());

            //    Response.Redirect(link);
            //}



            if (!Page.IsPostBack)
            {










            }

            




        }


        protected void btnCancel_Click(object sender, EventArgs e)
        {
            txtPassword.Text = "";
            txtUserName.Text = "";
            txtUserName.Focus();
            lblError.Attributes.Remove("Class");

        }
        protected void bttTH_Click(object sender, ImageClickEventArgs e)
        {

        }
        protected void bttEN_Click(object sender, ImageClickEventArgs e)
        {
        }

        protected void btnChange_Click(object sender, EventArgs e)
        {
            if (txtUserName.Text.Length == 0)
            {
                System.Web.UI.ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "Message", "alert('Please input username information.');", true);
                txtUserName.Focus();
            }
            else
            {
                Response.Redirect("frmChangPassword?key=" + txtUserName.Text.Trim());

            }
        }

        protected void btnOK_Click(object sender, EventArgs e)
        {


            if (txtUserName.Text.Length == 0)
            {
                lblError.Text = "Please input username information.";
                txtUserName.Focus();
                lblError.Attributes.Add("Class", "cssalert");


            }
            else if (txtPassword.Text.Length == 0)
            {

                lblError.Text = "Please input password information.";
                txtPassword.Focus();
                lblError.Attributes.Add("Class", "cssalert");

            }

            else
            {




                lblError.Text = "";
                //if(txtPassword.Text=="1234" && txtUserName.Text=="admin")
                //{
                //    Response.Redirect("Mainmenu");

                //}
                //else
                //{
                //    lblError.Text = "Username/Password is incorrect";
                //    lblError.Visible = true;
                //    txtUserName.Focus();
                //    txtUserName.Text = "";
                //    lblError.Attributes.Add("Class", "cssalert");



                //}
                //string strEncriptPassword = clsControlUI.encriptpassword(txtUserName.Text.Trim(), txtPassword.Text.Trim());




                using (FcSql.Function fc = new FcSql.Function())
                {




                    string sqlquery = string.Format("select usercode,username,firstname,lastname,position,emailaddress from Users Where username='{0}' and password='{1}'  ", txtUserName.Text.Trim().TrimStart().TrimEnd(), txtPassword.Text.Trim().TrimStart());
                    DataTable dt = fc.SQL_DataTable(sqlquery.ToString());
                    string cmd = string.Empty;

                    if (dt.Rows.Count > 0)
                    {

                        Response.Cookies["userid"].Value = dt.Rows[0]["usercode"].ToString();
                        Response.Cookies["username"].Value = dt.Rows[0]["username"].ToString();
                        Response.Cookies["fullname"].Value = dt.Rows[0]["firstname"].ToString() + "  " + dt.Rows[0]["lastname"].ToString();
                        Response.Cookies["position"].Value = dt.Rows[0]["position"].ToString();
                        Response.Cookies["useremail"].Value = dt.Rows[0]["emailaddress"].ToString();
                        Response.Redirect("Mainmenu");
                    }
                    else
                    {

                        lblError.Text = "Username/Password is incorrect";
                        lblError.Visible = true;
                        txtUserName.Focus();
                        txtUserName.Text = "";
                        lblError.Attributes.Add("Class", "cssalert");

                    }


                }

            }

        }





    }



}


