예제 #1
0
    static void Main()
    {
        Handle.GET("/invoicedemo", () => {
            MasterPage master;

            if (Session.Current != null && Session.Current.Data != null) {
                master = (MasterPage)Session.Current.Data;
            } else {
                master = new MasterPage();

                if (Session.Current != null) {
                    master.Html = "/InvoiceDemo/LauncherWrapperPage.html";
                    master.Session = Session.Current;
                } else {
                    master.Html = "/InvoiceDemo/MasterPage.html";
                    master.Session = new Session(SessionOptions.PatchVersioning);
                }

                master.RecentInvoices = new InvoicesPage()
                {
                    Html = "/InvoiceDemo/InvoicesPage.html"
                };
            }

            ((InvoicesPage)master.RecentInvoices).RefreshData();
            master.FocusedInvoice = null;

            return master;
        });

        Handle.GET("/invoicedemo/new-invoice", () =>
        {
            MasterPage master = Self.GET<MasterPage>("/invoicedemo");

            master.FocusedInvoice = Db.Scope(() =>
            {
                var page = new InvoiceDetails()
                {
                    Html = "/InvoiceDemo/InvoiceDetailsPage.html",
                    Data = new Invoice()
                };

                page.Items = Db.SQL<InvoiceRow>("SELECT r FROM InvoiceRow r WHERE r.Invoice=?", page.Data);

                page.TaxSource.Add(new Json("0"));
                page.TaxSource.Add(new Json("5"));
                page.TaxSource.Add(new Json("7"));
                page.TaxSource.Add(new Json("22"));
                page.TaxSource.Add(new Json("23"));

                page.Pagination.Buttons.PreviousName = "<";
                page.Pagination.Buttons.NextName = ">";

                page.Pagination.RowsLimit.Add(new Json("10"));
                page.Pagination.RowsLimit.Add(new Json("25"));
                page.Pagination.RowsLimit.Add(new Json("50"));
                page.Pagination.RowsLimit.Add(new Json("100"));

                page.Pagination.RowsPage = page.Pagination.RowsLimit[0].IntegerValue;

                page.Saved += (s, a) =>
                {
                    ((InvoicesPage)master.RecentInvoices).RefreshData();
                };

                page.Deleted += (s, a) =>
                {
                    ((InvoicesPage)master.RecentInvoices).RefreshData();
                };

                return page;
            });

            return master;
        });

        Handle.GET("/invoicedemo/invoices/{?}", (int InvoiceNo) =>
        {
            MasterPage master = Self.GET<MasterPage>("/invoicedemo");

            master.FocusedInvoice = Db.Scope<InvoiceDetails>(() =>
            {
                var page = new InvoiceDetails() {
                    Html = "/InvoiceDemo/InvoiceDetailsPage.html",
                    Data = Db.SQL<Invoice>("SELECT i FROM Invoice i WHERE InvoiceNo = ?", InvoiceNo).First
                };

                //SIMPLE CODE TO MIGRATE OLD DATA
                //WITH DEFUALT ROWINDEX EQUALS 0
                var isToUpdateRow = Db.SQL<long>("SELECT COUNT(r) FROM InvoiceRow r WHERE r.Invoice=? AND r.RowIndex=?", page.Data, 0).First;
                if (isToUpdateRow > 1)
                {
                    //page.UpdateAllRows(page.Data);
                }

                page.InvoiceNo = InvoiceNo;

                page.Pagination.RowsLimit.Add(new Json("10"));
                page.Pagination.RowsLimit.Add(new Json("25"));
                page.Pagination.RowsLimit.Add(new Json("50"));
                page.Pagination.RowsLimit.Add(new Json("100"));

                page.Pagination.RowsPage = page.Pagination.RowsLimit[0].IntegerValue;

                page.Pagination.Buttons.PreviousName = "<";
                page.Pagination.Buttons.NextName = ">";

                page.TaxSource.Add(new Json("0"));
                page.TaxSource.Add(new Json("5"));
                page.TaxSource.Add(new Json("7"));
                page.TaxSource.Add(new Json("22"));
                page.TaxSource.Add(new Json("23"));

                page.Saved += (s, a) =>
                {
                    ((InvoicesPage)master.RecentInvoices).RefreshData();
                };

                page.Deleted += (s, a) =>
                {
                    ((InvoicesPage)master.RecentInvoices).RefreshData();
                };

                page.RefreshInvoiceData();

                return page;
            });

            return master;
        });

        Handle.GET("/invoicedemo/app-name", () => {
            return new AppName();
        });

        Handle.GET("/invoicedemo/app-icon", () => {
            return new Page() { Html = "/InvoiceDemo/AppIconPage.html" };
        });

        Handle.GET("/invoicedemo/menu", () => {
            return new Page() { Html = "/InvoiceDemo/AppMenuPage.html" };
        });

        UriMapping.Map("/invoicedemo/menu", UriMapping.MappingUriPrefix + "/menu");
        UriMapping.Map("/invoicedemo/app-name", UriMapping.MappingUriPrefix + "/app-name");
        UriMapping.Map("/invoicedemo/app-icon", UriMapping.MappingUriPrefix + "/app-icon");
    }