using System;
using System.Collections.Generic;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class MasterFile_PassportVisaExpiry : System.Web.UI.Page
{
    cls_Common objCommon = new cls_Common();
    EmployeeEventData objempEvent = new EmployeeEventData();
    string strIsFrom = "1";
    DataSet ds = new DataSet();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            stylebootstrap.Href = "../bootstrap/css/bootstrap.min.css";
            stylefontawesome.Href = "../bootstrap/font-awesome/css/font-awesome.css";
            styleAdminLTE.Href = "../dist/css/AdminLTE.min.css";
            stylecustom.Href = "../dist/css/custom.css";
            stylefonts.Href = "../dist/css/fonts.css";
            if (Request.QueryString["IsFrom"] != null)
                strIsFrom = Convert.ToString(Request.QueryString["IsFrom"]);
            ds = BindPassportVisaExpiryDetails();
            if (ds.Tables.Count > 0)
            {
                if (ds.Tables[0].Rows.Count > 0)
                {
                    BindDataset();
                }
                else
                {
                    BindEmptyDataset();
                }
            }
            else
            {
                BindEmptyDataset();
            }
            //DataTable dt = new DataTable();
            //dt.Columns.Add("ExpiryContent", typeof(string));
            //dt.Columns.Add("ExpiryNumber", typeof(int));
            //dt.Rows.Add("Your Passport will expire on <B> 28/05/2022 </B>, please get it renewed.", 1);
            //dt.Rows.Add("Your Visa will expire on <B> 28/05/2022 </B>, please get it renewed.", 2);
            //DataSet ds = new DataSet();
            //ds.Tables.Add(dt);
            //grvPassVisa.DataSource = ds;
            //grvPassVisa.DataBind();
            if (strIsFrom == "1")
            {
                Response.Write(Convert.ToString(hdnrecord.Value));
                Response.End();
            }
        }
    }
    private void BindDataset()
    {
        hdnrecord.Value = "1";
        grvPassVisa.DataSource = ds;
        grvPassVisa.DataBind();
        Session["passvisaExpiry"] = ds;
    }
    private DataSet BindPassportVisaExpiryDetails()
    {
        DataSet ds;
        if (Session["passvisaExpiry"] != null && strIsFrom != "1")
        {
            ds = (DataSet)Session["passvisaExpiry"];
        }
        else
            ds = objCommon.GetPassportVisaExpiryDetails(Convert.ToInt32(Session["EmpAutoId"]), Convert.ToString(Session["UserGroupName"]));
        return ds;
    }
    protected void btn_Add_Click(object sender, EventArgs e)
    {
        if (Convert.ToString(txtRemindme.Text) != "")
        {
            foreach (GridViewRow row in grvPassVisa.Rows)
            {
                if (grvPassVisa.SelectedIndex >= 0)
                {
                    if (row.RowIndex == grvPassVisa.SelectedIndex)
                    {
                        Label lblExpiryNumber = (Label)row.FindControl("lblExpiryNumber");
                        if (lblExpiryNumber != null)
                        {
                            if (Convert.ToString(lblExpiryNumber.Text) == "1" || Convert.ToString(lblExpiryNumber.Text) == "2")
                            {
                                objempEvent.UpdateReminderDays(Convert.ToInt32(Session["EmpAutoId"]), Convert.ToInt16(txtRemindme.Text), Convert.ToInt16(lblExpiryNumber.Text));
                                ds = BindPassportVisaExpiryDetails();
                                grvPassVisa.SelectedIndex = -1;
                                if (ds.Tables.Count > 0)
                                {
                                    if (ds.Tables[0].Rows.Count > 0)
                                    {
                                        BindDataset();
                                    }
                                    else
                                    {
                                        BindEmptyDataset();
                                    }
                                }
                                else
                                {
                                    BindEmptyDataset();
                                }
                            }
                        }
                        break;
                    }
                }
                else
                {
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "alert", "alert('select data in listview')", true);
                }
            }
        }
        else
        {
        }
    }
    private void BindEmptyDataset()
    {
        grvPassVisa.DataSource = null;
        grvPassVisa.DataBind();
        hdnrecord.Value = "0";
        string strScripts = "";
        strScripts = strScripts + "<script language='javascript'>";
        strScripts = strScripts + "parent.$('#passport_visaExpiry').modal('hide');</script>";
        Page.RegisterStartupScript("AlertManualApproval", strScripts);
        return;
    }
    protected void grvPassVisa_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.Header)
        {
        }
        else if (e.Row.RowType == DataControlRowType.DataRow)
        {
            e.Row.Attributes["onclick"] = Page.ClientScript.GetPostBackClientHyperlink(grvPassVisa, "Select$" + e.Row.RowIndex);
            e.Row.ToolTip = "Click to select this row.";
        }
    }
    protected void grvPassVisa_SelectedIndexChanged(object sender, EventArgs e)
    {
        foreach (GridViewRow row in grvPassVisa.Rows)
        {
            if (row.RowIndex == grvPassVisa.SelectedIndex)
            {
                row.BackColor = ColorTranslator.FromHtml("#A1DCF2");
                row.ToolTip = string.Empty;
            }
            else
            {
                row.BackColor = ColorTranslator.FromHtml("#FFFFFF");
                row.ToolTip = "Click to select this row.";
            }
        }
    }
    protected void grvPassVisa_DataBound(object sender, EventArgs e)
    {
        if (grvPassVisa.Rows.Count > 0)
        {
            grvPassVisa.Rows[0].RowState = DataControlRowState.Selected;
            //grvPassVisa.Rows[0].BackColor = ColorTranslator.FromHtml("#eaf7f7");
            grvPassVisa.SelectedIndex = 0;
        }
    }
}