Referring to one of my last questions. I need for my WPF application to Auto-Calculate the Age of the movie based off of the release date, and the current date. This is one area that I personally have no experience with. I would assume it would have something to do with DateTime and CurrentDate. Any suggestions?
My WPF has a Movie class which contains:
namespace FinalExam
{
public class Movie
{
public string movieName { get; set; }
public DateTime releaseDate { get; set; }
public DateTime movieAge { get; set; }
public string onDVD { get; set; }
public string onBluRay { get; set; }
public string genreType { get; set; }
public string directorName { get; set; }
public string producerName { get; set; }
public int movieLength { get; set; }
public string moveRating { get; set; }
}
}
MovieUtility class which contains:
namespace FinalExam
{
public static class MovieUtility
{
public static bool isItDate(string dateString)
{
DateTime date;
bool isDate;
isDate = DateTime.TryParse(dateString, out date);
return isDate;
}
public static DateTime ConvertStringToDate(string dateString)
{
DateTime date;
DateTime.TryParse(dateString, out date);
return date;
}
}
}
And the MainWindow.xaml which is where the user will input the data and a datagrid will display it, and last, the MainWindow.xaml.cs which is where all of the strings are called and the data will be added the the List.
namespace FinalExam
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
//GLOBAL VARIABLE AREA
List<Movie> movieList = new List<Movie>();
public MainWindow()
{
InitializeComponent();
}
private void but_Submit_Click(object sender, RoutedEventArgs e)
{
bool isGoodToAddNewMovie = true;
Movie newMovie = new Movie();
newMovie.movieName = txtBox_MovieName.Text;
newMovie.onDVD = txtBox_DVD.Text;
newMovie.onBluRay = txtBox_BluRay.Text;
newMovie.genreType = txtBox_Genre.Text;
newMovie.directorName = txtBox_Director.Text;
newMovie.producerName = txtBox_Producer.Text;
newMovie.moveRating = txtBox_Rating.Text;
if (MovieUtility.isItDate(txtBox_ReleaseDate.Text))
{
newMovie.releaseDate = MovieUtility.ConvertStringToDate(txtBox_ReleaseDate.Text);
txtBox_ReleaseDate.Background = new SolidColorBrush(Colors.LightGray);
}
else
{
txtBox_ReleaseDate.Background = new SolidColorBrush(Colors.Red);
isGoodToAddNewMovie = false;
}
int length;
if (int.TryParse(txtBox_Length.Text, out length))
{
newMovie.movieLength = length;
txtBox_Length.Background = new SolidColorBrush(Colors.LightGray);
}
else
{
txtBox_Length.Background = new SolidColorBrush(Colors.Red);
MessageBox.Show("Please enter movie length in minutes.");
isGoodToAddNewMovie = false;
}
//ADD PERSON TO LIST
if (isGoodToAddNewMovie)
{
movieList.Add(newMovie);
dataGrid_Movies.ItemsSource = new List<Movie>(movieList);
}
}
}
}
So how would I go about Auto-Calculating the Age of the movie based on release date and have it automatically put the age of the movie into the DataGrid on the Window.