コード例 #1
0
    /// <summary>
    /// Displays the information of the downloadable item
    /// </summary>
    /// <param name="download"></param>
    private void DisplayDownloadInfo(DownloadableItem download)
    {
        if (null != download)
        {
            lblDownloadIdCaption.Text = string.Format("Download Id : {0}", download.DownloadId);
            if (CommonLogic.FileExists(string.Format("images/icon/{0}.png", download.Extension)))
            {
                imgFileType.ImageUrl = string.Format("images/icon/{0}.png", download.Extension);
            }
            else
            {
                imgFileType.ImageUrl = "images/icon/defaultfile.png";
            }

            lblFileNameCaption.Text = string.Format("File Name: {0}", download.FileName);
            lblContentType.Text     = string.Format("Content Type: {0}", download.ContentType);
            lblDownloadCaption.Text = string.Format("This file has been downloaded {0} times", download.GetNumberOfDownloads());
            lblDownloadSize.Text    = string.Format("File size: {0} kb", download.ContentLength);
            if (download.IsPhysicalFileExisting())
            {
                lblActiveCaption.Text = string.Format("This file is {0}", download.IsActive ? "active" : "inactive");
            }
            else
            {
                lblActiveCaption.Text = "This file is missing!!!";
            }

            pnlInfo.Visible = true;
        }
        else
        {
            pnlInfo.Visible = false;
        }
    }
コード例 #2
0
    protected void Grid_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (DataControlRowType.DataRow == e.Row.RowType)
        {
            // check if the download id is null
            DbDataRecord currentRow = e.Row.DataItem as DbDataRecord;
            if (null != currentRow)
            {
                int    counter  = (int)currentRow["Counter"];
                string itemCode = (string)currentRow["ItemCode"];


                // File Name Cell
                DataControlFieldCell fileNameCell = e.Row.Controls[0] as DataControlFieldCell;
                string fileNameText = string.Empty;
                if (currentRow["FileName"] == DBNull.Value ||
                    currentRow["FileName"] is string &&
                    string.IsNullOrEmpty((string)currentRow["FileName"]))
                {
                    fileNameText = "[UnAssigned]";
                }
                else
                {
                    fileNameText = Security.HtmlEncode((string)currentRow["FileName"]);
                }

                fileNameCell.Text = fileNameText;


                //Description
                DataControlFieldCell descriptionCell = e.Row.Controls[3] as DataControlFieldCell;
                string descriptionText = string.Empty;
                if (currentRow["WebDescription"] == DBNull.Value ||
                    currentRow["WebDescription"] is string &&
                    string.IsNullOrEmpty((string)currentRow["WebDescription"]))
                {
                    descriptionText = (string)currentRow["ItemDescription"];
                }
                else
                {
                    descriptionText = (string)currentRow["WebDescription"];
                }
                descriptionCell.Text = Security.HtmlEncode(descriptionText);

                // DownloadId Cell
                DataControlFieldCell downloadCell = e.Row.Controls[4] as DataControlFieldCell;

                string downloadText = string.Empty;
                if (currentRow["DownloadId"] == DBNull.Value ||
                    currentRow["DownloadId"] is string &&
                    string.IsNullOrEmpty((string)currentRow["DownloadId"]))
                {
                    downloadText = "Upload file";
                }
                else
                {
                    downloadText = (string)currentRow["DownloadId"];
                }

                downloadCell.Text = string.Format("<a href=\"DownloadableItem.aspx?id={0}\">{1}</a>", counter, Security.HtmlEncode(downloadText));


                // Status Cell
                DataControlFieldCell statusCell = e.Row.Controls[6] as DataControlFieldCell;
                DownloadableItem     download   = DownloadableItem.FindByItemCode(itemCode);

                string statusText = string.Empty;

                if (null == download)
                {
                    statusText = "N/A";
                }
                else if (download.IsPhysicalFileExisting())
                {
                    if (currentRow["IsActive"] == DBNull.Value)
                    {
                        statusText = "N/A";
                    }
                    else if (currentRow["IsActive"] is bool)
                    {
                        statusText = CommonLogic.IIF((bool)currentRow["IsActive"], "A", "I");
                    }
                    else
                    {
                        statusText = "?";
                    }
                }
                else
                {
                    statusText = "?";
                }

                statusCell.Text = Security.HtmlEncode(statusText);
            }
        }
    }