protected void btnAcao_Click(object sender, EventArgs e)
    {
        bool result = false;
        bool erro = false;
        string msg = "";
        t14_resultado t14 = new t14_resultado();
        {
            t14.t03_cd_projeto = pb.cd_projeto();
            t14.ds_resultado = txtds_resultado.Text;
            t14.nm_medida = txtnm_medida.Text;
            t14.nm_resultado = txtnm_resultado.Text;
            t14.nm_unid = txtnm_unid.Text;

            if (txtnu_ano.Text != "")
            {
                if (txtnu_ano.Text.Length == 4)
                {
                    t14.nu_ano = Int32.Parse(txtnu_ano.Text);
                }
                else
                {
                    erro = true;
                    msg = pb.Message("Ano inválido", "erro");
                }
            }
            else{t14.nu_ano = 0;}
            if (txtvl_t0.Text != ""){t14.vl_t0 = decimal.Parse(txtvl_t0.Text);}
            else{t14.vl_t0 = 0;}

            t14.fl_acumulado = bool.Parse(rblfl_acumulado.SelectedValue.ToString());
            t14.dt_cadastro = DateTime.Now;
            t14.dt_alterado = DateTime.Now;
            t15_vlresultado t15 = new t15_vlresultado();
            t03_projeto t03 = new t03_projeto();
            t03.t03_cd_projeto = pb.cd_projeto();
            t03.Retrieve();
            if (!(erro))
            {
                if (cod.Value != "0")
                {
                    t14.t14_cd_resultado = Int32.Parse(dlResultado.SelectedValue.ToString());
                    result = t14.Update();
                    msg = pb.Message("Alteração realizada com sucesso!", "ok");
                    if (result)
                    {
                        //Altera os Valores
                        if (t03.Found)
                        {
                            t15.t14_cd_resultado = Int32.Parse(cod.Value.ToString());
                            t15.Delete();

                            for (int i = t03.dt_inicio.Year; i <= t03.dt_fim.Year; i++)
                            {
                                TextBox txtPrev = (TextBox)ucAnos.FindControl("txtPrev" + i.ToString());
                                TextBox txtReal = (TextBox)ucAnos.FindControl("txtReal" + i.ToString());
                                if (txtPrev != null)
                                {
                                    if (txtPrev.Text == "") txtPrev.Text = "0";
                                    if (txtReal.Text == "") txtReal.Text = "0";

                                    t15.t14_cd_resultado = Int32.Parse(cod.Value.ToString());
                                    t15.nu_ano = i;
                                    t15.vl_previsto = decimal.Parse(txtPrev.Text);
                                    t15.vl_realizado = decimal.Parse(txtReal.Text);
                                    t15.dt_alterado = DateTime.Now;
                                    t15.dt_cadastro = DateTime.Now;
                                    t15.Save();

                                }
                            }
                        }

                        cod.Value = "0";
                        pb.saveLog(pb.cd_usuario(), pb.cd_projeto(), "", "t14_resultado", "update", t14.t14_cd_resultado.ToString());
                    }
                }
                else
                {
                    result = t14.Save();
                    msg = pb.Message("Cadastro realizado com sucesso!", "ok");
                    if (result)
                    {
                        if (t03.Found)
                        {
                            t14.RetrieveCod();
                            if (t14.Found)
                            {
                                for (int i = t03.dt_inicio.Year; i <= t03.dt_fim.Year; i++)
                                {
                                    TextBox txtPrev = (TextBox)ucAnos.FindControl("txtPrev" + i.ToString());
                                    TextBox txtReal = (TextBox)ucAnos.FindControl("txtReal" + i.ToString());
                                    if (txtPrev != null)
                                    {
                                        if (txtPrev.Text == "") txtPrev.Text = "0";
                                        if (txtReal.Text == "") txtReal.Text = "0";
                                        t15.t14_cd_resultado = t14.t14_cd_resultado;
                                        t15.nu_ano = i;
                                        t15.vl_previsto = decimal.Parse(txtPrev.Text);
                                        t15.vl_realizado = decimal.Parse(txtReal.Text);
                                        t15.dt_alterado = DateTime.Now;
                                        t15.dt_cadastro = DateTime.Now;
                                        t15.Save();

                                    }
                                }
                            }
                        }
                        pb.saveLog(pb.cd_usuario(), pb.cd_projeto(), "", "t14_resultado", "update", t14.nm_resultado);
                    }

                }
                if (result)
                {
                    Ocultar();
                    GridBind("");
                }
                else
                {
                    msg = pb.Message(pb.msgerro, "erro");
                }
            }
            lblMsg.Text = msg;
            lblMsg.Visible = true;
        }
    }
 private void GridBind(string order)
 {
     t14_resultado t14 = new t14_resultado();
     {
         t14.t03_cd_projeto = pb.cd_projeto();
         dlResultado.DataSource = t14.List();
         dlResultado.DataBind();
         if (pb.fl_gerente())
         {
             if ((dlResultado.Items.Count == 0) && (pb.fl_gerente()))
             {
                 lblHeader.Text = "Cadastro";
                 btnAcao.Text = "Cadastrar";
                 Exibir();
             }
         }
     }
 }
    private void Retrieve()
    {
        t14_resultado t14 = new t14_resultado();
        {
            t14.t14_cd_resultado = Int32.Parse(cod.Value);
            t14.Retrieve();
            if (t14.Found)
            {
                txtds_resultado.Text = t14.ds_resultado;
                txtnm_medida.Text = t14.nm_medida;
                txtnm_unid.Text = t14.nm_unid;
                txtnm_resultado.Text = t14.nm_resultado;
                txtnu_ano.Text = t14.nu_ano.ToString();
                txtvl_t0.Text = t14.vl_t0.ToString("N");
                ListItem li = rblfl_acumulado.Items.FindByValue(t14.fl_acumulado.ToString());
                if (li != null) li.Selected = true;

                t03_projeto t03 = new t03_projeto();
                {
                    t03.t03_cd_projeto = pb.cd_projeto();
                    t03.Retrieve();
                    if (t03.Found)
                    {
                        for (int i = t03.dt_inicio.Year; i <= t03.dt_fim.Year; i++)
                        {
                            t15_vlresultado t15 = new t15_vlresultado();
                            {
                                t15.t14_cd_resultado = t14.t14_cd_resultado;
                                t15.nu_ano = i;
                                t15.Retrieve();
                                TextBox txtPrev = (TextBox)ucAnos.FindControl("txtPrev" + i.ToString());
                                TextBox txtReal = (TextBox)ucAnos.FindControl("txtReal" + i.ToString());
                                if (t15.Found)
                                {
                                    if (txtPrev != null) txtPrev.Text = t15.vl_previsto.ToString("N");
                                    if (txtReal != null) txtReal.Text = t15.vl_realizado.ToString("N");
                                }
                                else
                                {
                                    if (txtPrev != null) txtPrev.Text = "0";
                                    if (txtReal != null) txtReal.Text = "0";
                                }
                            }
                        }
                    }
                }
            }
        }
    }
 protected void btnExc_Click(object sender, ImageClickEventArgs e)
 {
     ImageButton btn = (ImageButton)sender;
     t14_resultado t14 = new t14_resultado();
     {
         t14.t14_cd_resultado = Int32.Parse(btn.CommandArgument);
         t14.Delete();
         pb.saveLog(pb.cd_usuario(), pb.cd_projeto(), "", "t14_resultado", "delete", btn.CommandArgument);
         GridBind("");
         lblMsg.Text = pb.Message("Exclusão realizada com sucesso!", "ok"); ;
         lblMsg.Visible = true;
     }
 }