using System;
using System.Reflection;
using System.Windows.Forms;
using Model;
using Telerik.OpenAccess;
using Telerik.WinControls.UI;

namespace WinApp
{
  public partial class Form1 : Form
  {
    public Form1()
    {
      InitializeComponent();
    }

    OpenAccessTracer tracer = null;

    private void Form1_Load(object sender, EventArgs e)
    {
      tracer = new OpenAccessTracer(tbStatus, lblStatus);
      Assembly.GetAssembly(typeof(Customer));
    }

    private void cbSelect_SelectedIndexChanged(object sender, EventArgs e)
    {
      string selectedQuery =
        ((RadComboBoxItem)this.cbSelect.SelectedItem).Text;
      string query = string.Empty;

      switch (selectedQuery)
      {
        case "Select all products":
          {
            query = "select * from ProductExtent as p";
            break;
          }
        case "Select all customers":
          {
            query = "select * from CustomerExtent as c";
            break;
          }
        case "Select all orders":
          {
            query = "select * from OrderExtent as o";
            break;
          }
      }

      IObjectScope scope = ObjectScopeProvider1.GetNewObjectScope();
      IQueryResult result = scope.GetOqlQuery(query).Execute();
      this.gvMain.DataSource = result;
    }

    private void btnReset_Click(object sender, EventArgs e)
    {
      tracer.Reset(); 
    }
  }
}
