// File Name: Orders_ViewDetail_Base.cs

// Description: This file contains the generated code relating to viewing a single 'Order'.

// Last Generated: 6/8/2005 by Blue Ink - http://www.blueink.biz

// Attention: DO NOT MODIFY THIS FILE.  It is liable to be regenerated and your changes may be lost.

 

using System;

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 AutomatedArchitecture.Northwind.UiCommon;

using AutomatedArchitecture.Northwind.Common.Entities;

using AutomatedArchitecture.Northwind.ServiceInterface;

using AutomatedArchitecture.Northwind.WebUserControls;

 

namespace AutomatedArchitecture.Northwind.Base {

      public class Orders_ViewDetail_Base : PageBase {

            // column controls

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

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

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

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

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

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

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

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

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

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

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

            // 1-n controls

            // Customers

            private System.Web.UI.WebControls.PlaceHolder plhFK_Orders_Customers;

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

            private System.Web.UI.WebControls.Button cmdFK_Orders_Customers;

            protected CustomersIdentify mwucIdentifyFK_Orders_Customers;

            // Employees

            private System.Web.UI.WebControls.PlaceHolder plhFK_Orders_Employees;

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

            private System.Web.UI.WebControls.Button cmdFK_Orders_Employees;

            protected EmployeesIdentify mwucIdentifyFK_Orders_Employees;

            // n-1 controls

            // Order detail

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

            private System.Web.UI.WebControls.PlaceHolder plhFK_Order_Details_Orders;

            private System.Web.UI.WebControls.Button cmdAddFK_Order_Details_Orders;

            protected OrderDetailsViewMultiple mwucFK_Order_Details_Orders_ViewMultiple = null;

            // page controls

            private System.Web.UI.WebControls.Button cmdEdit;

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

 

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

             * CONSTRUCTOR

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

            public Orders_ViewDetail_Base() { }

 

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

             * PRIVATE PROPERTIES

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

            protected string CustomerID {

                  get {return (string)ViewState["CustomerID"];}

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

            }

 

            protected int EmployeeID {

                  get {return (int)ViewState["EmployeeID"];}

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

            }

 

            protected int OrderID {

                  get {return (int)ViewState["OrderID"];}

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

            }

 

            protected int ShipVia {

                  get {return (int)ViewState["ShipVia"];}

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

            }

 

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

             * PRIVATE FUNCTIONS

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

            protected virtual void BindControlsToData(Orders_ViewDetailDataSet tdsViewDetail) {

                  bool blnOrderDetailsWriteable = Security_ServiceInterface.PermitAction("OrderDetails", "Write");

                  bool blnOrderDetailsReadable = Security_ServiceInterface.PermitAction("OrderDetails", "Read");

 

                  Orders_ViewDetailDataSet.OrdersRow rowViewDetail = tdsViewDetail.Orders[0];

                  // populate all the regular data columns, and fk to lookup columns

                  UiHelper.PopulateLabel(lblFreight, rowViewDetail, "Freight", "c");

                  UiHelper.PopulateLabel(lblOrderDate, rowViewDetail, "OrderDate", "d");

                  UiHelper.PopulateLabel(lblRequiredDate, rowViewDetail, "RequiredDate", "d");

                  UiHelper.PopulateLabel(lblShipAddress, rowViewDetail, "ShipAddress", "");

                  UiHelper.PopulateLabel(lblShipCity, rowViewDetail, "ShipCity", "");

                  UiHelper.PopulateLabel(lblShipCountry, rowViewDetail, "ShipCountry", "");

                  UiHelper.PopulateLabel(lblShipName, rowViewDetail, "ShipName", "");

                  UiHelper.PopulateLabel(lblShippedDate, rowViewDetail, "ShippedDate", "d");

                  UiHelper.PopulateLabel(lblShipPostalCode, rowViewDetail, "ShipPostalCode", "");

                  UiHelper.PopulateLabel(lblShipRegion, rowViewDetail, "ShipRegion", "");

                  if (!rowViewDetail.IsShipViaNull())

                        UiHelper.PopulateLabel(lblShipVia, rowViewDetail.ShippersRow, "CompanyName", "");

 

                  // POPULATE 1-N TABLES

 

                  // Customers

                  mwucIdentifyFK_Orders_Customers.IdentifyRow = rowViewDetail.CustomersRow;

 

                  // Employees

                  mwucIdentifyFK_Orders_Employees.IdentifyRow = rowViewDetail.EmployeesRow;

 

 

                  // POPULATE N-1 PLACEHOLDERS

                  DataView view;

                  view = new DataView(tdsViewDetail.OrderDetails);

                  view.RowFilter = "OrderID=" + this.OrderID.ToString();

                  mwucFK_Order_Details_Orders_ViewMultiple.TableView = view;

 

                  // POPULATE PRIVATE FK PROPERTIES

                  this.CustomerID = rowViewDetail.CustomerID;

                  this.EmployeeID = rowViewDetail.EmployeeID;

                  if (!rowViewDetail.IsShipViaNull())

                        this.ShipVia = rowViewDetail.ShipVia;

            }

 

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

