Пример #1
0
 public int LoadFromDataBase()
 {
     X.ADO.CommandedTable worksCTable = X.ADO.GetTable("select * from Work", "Work");
     X.ADO.CommandedTable booksCTable = X.ADO.GetTable("select * from Book", "Book");
     X.ADO.CommandedTable cdsCTable   = X.ADO.GetTable("select * from CD", "CD");
     if (worksCTable == null)
     {
         return(0);
     }
     else
     {
         foreach (DataRow row in booksCTable.DataTable.Rows)
         {
             if (GetBook((int)row["Code"]) == null)
             {
                 Works.Add(new Book("", (string)row["AuthorName"], (string)row["EditorName"]));
             }
         }
         foreach (DataRow row in cdsCTable.DataTable.Rows)
         {
             if (GetCD((int)row["Code"]) == null)
             {
                 Works.Add(new CD("", (string)row["ArtistName"], (int)row["TrackCount"]));
             }
         }
         foreach (DataRow row in worksCTable.DataTable.Rows)
         {
             if (GetWork((int)row["Code"]) != null)
             {
                 Works[worksCTable.DataTable.Rows.IndexOf(row)].Title = (string)row["Title"];
             }
         }
         return(worksCTable.DataTable.Rows.Count);
     }
 }
Пример #2
0
        // Save
        public string SaveToDataBase()
        {
            X.ADO.CommandedTable worksCTable = X.ADO.GetTable("select * from Work", "Work");
            X.ADO.CommandedTable booksCTable = X.ADO.GetTable("select * from Book", "Book");
            X.ADO.CommandedTable cdsCTable   = X.ADO.GetTable("select * from CD", "CD");
            bool workNotFound = true;

            foreach (Work work in Works)
            {
                workNotFound = true;
                foreach (DataRow row in worksCTable.DataTable.Rows)
                {
                    if ((int)row["Code"] == work.Code)
                    {
                        workNotFound       = false;
                        row["Title"]       = work.Title;
                        row["State"]       = work.State;
                        row["BorrowCount"] = work.BorrowCount;
                    }
                }
                if (workNotFound)
                {
                    worksCTable.DataTable.Rows.Add(work.Code, work.Title, work.State, work.BorrowCount);
                }
            }
            foreach (Book book in Books)
            {
                workNotFound = true;
                foreach (DataRow row in booksCTable.DataTable.Rows)
                {
                    if ((int)row["Code"] == book.Code)
                    {
                        workNotFound      = false;
                        row["AuthorName"] = book.AuthorName;
                        row["EditorName"] = book.EditorName;
                    }
                }
                if (workNotFound)
                {
                    booksCTable.DataTable.Rows.Add(book.Code, book.AuthorName, book.EditorName);
                }
            }
            foreach (CD cd in CDs)
            {
                workNotFound = true;
                foreach (DataRow row in cdsCTable.DataTable.Rows)
                {
                    if ((int)row["Code"] == cd.Code)
                    {
                        workNotFound      = false;
                        row["ArtistName"] = cd.ArtistName;
                        row["TrackCount"] = cd.TrackCount;
                    }
                }
                if (workNotFound)
                {
                    cdsCTable.DataTable.Rows.Add(cd.Code, cd.ArtistName, cd.TrackCount);
                }
            }
            foreach (DataRow row in worksCTable.DataTable.Rows)
            {
                if (GetWork((int)row["Code"]) == null)
                {
                    row.Delete();
                }
            }
            return(string.Format
                       ("{0} works ({1} books, {2} CDs) successfully saved.",
                       X.ADO.SetTable(worksCTable),
                       X.ADO.SetTable(booksCTable),
                       X.ADO.SetTable(cdsCTable)
                       ));
        }