protected void btnRegresh_Click(object sender, ImageClickEventArgs e)
 {
     if (!string.IsNullOrEmpty(Customerid.Value))
     {
         int CustID = Convert.ToInt32(Customerid.Value);
         Customer objCust = new Customer();
         CustomerBLL objCBLL = new CustomerBLL();
         objCust.CustomerID = CustID;
         List<Customer> objLCust = objCBLL.GetCustomerDetailByCustID(ref objCust);
         if (null != objLCust)
         {
             PopulateFormFields(objLCust);
         }
     }
     ScriptManager.RegisterStartupScript(this, this.GetType(), "PopulateCustomer", "Populate()", true);
 }
    private void PopulateGrid()
    {
        try
        {
            if (txtSearch.Text.Trim() != "Search")
            {
                objPI.SearchText = txtSearch.Text.Trim();
            }
            else
            {
                objPI.SearchText = "";
            }

            if (objPI.SortDirection == null && objPI.SortColumnName == null)
            {
                objPI.SortDirection = Convert.ToString(ViewState[Constants.SORTDERECTION]);
                objPI.SortColumnName = Convert.ToString(ViewState[Constants.SORTCOLUMNNAME]);
            }
            CustomerBLL objCustomerBLL = new CustomerBLL();

            List<Customer> objData = new List<Customer>();
            objData = objCustomerBLL.GetAllCustomer(objData, objPI);

            gvGrid.DataSource = objData;
            gvGrid.ExportTemplate = "export_template_4Column.xlsx";
            gvGrid.ExportCaption = "";
            gvGrid.ExcelColumn = "";
            gvGrid.DataBind();

            if (objData != null)
            {
                if (!iFlag && lblMsg.Text == "")
                {
                    int mintMode = Common.GetQueryStringIntValue("Mode");
                    if (mintMode > 0)
                    {
                        if (mintMode == 1)
                        {
                            divMess.Attributes.Add("class", "success");
                            divMess.Visible = true;
                            lblMsg.Text = "-'" + objData[0].FirstName + "' " + Constants.Added;

                        }
                        else if (mintMode == 2)
                        {

                        }

                    }
                    else
                    {
                        divMess.Visible = false;
                        lblMsg.Text = "";
                    }
                }
                else
                {
                    if (lblMsg.Text == "")
                    {
                        divMess.Visible = false;
                        lblMsg.Text = "";
                    }
                }

            }

        }
        catch (Exception ex)
        {
            SendMail.MailMessage("CSWeb > Error > " + (new StackTrace()).GetFrame(0).GetMethod().Name, ex.ToString());
        }
    }
    private void LoadData(int vintCustomerID)
    {
        try
        {
            Customer objCustomer = new Customer();
            CustomerBLL objUBLL = new CustomerBLL();
            objCustomer.CustomerID = vintCustomerID;
            List<Customer> objList = objUBLL.GetCustomerDetailByCustID(ref objCustomer);

            if (null != objList)
            {
                txtFirstName.Text = objList[0].FirstName;
                txtLastName.Text = objList[0].LastName;
                txtAddress.Text = objList[0].Address;
                txtZIP.Text = objList[0].ZIP;
                txtCity.Text = objList[0].City;
                txtCountry.Text = objList[0].Country;
                txtPhone.Text = objList[0].TeleNumber;
                txtEmailID.Text = objList[0].Email;
                txtNote.Text = objList[0].Notes;
                ScriptManager.RegisterStartupScript(this, this.GetType(), "AddEditCustomer", "ShowModalDiv('ModalWindow1','dvInnerWindow',0);", true);

            }
        }
        catch (Exception ex)
        {
            SendMail.MailMessage("CSWeb > Error > " + (new StackTrace()).GetFrame(0).GetMethod().Name, ex.ToString());
        }

    }
    private void SaveData(string vstrMode, int vintCustomerID)
    {
        Customer objCustomer = new Customer();
        CustomerBLL objUBLL = new CustomerBLL();
        objCustomer.CustomerID = vintCustomerID;
        
        objCustomer.FirstName = txtFirstName.Text.Trim();
        objCustomer.LastName = txtLastName.Text.Trim();
        objCustomer.Address = txtAddress.Text.Trim();
        objCustomer.ZIP = txtZIP.Text.Trim();
        objCustomer.City = txtCity.Text.Trim();
        objCustomer.Country = txtCountry.Text.Trim();
        objCustomer.TeleNumber = txtPhone.Text.Trim();
        objCustomer.Email = txtEmailID.Text.Trim();
        objCustomer.Notes = txtNote.Text.Trim();
        objCustomer.CreatedBy = ((User)Session["UserData"]).UserID;
        Message objMsg = objUBLL.InsertUpdatePlatformCustomer(objCustomer);

        lblError.InnerHtml = objMsg.ReturnMessage;
        if (objMsg.ReturnValue > 0)
        {
            divMess.Visible = true;
            lblMsg.Text = objMsg.ReturnMessage;
            ViewState["intCustomerID"] = null;
            PopulateGrid();
        }
        else
        {
            Page.ClientScript.RegisterStartupScript(GetType(), "AddEditCustomer", "ShowModalDiv('ModalWindow1','dvInnerWindow',0);", true);
        }
    }
    protected void gvGrid_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        try
        {
            if (e.CommandName == "Edit")
            {
                int intCustomerID = Convert.ToInt32(e.CommandArgument.ToString());
                ViewState["intCustomerID"] = intCustomerID;
                LoadData(intCustomerID);
            }

            if (e.CommandName == "Delete")
            {

                Message vobjMsg = new Message();
                int intCustomerID = Convert.ToInt32(e.CommandArgument.ToString());
                Customer objCustomer = new Customer();
                CustomerBLL objUBLL = new CustomerBLL();
                objCustomer.CustomerID = intCustomerID;
                vobjMsg = objUBLL.DeletePlatformCustomer(objCustomer);

                if (vobjMsg.ReturnValue > 0)
                {
                    divMess.Visible = true;
                    lblMsg.Text = Constants.Deleted;
                    divMess.Attributes.Add("class", "Deleted");
                    lblMsg.Style.Add("color", "Black");
                }
                else
                {
                    divMess.Visible = true;
                    lblMsg.Style.Add("color", "Red");
                    divMess.Attributes.Add("class", "error");
                    lblMsg.Text = vobjMsg.ReturnMessage;
                }
            }



        }
        catch (Exception ex)
        {
            SendMail.MailMessage("CSWeb > Error > " + (new StackTrace()).GetFrame(0).GetMethod().Name, ex.ToString());
        }
    }