private void Page_Load(object sender, System.EventArgs e)
		{
			this._module = base.Module as ShopModule;
			// Add the CSS
			string cssfile = String.Format("{0}Modules/Shop/Images/Standard/shop.css",UrlHelper.GetApplicationPath());
			this.RegisterStylesheet("shopcss",cssfile);

			this._origProduct		= this._module.GetShopProductById(this._module.CurrentShopProductId);
			this._shopShop	= this._module.GetShopById(this._module.CurrentShopId);
			this._module.CurrentShopCategoryId	= this._shopShop.CategoryId;

            this.BindTopFooter();
            base.LocalizeControls();
            this.ltOrigProduct.Text = this._origProduct.Message;
			this.BindJS();
			this.BindEmoticon();

			if(!this.IsPostBack)
			{
				if(this._module.QuoteProduct == 1)
				{
					this.txtMessage.Text = "[quote]" + TextParser.HtmlToShopCode(this._origProduct.Message,this._module) + "[/quote]";
				}
			}
		}
        protected void btnSave_Click1(object sender, EventArgs e)
        {
            if (this.Page.IsValid)
            {
                Cuyahoga.Core.Domain.User tUser = this.Page.User.Identity as User;
                FileUpload postedFile = this.FileUploadDocument;
                ShopImage fFile;

                ShopProduct tShopProduct = this._module.GetShopProductById(this._module.CurrentShopProductId);

                if (tShopProduct == null)
                {
                    tShopProduct = new ShopProduct();
                    tShopProduct.ShopId = this._module.CurrentShopId;
                    tShopProduct.DateCreated = DateTime.Now;
                    if (tUser != null)
                    {
                        tShopProduct.UserId = tUser.Id;
                        tShopProduct.UserName = tUser.UserName;
                    }
                    else
                    {
                        tShopProduct.UserId = 0;
                        tShopProduct.UserName = base.GetText("GUEST");
                    }
                }
                tShopProduct.DateModified = DateTime.Now;
                tShopProduct.Message = TextParser.ShopCodeToHtml(this.txtMessage.Text, this._module);
                tShopProduct.Title = this.txtSubject.Text;
                tShopProduct.Price = decimal.Parse(this.txtPrice.Text);

                this._module.SaveShopProduct(tShopProduct);

                // Save attachement
                if (postedFile.PostedFile.ContentLength > 0)
                {
                    try
                    {
                        //TODO: Manage Images
                        this.CheckValidFile(this.FileUploadDocument);
                        fFile = this.SaveAttachment(tShopProduct, this.FileUploadDocument);
                        //tShopProduct.AttachmentId = fFile.Id;
                        this._module.SaveShopProduct(tShopProduct);
                    }
                    catch (Exception ex)
                    {
                        this.pnlUploadError.Visible = true;
                        this.ltlUploadError.Text = ex.Message;
                        this._module.DeleteShopProduct(tShopProduct);
                        return;
                    }
                }
                // Update number of products and number of posts
                //TODO: Modify comments or product publishing
                ShopShop tShopShop = this._module.GetShopById(this._module.CurrentShopId);
                tShopShop.LastPublished = DateTime.Now;
                tShopShop.LastPublishUserName = tShopProduct.UserName;
                tShopShop.LastProductId = tShopProduct.Id;
                this._module.SaveShop(tShopShop);

                Response.Redirect(String.Format("{0}/ShopView/{1}", UrlHelper.GetUrlFromSection(this._module.Section), this._module.CurrentShopId));
            }
        }
		private ShopImage SaveAttachment(ShopProduct product, FileUpload file)
		{
			ShopImage imgProductImage = new ShopImage();
			if(file.PostedFile == null || file.PostedFile.FileName.Trim().Length==0 || file.PostedFile.ContentLength==0)
				return null;

			string filename = file.PostedFile.FileName;

            imgProductImage.OrigImageName = filename;
            imgProductImage.ShopImageName = filename;
            imgProductImage.ImageSize = file.PostedFile.ContentLength;
            imgProductImage.ContentType = file.PostedFile.ContentType;
            imgProductImage.ProductId = product.Id;
            imgProductImage.Data = file.FileBytes;

			try
			{
                this._module.SaveShopImage(imgProductImage);


			}
			catch(Exception ex)
			{
				throw new Exception("Unable to save image ",ex);
			}
            return imgProductImage;

		}
        public virtual void DeleteShopProduct(ShopProduct product)
		{
            ISession session = this._sessionManager.OpenSession();
            NHibernate.ITransaction tx = session.BeginTransaction();
            try
            {
                foreach (Object obj in product.Images)
                {
                    session.Delete((ShopImage)obj);
                }
                foreach (Object obj in product.CommentList)
                {
                    session.Delete((ShopComment)obj);
                }
                session.Delete(product);
                tx.Commit();
                session.Close();
            }
			catch (Exception ex)
			{
                tx.Rollback();
                throw new Exception("Unable to delete Shop product" + "<br>" + ex.Message + "<br>" + ex.InnerException, ex);
			}
		}
        /// <summary>
        /// Get the number of comments.
        /// </summary>
        /// <returns></returns>
        public IList GetCommentCount(ShopProduct product)
        {
            ISession session = this._sessionManager.OpenSession();
            try
            {
                string hql;
                hql = "select count(comment.Id) from ShopComment comment Where comment.ProductId = :productid";
                IQuery q = session.CreateQuery(hql);
                q.SetString("productid", product.Id.ToString());

                IList commentlist = q.List();


                return commentlist;
            }
            catch (Exception ex)
            {
                throw new Exception("Unable to get number of comments", ex);
            }
        }
        public virtual void SaveShopProduct(ShopProduct shopproduct)
		{
            ISession session = this._sessionManager.OpenSession();
            NHibernate.ITransaction tx = session.BeginTransaction();
            try
            {
                session.SaveOrUpdate(shopproduct);
                tx.Commit();
                session.Close(); 
			}
			catch (Exception ex)
			{
                tx.Rollback();
                throw new Exception("Unable to save Shop product" + "<br>" + ex.Message + "<br>" + ex.InnerException, ex);
			}
		}
		private ShopImage SaveAttachment(ShopProduct product, HtmlInputFile file)
		{
			ShopImage imgProductImage = new ShopImage();
			if(file.PostedFile==null || file.PostedFile.FileName.Trim().Length==0 || file.PostedFile.ContentLength==0)
				return null;

			string sUpDir = Server.MapPath(UrlHelper.GetApplicationPath() + "/Modules/Shop/Attach/");
			string filename = file.PostedFile.FileName;

			if(!System.IO.Directory.Exists(sUpDir))
			{
				System.IO.Directory.CreateDirectory(sUpDir);
			}

			int pos = filename.LastIndexOfAny(new char[]{'/','\\'});
			if (pos >= 0)
				filename = filename.Substring(pos+1);

            string newfilename = String.Format("{0}{1}.{2}.{3}", sUpDir, this._shopShop.Id , product.Id, filename);
			file.PostedFile.SaveAs(newfilename);
            imgProductImage.OrigImageName = filename;
            imgProductImage.ShopImageName = newfilename;
            imgProductImage.ImageSize = file.PostedFile.ContentLength;
            imgProductImage.ContentType = file.PostedFile.ContentType;
            imgProductImage.ProductId = product.Id;

			try
			{
                this._module.SaveShopImage(imgProductImage);


			}
			catch(Exception ex)
			{
				throw new Exception("Unable to save image ",ex);
			}
            return imgProductImage;

		}
 protected void lbtnBuy_Click(object sender, EventArgs e)
 {
     
     if (this._module.CurrentShopOrder == null)
     {
         ShopOrder order = new ShopOrder();
         Cuyahoga.Core.Domain.User currentUser = Context.User.Identity as Cuyahoga.Core.Domain.User;
         order.Owner = currentUser;
         order.OrderState = this._module.GetOrderState(1);
         this._module.SaveOrder(order);
         this._module.CurrentShopOrder = order;
     }
     this._shopProduct = this._module.GetShopProductById(this._module.CurrentShopProductId);
     ShopOrderLine orderline = new ShopOrderLine();
     orderline.Product = this._shopProduct;
     orderline.ShopOrder = this._module.CurrentShopOrder;
     this._module.CurrentShopOrder.OrderLines.Add(orderline);
     this._module.SaveOrder(this._module.CurrentShopOrder);
 }
		private void BindShopProduct()
		{
			this._shopProduct	= this._module.GetShopProductById(this._module.CurrentShopProductId);
			this._shopProduct.Views++;
			this._module.SaveShopProduct(this._shopProduct);
			this.lblTitle.Text	= this._shopProduct.Title;

			if(this._shopProduct.UserId == 0)
			{
				this.hplAuthor.Text = "Guest";
				this.hplAuthor.CssClass = "shop";
				this.lblUserInfo.Text	= "&nbsp;";
			}
			else
			{
				this.hplAuthor.Text			= this._shopProduct.UserName;
				this.hplAuthor.NavigateUrl	= String.Format("{0}/ShopViewProfile/{1}",UrlHelper.GetUrlFromSection(this._module.Section), this._shopProduct.UserId);
				this.hplAuthor.CssClass		= "shop";
				this.lblUserInfo.Text		= "&nbsp;";
			}
			string msg				= this._shopProduct.Message;


			this.lblMessages.Text	= this._shopProduct.Message;
            this.lblPrice.Text = String.Format("{0:c}",this._shopProduct.Price);
			this.lblPublishedDate.Text = TimeZoneUtil.AdjustDateToUserTimeZone(this._shopProduct.DateCreated, this.Page.User.Identity).ToLongDateString() + " " +TimeZoneUtil.AdjustDateToUserTimeZone(this._shopProduct.DateCreated, this.Page.User.Identity).ToLongTimeString();            
		}