protected void btnSearch_Click(object sender, EventArgs e)
        {
            try
            {
                CreamBell_DMS_WebApps.App_Code.Global baseObj = new CreamBell_DMS_WebApps.App_Code.Global();

                if (txtFromDate.Text.Trim().Length > 0)
                {
                    if (!baseObj.IsDate(txtFromDate.Text))
                    {
                        string message = "alert('Invalid From Date !!!');";
                        ScriptManager.RegisterStartupScript(this, this.GetType(), "alert", message, true);
                        txtFromDate.Focus();
                        return;
                    }
                }
                if (txtToDate.Text.Trim().Length > 0)
                {
                    if (!baseObj.IsDate(txtToDate.Text))
                    {
                        string message = "alert('Invalid To Date !!!');";
                        ScriptManager.RegisterStartupScript(this, this.GetType(), "alert", message, true);
                        txtToDate.Focus();
                        return;
                    }
                }

                CreamBell_DMS_WebApps.App_Code.Global obj = new CreamBell_DMS_WebApps.App_Code.Global();
                bool b = ValidateSearch();
                GridView1.DataSource = null;
                GridView2.DataSource = null;
                GridView2.DataBind();
                if (b == true)
                {
                    DateTime endDate = Convert.ToDateTime(this.txtToDate.Text);
                    //endDate.AddDays(1);
                    //DateTime end = endDate.AddDays(1);

                    string FromDate = Convert.ToDateTime(txtFromDate.Text).ToString("dd-MMM-yyyy");
                    string ToDate   = endDate.ToString("dd-MMM-yyyy");

                    //string query = "Select A.PURCH_RETURNNO as INVOICE_NO , A.PURCH_RETURNDATE as INVOIC_DATE, A.Purch_recieptno as SO_NO,case when CONVERT(VARCHAR(10),PURCH_RECIEPTDATE , 103)= '01/01/1900' then '' else CONVERT(VARCHAR(10),PURCH_RECIEPTDATE , 103) end  AS SO_DATE, ('[' + A.SITE_CODE +']' + ' ' + B.NAME) as CUSTOMER , A.Return_docvalue as INVOICE_VALUE" +
                    //               " from ax.[ACXPURCHRETURNHEADER]  A  INNER JOIN ax.inventsite B   ON A.SITE_CODE=B.SITEID" +
                    //                " where  A.SITE_CODE= '" + Session["SiteCode"].ToString() + "' and PURCH_RETURNDATE>='" + FromDate + "' and PURCH_RETURNDATE<='" + ToDate + "'";

                    string query = "Select A.PURCH_RETURNNO as INVOICE_NO , A.PURCH_RETURNDATE as INVOIC_DATE, A.Purch_recieptno as SO_NO,case when CONVERT(VARCHAR(10),PURCH_RECIEPTDATE , 103)= '01/01/1900' then '' else CONVERT(VARCHAR(10),PURCH_RECIEPTDATE , 103) end  AS SO_DATE, ('[' + A.SITE_CODE +']' + ' ' + B.NAME) as CUSTOMER , A.Return_docvalue as INVOICE_VALUE" +
                                   " from ax.[ACXPURCHRETURNHEADER]  A  INNER JOIN ax.inventsite B   ON A.SITE_CODE=B.SITEID" +
                                   " where  A.SITE_CODE IN (" + ucRoleFilters.GetCommaSepartedSiteId() + ") and PURCH_RETURNDATE>='" + FromDate + "' and PURCH_RETURNDATE<='" + ToDate + "'";

                    //if (txtInvoiceNoStart.Text != string.Empty && txtInvoiceNoEnd.Text != string.Empty)
                    //{
                    //    try
                    //    {
                    //        string[] strInvoicefromsplit = txtInvoiceNoStart.Text.Split('-');
                    //        string[] strInvoiceTosplit = txtInvoiceNoEnd.Text.Split('-');
                    //        query = query + "and cast(Right(A.invoice_no,6) as int) between " + strInvoicefromsplit[1] + " and " + strInvoiceTosplit[1] + " ";
                    //    }
                    //    catch
                    //    {
                    //        ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", " alert('Invoice number is not in correct format !! ');", true);
                    //        GridView1.DataSource = null;
                    //        GridView1.DataBind();
                    //        return;
                    //    }
                    //
                    //
                    //}
                    //if (drpPSR.SelectedItem.Text != string.Empty && drpPSR.SelectedItem.Text != "Select...")
                    //{
                    //    query = query + "and B.psr_code='" + drpPSR.SelectedItem.Value + "' ";
                    //
                    //    if (drpBeat.SelectedItem.Text != string.Empty && drpBeat.SelectedItem.Text != "Select...")
                    //    {
                    //        query = query + "and B.psr_beat='" + drpBeat.SelectedItem.Value + "' ";
                    //
                    //        if (drpCustomer.SelectedItem.Text != string.Empty && drpCustomer.Text != "Select...")
                    //        {
                    //            query = query + "and A.CUSTOMER_CODE='" + drpCustomer.SelectedItem.Value + "' ";
                    //        }
                    //    }
                    //}
                    if (ddlSearchNew.Text == "Sales Invoice No" && txtSearch.Text != "")
                    {
                        query = query + "AND A.PURCH_RETURNNO like '%" + txtSearch.Text.Trim().ToString() + "%'";
                    }
                    //if (ddlSearch.Text == "Customer")
                    //{
                    //    query = query + " and (A.CUSTOMER_CODE like '%" + txtSearch.Text.Trim().ToString() + "%' or B.CUSTOMER_NAME like '%" + txtSearch.Text.Trim().ToString() + "%') ";
                    //}
                    query = query + "  ORDER BY A.PURCH_RETURNDATE DESC, A.PURCH_RETURNNO DESC";

                    DataTable dtFilter = obj.GetData(query);
                    if (dtFilter.Rows.Count > 0)
                    {
                        GridView1.DataSource = dtFilter;
                        GridView1.DataBind();

                        CheckBox chk = (CheckBox)GridView1.HeaderRow.FindControl("checkAll");
                        chk.Checked = true;


                        foreach (GridViewRow grv in GridView1.Rows)
                        {
                            CheckBox chkAll = (CheckBox)grv.Cells[0].FindControl("chklist");
                            chkAll.Checked = true;
                        }
                        // uppanel.Update();
                    }
                    else
                    {
                        ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", " alert('No Data Exist !! ');", true);
                        GridView1.DataSource = null;
                        GridView1.DataBind();
                        //GridDetail();
                        txtSearch.Text = string.Empty;
                    }
                }
            }
            catch (Exception ex)
            {
                ErrorSignal.FromCurrentContext().Raise(ex);
            }
        }
        protected void btnSearch_Click(object sender, EventArgs e)
        {
            CreamBell_DMS_WebApps.App_Code.Global baseObj = new CreamBell_DMS_WebApps.App_Code.Global();

            if (txtFromDate.Text.Trim().Length > 0)
            {
                if (!baseObj.IsDate(txtFromDate.Text))
                {
                    string message = "alert('Invalid From Date !!!');";
                    ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alert", message, true);
                    txtFromDate.Focus();
                    return;
                }
            }
            if (txtToDate.Text.Trim().Length > 0)
            {
                if (!baseObj.IsDate(txtToDate.Text))
                {
                    string message = "alert('Invalid To Date !!!');";
                    ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alert", message, true);
                    txtToDate.Focus();
                    return;
                }
            }

            CreamBell_DMS_WebApps.App_Code.Global obj = new CreamBell_DMS_WebApps.App_Code.Global();
            bool b = ValidateSearch();

            GridView1.DataSource = null;
            GridView2.DataSource = null;
            GridView2.DataBind();
            if (b == true)
            {
                DateTime endDate = Convert.ToDateTime(this.txtToDate.Text);

                string FromDate = Convert.ToDateTime(txtFromDate.Text).ToString("dd-MMM-yyyy");
                string ToDate   = endDate.ToString("dd-MMM-yyyy");
                if (ddlState.SelectedItem.Text == "Select...")
                {
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", " alert('Please fill the State !! ');", true);
                    return;
                }
                else
                {
                    if (ddlSiteId.SelectedItem.Text == "Select...")
                    {
                        ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", " alert('Please fill the Distributor !! ');", true);
                        return;
                    }
                    else
                    {
                        string    query    = "EXEC USP_SERVICEINVOICEDETAIL '" + ddlSiteId.SelectedValue + "','" + FromDate + "','" + ToDate + "'";
                        DataTable dtFilter = obj.GetData(query);
                        if (dtFilter.Rows.Count > 0)
                        {
                            GridView1.DataSource = dtFilter;
                            GridView1.DataBind();

                            CheckBox chk = (CheckBox)GridView1.HeaderRow.FindControl("checkAll");
                            chk.Checked = true;


                            foreach (GridViewRow grv in GridView1.Rows)
                            {
                                CheckBox chkAll = (CheckBox)grv.Cells[0].FindControl("chklist");
                                chkAll.Checked = true;
                            }
                        }
                        else
                        {
                            ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", " alert('No Data Exist !! ');", true);
                            GridView1.DataSource = null;
                            GridView1.DataBind();
                        }
                    }
                }
            }
        }