             * PAGE LOAD

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

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

                  // security

                  lblEditRow.Visible = Security_ServiceInterface.PermitAction("Orders", "Write");

                  bool blnOrderDetailsWriteable = Security_ServiceInterface.PermitAction("OrderDetails", "Write");

                  bool blnOrderDetailsReadable = Security_ServiceInterface.PermitAction("OrderDetails", "Read");

 

                  // OrderDetails

                  lblViewFK_Order_Details_Orders.Visible = blnOrderDetailsReadable;

                  plhFK_Order_Details_Orders.Visible = blnOrderDetailsReadable;

                  cmdAddFK_Order_Details_Orders.Visible = blnOrderDetailsReadable;

                  cmdFK_Orders_Customers.Visible = Security_ServiceInterface.PermitAction("Customers", "Read");

                  cmdFK_Orders_Employees.Visible = Security_ServiceInterface.PermitAction("Employees", "Read");

 

                  // load 1-n web user controls

                  // Customers

                  mwucIdentifyFK_Orders_Customers = (CustomersIdentify)LoadControl("WebUserControls/CustomersIdentify.ascx");

                  plhFK_Orders_Customers.Controls.Add(mwucIdentifyFK_Orders_Customers);

 

                  // Employees

                  mwucIdentifyFK_Orders_Employees = (EmployeesIdentify)LoadControl("WebUserControls/EmployeesIdentify.ascx");

                  plhFK_Orders_Employees.Controls.Add(mwucIdentifyFK_Orders_Employees);

 

 

                  // load n-1 web user controls

                  // Order detail

                  cmdAddFK_Order_Details_Orders.Visible = blnOrderDetailsWriteable;

                  mwucFK_Order_Details_Orders_ViewMultiple = (OrderDetailsViewMultiple)LoadControl("WebUserControls/OrderDetailsViewMultiple.ascx");

                  mwucFK_Order_Details_Orders_ViewMultiple.ShowFK_Order_Details_Orders = false;

                  plhFK_Order_Details_Orders.Controls.Add(mwucFK_Order_Details_Orders_ViewMultiple);

 

                  // get Order and related records from the db

                  this.OrderID = Convert.ToInt32(Session["OrderID"]);

                  Orders_ViewDetailDataSet tdsViewDetail = Orders_ServiceInterface.GetViewDetail(this.OrderID);

                  if (tdsViewDetail.Orders.Count < 1)

                        throw new Exception("The Order you specified does not exist.");

 

                  BindControlsToData(tdsViewDetail);

            }

 

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

             * EVENT HOOKUPS

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

            #region Event Hookups

            override protected void OnInit(EventArgs e) {

                  BindLocalControlVariables();

                  InitializeComponent();

                  base.OnInit(e);

            }

 

