using System;

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;

 

namespace AutomatedArchitecture.Northwind.WebUserControls.Base {

      public class OrderDetails_ViewMultiple_Base : System.Web.UI.UserControl {

            private System.Web.UI.WebControls.DataGrid dgResults;

            private System.Web.UI.WebControls.Label lblNoResults;

 

            /*********************************************************************

             * CONSTRUCTOR

             ********************************************************************/

            public OrderDetails_ViewMultiple_Base() {

                  this.RedirectTo = "OrderDetailsViewDetail.aspx";

            }

 

            /*********************************************************************

             * CONSTANTS

             ********************************************************************/

            protected int mintOrderID = 0;

            protected int mintProductID = 1;

            protected int mintFK_Order_Details_Orders_OrderDate = 2;

            protected int mintFK_Order_Details_Products_ProductName = 3;

            protected int mintFK_Order_Details_Products_UnitPrice = 4;

            protected int mintFK_Order_Details_Products_UnitsInStock = 5;

            protected int mintUnitPrice = 6;

            protected int mintQuantity = 7;

            protected int mintDiscount = 8;

 

            /*********************************************************************

             * PRIVATE VARS

             ********************************************************************/

            private DataView mviewTableView;

            private bool mblnDataBind = false;

            protected bool mblnShowFK_Order_Details_Orders = true;

            protected bool mblnShowFK_Order_Details_Products = true;

 

            /*********************************************************************

             * PUBLIC PROPERTIES

             ********************************************************************/

            public DataView TableView {

                  get {return mviewTableView;}

                  set {

                        mviewTableView = value;

                        bool blnNoResults = this.TableView.Count <= 0;

                        lblNoResults.Visible = blnNoResults;

                        dgResults.Visible = !blnNoResults;

                        if (!blnNoResults) {

                              dgResults.DataSource = this.TableView;

                              mblnDataBind = true;                      }

                  }

            }

 

            public string RedirectTo {

                  get {return ViewState["OrderDetailsViewMultiple_RedirectTo"].ToString();}

                  set {ViewState["OrderDetailsViewMultiple_RedirectTo"] = value;}

            }

 

            public bool ShowFK_Order_Details_Orders {

                  get {return mblnShowFK_Order_Details_Orders;}

                  set {mblnShowFK_Order_Details_Orders = value;}

            }

 

            public bool ShowFK_Order_Details_Products {

                  get {return mblnShowFK_Order_Details_Products;}

                  set {mblnShowFK_Order_Details_Products = value;}

            }

 

            /*********************************************************************

             * PAGE LOAD_BASE

             ********************************************************************/

            protected virtual void Page_Load_Base(object sender, System.EventArgs e) {

                  // set the visibility of columns whose relationships are not necessary to display (set by the container)

                  dgResults.Columns[mintFK_Order_Details_Orders_OrderDate].Visible = ShowFK_Order_Details_Orders;

                  dgResults.Columns[mintFK_Order_Details_Products_ProductName].Visible = ShowFK_Order_Details_Products;

                  dgResults.Columns[mintFK_Order_Details_Products_UnitPrice].Visible = ShowFK_Order_Details_Products;

                  dgResults.Columns[mintFK_Order_Details_Products_UnitsInStock].Visible = ShowFK_Order_Details_Products;

                  if (mblnDataBind)

                        dgResults.DataBind();

            }

 

            /*********************************************************************

             * EVENT HOOKUPS

             ********************************************************************/

            #region Event Hookups

            override protected void OnInit(EventArgs e) {

                  BindLocalControlVariables();

                  InitializeComponent();

                  base.OnInit(e);

            }

 

            private void InitializeComponent() {

                  this.Load += new System.EventHandler(this.Page_Load_Base);

                  this.dgResults.ItemCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.dgResults_ItemCommand);

            }

 

            private void BindLocalControlVariables() {

                  dgResults = (DataGrid)this.FindControl("dgResults");

                  lblNoResults = (Label)this.FindControl("lblNoResults");

            }

            #endregion

 

            /*********************************************************************

             * EVENT HANDLERS

             ********************************************************************/

            protected virtual void dgResults_ItemCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e) {

                  string strCommandName = ((Button)e.CommandSource).CommandName;

 

                  if (strCommandName.Equals("Select")) {

                        int intOrderID = Convert.ToInt32(e.Item.Cells[0].Text);

                        Session["OrderID"] = intOrderID;

                        int intProductID = Convert.ToInt32(e.Item.Cells[1].Text);

                        Session["ProductID"] = intProductID;

                        Response.Redirect(this.RedirectTo);

                  }

            }

      }

}