public AircraftDataChart(List <string> param, string mode) { InitializeComponent(); opMode = mode; if (mode == "edit") { aircraftName = param[0]; } else { nameList = param; } pdata = new PerformanceData(); fsdata = new FuelStartData(); frdata = new FuelReduceData(); performanceChart.Items.SortDescriptions.Add(new SortDescription(performanceChart.Columns[0].SortMemberPath, ListSortDirection.Ascending)); performanceChart.Items.IsLiveSorting = true; performanceChart.DataContext = pdata; performanceChart.ItemsSource = pdata.performanceDatas; //startFuelChart.Items.SortDescriptions.Add(new SortDescription(performanceChart.Columns[0].SortMemberPath, ListSortDirection.Ascending)); //startFuelChart.Items.IsLiveSorting = true; startFuelChart.DataContext = fsdata; startFuelChart.ItemsSource = fsdata.fuelStartDatas; //reductionFuelChart.Items.SortDescriptions.Add(new SortDescription(performanceChart.Columns[0].SortMemberPath, ListSortDirection.Ascending)); //reductionFuelChart.Items.IsLiveSorting = true; reductionFuelChart.DataContext = frdata; reductionFuelChart.ItemsSource = frdata.fuelReduceDatas; if (!File.Exists(@".\test.db")) { using (IDbConnection conn = new SQLiteConnection(@"Data Source=.\test.db;Version=3")) { conn.Execute($"CREATE TABLE '{performanceTable}' ('Aircraft' TEXT, 'ALT' REAL, 'ClimbTime' REAL, 'ClimbDistance' REAL, 'ClimbFuel' REAL, 'DescendTime' REAL, 'DescendDistance' REAL, 'DescendFuel' REAL, 'Speed01' REAL, 'Speed02' REAL, 'Speed03' REAL, 'Speed04' REAL, 'Speed05' REAL)", new DynamicParameters()); conn.Execute($"CREATE TABLE '{fuelTable}' ('Aircraft' TEXT, 'Type' TEXT, 'Label' TEXT, 'Value' REAL)", new DynamicParameters()); conn.Execute($"CREATE TABLE '{speedUnitTable}' ('Aircraft' TEXT, 'SpeedID' INTEGER NOT NULL UNIQUE, 'Value' REAL, 'Unit' TEXT, PRIMARY KEY(SpeedID AUTOINCREMENT))", new DynamicParameters()); } } if (mode == "edit") { aircraftNameBx.Text = aircraftName; aircraftNameBx.IsReadOnly = true; using (IDbConnection conn = new SQLiteConnection(@"Data Source=.\test.db;Version=3")) { var uOutput = conn.Query <String>($"SELECT Unit FROM '{speedUnitTable}' WHERE Aircraft='{aircraftName}' ORDER BY SpeedID", new DynamicParameters()); String[] units = uOutput.ToArray(); alt_units.SelectedValue = units[0]; dist_units.SelectedValue = units[1]; speed_units.SelectedValue = units[2]; fuel_units.SelectedValue = units[3]; lfft_units.SelectedValue = units[4]; var pOutput = conn.Query <PerformanceData>($"SELECT * FROM '{performanceTable}' WHERE Aircraft='{aircraftName}' ORDER BY ALT", new DynamicParameters()); pdata.performanceDatas.Clear(); foreach (PerformanceData info in pOutput) { pdata.performanceDatas.Add(info); } var fsOutput = conn.Query <FuelStartData>($"SELECT Label, Value FROM '{fuelTable}' WHERE Aircraft='{aircraftName}' AND Type='Starting' ORDER BY Label", new DynamicParameters()); fsdata.fuelStartDatas.Clear(); foreach (FuelStartData info in fsOutput) { fsdata.fuelStartDatas.Add(info); } var frOutput = conn.Query <FuelReduceData>($"SELECT Label, Value FROM '{fuelTable}' WHERE Aircraft='{aircraftName}' AND Type='Reduction' ORDER BY Label", new DynamicParameters()); frdata.fuelReduceDatas.Clear(); foreach (FuelReduceData info in frOutput) { frdata.fuelReduceDatas.Add(info); } var dOutput = conn.Query <Double>($"SELECT Value FROM '{speedUnitTable}' WHERE Aircraft='{aircraftName}' ORDER BY SpeedID", new DynamicParameters()); Double[] columnNames = dOutput.ToArray(); if (columnNames[0] != 0) { dataspd1.Text = columnNames[0].ToString(); } if (columnNames[1] != 0) { dataspd2.Text = columnNames[1].ToString(); } if (columnNames[2] != 0) { dataspd3.Text = columnNames[2].ToString(); } if (columnNames[3] != 0) { dataspd4.Text = columnNames[3].ToString(); } if (columnNames[4] != 0) { dataspd5.Text = columnNames[4].ToString(); } } } }
public void setpData(PerformanceData pd, int index, double spd) { speed = spd; if (index == -1) { alt = pd.alt; climbtime = pd.climbtime; climbdist = pd.climbdist; climbfuel = pd.climbfuel; descenddist = pd.descenddist; descendtime = pd.descendtime; descendfuel = pd.descendfuel; lfft = 0; return; } List <double> speeds = new List <double>() { pd.spd1, pd.spd2, pd.spd3, pd.spd4, pd.spd5 }; int spid = 0; for (int i = 0; i < 5; i++) { if (speeds[i] == spd) { spid = i + 1; break; } } aircraft = pd.performanceDatas[index].aircraft; alt = pd.performanceDatas[index].alt; climbtime = pd.performanceDatas[index].climbtime; climbdist = pd.performanceDatas[index].climbdist; climbfuel = pd.performanceDatas[index].climbfuel; descenddist = pd.performanceDatas[index].descenddist; descendtime = pd.performanceDatas[index].descendtime; descendfuel = pd.performanceDatas[index].descendfuel; switch (spid) { case 1: lfft = pd.performanceDatas[index].spd1; break; case 2: lfft = pd.performanceDatas[index].spd2; break; case 3: lfft = pd.performanceDatas[index].spd3; break; case 4: lfft = pd.performanceDatas[index].spd4; break; case 5: lfft = pd.performanceDatas[index].spd5; break; default: lfft = 0; break; } }