private void buttonReturn_Click(object sender, EventArgs e)
        {
            LibraryEntities1 context = new LibraryEntities1();

            List <int> books = new List <int>();

            foreach (DataGridViewRow row in dataGridViewLoaned.SelectedRows)
            {
                if (row.Cells[0].Value != null)
                {
                    books.Add(Convert.ToInt32(row.Cells[0].Value));
                }
            }

            if (books.Count > 0)
            {
                var client = (from c in context.Clients
                              where c.ClientID == id
                              select c).SingleOrDefault();

                foreach (ClientsBook cBook in client.ClientsBooks)
                {
                    if (books.Contains(cBook.BookID))
                    {
                        cBook.Returned = true;
                        MessageBox.Show("Връщане - успешно!");
                    }
                }

                context.SaveChanges();
            }
        }
 static void DeleteAccaunt(int accauntID)
 {
     LibraryEntities1 context = new LibraryEntities1();
     Accaunt accaunt = GetAccauntID(context, accauntID);
     context.Accaunts .DeleteObject(accaunt);
     context.SaveChanges();
 }
 static void ModifyBookRejection(int bookID, bool newRejection)
 {
     LibraryEntities1 context = new LibraryEntities1();
     Book book = GetBookID(context, bookID);
     book.Rejection = newRejection;
     context.SaveChanges();
 }
Exemple #4
0
        static void DeleteAccaunt(int accauntID)
        {
            LibraryEntities1 context = new LibraryEntities1();
            Accaunt          accaunt = GetAccauntID(context, accauntID);

            context.Accaunts.DeleteObject(accaunt);
            context.SaveChanges();
        }
Exemple #5
0
        private void EditClick(object sender, RoutedEventArgs e)
        {
            Tenant tenant = TenantGrid.SelectedItem as Tenant;

            db.Tenants.Remove(tenant);
            db.SaveChanges();
            TenantGrid.ItemsSource = db.Tenants.ToList();
        }
