예제 #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();
         
     }
 }
        private void buttonConfirm_Click(object sender, EventArgs e)
        {
            if (String.IsNullOrEmpty(textBoxPassword.Text))
            {
                SystemSounds.Beep.Play();
                MessageBox.Show("Senha vazia", "Erro");
            }
            else if (textBoxPassword.Text != textBoxPasswordConfirm.Text)
            {
                SystemSounds.Beep.Play();
                MessageBox.Show("Senhas não conferem", "Erro");
            }
            else
            {
                ISession session = NHibernateHelper.OpenSession();
                StudentDAO studentDAO = new StudentDAO(session);
                Student student = studentDAO.Get(this.studentId);
                student.ChangePassword(Int32.Parse(textBoxPassword.Text));
                studentDAO.Update(student);
                session.Close();

                this.updated = true;

                MessageBox.Show("Senha trocada com sucesso", "Trocar senha");

                this.Close();
            }
        }
예제 #3
0
        private void StudentRUDForm_Load(object sender, EventArgs e)
        {
            this.session = NHibernateHelper.OpenSession();
            this.studentDAO = new StudentDAO(this.session);

            this.student = this.studentDAO.GetFirst();
            this.Fill(student);

            //counts number of students
            this.numberOfStudents = this.studentDAO.GetTotal();
        }
        public HttpResponseMessage Get([FromUri] int id)
        {
            ISession session = NHibernateHelper.OpenSession();
            StudentDAO studentDAO = new StudentDAO(session);
            Student student = studentDAO.Get(id);

            if (student == null)
                return ReturnResponse(session, HttpStatusCode.NotFound);
            else
                return ReturnResponse(session, HttpStatusCode.OK, student.Balance);  
        }
예제 #5
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);
                }
            }
        }
예제 #6
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();
                }
            }
        }
        private void buttonOk_Click(object sender, EventArgs e)
        {
            string errorMsg = "";

            if (textBoxPassword.Text != textBoxPasswordConfirm.Text)
                errorMsg = "Senhas não conferem";

            if (!String.IsNullOrEmpty(errorMsg))
            {
                ShowError(errorMsg);
                return;
            }

            try
            {
                Student student = new Student(this.textBoxNome.Text,
                                    this.textBoxSobrenome.Text,
                                    this.dateTimePickerNascimento.Value,
                                    new Email(this.textBoxEmailStudent.Text),
                                    new Email(this.textBoxEmailParent.Text),
                                    Int32.Parse(this.textBoxPassword.Text));

                ISession session = NHibernateHelper.OpenSession();
                StudentDAO studentDAO = new StudentDAO(session);
                studentDAO.Add(student);
                bSaved = true;
                session.Close();
                MessageBox.Show("Cadastro efetuado com sucesso!\n\nMatrícula: " + student.Id, "Cadastro");
                
                this.Close();
            }
            catch (Exception ex)    //at least one field with error
            {
                ShowError(ex.Message);
            }
        }
예제 #8
0
        public virtual string sendBalance(string studentID)
        {
            string incomingMsg;
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://192.168.25.66:56556/api/student/"+studentID);
            request.Method = "GET";
            //request.Method = "POST";
            //request.Accept = "application/xml";
            request.ContentType = "application/json";
            HttpWebResponse response;
            try
            {

                response = (HttpWebResponse)request.GetResponse();
                using (Stream responseStreamer = response.GetResponseStream())
                {
                    StreamReader reader = new StreamReader(responseStreamer, Encoding.UTF8);
                    incomingMsg = reader.ReadToEnd();
                }

                ISession session = NHibernateHelper.OpenSession();
                StudentDAO studentDAO = new StudentDAO(session);
                Student student = studentDAO.Get(Int32.Parse(studentID));
                String student_name = student.Name+" "+student.LastName;
                session.Close();
                return "Saldo do aluno "+student_name+": R$" + incomingMsg;
            }
            catch (WebException e)
            {
                if (e.Status == WebExceptionStatus.ProtocolError && e.Response != null)
                {
                    var resp = (HttpWebResponse)e.Response;
                    if (resp.StatusCode == HttpStatusCode.NotFound)
                        return "Matrícula inexistente.";
                    else
                        return "Erro interno.";
                }
                return "Erro de comunicação";
            }
        }