private void dgView_LoadingRow(object sender, DataGridRowEventArgs e)
        {
            string    row = e.Row.Item.ToString().Substring(e.Row.Item.ToString().IndexOf("=") + 2, e.Row.Item.ToString().IndexOf(",") - e.Row.Item.ToString().IndexOf("=") - 2);
            int       _ID = int.Parse(row);
            Schedules _sc = Manager.db.Schedules.FirstOrDefault(n => n.ID == _ID);

            e.Row.Background = _sc.Confirmed ? new SolidColorBrush(Colors.White):new SolidColorBrush(Colors.Red);
        }
Beispiel #2
0
 public ShadulesEdit(String schedules, ManageFly window)
 {
     InitializeComponent();
     _window     = window;
     schedules   = schedules.Substring(schedules.IndexOf("=") + 2);
     _ID         = int.Parse(schedules.Substring(0, schedules.IndexOf(",")));
     _sc         = Manager.db.Schedules.FirstOrDefault(n => n.ID == _ID);
     DataContext = _sc;
 }
        private void FlightCancel_Click(object sender, RoutedEventArgs e)
        {
            if (dgView.SelectedItem == null)
            {
                return;
            }
            string    schedules = dgView.SelectedItem.ToString().Substring(dgView.SelectedItem.ToString().IndexOf("=") + 2, dgView.SelectedItem.ToString().IndexOf(",") - dgView.SelectedItem.ToString().IndexOf("=") - 2);
            int       _ID       = int.Parse(schedules);
            Schedules _sc       = Manager.db.Schedules.FirstOrDefault(n => n.ID == _ID);

            _sc.Confirmed = !_sc.Confirmed;
            Manager.db.SaveChanges();
        }
        private void ImportChangesButton_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog oFD = new OpenFileDialog();

            oFD.Title            = "Открытие файла";
            oFD.Filter           = "csv (*.csv)|*.csv|All files (*.*)|*.*";
            oFD.RestoreDirectory = true;
            if (oFD.ShowDialog() == true)
            {
                StreamReader fileIn     = new StreamReader(new FileStream(oFD.FileName.ToString(), FileMode.Open, FileAccess.Read));
                string[]     s          = fileIn.ReadToEnd().Split('\n');
                int          miss       = 0;
                int          duplicate  = 0;
                int          successful = 0;
                for (int i = 0; i < s.Length; i++)
                {
                    string[] q = s[i].Split(',');
                    if (q[0] == "ADD")
                    {
                        try
                        {
                            DateTime dateTime     = Convert.ToDateTime(q[1]);
                            string   flightNumber = q[3];
                            TimeSpan time         = new TimeSpan(Convert.ToDateTime(q[2]).Ticks % 864000000000);
                            if (Manager.db.Schedules.FirstOrDefault(n => dateTime == n.Date && n.Time == time && n.FlightNumber == flightNumber) != null)
                            {
                                DublicateTextBlock.Text = duplicate++.ToString();
                                goto Finish;
                            }
                            Schedules schedules = new Schedules();
                            schedules.Date         = dateTime;
                            schedules.Time         = time;
                            schedules.FlightNumber = flightNumber;
                            var    q1        = q[4].ToString();
                            var    q2        = q[5].ToString();
                            int    airports  = Manager.db.Airports.FirstOrDefault(n => n.IATACode == q1).ID;
                            int    airports1 = Manager.db.Airports.FirstOrDefault(n => n.IATACode == q2).ID;
                            Routes routes    = Manager.db.Routes.FirstOrDefault(n => n.DepartureAirportID == airports && n.ArrivalAirportID == airports1);
                            schedules.RouteID    = routes.ID;
                            schedules.AircraftID = Convert.ToInt32(q[6]);
                            q[7] = q[7].Substring(0, q[7].IndexOf('.'));
                            schedules.EconomyPrice = Convert.ToDecimal(q[7]);
                            schedules.Confirmed    = (q[8].Contains("OK"));
                            Manager.db.Schedules.Add(schedules);
                            SuccessfulTextBlock.Text = successful++.ToString();
                            Finish : { }
                        }
                        catch
                        {
                            miss++;
                        }
                    }
                    if (q[0] == "EDIT")
                    {
                        DateTime  dt        = Convert.ToDateTime(q[1]);
                        TimeSpan  ts        = new TimeSpan(Convert.ToDateTime(q[2]).Ticks % 864000000000);
                        Schedules schedules = Manager.db.Schedules.FirstOrDefault(n => n.Date == dt && n.Time == ts);
                        schedules.Confirmed = !schedules.Confirmed;
                    }
                }
                Manager.db.SaveChanges();
                RecordTextBlock.Text = miss.ToString();
                fileIn.Close();
            }
        }