Exemple #6
0
        static void ModifyBookRejection(int bookID, bool newRejection)
        {
            LibraryEntities1 context = new LibraryEntities1();
            Book             book    = GetBookID(context, bookID);

            book.Rejection = newRejection;
            context.SaveChanges();
        }
        private void buttonAdd_Click(object sender, EventArgs e)
        {
            LibraryEntities1 context = new LibraryEntities1();

            //създаваме нова книга чрез конструктора Books()
            try
            {
                if (textBoxInvNum.Text != "" && textBoxTitle.Text != "")
                {
                    Book newBook = new Book();
                    //на съответните полета присвояваме стойностите от текстовите кутии
                    newBook.InvNum      = textBoxInvNum.Text;
                    newBook.ISBN        = textBoxISBN.Text;
                    newBook.Title       = textBoxTitle.Text;
                    newBook.Description = textBoxDescription.Text;
                    newBook.YearPub     = Int32.Parse(textBoxYearPubl.Text);
                    newBook.Price       = Decimal.Parse(textBoxPrice.Text);
                    newBook.Rejection   = false;
                    newBook.CategoryID  = Int32.Parse(comboBoxCategory.SelectedValue.ToString());
                    newBook.LanguageID  = Int32.Parse(comboBoxLanguage.SelectedValue.ToString());
                    // обработка на селектираните редове от  DataGridViewAuthors - това са авторите на новата книга
                    int authorID;//локална променлива
                    foreach (DataGridViewRow row in dataGridViewAuthors.SelectedRows)
                    {
                        authorID = Convert.ToInt32(row.Cells[0].Value);//вземаме стойността Value на ID на автора от текущо селектирания ред - row.Cells[0].Value
                        //добавяне на данните за автора към свойството Authors на книгата, която обработваме
                        //свойството не е просто свойство, а е списък (List) от автори
                        newBook.Authors.Add(context.Authors.ToList().Find(a => a.AuthorID == authorID));
                    }
                    //добавяне на новата книга в базата и записване на промените
                    context.Books.AddObject(newBook);
                    context.SaveChanges();
                    MessageBox.Show("Книгата е добавена!");
                }
                else
                {
                    MessageBox.Show("Грешка! Не сте въвели данни.");
                }
            }
            catch (FormatException)
            {
                MessageBox.Show("Вие не сте въвели данни! " + "Книгата не е добавена!");
            }
            if (MessageBox.Show("Ще въвеждате ли други книги?", "Добавяне на книга",
                                MessageBoxButtons.YesNo) == DialogResult.No)
            {
                this.Close();
            }
            else
            {
                Clear();
            }
        }
        private void buttonAdd_Click(object sender, EventArgs e)
        {
            LibraryEntities1 context = new LibraryEntities1();
            //създаваме нова книга чрез конструктора Books()
            try
            {
                if (textBoxInvNum.Text != "" && textBoxTitle.Text != "")
                {
                    Book newBook = new Book();
                    //на съответните полета присвояваме стойностите от текстовите кутии
                    newBook.InvNum = textBoxInvNum.Text;
                    newBook.ISBN = textBoxISBN.Text;
                    newBook.Title = textBoxTitle.Text;
                    newBook.Description = textBoxDescription.Text;
                    newBook.YearPub = Int32.Parse(textBoxYearPubl.Text);
                    newBook.Price = Decimal.Parse(textBoxPrice.Text);
                    newBook.Rejection = false;
                    newBook.CategoryID = Int32.Parse(comboBoxCategory.SelectedValue.ToString());
                    newBook.LanguageID = Int32.Parse(comboBoxLanguage.SelectedValue.ToString());
                    // обработка на селектираните редове от  DataGridViewAuthors - това са авторите на новата книга
                    int authorID;//локална променлива
                    foreach (DataGridViewRow row in dataGridViewAuthors.SelectedRows)
                    {
                        authorID = Convert.ToInt32(row.Cells[0].Value);//вземаме стойността Value на ID на автора от текущо селектирания ред - row.Cells[0].Value
                        //добавяне на данните за автора към свойството Authors на книгата, която обработваме
                        //свойството не е просто свойство, а е списък (List) от автори
                        newBook.Authors.Add(context.Authors.ToList().Find(a => a.AuthorID == authorID));
                    }
                    //добавяне на новата книга в базата и записване на промените
                    context.Books.AddObject(newBook);
                    context.SaveChanges();
                    MessageBox.Show("Книгата е добавена!");
                }
                else
                {
                    MessageBox.Show("Грешка! Не сте въвели данни.");
                }

            }
            catch (FormatException)
            {
                MessageBox.Show("Вие не сте въвели данни! " + "Книгата не е добавена!");
            }
            if (MessageBox.Show("Ще въвеждате ли други книги?", "Добавяне на книга",
                        MessageBoxButtons.YesNo) == DialogResult.No)
            {
                this.Close();
            }
            else
            {
                Clear();
            }
        }
 private void buttonAdd_Click(object sender, EventArgs e)
 {
     LibraryEntities1 context = new LibraryEntities1();
     Accaunt newAccaunt = new Accaunt()
     {
         Login = textBoxLogin.Text.Trim(),
         PasswordSHA1 =CalculateSHA1(textBoxLogin.Text).Trim(),
         FirstName = textBoxFName.Text.Trim(),
         LastName = textBoxLName.Text.Trim()
     };
     context.Accaunts.AddObject(newAccaunt);
     context.SaveChanges();
     MessageBox.Show("Добавянето е успешно.");
     Clear();
 }
Exemple #10
0
        private void Accept_Click(object sender, RoutedEventArgs e)
        {
            Rent rent = new Rent();

            Tenant ten  = TenantCB.SelectedItem as Tenant;
            Book   book = BookCB.SelectedItem as Book;

            book.FK_StatusId = 1;

            rent.FK_Tenant  = ten.TenantID;
            rent.DateOfRent = DateTime.Now.Date;

            db.Rents.Add(rent);
            db.SaveChanges();
            Close();
        }
