pageRecord m_recordPage; //List with page records

        #endregion Fields

        #region Constructors

        /// <summary>
        /// This method performs a connection to the server,get the first page
        /// of records and populate the grid with it.
        /// </summary>
        public MainWindow()
        {
            InitializeComponent();
            ChannelFactory<IDataController> dataFactory;
            NetTcpBinding tcpBinding = new NetTcpBinding();

            tcpBinding.MaxReceivedMessageSize = System.Int32.MaxValue;
            tcpBinding.ReaderQuotas.MaxArrayLength = System.Int32.MaxValue;
            string sURL = "net.tcp://localhost:50001/Data";

            dataFactory = new ChannelFactory<IDataController>(tcpBinding, sURL);

            m_data = dataFactory.CreateChannel();

            string [] columns = m_data.GetColumnNames();

            /*Binds the columns with the name of the fields of the table*/
            foreach (string name in columns)
            {
                DataGridTextColumn textcol = new DataGridTextColumn();
                Binding b = new Binding(name);
                textcol.Binding = b;
                textcol.Header = name;
                dgrdData.Columns.Add(textcol);
            }

            m_recordPage = new pageRecord();
            txtPage.Text = "1";
            UpdateDataGrid(1);
        }
        //Returns a list of records in a specific range from database
        public pageRecord GetPageRecord(int startRow, int endRow)
        {
            int[]      listID;
            pageRecord page = new pageRecord();

            listID = this.dataBase.GetItemIDList(startRow, endRow);

            foreach (int id in listID)
            {
                page.Records.Add(new dbRecord(this.GetItemRecord(id)));

                //Note field may be too large and bandwidth can be lost since this
                //list populates the grid, and notes field is not necessary
                page.Records[page.Records.Count - 1].Notes = "";
            }

            return(page);
        }
        //Returns a list of records in a specific range from database
        public pageRecord GetPageRecord(int startRow, int endRow)
        {
            int[] listID;
            pageRecord page = new pageRecord();
            listID = this.dataBase.GetItemIDList(startRow, endRow);

            foreach (int id in listID)
            {

                page.Records.Add(new dbRecord(this.GetItemRecord(id)));

                //Note field may be too large and bandwidth can be lost since this
                //list populates the grid, and notes field is not necessary
                page.Records[page.Records.Count - 1].Notes = "";
            }

            return page;
        }
        /// <summary>
        /// This method performs the validation of number pages, populates the grid with data
        /// and it hides the information that might not be shown(notes, etc)
        /// NOTE: The page has 100 records.
        /// </summary>
        private void UpdateDataGrid(int page)
        {
            int starRow, endRow, numRows;
            starRow = (page -1) * 100;
            endRow = (page*100) -1;
            numRows = m_data.getNumRows();

            if (endRow > (numRows - 1))
                endRow = (numRows - 1);

            if (starRow >= 0 && starRow < numRows)
            {
                m_recordPage = m_data.GetPageRecord(starRow, endRow);
                dgrdData.ItemsSource = m_recordPage.Records;
                dgrdData.IsReadOnly = true;
                dgrdData.Columns[4].Visibility = Visibility.Hidden;
                dgrdData.Columns[5].Visibility = Visibility.Hidden;
                dgrdData.Columns[7].Visibility = Visibility.Hidden;
                dgrdData.Columns[8].Visibility = Visibility.Hidden;
                dgrdData.Columns[10].Visibility = Visibility.Hidden;
                dgrdData.Columns[11].Visibility = Visibility.Hidden;
                dgrdData.SelectedIndex = 0;

                /*If the number of rows returned by the server is not divisible by 100,
                 * it means that the last page has less records than 100 records. So, it is add 1 at number
                 * pages.*/
                lblTotalPages.Content = numRows % 100 != 0 ? " of " + Convert.ToString((numRows / 100) + 1) : " of " + Convert.ToString((numRows / 100));
                txtPage.Text = page.ToString();

            }
            else
            {
                MessageBox.Show("This is not a valid page number");
            }
        }