Beispiel #1
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("Грешка! Няма въведени данни!");
        }
 /// <summary>
 /// Deprecated Method for adding a new object to the ClientsBooks EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToClientsBooks(ClientsBook clientsBook)
 {
     base.AddObject("ClientsBooks", clientsBook);
 }
 /// <summary>
 /// Create a new ClientsBook object.
 /// </summary>
 /// <param name="clientID">Initial value of the ClientID property.</param>
 /// <param name="bookID">Initial value of the BookID property.</param>
 /// <param name="dateLoaned">Initial value of the DateLoaned property.</param>
 /// <param name="dateReturned">Initial value of the DateReturned property.</param>
 /// <param name="returned">Initial value of the Returned property.</param>
 /// <param name="reservation">Initial value of the Reservation property.</param>
 public static ClientsBook CreateClientsBook(global::System.Int32 clientID, global::System.Int32 bookID, global::System.DateTime dateLoaned, global::System.DateTime dateReturned, global::System.Boolean returned, global::System.Boolean reservation)
 {
     ClientsBook clientsBook = new ClientsBook();
     clientsBook.ClientID = clientID;
     clientsBook.BookID = bookID;
     clientsBook.DateLoaned = dateLoaned;
     clientsBook.DateReturned = dateReturned;
     clientsBook.Returned = returned;
     clientsBook.Reservation = reservation;
     return clientsBook;
 }