p-GymReg / CSC330_CSharp_Midterm / RegistrationGuestForm.cs
RegistrationGuestForm.cs
Raw
using System;
using System.Windows.Forms;

namespace CSC330_CSharp_Midterm
{
    public partial class RegistrationGuestForm : Form
    {
        public RegistrationGuestForm()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox1.Text != "" && textBox2.Text != "") // if all fields are filled
            {
                // instantiate an object of the guest class
                Guest guest = new Guest();                
                guest.Name = textBox1.Text;
                guest.DOB = dateTimePicker1.Value.Date;               
                guest.Address = textBox2.Text;
                guest.Day = Convert.ToInt32(numericUpDown1.Value);
                guest.Cost = guest.Day * 0;
               
                string message = Requests.Request("INSERT INTO [Guest] ([Name], [DOB], [Address], [Day], [Cost]) VALUES ('" + guest.Name + "', '" + guest.DOB + "', '" + guest.Address + "', '" + guest.Day + "', '" + guest.Cost + "')"); // pass the method request to the database. If the method returns an empty string, it means that it worked without errors

                if (message == "")
                {
                    MessageBox.Show("Welcome guest, your trial has begun! You have been charged: $" + guest.ShowCost(guest) + ". That's right, FREE!", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    MessageBox.Show("Error during check!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }

                Close(); // close the registration form
            }
            else // if all fields are not filled
            {
                MessageBox.Show("Fill in all the fields!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }

        private void dateTimePicker1_ValueChanged(object sender, EventArgs e)
        {
        }
    }
}