예제 #1
0
파일: Railway.cs 프로젝트: overdd/svpp-lab
        public static IEnumerable <Railway> GetAllRailways()
        {
            var        commandString = "SELECT Id, Name, TrainQuantity, RailwayLength, StaffNumber FROM [Table]";
            SqlCommand getAllCommand = new SqlCommand(commandString, connection);

            connection.Open();
            var reader = getAllCommand.ExecuteReader(); if (reader.HasRows)

            {
                while (reader.Read())
                {
                    var id            = reader.GetInt32(0);
                    var name          = reader.GetSqlString(1);
                    var trainQuantity = reader.GetInt32(2);
                    var railwayLength = reader.GetInt32(3);
                    var staffNumber   = reader.GetInt32(4);
                    var railway       = new Railway
                    {
                        Id            = id,
                        Name          = name.IsNull == true ? "No name" : name.Value,
                        TrainQuantity = trainQuantity,
                        RailwayLength = railwayLength,
                        StaffNumber   = staffNumber
                    };
                    yield return(railway);
                }
            }
            ;
            connection.Close();
        }
예제 #2
0
        private void ButtonDeleteClick(object sender, RoutedEventArgs e)
        {
            var result = MessageBox.Show("Are you sure?", "Deleting record...", MessageBoxButton.YesNo);

            if (result == MessageBoxResult.Yes)
            {
                Railway railway = dataGrid.SelectedItem as Railway;
                context.Railways.Remove(railway);
                context.SaveChanges();
            }
        }
예제 #3
0
        private void ButtonAddClick(object sender, RoutedEventArgs e)
        {
            var        railway = new Railway();
            EditWindow ew      = new EditWindow(railway);
            var        result  = ew.ShowDialog();

            if (result == true)
            {
                context.Zkhs.Add(railway);
                context.SaveChanges();
                ew.Close();
            }
        }
예제 #4
0
        private void ButtonEditClick(object sender, RoutedEventArgs e)
        {
            Railway    railway = dataGrid.SelectedItem as Railway;
            EditWindow ew      = new EditWindow(railway);
            var        result  = ew.ShowDialog();

            if (result == true)
            {
                context.SaveChanges();
                ew.Close();
            }
            else
            {
                context.Entry(railway).Reload();
                dataGrid.DataContext = null;
                dataGrid.DataContext = context.Zkhs.Local;
            }
        }
예제 #5
0
 public EditWindow(Railway railway) : this()
 {
     this.railway     = railway;
     grid.DataContext = railway;
 }