private void btmSearchVarata_Click(object sender, EventArgs e) // New order { // Check date again, if user change data, and no do search if (!OrderUtils.CheckCottageBookDate(Convert.ToInt32(dgSearchTable.CurrentRow.Cells[0].Value), dtpSearchFROM.Text, dtpSearchTO.Text)) { btnSearchHae_Click(sender, e); return; } ConnectionUtils.OpenConnection(); MySqlCommand command = new MySqlCommand("SELECT toimintaalue_id FROM toimintaalue WHERE nimi Like '" + dgSearchTable.CurrentRow.Cells[1].Value.ToString() + "'", ConnectionUtils.connection); int toimintaalueid = Convert.ToInt32(command.ExecuteScalar().ToString()); // Make object to send on Booking window Cottage cottage = new Cottage(Convert.ToInt32(dgSearchTable.CurrentRow.Cells[0].Value), toimintaalueid, dgSearchTable.CurrentRow.Cells[2].Value.ToString(), dgSearchTable.CurrentRow.Cells[3].Value.ToString(), dgSearchTable.CurrentRow.Cells[4].Value.ToString(), dgSearchTable.CurrentRow.Cells[5].Value.ToString(), Convert.ToInt32(dgSearchTable.CurrentRow.Cells[6].Value.ToString()), dgSearchTable.CurrentRow.Cells[7].Value.ToString(), Convert.ToDouble(dgSearchTable.CurrentRow.Cells[8].Value.ToString())); ConnectionUtils.CloseConnection(); NewBook newbook = new NewBook(cottage, dtpSearchFROM.Value.Date, dtpSearchTO.Value.Date); Booking booking = new Booking(newbook); booking.ShowDialog(); }
public Booking(NewBook b) { InitializeComponent(); ConnectionUtils.OpenConnection(); MySqlCommand command = new MySqlCommand("SELECT nimi FROM toimintaalue WHERE toimintaalue_id Like '" + b.Cottage.RegionID.ToString() + "'", ConnectionUtils.connection); string region = command.ExecuteScalar().ToString(); ConnectionUtils.CloseConnection(); // Fill cottage data and book date lblBookCottageId.Text = b.Cottage.CottageID.ToString(); lblBookEquipment.Text = "(Varustelu: " + b.Cottage.Equipment + ")"; lblBookCottageName.Text = b.Cottage.Name.ToString(); lblBookCottageAddress.Text = b.Cottage.Address.ToString() + ", " + b.Cottage.Postal.ToString(); lblBookAlue.Text = region; lblBookMaxPersons.Text = b.Cottage.Capacity.ToString() + " hlö"; lblBookCottagePrice.Text = b.Cottage.Price.ToString() + " €/yö"; lblBookBookingDateFrom.Text = b.Alkupv.ToString("yyyy-MM-dd"); lblBookBookingDateTo.Text = b.Loppupv.ToString("yyyy-MM-dd"); cottagepriodprice = b.Cottage.Price * ((b.Loppupv - b.Alkupv).TotalDays); lblBookDays.Text = "(" + ((b.Loppupv - b.Alkupv).TotalDays).ToString() + " pv)"; lblBookSeasonPrice.Text = cottagepriodprice.ToString() + " €"; lblBookPriceFull.Text = cottagepriodprice.ToString() + " €"; MySqlDataAdapter sda = new MySqlDataAdapter("SELECT palvelu_id as 'ID', nimi as 'Nimi', kuvaus as 'Kuvaus', " + "hinta as 'hinta/kpl', 0 as 'kpl' FROM palvelu WHERE toimintaalue_id LIKE '" + b.Cottage.RegionID + "'", ConnectionUtils.connection); DataTable data = new DataTable(); sda.Fill(data); dgvBookServices.DataSource = data; dgvBookServices.Columns[0].Width = 26; dgvBookServices.Columns[1].Width = 200; dgvBookServices.Columns[2].Width = 320; dgvBookServices.Columns[3].Width = 57; dgvBookServices.Columns[4].Width = 30; foreach (DataGridViewColumn dgvc in dgvBookServices.Columns) // Make all rows non editable { dgvc.ReadOnly = true; dgvBookServices.Columns[4].DefaultCellStyle.BackColor = Color.PaleGreen; } dgvBookServices.Columns[4].ReadOnly = false; // Make editable only "kpl" row }