using AppData;
using System;
using System.Web.UI;

namespace NKC_WF.WebUserControls
{
    public partial class cmp_offlineOrders : BaseUserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                mod_righePag.numRowPag = 10;
                cmp_offOrderDetail.Visible = false;
            }
            mod_righePag.eh_newNum += Mod_righePag_eh_newNum;
            cmp_offOrderDetail.eh_doRefresh += Cmp_offOrderDetail_eh_doRefresh;
            cmp_offOrderDetail.eh_doReset += Cmp_offOrderDetail_eh_doReset;
        }

        private void Cmp_offOrderDetail_eh_doReset(object sender, EventArgs e)
        {
            forceReset();
        }

        private void Cmp_offOrderDetail_eh_doRefresh(object sender, EventArgs e)
        {
            doUpdate();
        }

        private void Mod_righePag_eh_newNum(object sender, EventArgs e)
        {
            grView.PageSize = mod_righePag.numRowPag;
        }
        public void doUpdate()
        {
            grView.DataBind();
        }

        protected void lbtReset_Click(object sender, EventArgs e)
        {
            forceReset();
        }

        private void forceReset()
        {
            grView.SelectedIndex = -1;
            grView.DataBind();
            cmp_offOrderDetail.Visible = false;
            raiseReset();
        }

        protected int selOrdId
        {
            get
            {
                int answ = 0;
                int.TryParse(grView.SelectedValue.ToString(), out answ);
                return answ;
            }
        }

        protected void grView_SelectedIndexChanged(object sender, EventArgs e)
        {
            // controllo update... SOLO SE status è 1...
            var currOrd = DLMan.taOffOL.getByKey(selOrdId);
            bool fatto = false;
            try
            {
                if (currOrd.Count == 1)
                {
                    if (currOrd[0].OrdStatus == 1 && string.IsNullOrEmpty(currOrd[0].DrawFilePath))
                    {
                        fatto = ComLib.checkOfflineOrderReq(selOrdId);
                    }
                }
            }
            catch
            { }
            // visualizzo dettaglio ordine...
            cmp_offOrderDetail.OffOrdId = selOrdId;
            cmp_offOrderDetail.Visible = true;
            if (fatto)
            {
                grView.DataBind();
            }
        }

    }
}