protected void GetTarikhLocation()
    {
        int caseID = int.Parse(((GridView)CaseSearch1.FindControl("grdCase")).SelectedRow.Cells[2].Text);

        tarikhLocationGrid.DataSource = BLLTarikhLocation.GetTarikhLocation(caseID);
        tarikhLocationGrid.DataBind();
    }
    protected void tarikhLocationGrid_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        int caseID   = int.Parse(((GridView)CaseSearch1.FindControl("grdCase")).SelectedRow.Cells[2].Text);
        int courtID  = Convert.ToInt32((this.tarikhLocationGrid.DataKeys[(e.RowIndex)].Values["CourtID"]));
        int personID = Convert.ToInt32((this.tarikhLocationGrid.DataKeys[(e.RowIndex)].Values["PersonID"]));

        try
        {
            BLLTarikhLocation.DeleteTarikhLocation(caseID, personID, courtID);
            GetTarikhLocation();
            lblStatusMessage.Text = "Deleted Successfully";
            programmaticModalPopup.Show();
        }
        catch (Exception ex)
        {
            throw ex;
            programmaticModalPopup.Show();
        }
    }
    protected void btnSave_Click(object sender, EventArgs e)
    {
        if (ddlCourt.SelectedIndex <= 0)
        {
            lblStatusMessage.Text = "Please Select Court Type";
            this.programmaticModalPopup.Show();
            return;
        }
        if (fromDateTxt.Text == "")
        {
            lblStatusMessage.Text = "जारी मिति छुट्यो";
            this.programmaticModalPopup.Show();
            return;
        }


        List <ATTTarikhLocation> lstTarikhLocation = new List <ATTTarikhLocation>();

        foreach (GridViewRow grow in grdLitigantsApp.Rows)
        {
            if (((CheckBox)grow.FindControl("chk")).Checked)
            {
                ATTTarikhLocation obj = new ATTTarikhLocation();

                obj.CaseID     = int.Parse(grow.Cells[1].Text.Trim());
                obj.PersonID   = int.Parse(grow.Cells[2].Text.Trim());
                obj.PersonType = "S";
                lstTarikhLocation.Add(obj);
            }
            foreach (GridViewRow grow1 in ((GridView)grow.FindControl("grdAttorney1")).Rows)
            {
                if (((CheckBox)grow1.FindControl("chk")).Checked)
                {
                    ATTTarikhLocation obj = new ATTTarikhLocation();
                    obj.CaseID     = int.Parse(grow1.Cells[0].Text.Trim());
                    obj.PersonID   = int.Parse(grow1.Cells[2].Text.Trim());
                    obj.PersonType = "W";
                    lstTarikhLocation.Add(obj);
                }
            }
        }

        foreach (GridViewRow grow in grdLitigantRes.Rows)
        {
            if (((CheckBox)grow.FindControl("chkRes")).Checked)
            {
                ATTTarikhLocation obj = new ATTTarikhLocation();
                obj.CaseID     = int.Parse(grow.Cells[1].Text.Trim());
                obj.PersonID   = int.Parse(grow.Cells[2].Text.Trim());
                obj.PersonType = "S";
                lstTarikhLocation.Add(obj);
            }
            foreach (GridViewRow grow1 in ((GridView)grow.FindControl("grdAttorney")).Rows)
            {
                if (((CheckBox)grow1.FindControl("chk")).Checked)
                {
                    ATTTarikhLocation obj = new ATTTarikhLocation();
                    obj.CaseID     = int.Parse(grow1.Cells[0].Text.Trim());
                    obj.PersonID   = int.Parse(grow1.Cells[2].Text.Trim());
                    obj.PersonType = "W";
                    lstTarikhLocation.Add(obj);
                }
            }
        }


        if (lstTarikhLocation.Count > 0)
        {
            foreach (ATTTarikhLocation obj in lstTarikhLocation)
            {
                obj.FromDate = fromDateTxt.Text;
                obj.EntryBy  = entryBy;
                obj.Action   = "A";
                obj.CourtID  = int.Parse(this.ddlCourt.SelectedValue.ToString());
            }
            //removing multiple occurences of person_id in case of attorney
            foreach (ATTTarikhLocation obj in lstTarikhLocation)
            {
                int personId = obj.PersonID;
                int count    = 0;

                for (int i = 0; i < lstTarikhLocation.Count; i++)
                {
                    if (personId == lstTarikhLocation[i].PersonID)
                    {
                        count++;
                    }
                    if (count > 1)
                    {
                        lstTarikhLocation[i].Action = "Rem";
                    }
                }
            }
        }

        if (lstTarikhLocation.Count == 0)
        {
            lblStatusMessage.Text = "No data selected";
            this.programmaticModalPopup.Show();
            return;
        }

        try
        {
            BLLTarikhLocation.AddTarikhLocation(lstTarikhLocation);
            lblStatusMessage.Text = "Data Saved Successfully";
            this.programmaticModalPopup.Show();
            ClearControls();
            GetTarikhLocation();
        }
        catch (Exception ex)
        {
            lblStatusMessage.Text = "Problem Saving Data " + ex.Message;
            this.programmaticModalPopup.Show();
        }
    }