Exemple #1
0
        private void buttonvalidate_Click(object sender, EventArgs e)
        {
            //int newClientId;
            string clientName    = textBoxname.Text;
            string clientPhone   = textBoxphone.Text;
            string clientEmail   = textBoxmail.Text;
            string clientaddress = textBoxaddress.Text;
            string clientZipCode = textBoxZipCode.Text;
            string clientCity    = textBoxCity.Text;
            string clientVat     = textBoxVat.Text;

            if (!(string.IsNullOrEmpty(textBoxname.Text) || string.IsNullOrEmpty(textBoxphone.Text) || string.IsNullOrEmpty(textBoxmail.Text) ||
                  string.IsNullOrEmpty(textBoxaddress.Text) || string.IsNullOrEmpty(textBoxZipCode.Text) || string.IsNullOrEmpty(textBoxCity.Text)))
            {
                if (EmailValide.IsValidEmail(textBoxmail.Text))
                {
                    AddNewClient addNewClient = new AddNewClient(clientName, clientPhone, clientEmail, clientaddress, clientZipCode, clientCity, clientVat);
                    DBConnection.InsertNewClient(addNewClient);
                    ClientIdentification clientIdentification = new ClientIdentification(user, client);
                    clientIdentification.Show();
                    this.Close();
                }
                else
                {
                    MessageBox.Show("Email not valide", "wrong Email", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
            {
                MessageBox.Show("Every box is not full", "textBox empty", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        // insert new client in the DB
        public void InsertNewClient(AddNewClient addNewClient)
        {
            //long newClientId = 4;
            string queryNewClient = "INSERT INTO Client (name, phone, email, address, zipCode, city, vat)" +
                                    "VALUES('" + addNewClient.clientName + "', '" +
                                    addNewClient.clientPhone + "', '" + addNewClient.clientEmail + "', '" + addNewClient.clientaddress + "', '" +
                                    addNewClient.clientZipCode + "', '" + addNewClient.clientCity + "', '" + addNewClient.clientVat + "')";

            //open connection
            if (this.OpenConnection() == true)
            {
                //create command and assign the query and connection from the constructor
                MySqlCommand cmdNewClient = new MySqlCommand(queryNewClient, connection);

                //Execute command
                cmdNewClient.ExecuteNonQuery();

                //close connection
                this.CloseConnection();
            }
        }