Exemple #1
0
        private void deleteCustomerButton_Click(object sender, EventArgs e)
        {
            if (indexCustomer > -1)
            {
                var confirmResult = MessageBox.Show("Are you sure you want to delete this Customer?",
                                                    "Confirm Delete", MessageBoxButtons.YesNo);

                if (confirmResult == DialogResult.Yes)

                {
                    try
                    {
                        if (!customerHasAppt(TrackSelected.SelectedCustomerId))
                        {
                            ;
                        }
                    }
                    catch (CustomerDeletionException customerDeletionException)
                    {
                        Console.WriteLine("/n" + customerDeletionException.Message);
                        return;
                    }

                    U069LrDataSetTableAdapters.customerTableAdapter customerTableAdapter = new U069LrDataSetTableAdapters.customerTableAdapter();
                    customerTableAdapter.DeleteQuery(TrackSelected.SelectedCustomerId);

                    U069LrDataSetTableAdapters.addressTableAdapter addressTableAdapter = new U069LrDataSetTableAdapters.addressTableAdapter();
                    addressTableAdapter.DeleteQuery(TrackSelected.SelectedAddressId);
                }
                else
                {
                    MessageBox.Show("Customer deletion cancelled.");
                }
            }
            else
            {
                MessageBox.Show("Please select a Customer to delete.");
            }
            indexCustomer = -1;
            formatDataGridView(customerDataGridView);
            this.customerTableAdapter.Fill(this.u069LrDataSet.customer);
        }
Exemple #2
0
        private void saveCustomerButton_Click(object sender, EventArgs e)
        {
            DatabaseConnection con = new DatabaseConnection();

            string custNameValue, add1Value, add2Value, postalCodeValue, phoneValue, city;
            int    cityId    = 0;
            int    countryId = 0;


            custNameValue   = custNameTextBox.Text;
            add1Value       = add1TextBox1.Text;
            add2Value       = add2TextBox2.Text;
            postalCodeValue = postalCodeTxtBox.Text;
            phoneValue      = phoneTextBox.Text;
            DateTime updateDate = DateTime.UtcNow;


            con.Open();

            try
            {
                MySqlDataReader row;
                string          query = "select countryId, cityId, city from city where city = '" + cityComboBox.Text + "'";
                row = con.ExecuteReader(query);


                if (row.HasRows)
                {
                    while (row.Read())
                    {
                        cityId    = Convert.ToInt32(row["cityId"]);
                        countryId = Convert.ToInt32(row["countryId"]);
                        city      = row["city"].ToString();
                    }

                    U069LrDataSetTableAdapters.customerTableAdapter customerTableAdapter = new U069LrDataSetTableAdapters.customerTableAdapter();
                    customerTableAdapter.UpdateQuery(custNameValue, updateDate, CurrentOnlineUser.currentOnlineUserName, TrackSelected.SelectedCustomerId);



                    U069LrDataSetTableAdapters.addressTableAdapter addressTableAdapter = new U069LrDataSetTableAdapters.addressTableAdapter();
                    addressTableAdapter.UpdateQuery(add1Value, add2Value, cityId, postalCodeValue, phoneValue, updateDate, CurrentOnlineUser.currentOnlineUserName, TrackSelected.SelectedAddressId);
                }
                else
                {
                    MessageBox.Show("Customer Record not Saved!", "Information");
                }
            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Information");
            }


            con.Close();

            this.Hide();
            CustomersForm customerForm = new CustomersForm();

            customerForm.Show();
        }