using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Foresight.Fleet.Services.User;
using IronIntel.Contractor;
using IronIntel.Contractor.Site.Maintenance;

public partial class Maintenance_AlertsManagement : AlertsBasePage
{
    public string BeginDate = "";
    public string EndDate = "";
    public string AssetID = "";
    public bool InDialog = false;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!CheckLoginSession())
        {
            RedirectToLoginPage();
        }
        else
        {
            string methodName = Request.Form["MethodName"];
            if (!string.IsNullOrEmpty(methodName))
            {
                ProcessRequest(methodName);
            }
            else if (!IsPostBack)
            {
                this.Title = PageTitle;
                bool license = SystemParams.HasLicense("AlertsManagement");
                if (!license)
                    RedirectToLoginPage();

                bool permission = CheckRight(SystemParams.CompanyID, Feature.ALERTS_MANAGEMENT);
                if (!permission)
                    RedirectToLoginPage();

                AssetID = Request.Params["mid"] ?? "";
                InDialog = Request.Params["InDialog"] == "1";
            }

            DateTime userlocaldate = SystemParams.ConvertToUserTimeFromUtc(GetCurrentLoginSession().User, DateTime.UtcNow);
            if (InDialog)
                BeginDate = userlocaldate.AddDays(-13).ToShortDateString();
            else
                BeginDate = userlocaldate.AddDays(-6).ToShortDateString();

            EndDate = userlocaldate.ToShortDateString();
        }
    }

    public bool CanEditWorkOrder
    {
        get
        {
            bool license = SystemParams.HasLicense("WorkOrder");
            bool permission = CheckRight(SystemParams.CompanyID, Feature.WORK_ORDER);
            return license && permission;
        }
    }

}