public static AirCompany RestoreDates(AirCompany company) { //JsonSerializer serializer = new JsonSerializer(); //using (StreamReader In = new StreamReader(Constants.path)) //using(JsonReader jsr = new JsonTextReader(In)) StreamReader In; try { In = new StreamReader(Constants.path); for (string s = In.ReadLine(); s != null; s = In.ReadLine()) { flight f = JsonConvert.DeserializeObject <flight>(s); if (f.typeOfPlane.Equals(Constants.typeOfPlaneIsCargo)) { company.AddCargoFlight(Convert.ToInt32(f.flightNumber), Convert.ToDouble(f.curbWeight) - Constants.emptyWeightOfCargoPlane, f.names); } if (f.typeOfPlane.Equals(Constants.typeOfPlaneIsPassenger)) { company.AddPassengerFlight(Convert.ToInt32(f.flightNumber), (int)((Convert.ToDouble(f.curbWeight) - Constants.emptyWeightOfPassengerPlane) / Constants.averagePassengerWeight), f.names); } } In.Close(); } catch { return(company); } return(company); }
private void Bt_add_Click(object sender, RoutedEventArgs e) { WindowAdd wndAdd = new WindowAdd(company); wndAdd.ShowDialog(); company = wndAdd.GetCompany(); ShowTable(); }
public MainWindow() { InitializeComponent(); company = new AirCompany(); GetDates(); ShowTable(); Closing += Window_Closed; }
public WindowAdd(AirCompany company) { InitializeComponent(); Bt_next.IsEnabled = false; Txt_type.Visibility = Visibility.Visible; TypeList.Visibility = Visibility.Visible; this.company = company; }
private void Bt_Clear_Click(object sender, RoutedEventArgs e) { MessageBoxResult res = MessageBox.Show(Constants.msgClearingList, Constants.headerClearingList, MessageBoxButton.YesNo); if (res == MessageBoxResult.No) { return; } company = new AirCompany(); ShowTable(); AirCompany.WriteFile(company); }
public static void WriteFile(AirCompany company) { StreamWriter Out; try { Out = new StreamWriter(Constants.path); Out.Write(""); for (int i = 0; i < company.GetCountOfFlights(); i++) { flight f = company.GetFlight(i); Out.WriteLine(JsonConvert.SerializeObject(f)); } Out.Close(); } catch { return; } }
private void Window_Closed(object sender, EventArgs e) { AirCompany.WriteFile(company); }
private void GetDates() { company = AirCompany.RestoreDates(company); }