            private void InitializeComponent() {

                  this.cmdEdit.Click += new System.EventHandler(this.cmdEdit_Click);

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

                  this.cmdFK_Orders_Customers.Click += new System.EventHandler(this.cmdFK_Orders_Customers_Click);

                  this.cmdFK_Orders_Employees.Click += new System.EventHandler(this.cmdFK_Orders_Employees_Click);

                  this.cmdAddFK_Order_Details_Orders.Click += new System.EventHandler(this.cmdAddFK_Order_Details_Orders_Click);

            }

            private void BindLocalControlVariables() {

                  // column controls

                  lblFreight = (Label)Page.FindControl("lblFreight");

                  lblOrderDate = (Label)Page.FindControl("lblOrderDate");

                  lblRequiredDate = (Label)Page.FindControl("lblRequiredDate");

                  lblShipAddress = (Label)Page.FindControl("lblShipAddress");

                  lblShipCity = (Label)Page.FindControl("lblShipCity");

                  lblShipCountry = (Label)Page.FindControl("lblShipCountry");

                  lblShipName = (Label)Page.FindControl("lblShipName");

                  lblShippedDate = (Label)Page.FindControl("lblShippedDate");

                  lblShipPostalCode = (Label)Page.FindControl("lblShipPostalCode");

                  lblShipRegion = (Label)Page.FindControl("lblShipRegion");

                  lblShipVia = (Label)Page.FindControl("lblShipVia");

                  // 1-n controls

                  plhFK_Orders_Customers = (PlaceHolder)Page.FindControl("plhFK_Orders_Customers");

                  lblFK_Orders_Customers = (Label)Page.FindControl("lblFK_Orders_Customers");

                  cmdFK_Orders_Customers = (Button)Page.FindControl("cmdFK_Orders_Customers");

                  plhFK_Orders_Employees = (PlaceHolder)Page.FindControl("plhFK_Orders_Employees");

                  lblFK_Orders_Employees = (Label)Page.FindControl("lblFK_Orders_Employees");

                  cmdFK_Orders_Employees = (Button)Page.FindControl("cmdFK_Orders_Employees");

                  // n-1 controls

                  lblViewFK_Order_Details_Orders = (Label)Page.FindControl("lblViewFK_Order_Details_Orders");

                  plhFK_Order_Details_Orders = (PlaceHolder)Page.FindControl("plhFK_Order_Details_Orders");

                  cmdAddFK_Order_Details_Orders = (Button)Page.FindControl("cmdAddFK_Order_Details_Orders");

                  // page controls

                  cmdEdit = (Button)Page.FindControl("cmdEdit");

                  lblEditRow = (Label)Page.FindControl("lblEditRow");

            }

            #endregion

 

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

             * EVENT HANDLERS

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

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

                  Session["CustomerID"] = this.CustomerID;

                  Response.Redirect("CustomersViewDetail.aspx");

            }

 

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

                  Session["EmployeeID"] = this.EmployeeID;

                  Response.Redirect("EmployeesViewDetail.aspx");

            }

 

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

                  // remove any possible saved state for the add page

                  Session.Remove("OrderDetailsAdd_InsertInputRow");

                  // tell the add page which relationship is being navigated from and what the primary key is

                  Session["OrderDetailsAdd_InsertFK_Order_Details_Orders"] = true;

                  Session["OrderID"] = this.OrderID;

                  // tell the add page to return to the new view detail page when finished & this page upon cancel

                  Session["OrderDetailsAdd_RedirectTo"] = "OrdersViewDetail.aspx";

                  Session["OrderDetailsAdd_RedirectTo_Cancel"] = "OrdersViewDetail.aspx";

                  // redirect to the add page

                  Response.Redirect("OrderDetailsAdd.aspx");

            }

 

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

                  // clear out any old editable records and redirect to the edit page

                  Session.Remove("OrdersEdit_UpdateInputRow");

                  Response.Redirect("OrdersEdit.aspx");

            }

 

 

      }

}