Program.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Population_Database
{
static class Program
{
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
}
Form1.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Population_Database
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void cityBindingNavigatorSaveItem_Click(object sender, EventArgs e)
{
this.Validate();
this.cityBindingSource.EndEdit();
this.tableAdapterManager.UpdateAll(this.cityDataSet);
}
private void Form1_Load(object sender, EventArgs e)
{
// TODO: This line of code loads data into the \'cityDataSet.City\' table. You can move,
or remove it, as needed.
this.cityTableAdapter.Fill(this.cityDataSet.City);
}
private void btnAscPopulation_Click(object sender, EventArgs e)
{
// Sort the table by population in ascending order
this.cityTableAdapter.FillByAscPopulation(this.cityDataSet.City);
}
private void btnDescPopulation_Click(object sender, EventArgs e)
{
// Sort the table by population in descending order
this.cityTableAdapter.FillByDescPopulation(this.cityDataSet.City);
}
private void btnName_Click(object sender, EventArgs e)
{
this.cityTableAdapter.FillByCity(this.cityDataSet.City);
}
private void btnTotal_Click(object sender, EventArgs e)
{
// Declare variable to hold total population.
double totalPopulation;
// Get the total population.
totalPopulation = (double)this.cityTableAdapter.TotalPopulation();
// Display the total population.
MessageBox.Show(\"Total Population: \" + totalPopulation.ToString(\"n0\"));
}
private void btnAverage_Click(object sender, EventArgs e)
{
// Declare variable to hold average population.
double averagePopulation;
// Get the average population.
averagePopulation = (double)this.cityTableAdapter.AveragePopulation();
// Display the average population.
MessageBox.Show(\"Average Population: \" + averagePopulation.ToString(\"n0\"));
}
private void btnMaxPopulation_Click(object sender, EventArgs e)
{
// Declare variable to hold highest population.
double maxPopulation;
// Get the highest population.
maxPopulation = (double)this.cityTableAdapter.MaxPopulation();
// Display the highest population.
MessageBox.Show(\"Highest Population: \" + maxPopulation.ToString(\"n0\"));
}
private void btnMinPopulation_Click(object sender, EventArgs e)
{
// Declare variable to hold lowest population.
double minPopulation;
// Get the lowest population.
minPopulation = (double)this.cityTableAdapter.MinPopulation();
// Display the lowest population.
MessageBox.Show(\"Lowest Population: \" + minPopulation.ToString(\"n0\"));
}
private void btnExit_Click(object sender, EventArgs e)
{
// Cl.
Program.csusing System; using System.Collections.Generic; usin.pdf
1. Program.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Population_Database
{
static class Program
{
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
}
Form1.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Population_Database
{
public partial class Form1 : Form
{
public Form1()
{
2. InitializeComponent();
}
private void cityBindingNavigatorSaveItem_Click(object sender, EventArgs e)
{
this.Validate();
this.cityBindingSource.EndEdit();
this.tableAdapterManager.UpdateAll(this.cityDataSet);
}
private void Form1_Load(object sender, EventArgs e)
{
// TODO: This line of code loads data into the 'cityDataSet.City' table. You can move,
or remove it, as needed.
this.cityTableAdapter.Fill(this.cityDataSet.City);
}
private void btnAscPopulation_Click(object sender, EventArgs e)
{
// Sort the table by population in ascending order
this.cityTableAdapter.FillByAscPopulation(this.cityDataSet.City);
}
private void btnDescPopulation_Click(object sender, EventArgs e)
{
// Sort the table by population in descending order
this.cityTableAdapter.FillByDescPopulation(this.cityDataSet.City);
}
private void btnName_Click(object sender, EventArgs e)
{
this.cityTableAdapter.FillByCity(this.cityDataSet.City);
}
private void btnTotal_Click(object sender, EventArgs e)
{
// Declare variable to hold total population.
double totalPopulation;
// Get the total population.
totalPopulation = (double)this.cityTableAdapter.TotalPopulation();
// Display the total population.
MessageBox.Show("Total Population: " + totalPopulation.ToString("n0"));
3. }
private void btnAverage_Click(object sender, EventArgs e)
{
// Declare variable to hold average population.
double averagePopulation;
// Get the average population.
averagePopulation = (double)this.cityTableAdapter.AveragePopulation();
// Display the average population.
MessageBox.Show("Average Population: " + averagePopulation.ToString("n0"));
}
private void btnMaxPopulation_Click(object sender, EventArgs e)
{
// Declare variable to hold highest population.
double maxPopulation;
// Get the highest population.
maxPopulation = (double)this.cityTableAdapter.MaxPopulation();
// Display the highest population.
MessageBox.Show("Highest Population: " + maxPopulation.ToString("n0"));
}
private void btnMinPopulation_Click(object sender, EventArgs e)
{
// Declare variable to hold lowest population.
double minPopulation;
// Get the lowest population.
minPopulation = (double)this.cityTableAdapter.MinPopulation();
// Display the lowest population.
MessageBox.Show("Lowest Population: " + minPopulation.ToString("n0"));
}
private void btnExit_Click(object sender, EventArgs e)
{
// Close the form.
this.Close();
}
}
}
4. Form1.Designer.cs
namespace Population_Database
{
partial class Form1
{
private System.ComponentModel.IContainer components = null;
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
System.ComponentModel.ComponentResourceManager resources = new
System.ComponentModel.ComponentResourceManager(typeof(Form1));
this.cityBindingNavigator = new
System.Windows.Forms.BindingNavigator(this.components);
this.bindingNavigatorAddNewItem = new System.Windows.Forms.ToolStripButton();
this.cityBindingSource = new System.Windows.Forms.BindingSource(this.components);
this.cityDataSet = new Population_Database.CityDataSet();
this.bindingNavigatorCountItem = new System.Windows.Forms.ToolStripLabel();
this.bindingNavigatorDeleteItem = new System.Windows.Forms.ToolStripButton();
this.bindingNavigatorMoveFirstItem = new System.Windows.Forms.ToolStripButton();
this.bindingNavigatorMovePreviousItem = new
System.Windows.Forms.ToolStripButton();
this.bindingNavigatorSeparator = new System.Windows.Forms.ToolStripSeparator();
this.bindingNavigatorPositionItem = new System.Windows.Forms.ToolStripTextBox();
this.bindingNavigatorSeparator1 = new System.Windows.Forms.ToolStripSeparator();
this.bindingNavigatorMoveNextItem = new System.Windows.Forms.ToolStripButton();
this.bindingNavigatorMoveLastItem = new System.Windows.Forms.ToolStripButton();
this.bindingNavigatorSeparator2 = new System.Windows.Forms.ToolStripSeparator();
5. this.cityBindingNavigatorSaveItem = new System.Windows.Forms.ToolStripButton();
this.cityDataGridView = new System.Windows.Forms.DataGridView();
this.dataGridViewTextBoxColumn1 = new
System.Windows.Forms.DataGridViewTextBoxColumn();
this.dataGridViewTextBoxColumn2 = new
System.Windows.Forms.DataGridViewTextBoxColumn();
this.grpSort = new System.Windows.Forms.GroupBox();
this.btnName = new System.Windows.Forms.Button();
this.btnDescPopulation = new System.Windows.Forms.Button();
this.btnAscPopulation = new System.Windows.Forms.Button();
this.grpDisplay = new System.Windows.Forms.GroupBox();
this.btnMinPopulation = new System.Windows.Forms.Button();
this.btnMaxPopulation = new System.Windows.Forms.Button();
this.btnAverage = new System.Windows.Forms.Button();
this.btnTotal = new System.Windows.Forms.Button();
this.btnExit = new System.Windows.Forms.Button();
this.cityTableAdapter = new
Population_Database.CityDataSetTableAdapters.CityTableAdapter();
this.tableAdapterManager = new
Population_Database.CityDataSetTableAdapters.TableAdapterManager();
((System.ComponentModel.ISupportInitialize)(this.cityBindingNavigator)).BeginInit();
this.cityBindingNavigator.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.cityBindingSource)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.cityDataSet)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.cityDataGridView)).BeginInit();
this.grpSort.SuspendLayout();
this.grpDisplay.SuspendLayout();
this.SuspendLayout();
//
// cityBindingNavigator
//
this.cityBindingNavigator.AddNewItem = this.bindingNavigatorAddNewItem;
this.cityBindingNavigator.BindingSource = this.cityBindingSource;
this.cityBindingNavigator.CountItem = this.bindingNavigatorCountItem;
this.cityBindingNavigator.DeleteItem = this.bindingNavigatorDeleteItem;
this.cityBindingNavigator.Items.AddRange(new
16. using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Population_Database
{
static class Program
{
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
}
Form1.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Population_Database
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void cityBindingNavigatorSaveItem_Click(object sender, EventArgs e)
17. {
this.Validate();
this.cityBindingSource.EndEdit();
this.tableAdapterManager.UpdateAll(this.cityDataSet);
}
private void Form1_Load(object sender, EventArgs e)
{
// TODO: This line of code loads data into the 'cityDataSet.City' table. You can move,
or remove it, as needed.
this.cityTableAdapter.Fill(this.cityDataSet.City);
}
private void btnAscPopulation_Click(object sender, EventArgs e)
{
// Sort the table by population in ascending order
this.cityTableAdapter.FillByAscPopulation(this.cityDataSet.City);
}
private void btnDescPopulation_Click(object sender, EventArgs e)
{
// Sort the table by population in descending order
this.cityTableAdapter.FillByDescPopulation(this.cityDataSet.City);
}
private void btnName_Click(object sender, EventArgs e)
{
this.cityTableAdapter.FillByCity(this.cityDataSet.City);
}
private void btnTotal_Click(object sender, EventArgs e)
{
// Declare variable to hold total population.
double totalPopulation;
// Get the total population.
totalPopulation = (double)this.cityTableAdapter.TotalPopulation();
// Display the total population.
MessageBox.Show("Total Population: " + totalPopulation.ToString("n0"));
}
private void btnAverage_Click(object sender, EventArgs e)
{
18. // Declare variable to hold average population.
double averagePopulation;
// Get the average population.
averagePopulation = (double)this.cityTableAdapter.AveragePopulation();
// Display the average population.
MessageBox.Show("Average Population: " + averagePopulation.ToString("n0"));
}
private void btnMaxPopulation_Click(object sender, EventArgs e)
{
// Declare variable to hold highest population.
double maxPopulation;
// Get the highest population.
maxPopulation = (double)this.cityTableAdapter.MaxPopulation();
// Display the highest population.
MessageBox.Show("Highest Population: " + maxPopulation.ToString("n0"));
}
private void btnMinPopulation_Click(object sender, EventArgs e)
{
// Declare variable to hold lowest population.
double minPopulation;
// Get the lowest population.
minPopulation = (double)this.cityTableAdapter.MinPopulation();
// Display the lowest population.
MessageBox.Show("Lowest Population: " + minPopulation.ToString("n0"));
}
private void btnExit_Click(object sender, EventArgs e)
{
// Close the form.
this.Close();
}
}
}
Form1.Designer.cs
namespace Population_Database
{
19. partial class Form1
{
private System.ComponentModel.IContainer components = null;
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
System.ComponentModel.ComponentResourceManager resources = new
System.ComponentModel.ComponentResourceManager(typeof(Form1));
this.cityBindingNavigator = new
System.Windows.Forms.BindingNavigator(this.components);
this.bindingNavigatorAddNewItem = new System.Windows.Forms.ToolStripButton();
this.cityBindingSource = new System.Windows.Forms.BindingSource(this.components);
this.cityDataSet = new Population_Database.CityDataSet();
this.bindingNavigatorCountItem = new System.Windows.Forms.ToolStripLabel();
this.bindingNavigatorDeleteItem = new System.Windows.Forms.ToolStripButton();
this.bindingNavigatorMoveFirstItem = new System.Windows.Forms.ToolStripButton();
this.bindingNavigatorMovePreviousItem = new
System.Windows.Forms.ToolStripButton();
this.bindingNavigatorSeparator = new System.Windows.Forms.ToolStripSeparator();
this.bindingNavigatorPositionItem = new System.Windows.Forms.ToolStripTextBox();
this.bindingNavigatorSeparator1 = new System.Windows.Forms.ToolStripSeparator();
this.bindingNavigatorMoveNextItem = new System.Windows.Forms.ToolStripButton();
this.bindingNavigatorMoveLastItem = new System.Windows.Forms.ToolStripButton();
this.bindingNavigatorSeparator2 = new System.Windows.Forms.ToolStripSeparator();
this.cityBindingNavigatorSaveItem = new System.Windows.Forms.ToolStripButton();
this.cityDataGridView = new System.Windows.Forms.DataGridView();
this.dataGridViewTextBoxColumn1 = new
20. System.Windows.Forms.DataGridViewTextBoxColumn();
this.dataGridViewTextBoxColumn2 = new
System.Windows.Forms.DataGridViewTextBoxColumn();
this.grpSort = new System.Windows.Forms.GroupBox();
this.btnName = new System.Windows.Forms.Button();
this.btnDescPopulation = new System.Windows.Forms.Button();
this.btnAscPopulation = new System.Windows.Forms.Button();
this.grpDisplay = new System.Windows.Forms.GroupBox();
this.btnMinPopulation = new System.Windows.Forms.Button();
this.btnMaxPopulation = new System.Windows.Forms.Button();
this.btnAverage = new System.Windows.Forms.Button();
this.btnTotal = new System.Windows.Forms.Button();
this.btnExit = new System.Windows.Forms.Button();
this.cityTableAdapter = new
Population_Database.CityDataSetTableAdapters.CityTableAdapter();
this.tableAdapterManager = new
Population_Database.CityDataSetTableAdapters.TableAdapterManager();
((System.ComponentModel.ISupportInitialize)(this.cityBindingNavigator)).BeginInit();
this.cityBindingNavigator.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.cityBindingSource)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.cityDataSet)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.cityDataGridView)).BeginInit();
this.grpSort.SuspendLayout();
this.grpDisplay.SuspendLayout();
this.SuspendLayout();
//
// cityBindingNavigator
//
this.cityBindingNavigator.AddNewItem = this.bindingNavigatorAddNewItem;
this.cityBindingNavigator.BindingSource = this.cityBindingSource;
this.cityBindingNavigator.CountItem = this.bindingNavigatorCountItem;
this.cityBindingNavigator.DeleteItem = this.bindingNavigatorDeleteItem;
this.cityBindingNavigator.Items.AddRange(new
System.Windows.Forms.ToolStripItem[] {
this.bindingNavigatorMoveFirstItem,
this.bindingNavigatorMovePreviousItem,