Click here to Skip to main content
15,894,291 members
Articles / Web Development / ASP.NET

An Introduction to a Post-relational Database for .NET: Matisse - Part 6

Rate me:
Please Sign up or sign in to vote.
4.45/5 (21 votes)
2 May 20043 min read 65.9K   966   37  
ASP.NET programming with a post-relational database.
using System;
using System.IO;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using com.matisse;
using com.matisse.Data;

namespace MediaDemoASP
{
	/// <summary>
	/// Summary description for MovieListForm.
	/// </summary>
	public class MovieListForm : System.Web.UI.Page
	{
        public StartForm sourcepage;
        private int CurrentPage;
        protected System.Web.UI.WebControls.LinkButton NextButton;
        protected System.Web.UI.WebControls.DataList DataList1;
        static private int PageSize = 4;
    
		private void Page_Load(object sender, System.EventArgs e)
		{

            if (!IsPostBack){
                sourcepage = (StartForm) Context.Handler;
                ViewState["DbName"] = sourcepage.DbName;
                CurrentPage = 0;
                FillData();
            }

		}

		#region Web Form Designer generated code
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: This call is required by the ASP.NET Web Form Designer.
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{    
            this.NextButton.Click += new System.EventHandler(this.NextButton_Click);
            this.Load += new System.EventHandler(this.Page_Load);

        }
		#endregion

        private void FillData() {
            MtDatabase db;

            db = new MtDatabase("localhost", (string) ViewState["DbName"],
                new MtPackageObjectFactory("Johnssk.example.media,DbSchema"));
            try {
                db.Open();

                string query = 
                    "SELECT Title, Description, OID FROM Photo ORDER BY Title LIMIT " +
                    PageSize +
                    " OFFSET " + 
                    (CurrentPage * PageSize);

                // For DataGrid
                /*
                MtDataAdapter adapter = new MtDataAdapter(query, db);

                DataSet ds = new DataSet();
                adapter.Fill(ds, "Movies");

                DataGrid1.DataSource=ds.Tables["Movies"].DefaultView;
                DataGrid1.DataBind();
                */

                // For DataList
                MtCommand cmd = db.CreateCommand();
                cmd.CommandText = query;
                MtDataReader reader = (MtDataReader) cmd.ExecuteReader();
                DataList1.DataSource = reader;
                DataList1.DataBind();
                reader.Close();

                if ( DataList1.Items.Count < PageSize ) {
                    // No more data. Disable the 'next' button
                    NextButton.Enabled = false;
                }

                db.Close();
            } catch (MtException ex) {
                Response.Write(ex.Message);
            }
            ViewState["CurrentPage"] = CurrentPage;
        }

        private void NextButton_Click(object sender, System.EventArgs e) {
            CurrentPage = (int) ViewState["CurrentPage"];
            ++CurrentPage;
            FillData();
        }

        private void DataGrid1_SelectedIndexChanged(object sender, System.EventArgs e) {
        
        }

        public string PhotoThumbnailURL(string oid) 
        {
            return "ReadThumbnail.aspx?id=" + oid + 
                   "&dbname=" + (string) ViewState["DbName"];
        }

        public string PhotoScreenshotURL(string oid) {
            return "ReadScreenshot.aspx?id=" + oid + 
                "&dbname=" + (string) ViewState["DbName"];
        }

	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.


Written By
Web Developer
United States United States
John is a software consultant and currently working for a large .NET project. He has an extensive experience in object-oriented technologies for more than 15 years ranging from Smalltalk, C++, Java, .NET to databases.

Comments and Discussions