private void button1_Click(object sender, EventArgs e) { try { using (var db = new BibliotecaEntities()) { if (String.IsNullOrEmpty(username.Text) || String.IsNullOrEmpty(password.Text) || String.IsNullOrEmpty(cnp.Text) || String.IsNullOrEmpty(name.Text) || String.IsNullOrEmpty(last_name.Text)) { MessageBox.Show("Va rugam completati campurile marcate cu (*)."); } else { String checked_username = (from b in db.People where b.Utilizator == username.Text select b.Utilizator).FirstOrDefault(); if (String.IsNullOrEmpty(checked_username) == false) { MessageBox.Show("Username existent in baza de date. Va rugam incercati din nou."); } else { var user = new Person(); user.Utilizator = username.Text; user.Parola = PasswordHash.GetHashString(password.Text); // aici pentru securitate user.Nume = name.Text; user.Prenume = last_name.Text; user.CNP = cnp.Text; user.Telefon = phone.Text; user.Email = email.Text; user.Role = db.Roles.Where(r => r.ID == 1).First(); db.People.Add(user); db.SaveChanges(); MessageBox.Show("Cont creat cu succes."); this.Close(); var login = new Form1(); login.Show(); } } } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void button_update_Click(object sender, EventArgs e) { try { using (var db = new BibliotecaEntities()) { if (String.IsNullOrEmpty(textBox2.Text) || String.IsNullOrEmpty(textBox1.Text) || String.IsNullOrEmpty(textBox_nume_membru.Text)) { MessageBox.Show("Un camp este necompletat. Va rugam sa introduceti toate datele necesare si sa incercati din nou."); } else { String titlu = textBox1.Text; String member_name = textBox_nume_membru.Text; DateTime enteredDate = DateTime.Parse(textBox2.Text); int book_id = (from b in db.Books where b.Titlu == titlu select b.ID).SingleOrDefault(); String[] nume = member_name.Split(' '); String nume0 = nume[0]; String nume1 = nume[1]; int member_id = (from b in db.People where b.Nume == nume0 && b.Prenume == nume1 && b.Rol == 1 select b.ID).SingleOrDefault(); var rowToUpdate = db.Lends.Where(o => (o.Book_ID == book_id)).Where(o => (o.Person_ID == member_id)).Where(o => o.Stare_Imprumut == 1); if (rowToUpdate.Any()) { foreach (var item in rowToUpdate) { item.Data_Retur = enteredDate; } MessageBox.Show("Data de returnare a fost schimbata."); } else { MessageBox.Show("Cartea nu se afla la membrul selectat."); } db.SaveChanges(); } } } catch (Exception ex) { MessageBox.Show("A avut loc o eroare. Vă rugăm să încercaţi din nou."); } }
private void button1_Click(object sender, EventArgs e) { using (var db = new BibliotecaEntities()) { var publisher = new Publisher(); publisher.Nume = publisher_text.Text; db.Publishers.Add(publisher); db.SaveChanges(); publisher_text.Text = ""; MessageBox.Show("Editura creata cu success!"); } }
private void add_author_Click(object sender, EventArgs e) { using (var db = new BibliotecaEntities()) { var autor = new Author(); autor.Nume = author_text.Text; db.Authors.Add(autor); db.SaveChanges(); author_text.Text = ""; MessageBox.Show("Autor creat cu success!"); } }
private void add_domain_Click(object sender, EventArgs e) { using (var db = new BibliotecaEntities()) { var domain = new Domain(); domain.Nume = domain_text.Text; db.Domains.Add(domain); db.SaveChanges(); domain_text.Text = ""; MessageBox.Show("Domeniu creat cu success!"); } }
private void MemberInformation_Load(object sender, EventArgs e) { using (var db = new BibliotecaEntities()) { var user = (from p in db.People where p.ID == id select p).First(); labelID.Text = user.ID.ToString(); labelUsername.Text = user.Utilizator.ToString(); labelName.Text = user.Nume.ToString() + " " + user.Prenume.ToString(); labelCNP.Text = user.CNP.ToString(); labelContactNo.Text = user.Telefon.ToString(); labelEmail.Text = user.Email.ToString(); } }
private void BookList_Load(object sender, EventArgs e) { using (var db = new BibliotecaEntities()) { try { BindingSource bi = new BindingSource(); bi.DataSource = db.booksViews.ToList(); dataGridView1.DataSource = bi; dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; dataGridView1.Refresh(); } catch (Exception ex) { MessageBox.Show(ex.Message); } } }
private void button_retur_Click(object sender, EventArgs e) { using (var db = new BibliotecaEntities()) { var titlu = carte_combo.SelectedItem.ToString(); var nume = membru_combo.SelectedItem.ToString(); int book_id = (from b in db.Books where b.Titlu == titlu select b.ID).SingleOrDefault(); String[] member_name = nume.Split(' '); String nume0 = member_name[0]; String nume1 = member_name[1]; int member_id = (from b in db.People where b.Nume == nume0 && b.Prenume == nume1 && b.Rol == 1 select b.ID).SingleOrDefault(); var rowToUpdate = db.Lends.Where(o => (o.Book_ID == book_id)).Where(o => (o.Person_ID == member_id)); if (rowToUpdate.Any()) { foreach (var item in rowToUpdate) { item.Stare_Imprumut = 0; } MessageBox.Show("Actiune realizata cu succes."); var result = (from b in db.Books where b.Titlu == titlu select b).SingleOrDefault(); result.Exemplare++; } else { MessageBox.Show("Va rugam, introduceti date pentru o inregistrare valida."); } db.SaveChanges(); } }
//public void InitializeNewButtons() //{ // // label3 // // // this.label3.AutoSize = true; // this.label3.Location = new System.Drawing.Point(34, 401); // this.label3.Name = "label3"; // this.label3.Size = new System.Drawing.Size(168, 17); // this.label3.TabIndex = 5; // this.label3.Text = "Modificare data returnare"; // // // // label4 // // // this.label4.AutoSize = true; // this.label4.Location = new System.Drawing.Point(300, 401); // this.label4.Name = "label4"; // this.label4.Size = new System.Drawing.Size(71, 17); // this.label4.TabIndex = 6; // this.label4.Text = "Titlu carte"; // // // // label5 // // // this.label5.AutoSize = true; // this.label5.Location = new System.Drawing.Point(554, 401); // this.label5.Name = "label5"; // this.label5.Size = new System.Drawing.Size(74, 17); // this.label5.TabIndex = 7; // this.label5.Text = "Data noua"; // // // // textBox1 // // // this.textBox1.Location = new System.Drawing.Point(303, 422); // this.textBox1.Name = "textBox1"; // this.textBox1.Size = new System.Drawing.Size(166, 22); // this.textBox1.TabIndex = 8; // // // // textBox2 // // // this.textBox2.Location = new System.Drawing.Point(557, 422); // this.textBox2.Name = "textBox2"; // this.textBox2.Size = new System.Drawing.Size(166, 22); // this.textBox2.TabIndex = 9; //} private void button_cautare_Click(object sender, EventArgs e) { dataGrid_membri.Rows.Clear(); try { using (var db = new BibliotecaEntities()) { // InitializeNewButtons(); String member_name = textBox_nume_membru.Text; String[] nume = member_name.Split(' '); String nume0 = nume[0]; String nume1 = nume[1]; int member_id = (from b in db.People where b.Nume == nume0 && b.Prenume == nume1 && b.Rol == 1 select b.ID).SingleOrDefault(); var lended_books = db.return_card(member_id); //stored procedure foreach (var item in lended_books) { String stare; if (item.Stare_Imprumut == 1) { stare = "Nereturnata"; } else { stare = "Returnata"; } dataGrid_membri.Rows.Add(item.Titlu, item.ISBN, item.Data_Imprumut, item.Data_Retur, stare); } } } catch (Exception ex) { MessageBox.Show("A avut loc o eroare. Vă rugăm să încercaţi din nou."); } }
private void button1_Click(object sender, EventArgs e) //autentificare { bool login = false; int rol = 0; using (var db = new BibliotecaEntities()) { var query = from p in db.People select p; foreach (var item in query) { if (item.Utilizator == username.Text) { if (item.Parola == PasswordHash.GetHashString(password.Text)) { rol = item.Rol; login = true; } } } } if (login) { if (rol == 1) { this.Close(); var membru = new MembruForm(); membru.Show(); } if (rol == 2) { this.Close(); var administrator = new AdministratorForm(); administrator.Show(); } } else { MessageBox.Show("Parola sau Nume de utilizator Incorect"); } }
private void buttonSchimba_Click(object sender, EventArgs e) { try { using (var db = new BibliotecaEntities()) { var user = (from p in db.People where p.ID == id select p).First(); if (user.Parola == PasswordHash.GetHashString(textBoxCurrentPassword.Text)) { if (textBoxNewPassword.Text == textBoxConfirm.Text) { user.Parola = PasswordHash.GetHashString(textBoxNewPassword.Text); } } } } catch { MessageBox.Show("Parola incorecta! Va rugam reintroduceti!"); } }
public void InitializeDropDowns() { using (var db = new BibliotecaEntities()) { List <string> members = new List <string>(); List <string> books = new List <string>(); var query = from m in db.People where m.Rol == 1 select m; foreach (var item in query) { members.Add(item.Nume + " " + item.Prenume); } var query2 = from b in db.Books select b; foreach (var item in query2) { books.Add(item.Titlu); } membru_combo.DataSource = members; carte_combo.DataSource = books; } }