protected void btnSalvar_Click(object sender, EventArgs e)
        {
            if (txtDescricao.Value != "")
            {
                tipo_registro tr = new tipo_registro();
                tr.descricao = txtDescricao.Value;

                TipoRegistro_Model model = new TipoRegistro_Model();

                // se tiver ID preenche o parâmetro
                if (txtID.Text != "Novo")
                    tr.id = int.Parse(txtID.Text);

                // faz a inserção ou atualização do cadastro da cidade
                if (model.InserirAtualizar(tr))
                {
                    Master.Sucesso("Registro salvo com sucesso.");
                    txtID.Text = tr.id.ToString();
                }
                else
                    Master.Alerta("Erro ao salvar o registro");
            }
            else
            {
                Master.Alerta("Campo descrição é obrigatório.");
            }
        }
        protected void btnBuscar_Click(object sender, EventArgs e)
        {
            TipoRegistro_Model model = new TipoRegistro_Model();

            gdvLista.DataSource = model.ListarPorDescricao(txtDescricao.Text);
            gdvLista.DataBind();
        }
        protected void PreencherGrid()
        {
            TipoRegistro_Model model = new TipoRegistro_Model();

            gdvLista.DataSource = model.Totalizar(txtDataIni.Value, txtDataFim.Value, Int32.Parse(ddLocal.SelectedValue), cbTodos.Checked);

            gdvLista.DataBind();

            if (gdvLista.Rows.Count > 0)
            {
                gdvLista.UseAccessibleHeader = true;
                gdvLista.HeaderRow.TableSection = TableRowSection.TableHeader;
            }
        }
        protected void PreencherGrid()
        {
            TipoRegistro_Model model = new TipoRegistro_Model();

            // asp:repeater
            gdvLista.DataSource = model.Listar();
            gdvLista.DataBind();

            if (gdvLista.Rows.Count > 0)
            {
                gdvLista.UseAccessibleHeader = true;
                gdvLista.HeaderRow.TableSection = TableRowSection.TableHeader;
            }
        }
        // ======================================================== PAGE LOAD =====================================================
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                TipoRegistro_Model model = new TipoRegistro_Model();
                ddTipoRegistro.DataSource = model.Listar();
                ddTipoRegistro.DataValueField = "id";
                ddTipoRegistro.DataTextField = "descricao";
                ddTipoRegistro.DataBind();
                ddTipoRegistro.SelectedIndex = 0;

                txtTemaConflito.MaxLength = 50;

                txtData.Value = DateTime.Parse(DateTime.Now.ToString()).ToString("yyyy-MM-dd");
                txtHora.Value = DateTime.Now.Hour.ToString() + ":" + DateTime.Now.Minute.ToString();
            }
            else
            {

            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Master.GetNivelPermissao() < Mediador_Model.PERM_ADMIN)
            {
                Response.Redirect("index.aspx");
            }

            if (!IsPostBack)
            {
                // MAXIMO DE CARACTERES
                txtDescricao.MaxLength = 50;

                // declara ID e verifica se existe ID no txtID ou no endereço
                int id = 0;

                if (txtID.Text != "Novo")
                {
                    // recupera o id
                    try
                    {
                        id = int.Parse(txtID.Text);
                    }
                    catch (Exception)
                    {
                        Master.Alerta("Erro ao carregar o cadastro.");
                    }
                }

                if (Request.QueryString["ID"] != null)
                {
                    //recupera o id
                    id = int.Parse(Request.QueryString["ID"]);
                    txtID.Text = id.ToString();
                }

                // se houver ID informado, então carrega o registro do ID informado
                if (id != 0)
                {
                    try
                    {
                        // declara o objeto model
                        TipoRegistro_Model model = new TipoRegistro_Model();
                        //recupera o produto do id informado
                        tipo_registro tr = model.Obter(id);

                        //preencher caixas de texto com valores
                        txtDescricao.Value = tr.descricao;
                    }
                    catch (Exception)
                    {
                        Master.Alerta("Registro não encontrado.");
                    }
                }
                else
                {
                    txtID.Text = "Novo";
                }
            }
        }