﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;
using System.Linq;

public partial class Modules_UIControls_TerritoryTabMenu : System.Web.UI.UserControl
{
    protected override void OnInit(EventArgs e)
    {
        base.OnInit(e);
        if (CurrentUser.TerritoryId == 0)
        {
            Session.Clear();
            Response.Cookies.Clear();
            FormsAuthentication.SignOut();
            string serverName = HttpUtility.UrlEncode(Request.ServerVariables["SERVER_NAME"]);
            Response.Redirect("~/default.aspx");
        }

    }
    protected void Page_Load(object sender, EventArgs e)
    {
        var db = new TerritorySite.BL.Linq.TerritoryDBDataContext();
        var currentTerritory = (from t in db.Territories
                                where t.TerritoryId == CurrentUser.TerritoryId
                                select t).FirstOrDefault();
        if (currentTerritory.IsAssigned | currentTerritory.IsBeingReturned )
        {
            RadTabStrip1.Tabs[2].Visible  = false;
            RadTabStrip1.Tabs[4].Visible  = false;

        }
        else
        {
            RadTabStrip1.Tabs[2].Visible = true;
            RadTabStrip1.Tabs[4].Visible = true;
        }


        if (Request.RawUrl.ToLower().Contains("territoryedit.aspx"))
        {
            RadTabStrip1.SelectedIndex = 0;
        }
        else if (Request.RawUrl.ToLower().Contains("assignments.aspx"))
        {
            RadTabStrip1.SelectedIndex = 1;
        }
        else if (Request.RawUrl.ToLower().Contains("territorydesigner.aspx"))
        {
            RadTabStrip1.SelectedIndex = 2;
        }
        else if (Request.RawUrl.ToLower().Contains("printcenter.aspx"))
        {
            RadTabStrip1.SelectedIndex = 3;
        }
        else if (Request.RawUrl.ToLower().Contains("mapcleanup.aspx"))
        {
            RadTabStrip1.SelectedIndex = 4;
        }

    }
}
