using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class OutcomingOrders : System.Web.UI.Page
{
    private GammaStockInterface
        gammaStockInterface = new GammaStockInterface();
    private PlanningManagement
       planningManager = new PlanningManagement();

    // ------------------------------------------------------------------------------
    // ------------------------------------------------------------------------------

    protected void Page_Load(object sender, EventArgs e)
    {
        //Response.Cache.SetCacheability(HttpCacheability.NoCache);
    }

    // ------------------------------------------------------------------------------
    // ------------------------------------------------------------------------------

    protected void GridViewOrderComponents_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType != DataControlRowType.DataRow)
            return;

        e.Row.Attributes["ID"] = "" + (Int32)DataBinder.Eval(e.Row.DataItem, "ID");

        string componentID = (string)DataBinder.Eval(e.Row.DataItem, "ComponentID");
        string productID = (string)DataBinder.Eval(e.Row.DataItem, "ProductID");

        // ---------------------
        // DESCRIPTION 
        // Put the description into the first cell of the table
        ProdProcessCurrent.ProductInfoCacheRow cachedData =
            gammaStockInterface.GetProductInfoCacheByProductID(productID);

        if (cachedData != null)
        {
            ((Label)e.Row.FindControl("LabelProductID")).Text =
                MessagesUtility.getDescriptionTitled(productID, cachedData.Description);
        }


        // ---------------------
        // DESCRIPTION 
        // Put the description into the first cell of the table
        cachedData = gammaStockInterface.GetProductInfoCacheByProductID(componentID);

        if (cachedData != null)
        {
            ((Label)e.Row.FindControl("LabelComponentID")).Text =
                MessagesUtility.getDescriptionTitled(componentID, cachedData.Description);
        }

        // ---------------------
        // ROW SELECTION
        CommonFuncs.AddWholeRowSelection((System.Web.UI.Control)sender, e.Row, Page);

        // ---------------------
        // ROW SELECTION

        Label labelStateIdentificator = (Label)e.Row.FindControl("LabelStateIdentificator");
            
        if (((Int32)DataBinder.Eval(e.Row.DataItem, "State")) == 
            PlanningManagement.ORDERCOMPONENTS_STATE_INITIAL)
            labelStateIdentificator.BackColor = System.Drawing.Color.FromArgb(220, 200, 150);

    }

    // ------------------------------------------------------------------------------
    // ------------------------------------------------------------------------------

    private String getSelectedID()
    {
        return GridViewOrderComponents.SelectedRow.Attributes["ID"];
    }
    
    // ------------------------------------------------------------------------------
    // ------------------------------------------------------------------------------

    protected void GridViewOrderComponents_SelectedIndexChanged(object sender, EventArgs e)
    {
        DataSourceSingleOrderComponent.SelectParameters["ID"].DefaultValue = getSelectedID();
    }
    
    // ------------------------------------------------------------------------------
    // ------------------------------------------------------------------------------

    protected void DetailsViewSingleOrderComponent_ItemUpdated(object sender, EventArgs e)
    {
        GridViewOrderComponents.DataBind();
    }
        
    // ------------------------------------------------------------------------------
    // ------------------------------------------------------------------------------

    protected void CalendarDateSupply_SelectionChanged(object sender, EventArgs e)
    {
        DetailsView detailsRow = (DetailsView) (((Calendar)sender).Parent.Parent.Parent.Parent);
        ((DropDownList) detailsRow.FindControl("DropDownListState")).SelectedIndex = 1;

    }

    // ------------------------------------------------------------------------------
    // ------------------------------------------------------------------------------

    // DropDownList needs these constants
    public int orderComponentStateInitial = PlanningManagement.ORDERCOMPONENTS_STATE_INITIAL;
    public int orderComponentStateChecked = PlanningManagement.ORDERCOMPONENTS_STATE_CHECKED;

}
