示例#1
0
        //ComboBox dropdown style = dropdown list
        private void loadCustomersToCombo()
        {//loading from customer class to combobox
            try
            {
                // customerObject = new CustomerClass();
                //  customerObject.loadCustomers();
                // customer = new CustomerService.CustomerClass();
                customer = client.loadCustomers();


                comboBox1.Items.Clear();
                for (int i = 0; i < customer.customerCount; i++)
                {
                    customerID = customer.custObject[i].Cid;
                    string customerFullName = customer.custObject[i].Fname + " " + customer.custObject[i].Lname; //display name
                    string cmbDisplay       = customerID + " - " + customerFullName;
                    //comboBox1.Items.Add(customerFullName);
                    comboBox1.Items.Add(cmbDisplay);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Exception error :" + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
示例#2
0
        private void button1_Click_1(object sender, EventArgs e)    //Book Seat
        {
            CustomerService.CustomerServiceClient client   = new AirlineApplication.CustomerService.CustomerServiceClient();
            CustomerService.CustomerClass         customer = null;

            try
            {
                if (newCustomer == true)
                {
                    //validation
                    var controls = new[] { txtFname.Text, txtLname.Text, txtNic.Text, txtAdd1.Text, txtAdd2.Text, txtEmail.Text, txtPhn.Text };
                    if (!controls.All(x => string.IsNullOrEmpty(x))) //if its not null or empty enter the details to database
                    {                                                //Validation^^^^^^^
                        if (dateTimePicker1.Value < DateTime.Today)  //validation for date must be in past
                        {
                            if ((Regex.IsMatch(txtFname.Text, @"^[a-zA-Z]+$")) && (Regex.IsMatch(txtLname.Text, @"^[a-zA-Z]+$")))
                            {
                                // addDetails(); assign all the varialbes from customer class to these controls
                                //  customerObject = new CustomerClass();   //reuse as new object
                                customer       = new CustomerService.CustomerClass();
                                customer.Fname = txtFname.Text;
                                customer.Lname = txtLname.Text;
                                customer.Nic   = txtNic.Text;
                                //gender
                                if (rbMale.Checked)
                                {
                                    customer.Gender = Convert.ToChar(rbMale.Tag); //male
                                }
                                else
                                {
                                    customer.Gender = Convert.ToChar(rbFemale.Tag); //female
                                }
                                customer.Dob   = dateTimePicker1.Value;
                                customer.Add1  = txtAdd1.Text;
                                customer.Add2  = txtAdd2.Text;
                                customer.Phone = txtPhn.Text;
                                customer.Email = txtEmail.Text;

                                //   customerID = customer.addDetails();
                                this.Refresh();

                                BookSeatPlan bookSeat = new BookSeatPlan();
                                //// check this             bookSeat.getCustomerNic(customerID, txtNic.Text, txtFname.Text, txtLname.Text);
                                client.addDetails(customer);
                                newCustomer = false;
                                MessageBox.Show("Data added successfully! \r\nSelect from existing customer before booking", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                MessageBox.Show("Please wait while the booking form loads......", "Loading", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);

                                bookSeat.ShowDialog();
                                this.Close();
                            }
                            else
                            {//check if value is selected from comboBox, if selected - then newCustomer = false and dont allow to add same details to database
                                MessageBox.Show("Make sure first name and last name contain only letters", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                            }
                        }
                        else
                        {
                            MessageBox.Show("date should be in past", "Invalid Date", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        }
                    }
                    else
                    {
                        MessageBox.Show("Please make sure that all fields are filled", "Empty Fields", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                }
                else//newCustomer=false
                {//if its false it means from comboBox
                    int i = comboBox1.SelectedIndex;
                    ////check this               customerID = customerObject.custObject[i].Cid;
                    //  customerID = customer.custObject[i].Cid;
                    BookSeatPlan bookSeat = new BookSeatPlan();
                    bookSeat.getCustomerNic(customerID, txtNic.Text, txtFname.Text, txtLname.Text);
                    newCustomer = false;
                    //MessageBox.Show("Data added successfully! \r\nSelect from existing customer before booking", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    MessageBox.Show("Please wait while the booking form loads......", "Loading", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);

                    bookSeat.ShowDialog();
                    this.Close();
                }
            }

            catch (IndexOutOfRangeException exc)
            {
                MessageBox.Show("Select the customer before booking seat\n\nError:" + exc.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Exception error " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }