protected void GridView1_RowDataBound(Object sender, GridViewRowEventArgs e)
 {
     GridView gv = (GridView)sender;
      if (e.Row.RowType == DataControlRowType.DataRow)
      {
          DataRowView drv = ((DataRowView)e.Row.DataItem);
          t01_entidade t01 = new t01_entidade();
          {
              t01.t01_cd_entidade = (int)drv["t01_cd_entidade"];
              t01.Retrieve();
              if (!t01.Found)
              {
                  t05_parceiro t05 = new t05_parceiro();
                  {
                      t05.t05_cd_parceiro = (int)drv["t05_cd_parceiro"];
                      t05.Retrieve();
                      if (t05.Found)
                      {
                          t01.t01_cd_entidade = t05.t01_cd_entidade;
                          t01.Retrieve();
                          if (t01.Found)
                          {
                              e.Row.Cells[2].Controls.Add(pb.GetLiteral(t01.nm_entidade + "\\" + t05.nm_parceiro));
                          }
                      }
                  }
              }
          }
      }
 }
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        GridView gv = (GridView)sender;
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            DataRowView drv = ((DataRowView)e.Row.DataItem);
            t26_usuarioperfil t26 = new t26_usuarioperfil();
            {
                t26.t02_cd_usuario = drv["t02_cd_usuario"].ToString();
                foreach (DataRow dr in t26.List().Tables[0].Rows)
                {
                    e.Row.Cells[9].Controls.Add(pb.GetLiteral("- " + dr["nm_perfil"].ToString() + "<br />"));
                }
            }
            t01_entidade t01 = new t01_entidade();
            {
                t01.t01_cd_entidade = (int)drv["t01_cd_entidade"];
                t01.Retrieve();
                if (!t01.Found)
                {
                    t05_parceiro t05 = new t05_parceiro();
                    {
                        t05.t05_cd_parceiro = (int)drv["t05_cd_parceiro"];
                        t05.Retrieve();
                        if (t05.Found)
                        {
                            t01.t01_cd_entidade = t05.t01_cd_entidade;
                            t01.Retrieve();
                            if (t01.Found)
                            {
                                if (pb.fl_admin())
                                {
                                    e.Row.Cells[8].Controls.Add(pb.GetLiteral(t01.nm_entidade + "\\" + t05.nm_parceiro));
                                }
                                else
                                {
                                    e.Row.Cells[8].Controls.Add(pb.GetLiteral(t05.nm_parceiro));
                                }
                            }
                        }
                    }
                }
            }

            if ((Int64)drv["nu_telefone"] == 0)
                e.Row.Cells[5].Text = "-";

            if ((Int64)drv["nu_celular"] == 0)
                e.Row.Cells[6].Text = "-";
        }
    }
    protected void btnFiltro_Click(object sender, EventArgs e)
    {
        System.Text.StringBuilder query = new System.Text.StringBuilder();
        string cd_entidade = "0";
        if (pb.fl_admin())
        {
            trParceiro.Visible = true;
            if (ddlt01_cd_entidade.SelectedValue != "")
            {
                cd_entidade = ddlt01_cd_entidade.SelectedValue;
            }
        }
        else
        {
            cd_entidade = pb.cd_entidade().ToString();
            trParceiro.Visible = false;
        }
        if (cd_entidade != "0")
        {
            query.Append("and (t01_cd_entidade=" + cd_entidade + ") ");
        }
        else
        {   //usuário parceiro
            query.Append("and (t01_cd_entidade in (select t01_cd_entidade from t05_parceiro where t05_cd_parceiro=" + pb.cd_parceiro() + ")) ");
        }

        if (ddlt03_cd_projeto.SelectedValue != "")
        {
            query.Append("and (t03_cd_projeto=" + ddlt03_cd_projeto.SelectedValue + ") ");
        }
        else
        {
            if (!(pb.fl_estrategico() || pb.fl_adminparceiro() || pb.fl_admin()))
             query.Append(" and (t03_cd_projeto in (select t03_cd_projeto from t03_projeto where t02_cd_usuario='" + pb.cd_usuario() + "')) ");
        }

        if (ddlt04_cd_tipologia.SelectedValue != "")
        {
            query.Append("and (t04_cd_tipologia=" + ddlt04_cd_tipologia.SelectedValue + ") ");
        }
        if (ddlt05_cd_parceiro.SelectedValue != "")
        {
            query.Append("and (t05_cd_parceiro=" + ddlt05_cd_parceiro.SelectedValue + ") ");
          // query.Append("and (t03_cd_projeto in (select t03_cd_projeto from t20_faseprojeto where t05_cd_parceiro=" + ddlt05_cd_parceiro.SelectedValue + "')) ");
        }
        if (ddlt19_cd_fase.SelectedValue != "")
        {
            query.Append("and (t03_cd_projeto in (select t03_cd_projeto from t20_faseprojeto where t19_cd_fase=" + ddlt19_cd_fase.SelectedValue + " and fl_ativa=1)) ");
        }
        //Response.Write(query.ToString());
        t03_projeto t03 = new t03_projeto();
        {
            t03.order = "select * from t03_projeto where (fl_ativa=1) " + query.ToString();
            int i = t03.ListQuery().Tables[0].Rows.Count;

            if (i > 0)
            {
                Session["sqlfiltro"] = query.ToString();

                //Detalhes do Filtro
                t03.order = "select max(dt_fim) as datafim, min(dt_inicio) as dataini from t03_projeto where (fl_ativa=1) and (dt_alterado is not null) " + query.ToString();
                foreach (DataRow drp in t03.ListQuery().Tables[0].Rows)
                {
                    if (drp["dataini"] != DBNull.Value)
                    {
                        DateTime dti = (DateTime)drp["dataini"];
                        DateTime dtf = (DateTime)drp["datafim"];
                        Session["mondti"] = dti.ToShortDateString();
                        Session["mondtf"] = dtf.ToShortDateString();
                    }
                }
                t01_entidade t01 = new t01_entidade();
                {
                    if (cd_entidade == "0")
                    {
                        t05_parceiro t05 = new t05_parceiro();
                        {
                            t05.t05_cd_parceiro = pb.cd_parceiro();
                            t05.Retrieve();
                            if (t05.Found)
                            {
                                cd_entidade = t05.t01_cd_entidade.ToString();
                            }
                        }
                    }
                    t01.t01_cd_entidade = Int32.Parse(cd_entidade);
                    t01.Retrieve();
                    if (t01.Found)
                    {
                        Session["monparceiro"] = t01.nm_entidade;
                    }
                }
                Session["monquantproj"] = i.ToString();
                Session["monprojeto"] = ddlt03_cd_projeto.SelectedItem.Text;
                Session["montipologia"] = ddlt04_cd_tipologia.SelectedItem.Text;
                Session["monresponsavel"] = ddlt05_cd_parceiro.SelectedItem.Text;
                Session["monfase"] = ddlt19_cd_fase.SelectedItem.Text;
                Response.Redirect("MonPainel2.aspx");
            }
            else
            {
                lblMsg.Visible = true;
                lblMsg.Text = pb.Message("A seleção efetuada não possui informações. Tente novamente.", "erro");
            }
        }
    }