Exemple #1
0
        protected void Button1_Click(object sender, EventArgs e)
        {
            DAL.DALTransacaoPacote aDALTPacote;
            Modelo.TransacaoPacote aTP;
            DAL.DALClientes        aDALClientes  = new DAL.DALClientes();
            DAL.DALPacote          aDALPacote    = new DAL.DALPacote();
            DAL.DALHistorico       aDALHistorico = new DAL.DALHistorico();
            Modelo.Historico       aH;
            int i, u;

            i = Convert.ToInt32(Session["idpacote"]);
            u = Convert.ToInt32(Session["idlogin"]);
            string error = " ";

            aDALTPacote = new DAL.DALTransacaoPacote();

            if (aDALTPacote.VerificarT(i, u))
            {
                aDALTPacote.Delete(i, u);
                Response.Redirect("~\\WebFormPacotesC.aspx");
            }
            else
            {
                double preco = aDALPacote.Select(i).ElementAt(0).Preco;
                aTP = new Modelo.TransacaoPacote(0, i, u);
                if (aDALPacote.Select(i).ElementAt(0).Preco < aDALClientes.Select1(u).ElementAt(0).Saldo)
                {
                    aDALTPacote.Insert(aTP);
                    aDALClientes.UpdateComprar(aDALPacote.Select(i).ElementAt(0).Preco, aDALClientes.Select1(u).ElementAt(0).Saldo, u);

                    aH = new Modelo.Historico(0, DateTime.Now, aDALPacote.Select(i).ElementAt(0).Preco, aDALClientes.Select1(u).ElementAt(0).Saldo, u, i);
                    aDALHistorico.InsertPacote(aH);


                    Response.Redirect("~\\WebFormPacotesListar.aspx");
                }
                else
                {
                    error = "Saldo insuficiente para realizar a transação";
                    Error(error);
                }
            }
        }