示例#1
0
        public void Add()
        {
            var le  = new LibraryEntities();
            var ath = new Author();
            var lib = new Librar();

            var name    = MediatorLoadBook.GetName();
            var surname = MediatorLoadBook.GetSurname();

            var bk = new Books
            {
                NameBook = Mediator.MediatorAddBook.GetNameBook(),
                Gener    = Mediator.MediatorAddBook.GetGenre(),
                Year     = Mediator.MediatorAddBook.GetDate()
            };

            var NomberShelf    = Mediator.MediatorAddBook.GetShelf();
            var NomberCupboard = Mediator.MediatorAddBook.GetCupboatd();


            ath          = le.Author.FirstOrDefault(x => x.Name == name && x.Surname == surname);
            bk.id_Author = ath.id;

            var c = le.Librar.FirstOrDefault(x => x.NomberCupboard == lib.NomberCupboard && x.NomberShelf == lib.NomberShelf);

            if (c == null)
            {
                le.Librar.Add(lib);

                lib          = le.Librar.FirstOrDefault(x => x.NomberCupboard == NomberCupboard && x.NomberShelf == NomberShelf);
                bk.id_Librar = lib.id;
                le.SaveChanges();
            }
            else
            {
                bk.id_Librar = c.id;
                le.SaveChanges();
            }

            le.Books.Add(bk);
            le.SaveChanges();
        }
示例#2
0
 public void Load()
 {
     try
     {
         string     pathTofile = Mediator.MediatorLoadBook.GetNameFile();
         string     rowStr     = "";
         TextWriter sw         = new StreamWriter(pathTofile, true, Encoding.Unicode);
         foreach (DataGridViewRow row in MediatorLoadBook.GetBooks())
         {
             foreach (DataGridViewCell cel in row.Cells)
             {
                 rowStr += cel.Value + "\t";
             }
             sw.WriteLine(rowStr.TrimEnd());
             rowStr = "";
         }
         sw.Close();
     }
     catch (Exception ex)
     {
         System.Windows.Forms.MessageBox.Show(ex.Message);
     }
 }