private void BindGrid() { using (var context = new IMDBEntities()) { var imdb = new IMDBEntities(); var aux = from c in imdb.Filmes orderby c.ID_Film select new { c.ID_Film, c.Nume, c.Nota }; dataGridViewTOP.DataSource = aux.ToList(); //DataColumn note = new DataColumn("YourRating",typeof(int),"0"); // DataTable dt = new DataTable(); // dt.Columns.Add("Nota", typeof(System.Int32), "0"); //DataGridViewColumn dgvc = new DataGridViewColumn(); //dgvc.HeaderText = "YourRatings"; //dataGridViewTOP.Columns.Add(dgvc); //for (int i = 0; i < dataGridViewTOP.RowCount; i++) //{ // dataGridViewTOP.Rows.Add(new object[] { '0' } ); //} } }
private void labelLog_Click(object sender, EventArgs e) { using (var context = new IMDBEntities()) { var result = (from c in context.Users where c.Username.Equals(TextBoxUsername.Text) select c).FirstOrDefault(); if (result != null) { if (result.Rights.Contains("admin")) { AdminOrUser aou = new AdminOrUser(TextBoxUsername.Text, this); aou.Show(); } else { UserPage up = new UserPage(result.Username, this); up.Show(); } SoundPlayer log = new SoundPlayer(@"C:\Users\Mosu\Desktop\proiect_utile\sound.wav"); log.Play(); } else { SystemSounds.Exclamation.Play(); MessageBox.Show("The password or username aren't correct!"); } } }
private void SearchByGender() { clear_datagridview(); using (var context = new IMDBEntities()) { var resultsearchgender = from r in context.Genuris where r.Nume_Gen.Contains(MemberField) select new { r.Nume_Gen }; MemberFieldOption = "Gender"; dataGridViewUniversal.DataSource = resultsearchgender.ToList(); } }
private void UserPage_Load(object sender, EventArgs e) { using (var context = new IMDBEntities()) { var result = (from c in context.Users where c.Username.Equals(MemberUserName) select c).First(); labelRegister.Text += " " + result.DateofRegister.Value.ToShortDateString(); labelRights.Text += " " + result.Rights.ToString(); if (result.Rights.Contains("admin")) { labelGOTOADMINMODE.Visible = true; } } }
private void BindGrid() { using (var context = new IMDBEntities()) { var imdb = new IMDBEntities(); var aux = from c in imdb.Filmes orderby c.ID_Film select new { c.ID_Film, c.Nume, c.Nota }; dataGridViewTOP.DataSource = aux.ToList(); } }
private void SearchByTvSeriesBind() { clear_datagridview(); using (var context = new IMDBEntities()) { var resultsearchtvseries = from b in context.Seriales where b.Nume.Contains(MemberField) select new { b.ID_Serial, b.Nume }; MemberFieldOption = "TVSeries"; dataGridViewUniversal.DataSource = resultsearchtvseries.ToList(); } }
private void SearchByMoviesBind() { clear_datagridview(); using (var context = new IMDBEntities()) { var resultsearchmovies = from a in context.Filmes where a.Nume.Contains(MemberField) select new { a.ID_Film, a.Nume }; MemberFieldOption = "Movies"; dataGridViewUniversal.DataSource = resultsearchmovies.ToList(); } }
private void BindByTop(int limit) //gandeste-te la most popular bagi filme in aceeasi tabela dar de la id 101 { using (var context = new IMDBEntities()) { var results = from movies in context.Filmes where movies.ID_Film < limit orderby movies.Nota descending, movies.ID_Film select new { movies.ID_Film, movies.Nume, movies.Nota }; dataGridViewUniversal.DataSource = results.ToList(); } }
private void BindByTopTVSeries(int limit) { using (var context = new IMDBEntities()) { var results = from tvseries in context.Seriales where tvseries.ID_Serial <= limit orderby tvseries.Nota descending, tvseries.ID_Serial select new { tvseries.ID_Serial, tvseries.Nume, tvseries.Nota }; dataGridViewUniversal.DataSource = results.ToList(); } }
private void watchlistToolStripMenuItem_Click(object sender, EventArgs e) { int id; using (var con = new IMDBEntities()) { var result = (from a in con.Users where a.Username.Contains(MemberUserName) select a).First(); id = result.ID_User; } AdminOrUser aou = new AdminOrUser(MemberUserName, this, id, "Watchlist"); aou.Show(); this.Hide(); }
private void pictureBoxAscending_Click(object sender, EventArgs e) { using (var context = new IMDBEntities()) { if (MemberFieldOption.Equals("Movies")) { if (SearchBy.Text.Equals("ID")) { var resultsortascid = from a in context.Filmes orderby a.ID_Film ascending select new { a.ID_Film, a.Nume, a.Nota }; } } //else if (MemberFieldOption.Equals("TVSeries")) //{ // MoviePage mp = new MoviePage(dataGridViewUniversal.Rows[e.RowIndex].Cells[1].Value.ToString(), this, "TVSeries"); // mp.Show(); // this.Hide(); //} //else if (MemberFieldOption.Equals("News")) //{ // string text = File.ReadAllText(paths[e.RowIndex]); // NewsPage np = new NewsPage(dataGridViewUniversal.Rows[e.RowIndex].Cells[0].Value.ToString(), text); // np.Show(); //} //else if (MemberFieldOption.Equals("Actors")) //{ // ActorsOrDirectorsPage aodp = new ActorsOrDirectorsPage(this, "Actor", dataGridViewUniversal.Rows[e.RowIndex].Cells[2].Value.ToString(), dataGridViewUniversal.Rows[e.RowIndex].Cells[1].Value.ToString()); // aodp.Show(); // this.Hide(); //} //else if (MemberFieldOption.Equals("Directors")) //{ // ActorsOrDirectorsPage aodp = new ActorsOrDirectorsPage(this, "Regizor", dataGridViewUniversal.Rows[e.RowIndex].Cells[2].Value.ToString(), dataGridViewUniversal.Rows[e.RowIndex].Cells[1].Value.ToString()); // aodp.Show(); // this.Hide(); //} //else if (MemberFieldOption.Equals("Gender")) //{ // BindByGender(dataGridViewUniversal.Rows[e.RowIndex].Cells[0].Value.ToString()); //} } }
private void BindbyAllActors() { clear_datagridview(); MemberFieldOption = "Actors"; using (var context = new IMDBEntities()) { var results = from a in context.Actoris select new { a.ID_Actor, a.Nume, a.Prenume }; dataGridViewUniversal.DataSource = results.ToList(); } }
private void SearchByActors() { clear_datagridview(); using (var context = new IMDBEntities()) { var resultsearchactors = from c in context.Actoris where c.Nume.Contains(MemberField) || c.Prenume.Equals(MemberField) select new { c.ID_Actor, c.Nume, c.Prenume }; MemberFieldOption = "Actors"; dataGridViewUniversal.DataSource = resultsearchactors.ToList(); } }
private void pictureBoxWatchlistFilled_Click(object sender, EventArgs e) //asta e de fapt empty { using (var context = new IMDBEntities()) { if (MemberMovieOrTvSeries.Equals("Movie")) { var resultuserid = (from a in context.Users where a.Username.Equals(MemberUserName) select a).First(); var resultfilmid = (from c in context.Filmes where c.Nume.Equals(MemberMovieName) select c).First(); var addWatch = new WatchList() { ID_User = resultuserid.ID_User, ID_Film = resultfilmid.ID_Film, Watched = 1 }; context.WatchLists.Add(addWatch); context.SaveChanges(); pictureBoxWatchlistFilled.Visible = false; //butoanele sunt inversate ca si denumire pictureBoxWatchlistEmpty.Visible = true; MessageBox.Show("Filmul " + MemberMovieName + " a fost adaugat in watchlist!"); } else { var resultuserid = (from a in context.Users where a.Username.Equals(MemberUserName) select a).First(); var resultfilmid = (from c in context.Seriales where c.Nume.Equals(MemberMovieName) select c).First(); var addWatch = new WatchlistSeriale() { ID_User = resultuserid.ID_User, ID_Serial = resultfilmid.ID_Serial, Watched = 1 }; context.WatchlistSeriales.Add(addWatch); context.SaveChanges(); pictureBoxWatchlistFilled.Visible = false; //butoanele sunt inversate ca si denumire pictureBoxWatchlistEmpty.Visible = true; MessageBox.Show("Serialul " + MemberMovieName + " a fost adaugat in watchlist!"); } } }
public UserPage(string UserName, Form startpage) { InitializeComponent(); labelUsername.Text = UserName; MemberUserName = UserName; ParentPageUserPage = startpage; using (var context = new IMDBEntities()) { var res = (from a in context.Users where a.Username.Equals(UserName) select new { a.ID_User }).First(); MemberUserID = res.ID_User; } }
private void SearchByDirectors() { clear_datagridview(); using (var context = new IMDBEntities()) { var resultsearchdirectors = from d in context.Regizoris where d.Nume.Contains(MemberField) || d.Prenume.Equals(MemberField) select new { d.ID_Regizor, d.Nume, d.Prenume }; MemberFieldOption = "Directors"; dataGridViewUniversal.DataSource = resultsearchdirectors.ToList(); } }
private void BindByTopTVSeries() { clear_datagridview(); MemberFieldOption = "TVSeries"; using (var context = new IMDBEntities()) { var results = from tvseries in context.Seriales orderby tvseries.Nota descending, tvseries.ID_Serial select new { tvseries.ID_Serial, tvseries.Nume, tvseries.Nota }; dataGridViewUniversal.DataSource = results.ToList(); } }
private void pictureBoxAscending_Click(object sender, EventArgs e) { pictureBoxDescending.Visible = true; pictureBoxAscending.Visible = false; using (var context = new IMDBEntities()) { var imdb = new IMDBEntities(); var aux = from c in imdb.Filmes orderby c.ID_Film ascending select new { c.ID_Film, c.Nume, c.Nota }; dataGridViewTOP.DataSource = aux.ToList(); } }
private void labelLog_Click(object sender, EventArgs e) { using (var context = new IMDBEntities()) { var result = (from c in context.Users where c.Username.Equals(TextBoxUsername.Text) select c).FirstOrDefault(); if (result != null) { string parola = result.Password; parola = parola.Replace(" ", string.Empty); string parola2 = CalculateMD5Hash(TextBoxPassword.Text); if (!parola2.Equals(parola)) { MessageBox.Show("The password isn't correct!", "Sign in Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { if (result.Rights.Contains("admin")) { AdminOrUser aou = new AdminOrUser(TextBoxUsername.Text, this); aou.Show(); } else { UserPage up = new UserPage(result.Username, this); up.Show(); } SoundPlayer log = new SoundPlayer(@"C:\Users\Mosu\Desktop\proiect_utile\sound.wav"); log.Play(); TextBoxUsername.Text = ""; TextBoxPassword.Text = ""; } } else { SystemSounds.Exclamation.Play(); MessageBox.Show("The password or username isn't correct!"); } } }
public void schimba_parole() { using (var context = new IMDBEntities()) { var users = (from a in context.Users where a.ID_User == 2 select a).First(); //// int count = users.Count(); // // var item = users.ToList(); // //for(int i= 0;i<count;i++) // //{ // item[i].Password = CalculateMD5Hash(item[i].Password); // } users.Password = CalculateMD5Hash(users.Password); context.SaveChanges(); } }
private void BindByBornToday() { MemberFieldOption = "Actors"; //if (dataGridViewUniversal.Columns.Count != 0) //{ remove_column(); } clear_datagridview(); using (var context = new IMDBEntities()) { var query = context.WhoIsBornToday(DateTime.Now); var res = from a in query select new { a.ID_Actor, a.Prenume, a.Nume }; dataGridViewUniversal.DataSource = res.ToList(); } }
private void StartOwnTransactionWithinContext() { using (var context = new IMDBEntities()) { using (var dbContextTransaction = context.Database.BeginTransaction()) { try { if (verify(textBoxUserName.Text, textBoxEmail.Text, textBoxPhoneNR.Text).Equals("OK")) { var newUser = new User { Username = textBoxUserName.Text, Password = CalculateMD5Hash(textBoxPassword.Text), E_mail = textBoxEmail.Text, PhoneNumber = textBoxPhoneNR.Text, Rights = "user", DateofRegister = DateTime.Now }; context.Users.Add(newUser); } else { MessageBox.Show(verify(textBoxUserName.Text, textBoxEmail.Text, textBoxPhoneNR.Text)); } context.SaveChanges(); dbContextTransaction.Commit(); MessageBox.Show("Welcome to our site!"); } catch (Exception) { Console.WriteLine("Nu exista nume!!!"); dbContextTransaction.Rollback(); } } } }
private void BindByMostPopularMovies(int limitleft) { clear_datagridview(); MemberFieldOption = "Movies"; //if (dataGridViewUniversal.Columns.Count != 0) //{ remove_column(); } using (var context = new IMDBEntities()) { var results = from movies in context.Filmes where movies.ID_Film > limitleft - 1 || (movies.ID_Film < limitleft && movies.An_aparitie > 2016) orderby movies.Nota descending, movies.ID_Film select new { movies.ID_Film, movies.Nume, movies.An_aparitie, movies.Nota }; dataGridViewUniversal.DataSource = results.ToList(); } }
private void button2_Click(object sender, EventArgs e) //pt creare cont { if (verify(textBoxUserName.Text, textBoxEmail.Text, textBoxPhoneNR.Text).Equals("OK")) { var context = new IMDBEntities(); var newUser = new User { Username = textBoxUserName.Text, Password = textBoxPassword.Text, E_mail = textBoxEmail.Text, PhoneNumber = textBoxPhoneNR.Text, Rights = "user" }; context.Users.Add(newUser); context.SaveChanges(); MessageBox.Show("Welcome to our site!"); } else { MessageBox.Show(verify(textBoxUserName.Text, textBoxEmail.Text, textBoxPhoneNR.Text)); } }
private void BindByMostPopularTVSeries() { clear_datagridview(); MemberFieldOption = "Movies"; if (dataGridViewUniversal.Columns.Count != 0) { remove_column(); } using (var context = new IMDBEntities()) { var results = from movies in context.Seriales where movies.An_aparitie > 2013 orderby movies.Nota descending, movies.ID_Serial select new { movies.ID_Serial, movies.Nume, movies.An_aparitie, movies.Nota }; dataGridViewUniversal.DataSource = results.ToList(); } }
private void BindByMostPopularCelebs() { clear_datagridview(); MemberFieldOption = "Actors"; using (var context = new IMDBEntities()) { var results = from a in context.Actoris join b in context.Relatie_actor_film on a.ID_Actor equals b.ID_Actor join c in context.Filmes on b.ID_Film equals c.ID_Film where c.An_aparitie > 2016 select new { a.ID_Actor, a.Nume, a.Prenume }; dataGridViewUniversal.DataSource = results.Distinct().ToList(); } }
private void UserPage_Load(object sender, EventArgs e) { using (var context = new IMDBEntities()) { var result = (from c in context.Users where c.Username.Equals(MemberUserName) select c).First(); labelRegister.Text += " " + result.DateofRegister.Value.ToShortDateString(); labelRights.Text += " " + result.Rights.ToString(); try { pictureBoxUser.Image = ConvertByteToImage(result.Photo); } catch { MessageBox.Show("Can't load this user's photo!", "ErrorPhoto"); } if (result.Rights.Contains("admin")) { labelGOTOADMINMODE.Visible = true; } } }
private void SearchPictureBox_Click(object sender, EventArgs e) { if (textBox1.Text.Equals("")) { MessageBox.Show("Please enter a keyword for search!", "InfoMessage"); } else { using (var context = new IMDBEntities()) { var ResultMovies = (from rmov in context.Filmes where rmov.Nume.Contains(textBox1.Text) select rmov).FirstOrDefault(); var ResultTVSeries = (from rtv in context.Seriales where rtv.Nume.Contains(textBox1.Text) select rtv).FirstOrDefault(); var ResultActors = (from ra in context.Actoris where ra.Nume.Contains(textBox1.Text) || ra.Prenume.Equals(textBox1.Text) select ra).FirstOrDefault(); var ResultDirectors = (from rd in context.Regizoris where rd.Nume.Contains(textBox1.Text) || rd.Prenume.Equals(textBox1.Text) select rd).FirstOrDefault(); var ResultGender = (from rg in context.Genuris where rg.Nume_Gen.Contains(textBox1.Text) select rg).FirstOrDefault(); if (SearchBy.Text.Equals("Movies")) { if (ResultMovies != null) { UniversalPage searchbymovies = new UniversalPage("SearchByMovies", textBox1.Text, this); searchbymovies.Show(); this.Hide(); } else { MessageBox.Show("Nu exista nici o inregistrare care sa corespunda textului introdus!"); } } else if (SearchBy.Text.Equals("TV Series")) { if (ResultTVSeries != null) { UniversalPage searchbytvseries = new UniversalPage("SearchByTVSeries", textBox1.Text, this); searchbytvseries.Show(); this.Hide(); } else { MessageBox.Show("Nu exista nici o inregistrare care sa corepunda textului introdus!"); } } else if (SearchBy.Text.Equals("Actors")) { if (ResultActors != null) { UniversalPage searchbyactors = new UniversalPage("SearchByActors", textBox1.Text, this); searchbyactors.Show(); this.Hide(); } else { MessageBox.Show("Nu exista nici o inregistrare care sa corepunda textului introdus!"); } } else if (SearchBy.Text.Equals("Directors")) { if (ResultDirectors != null) { UniversalPage searchbydirectors = new UniversalPage("SearchByDirectors", textBox1.Text, this); searchbydirectors.Show(); this.Hide(); } else { MessageBox.Show("Nu exista nici o inregistrare care sa corepunda textului introdus!"); } } else if (SearchBy.Text.Equals("Gender")) { if (ResultGender != null) { UniversalPage searchbygender = new UniversalPage("SearchByGender", textBox1.Text, this); searchbygender.Show(); this.Hide(); } else { MessageBox.Show("Nu exista nici o inregistrare care sa corepunda textului introdus!"); } } } } }
private void buttonSalveaza_Click(object sender, EventArgs e) { try { if (!comboBoxTable.Text.Equals("Alege o tabela...")) { int lengthtext = textBoxID.TextLength; string digit = "0123456789"; for (int i = 0; i < lengthtext; i++) { if (!digit.Contains(textBoxID.Text[i])) { lengthtext = 0; } } if (lengthtext != 0) { using (IMDBEntities context = new IMDBEntities()) { if (comboBoxTable.Text.Equals("Actori")) { int x = Convert.ToInt32(textBoxID.Text); var result = (from b in context.Actoris where b.ID_Actor.Equals(x) select b).First(); if (result != null) { result.Photo = ConvertFiletoByte(this.pictureBoxPhoto.ImageLocation); context.SaveChanges(); MessageBox.Show("Fotografie adaugata cu succes!"); } else { MessageBox.Show("Acest Id nu apartine nici unei inregistrari!"); } } else if (comboBoxTable.Text.Equals("Filme")) { int x = Convert.ToInt32(textBoxID.Text); var result = (from b in context.Filmes where b.ID_Film.Equals(x) select b).First(); if (result != null) { result.Photo = ConvertFiletoByte(this.pictureBoxPhoto.ImageLocation); context.SaveChanges(); MessageBox.Show("Fotografie adaugata cu succes!"); } else { MessageBox.Show("Acest Id nu apartine nici unei inregistrari!"); } } else if (comboBoxTable.Text.Equals("Regizori")) { int x = Convert.ToInt32(textBoxID.Text); var result = (from b in context.Regizoris where b.ID_Regizor.Equals(x) select b).First(); if (result != null) { result.Photo = ConvertFiletoByte(this.pictureBoxPhoto.ImageLocation); context.SaveChanges(); MessageBox.Show("Fotografie adaugata cu succes!"); } else { MessageBox.Show("Acest Id nu apartine nici unei inregistrari!"); } } else if (comboBoxTable.Text.Equals("Seriale")) { int x = Convert.ToInt32(textBoxID.Text); var result = (from b in context.Seriales where b.ID_Serial.Equals(x) select b).First(); if (result != null) { result.Photo = ConvertFiletoByte(this.pictureBoxPhoto.ImageLocation); context.SaveChanges(); MessageBox.Show("Fotografie adaugata cu succes!"); } else { MessageBox.Show("Acest Id nu apartine nici unei inregistrari!"); } } else if (comboBoxTable.Text.Equals("Users")) { int x = Convert.ToInt32(textBoxID.Text); var result = (from b in context.Users where b.ID_User.Equals(x) select b).First(); if (result != null) { result.Photo = ConvertFiletoByte(this.pictureBoxPhoto.ImageLocation); context.SaveChanges(); MessageBox.Show("Fotografie adaugata cu succes!"); } else { MessageBox.Show("Acest Id nu apartine nici unei inregistrari!"); } } } } else { MessageBox.Show("Please insert correct ID!"); } } else { MessageBox.Show("Selecteaza o tabela!"); } } catch { MessageBox.Show("Can't add this file in " + comboBoxTable.Text + " table!"); } }
private string verify(string username, string email, string phonenumeber) { if (!textBoxUserName.Text.Equals("")) { if (!textBoxPassword.Text.Equals("")) { if (!textBoxReEnterPass.Text.Equals("")) { if (!textBoxPhoneNR.Text.Equals("")) { if (textBoxPhoneNR.Text.Length != 10) { return("Please enter a correct number phone!"); } if (!textBoxEmail.Text.Equals("")) { if (!textBoxEmail.Text.Contains("@")) { return("Please introduce a valid E-mail"); } } else { return("Please enter an E-mail address"); } } else { return("Please enter a phone number"); } } else { return("Please re-enter the password"); } } else { return("Please enter a password"); } } else { return("Please enter an username"); } using (var context = new IMDBEntities()) { var resultname = (from a in context.Users where a.Username.Equals(username) select a).FirstOrDefault(); var resultemail = (from b in context.Users where b.E_mail.Equals(email) select b).FirstOrDefault(); var resultphonenumber = (from c in context.Users where c.PhoneNumber.Equals(phonenumeber) select c).FirstOrDefault(); if (resultname != null) { return("Users exists in our database. Please try other username"); } if (resultemail != null) { return("E-mail is already used! Please try another E-mail address"); } if (resultphonenumber != null) { return("Phone number is already used! Please try another phonenumber"); } if (!textBoxPassword.Text.Equals(textBoxReEnterPass.Text)) { return("The content from password field and re-enter password field are not the same! Please try re-type password"); } } return("OK"); }