|
using System;
using System.Data;
using System.Web.UI.WebControls;
using Model.Data.Interfaces;
using Presentation;
using Presentation.Interfaces;
/// <remarks>
/// Class Views_ProductsView is our IProductsView. It is the View in the MVP relationship.
/// This view knows about its presenter, and it must attach the presenter.
/// The View initializer (ASPX) creates the MVP relationship.
/// </remarks>
public partial class Views_ProductsView : System.Web.UI.UserControl, IProductsView
{
private ProductsPresenter presenter = null;
#region IProductsView Members
public void AttachPresenter(ProductsPresenter presenter)
{
Check.IsNotNull(presenter, "presenter cannot be null");
this.presenter = presenter;
}
public void SetProducts(IDataReader productsReader)
{
ddlProducts.DataSource = productsReader;
ddlProducts.DataValueField = "ProductID";
ddlProducts.DataTextField ="ProductName";
ddlProducts.DataBind();
ddlProducts.Items.Insert(0, new ListItem("Select Product", "0"));
}
public void SetProductDetails(IProduct product)
{
if (product == null)
{
lblCategoryID.Text = string.Empty;
lblDiscontinued.Text = string.Empty;
lblProductID.Text = string.Empty;
lblProductName.Text = string.Empty;
lblQuantityPerUnit.Text = string.Empty;
lblReorderLevel.Text = string.Empty;
lblSupplierID.Text = string.Empty;
lblUnitPrice.Text = string.Empty;
lblUnitsInStock.Text = string.Empty;
lblUnitsInOrder.Text = string.Empty;
}
else
{
lblCategoryID.Text = product.CategoryID.ToString();
lblDiscontinued.Text = product.Discontinued.ToString();
lblProductID.Text = product.ProductID.ToString();
lblProductName.Text = product.ProductName;
lblQuantityPerUnit.Text = product.QuantityPerUnit;
lblReorderLevel.Text = product.ReorderLevel.ToString();
lblSupplierID.Text = product.SupplierID.ToString();
lblUnitPrice.Text = product.UnitPrice.ToString();
lblUnitsInStock.Text = product.UnitsInStock.ToString();
lblUnitsInOrder.Text = product.UnitsOnOrder.ToString();
}
}
public void SetRefreshTime(DateTime dateTime)
{
lblTime.Text = dateTime.ToString();
}
#endregion
protected void ddlProducts_SelectedIndexChanged(object sender, EventArgs e)
{
presenter.UpdateProductDetails(ddlProducts.SelectedValue);
if(int.Parse(ddlProducts.SelectedValue) > 0)
{
btnEdit.Visible = true;
}
else
{
btnEdit.Visible = false;
}
}
protected void btnEdit_Click(object sender, EventArgs e)
{
presenter.EditProduct(int.Parse(ddlProducts.SelectedValue));
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.