#region Name Spaces
using System;
using System.Data;
using System.Web;
using System.Resources;
using System.Globalization;
using System.Threading;
#endregion
public partial class Error_Page_ErrorPage : System.Web.UI.Page
{
    #region Local Variable Declaration
    cls_Common _ObjCommon = new cls_Common();
    DataTable dtErr = new DataTable();
    string strPageName = string.Empty, strTrackingPlatform = string.Empty, strErrorMsg = string.Empty, strErrorText = string.Empty, strSourceLanguage = string.Empty;
    ResourceManager rm;
    CultureInfo ci;
    EmployeeEventData ObjEmployeeEventData = new EmployeeEventData();
    #endregion
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            if (!IsPostBack)
            {
                if (Session["Exception"] != null)
                {
                    Exception ex = ((Exception)Session["Exception"]);
                    strPageName = Convert.ToString(Session["PageName"]);
                    string userAgent = "";
                    userAgent = Request.UserAgent;

                    if (userAgent.IndexOf("Edge") > -1)
                    {
                        // maybe client's browser is Microsoft Edge
                        strTrackingPlatform = "Microsoft Edge " + Convert.ToString(Request.Browser.Version);
                    }
                    else
                    {
                        strTrackingPlatform = Convert.ToString(Request.Browser.Browser) + " " + Convert.ToString(Request.Browser.Version);
                    }
                    //strTrackingPlatform = Convert.ToString(Request.Browser.Browser) + " " + Convert.ToString(Request.Browser.Version);
                    strErrorMsg = ex.InnerException.Message;
                    strErrorText = ex.ToString();
                    dtErr = _ObjCommon.GetErrorVersionDetails(strPageName, strTrackingPlatform, strErrorMsg, strErrorText);
                    if (dtErr.Rows.Count > 0)
                    {
                        strSourceLanguage = Convert.ToString(Session["Session_ActiveLanguage"]);
                        rm = new ResourceManager(strSourceLanguage, System.Reflection.Assembly.Load("App_GlobalResources"));
                        ci = Thread.CurrentThread.CurrentCulture;
                        lblDateText.Text = Convert.ToString(dtErr.Rows[0]["DateTime"]);
                        lblVersionText.Text = Convert.ToString(dtErr.Rows[0]["Version"]);
                        lblReportFromText.Text = Convert.ToString(dtErr.Rows[0]["ClientName"]);
                        lnkBugHistoryText.Text = Convert.ToString(dtErr.Rows[0]["BugId"]);
                        lnkBugHistoryText.ToolTip = Convert.ToString(dtErr.Rows[0]["BugHistory"]);
                        lblTrackingPlatformText.Text = Convert.ToString(dtErr.Rows[0]["TrackingPlatform"]);
                        try
                        {
                            if (rm.GetString(Convert.ToString(dtErr.Rows[0]["PageName"]), ci) != null && rm.GetString(Convert.ToString(dtErr.Rows[0]["PageName"]), ci) != "")
                                lblPageNameText.Text = rm.GetString(Convert.ToString(dtErr.Rows[0]["PageName"]), ci);
                            else
                                lblPageNameText.Text = Convert.ToString(dtErr.Rows[0]["PageName"]);
                        }
                        catch (Exception)
                        {
                        }
                        lnkErrorText.Text = Convert.ToString(dtErr.Rows[0]["ErrorMsg"]);
                        lnkErrorText.ToolTip = Convert.ToString(dtErr.Rows[0]["ErrorText"]);
                    }
                    else
                    {
                        lblDateText.Text = DateTime.Now.ToString("dd-MMM-yyyy hh:mm:ss tt");
                        lblVersionText.Text = "V1.3";
                        lblReportFromText.Text = "General";
                        lnkBugHistoryText.Text = "Bug No: 0001";
                        lnkBugHistoryText.ToolTip = "Bug No: 0001 " + strErrorMsg;
                        lblTrackingPlatformText.Text = strTrackingPlatform;
                        lblPageNameText.Text = strPageName;
                        lnkErrorText.Text = strErrorMsg;
                        lnkErrorText.ToolTip = strErrorText;
                    }
                }
            }
        }
        catch (Exception Ex)
        {
            Response.Redirect("~/Index.aspx");
        }
    }
    protected void btnSendMail_Click(object sender, EventArgs e)
    {
    }
    protected void btnHome_Click(object sender, EventArgs e)
    {
        if (Session["EmployeeId"] != null)
        {
            string userId = Session["EmployeeId"].ToString();
            string sUser = Convert.ToString(Cache[Session["EmployeeId"].ToString().ToUpper()]);
            if (sUser != null && sUser != String.Empty)
            {
                ObjEmployeeEventData.InsertUpdateLastLogout(userId);
                HttpContext.Current.Cache.Remove(Session["EmployeeId"].ToString().ToUpper());
                Session.Clear();
            }
        }
        HttpContext.Current.Response.Redirect("../Index.aspx");
    }
}