private void GridBind(string order)
    {
        string tipologia="";
        if (pb.cd_tipologia().ToString() != "0")
        {
            tipologia = " t04_cd_tipologia = " + pb.cd_tipologia().ToString() +" and ";
        }

        string colspan = "5";
        PanelGrid.Controls.Clear();
        StringBuilder sb = new StringBuilder();
        sb.Append("<table  cellspacing=\"2\" cellpadding=\"4\" class=\"tblist\">");

        t03_projeto t03 = new t03_projeto();
        {
            //t03.t01_cd_entidade = cd_entidade; //somente a entidade do parceiro
            if (pb.fl_admin() || pb.fl_visitante() || pb.fl_estrategico())
            {

                //entidade do usuário
                //t03.order = " and t01_cd_entidade in (select t01_cd_entidade from t03_projeto where " + tipologia + " fl_ativa=1 and t01_cd_entidade="+pb.cd_entidade()+" ) order by nm_entidade";
                if (pb.fl_visitante())
                {
                    t03.order = " and t01_cd_entidade in (select t01_cd_entidade from t03_projeto where " + tipologia + " fl_ativa=1 and t03_cd_projeto in (select t03_cd_projeto from t20_faseprojeto where t19_cd_fase = 2 or t19_cd_fase = 1)) order by nm_entidade";
               }
                else
                {
                    t03.order = " and t01_cd_entidade in (select t01_cd_entidade from t03_projeto where " + tipologia + " fl_ativa=1) order by nm_entidade";
                }

                if (Session["vr"] != null)
                {
                    t03.order = " and t01_cd_entidade = " + Session["vr"].ToString() + " "+
                            //"(select t01_cd_entidade from t03_projeto where " + tipologia + " fl_ativa=1 and t01_cd_entidade = " + Session["vr"].ToString() + " " +
                            "order by nm_entidade";
                }

                    foreach (DataRow dre in t03.ListEntidade().Tables[0].Rows)
                {
                    sb.Append("<tr class=\"hr_white\">");
                    sb.Append("<td colspan='" + colspan + "'>" + dre["nm_entidade"] + "</td>");
                    sb.Append("</tr>");

                    t03.order = tipologia;
                    t03.t01_cd_entidade = Int32.Parse(dre["t01_cd_entidade"].ToString());
                    foreach (DataRow drt in t03.ListTipologia().Tables[0].Rows)
                    {
                        sb.Append("<tr  class=\"hr_yellow\">");
                        sb.Append("<td colspan='" + colspan + "'>" + drt["nm_tipologia"] + "</td>");
                        sb.Append("</tr>");

                        sb.Append("<tr class=\"hr_orange\">");
                        if (!pb.fl_semperfil((int)dre["t01_cd_entidade"]))
                        {
                            sb.Append("<td>Eixos</td>");
                        }
                        else { sb.Append("<td colspan=2>Eixos</td>"); }

         //LEVI               sb.Append("<td>Fase</td>");
         //LEVI 11-02-2015                  sb.Append("<td>Atualizado</td>");
                        if (!pb.fl_semperfil((int)dre["t01_cd_entidade"])) { sb.Append("<td>Restri&ccedil;&atilde;o</td>"); }
                        sb.Append("<td style='width:200px'>Evolu&ccedil;&atilde;o</td>");
                        sb.Append("</tr>");

                        if (pb.fl_visitante())
                        {
                            t03.order = "where fl_ativa = 1" +
                                " and t03_cd_projeto in " +
                                " (select t03_cd_projeto from t20_faseprojeto where t19_cd_fase = 2 or t19_cd_fase = 1)" +
                                " and t01_cd_entidade=" + dre["t01_cd_entidade"].ToString() +
                                " and t04_cd_tipologia=" + drt["t04_cd_tipologia"].ToString();
                        }
                        else
                        {
                            t03.order = "where fl_ativa=1" +
                                " and t01_cd_entidade=" + dre["t01_cd_entidade"].ToString() +
                                " and t04_cd_tipologia=" + drt["t04_cd_tipologia"].ToString() +
                                " order by nm_projeto";

                        }
                        foreach (DataRow drp in t03.List().Tables[0].Rows)
                        {
                            string nm_projeto = drp["nm_projeto"].ToString();
                            string nm_fase = "";
                            string data = "-";

                            if (drp["dt_alterado"] != DBNull.Value)
                            {
                                data = String.Format("{0:dd/MM/yyyy}", DateTime.Parse(drp["dt_alterado"].ToString()));
                            }

                            t19_fase t19 = new t19_fase();
                            {
                                t19.t19_cd_fase = Int32.Parse(drp["t03_cd_projeto"].ToString()); //usando o t19_cd_fase para armazenar t03_cd_projeto;
                                t19.RetrieveFaseProjeto();
                                if (t19.Found)
                                {
                                    nm_fase = t19.nm_fase;
                                }
                            }

                            sb.Append("<tr>");
                            PanelGrid.Controls.Add(pb.GetLiteral(sb.ToString()));

                            if (!pb.fl_semperfil((int)dre["t01_cd_entidade"]))
                            {
                                PanelGrid.Controls.Add(pb.GetLiteral("<td>"));
                            }
                            else { PanelGrid.Controls.Add(pb.GetLiteral("<td colspan=2>")); }
                            LinkButton link = new LinkButton();
                            {
                                link.ID = "linkP" + drp["t03_cd_projeto"].ToString();
                                link.CommandArgument = drp["t03_cd_projeto"].ToString();
                                link.Text = nm_projeto;
                                link.Click += new EventHandler(link_Click);
                            }
                            PanelGrid.Controls.Add(link);
                            PanelGrid.Controls.Add(pb.GetLiteral("</td>"));//Projeto

                            sb = new StringBuilder();
                 //LEVI           sb.Append("<td>" + nm_fase + "</td>"); //Fase
                 //LEVI 11-02-2015        sb.Append("<td style='text-align:center'>" + data + "</td>"); //Atualizado

                            if (!pb.fl_semperfil((int)dre["t01_cd_entidade"]))
                            {
                                t07_restricao t07 = new t07_restricao();
                                {
                                    t07.t03_cd_projeto = Int32.Parse(drp["t03_cd_projeto"].ToString());
                                    if (t07.List().Tables[0].Rows.Count == 0)
                                    {
                                        sb.Append("<td>&nbsp;</td>"); //Restrição
                                    }
                                    else
                                    {
                                        sb.Append("<td style='text-align:center'><b>R</b></td>"); //Restrição
                                    }
                                }
                            }

                            sb.Append("<td>" + pb.Status(Int32.Parse(drp["t03_cd_projeto"].ToString())) + "</td>"); //Evolução
                            sb.Append("</tr>");
                        }
                    }
                }
                //restante das entidades
                //t03.order = " and t01_cd_entidade in (select t01_cd_entidade from t03_projeto where " + tipologia + " fl_ativa=1  and t01_cd_entidade<>" + pb.cd_entidade() + ") order by nm_entidade";
                //foreach (DataRow dre in t03.ListEntidade().Tables[0].Rows)
                //{
                //    sb.Append("<tr class=\"hr_white\">");
                //    sb.Append("<td colspan='" + colspan + "'>" + dre["nm_entidade"] + "</td>");
                //    sb.Append("</tr>");

                //    t03.order = tipologia;
                //    t03.t01_cd_entidade = Int32.Parse(dre["t01_cd_entidade"].ToString());
                //    foreach (DataRow drt in t03.ListTipologia().Tables[0].Rows)
                //    {
                //        sb.Append("<tr  class=\"hr_yellow\">");
                //        sb.Append("<td colspan='" + colspan + "'>" + drt["nm_tipologia"] + "</td>");
                //        sb.Append("</tr>");

                //        sb.Append("<tr class=\"hr_orange\">");
                //        if (!pb.fl_semperfil((int)dre["t01_cd_entidade"]))
                //        {
                //            sb.Append("<td>Projeto</td>");
                //        }
                //        else { sb.Append("<td colspan=2>Projeto</td>"); }

                //        sb.Append("<td>Fase</td>");
                //        sb.Append("<td>Atualizado</td>");
                //        if (!pb.fl_semperfil((int)dre["t01_cd_entidade"])) { sb.Append("<td>Restri&ccedil;&atilde;o</td>"); }
                //        sb.Append("<td style='width:120px'>Evolu&ccedil;&atilde;o</td>");
                //        sb.Append("</tr>");

                //        t03.order = "where fl_ativa=1" +
                //            " and t01_cd_entidade=" + dre["t01_cd_entidade"].ToString() +
                //            " and t04_cd_tipologia=" + drt["t04_cd_tipologia"].ToString() +
                //            " order by nm_projeto";

                //        foreach (DataRow drp in t03.List().Tables[0].Rows)
                //        {
                //            string nm_projeto = drp["nm_projeto"].ToString();
                //            string nm_fase = "";
                //            string data = "-";

                //            if (drp["dt_alterado"] != DBNull.Value)
                //            {
                //                data = String.Format("{0:dd/MM/yyyy}", DateTime.Parse(drp["dt_alterado"].ToString()));
                //            }

                //            t19_fase t19 = new t19_fase();
                //            {
                //                t19.t19_cd_fase = Int32.Parse(drp["t03_cd_projeto"].ToString()); //usando o t19_cd_fase para armazenar t03_cd_projeto;
                //                t19.RetrieveFaseProjeto();
                //                if (t19.Found)
                //                {
                //                    nm_fase = t19.nm_fase;
                //                }
                //            }

                //            sb.Append("<tr>");
                //            PanelGrid.Controls.Add(pb.GetLiteral(sb.ToString()));

                //            if (!pb.fl_semperfil((int)dre["t01_cd_entidade"]))
                //            {
                //                PanelGrid.Controls.Add(pb.GetLiteral("<td>"));
                //            }
                //            else { PanelGrid.Controls.Add(pb.GetLiteral("<td colspan=2>")); }

                //            LinkButton link = new LinkButton();
                //            {
                //                link.ID = "linkP" + drp["t03_cd_projeto"].ToString();
                //                link.CommandArgument = drp["t03_cd_projeto"].ToString();
                //                link.Text = nm_projeto;
                //                link.Click += new EventHandler(link_Click);
                //            }
                //            PanelGrid.Controls.Add(link);
                //            PanelGrid.Controls.Add(pb.GetLiteral("</td>"));//Projeto

                //            sb = new StringBuilder();
                //            sb.Append("<td>" + nm_fase + "</td>"); //Fase
                //            sb.Append("<td style='text-align:center'>" + data + "</td>"); //Atualizado
                //            if (!pb.fl_semperfil((int)dre["t01_cd_entidade"]))
                //            {
                //                t07_restricao t07 = new t07_restricao();
                //                {
                //                    t07.t03_cd_projeto = Int32.Parse(drp["t03_cd_projeto"].ToString());
                //                    if (t07.List().Tables[0].Rows.Count == 0)
                //                    {
                //                        sb.Append("<td>&nbsp;</td>"); //Restrição
                //                    }
                //                    else
                //                    {
                //                        sb.Append("<td style='text-align:center'><b>R</b></td>"); //Restrição
                //                    }
                //                }
                //            }

                //            sb.Append("<td>" + pb.Status(Int32.Parse(drp["t03_cd_projeto"].ToString())) + "</td>"); //Evolução
                //            sb.Append("</tr>");
                //        }
                //    }
                //}
            }
            else //se usuário sem perfil e diferente de visitante
            {
                if (pb.cd_parceiro() != 0) //parceiro
                {
                    t03.order = " and t01_cd_entidade in " +
                        "(select t01_cd_entidade from t03_projeto where " + tipologia + " fl_ativa=1 and t01_cd_entidade in " +
                        "(select t01_cd_entidade from t05_parceiro where t05_cd_parceiro=" + pb.cd_parceiro() + ")) " +
                        "order by nm_entidade";
                    //Response.Write(t03.order+"<br>");
                    foreach (DataRow dre in t03.ListEntidade().Tables[0].Rows)
                    {
                        sb.Append("<tr class=\"hr_white\">");
                        sb.Append("<td colspan='" + colspan + "'>" + dre["nm_entidade"] + "</td>");
                        sb.Append("</tr>");

                        t03.order = tipologia;
                        t03.t01_cd_entidade = Int32.Parse(dre["t01_cd_entidade"].ToString());
                        foreach (DataRow drt in t03.ListTipologia().Tables[0].Rows)
                        {
                            sb.Append("<tr  class=\"hr_yellow\">");
                            sb.Append("<td colspan='" + colspan + "'>" + drt["nm_tipologia"] + "</td>");
                            sb.Append("</tr>");

                            sb.Append("<tr class=\"hr_orange\">");
                            if (!pb.fl_semperfil((int)dre["t01_cd_entidade"]))
                            {
                                sb.Append("<td>Eixos</td>");
                            }
                            else { sb.Append("<td colspan=2>Eixos</td>"); }
                      //LEVI       sb.Append("<td>Fase</td>");
                    //LEVI 11-02-2015		sb.Append("<td>Atualizado</td>");

                    //LEVI         if (!pb.fl_semperfil((int)dre["t01_cd_entidade"])) { sb.Append("<td>Restri&ccedil;&atilde;o</td>"); }
                            sb.Append("<td style='width:200px'>Evolu&ccedil;&atilde;o</td>");
                            sb.Append("</tr>");

                            t03.order = "where fl_ativa=1" +
                                " and t01_cd_entidade=" + dre["t01_cd_entidade"].ToString() +
                                " and t04_cd_tipologia=" + drt["t04_cd_tipologia"].ToString() +
                                " order by nm_projeto";

                            foreach (DataRow drp in t03.List().Tables[0].Rows)
                            {
                                string nm_projeto = drp["nm_projeto"].ToString();
                                string nm_fase = "";
                                string data = "-";

                                if (drp["dt_alterado"] != DBNull.Value)
                                {
                                    data = String.Format("{0:dd/MM/yyyy}", DateTime.Parse(drp["dt_alterado"].ToString()));
                                }

                                t19_fase t19 = new t19_fase();
                                {
                                    t19.t19_cd_fase = Int32.Parse(drp["t03_cd_projeto"].ToString()); //usando o t19_cd_fase para armazenar t03_cd_projeto;
                                    t19.RetrieveFaseProjeto();
                                    if (t19.Found)
                                    {
                                        nm_fase = t19.nm_fase;
                                    }
                                }

                                sb.Append("<tr>");
                                PanelGrid.Controls.Add(pb.GetLiteral(sb.ToString()));

                                if (!pb.fl_semperfil((int)dre["t01_cd_entidade"]))
                                {
                                    PanelGrid.Controls.Add(pb.GetLiteral("<td>"));
                                }
                                else { PanelGrid.Controls.Add(pb.GetLiteral("<td colspan=2>")); }

                                LinkButton link = new LinkButton();
                                {
                                    link.ID = "linkP2" + drp["t03_cd_projeto"].ToString();
                                    link.CommandArgument = drp["t03_cd_projeto"].ToString();
                                    link.Text = nm_projeto;
                                    link.Click += new EventHandler(link_Click);
                                }
                                PanelGrid.Controls.Add(link);
                                PanelGrid.Controls.Add(pb.GetLiteral("</td>"));//Programas

                                sb = new StringBuilder();
                         //LEVI        sb.Append("<td>" + nm_fase + "</td>"); //Fase
                         //LEVI 11-02-2015       sb.Append("<td style='text-align:center'>" + data + "</td>"); //Atualizado
                                if (!pb.fl_semperfil((int)dre["t01_cd_entidade"]))
                                {
                                    t07_restricao t07 = new t07_restricao();
                                    {
                                        t07.t03_cd_projeto = Int32.Parse(drp["t03_cd_projeto"].ToString());
                                        if (t07.List().Tables[0].Rows.Count == 0)
                                        {
                                     //LEVI        sb.Append("<td>&nbsp;</td>"); //Restrição
                                        }
                                        else
                                        {
                                     //LEVI       sb.Append("<td style='text-align:center'><b>R</b></td>"); //Restrição
                                        }
                                    }
                                }

                                sb.Append("<td>" + pb.Status(Int32.Parse(drp["t03_cd_projeto"].ToString())) + "</td>"); //Evolução
                                sb.Append("</tr>");
                            }
                        }
                    }
                }
                else //administrador parceiro
                {
                    t03.order = " and t01_cd_entidade in (select t01_cd_entidade from t03_projeto where " + tipologia + " fl_ativa=1 and t01_cd_entidade=" + pb.cd_entidade() + " ) order by nm_entidade";
                    foreach (DataRow dre in t03.ListEntidade().Tables[0].Rows)
                    {
                        sb.Append("<tr class=\"hr_white\">");
                        sb.Append("<td colspan='" + colspan + "'>" + dre["nm_entidade"] + "</td>");
                        sb.Append("</tr>");

                        t03.order = tipologia;
                        t03.t01_cd_entidade = Int32.Parse(dre["t01_cd_entidade"].ToString());
                        foreach (DataRow drt in t03.ListTipologia().Tables[0].Rows)
                        {
                            sb.Append("<tr  class=\"hr_yellow\">");
                            sb.Append("<td colspan='" + colspan + "'>" + drt["nm_tipologia"] + "</td>");
                            sb.Append("</tr>");

                            sb.Append("<tr class=\"hr_orange\">");
                            if (!pb.fl_semperfil((int)dre["t01_cd_entidade"]))
                            {
                                sb.Append("<td>Eixos</td>");
                            }
                            else { sb.Append("<td colspan=2>Eixos</td>"); }

                           // sb.Append("<td>Fase</td>");
                            sb.Append("<td>Atualizado</td>");
                            //if (!pb.fl_semperfil((int)dre["t01_cd_entidade"])) { sb.Append("<td>Restri&ccedil;&atilde;o</td>"); }
                            //sb.Append("<td style='width:120px'>Evolu&ccedil;&atilde;o</td>");
                            sb.Append("</tr>");

                            t03.order = "where fl_ativa=1" +
                                " and t01_cd_entidade=" + dre["t01_cd_entidade"].ToString() +
                                " and t04_cd_tipologia=" + drt["t04_cd_tipologia"].ToString() +
                                " order by nm_projeto";

                            foreach (DataRow drp in t03.List().Tables[0].Rows)
                            {
                                string nm_projeto = drp["nm_projeto"].ToString();
                                string nm_fase = "";
                                string data = "-";

                                if (drp["dt_alterado"] != DBNull.Value)
                                {
                                    data = String.Format("{0:dd/MM/yyyy}", DateTime.Parse(drp["dt_alterado"].ToString()));
                                }

                                t19_fase t19 = new t19_fase();
                                {
                                    t19.t19_cd_fase = Int32.Parse(drp["t03_cd_projeto"].ToString()); //usando o t19_cd_fase para armazenar t03_cd_projeto;
                                    t19.RetrieveFaseProjeto();
                                    if (t19.Found)
                                    {
                                        nm_fase = t19.nm_fase;
                                    }
                                }

                                sb.Append("<tr>");
                                PanelGrid.Controls.Add(pb.GetLiteral(sb.ToString()));

                                if (!pb.fl_semperfil((int)dre["t01_cd_entidade"]))
                                {
                                    PanelGrid.Controls.Add(pb.GetLiteral("<td>"));
                                }
                                else { PanelGrid.Controls.Add(pb.GetLiteral("<td colspan=2>")); }
                                LinkButton link = new LinkButton();
                                {
                                    link.ID = "linkP" + drp["t03_cd_projeto"].ToString();
                                    link.CommandArgument = drp["t03_cd_projeto"].ToString();
                                    link.Text = nm_projeto;
                                    link.Click += new EventHandler(link_Click);
                                }
                                PanelGrid.Controls.Add(link);
                                PanelGrid.Controls.Add(pb.GetLiteral("</td>"));//Programas

                                sb = new StringBuilder();
                               // sb.Append("<td>" + nm_fase + "</td>"); //Fase
                                sb.Append("<td style='text-align:center'>" + data + "</td>"); //Atualizado

                                //if (!pb.fl_semperfil((int)dre["t01_cd_entidade"]))
                                //{
                                   // t07_restricao t07 = new t07_restricao();
                                   // {
                                      //  t07.t03_cd_projeto = Int32.Parse(drp["t03_cd_projeto"].ToString());
                                      //  if (t07.List().Tables[0].Rows.Count == 0)
                                      //  {
                                      //      sb.Append("<td>&nbsp;</td>");
                                     //   }
                                    //    else
                                       // {
                                       //     sb.Append("<td style='text-align:center'><b>R</b></td>");
                                      //  }
                                   // }
                              //  }

                                //sb.Append("<td>" + pb.Status(Int32.Parse(drp["t03_cd_projeto"].ToString())) + "</td>");
                                sb.Append("</tr>");
                            }
                        }
                    }
                }
                //t03.order = " and t01_cd_entidade in " +
                //    "(select t01_cd_entidade from t03_projeto where "+ tipologia +" fl_ativa=1 and t01_cd_entidade not in " +
                //    "(select t01_cd_entidade from t05_parceiro where t05_cd_parceiro=" + pb.cd_parceiro() + ")) " +
                //    "order by nm_entidade";
                ////Response.Write(t03.order + "<br>");
                //foreach (DataRow dre in t03.ListEntidade().Tables[0].Rows)
                //{
                //    sb.Append("<tr class=\"hr_white\">");
                //    sb.Append("<td colspan='" + colspan + "'>" + dre["nm_entidade"] + "</td>");
                //    sb.Append("</tr>");

                //    t03.order = tipologia;
                //    t03.t01_cd_entidade = Int32.Parse(dre["t01_cd_entidade"].ToString());
                //    foreach (DataRow drt in t03.ListTipologia().Tables[0].Rows)
                //    {
                //        sb.Append("<tr  class=\"hr_yellow\">");
                //        sb.Append("<td colspan='" + colspan + "'>" + drt["nm_tipologia"] + "</td>");
                //        sb.Append("</tr>");

                //        sb.Append("<tr class=\"hr_orange\">");
                //        if (!pb.fl_semperfil((int)dre["t01_cd_entidade"]))
                //        {
                //            sb.Append("<td>Projeto</td>");
                //        }
                //        else { sb.Append("<td colspan=2>Projeto</td>"); }
                //        sb.Append("<td>Fase</td>");
                //        sb.Append("<td>Atualizado</td>");
                //        if (!pb.fl_semperfil((int)dre["t01_cd_entidade"])) { sb.Append("<td>Restri&ccedil;&atilde;o</td>"); }
                //        sb.Append("<td style='width:120px'>Evolu&ccedil;&atilde;o</td>");
                //        sb.Append("</tr>");

                //        t03.order = "where fl_ativa=1" +
                //            " and t01_cd_entidade=" + dre["t01_cd_entidade"].ToString() +
                //            " and t04_cd_tipologia=" + drt["t04_cd_tipologia"].ToString() +
                //            " order by nm_projeto";

                //        foreach (DataRow drp in t03.List().Tables[0].Rows)
                //        {
                //            string nm_projeto = drp["nm_projeto"].ToString();
                //            string nm_fase = "";
                //            string data = "-";

                //            if (drp["dt_alterado"] != DBNull.Value)
                //            {
                //                data = String.Format("{0:dd/MM/yyyy}", DateTime.Parse(drp["dt_alterado"].ToString()));
                //            }

                //            t19_fase t19 = new t19_fase();
                //            {
                //                t19.t19_cd_fase = Int32.Parse(drp["t03_cd_projeto"].ToString()); //usando o t19_cd_fase para armazenar t03_cd_projeto;
                //                t19.RetrieveFaseProjeto();
                //                if (t19.Found)
                //                {
                //                    nm_fase = t19.nm_fase;
                //                }
                //            }

                //            sb.Append("<tr>");
                //            PanelGrid.Controls.Add(pb.GetLiteral(sb.ToString()));

                //            if (!pb.fl_semperfil((int)dre["t01_cd_entidade"]))
                //            {
                //                PanelGrid.Controls.Add(pb.GetLiteral("<td>"));
                //            }
                //            else { PanelGrid.Controls.Add(pb.GetLiteral("<td colspan=2>")); }
                //            LinkButton link = new LinkButton();
                //            {
                //                link.ID = "linkP3" + drp["t03_cd_projeto"].ToString();
                //                link.CommandArgument = drp["t03_cd_projeto"].ToString();
                //                link.Text = nm_projeto;
                //                link.Click += new EventHandler(link_Click);
                //            }
                //            PanelGrid.Controls.Add(link);
                //            PanelGrid.Controls.Add(pb.GetLiteral("</td>"));//Projeto

                //            sb = new StringBuilder();
                //            sb.Append("<td>" + nm_fase + "</td>"); //Fase
                //            sb.Append("<td style='text-align:center'>" + data + "</td>"); //Atualizado
                //            if (!pb.fl_semperfil((int)dre["t01_cd_entidade"]))
                //            {
                //                t07_restricao t07 = new t07_restricao();
                //                {
                //                    t07.t03_cd_projeto = Int32.Parse(drp["t03_cd_projeto"].ToString());
                //                    if (t07.List().Tables[0].Rows.Count == 0)
                //                    {
                //                        sb.Append("<td>&nbsp;</td>"); //Restrição
                //                    }
                //                    else
                //                    {
                //                        sb.Append("<td style='text-align:center'><b>R</b></td>"); //Restrição
                //                    }
                //                }
                //            }

                //            sb.Append("<td>" + pb.Status(Int32.Parse(drp["t03_cd_projeto"].ToString())) + "</td>"); //Evolução
                //            sb.Append("</tr>");
                //        }
                //    }
                //}
            }

            sb.Append("</table>");
        }
        PanelGrid.Controls.Add(pb.GetLiteral(sb.ToString()));
    }
    private void GridBind(string order)
    {
        string colspan = "7";
        PanelGrid.Controls.Clear();
        StringBuilder sb = new StringBuilder();
        sb.Append("<table  cellspacing=\"2\" cellpadding=\"4\" class=\"tblist\">");

        t03_projeto t03 = new t03_projeto();
        {
            t03.t01_cd_entidade = cd_entidade; //somente a entidade do parceiro
            foreach (DataRow dre in t03.ListEntidadeAdm().Tables[0].Rows)
            {
                sb.Append("<tr class=\"hr_white\">");
                sb.Append("<td colspan='" + colspan + "'>" + dre["nm_entidade"] + "</td>");
                sb.Append("</tr>");

                t03.t01_cd_entidade = Int32.Parse(dre["t01_cd_entidade"].ToString());
                foreach (DataRow drt in t03.ListTipologia().Tables[0].Rows)
                {
                    sb.Append("<tr  class=\"hr_yellow\">");
                    sb.Append("<td colspan='" + colspan + "'>" + drt["nm_tipologia"] + "</td>");
                    sb.Append("</tr>");

                    sb.Append("<tr class=\"hr_orange\">");
                    sb.Append("<td style='width:1%'>&nbsp</td>");
                    sb.Append("<td style='width:1%'>&nbsp</td>");
                    sb.Append("<td>Programas</td>");
                    sb.Append("<td>Fase</td>");
                    sb.Append("<td>Atualizado</td>");
                    sb.Append("<td>Restri&ccedil;&atilde;o</td>");
                    sb.Append("<td style='width:120px'>Evolu&ccedil;&atilde;o</td>");
                    sb.Append("</tr>");

                    t03.order = "where fl_ativa=1"+
                        " and t01_cd_entidade=" + dre["t01_cd_entidade"].ToString() +
                        " and t04_cd_tipologia=" + drt["t04_cd_tipologia"].ToString() +
                        " order by nm_projeto";

                    foreach (DataRow drp in t03.List().Tables[0].Rows)
                    {
                        string nm_projeto = drp["nm_projeto"].ToString();
                        string nm_fase = "";
                        string data = "-";
                        t19_fase t19 = new t19_fase();
                        {
                            t19.t19_cd_fase = Int32.Parse(drp["t03_cd_projeto"].ToString()); //usando o t19_cd_fase para armazenar t03_cd_projeto;
                            t19.RetrieveFaseProjeto();
                            if (t19.Found)
                            {
                                nm_fase = t19.nm_fase;
                            }
                        }

                        sb.Append("<tr>");
                        PanelGrid.Controls.Add(pb.GetLiteral(sb.ToString()));

                        PanelGrid.Controls.Add(pb.GetLiteral("<td>"));
                        ImageButton btne = new ImageButton();
                        btne.ID = "ImageButton1_" + drp["t03_cd_projeto"].ToString();
                        btne.CommandArgument = drp["t03_cd_projeto"].ToString();
                        btne.ImageUrl = "~/images/ico_exc.gif";
                        btne.ToolTip = "Excluir";
                        btne.OnClientClick = "javascript:return confirm('Tem certeza que deseja excluir?')";
                        btne.Click += new ImageClickEventHandler(Delete_Click);
                        PanelGrid.Controls.Add(btne); //Adiciona o botão de exclusão

                        PanelGrid.Controls.Add(pb.GetLiteral("</td><td>"));

                        btne = new ImageButton();
                        btne.ID = "ImageButton2_" + drp["t03_cd_projeto"].ToString();
                        btne.CommandArgument = drp["t03_cd_projeto"].ToString();
                        btne.ImageUrl = "~/images/ico_edit.gif";
                        btne.ToolTip = "Editar";
                        btne.Click += new ImageClickEventHandler(Edit_Click);
                        PanelGrid.Controls.Add(btne); //Adiciona o botão de edição

                        PanelGrid.Controls.Add(pb.GetLiteral("</td>"));

                        PanelGrid.Controls.Add(pb.GetLiteral("<td>"));
                        LinkButton link = new LinkButton();
                        {
                            link.ID = "link" + drp["t03_cd_projeto"].ToString();
                            link.CommandArgument = drp["t03_cd_projeto"].ToString();
                            link.Text = nm_projeto;
                            link.Click +=new EventHandler(link_Click);
                        }
                        PanelGrid.Controls.Add(link);
                        PanelGrid.Controls.Add(pb.GetLiteral("</td>"));//Projeto

                        sb = new StringBuilder();
                        sb.Append("<td>" + nm_fase + "</td>"); //Fase
                        sb.Append("<td>" + data + "</td>"); //Atualizado
                        sb = new StringBuilder();
                        sb.Append("<td>" + nm_fase + "</td>"); //Fase
                        sb.Append("<td style='text-align:center'>" + data + "</td>"); //Atualizado
                        t07_restricao t07 = new t07_restricao();
                        {
                            t07.t03_cd_projeto = Int32.Parse(drp["t03_cd_projeto"].ToString());
                            if (t07.List().Tables[0].Rows.Count == 0)
                            {
                                sb.Append("<td>&nbsp;</td>"); //Restrição
                            }
                            else
                            {
                                sb.Append("<td style='text-align:center'><b>R</b></td>"); //Restrição
                            }
                        }

                        sb.Append("<td>" + pb.Status(Int32.Parse(drp["t03_cd_projeto"].ToString())) + "</td>"); //Evolução
                        sb.Append("</tr>");
                    }
                }
            }
            sb.Append("</table>");
        }
        PanelGrid.Controls.Add(pb.GetLiteral(sb.ToString()));
    }
    protected void btnAcao_Click(object sender, System.EventArgs e)
    {
        t03_projeto t03 = new t03_projeto();
        bool result=false;
        bool erro=false;
        string msg="";
        {
            t03.nm_projeto = txtnm_projeto.Text;
            t03.t01_cd_entidade = cd_entidade;
            t03.t04_cd_tipologia = Int32.Parse(ddlt04_cd_tipologia.SelectedValue);
            t03.t02_cd_usuario = ddlt02_cd_usuario.SelectedValue;
            t03.t02_cd_usuario_monitoramento = ddlt02_cd_usuario_monitoramento.SelectedValue;
            t03.dt_cadastro = DateTime.Now;
            t03.dt_alterado = DateTime.Now;
            t03.fl_ativa = true;
            if (!(erro))
            {
                if (cod.Value != "0")
                {
                    t03.t03_cd_projeto = Int32.Parse(cod.Value);
                    result = t03.Update();
                    msg = pb.Message("Alteração realizada com sucesso!", "ok");
                    pb.saveLog(cd_usuario, t03.t03_cd_projeto, "", "t03_projeto", "update", t03.t03_cd_projeto.ToString());
                    cod.Value = "0";
                }
                else
                {
                    result = t03.Save();
                    msg = pb.Message("Cadastro realizado com sucesso!", "ok");

                    t19_fase t19 = new t19_fase();
                    {
                        t19.fl_fase = "ES";
                        t19.Retrieve();
                        if (t19.Found)
                        {
                            t03.RetrieveCod();
                            if (t03.Found)
                            {
                                t20_faseprojeto t20 = new t20_faseprojeto();
                                {
                                    t20.t03_cd_projeto = t03.t03_cd_projeto;
                                    t20.t19_cd_fase = t19.t19_cd_fase;
                                    t20.dt_alterado = DateTime.Now;
                                    t20.dt_cadastro = DateTime.Now;
                                    t20.Save();
                                    pb.saveLog(cd_usuario, t03.t03_cd_projeto, "", "t03_projeto", "insert", t03.t03_cd_projeto.ToString());
                                }
                            }
                        }
                    }
                }

                if (result)
                {
                    Ocultar();
                    GridBind("order by nm_projeto");
                }
                else
                {
                    msg = pb.Message(pb.msgerro, "erro");
                }
            }
            lblMsg.Text = msg;
            lblMsg.Visible = true;
        }
    }
 protected void ddlBind()
 {
     if (pb.fl_admin())
     {
         t01_entidade t01 = new t01_entidade();
         {
             t01.fl_ativa = true;
             t01.order = " and t01_cd_entidade in (select t01_cd_entidade from t03_projeto where fl_ativa=1) order by nm_entidade";
             ddlt01_cd_entidade.DataSource = t01.List();
             ddlt01_cd_entidade.DataTextField = "nm_entidade";
             ddlt01_cd_entidade.DataValueField = "t01_cd_entidade";
             ddlt01_cd_entidade.DataBind();
             pb.AddEmptyItem(ddlt01_cd_entidade, "Selecione");
         }
         ddlt03_cd_projeto.Enabled = false;
         trParceiro.Visible = true;
     }
     else
     {
         trParceiro.Visible = false;
     }
     t03_projeto t03 = new t03_projeto();
     {
         if (pb.cd_entidade() != 0)
         {
             //se usuário normal
             if (pb.fl_estrategico() || pb.fl_adminparceiro())
             {
                 t03.order = "where t01_cd_entidade=" + pb.cd_entidade() + " and fl_ativa=1 order by nm_projeto";
             }
             else
             {
                 t03.order = "where t02_cd_usuario='" + pb.cd_usuario() + "' ";
             }
         }
         else
         {
             //se usuário parceiro
             t03.order = "where t02_cd_usuario='" + pb.cd_usuario() + "' ";
         }
         ddlt03_cd_projeto.Items.Clear();
         ddlt03_cd_projeto.DataSource = t03.List();
         ddlt03_cd_projeto.DataTextField = "nm_projeto";
         ddlt03_cd_projeto.DataValueField = "t03_cd_projeto";
         ddlt03_cd_projeto.DataBind();
         pb.AddEmptyItem(ddlt03_cd_projeto, "Todos");
     }
     t04_tipologia t04 = new t04_tipologia();
     {
         t04.fl_ativa = true;
         t04.order = "order by nm_tipologia";
         ddlt04_cd_tipologia.DataSource = t04.List();
         ddlt04_cd_tipologia.DataTextField = "nm_tipologia";
         ddlt04_cd_tipologia.DataValueField = "t04_cd_tipologia";
         ddlt04_cd_tipologia.DataBind();
         pb.AddEmptyItem(ddlt04_cd_tipologia, "Todas");
     }
     t05_parceiro t05 = new t05_parceiro();
     {
       //  t05.fl_entidade = true;
         t05.order = "order by nm_parceiro";
         ddlt05_cd_parceiro.DataSource = t05.List();
         ddlt05_cd_parceiro.DataTextField = "nm_parceiro";
         ddlt05_cd_parceiro.DataValueField = "t05_cd_parceiro";
         ddlt05_cd_parceiro.DataBind();
         pb.AddEmptyItem(ddlt05_cd_parceiro, "Todos");
     }
     t19_fase t19 = new t19_fase();
     {
         t19.order = "order by nm_fase";
         ddlt19_cd_fase.DataSource = t19.List();
         ddlt19_cd_fase.DataTextField = "nm_fase";
         ddlt19_cd_fase.DataValueField = "t19_cd_fase";
         ddlt19_cd_fase.DataBind();
         pb.AddEmptyItem(ddlt19_cd_fase, "Todas");
     }
 }