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

public partial class Maintenance_ScheduleMachines : PreventativeMaintenanceBasePage
{
    protected string IID;
    protected string ScheduleType;
    protected string Header;
    protected PmScheduleInfo Schedule;
    protected string StartingColumn;
    protected string PmScheduleUom;
    public string CurrentDate = "";

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!CheckLoginSession())
        {
            // TODO: sub page
            //RedirectToLoginPage();
        }
        else
        {
            bool license = SystemParams.HasLicense("PreventativeMaintenance");
            if (!license)
                RedirectToLoginPage();

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

            string methodName = Request.Form["MethodName"];
            if (!string.IsNullOrEmpty(methodName))
            {
                ProcessRequest(methodName);
            }
            else if (!IsPostBack)
            {
                // todo nothing
                IID = Request.QueryString["IID"];
                if (string.IsNullOrWhiteSpace(IID))
                {
                    Response.Redirect("MaintenanceSchedulesManagement.aspx", true);
                    return;
                }
                Schedule = MaintenanceManagement.GetPMScheduleByID(GetCurrentLoginSession().SessionID, IID);
                ScheduleType = Schedule.PmScheduleType;
                PmScheduleUom = Schedule.PmScheduleUom;

                if (string.IsNullOrWhiteSpace(ScheduleType))
                {
                    ScheduleType = "PM";
                }
                else
                {
                    ScheduleType = ScheduleType.ToUpper();
                }
                switch (ScheduleType)
                {
                    case "TBM":
                        Header = "Manage Time Based Maintenance Assets";
                        StartingColumn = "<th>Plan Start Date</th>";
                        break;
                    case "HM":
                        Header = "Manage Hours Maintenance Assets";
                        StartingColumn = "<th>Starting Hours</th>";
                        break;
                    case "ADM":
                        Header = "Manage Absolute Distance Maintenance Assets";
                        break;
                    case "RDM":
                        Header = "Manage Relative Distance Maintenance Assets";
                        StartingColumn = "<th style='min-width:60px;'>Starting Distance</th>";
                        break;
                    default:
                        Header = "Manage Absolute Hours Maintenance Assets";
                        break;
                }
            }
            DateTime userlocaldate = SystemParams.ConvertToUserTimeFromUtc(GetCurrentLoginSession().User, DateTime.UtcNow);
            CurrentDate = userlocaldate.ToShortDateString();
        }
    }
}