Exemple #11
0
        private void buttonAdd_Click(object sender, EventArgs e)
        {
            LibraryEntities1 context    = new LibraryEntities1();
            Accaunt          newAccaunt = new Accaunt()
            {
                Login        = textBoxLogin.Text.Trim(),
                PasswordSHA1 = CalculateSHA1(textBoxLogin.Text).Trim(),
                FirstName    = textBoxFName.Text.Trim(),
                LastName     = textBoxLName.Text.Trim()
            };

            context.Accaunts.AddObject(newAccaunt);
            context.SaveChanges();
            MessageBox.Show("Добавянето е успешно.");
            Clear();
        }
        private void buttonAdd_Click(object sender, EventArgs e)
        {
            LibraryEntities1 context = new LibraryEntities1();
            if (textBoxLName.Text!="")
            {
                Author newAuthor = new Author()
                {
                    FName = textBoxFName.Text,
                    LName = textBoxLName.Text
                };

                context.Authors.AddObject(newAuthor);
                context.SaveChanges();
                MessageBox.Show("Авторът е добавен.");
            }
            else MessageBox.Show("Грешка! Няма въведени данни.");
        }
        static void ModifyClien(int clientID, string newFName, string newSName, string newLName, string newEgn,
                                string newAdress, string newPhone, string newEmail, int newLeaving, int newStatusID, int genderID)
        {
            LibraryEntities1 context = new LibraryEntities1();

            Client client = GetClientByID(context, clientID);

            client.FName    = newFName;
            client.SName    = newSName;
            client.LName    = newLName;
            client.EGN      = newEgn;
            client.Adress   = newAdress;
            client.Phone    = newPhone;
            client.Email    = newEmail;
            client.Leaving  = newLeaving;
            client.StatusID = newStatusID;
            client.GenderID = genderID;
            context.SaveChanges();
        }
Exemple #14
0
        static void CreateNewClient(string fName, string sName, string lName, string egn, string adress, string phone, string email, int leaving, int statusID, int genderID)
        {
            LibraryEntities1 context   = new LibraryEntities1();
            Client           newClient = new Client()
            {
                FName    = fName,
                SName    = sName,
                LName    = lName,
                EGN      = egn,
                Adress   = adress,
                Phone    = phone,
                Email    = email,
                Leaving  = leaving,
                StatusID = statusID,
                GenderID = genderID
            };

            context.Clients.AddObject(newClient);
            context.SaveChanges();
        }
        private void buttonAdd_Click(object sender, EventArgs e)
        {
            LibraryEntities1 context = new LibraryEntities1();

            if (textBoxLName.Text != "")
            {
                Author newAuthor = new Author()
                {
                    FName = textBoxFName.Text,
                    LName = textBoxLName.Text
                };

                context.Authors.AddObject(newAuthor);
                context.SaveChanges();
                MessageBox.Show("Авторът е добавен.");
            }
            else
            {
                MessageBox.Show("Грешка! Няма въведени данни.");
            }
        }
Exemple #16
0
        //за резервиране на книги
        private void buttonReserveNew_Click(object sender, EventArgs e)
        {
            LibraryEntities1 context = new LibraryEntities1();
            var client = (from c in context.Clients
                          where c.ClientID == clientId
                          select c).SingleOrDefault();

            bool hasBooks = false;

            foreach (DataGridViewRow item in dataGridViewLoaned.Rows)
            {
                if (item.Cells[4].Value != null)
                {
                    int      bookID = Convert.ToInt32(item.Cells[4].Value);
                    DateTime dateL  = Convert.ToDateTime(item.Cells[2].Value);
                    DateTime dateR  = Convert.ToDateTime(item.Cells[3].Value);

                    ClientsBook cBook = new ClientsBook();
                    cBook.BookID       = bookID;
                    cBook.ClientID     = client.ClientID;
                    cBook.DateLoaned   = dateL;
                    cBook.DateReturned = dateR;
                    cBook.Reservation  = true;

                    client.ClientsBooks.Add(cBook);

                    hasBooks = true;
                }
            }

            if (hasBooks)
            {
                context.SaveChanges();
                MessageBox.Show("Книгата е резервирана!");
            }
            else
            {
                MessageBox.Show("Грешка! Няма въведени данни!");
            }
        }
