//protected void tarikhDetailsGrid_SelectedIndexChanged(object sender, EventArgs e)
    //{
    //    GridViewRow row = ((GridView)sender).SelectedRow;

    //    if (row == null) return;

    //    ModalPopupExtender Extender = row.FindControl("extPerson") as ModalPopupExtender;


    //    if (Extender != null)
    //    {
    //        Extender.Show();
    //    }
    //}

  
    //protected void tarikhDetailsGrid_RowDataBound(object sender, GridViewRowEventArgs e)
    //{
    //    e.Row.Cells[0].Visible = false;
    //}
    //protected void tarikhListGrid_RowEditing(object sender, GridViewEditEventArgs e)
    //{
    //    this.tarikhListGrid.EditIndex = e.NewEditIndex;
    //    this.tarikhListGrid.DataSource = (List<ATTTarikh>)Session["TarikhList"];
    //    this.tarikhListGrid.DataBind();
    //}
    //protected void tarikhListGrid_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
    //{
    //    this.tarikhListGrid.EditIndex = -1;
    //    this.tarikhListGrid.DataSource = (List<ATTTarikh>)Session["TarikhList"];
    //    this.tarikhListGrid.DataBind();
    //}
    //protected void tarikhListGrid_RowUpdating(object sender, GridViewUpdateEventArgs e)
    //{
    //    List<ATTTarikh> tarikhLst=(List<ATTTarikh>)Session["TarikhList"];
    //    int personId = Convert.ToInt32(this.tarikhListGrid.DataKeys[(e.RowIndex)].Values["PersonID"]);

    //    int index = tarikhLst.FindIndex
    //    (
    //        delegate(ATTTarikh obj)
    //        {
    //            return obj.PersonID == personId;

    //        }
    //    );

        
    //    tarikhLst[index].TakenTime = ((TextBox)tarikhListGrid.Rows[e.RowIndex].Cells[1].FindControl("takenDateTxtEdit")).Text;
    //    tarikhLst[index].PresentDate = ((TextBox)tarikhListGrid.Rows[e.RowIndex].Cells[2].FindControl("presentDateTxtEdit")).Text;
    //    tarikhLst[index].Action = "E";
    //    Session["TarikhList"] = tarikhLst;
    //    this.tarikhListGrid.EditIndex = -1;
    //    this.tarikhListGrid.DataSource = (List<ATTTarikh>)Session["TarikhList"];
    //    this.tarikhListGrid.DataBind();





    //}
    protected void saveTarikhListBtn_Click(object sender, EventArgs e)
    {
        if (this.tarikhGrid.SelectedIndex > -1)
        {
            
            ATTTarikh tarikh=new ATTTarikh();
            List<ATTTarikh> listTarikh = new List<ATTTarikh>();
           
            tarikh.CaseID=int.Parse(((GridView)CaseSearch1.FindControl("grdCase")).SelectedRow.Cells[2].Text);
            tarikh.TarikhDate = tarikhGrid.SelectedRow.Cells[0].Text;
            tarikh.TarikhTime =((TextBox)tarikhGrid.SelectedRow.FindControl("tarikhTimeTxt")).Text;
            tarikh.Action="E";

        
        List<ATTTarikh> tarikhLst = (List<ATTTarikh>)Session["TarikhList"];
        try
        {
            BLLTarikh.AddTarikhDetails(tarikhLst);
            BLLTarikh.AddTarikh(listTarikh);
            lblStatusMessage.Text = "Tarikh List Updated Successfully";
            this.programmaticModalPopup.Show();
            return;
        }
        catch (Exception ex)
        {
            this.lblStatusMessage.Text = "Tarikh List Could not be updated " + ex.Message;
            this.programmaticModalPopup.Show();
            return;
        }
    }

    }
    protected void btnSave_Click(object sender, EventArgs e)
    {
        TarikhFunction();
      

        if (this.tarikhGrid.SelectedIndex > -1)
        {
            List<ATTTarikh> tarikhDetailsList = (List<ATTTarikh>)Session["TarikhList"];
            List<ATTTarikh> tarikhList = (List<ATTTarikh>)Session["Tarikh"];

            foreach (ATTTarikh objT in tarikhDetailsList)
            {
                if (objT.Action != "A" && objT.Action!="R")
                {
                    objT.Action = "E";
                }
            }

            for (int i = 0; i < tarikhListGrid.Rows.Count;i++ )
            {
                int index = tarikhDetailsList.FindIndex
                (   
                        delegate(ATTTarikh obj1)
                        {
                            return (obj1.PersonID ==Convert.ToInt32(this.tarikhListGrid.DataKeys[i].Values["PersonID"]));
                        }
                    );
                tarikhDetailsList[index].TakenTime = ((TextBox)tarikhListGrid.Rows[i].FindControl("takenDateTxtEdit")).Text;
                tarikhDetailsList[index].PresentDate = ((TextBox)tarikhListGrid.Rows[i].FindControl("presentDateTxtEdit")).Text;
                tarikhDetailsList[index].TarikhDate = tarikhGrid.SelectedRow.Cells[0].Text;
            }

            try
            {
                if (BLLTarikh.AddTarikh(tarikhList) && BLLTarikh.AddTarikhDetails(tarikhDetailsList))
                {
                    lblStatusMessage.Text = "Save Successful";
                    this.programmaticModalPopup.Show();
                }

            }
            catch (Exception ex)
            {
                lblStatusMessage.Text = "Problem while saving data" + ex.Message;
                this.programmaticModalPopup.Show();
            }


            ClearControls();
            GetTarikh();

        }
        else
        {
            this.lblStatusMessage.Text = "Please select Tarikh";
            this.programmaticModalPopup.Show();
        }

    }
 protected void GetTarikh()
 {
     int caseId=int.Parse(((GridView)CaseSearch1.FindControl("grdCase")).SelectedRow.Cells[2].Text);
     List<ATTTarikh> lst = BLLTarikh.GetTarikh(caseId);
     Session["Tarikh"] = lst;
     tarikhGrid.DataSource = lst;
     tarikhGrid.DataBind();
 }
    protected void GetTarkihList(int caseId, string tarikhDate)
    {

        List<ATTTarikh> tarikhList = BLLTarikh.GetTarikhDetails(caseId, tarikhDate);
        Session["TarikhList"] = tarikhList;
        this.tarikhListGrid.DataSource = tarikhList;
        this.tarikhListGrid.DataBind();

    }