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.Data.SqlClient; using System.Windows.Forms; using System.Windows.Forms.DataVisualization.Charting; namespace GeoTema { public partial class ViewData : Form { public ViewData() { InitializeComponent(); chGraph.Visible = false; dtgrBirth.Visible = false; } private void btnTable_Click(object sender, EventArgs e) { Sql CS = new Sql(); chGraph.Visible = false; dtgrBirth.Visible = true; string statement1 = "use fødselsrate_2017 select Land.Land,Verdensdel.Verdensdel,Rang.Rang,Rang.Fødselsrate from Land inner join Verdensdel on Land.Verdensdel1 = Verdensdel.VerdenID inner join Rang on Land.LandID = Rang.LandID"; DataTable table = new DataTable(); using (SqlConnection con = new SqlConnection(CS.ConString())) { con.Open(); SqlDataAdapter adapter = new SqlDataAdapter(statement1, con); adapter.Fill(table); dtgrBirth.DataSource = new BindingSource(table, null); } } private void btnGraph_Click(object sender, EventArgs e) { Sql CS = new Sql(); dtgrBirth.Visible = false; chGraph.Visible = true; string statement2 = "use fødselsrate_2017 select Land.Land, Rang.Fødselsrate from Land inner join Rang on Land.LandID = Rang.LandID"; DataSet DS = new DataSet(); using (SqlConnection con = new SqlConnection(CS.ConString())) { con.Open(); SqlDataAdapter adapter = new SqlDataAdapter(statement2, con); adapter.Fill(DS); chGraph.DataSource = DS; chGraph.Series["Birthrate"].XValueMember = "Land"; chGraph.Series["Birthrate"].YValueMembers = "Fødselsrate"; chGraph.ChartAreas["ChartArea1"].AxisX.LabelStyle.Interval = 1; //Forces the graph to show ALL Xaxis values and not just every other chGraph.DataBind(); } } private void btnBack_Click(object sender, EventArgs e) { switch(MainMenu.type) { case "administrator": { this.Hide(); AdminMenu Admin1 = new AdminMenu(); Admin1.ShowDialog(); this.Close(); break; } case "super user": { this.Hide(); SuperMenu Super1 = new SuperMenu(); Super1.ShowDialog(); this.Close(); break; } case "user": { this.Hide(); UserMenu User1 = new UserMenu(); User1.ShowDialog(); this.Close(); break; } } } } }