Exemple #17
0
 private void InsertClick(object sender, RoutedEventArgs e)
 {
     if (FirstName != null && LastName != null && MiddleName != null && PhoneNumber != null && NumberList != null)
     {
         Tenant Tenant = new Tenant();
         Tenant.FirstName   = FirstName.Text;
         Tenant.LastName    = LastName.Text;
         Tenant.MiddleName  = MiddleName.Text;
         Tenant.PhoneNumber = PhoneNumber.Text;
         Tenant.LibraryCard = int.Parse(NumberList.Text);
         db.Tenants.Add(Tenant);
         db.SaveChanges();
         MessageBox.Show("Создание прошло успешно");
         ReaderList op = new ReaderList();
         op.Show();
         this.Close();
     }
     else
     {
         MessageBox.Show("Неправильно введены ");
     }
 }
 private void buttonAdd_Click(object sender, EventArgs e)
 {
     int i = dataGridViewLanguages.CurrentRow.Index;
     int LanguageID = (int)dataGridViewLanguages.Rows[i].Cells[0].Value;
     string lang = dataGridViewLanguages.Rows[i].Cells[1].Value.ToString();
     LibraryEntities1 context = new LibraryEntities1();
     if(LanguageID!=0)
     {
         Language newLanguage = new Language()
         {
             LanguageName = lang
         };
         context.Languages.AddObject(newLanguage);
         context.SaveChanges();
         MessageBox.Show("Добавен е език!");
         buttonAdd.Enabled = false;
     }
     else
     {
         MessageBox.Show("Грешка! Не сте въвели език.");
         this.Close();
     }
 }
Exemple #19
0
        private void buttonNew_Click(object sender, EventArgs e)
        {
            LibraryEntities1 context = new LibraryEntities1();
            var client = (from c in context.Clients
                          where c.ClientID == clientId
                          select c).SingleOrDefault();

            bool hasBooks = false;

            foreach (DataGridViewRow item in dataGridViewLoaned.Rows)
            {
                if (item.Cells[4].Value != null)
                {
                    int bookID = Convert.ToInt32(item.Cells[4].Value);
                    DateTime dateL = Convert.ToDateTime(item.Cells[2].Value);
                    DateTime dateR = Convert.ToDateTime(item.Cells[3].Value);

                    ClientsBook cBook = new ClientsBook();
                    cBook.BookID = bookID;
                    cBook.ClientID = client.ClientID;
                    cBook.DateLoaned = dateL;
                    cBook.DateReturned = dateR;

                    client.ClientsBooks.Add(cBook);

                    hasBooks = true;
                }
            }

            if (hasBooks)
            {
                context.SaveChanges();
                MessageBox.Show("Книгите са записани - заети!");
            }
            else MessageBox.Show("Грешка! Няма въведени данни!");
        }
Exemple #20
0
 private void Accept_Click(object sender, RoutedEventArgs e)
 {
     if (NameBookTB.Text == "" || AuthorTB.Text == "" || GenreeCB.Text == "" || SectionCB.Text == "" || LocationCB.Text == "")
     {
         Err.Visibility = System.Windows.Visibility.Visible;
     }
     else
     {
         Book book = new Book();
         book.BookName = NameBookTB.Text;
         book.Autor    = AuthorTB.Text;
         Genre gen = GenreeCB.SelectedItem as Genre;
         book.FK_GENRE = gen.GenreID;
         BookLocation bl = LocationCB.SelectedItem as BookLocation;
         book.FK_BookLocation = bl.BookLocationID;
         Section sec = SectionCB.SelectedItem as Section;
         book.FK_Section  = sec.SectionID;
         book.FK_StatusId = 2;
         book.FK_RentID   = null;
         db.Books.Add(book);
         db.SaveChanges();
         this.Close();
     }
 }
