private void BindGrid()
    {
        try
        {
            AstreeDonnees a = new AstreeDonnees();

            List <DetailCommandeDB> ls = a.GetDetailCommande().Where(w => w.LibelleService.Trim() == "Commande" && w.code_dest == Convert.ToInt16(Session["code_utilisateur"].ToString())).OrderBy(w => w.etat).ThenByDescending(w => w.dateDemande).ToList();
            gv_Commande.DataSource = ls;
            gv_Commande.DataBind();
            foreach (GridViewRow row in gv_Commande.Rows)
            {
                if (row.RowType == DataControlRowType.DataRow)
                {
                    CheckBox cb = (row.Cells[0].FindControl("Accepter") as CheckBox);

                    DetailCommandeDB serv = ls.Where(w => w.code_service == Convert.ToInt16(row.Cells[1].Text.ToString().Trim())).FirstOrDefault();
                    if (serv != null)
                    {
                        if (serv.etat.ToString().Trim() == "V")
                        {
                            cb.Checked = true;
                        }
                    }
                }
            }
        }
        catch (Exception ex)
        {
        }
    }
    protected void Btnreponse_Click(object sender, EventArgs e)
    {
        MsgCode.Text    = "";
        MsgEtat.Text    = "";
        MsgReponse.Text = "";

        try
        {
            AstreeDonnees a          = new AstreeDonnees();
            serviceDB     lstService = a.GetServices().Where(w => w.libelleService.Trim() == "Commande" && w.code_service == Convert.ToInt16(txtcodeService.Text)).FirstOrDefault();



            if (txtCode.Text == "")
            {
                MsgCode.Visible = true;
                MsgCode.Text    = "Vous devez selectionner une commande !";
            }
            //else if (txtEtat.Text == "")
            //{
            //    MsgEtat.Visible = true;
            //    MsgEtat.Text = "Vous devez valider la commande !";
            //}
            else if (txtReponse.Text == "")
            {
                MsgReponse.Visible = true;
                MsgReponse.Text    = "Vous devez sasir votre réponse !";
            }
            else
            {
                DetailCommandeDB detailComm = a.GetDetailCommande().Where(w => w.LibelleService.Trim() == "Commande" && w.code_service == lstService.code_service && w.LibelleProduit.Trim() == txtProduit.Text.Trim()).FirstOrDefault();

                if (detailComm != null)
                {
                    detailComm.reponse   = txtReponse.Text;
                    detailComm.QteLivree = detailComm.Qte;
                    a.maj_DetailCommande(detailComm);
                }

                List <DetailCommandeDB> lstDetailComm = a.GetDetailCommande().Where(w => w.LibelleService.Trim() == "Commande" && w.code_dest == Convert.ToInt16(Session["code_utilisateur"].ToString()) && w.code_service == lstService.code_service && w.QteLivree == 0).ToList();

                if (lstService != null && lstDetailComm.Count == 0)
                {
                    lstService.etat        = "V";
                    lstService.dateReponse = DateTime.Now;
                    lstService.reponse     = txtReponse.Text;
                    a.maj_Commande(lstService);



                    Label x = (Label)Master.FindControl("lblNotifCommandeFourn") as Label;
                    Label y = (Label)Master.FindControl("nbNotification") as Label;

                    List <serviceDB> lsNotification = a.GetServices().Where(w => (w.libelleService != null) && (w.etat.Trim() == "A") && (w.codeDest == Convert.ToInt16(Session["code_utilisateur"]))).ToList();
                    x.Text = lsNotification.Where(w => w.libelleService.Trim() == "Commande").Count().ToString();
                    y.Text = x.Text;
                    BindGrid();
                }

                lblMsgSucces.Visible = true;
                lblMsgSucces.Text    = "Reponse envoyé avec succés!";
                txtCode.Text         = "";
                txtcodeService.Text  = "";
                //txtEtat.Text = "";
                txtReponse.Text = "";


                List <DetailCommandeDB> ls = a.GetDetailCommande().Where(w => w.LibelleService.Trim() == "Commande" && w.code_dest == Convert.ToInt16(Session["code_utilisateur"].ToString())).ToList();
                gv_Commande.DataSource = ls;
                gv_Commande.DataBind();
            }
        }
        catch (Exception ex)
        {
            MsgCode.Visible = true;
            MsgCode.Text    = "Vous devez selectionner une commande !";
        }
    }