예제 #1
0
        private void CustomerOptions_SelectedIndexChanged(object sender, EventArgs e)
        {
            checkBookings check = new checkBookings(); //Open Customer bookings&extras window

            check.ShowDialog();
        }
        private void button1_Click(object sender, EventArgs e)
        {
            button1.BackColor = SystemColors.Control; //format form
            button1.Text      = "Search";
            textBox2.Text     = ""; textBox4.Text = "";
            groupBox2.Enabled = false;


            conn = new SqlConnection(connectionString); //set up connection
            conn.Open();

            if (textBox1.Text != "" && textBox3.Text != "") //only proceed with query if there was input entered
            {
                try
                {
                    id = Int32.Parse(textBox1.Text);    //try to convert entered id string
                }
                catch (Exception ex) { MessageBox.Show(ex.Message); }
                password = textBox3.Text;

                try
                {
                    selectStatement = "SELECT name FROM dbo.Assess_Customers WHERE ID=@ID and password=@pwd";
                    SqlCommand commDB = new SqlCommand(selectStatement, conn);
                    commDB.Parameters.Add(new SqlParameter("ID", id));
                    commDB.Parameters.Add(new SqlParameter("pwd", password));
                    if (Convert.ToString(commDB.ExecuteScalar()) == "") //let the user know if there is no match in the database for the entered login details
                    {
                        MessageBox.Show("Incorrect login data");
                        checkBookings newCheck = new checkBookings();
                        this.Hide();
                        newCheck.ShowDialog();
                        this.Close();
                    }
                    else //successful login
                    {
                        groupBox1.Enabled = true;
                        label10.Text      = "Hi " + Convert.ToString(commDB.ExecuteScalar());

                        label2.Enabled   = true; label3.Enabled = true; label8.Enabled = true; label10.Visible = true;
                        textBox2.Enabled = true; textBox4.Enabled = true; button4.Enabled = true;

                        conn.Close(); conn.Open();
                        string     select  = "select * from dbo.BookingDetails where customerID=@ID";
                        SqlCommand commDB1 = new SqlCommand(select, conn);
                        commDB1.Parameters.Add(new SqlParameter("ID", id));

                        try
                        {
                            gridDisplay(commDB1); //Display customer's booking  details
                            conn.Close();
                        }
                        catch (Exception ex) { MessageBox.Show(ex.Message); }
                    }
                }
                catch (Exception ex) { MessageBox.Show(ex.Message); }
            }
            else
            {
                MessageBox.Show("Incorrect login data");
            }
        } //Login process && retrieve booking data