示例#1
0
        protected void Initialize(List <AttachFileForFrontend> attachFiles)
        {
            foreach (AttachFileForFrontend attFile in attachFiles)
            {
                string attSubject    = attFile.AttSubject;
                int    sortNo        = attFile.SortNo.Value;
                string fileSavedName = attFile.FileSavedName;

                //找出同名AttInfo
                AttInfo curAttInfo = attList.Find(x => x.AttSubject == attSubject);

                if (curAttInfo == null)
                {
                    curAttInfo            = new AttInfo();
                    curAttInfo.AttSubject = attSubject;
                    curAttInfo.SortNo     = sortNo;

                    attList.Add(curAttInfo);
                }

                string   ext     = Path.GetExtension(fileSavedName);
                DateTime?mdfDate = attFile.MdfDate;

                if (!mdfDate.HasValue)
                {
                    mdfDate = attFile.PostDate.Value;
                }

                // add file data
                FileData curFile = new FileData()
                {
                    AttId     = attFile.AttId,
                    SortNo    = attFile.SortNo.Value,
                    FileName  = fileSavedName,
                    FileExt   = ext,
                    FileSize  = attFile.FileSize,
                    ReadCount = attFile.ReadCount,
                    MdfDate   = mdfDate.Value
                };

                if (curFile.FileSize > 1024)
                {
                    curFile.FileSizeDesc = string.Format("{0:#,0.##} MB", curFile.FileSize / 1024f);
                }
                else
                {
                    curFile.FileSizeDesc = string.Format("{0:#,0} KB", curFile.FileSize);
                }

                if (curAttInfo.SortNo > curFile.SortNo)
                {
                    curAttInfo.SortNo = curFile.SortNo;
                }

                curAttInfo.Files.Add(curFile);
            }

            // attList.Sort((x, y) => x.SortNo.CompareTo(y.SortNo));
        }
    protected void rptAttachments_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        Att.AttInfo attInfo = (Att.AttInfo)e.Item.DataItem;

        Literal ltrAttSubject = (Literal)e.Item.FindControl("ltrAttSubject");

        ltrAttSubject.Text = attInfo.AttSubject;

        Repeater rptAttSubitems = (Repeater)e.Item.FindControl("rptAttSubitems");

        rptAttSubitems.DataSource = attInfo.Files;
        rptAttSubitems.DataBind();
    }