using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace CitySunlight.Product
{
    public partial class ProductShow : System.Web.UI.Page
    {
        public String type;
        public String username;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["username"] != null)
            {
                username = Session["username"].ToString();
            }
        }
        protected String ShowProduct()
        {
            String html = "";
            int id = HttpUtils.getQueryString("id").ToInt();
            if (ProductManager.isExist(id))
                html = GetProductInfo(id);
            else
                html = "<span style=\"color:red\">当前ID的产品不存在或已被删除!</span>";
            return html;
        }

        private string GetProductInfo(int id)
        {
            String html = "";
            String name = ProductManager.GetProductInfo(id, ProductManager.Info.ItemName);
            String url = ProductManager.GetProductInfo(id, ProductManager.Info.PicUrl);
            String picurl = String.Format("<img src=\"../Picture/{0}\"alt=\"\" width=\"256\" height=\"256\"/>", url);
            String price = ProductManager.GetProductInfo(id, ProductManager.Info.Price);
            String amount = ProductManager.GetProductInfo(id, ProductManager.Info.Amount);
            String user = ProductManager.GetProductInfo(id, ProductManager.Info.UserName);
            String edit = "<a href=\"/Product/ProductEdit.aspx?id=" + id + "&type=edit\" >编辑</a>";
            String classname = ProductClassManager.getClassName(int.Parse(ProductManager.GetProductInfo(id, ProductManager.Info.Class)));
            html += "<table align=\"center\">";
            html += "<tr>";
            html += HttpUtils.addTd(picurl, 3, 3);
            html += HttpUtils.addTd(String.Format("名称: {0}", name));
            html += user == username ? HttpUtils.addTd(edit) : "";
            html += "<tr>";
            html += HttpUtils.addTd(String.Format("分类: {0}", classname));
            html += "</tr><tr>";
            html += HttpUtils.addTd(String.Format("库存: {0}", amount));
            html += "</tr><tr>";
            html += HttpUtils.addTd();
            html += HttpUtils.addTd(String.Format("价格: {0}", price));
            html += HttpUtils.addTd();
            html += HttpUtils.addTd("<a href=\"#\">购买</a>");
            html += "</tr>";
            html += "</table>";
            return html;
        }

    }
}