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 btnAdd_Click(object sender, EventArgs e)
    {
        bool result;
        string msg;
        t01_entidade t01 = new t01_entidade();
        {
            try
            {
                t01.nm_entidade = txtnm_entidade.Text;
                t01.nm_uf = ddlnm_uf.SelectedValue;
                t01.nm_arquivo = "";
                t01.nm_cnpj = "";
                t01.fl_ativa = true;
                t01.dt_cadastro = DateTime.Now;
                t01.dt_alterado = DateTime.Now;
                result = t01.Save();
                msg = pb.Message("Inclusão realizada com sucesso", "ok");
                pb.saveLog(cd_usuario, 0, "", "t01_entidade", "insert", t01.nm_entidade);
                txtnm_entidade.Text = "";

                if (result)
                {
                    t01.RetrieveCod();
                    if (t01.Found)
                    {
                        t05_parceiro t05 = new t05_parceiro();
                        {
                            t05.nm_parceiro = t01.nm_entidade;
                            t05.t01_cd_entidade = t01.t01_cd_entidade;
                            t05.fl_entidade = true;
                            t05.nm_arquivo = "";
                            t05.nm_cnpj = "";
                            t05.dt_cadastro = DateTime.Now;
                            t05.dt_alterado = DateTime.Now;
                            t05.Save();
                            pb.saveLog(cd_usuario, 0, "", "t05_parceiro", "insert", t05.nm_parceiro);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                msg = pb.Message(pb.msgerro + " <small>Descrição: "+ ex.Message + "</small>", "erro");
            }

            lblMsg.Text = msg;
            lblMsg.Visible = true;
            GridBind("order by nm_entidade");
        }
    }
    protected void Delete_Click(object sender, System.Web.UI.ImageClickEventArgs e)
    {
        ImageButton btn = (ImageButton)sender;
        bool result;
        string msg;
        t01_entidade t01 = new t01_entidade();
        {
            try
            {
                t01.t01_cd_entidade = Int32.Parse(btn.CommandArgument);
                result = t01.Delete();
                pb.saveLog(cd_usuario, 0, "", "t01_entidade", "delete", t01.t01_cd_entidade.ToString());
                msg = pb.Message("Exclusão realizada com sucesso", "ok");
            }
            catch
            {
                msg = pb.Message(pb.msgerro, "erro");
            }

            lblMsg.Text = msg;
            lblMsg.Visible = true;
            GridBind("order by nm_entidade");
        }
    }
    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 FormBind()
 {
     DropDownList ddl = this.ddlt01_cd_entidade;
     t01_entidade t01 = new t01_entidade();
     {
         t01.order = "order by nm_entidade";
         t01.fl_ativa = true;
         ddl.DataSource = t01.List();
         ddl.DataTextField = "nm_entidade";
         ddl.DataValueField = "t01_cd_entidade";
         ddl.DataBind();
         pb.AddEmptyItem(ddl, "Selecione");
     }
     ddl = ddlt05_cd_parceiro;
     t05_parceiro t05 = new t05_parceiro();
     {
         t05.order = "order by nm_parceiro";
         t05.t01_cd_entidade = pb.cd_entidade();
         ddl.DataSource = t05.List();
         ddl.DataTextField = "nm_parceiro";
         ddl.DataValueField = "t05_cd_parceiro";
         ddl.DataBind();
         pb.AddEmptyItem(ddl, "Selecione");
     }
     CheckBoxList cbl = cblt25_cd_perfil;
     t25_perfil t25 = new t25_perfil();
     {
         cbl.DataSource = t25.List();
         cbl.DataTextField = "nm_perfil";
         cbl.DataValueField = "t25_cd_perfil";
         cbl.DataBind();
     }
 }
    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");
            }
        }
    }
 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");
     }
 }
 private void GridBind(String order)
 {
     t01_entidade t01 = new t01_entidade();
     {
         t01.order = order;
         t01.fl_ativa = true;
         GridView1.DataSource = t01.List();
         GridView1.DataBind();
         ddlBind(ddlnm_uf);
     }
 }
    protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        GridViewRow row = GridView1.Rows[e.RowIndex];
        int cod = Int32.Parse(GridView1.DataKeys[e.RowIndex].Value.ToString());
        TextBox txt1 = (TextBox)row.FindControl("txtnm_entidade");
        DropDownList ddl = (DropDownList)row.FindControl("ddlnm_uf");
        bool result;
        string msg;
        t01_entidade t01 = new t01_entidade();
        {
            try
            {
                t01.t01_cd_entidade = cod;
                t01.nm_entidade = txt1.Text;
                t01.nm_arquivo = "";
                t01.nm_cnpj = "";
                t01.nm_uf = ddl.SelectedValue;
                t01.dt_alterado = DateTime.Now;
                pb.saveLog(cd_usuario, 0, "", "t01_entidade", "update" , t01.t01_cd_entidade.ToString());
                result = t01.Update();
                msg = pb.Message("Alteração realizada com sucesso", "ok");
            }
            catch
            {
                msg = pb.Message(pb.msgerro, "erro");
            }

            lblMsg.Text = msg;
            lblMsg.Visible = true;

            GridView1.EditIndex = -1;
            GridBind("order by nm_entidade");
        }
    }
 private void FormBind()
 {
     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)";
         DropDownList ddl = ddlt01_cd_entidade;
         ddl.DataSource = t01.List();
         ddl.DataTextField = "nm_entidade";
         ddl.DataValueField = "t01_cd_entidade";
         ddl.DataBind();
         pb.AddEmptyItem(ddl, "Selecione");
     }
 }