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

namespace NKC_WF.WebUserControls
{
    public partial class cmp_scrapList : BaseUserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                mod_righePag.numRowPag = 10;
            }
            mod_righePag.eh_newNum += Mod_righePag_eh_newNum;
        }

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

        public void doUpdate()
        {
            grView.DataBind();
        }

        protected void chkToggle_CheckedChanged(object sender, EventArgs e)
        {
            // seleziono TUTTI i checkbox presenti
            foreach (GridViewRow row in grView.Rows)
            {
                try
                {
                    CheckBox chkb = (CheckBox)row.FindControl("chkSelected");
                    chkb.Checked = !chkb.Checked;
                }
                catch { }
            }
        }
        public string cssByStatus(object _statusId)
        {
            int statusId = 0;
            int.TryParse(_statusId.ToString(), out statusId);
            string answ = statusId == 990 ? "text-dark" : "text-secondary font-italic";

            return answ;
        }
        protected void lbtCreateOffOrd_Click(object sender, EventArgs e)
        {
            bool doReport = false;
            // creo NUOVO ordine offline...
            DS_App.OfflineOrderListDataTable tabOrdini = DLMan.taOffOL.insertNew();
            int itemId = 0;
            // se ho la riga new in risposta...
            if (tabOrdini.Count == 1)
            {
                // ciclo sulla grView x i selezionati
                foreach (GridViewRow row in grView.Rows)
                {
                    itemId = 0;
                    try
                    {
                        CheckBox chkb = (CheckBox)row.FindControl("chkSelected");
                        if (chkb.Checked)
                        {
                            // recupero valore
                            HiddenField hfid = (HiddenField)row.FindControl("hfItemID");
                            int.TryParse(hfid.Value, out itemId);
                            // aggiungo ad ordine
                            if (itemId > 0)
                            {
                                DLMan.taOO2I.insertQuery(tabOrdini[0].OrdID, itemId);
                                doReport = true;
                            }
                        }
                    }
                    catch { }
                }
            }
            if (doReport)
            {
                grView.DataBind();
                raiseEvent();
            }
        }
    }
}