Commit 93c05fa2 authored by Rabbit's avatar Rabbit
Browse files

ListCore创建列表功能,加入主窗口

parent 8f3cde82
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
namespace CountDownList.Class
{
    /// <summary>
    /// 背景画刷的获取和生成
    /// </summary>
    public class CountDownBackground
    {
        public CountDownBackground() { }
+302 −0
Original line number Diff line number Diff line
using System;
using System.Collections.Generic;
using System.Diagnostics.Metrics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using CountDownList.Controls;
using CountDownList.UI.Window;

namespace CountDownList.Class
{
    /// <summary>
    /// 次类提供了CountDownList的基本操作,如创建、修改、删除、查找、分享等功能
    /// </summary>
    public class ListCore
    {
        public StackPanel DoingPanel , WcPanel, CountPanel;
        public Expander DoingE, WcE, CountE;

        public bool IsOpen = true;
        public ListCore
        (
            StackPanel doingPanel,
            StackPanel wcPanel,
            StackPanel countPanel,
            Expander doingE,
            Expander wcE,
            Expander countE
        )
        {
            DoingPanel = doingPanel;
            WcPanel = wcPanel;
            CountPanel = countPanel;
            DoingE = doingE;
            WcE = wcE;
            CountE = countE;
        }

        /// <summary>
        /// 添加一个标准倒计时标签到容器
        /// </summary>
        /// <param name="t">标题</param>
        /// <param name="st">开始时间</param>
        /// <param name="et">结束时间</param>
        /// <param name="f">时间转换的格式</param>
        /// <param name="dark">黑的文字</param>
        /// <param name="brush">背景画刷</param>
        public async void AddCountDownLabel(string t, DateTime st, DateTime et, string f, bool dark, Brush brush)
        {
            bool Move = false;

            //动态添加控件
            Controls.ListLabel lb;
            lb = new(t, st, et, f, dark, brush, false);
            lb.Uid = t;

            DoingPanel.Children.Add(lb);

            while (true)
            {
                if (DateTime.Now <= et)
                {
                    //当不是正计时时执行
                    //当展开框展开时才刷新控件,以优化性能

                    if (DoingE.IsExpanded && IsOpen)
                    {
                        lb.SyncProgress();
                        lb.SyncTime();
                        lb.SyncTitle();
                    }
                }
                else
                {
                    //当不是正计时并且已完成
                    //完成时移入“已完成”
                    if (!Move)
                    {
                        Move = true;//运行一次

                        DoingPanel.Children.Remove(lb);//从进行中移除控件
                        WcPanel.Children.Add(lb);//添加到已完成
                    }

                    DoingE.Header = $"进行中({DoingPanel.Children.Count})";
                    WcE.Header = $"已完成({WcPanel.Children.Count})";
                    CountE.Header = $"正计时({CountPanel.Children.Count})";

                    if (WcE.IsExpanded && IsOpen)
                    {
                        //当展开框展开时才刷新控件,以优化性能
                        lb.SyncProgress();
                        lb.SyncTime();
                        lb.SyncTitle();
                    }
                }
                await Task.Delay(20);
            }
        }
        
        /// <summary>
        /// 创建一个正计时标签到容器
        /// </summary>
        /// <param name="t">标题</param>
        /// <param name="st">开始时间</param>
        /// <param name="f">时间转换的格式</param>
        /// <param name="dark">深色文本</param>
        /// <param name="brush">背景画刷</param>
        public async void AddCountLabel(string t, DateTime st, string f, bool dark, Brush brush)
        {
            //动态添加控件
            ListLabel lb;
            lb = new(t, st, new(), f, dark, brush, true);
            lb.Uid = t;
            CountPanel.Children.Add(lb);

            while (true)
            {
                //当不是正计时时执行
                //当展开框展开时才刷新控件,以优化性能
                if (CountE.IsExpanded && IsOpen)
                {
                    lb.SyncProgress();
                    lb.SyncTime();
                    lb.SyncTitle();
                }
                CountE.Header = $"正计时({CountPanel.Children.Count})";
                await Task.Delay(20);
            }
        }

        /// <summary>
        /// 通过对比标题从容器中删除标签
        /// </summary>
        /// <param name="Title">要删除标签的标题</param>
        public void DeleteForTitle(string Title)
        {
            foreach (ListLabel item in DoingPanel.Children)
            {
                if (Title == item.Title)
                {
                    DoingPanel.Children.Remove(item);
                }
            }

            foreach (ListLabel item in WcPanel.Children)
            {
                if (Title == item.Title)
                {
                    WcPanel.Children.Remove(item);
                }
            }

            foreach (ListLabel item in CountPanel.Children)
            {
                if (Title == item.Title)
                {
                    CountPanel.Children.Remove(item);
                }
            }
        }

        /// <summary>
        /// 通过对比元素从容器中删除标签
        /// </summary>
        /// <param name="element">要删除标签的元素</param>
        public void DeleteForElement(ListLabel element)
        {
            DoingPanel.Children.Remove(element);
            WcPanel.Children.Remove(element);
            CountPanel.Children.Remove(element);
        }

        /// <summary>
        /// 打开主界面并扫描列表
        /// </summary>
        public void OpenMainWindow()
        {
            List<ListP> l = new();

            foreach (Controls.ListLabel item in DoingPanel.Children)
            {
                string t, st, et, bg, d;

                t = item.Title;
                st = item.StartTime.ToString("yyyy/MM/dd HH:mm:ss.fff");
                et = item.EndTime.ToString("yyyy/MM/dd HH:mm:ss.fff");

                bg = string.Empty;

                if (Equals(item.LabelBackground.GetType(), new SolidColorBrush().GetType()))
                {
                    bg = "(纯色HEX)" + ((SolidColorBrush)item.LabelBackground).ToString();
                }
                else if (Equals(item.LabelBackground.GetType(), new ImageBrush().GetType()))
                {
                    bg = "(图片路径)" + ((ImageBrush)item.LabelBackground).ImageSource.ToString();
                }

                if (item.DarkText)
                {
                    d = "是";
                }
                else
                {
                    d = "否";
                }

                l.Add(new ListP()
                {
                    Title = t,
                    StartTime = st,
                    EndTime = et,
                    BackGroung = bg,
                    DarkText = d
                });
            }

            foreach (Controls.ListLabel item in WcPanel.Children)
            {
                string t, st, et, bg, d;

                t = item.Title;
                st = item.StartTime.ToString("yyyy/MM/dd HH:mm:ss.fff");
                et = item.EndTime.ToString("yyyy/MM/dd HH:mm:ss.fff");

                bg = string.Empty;

                if (Equals(item.LabelBackground.GetType(), new SolidColorBrush().GetType()))
                {
                    bg = "(纯色HEX)" + ((SolidColorBrush)item.LabelBackground).ToString();
                }
                else if (Equals(item.LabelBackground.GetType(), new ImageBrush().GetType()))
                {
                    bg = "(图片路径)" + ((ImageBrush)item.LabelBackground).ImageSource.ToString();
                }

                if (item.DarkText)
                {
                    d = "是";
                }
                else
                {
                    d = "否";
                }

                l.Add(new ListP()
                {
                    Title = t,
                    StartTime = st,
                    EndTime = et,
                    BackGroung = bg,
                    DarkText = d
                });
            }

            foreach (Controls.ListLabel item in CountPanel.Children)
            {
                string t, st, et, bg, d;

                t = item.Title;
                st = item.StartTime.ToString("yyyy/MM/dd HH:mm:ss.fff");
                et = item.EndTime.ToString("yyyy/MM/dd HH:mm:ss.fff");

                bg = string.Empty;

                if (Equals(item.LabelBackground.GetType(), new SolidColorBrush().GetType()))
                {
                    bg = "(纯色HEX)" + ((SolidColorBrush)item.LabelBackground).ToString();
                }
                else if (item.LabelBackground.GetType() == typeof(ImageBrush))
                {
                    bg = "(图片路径)" + ((ImageBrush)item.LabelBackground).ImageSource.ToString();
                }

                if (item.DarkText)
                {
                    d = "是";
                }
                else
                {
                    d = "否";
                }

                l.Add(new ListP()
                {
                    Title = t,
                    StartTime = st,
                    EndTime = et,
                    BackGroung = bg,
                    DarkText = d
                });
            }

            Home home = new(l);
            home.Show();
        }
    }
}
+20 −1
Original line number Diff line number Diff line
@@ -124,9 +124,28 @@
        <SolidColorBrush x:Key="Dark" Color="#FF202020"></SolidColorBrush>
        <SolidColorBrush x:Key="Binding" Color="Yellow"></SolidColorBrush>

        <ContextMenu x:Key="ContextMenu">
            <MenuItem Name="Delete" Header="删除" Click="Delete_Click">
                <MenuItem.Icon>
                    <Image RenderOptions.BitmapScalingMode="Fant" Source="/UI/Icon/1-Del.png"/>
                </MenuItem.Icon>
            </MenuItem>

            <MenuItem Name="Edit" Header="编辑" Click="Edit_Click">
                <MenuItem.Icon>
                    <Image RenderOptions.BitmapScalingMode="Fant" Source="/UI/Icon/1-Del.png"/>
                </MenuItem.Icon>
            </MenuItem>

            <MenuItem Name="Share" Header="分享为图片" Click="Share_Click">
                <MenuItem.Icon>
                    <Image RenderOptions.BitmapScalingMode="Fant" Source="/UI/Icon/1-Del.png"/>
                </MenuItem.Icon>
            </MenuItem>
        </ContextMenu>
    </UserControl.Resources>
    <Grid>
        <Border x:Name="bg" Margin="4,4,4,4" BorderBrush="#FFF7F7F7" CornerRadius="8,8,8,8" BorderThickness="2,2,2,2" Cursor="Hand" MouseLeftButtonUp="Border_MouseLeftButtonUp">
        <Border x:Name="bg" Margin="4,4,4,4" BorderBrush="#FFF7F7F7" CornerRadius="8,8,8,8" BorderThickness="2,2,2,2" Cursor="Hand" MouseLeftButtonUp="Border_MouseLeftButtonUp" ContextMenu="{DynamicResource ContextMenu}">
            <Border.Background>
                <ImageBrush ImageSource="/UI/test.png" Stretch="UniformToFill"/>
            </Border.Background>
+20 −0
Original line number Diff line number Diff line
@@ -32,6 +32,9 @@ namespace CountDownList.Controls
        public Brush LabelBackground { get; set; }
        public bool DarkText { get; set; }

        public event EventHandler<EventArgs>? OnEdit;
        public event EventHandler<EventArgs>? OnDelete;
        public event EventHandler<EventArgs>? OnShare;

        public string? TimeFormat;

@@ -170,5 +173,22 @@ namespace CountDownList.Controls
        {
            bg.Background = LabelBackground;
        }

#pragma warning disable CS8602 // 解引用可能出现空引用。
        private void Delete_Click(object sender, RoutedEventArgs e)
        {
            OnDelete(this,e);
        }

        private void Edit_Click(object sender, RoutedEventArgs e)
        {
            OnEdit(this, e);
        }

        private void Share_Click(object sender, RoutedEventArgs e)
        {
            OnShare(this, e);
        }
#pragma warning restore CS8602 // 解引用可能出现空引用。
    }
}
+1 −1
Original line number Diff line number Diff line
@@ -102,7 +102,7 @@
                        <Image Source="/UI/Icon/collapse.png" Width="24" RenderOptions.BitmapScalingMode="Fant"/>
                    </Button>

                    <Button Padding="0,0,0,0" Width="28" Background="Transparent" BorderBrush="{x:Null}">
                    <Button Padding="0,0,0,0" Width="28" Background="Transparent" BorderBrush="{x:Null}" Click="Button_Click_3">
                        <Image Source="/UI/Icon/Home.png" Width="16" RenderOptions.BitmapScalingMode="Fant"/>
                    </Button>

Loading