예제 #1
0
 private void button1_Click(object sender, EventArgs e)
 {
     Boolean bFlag = false;
     if (matAluno.Text != "")
     {
         this.Hide();
         
         ISession session = NHibernateHelper.OpenSession();
         StudentDAO studentDAO = new StudentDAO(session);
         Student student = studentDAO.Get(Int32.Parse(matAluno.Text));
         if (student == null)
             MessageBox.Show("Aluno inexistente");
         else
         {
             CardDAO cardDAO = new CardDAO(session);
             foreach (Card c in student.Cards)
                 if (!c.Blocked)
                 {
                     bFlag = true;
                     c.Blocked = true;
                     cardDAO.Update(c);
                 }
             MessageBox.Show((bFlag? "Cartão bloqueado com sucesso.":"Não há cartões ativos para esse aluno."), "Bloquear cartão");
         }
         session.Close();
         
     }
 }
예제 #2
0
        public HttpResponseMessage Post([FromBody] Sale sale)
        {
            if (sale == null)
                Request.CreateResponse(HttpStatusCode.NoContent);

            ISession session = NHibernateHelper.OpenSession();
            SaleDAO saleDAO = new SaleDAO(session);
            CardDAO cardDAO = new CardDAO(session);
            StudentDAO studentDAO = new StudentDAO(session);
            Student student;

            if (sale.IsReload || sale.WasRefunded)
            {
                student = studentDAO.Get(sale.Student.Id);
                if (student == null)
                    return ReturnResponse(session, HttpStatusCode.NotFound);

                saleDAO.Add(sale);
                student.Balance += sale.Value;
                studentDAO.Update(student);
                return ReturnResponse(session, HttpStatusCode.OK);
            }
            else //sale
            {
                Card card = cardDAO.Get(sale.Card.PAN);
                if (card == null)
                    return ReturnResponse(session, HttpStatusCode.NotFound);

                student = card.Student;

                if (card.Blocked)
                    return ReturnResponse(session, HttpStatusCode.UpgradeRequired);
                else if (!student.CheckPassword(sale.Password))
                    return ReturnResponse(session, HttpStatusCode.Conflict);
                else if (student.Balance < sale.Value)
                    return ReturnResponse(session, HttpStatusCode.Unauthorized);
                else
                {
                    sale.Student = student;
                    student.Sales.Add(sale);
                    saleDAO.Add(sale);
                    student.Balance -= sale.Value;
                    studentDAO.Update(student);

                    EmailSender.sendEmail(sale);

                    return ReturnResponse(session, HttpStatusCode.OK);
                }
            }
        }
예제 #3
0
        private void okMat_Click(object sender, EventArgs e)
        {
            if (matAluno.Text != "")
            {
                FormCard formCard = new FormCard();
                DialogResult showFormCard;

                this.Hide();
                showFormCard = formCard.ShowDialog();

                if (showFormCard == DialogResult.OK)
                {
                    ISession session = NHibernateHelper.OpenSession();
                    StudentDAO studentDAO = new StudentDAO(session);
                    Student student = studentDAO.Get(Int32.Parse(matAluno.Text));
                    if (student == null)
                        MessageBox.Show("Aluno inexistente");
                    else
                    {
                        Card card = formCard.ReturnValueCard;
                        CardDAO cardDAO = new CardDAO(session);

                        if (cardDAO.Get(card.PAN) == null)
                        {
                            foreach (Card c in student.Cards)
                                if (!c.Blocked)
                                {
                                    MessageBox.Show("Já existe um cartão ativo.", "Erro");
                                    return;
                                }

                            student.Cards.Add(card);
                            cardDAO.Add(card);
                            studentDAO.Update(student);
                            MessageBox.Show("Cartão cadastrado com sucesso para "+student.Name+" "+student.LastName+".","Cadastro de cartão");
                        }
                        else
                            MessageBox.Show("Cartão já cadastrado para um aluno.", "Erro" );
                    }
                    session.Close();
                }
            }
        }