コード例 #1
0
 protected void FileGrid_RowDataBound(object sender, GridViewRowEventArgs e)
 {
     if (e.Row.RowType == DataControlRowType.DataRow)
     {
         FileDigitalGood dataItem  = e.Row.DataItem as FileDigitalGood;
         Repeater        goodsList = (Repeater)e.Row.FindControl("DigitalGoodsList");
         if (dataItem != null && dataItem.DigitalGoods != null && goodsList != null)
         {
             goodsList.DataSource = dataItem.DigitalGoods;
             goodsList.DataBind();
         }
     }
 }
コード例 #2
0
        protected void RenameButton_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                string sourceFileName = Path.GetFileName(RenameFileName.Text);
                string sourcePath     = Path.Combine(_DigitalGoodPath, sourceFileName);
                if (File.Exists(sourcePath))
                {
                    // FIGURE OUT THE TARGET FILENAME
                    string targetFileName = Path.GetFileName(RenameNewFilename.Text);
                    string targetFolder   = Path.Combine(_BaseDigitalGoodPath, RenameFileNewFolder.SelectedValue);
                    string targetPath     = Path.Combine(targetFolder, targetFileName);

                    if (FileHelper.IsExtensionValid(targetFileName, AbleContext.Current.Store.Settings.FileExt_DigitalGoods))
                    {
                        if (!File.Exists(targetPath) || RenameOverwrite.Checked)
                        {
                            // IF NECESSARY, REMOVE THE EXISTING TARGET FILE FROM DISK AND IN-MEMORY LIST
                            if (File.Exists(targetPath))
                            {
                                int targetIndex = IndexOfFile(targetFileName);
                                if (targetIndex > -1)
                                {
                                    _FileList.RemoveAt(targetIndex);
                                }
                                File.Delete(targetPath);
                            }
                            // MOVE THE FILE TO THE NEW NAME
                            File.Move(sourcePath, targetPath);
                            // UPDATE THE FILE IN THE LIST
                            int index = IndexOfFile(sourceFileName);
                            if (index > -1)
                            {
                                FileDigitalGood fdg = _FileList[index];
                                // SEE IF WE NEED TO UPDATE THE ASSOCIATED DIGITAL GOODS
                                if (UpdateDigitalGoodsOnRename.Checked)
                                {
                                    IList <DigitalGood> goods = GetFileDigitalGoods(sourceFileName);
                                    foreach (DigitalGood dg in goods)
                                    {
                                        dg.ServerFileName = RenameFileNewFolder.SelectedValue + targetFileName;
                                        if (dg.FileName == sourceFileName)
                                        {
                                            dg.FileName = targetFileName;
                                        }
                                        dg.Save();
                                    }
                                }
                                else
                                {
                                    fdg.DigitalGoods = null;
                                }
                                fdg.FileName = targetFileName;
                                RebindFileGrid();
                            }
                        }
                        else
                        {
                            CustomValidator overwrite = new CustomValidator();
                            overwrite.IsValid           = false;
                            overwrite.ControlToValidate = "RenameNewFileName";
                            overwrite.ErrorMessage      = "The target file '" + targetFileName + "' already exists.  Either allow overwrite or use an alternate file name.";
                            overwrite.Text            = "*";
                            overwrite.ValidationGroup = "Rename";
                            phRenameOverwrite.Controls.Add(overwrite);
                            RenamePopup.Show();
                        }
                    }
                    else
                    {
                        CustomValidator filetype = new CustomValidator();
                        filetype.IsValid           = false;
                        filetype.ControlToValidate = "RenameNewFileName";
                        filetype.ErrorMessage      = "The target file '" + targetFileName + "' does not have a valid file extension.";
                        filetype.Text            = "*";
                        filetype.ValidationGroup = "Rename";
                        phRenameFileExtensions.Controls.Add(filetype);
                        RenamePopup.Show();
                    }
                }
            }
            else
            {
                RenamePopup.Show();
            }
        }
コード例 #3
0
        protected void AddButton_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                if (!DigitalGoodNameExists(Name.Text))
                {
                    string      fileName = Path.GetFileName(ServerFileName.Text);
                    DigitalGood dg       = new DigitalGood();
                    dg.ServerFileName   = _RelativeDigitalGoodPath + fileName;
                    dg.Name             = Name.Text;
                    dg.FileSize         = new FileInfo(Path.Combine(_DigitalGoodPath, fileName)).Length;
                    dg.FileName         = string.IsNullOrEmpty(DownloadName.Text) ? fileName : DownloadName.Text;
                    dg.ActivationModeId = AlwaysConvert.ToByte(ActivationMode.SelectedValue);
                    dg.MaxDownloads     = AlwaysConvert.ToByte(MaxDownloads.Text);
                    int tempDays    = AlwaysConvert.ToInt(ActivationTimeoutDays.Text);
                    int tempHours   = AlwaysConvert.ToInt(ActivationTimeoutHours.Text);
                    int tempMinutes = AlwaysConvert.ToInt(ActivationTimeoutMinutes.Text);
                    if ((tempDays > 0) || (tempHours > 0) || (tempMinutes > 0))
                    {
                        dg.ActivationTimeout = string.Format("{0},{1},{2}", tempDays, tempHours, tempMinutes);
                    }
                    else
                    {
                        dg.ActivationTimeout = string.Empty;
                    }
                    tempDays    = AlwaysConvert.ToInt(DownloadTimeoutDays.Text);
                    tempHours   = AlwaysConvert.ToInt(DownloadTimeoutHours.Text);
                    tempMinutes = AlwaysConvert.ToInt(DownloadTimeoutMinutes.Text);
                    if ((tempDays > 0) || (tempHours > 0) || (tempMinutes > 0))
                    {
                        dg.DownloadTimeout = string.Format("{0},{1},{2}", tempDays, tempHours, tempMinutes);
                    }
                    else
                    {
                        dg.DownloadTimeout = string.Empty;
                    }
                    dg.Save();

                    // SEE WHETHER WE ARE SUPPOSED TO EDIT AFTER SAVING
                    if (((WebControl)sender).ID == "AddAndEditButton")
                    {
                        // REDIRECT TO THE EDIT PAGE
                        Response.Redirect("~/Admin/DigitalGoods/EditDigitalGood.aspx?DigitalGoodId=" + dg.Id);
                    }

                    // UPDATE THE FILE LIST
                    int index = IndexOfFile(fileName);
                    if (index > -1)
                    {
                        FileDigitalGood fdg = _FileList[index];
                        if (fdg.DigitalGoods == null)
                        {
                            fdg.DigitalGoods = new List <DigitalGood>();
                        }
                        fdg.DigitalGoods.Add(dg);
                    }

                    // REBIND THE FILE GRID
                    BindFileGrid();
                }
                else
                {
                    CustomValidator uniqueName = new CustomValidator();
                    uniqueName.IsValid           = false;
                    uniqueName.ControlToValidate = "Name";
                    uniqueName.ErrorMessage      = "The specified name already exists.  You must use an alternate name.";
                    uniqueName.Text            = "*";
                    uniqueName.ValidationGroup = "Add";
                    phUniqueName.Controls.Add(uniqueName);
                    AddPopup.Show();
                }
            }
            else
            {
                AddPopup.Show();
            }
        }