Commit 1dbb0a72 authored by Rabbit's avatar Rabbit
Browse files

ListCore完善,设置界面完成

parent 93c05fa2
Loading
Loading
Loading
Loading

CountDownList/Class/Comon.cs

deleted100644 → 0
+0 −13
Original line number Diff line number Diff line
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CountDownList.Class
{
    public static class Comon
    {
        public const string ListPath = @"Data\CountDownList.json";
    }
}
+125 −12
Original line number Diff line number Diff line
@@ -5,6 +5,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Automation.Peers;
using System.Windows.Controls;
using System.Windows.Media;
using CountDownList.Controls;
@@ -27,7 +28,7 @@ namespace CountDownList.Class
            StackPanel wcPanel,
            StackPanel countPanel,
            Expander doingE,
            Expander wcE,
            Expander WcE,
            Expander countE
        )
        {
@@ -35,10 +36,22 @@ namespace CountDownList.Class
            WcPanel = wcPanel;
            CountPanel = countPanel;
            DoingE = doingE;
            WcE = wcE;
            WcE = WcE;
            CountE = countE;
        }

        private async void RefreshNumber()
        {
            while (true)
            {

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

        /// <summary>
        /// 添加一个标准倒计时标签到容器
        /// </summary>
@@ -48,7 +61,8 @@ namespace CountDownList.Class
        /// <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)
        /// <param name="InsertIndex">插入的位置,为null则插到最后</param>
        public async void AddCountDownLabel(string t, DateTime st, DateTime et, string f, bool dark, Brush brush, int? InsertIndex = null)
        {
            bool Move = false;

@@ -57,7 +71,19 @@ namespace CountDownList.Class
            lb = new(t, st, et, f, dark, brush, false);
            lb.Uid = t;

            //事件绑定
            lb.OnEdit += CountDown_OnEdit;
            lb.OnDelete += CountDown_OnDelete;
            lb.OnShare += CountDown_OnShare;

            if (InsertIndex != null)
            {
                DoingPanel.Children.Insert((int)InsertIndex, lb);
            }
            else
            {
                DoingPanel.Children.Add(lb);
            }

            while (true)
            {
@@ -85,10 +111,6 @@ namespace CountDownList.Class
                        WcPanel.Children.Add(lb);//添加到已完成
                    }

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

                    if (WcE.IsExpanded && IsOpen)
                    {
                        //当展开框展开时才刷新控件,以优化性能
@@ -101,6 +123,27 @@ namespace CountDownList.Class
            }
        }

        private void CountDown_OnShare(object? sender, EventArgs e)
        {
            throw new NotImplementedException();
        }

        private void CountDown_OnDelete(object? sender, EventArgs e)
        {
            if (sender != null)
            {
                DeleteForElement((Controls.ListLabel)sender);
            }
        }

        private void CountDown_OnEdit(object? sender, EventArgs e)
        {
            if (sender != null)
            {
                EditAndChange((Controls.ListLabel)sender);
            }
        }

        /// <summary>
        /// 创建一个正计时标签到容器
        /// </summary>
@@ -109,13 +152,22 @@ namespace CountDownList.Class
        /// <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)
        public async void AddCountLabel(string t, DateTime st, string f, bool dark, Brush brush, int? InsertIndex = null)
        {
            //动态添加控件
            ListLabel lb;
            lb = new(t, st, new(), f, dark, brush, true);
            lb.Uid = t;

            if (InsertIndex != null)
            {
                CountPanel.Children.Insert((int)InsertIndex, lb);
            }
            else
            {
                CountPanel.Children.Add(lb);
            }


            while (true)
            {
@@ -127,7 +179,6 @@ namespace CountDownList.Class
                    lb.SyncTime();
                    lb.SyncTitle();
                }
                CountE.Header = $"正计时({CountPanel.Children.Count})";
                await Task.Delay(20);
            }
        }
@@ -298,5 +349,67 @@ namespace CountDownList.Class
            Home home = new(l);
            home.Show();
        }

        /// <summary>
        /// 打开编辑窗口
        /// </summary>
        /// <param name="labelElement">需要编辑的ListLabel控件</param>
        /// <returns>更改后的ListLabel</returns>
        public CountDownList.Controls.ListLabel? OpenEditWindow(CountDownList.Controls.ListLabel labelElement)
        {
            var window = new EditWindow(labelElement);
            window.ShowDialog();
            return window.EditResult;
        }

        /// <summary>
        /// 打开编辑窗口并直接应用更改
        /// </summary>
        /// <param name="labelElement">需要编辑的ListLabel控件</param>
        public void EditAndChange(CountDownList.Controls.ListLabel labelElement)
        {
            var window = new EditWindow(labelElement);

            //获取原标签所在位置,以便设置后插回到原来的位置
            int Index = 0;
            for (int i = 0; i < DoingPanel.Children.Count; i++)
            {
                //判断
                if (Equals(DoingPanel.Children[i],labelElement))
                {
                    Index = i;
                }
            }
            for (int i = 0; i < WcPanel.Children.Count; i++)
            {
                //判断
                if (Equals(WcPanel.Children[i], labelElement))
                {
                    Index = i;
                }
            }
            for (int i = 0; i < CountPanel.Children.Count; i++)
            {
                //判断
                if (Equals(CountPanel.Children[i], labelElement))
                {
                    Index = i;
                }
            }

            window.ShowDialog();
            if (window.EditResult != null)
            {
                DeleteForElement(labelElement);
                if (window.EditResult.IsCountMode)
                {
                    AddCountLabel(window.EditResult.Title, window.EditResult.StartTime, window.EditResult.TimeFormat, window.EditResult.DarkText, window.EditResult.LabelBackground,Index);
                }
                else
                {
                    AddCountDownLabel(window.EditResult.Title, window.EditResult.StartTime, window.EditResult.EndTime, window.EditResult.TimeFormat, window.EditResult.DarkText, window.EditResult.LabelBackground,Index);
                }
            }
        }
    }
}
+1 −1
Original line number Diff line number Diff line
@@ -19,7 +19,7 @@ namespace CountDownList.Class
        public required XElement main;
        public CountCownListXml() 
        {
            xmlDoc = XDocument.Load($"{AppDomain.CurrentDomain.BaseDirectory}{Comon.ListPath}");
            xmlDoc = XDocument.Load($"{AppDomain.CurrentDomain.BaseDirectory}\\Data\\CountDownList.xml");

            try
            {
+0 −30
Original line number Diff line number Diff line
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CountDownList.Class
{
    public class cdlTimeSpan
    {
        /// <summary>
        /// 自动转换TimeSpan到String,根据时间跨度选择合适的单位
        /// </summary>
        /// <param name="timeSpan"></param>
        /// <returns>例如:5月02天,3年6月,2分钟28秒</returns>
        public string AutoToStringZh(TimeSpan timeSpan)
        {
            string returns = string.Empty;
            if (timeSpan.TotalDays >= 366)
            {
                returns = $"{Math.Floor(timeSpan.TotalDays / 365.25)}{(timeSpan.TotalDays % 365d) / 30 :F0}月";
            }
            else if(timeSpan.TotalDays < 366 && timeSpan.TotalDays >= 180)
            {
                returns = $"{Math.Floor(timeSpan.TotalDays / 30)}{Math.Floor(timeSpan.TotalDays - (timeSpan.TotalDays % 30))}天";
            }
            return returns;
        } 
    }
}
+2 −2
Original line number Diff line number Diff line
@@ -133,13 +133,13 @@

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

            <MenuItem Name="Share" Header="分享为图片" Click="Share_Click">
                <MenuItem.Icon>
                    <Image RenderOptions.BitmapScalingMode="Fant" Source="/UI/Icon/1-Del.png"/>
                    <Image RenderOptions.BitmapScalingMode="Fant" Source="/UI/Icon/share.png"/>
                </MenuItem.Icon>
            </MenuItem>
        </ContextMenu>
Loading