using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BusinessLayer;
using DTO;
using Telerik.Web.UI;

namespace NikaiDSR.Admin
{
    public partial class Customer : PageBase
    {
        #region Declare
        CustomerManager CustM = new CustomerManager();
        #endregion

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                PageTitle = "NIKAI- ADMIN - CUSTOMERS";
                //FillCustomerComboBox();
                btnAdd.OnClientClick = "openRadWin('../Controls/EditCustomer.aspx?CustId=','AddCustomer'); return false;";
            }
        }

        //void FillCustomerComboBox()
        //{
        //    IList<CustomerDTO> Customers = CustM.GetAllCustomer();
        //    Helper.Validation.FillTelerikDropdown(cmbCustomer, Customers, "Customer_Name", "Customer_Id", "Select", "0");
        //}

        protected void Grid_NeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
        {
            Grid.DataSource = CustM.GetCustomerLocationRegionCountry(UserID, txtCustomer.Text);
        }

        protected void Grid_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
        {
            if (e.Item is GridDataItem)
            {
                GridDataItem item = (GridDataItem)e.Item;

                Button btnEdit = (Button)item["Edit"].Controls[1];

                btnEdit.OnClientClick = "openRadWin('../Controls/EditCustomer.aspx?CustId=" + item["Customer_Id"].Text + "','EditCustomer'); return false;";

                btnEdit = (Button)item["Edit"].Controls[3];
                btnEdit.OnClientClick = "openRadWin('../Controls/ViewContacts.aspx?CustId=" + item["Customer_Id"].Text + "','ViewContacts'); return false;";
                if (item["Customer_Status"].Text == "True")
                {
                    item["Customer_Status"].Text = "Active";
                }
                else
                {
                    item["Customer_Status"].Text = "In-active";
                    }
            }
        }

        protected void btnGo_Click(object sender, EventArgs e)
        {
            Grid.Rebind();
        }
    }
}