Esempio n. 1
0
        private void saveCustomerButton_Click(object sender, EventArgs e)
        {
            int findNxtAddId       = findNtextAddressID();
            DatabaseConnection con = new DatabaseConnection();

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

            custNameValue   = custNameTextBox.Text;
            add1Value       = address1TextBox.Text;
            add2Value       = address2textBox.Text;
            postalCodeValue = postalCodeTextBox.Text;
            phoneValue      = phoneTextBox.Text;
            DateTime creaetDate = 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.addressTableAdapter addressTableAdapter = new U069LrDataSetTableAdapters.addressTableAdapter();
                    addressTableAdapter.InsertQuery(findNxtAddId, add1Value, add2Value, cityId, postalCodeValue, phoneValue, creaetDate, CurrentOnlineUser.currentOnlineUserName, creaetDate, CurrentOnlineUser.currentOnlineUserName);


                    U069LrDataSetTableAdapters.customerTableAdapter customerTableAdapter = new U069LrDataSetTableAdapters.customerTableAdapter();
                    customerTableAdapter.InsertQuery(custNameValue, findNxtAddId, 1, creaetDate, CurrentOnlineUser.currentOnlineUserName, creaetDate, CurrentOnlineUser.currentOnlineUserName);
                }
                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();
        }