public void LoadAirportList(string country) { AirportDAL aDAO = new AirportDAL(); dsAirport = aDAO.GetAirportByCountryDataset(country); bindingSourceAirport = new BindingSource(); bindingSourceAirport.DataSource = dsAirport; bindingSourceAirport.DataMember = "Airport"; dgvAirport.DataSource = null; dgvAirport.DataSource = bindingSourceAirport; BindingControls(); dgvAirport.RowTemplate.Height = 24; dgvAirport.Columns["code"].Width = 40; dgvAirport.Columns["name"].Width = 220; dgvAirport.Columns["city"].Width = 120; dgvAirport.Columns["state"].Width = 120; dgvAirport.Columns["country"].Width = 120; dgvAirport.Columns["utc_time"].Width = 80; dgvAirport.RowHeadersVisible = false; dgvAirport.SelectionMode = DataGridViewSelectionMode.FullRowSelect; dgvAirport.Columns["deleted"].Visible = false; dgvAirport.Columns["openning"].Visible = false; dgvAirport.Refresh(); }
private void btnAdd_Click(object sender, EventArgs e) { if (btnAdd.Text.Equals("Add")) { btnAdd.Text = "Save"; LockControls(false); ClearBindingControls(); ClearControls(); } else if (btnAdd.Text.Equals("Save")) { AirportEntity ae = new AirportEntity(); ae.Code = txtCode.Text; ae.Name = txtName.Text; ae.City = txtCity.Text; ae.State = txtState.Text; ae.Country = txtCountry.Text; ae.UtcTime = txtUTCTime.Text; ae.Openning = chkClosed.Checked; ae.Deleted = false; AirportDAL ado = new AirportDAL(); if (!ado.AddNewAirport(ae)) { MessageBox.Show("Can not insert new Airport. Please check again.", "Error", MessageBoxButtons.OKCancel, MessageBoxIcon.Error); } else { DataRow newRow = dsAirport.Tables["Airport"].NewRow(); newRow["code"] = ae.Code; newRow["name"] = ae.Name; newRow["city"] = ae.City; newRow["state"] = ae.State; newRow["country"] = ae.Country; newRow["utc_time"] = ae.UtcTime; newRow["openning"] = ae.Openning; newRow["deleted"] = ae.Deleted; dsAirport.Tables["Airport"].Rows.Add(newRow); BindingControls(); ClearControls(); LockControls(true); // LoadAirportList(lsbCountry.GetItemText(lsbCountry.SelectedItem)); } } }
private void btnDelete_Click(object sender, EventArgs e) { if (txtCode.Text.Equals("")) { MessageBox.Show("Please select an airport to delete."); } else { DialogResult isDelete = MessageBox.Show("Do you want to delete the Aiport " + txtName.Text + "?", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (isDelete == DialogResult.Yes) { AirportDAL aDAO = new AirportDAL(); if (aDAO.DeleteAirport(txtCode.Text)) { LoadAirportList(lsbCountry.GetItemText(lsbCountry.SelectedItem)); } } } }
public void LoadCountryList() { AirportDAL aDAO = new AirportDAL(); dsCountry = aDAO.GetUniqueCountryDataset(); DataTable dt = new DataTable(); dt = dsCountry.Tables["Country"]; dt.DefaultView.Sort = "Country ASC"; BindingSource bindingSource = new BindingSource(); bindingSource.DataSource = dt; //bindingSource.DataMember = "Country"; lsbCountry.DataSource = bindingSource; lsbCountry.DisplayMember = "Country"; lsbCountry.ValueMember = "Country"; }