Exemple #21
0
        private void buttonAdd_Click(object sender, EventArgs e)
        {
            int              i          = dataGridViewLanguages.CurrentRow.Index;
            int              LanguageID = (int)dataGridViewLanguages.Rows[i].Cells[0].Value;
            string           lang       = dataGridViewLanguages.Rows[i].Cells[1].Value.ToString();
            LibraryEntities1 context    = new LibraryEntities1();

            if (LanguageID != 0)
            {
                Language newLanguage = new Language()
                {
                    LanguageName = lang
                };
                context.Languages.AddObject(newLanguage);
                context.SaveChanges();
                MessageBox.Show("Добавен е език!");
                buttonAdd.Enabled = false;
            }
            else
            {
                MessageBox.Show("Грешка! Не сте въвели език.");
                this.Close();
            }
        }
        private void buttonAdd_Click(object sender, EventArgs e)
        {
            int i = dataGridViewCategories.CurrentRow.Index;
            int categoryID = (int)dataGridViewCategories.Rows[i].Cells[0].Value;
            string category = dataGridViewCategories.Rows[i].Cells[1].Value.ToString();
            LibraryEntities1 context = new LibraryEntities1();
            if (categoryID != 0)
            {
                Category newCategory = new Category()
                {
                    CategoryName = category
                };
                context.Categories.AddObject(newCategory);
                context.SaveChanges();
                MessageBox.Show("Категорията е добавена!");
                buttonAdd.Enabled = false;

            }
            else
            {
                MessageBox.Show("Грешка! Не сте въвели категория.");
                this.Close();
            }
        }
Exemple #23
0
        private void buttonAdd_Click(object sender, EventArgs e)
        {
            int              i          = dataGridViewCategories.CurrentRow.Index;
            int              categoryID = (int)dataGridViewCategories.Rows[i].Cells[0].Value;
            string           category   = dataGridViewCategories.Rows[i].Cells[1].Value.ToString();
            LibraryEntities1 context    = new LibraryEntities1();

            if (categoryID != 0)
            {
                Category newCategory = new Category()
                {
                    CategoryName = category
                };
                context.Categories.AddObject(newCategory);
                context.SaveChanges();
                MessageBox.Show("Категорията е добавена!");
                buttonAdd.Enabled = false;
            }
            else
            {
                MessageBox.Show("Грешка! Не сте въвели категория.");
                this.Close();
            }
        }
        static void ModifyClien(int clientID,string newFName, string newSName, string newLName, string newEgn, 
            string newAdress, string newPhone, string newEmail, int newLeaving, int newStatusID, int genderID)
        {
            LibraryEntities1 context = new LibraryEntities1();

            Client client = GetClientByID(context, clientID);
            client.FName = newFName;
            client.SName = newSName;
            client.LName = newLName;
            client.EGN  = newEgn ;
            client.Adress = newAdress;
            client.Phone = newPhone;
            client.Email = newEmail;
            client.Leaving = newLeaving;
            client.StatusID  = newStatusID;
            client.GenderID = genderID;
            context.SaveChanges();
        }
 static void CreateNewClient(string fName, string sName, string lName, string egn, string adress, string phone, string email, int leaving, int statusID, int genderID)
 {
     LibraryEntities1 context = new LibraryEntities1();
     Client newClient = new Client()
     {
         FName = fName,
         SName = sName,
         LName = lName,
         EGN = egn,
         Adress = adress,
         Phone = phone,
         Email = email,
         Leaving = leaving,
         StatusID = statusID,
         GenderID = genderID
     };
     context.Clients.AddObject(newClient);
     context.SaveChanges();
 }
        private void buttonReturn_Click(object sender, EventArgs e)
        {
            LibraryEntities1 context = new LibraryEntities1();

            List<int> books = new List<int>();

            foreach (DataGridViewRow row in dataGridViewLoaned.SelectedRows)
            {
                if (row.Cells[0].Value != null)
                {
                    books.Add(Convert.ToInt32(row.Cells[0].Value));
                }
            }

            if (books.Count > 0)
            {

                var client = (from c in context.Clients
                              where c.ClientID == id
                              select c).SingleOrDefault();

                foreach (ClientsBook cBook in client.ClientsBooks)
                {
                    if (books.Contains(cBook.BookID))
                    {
                        cBook.Returned = true;
                        MessageBox.Show("Връщане - успешно!");
                    }
                }

                context.SaveChanges();
            }
        }