private void btnCottageSearch_Click(object sender, EventArgs e) { try { //Get's data from form components, and does a query to the DB. Updates CottageDataGridView-component to show search results string query = "SELECT * FROM mokki " + "WHERE toimintaalue_id = " + RegionUtils.RegionNameToIndex(cbCottageRegions.Text) + " " + "AND postinro LIKE '%" + TextBoxUtils.ModifyInput(tbCottagePostNum.Text, 5) + "%' " + "AND mokkinimi LIKE '%" + TextBoxUtils.ModifyInput(tbCottageName.Text, 45) + "%' " + "AND katuosoite LIKE '%" + TextBoxUtils.ModifyInput(tbCottageStreetAddress.Text, 45) + "%' " + "AND kuvaus LIKE '%" + TextBoxUtils.ModifyInput(tbCottageDescription.Text, 500) + "%' " + "AND henkilomaara > '" + (nudCottageCapacity.Value - 1) + "' " + "AND varustelu LIKE '%" + cbCottageEqupment.Text + "%' " + "AND hinta <(" + Convert.ToDouble(nudCottagePrice.Value + 1) + ");"; try { DataTable table = new DataTable(); MySqlDataAdapter adapter = new MySqlDataAdapter(query, ConnectionUtils.connection); adapter.Fill(table); dgvCottage.DataSource = table; } catch (Exception ex) { MessageBox.Show("Virhe tietojen hakemisessa. Tarkista tiedot ja yritä uudelleen. Lisätietoja: " + ex.Message); } } catch (Exception ex) { MessageBox.Show("Virhe haun tekemisessä. Tarkista tiedot ja yritä uudelleen. Lisätietoja: " + ex.Message); } }
private void btnServiceSearch_Click(object sender, EventArgs e) { try { //Get's data from form components, and does a query to the DB. Updates ServiceDataGridView-component to show search results string query = "SELECT * FROM palvelu " + "WHERE toimintaalue_id = " + RegionUtils.RegionNameToIndex(cbServiceRegion.Text) + " " + "AND nimi LIKE '%" + TextBoxUtils.ModifyInput(tbServiceName.Text, 40) + "%' " + "AND tyyppi LIKE '%" + tbServiceType.Text + "%' " + "AND kuvaus LIKE '%" + TextBoxUtils.ModifyInput(tbServiceDescription.Text, 500) + "%' " + "AND hinta <(" + (nudServicePrice.Value + 1) + ");"; try { DataTable table = new DataTable(); MySqlDataAdapter adapter = new MySqlDataAdapter(query, ConnectionUtils.connection); adapter.Fill(table); dgvService.DataSource = table; dgvService.Columns[0].HeaderText = "Palvelu ID"; dgvService.Columns[1].HeaderText = "Toiminta-alue ID"; dgvService.Columns[2].HeaderText = "Nimi"; dgvService.Columns[3].HeaderText = "Tyyppi"; dgvService.Columns[4].HeaderText = "Kuvaus"; dgvService.Columns[5].HeaderText = "Hinta (€)"; dgvService.Columns[6].HeaderText = "Alv (%)"; } catch (Exception ex) { MessageBox.Show("Virhe tietojen hakemisessa. Tarkista tiedot ja yritä uudelleen. Lisätietoja: " + ex.Message); } } catch (Exception ex) { MessageBox.Show("Virhe haun tekemisessä. Tarkista tiedot ja yritä uudelleen. Lisätietoja: " + ex.Message); } }
private void btnModifyCottageModify_Click(object sender, EventArgs e) { //Make sure the data should be modified DialogResult result = MessageBox.Show("Haluatko varmasti muuttaa valitun mökin tietoja?", "Muuta mökin tietoja", MessageBoxButtons.YesNo, MessageBoxIcon.Information); if (result == DialogResult.Yes) { try { //Updates cottages information in the database. Gets data from form components, cottage is uniquely identified by cottageID, which can't be modified string query = "START TRANSACTION; " + "UPDATE mokki " + "SET toimintaalue_id=" + RegionUtils.RegionNameToIndex(cbModifyCottageRegion.Text) + ",postinro='" + TextBoxUtils.ModifyInput(tbModifyCottagePostNum.Text, 5) + "',mokkinimi='" + TextBoxUtils.ModifyInput(tbModifyCottageName.Text, 45) + "',katuosoite='" + TextBoxUtils.ModifyInput(tbModifyCottageStreet.Text, 45) + "'," + "kuvaus='" + TextBoxUtils.ModifyInput(tbModifyCottageDescription.Text, 500) + "',henkilomaara=" + nudModifyCottageCapacity.Value + " ,varustelu='" + TextBoxUtils.ModifyInput(cbModifyCottageEquipment.Text, 100) + "', hinta=" + Convert.ToDouble(nudModifyCottagePrice.Value) + " " + "WHERE mokki_id=" + Convert.ToInt32(lblModifyCottageID.Text) + "; " + "COMMIT;"; try { ConnectionUtils.OpenConnection(); MySqlCommand command = new MySqlCommand(query, ConnectionUtils.connection); command.ExecuteNonQuery(); ConnectionUtils.CloseConnection(); this.Close(); } catch (Exception ex) { //Incase of database-connection problems ConnectionUtils.CloseConnection(); MessageBox.Show("Virhe tietojen syöttämisessä tietokantaan. Tarkista kenttien tiedot, ja yritä uudelleen myöhemmin. Lisätietoja virheestä: " + ex.Message.ToString()); } } catch (Exception ex) { //Incase of variable conversion problems ConnectionUtils.CloseConnection(); MessageBox.Show("Virhe tietojen muuntamisessa. Onhan kaikkien kenttien syötteet oikein? Lisätietoja virheestä: " + ex.Message.ToString()); } } }
private void btnModifyServiceModify_Click(object sender, EventArgs e) { //Make sure the data should be modified DialogResult result = MessageBox.Show("Haluatko varmasti muuttaa valitun palvelun tietoja?", "Muuta palvelun tietoja", MessageBoxButtons.YesNo, MessageBoxIcon.Information); if (result == DialogResult.Yes) { try { //Updates services information in the database. Gets data from form components, service is uniquely identified by serviceID, which can't be modified string query = "START TRANSACTION; " + "UPDATE palvelu " + "SET toimintaalue_id=" + RegionUtils.RegionNameToIndex(cbModifyServiceRegion.Text) + ",nimi='" + TextBoxUtils.ModifyInput(tbModifyServiceName.Text, 40) + "',tyyppi=" + Convert.ToInt32(tbModifyServiceType.Text) + ",kuvaus='" + TextBoxUtils.ModifyInput(tbModifyServiceDescription.Text, 40) + "'," + "hinta=" + Convert.ToDouble(nudModifyServicePrice.Value) + ",alv=" + Convert.ToDouble(nudModifyServiceVAT.Value) + " " + "WHERE palvelu_id=" + Convert.ToInt32(lblModifyServiceID.Text) + "; " + "COMMIT;"; try { ConnectionUtils.OpenConnection(); MySqlCommand command = new MySqlCommand(query, ConnectionUtils.connection); command.ExecuteNonQuery(); ConnectionUtils.CloseConnection(); this.Close(); } catch (Exception ex) { //Incase of database-connection problems ConnectionUtils.CloseConnection(); MessageBox.Show("Virhe tietojen syöttämisessä tietokantaan. Tarkista kenttien tiedot, ja yritä uudelleen myöhemmin. Lisätietoja virheestä: " + ex.Message.ToString()); } } catch (Exception ex) { //Incase of variable conversion problems ConnectionUtils.CloseConnection(); MessageBox.Show("Virhe tietojen muuntamisessa. Onhan kaikkien kenttien syötteet oikein? Lisätietoja virheestä: " + ex.Message.ToString()); } } }
private void btnAddCottageAdd_Click(object sender, EventArgs e) { //Add a cottage to the database, gets data from form components try { PostUtils.CheckPostal(tbAddCottagePostNum.Text, tbAddCottagePostRegion.Text); string query = "START TRANSACTION; " + "INSERT INTO mokki(mokki_id,toimintaalue_id,postinro,mokkinimi,katuosoite,kuvaus,henkilomaara,varustelu,hinta) " + "VALUES(default," + RegionUtils.RegionNameToIndex(cbAddCottageRegion.Text) + ",'" + TextBoxUtils.ModifyInput(tbAddCottagePostNum.Text, 5) + "','" + TextBoxUtils.ModifyInput(tbAddCottageName.Text, 45) + "','" + TextBoxUtils.ModifyInput(tbAddCottageStreet.Text, 45) + "','" + TextBoxUtils.ModifyInput(tbAddCottageDescription.Text, 500) + "'," + (int)nudAddCottageCapacity.Value + ",'" + TextBoxUtils.ModifyInput(cbAddCottageEquipment.Text, 100) + "'," + (double)nudAddCottagePrice.Value + "); " + "COMMIT;"; try { ConnectionUtils.OpenConnection(); MySqlCommand command = new MySqlCommand(query, ConnectionUtils.connection); command.ExecuteNonQuery(); ConnectionUtils.CloseConnection(); this.Close(); } catch (Exception ex) { //Incase of connction problems ConnectionUtils.CloseConnection(); MessageBox.Show("Virhe tietojen syöttämisessä tietokantaan. Tarkista kenttien tiedot. Lisätietoja: " + ex.Message.ToString()); } } catch (Exception ex) { //Incase of exceptions in variable conversion ConnectionUtils.CloseConnection(); MessageBox.Show("Virhe tietojen muuntamisessa. Tarkista kenttien tiedot. Lisätietoja: " + ex.Message.ToString()); } }
private void btnAddServiceAdd_Click(object sender, EventArgs e) { try { //Add a service to the database, gets data from form components string query = "START TRANSACTION; " + "INSERT INTO palvelu(palvelu_id,toimintaalue_id,nimi,tyyppi,kuvaus,hinta,alv) " + "VALUES(default," + RegionUtils.RegionNameToIndex(cbAddServiceRegion.Text) + ",'" + TextBoxUtils.ModifyInput(tbAddServiceName.Text, 40) + "'," + Convert.ToInt32(tbAddServiceType.Text) + ",'" + TextBoxUtils.ModifyInput(tbAddServiceDescription.Text, 500) + "'," + (double)nudAddServicePrice.Value + "," + (double)nudAddServiceVAT.Value + "); " + "COMMIT;"; try { ConnectionUtils.OpenConnection(); MySqlCommand command = new MySqlCommand(query, ConnectionUtils.connection); command.ExecuteNonQuery(); ConnectionUtils.CloseConnection(); this.Close(); } catch (Exception ex) { //Incase of database-connection problems ConnectionUtils.CloseConnection(); MessageBox.Show("Virhe tietojen syöttämisessä tietokantaan. Tarkista kenttien tiedot. Lisätietoja: " + ex.Message.ToString()); } } catch (Exception ex) { //Incase of variable conversion problems ConnectionUtils.CloseConnection(); MessageBox.Show("Virhe tietojen muuntamisessa. Tarkista kenttien tiedot. Lisätietoja: " + ex.Message.ToString()); } }