private static void SaveScores(LandingStats stats) { //load the LandingStats string scorefile = GlobalData.landinglistsJsonPath; if (!File.Exists(scorefile)) { File.Create(scorefile).Close(); } try { var dat = JsonConvert.DeserializeObject <LandingStatList>(File.ReadAllText(scorefile)); dat.LandingStatslist.Add(stats); string json = JsonConvert.SerializeObject(dat, Formatting.Indented); File.WriteAllText(scorefile, json); } catch { LandingStatList l = new LandingStatList { LandingStatslist = new List <LandingStats>() }; l.LandingStatslist.Add(stats); string json = JsonConvert.SerializeObject(l, Formatting.Indented); File.WriteAllText(scorefile, json); } }
private void DataGridView1_MouseClick(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Right) { ContextMenu m = new ContextMenu(); var d = m.MenuItems.Add(new MenuItem("Delete")); m.Show(dataGridView1, new Point(e.X, e.Y)); m.MenuItems[d].Click += (object sender2, EventArgs e2) => { int currentMouseOverRow = dataGridView1.HitTest(e.X, e.Y).RowIndex; if (currentMouseOverRow >= 0) { var row = dataGridView1.Rows[currentMouseOverRow]; string date = row.Cells[0].Value.ToString(); string fpm = row.Cells[2].Value.ToString(); LandingStats item = currentStats.LandingStatslist.FirstOrDefault(x => x.FPM == fpm && x.Date == date); currentStats.LandingStatslist.Remove(item); dataGridView1.Rows.Remove(row); SaveScores(); } }; } }
internal static void AddStat(LandingStats stats) { dgv.Rows.Add(); dgv.Rows[rownum].Cells[0].Value = stats.Date; dgv.Rows[rownum].Cells[1].Value = stats.Score; dgv.Rows[rownum].Cells[2].Value = stats.FPM; dgv.Rows[rownum].Cells[3].Value = stats.Speed; dgv.Rows[rownum].Cells[4].Value = stats.Pitch; dgv.Rows[rownum].Cells[5].Value = stats.Roll; dgv.Rows[rownum].Cells[6].Value = stats.WindSpeed; dgv.Rows[rownum].Cells[7].Value = stats.WindDirection; dgv.Refresh(); //checkEmptyRow(); SaveScores(stats); rownum++; }
private void timer1_Tick(object sender, EventArgs e) { UpdateScreenData(); if (checkGroundTime >= 150) { if (FSUIPCConnection.IsOpen) { try { FSUIPCConnection.Process(); if (GlobalData.COM1act != COM1act.Value) { GlobalData.COM1act = COM1act.Value; } if (GlobalData.COM1sby != COM1sby.Value) { GlobalData.COM1sby = COM1sby.Value; } ATCID = aircraftID.Value; int fpm = 0; if (ATCID != OldCraft) { imageList1.Images.Clear(); Console.WriteLine("Changing Image..."); ATCID = aircraftID.Value; ATCTYPE = aircraftType.Value; label10.Text = $"{ATCID} - {ATCTYPE}"; string urlAddress = "https://www.airplane-pictures.net/registration.php?p=" + ATCID; Console.WriteLine(urlAddress); WebClient client = new WebClient(); client.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)"); int lineis = 0; bool Found = false; bool count = false; string image = ""; int permline = 0; client.DownloadFile(urlAddress, Environment.CurrentDirectory + @"\Data\AircraftConfig.tmp"); string[] Page_AppGet = File.ReadAllLines(Environment.CurrentDirectory + @"\Data\AircraftConfig.tmp"); foreach (string line in Page_AppGet) { lineis = lineis + 1; if (Found == false) { if (line.Contains("<img src='")) { Found = true; } } else { if (count == false) { permline = lineis - 1; count = true; } } } string Line = GetLine(File.ReadAllText(Environment.CurrentDirectory + @"\Data\AircraftConfig.tmp"), permline); if (Line != "0x359") { string before = Regex.Split(Line, "<img src='")[1]; string Images = Regex.Split(before, "'")[0]; string Type = Images.Split('.')[1]; client.DownloadFile(Images, Environment.CurrentDirectory + @"\Data\AircraftImage.lco"); imageList1.Images.Add(Image.FromFile(Environment.CurrentDirectory + @"\Data\AircraftImage.lco")); imageList1.ImageSize = new Size(191, 125); pictureBox1.Image = imageList1.Images[0]; File.Delete(Environment.CurrentDirectory + @"\Data\AircraftConfig.tmp"); } else { try { imageList1.Images.Clear(); Console.WriteLine("Failed.."); } catch { } } } OldCraft = ATCID; if (!ongrnd) { double verticalSpeedMPS = verticalSpeed.Value / 256d; double verticalSpeedFPM = verticalSpeedMPS * 60d * 3.28084d; var vsFPM = Convert.ToInt32(verticalSpeedFPM); ATCTYPE = aircraftType.Value; label10.Text = $"{ATCID} - {ATCTYPE}"; fpm = vsFPM; VSRate.Text = "Feet Per Minute: " + vsFPM.ToString(); timer1.Enabled = timerOn; double airspeedKnots = (double)airspeed.Value / 128d; airspd = Convert.ToInt32(airspeedKnots).ToString(); SpeedLabel.Text = "Speed: " + airspd; var plnPitch = (double)pitch.Value * 360 / 4294967296 * -1; WeatherServices ws = FSUIPCConnection.WeatherServices; FsWeather weather = ws.GetWeatherAtAircraft(); if (weather.WindLayers.Count > 0) { FsWindLayer windLayer = weather.WindLayers[0]; windHdg = windLayer.Direction.ToString("000"); windSpd = windLayer.SpeedKnots.ToString("F0"); WiSpLabel.Text = "Wind Speed: " + windLayer.SpeedKnots.ToString("F0"); WiDiLabel.Text = "Wind Direction: " + windLayer.Direction.ToString("000"); } tmp = Convert.ToInt32(plnPitch); if (tmp >= 0) { PitchLabel.Text = "Pitch: " + tmp.ToString() + "▲"; } if (tmp < 0) { tmp = tmp * -1; PitchLabel.Text = "Pitch: " + tmp.ToString() + "▼"; } var plnBank = (double)roll.Value * 360 / 4294967296; var planebnk = ""; if (plnBank >= 0) { planebnk = Convert.ToInt32(plnBank).ToString() + "L"; } if (plnBank < 0) { planebnk = Convert.ToInt32(plnBank * -1).ToString() + "R"; } plnbnk = planebnk; BankLabel.Text = "Bank: " + planebnk; timer1.Interval = RefreshRate; } string onGroundText = this.onGround.Value > 0 ? "Y" : "N"; if (onGroundText == "Y") { checkGroundTime = 0; if (GlobalData.LoggedIn) { if (rptask) { checkBox1.Show(); rptask = false; } } if (!GlobalData.LoggedIn) { if (rptask) { checkBox1.Hide(); rptask = true; } } if (rptOnGround) { if (checkBox1.Checked) { SendData(fpm.ToString(), airspd, tmp.ToString(), plnbnk, windSpd, windHdg, ATCID, ATCTYPE); } rptOnGround = false; label8.Text = "Landed!"; ongrnd = true; fpmstringscore(fpm); if (Rate.Text != "") { LandingStats ls = new LandingStats(); ls.FPM = fpm.ToString(); ls.Speed = airspd; ls.Score = Rate.Text; ls.Roll = plnbnk; ls.Pitch = PitchLabel.Text.Replace("Pitch: ", ""); ls.WindSpeed = windSpd; ls.WindDirection = windHdg; LRMDatabase.AddStat(ls); } } } if (onGroundText == "N") { label8.Text = "Airborn"; ongrnd = false; rptOnGround = true; } } catch (FSUIPCException ex) { FSUIPCConnection.Close(); timer1.Enabled = false; GlobalData.ErrorLogInput(ex, "ERROR"); MessageBox.Show("Error, Cannot read game data: " + ex.Message + ", please Disconnect"); return; } } } else { checkGroundTime++; } }