Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace ProjectMovieThisIsIt
- {
- public partial class LogIn : Form
- {
- public LogIn()
- {
- InitializeComponent();
- }
- private void Logowanie_Click(object sender, EventArgs e)
- {
- SqlConnection con = new SqlConnection(@"Data Source = DESKTOP-MELB6US\SQLEXPRESS; Initial Catalog = movies; Integrated Security = True;");
- con.Open();
- SqlDataAdapter sda = new SqlDataAdapter("SELECT COUNT(*) FROM tableUser WHERE UserName='" + textusername.Text + "' AND Password='" + textpassword.Text + "'", con);
- /* in above line the program is selecting the whole data from table and the matching it with the user name and password provided by user. */
- DataTable dt = new DataTable(); //this is creating a virtual table
- sda.Fill(dt);
- if (dt.Rows[0][0].ToString() == "1")
- {
- User u1 = new User(textusername.Text, textpassword.Text);
- this.Close();
- new ListOfMovies().Show();
- }
- else
- MessageBox.Show("Niepoprawna nazwa użytkownika lub hasło");
- }
- private void Exit_Click(object sender, EventArgs e)
- {
- this.Close();
- }
- public string fo //dzięki temu w innych klasach moge używać textusername jak wywołam klase i tą metode
- {
- get { return textusername.Text; }
- set { textusername.Text = value; }
- }
- public string fo1
- {
- get { return textpassword.Text; }
- set { textpassword.Text = value; }
- }
- }
- }
- namespace ProjectMovieThisIsIt
- {
- class User
- {
- string username;
- string password;
- public string Username { get => username; set => username = value; }
- public string Password { get => password; set => password = value; }
- public User(string username, string password)
- {
- Username = username;
- Password = password;
- }
- }}
- namespace ProjectMovieThisIsIt
- {
- public partial class ListOfMovies : Form
- {
- public ListOfMovies()
- {
- InitializeComponent();
- CreateComponents();
- PopulateData();
- SetUpEventHandlers();
- }
- private static bool selected;
- List<Movie> movies = new List<Movie>
- {
- new Movie(1, "Bękarty Wojny", 2009, "Quentinn Tarantino", 8.0, 313),
- new Movie(2, "Pulp Fiction", 1994, "Quentinn Tarantino", 8.4, 204),
- new Movie(3, "Batman : Początek", 2005, "Christopher Nolan", 7.6, 103),
- new Movie(4, "Ojciec Chrzestny", 1972, "Francis Ford Coppola", 8.59, 400),
- new Movie(5, "Skazani na Shawnshang", 1994, "Frank Darabont", 8.75, 678),
- new Movie(6, "Zielona Mila", 1999, "Frank Darabont", 8.61, 123),
- new Movie(7, "Forest Gump", 1994, "Robert Zemeckis", 8.52, 342),
- new Movie(8, "Fantastyczna Czwórka", 2015, "Josh Trank", 4.8, 576),
- new Movie(9, "Podziemny Krąg", 1999, "David Fincher", 9.26, 124),
- new Movie(10, "Piękny Umysł", 2001, "Ron Howard", 8.24, 898),
- new Movie(11, "Incepcja", 2010, "Christopher Nolan", 8.23, 356),
- new Movie(12, "Milczenie Owiec", 1991, "Jonathan Demme", 8.21, 786),
- new Movie(13, "Król Lew", 1994, "Rob Minkoff", 8.2, 521),
- new Movie(14, "Django", 2012, "Quentinn Tarantino", 8.21, 765),
- new Movie(15, "Leon Zawodowiec", 1994, "Luc Besson", 8.11, 637),
- new Movie(16, "Gladiator", 2000, "Ridley Scott", 8.08, 357),
- new Movie(17, "Prestiż", 2006, "Christopher Nolan", 8.06, 825),
- new Movie(18, "Zaginiona Dziewczyna", 2014, "David Fincher", 7.8, 678),
- new Movie(19, "Film o pszczołach", 2007, "Steve Hickner", 6.4, 167),
- new Movie(20, "Zmierzch", 2008, "Catherina Hardwicke", 5.6, 846),
- new Movie(21, "Mgła", 2007, "Frank Darabont", 5.8, 728),
- new Movie(22, "Batman vs Superman : Świt Sprawiedliwości", 2016, "Zack Snyder", 5.9, 167),
- new Movie(23, "Smoleńsk", 2016, "Antoni Krauze", 2.5, 748),
- new Movie(24, "The Room", 2008, "Tommy Wiseau", 2.8, 903),
- new Movie(25, "Dom Śmierci", 2003, "Uwe Boll", 2.7, 584),
- new Movie(26, "50 Twarzy Greya", 2008, "Sam Taylor-Johnson", 4.5, 678)
- };
- private void PopulateData()
- {
- foreach (Movie m in movies)
- {
- myListView.Items.Add(new ListViewItem(new[] { m.Name, m.Director, m.Year.ToString(), m.AvgRate.ToString(), m.NumberOfRates.ToString() }));
- }
- }
- private void SearchData(string searchTerm)
- {
- myListView.Items.Clear();
- foreach (Movie m in movies)
- {
- if (m.Name.ToLower().Contains(searchTerm.ToLower()) || m.Director.ToLower().Contains(searchTerm.ToLower()))
- {
- myListView.Items.Add(new ListViewItem(new[] { m.Name, m.Director, m.Year.ToString(), m.AvgRate.ToString(), m.NumberOfRates.ToString() }));
- }
- }
- }
- private void SetUpEventHandlers()
- {
- myListView.ItemSelectionChanged += MyListView_ItemSelectionChanged;
- searchTxt.TextChanged += SearchTxt_TextChanged;
- }
- private void MyListView_ItemSelectionChanged(object sender, ListViewItemSelectionChangedEventArgs e)
- {
- if (e.IsSelected)
- {
- Choice.Text = "Wybrałeś film : ";
- label1.Text = "Tytuł : ";
- label2.Text = myListView.SelectedItems[0].SubItems[0].Text;
- label4.Text = "Reżyser : ";
- label3.Text = myListView.SelectedItems[0].SubItems[1].Text;
- label10.Text = "Rok : ";
- label9.Text = myListView.SelectedItems[0].SubItems[2].Text;
- label12.Text = "Ocena : ";
- label11.Text = myListView.SelectedItems[0].SubItems[3].Text;
- label6.Text = "Liczba głosów: ";
- label5.Text = myListView.SelectedItems[0].SubItems[4].Text;
- ThanksForVoting.Text = "";
- myRatecomboBox.Visible = true;
- selected = true;
- }
- else
- {
- selected = false;
- }
- }
- private void SearchTxt_TextChanged(object sender, EventArgs e)
- {
- SearchData(searchTxt.Text);
- }
- private void CreateComponents()
- {
- LogIn f1 = new LogIn();
- przywitanie.Text = "Witaj " + f1.fo;
- }
- //sortowanie
- private void chooseSorting_SelectedIndexChanged(object sender, EventArgs e)
- {
- myListView.Sort();
- }
- //dodawanie oceny
- /*double newAvg;
- public double NewAvg { get => newAvg; set => newAvg = value; }
- public double AddRate(Movie movie)
- {
- movie.NumberOfRates++;
- //NewAvg = (Convert.ToDouble(myListView.SelectedItems[0].SubItems[3].Text)*movie.NumberofRates + Convert.ToDouble(myRatecomboBox.SelectedItem)) / (Convert.ToDouble(movie.NumberOfRates) + 1.0);
- NewAvg = (movie.AvgRate + Convert.ToDouble(myRatecomboBox.SelectedItem))/ (Convert.ToDouble(movie.NumberOfRates) + 1.0);
- return NewAvg;
- }*/
- public double AddRate()
- {
- double a = Convert.ToDouble(myListView.SelectedItems[0].SubItems[3].Text);
- double b = Convert.ToDouble(myListView.SelectedItems[0].SubItems[4].Text);
- int bi = Convert.ToInt32(myListView.SelectedItems[0].SubItems[4].Text);
- double c = Convert.ToDouble(myRatecomboBox.SelectedItem);
- a = (a * b + c) / (b + 1.0);
- return a;
- }
- public int PlusPlus()
- {
- int bi = Convert.ToInt32(myListView.SelectedItems[0].SubItems[4].Text);
- bi++;
- return bi;
- }
- public int fi
- {
- get { return Convert.ToInt32(myRatecomboBox.SelectedItem); }
- set { myRatecomboBox.SelectedItem = value; }
- }
- private void myRatecomboBox_SelectedIndexChanged(object sender, EventArgs e)
- {
- //myListView.SelectedItems[0].SubItems[3].Text = AddRate().ToString();
- //myListView.SelectedItems[0].SubItems[4].Text = PlusPlus().ToString();
- //myListView.SelectedItems[0].SubItems[3].Text = (Convert.ToDouble(myListView.SelectedItems[0].SubItems[3].Text)*Convert.ToDouble(myListView.SelectedItems[0].SubItems[4].Text) + Convert.ToDouble(myRatecomboBox.SelectedItem)) / (Convert.ToDouble(myListView.SelectedItems[0].SubItems[4].Text) + 1.0);
- label11.Text = AddRate().ToString();
- label5.Text = PlusPlus().ToString();
- myRatecomboBox.Visible = false;
- ThanksForVoting.Text = "Dziękujemy za oddanie głosu! ;) ";
- }
- //IClonable i IComparable
- //klasa abstrakcyjna
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement