Advertisement
Guest User

eh

a guest
Jan 10th, 2019
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 9.30 KB | None | 0 0
  1. namespace ProjectMovieThisIsIt
  2. {
  3.     public partial class LogIn : Form
  4.     {
  5.         public LogIn()
  6.         {
  7.             InitializeComponent();
  8.         }
  9.  
  10.         private void Logowanie_Click(object sender, EventArgs e)
  11.         {
  12.             SqlConnection con = new SqlConnection(@"Data Source = DESKTOP-MELB6US\SQLEXPRESS; Initial Catalog = movies; Integrated Security = True;");
  13.             con.Open();
  14.             SqlDataAdapter sda = new SqlDataAdapter("SELECT COUNT(*) FROM tableUser WHERE UserName='" + textusername.Text + "' AND Password='" + textpassword.Text + "'", con);
  15.             /* 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. */
  16.             DataTable dt = new DataTable(); //this is creating a virtual table  
  17.             sda.Fill(dt);
  18.  
  19.  
  20.             if (dt.Rows[0][0].ToString() == "1")
  21.             {
  22.                 User u1 = new User(textusername.Text, textpassword.Text);
  23.                 this.Close();
  24.                 new ListOfMovies().Show();
  25.             }
  26.             else
  27.                 MessageBox.Show("Niepoprawna nazwa użytkownika lub hasło");
  28.         }
  29.  
  30.         private void Exit_Click(object sender, EventArgs e)
  31.         {
  32.             this.Close();
  33.         }
  34.  
  35.         public string fo //dzięki temu w innych klasach moge używać textusername jak wywołam klase i tą metode
  36.         {
  37.             get { return textusername.Text; }
  38.             set { textusername.Text = value; }
  39.  
  40.         }
  41.  
  42.         public string fo1
  43.         {
  44.             get { return textpassword.Text; }
  45.             set { textpassword.Text = value; }
  46.  
  47.         }
  48.  
  49.     }
  50. }
  51.  
  52.  
  53. namespace ProjectMovieThisIsIt
  54. {
  55.     class User
  56.     {
  57.         string username;
  58.         string password;
  59.  
  60.  
  61.         public string Username { get => username; set => username = value; }
  62.         public string Password { get => password; set => password = value; }
  63.  
  64.  
  65.         public User(string username, string password)
  66.         {
  67.             Username = username;
  68.             Password = password;
  69.         }
  70. }}
  71.  
  72.  
  73. namespace ProjectMovieThisIsIt
  74. {
  75.     public partial class ListOfMovies : Form
  76.     {
  77.  
  78.         public ListOfMovies()
  79.         {
  80.             InitializeComponent();
  81.             CreateComponents();
  82.             PopulateData();
  83.             SetUpEventHandlers();
  84.         }
  85.  
  86.         private static bool selected;
  87.  
  88.         List<Movie> movies = new List<Movie>
  89.             {
  90.             new Movie(1, "Bękarty Wojny", 2009, "Quentinn Tarantino", 8.0, 313),
  91.             new Movie(2, "Pulp Fiction", 1994, "Quentinn Tarantino", 8.4, 204),
  92.             new Movie(3, "Batman : Początek", 2005, "Christopher Nolan", 7.6, 103),
  93.             new Movie(4, "Ojciec Chrzestny", 1972, "Francis Ford Coppola", 8.59, 400),
  94.             new Movie(5, "Skazani na Shawnshang", 1994, "Frank Darabont", 8.75, 678),
  95.             new Movie(6, "Zielona Mila", 1999, "Frank Darabont", 8.61, 123),
  96.             new Movie(7, "Forest Gump", 1994, "Robert Zemeckis", 8.52, 342),
  97.             new Movie(8, "Fantastyczna Czwórka", 2015, "Josh Trank", 4.8, 576),
  98.             new Movie(9, "Podziemny Krąg", 1999, "David Fincher", 9.26, 124),
  99.             new Movie(10, "Piękny Umysł", 2001, "Ron Howard", 8.24, 898),
  100.             new Movie(11, "Incepcja", 2010, "Christopher Nolan", 8.23, 356),
  101.             new Movie(12, "Milczenie Owiec", 1991, "Jonathan Demme", 8.21, 786),
  102.             new Movie(13, "Król Lew", 1994, "Rob Minkoff", 8.2, 521),
  103.             new Movie(14, "Django", 2012, "Quentinn Tarantino", 8.21, 765),
  104.             new Movie(15, "Leon Zawodowiec", 1994, "Luc Besson", 8.11, 637),
  105.             new Movie(16, "Gladiator", 2000, "Ridley Scott", 8.08, 357),
  106.             new Movie(17, "Prestiż", 2006, "Christopher Nolan", 8.06, 825),
  107.             new Movie(18, "Zaginiona Dziewczyna", 2014, "David Fincher", 7.8, 678),
  108.             new Movie(19, "Film o pszczołach", 2007, "Steve Hickner", 6.4, 167),
  109.             new Movie(20, "Zmierzch", 2008, "Catherina Hardwicke", 5.6, 846),
  110.             new Movie(21, "Mgła", 2007, "Frank Darabont", 5.8, 728),
  111.             new Movie(22, "Batman vs Superman : Świt Sprawiedliwości", 2016, "Zack Snyder", 5.9, 167),
  112.             new Movie(23, "Smoleńsk", 2016, "Antoni Krauze", 2.5, 748),
  113.             new Movie(24, "The Room", 2008, "Tommy Wiseau", 2.8, 903),
  114.             new Movie(25, "Dom Śmierci", 2003, "Uwe Boll", 2.7, 584),
  115.             new Movie(26, "50 Twarzy Greya", 2008, "Sam Taylor-Johnson", 4.5, 678)
  116.             };
  117.  
  118.  
  119.         private void PopulateData()
  120.         {
  121.             foreach (Movie m in movies)
  122.             {
  123.                 myListView.Items.Add(new ListViewItem(new[] { m.Name, m.Director, m.Year.ToString(), m.AvgRate.ToString(), m.NumberOfRates.ToString() }));
  124.             }
  125.         }
  126.  
  127.         private void SearchData(string searchTerm)
  128.         {
  129.             myListView.Items.Clear();
  130.             foreach (Movie m in movies)
  131.             {
  132.                 if (m.Name.ToLower().Contains(searchTerm.ToLower()) || m.Director.ToLower().Contains(searchTerm.ToLower()))
  133.                 {
  134.                     myListView.Items.Add(new ListViewItem(new[] { m.Name, m.Director, m.Year.ToString(), m.AvgRate.ToString(), m.NumberOfRates.ToString() }));
  135.                 }
  136.             }
  137.         }
  138.  
  139.         private void SetUpEventHandlers()
  140.         {
  141.             myListView.ItemSelectionChanged += MyListView_ItemSelectionChanged;
  142.             searchTxt.TextChanged += SearchTxt_TextChanged;
  143.  
  144.         }
  145.  
  146.  
  147.         private void MyListView_ItemSelectionChanged(object sender, ListViewItemSelectionChangedEventArgs e)
  148.         {
  149.             if (e.IsSelected)
  150.             {
  151.                 Choice.Text = "Wybrałeś film : ";
  152.                 label1.Text = "Tytuł : ";
  153.                 label2.Text = myListView.SelectedItems[0].SubItems[0].Text;
  154.                 label4.Text = "Reżyser : ";
  155.                 label3.Text = myListView.SelectedItems[0].SubItems[1].Text;
  156.                 label10.Text = "Rok : ";
  157.                 label9.Text = myListView.SelectedItems[0].SubItems[2].Text;
  158.                 label12.Text = "Ocena : ";
  159.                 label11.Text = myListView.SelectedItems[0].SubItems[3].Text;
  160.                 label6.Text = "Liczba głosów: ";
  161.                 label5.Text = myListView.SelectedItems[0].SubItems[4].Text;
  162.  
  163.  
  164.                 ThanksForVoting.Text = "";
  165.  
  166.                 myRatecomboBox.Visible = true;
  167.                 selected = true;
  168.             }
  169.             else
  170.             {
  171.                 selected = false;
  172.             }
  173.         }
  174.  
  175.  
  176.  
  177.         private void SearchTxt_TextChanged(object sender, EventArgs e)
  178.         {
  179.             SearchData(searchTxt.Text);
  180.         }
  181.  
  182.  
  183.  
  184.         private void CreateComponents()
  185.         {
  186.             LogIn f1 = new LogIn();
  187.             przywitanie.Text = "Witaj " + f1.fo;
  188.  
  189.         }
  190.  
  191.  
  192.  
  193.         //sortowanie
  194.         private void chooseSorting_SelectedIndexChanged(object sender, EventArgs e)
  195.         {
  196.             myListView.Sort();
  197.         }
  198.  
  199.  
  200.  
  201.  
  202.  
  203.  
  204.         //dodawanie oceny
  205.  
  206.  
  207.         /*double newAvg;
  208.         public double NewAvg { get => newAvg; set => newAvg = value; }
  209.        
  210.         public double AddRate(Movie movie)
  211.         {
  212.             movie.NumberOfRates++;
  213.             //NewAvg = (Convert.ToDouble(myListView.SelectedItems[0].SubItems[3].Text)*movie.NumberofRates + Convert.ToDouble(myRatecomboBox.SelectedItem)) / (Convert.ToDouble(movie.NumberOfRates) + 1.0);
  214.             NewAvg = (movie.AvgRate + Convert.ToDouble(myRatecomboBox.SelectedItem))/ (Convert.ToDouble(movie.NumberOfRates) + 1.0);
  215.             return NewAvg;
  216.         }*/
  217.  
  218.        
  219.         public double AddRate()
  220.         {
  221.             double a = Convert.ToDouble(myListView.SelectedItems[0].SubItems[3].Text);
  222.             double b = Convert.ToDouble(myListView.SelectedItems[0].SubItems[4].Text);
  223.             int bi = Convert.ToInt32(myListView.SelectedItems[0].SubItems[4].Text);
  224.             double c = Convert.ToDouble(myRatecomboBox.SelectedItem);
  225.             a = (a * b + c) / (b + 1.0);
  226.             return a;
  227.         }
  228.  
  229.         public int PlusPlus()
  230.         {
  231.             int bi = Convert.ToInt32(myListView.SelectedItems[0].SubItems[4].Text);
  232.             bi++;
  233.             return bi;
  234.  
  235.         }
  236.  
  237.         public int fi
  238.         {
  239.             get { return Convert.ToInt32(myRatecomboBox.SelectedItem); }
  240.             set { myRatecomboBox.SelectedItem = value; }
  241.  
  242.         }
  243.  
  244.         private void myRatecomboBox_SelectedIndexChanged(object sender, EventArgs e)
  245.         {
  246.             //myListView.SelectedItems[0].SubItems[3].Text = AddRate().ToString();
  247.             //myListView.SelectedItems[0].SubItems[4].Text = PlusPlus().ToString();
  248.             //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);
  249.             label11.Text = AddRate().ToString();
  250.             label5.Text = PlusPlus().ToString();
  251.             myRatecomboBox.Visible = false;
  252.             ThanksForVoting.Text = "Dziękujemy za oddanie głosu! ;) ";
  253.  
  254.         }
  255.  
  256.  
  257.  
  258.  
  259.         //IClonable i IComparable
  260.         //klasa abstrakcyjna
  261.     }
  262. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement