示例#1
0
        private void RenderList(List <FilePreview> l, int pageCount)
        {
            flowPreview.SuspendLayout();
            mediaPanelControl1.lblPage.Text = String.Format("{0} / {1}", (MediaPanelPage + 1), pageCount);

            var currentList = new List <PreviewBox>();

            for (int i = 0; i < flowPreview.Controls.Count; i++)
            {
                var pb = flowPreview.Controls[i] as PreviewBox;
                if (pb != null)
                {
                    var cd = pb.CreatedDate;
                    if (NeedsMediaRebuild || l.Count(p => p.CreatedDateTicks == cd.Ticks) == 0)
                    {
                        flowPreview.Controls.Remove(pb);
                        pb.MouseDown  -= PbMouseDown;
                        pb.MouseEnter -= PbMouseEnter;
                        pb.Dispose();
                        i--;
                    }
                    else
                    {
                        currentList.Add(pb);
                    }
                }
                else
                {
                    var lb = flowPreview.Controls[i] as Label;
                    if (lb != null)
                    {
                        flowPreview.Controls.Remove(lb);
                        i--;
                    }
                }
            }

            int      ci        = 0;
            DateTime dtCurrent = DateTime.MinValue;
            bool     first     = true;

            foreach (FilePreview fp in l)
            {
                var dt = new DateTime(fp.CreatedDateTicks);
                if (first || dtCurrent.DayOfYear != dt.DayOfYear)
                {
                    first     = false;
                    dtCurrent = dt;
                    var lb = new Label {
                        Text = dtCurrent.ToShortDateString(), Margin = new Padding(3), Padding = new Padding(0), ForeColor = Color.White, BackColor = Color.Black, Width = 96, Height = 73, TextAlign = ContentAlignment.MiddleCenter
                    };
                    flowPreview.Controls.Add(lb);
                    flowPreview.Controls.SetChildIndex(lb, ci);
                    ci++;
                }
                var cdt = new DateTime(fp.CreatedDateTicks);
                var pb  = currentList.FirstOrDefault(p => p.CreatedDate == cdt);
                if (pb == null)
                {
                    FilePreview fp1 = fp;
                    var         dir = Helper.GetMediaDirectory(fp1.ObjectTypeId, fp1.ObjectId);
                    switch (fp1.ObjectTypeId)
                    {
                    case 1:
                        var v = Microphones.SingleOrDefault(p => p.id == fp1.ObjectId);
                        if (v != null)
                        {
                            var filename = dir + "audio\\" + v.directory + "\\" + fp.Filename;
                            pb = AddPreviewControl(fp1, Resources.audio, filename, v.name);
                        }
                        break;

                    case 2:
                        var c = Cameras.SingleOrDefault(p => p.id == fp1.ObjectId);
                        if (c != null)
                        {
                            var filename = dir + "video\\" + c.directory + "\\" + fp.Filename;
                            var thumb    = dir + "video\\" + c.directory + "\\thumbs\\" +
                                           fp.Filename.Substring(0,
                                                                 fp.Filename.LastIndexOf(".", StringComparison.Ordinal)) +
                                           ".jpg";
                            pb = AddPreviewControl(fp1, thumb, filename, c.name);
                        }
                        break;
                    }
                }
                if (pb != null)
                {
                    flowPreview.Controls.SetChildIndex(pb, ci);
                    ci++;
                }
            }

            flowPreview.ResumeLayout(true);
            NeedsMediaRebuild = false;
        }
示例#2
0
        private void RenderList(List <FilePreview> l, int pageCount)
        {
            var currentList = new List <PreviewBox>();



            int      ci        = 0;
            DateTime dtCurrent = DateTime.MinValue;
            bool     first     = true;

            foreach (FilePreview fp in l)
            {
                var dt = new DateTime(fp.CreatedDateTicks);
                if (first || dtCurrent.DayOfYear != dt.DayOfYear)
                {
                    first     = false;
                    dtCurrent = dt;
                    DateTime tag = new DateTime(dtCurrent.Year, dtCurrent.Month, dtCurrent.Day);
                    var      lb  = new Label {
                        Text = dtCurrent.ToShortDateString(), Tag = tag, Margin = new Padding(3), Padding = new Padding(0), ForeColor = Color.White, BackColor = Color.Black, Width = 96, Height = 73, TextAlign = ContentAlignment.MiddleCenter
                    };
                    lb.Click += Lb_Click;
                    lb.Cursor = Cursors.Hand;

                    ci++;
                }
                var cdt = new DateTime(fp.CreatedDateTicks);
                var pb  = currentList.FirstOrDefault(p => p.CreatedDate == cdt);
                if (pb == null)
                {
                    FilePreview fp1 = fp;
                    var         dir = Helper.GetMediaDirectory(fp1.ObjectTypeId, fp1.ObjectId);
                    switch (fp1.ObjectTypeId)
                    {
                    case 1:
                        var v = Microphones.SingleOrDefault(p => p.id == fp1.ObjectId);
                        if (v != null)
                        {
                            var filename = dir + "audio\\" + v.directory + "\\" + fp.Filename;
                            pb = AddPreviewControl(fp1, Resources.audio, filename, v.name);
                        }
                        break;

                    case 2:
                        var c = Cameras.SingleOrDefault(p => p.id == fp1.ObjectId);
                        if (c != null)
                        {
                            var filename = dir + "video\\" + c.directory + "\\" + fp.Filename;
                            var thumb    = dir + "video\\" + c.directory + "\\thumbs\\" +
                                           fp.Filename.Substring(0,
                                                                 fp.Filename.LastIndexOf(".", StringComparison.Ordinal)) +
                                           ".jpg";
                            pb = AddPreviewControl(fp1, thumb, filename, c.name);
                        }
                        break;
                    }
                }
                if (pb != null)
                {
                    ci++;
                }
            }


            NeedsMediaRebuild = false;
        }