Liquid XML Data Binder 2020
Liquid XML Data Binder (C++, Java, VB6) / Help With Your Evaluation / Bookstore Sample / Main2017.cs
In This Topic
    Main2017.cs
    In This Topic
    using System;
    using LiquidTechnologies.Runtime.Net45;
    
    namespace LiquidTechnologies.Test
    {
            /// <summary>
            /// Summary description for Class1.
            /// </summary>
            class SampleApp
            {
                    /// <summary>
                    /// The main entry point for the application.
                    /// </summary>
                    [STAThread]
                    static void Main(string[] args)
                    {
                            // This example is used in a number of places so 
                            // ensure we have the correct path to the sample xml file
                            if (System.IO.File.Exists(@"BookStoreSample.xml"))
                                    TestRead(@"BookStoreSample.xml");
                            else
                                    TestRead(@"..\..\..\..\..\BookStoreSample.xml");
                            TestWrite();
                    }
                    
                    public static void TestWrite()
                    {
                            // to create the XML document from scratch
                            BookStoreLib.Bookstore bs = new BookStoreLib.Bookstore();
                BookStoreLib.BookType book = new BookStoreLib.BookType();
                bs.Book.Add(book);
                            book.Title = "The Autobiography of Benjamin Franklin";
                            book.Price = 8.99;
                book.Publicationdate = new LiquidTechnologies.Runtime.Net45.XmlDateTime(1981, 5, 11);
                            book.ISBN = "1-861003-11-0";
                            book.Author.First_name = "Benjamin";
                            book.Author.Last_name = "Franklin";
                            book.Genre = "autobiography";
                            string strXml = book.ToXml();
                            System.Console.WriteLine(strXml);
    
                            // Display with the XML viewer
                            Test.SimpleViewer viewer = new Test.SimpleViewer(bs);
                            viewer.ShowDialog();
                    }
    
                    public static void TestRead(string filename)
                    {
                            // to create the XML document from scratch
                            BookStoreLib.Bookstore bs = new BookStoreLib.Bookstore();
                            bs.FromXmlFile(filename);
                            foreach (BookStoreLib.BookType book in bs.Book)
                            {
                                    System.Console.WriteLine("Book Title           {0}", book.Title);
                                    System.Console.WriteLine("    Price            {0}", book.Price);
                                    System.Console.WriteLine("    Author           {0} {1}", book.Author.First_name, book.Author.Last_name);
                                    if (book.IsValidPublicationdate)
                                            System.Console.WriteLine("    Publicationdate  {0}", book.Publicationdate.ToString());
                                    else                                 
                                            System.Console.WriteLine("    Publicationdate  Not Listed");
                                    if (book.IsValidISBN)
                                            System.Console.WriteLine("    ISBN             {0}", book.ISBN);
                                    else                                 
                                            System.Console.WriteLine("    ISBN             Not Listed");
                                    if (book.IsValidGenre)
                                            System.Console.WriteLine("    Genre            {0}", book.Genre);
                                    else                                 
                                            System.Console.WriteLine("    Genre            Not Listed");
                            }
                    }
            }
    }