protected void gvAudios_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            int       productAudioId = (int)gvAudios.DataKeys[e.RowIndex]["AudioId"];
            AudioBiz  audioBiz       = new AudioBiz();
            lwg_Audio audio          = audioBiz.GetAudioById(productAudioId);

            if (audio != null)
            {
                audioBiz.DeleteCatalogAudio(productAudioId);
                LWGUtils.ClearOldFile(string.Format("{0}{1}", LWGUtils.GetSoundPath(), audio.SoundFile));
                BindData();
            }
        }
        protected void gvAudios_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "UpdateProductAudio")
            {
                int            index = Convert.ToInt32(e.CommandArgument);
                GridViewRow    row   = gvAudios.Rows[index];
                NumericTextBox txtProductVideoDisplayOrder = row.FindControl("txtProductAudioDisplayOrder") as NumericTextBox;
                HiddenField    hfProductAudioId            = row.FindControl("hdAudioId") as HiddenField;

                int       displayOrder   = txtProductVideoDisplayOrder.Value;
                int       productAudioId = int.Parse(hfProductAudioId.Value);
                AudioBiz  audioBiz       = new AudioBiz();
                lwg_Audio audio          = audioBiz.GetAudioById(productAudioId);
                if (audio != null)
                {
                    audio.DisplayOrder = displayOrder;
                    audioBiz.UpdateCatalogAudio(audio);
                }

                BindData();
            }
        }
        protected void BindData()
        {
            var product = ProductManager.GetProductById(this.ProductId);

            if (product != null)
            {
                ctrlProductRating.Visible = product.AllowCustomerRatings;
                //Get product extend information
                CatalogBiz  cService = new CatalogBiz();
                lwg_Catalog catalog  = cService.GetByID(product.ProductId);

                lProductName.Text      = Server.HtmlEncode(product.Name);
                lProductName1.Text     = Server.HtmlEncode(product.Name);
                lShortDescription.Text = product.ShortDescription;
                lFullDescription.Text  = product.FullDescription;
                lTableofContents.Text  = catalog.TableofContents;
                ltrSubtitle.Text       = catalog.Subtitle;

                var productPictures = product.ProductPictures;
                if (productPictures.Count > 1)
                {
                    defaultImage.ImageUrl        = PictureManager.GetPictureUrl(productPictures[0].PictureId, SettingManager.GetSettingValueInteger("Media.Product.DetailImageSize", 300));
                    defaultImage.ToolTip         = String.Format(GetLocaleResourceString("Media.Product.ImageAlternateTextFormat"), product.Name);
                    defaultImage.AlternateText   = String.Format(GetLocaleResourceString("Media.Product.ImageAlternateTextFormat"), product.Name);
                    lvProductPictures.DataSource = productPictures;
                    lvProductPictures.DataBind();
                }
                else if (productPictures.Count == 1)
                {
                    defaultImage.ImageUrl      = PictureManager.GetPictureUrl(productPictures[0].PictureId, SettingManager.GetSettingValueInteger("Media.Product.DetailImageSize", 300));
                    defaultImage.ToolTip       = String.Format(GetLocaleResourceString("Media.Product.ImageAlternateTextFormat"), product.Name);
                    defaultImage.AlternateText = String.Format(GetLocaleResourceString("Media.Product.ImageAlternateTextFormat"), product.Name);
                    lvProductPictures.Visible  = false;
                }
                else
                {
                    defaultImage.ImageUrl      = PictureManager.GetDefaultPictureUrl(SettingManager.GetSettingValueInteger("Media.Product.DetailImageSize", 300));
                    defaultImage.ToolTip       = String.Format(GetLocaleResourceString("Media.Product.ImageAlternateTextFormat"), product.Name);
                    defaultImage.AlternateText = String.Format(GetLocaleResourceString("Media.Product.ImageAlternateTextFormat"), product.Name);
                    lvProductPictures.Visible  = false;
                }



                if (catalog != null)
                {
                    lProductName.Text = catalog.CatalogNumber + " - " + lProductName.Text;
                    //lProductName1.Text = catalog.TitleDisplay;
                    string strCompare = "http://";

                    AudioBiz audioBiz = new AudioBiz();
                    //lwg_Audio audio = audioBiz.GetSoundFile(catalog.CatalogId);
                    //if (audio != null)
                    //{
                    //    if (audio.SoundFile.TrimStart().StartsWith(strCompare))
                    //    {
                    //        hplListenToTheSample.NavigateUrl = audio.SoundFile;
                    //    }
                    //    else
                    //    {
                    //        hplListenToTheSample.NavigateUrl = string.Format("{0}{1}", LWGUtils.GetSoundPath(), audio.SoundFile);
                    //    }

                    //}
                    List <lwg_Audio> audioList = audioBiz.GetAllSoundFiles(catalog.CatalogId);
                    if (audioList.Count > 0)
                    {
                        dlListenMusics.DataSource = audioList;
                        dlListenMusics.DataBind();
                        divListenToTheSample.Attributes.Add("style", "display:block;");
                    }

                    if (!string.IsNullOrEmpty(catalog.PDF))
                    {
                        hplPreviewMusic.NavigateUrl = string.Format("{0}{1}", LWGUtils.GetPDFPath(), catalog.PDF);
                        divPreviewMusic.Attributes.Add("style", "display:block;");
                    }


                    if (catalog.lwg_PersonInRole != null && catalog.lwg_PersonInRole.Count > 0)
                    {
                        StringBuilder sb = new StringBuilder();
                        foreach (lwg_PersonInRole catComposer in catalog.lwg_PersonInRole.OrderBy(p => p.RoleId))
                        {
                            if (catComposer.RoleId == LWGUtils.COMPOSER_ROLE_ID)
                            {
                                sb.Insert(0, string.Format("{0} ({1}), ", catComposer.lwg_Person.NameDisplay, catComposer.lwg_Role.Name));
                            }
                            else
                            {
                                sb.Append(catComposer.lwg_Person.NameDisplay).Append(" (" + catComposer.lwg_Role.Name).Append("), ");
                            }
                        }

                        string composer = sb.ToString();
                        if (composer.Length > 0)
                        {
                            try
                            {
                                composer = composer.Substring(0, composer.Length - 2);
                            }
                            catch
                            {
                                ;
                            }
                        }
                        ltrComposer.Text = "by " + composer;
                    }
                    else
                    {
                        ltrComposer.Text = string.Empty;
                    }

                    if (product.ProductVariants.Count > 0)
                    {
                        this.ltrPrice.Text = string.Format("{0:c}", product.ProductVariants[0].Price);
                        productVariantRepeater.DataSource = product.ProductVariants.OrderBy(pv => pv.Price);
                        productVariantRepeater.DataBind();
                    }
                    else
                    {
                        this.ltrPrice.Text = string.Format("{0:c}", "0");
                    }

                    this.ltrDuration.Text = catalog.Duration;
                    if (catalog.lwg_Instrumental != null)
                    {
                        this.ltrInstrumention.Text = catalog.lwg_Instrumental.LongName;
                    }

                    this.ltrYear.Text   = catalog.Year;
                    this.ltrPeriod.Text = string.Empty;

                    List <lwg_PeriodMapping> lstPeriod = new PeriodBiz().GetListPeriodMappingByCatalogID(ProductId);
                    if (lstPeriod != null && lstPeriod.Count > 0)
                    {
                        foreach (lwg_PeriodMapping lwg in lstPeriod)
                        {
                            this.ltrPeriod.Text += lwg.lwg_Period.Name + ", ";
                        }
                        this.ltrPeriod.Text = this.ltrPeriod.Text.Substring(0, this.ltrPeriod.Text.Length - 2);
                    }

                    if (catalog.lwg_CatalogGenre != null && catalog.lwg_CatalogGenre.Count > 0)
                    {
                        StringBuilder sb = new StringBuilder();
                        foreach (lwg_CatalogGenre catalogGenre in catalog.lwg_CatalogGenre)
                        {
                            sb.Append(catalogGenre.lwg_Genre.Name).Append(", ");
                        }

                        string genre = sb.ToString();
                        if (genre.Length > 0)
                        {
                            try
                            {
                                genre = genre.Substring(0, genre.Length - 2);
                            }
                            catch
                            {
                                ;
                            }
                        }

                        this.ltrGenre.Text    = genre;
                        this.lblGenre.Visible = (genre != ""); // hide when blank field
                    }

                    this.ltrOrigPrint.Text = string.Empty;
                    List <lwg_ReprintSourceMapping> lstReprintSourceMapping = new ReprintSourceBiz().GetListReprintSourceMappingByCatalogID(ProductId);
                    if (lstReprintSourceMapping != null && lstReprintSourceMapping.Count > 0)
                    {
                        foreach (lwg_ReprintSourceMapping lwg in lstReprintSourceMapping)
                        {
                            this.ltrOrigPrint.Text += lwg.lwg_ReprintSource.Name + ", ";
                        }
                        this.ltrOrigPrint.Text = this.ltrOrigPrint.Text.Substring(0, this.ltrOrigPrint.Text.Length - 2);
                    }


                    if (product.ProductCategories != null && product.ProductCategories.Count > 0)
                    {
                        StringBuilder sb = new StringBuilder();
                        foreach (ProductCategory productCat in product.ProductCategories)
                        {
                            sb.Append(productCat.Category.Name).Append(", ");
                        }

                        string category = sb.ToString();
                        if (category.Length > 0)
                        {
                            try
                            {
                                category = category.Substring(0, category.Length - 3);
                            }
                            catch
                            {
                                ;
                            }
                        }
                        this.ltrCategory.Text = category;
                    }

                    this.ltrSeries.Text = string.Empty;
                    List <lwg_SeriesMapping> lstSeriesMapping = new SeriesBiz().GetListSeriesMappingByCatalogID(ProductId);
                    if (lstSeriesMapping != null && lstSeriesMapping.Count > 0)
                    {
                        foreach (lwg_SeriesMapping lwg in lstSeriesMapping)
                        {
                            this.ltrSeries.Text += lwg.lwg_Series.Name + ", ";
                        }
                        this.ltrSeries.Text = this.ltrSeries.Text.Substring(0, this.ltrSeries.Text.Length - 2);
                    }

                    this.ltrText.Text          = catalog.TextLang;
                    this.lGrade.Text           = catalog.Grade;
                    this.ltrCopyrightYear.Text = catalog.CopyrightYear;
                    InitLabels(); // hide if blank field

                    // add Grade Product Info
                }
                else
                {
                }
            }
            else
            {
                this.Visible = false;
            }
        }
        protected void btnUploadProductAudio_Click(object sender, EventArgs e)
        {
            try
            {
                Product product = ProductManager.GetProductById(this.ProductId);
                if (product != null)
                {
                    CatalogBiz  catalogBiz = new CatalogBiz();
                    lwg_Catalog catalog    = catalogBiz.GetByID(product.ProductId);
                    if (catalog == null)
                    {
                        catalog               = new lwg_Catalog();
                        catalog.CatalogId     = product.ProductId;
                        catalog.CatalogNumber = string.Empty;
                        catalog.Subtitle      = string.Empty;
                        catalog.TextLang      = string.Empty;
                        catalog.PTSprodcode   = string.Empty;
                        catalog.KaldbNumber   = string.Empty;
                        catalog.SoundIcon     = string.Empty;
                        catalog.PDF           = string.Empty;
                        catalog.pages         = string.Empty;
                        catalogBiz.SaveCatalog(catalog);
                    }
                    List <lwg_Audio> audioList = new List <lwg_Audio>();
                    lwg_Audio        audio;
                    string           error = string.Empty;
                    string           path  = SaveSoundFile(fuProductAudio1, ref error);
                    if (string.IsNullOrEmpty(error))
                    {
                        audio              = new lwg_Audio();
                        audio.CatalogId    = this.ProductId;
                        audio.DisplayOrder = txtProductAudioDisplayOrder1.Value;
                        audio.SoundFile    = path;

                        audioList.Add(audio);
                    }
                    else
                    {
                        if (error == LWG.Business.LWGUtils.INVALID_FILE_EXTENSION)
                        {
                            throw new Exception("Invalid file extension.");
                        }
                        else
                        if (error == LWG.Business.LWGUtils.INVALID_FILE_SIZE)
                        {
                            throw new Exception("Invalid file size");
                        }
                    }
                    path = SaveSoundFile(fuProductAudio2, ref error);
                    if (string.IsNullOrEmpty(error))
                    {
                        audio              = new lwg_Audio();
                        audio.CatalogId    = this.ProductId;
                        audio.DisplayOrder = txtProductAudioDisplayOrder2.Value;
                        audio.SoundFile    = path;

                        audioList.Add(audio);
                    }
                    else
                    {
                        if (error == LWG.Business.LWGUtils.INVALID_FILE_EXTENSION)
                        {
                            throw new Exception("Invalid file extension.");
                        }
                        else
                        if (error == LWG.Business.LWGUtils.INVALID_FILE_SIZE)
                        {
                            throw new Exception("Invalid file size");
                        }
                    }
                    path = SaveSoundFile(fuProductAudio3, ref error);
                    if (string.IsNullOrEmpty(error))
                    {
                        audio              = new lwg_Audio();
                        audio.CatalogId    = this.ProductId;
                        audio.DisplayOrder = txtProductAudioDisplayOrder3.Value;
                        audio.SoundFile    = path;

                        audioList.Add(audio);
                    }
                    else
                    {
                        if (error == LWG.Business.LWGUtils.INVALID_FILE_EXTENSION)
                        {
                            throw new Exception("Invalid file extension.");
                        }
                        else
                        if (error == LWG.Business.LWGUtils.INVALID_FILE_SIZE)
                        {
                            throw new Exception("Invalid file size");
                        }
                    }
                    // add videos
                    if (audioList.Count > 0)
                    {
                        AudioBiz audioBiz = new AudioBiz();
                        audioBiz.AddCatalogAudio(audioList);

                        BindData();
                    }
                }
            }
            catch (Exception exc)
            {
                ProcessException(exc);
            }
        }