using SteamWare;
using System;
using System.Web;
using System.Web.UI;

namespace NKC_WF
{
    public partial class BunkDetail : BasePage
    {

        public override void VerifyRenderingInServerForm(Control control)
        {
            // Confirms that an HtmlForm control is rendered for the  specified ASP.NET server control at run time.
        }

        protected string BunkID
        {
            get
            {
                string answ = "0";
                answ = memLayer.ML.QSS("BunkID");
                return answ;
            }
        }

        private void doExport()
        {
            Response.Clear();
            string content = $"attachment; filename=Bunk_{BunkID}.xls";
            Response.AddHeader("content-disposition", content);
            Response.Charset = "";
            // If you want the option to open the Excel file without saving than
            // comment out the line below
            Response.Cache.SetCacheability(HttpCacheability.NoCache);
            Response.ContentType = "application/vnd.xls";
            System.IO.StringWriter stringWrite = new System.IO.StringWriter();
            using (var htmlWrite = new HtmlTextWriter(stringWrite))
            {
                grView.RenderControl(htmlWrite);
                Response.Write(stringWrite.ToString());
                Response.End();
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                aggiornamento();
                doExport();
            }
        }
        public void aggiornamento()
        {
            hfStackID.Value = BunkID;
            grView.AllowPaging = false;
            ods.DataBind();
        }
        /// <summary>
        /// Formatta in min/sec il tempo in sec decimale
        /// </summary>
        /// <param name="_timeSec"></param>
        /// <returns></returns>
        public string formatMinSec(object _timeSec)
        {
            int totSec = 0;
            string answ = "";
            int.TryParse(_timeSec.ToString().Replace(".", ""), out totSec);
            int numMin = totSec / 60;
            int numSec = totSec - (60 * numMin);
            answ = $"00:{numMin:00}:{numSec:00}";
            return answ;
        }
        /// <summary>
        /// Restitusice path bonificato
        /// </summary>
        /// <param name="_rawPath"></param>
        /// <returns></returns>
        public string fixFilePath(object _rawPath)
        {
            string answ = _rawPath.ToString().ToLower();
            string fileBasePath = memLayer.ML.CRS("nestBasePath").ToLower();
            if (string.IsNullOrEmpty(fileBasePath))
            {
                fileBasePath = "c:/users/dell/dropbox/SVG/";
            }
            answ = answ.Replace(fileBasePath, "");
            return answ;
        }
    }
}