陈嘉乐
2020-09-02 652243206427f35a256400a149a1734085824cb9
ZigbeeApp/Shared/Phone/Device/Logic/EverymonthPage.cs
@@ -1,4 +1,7 @@
using System;

using System;
using System.Collections.Generic;
using Shared;
using Shared.Phone;
@@ -6,266 +9,65 @@
using Shared.Common;
namespace Shared.Phone.Device.Logic
{
    public class EverymonthPage : FrameLayout
    {
        public void Show()
        public EverymonthPage()
        {
            Tag = "Logic";
        }
        public void Show(string titlename)
        {
            this.BackgroundColor = ZigbeeColor.Current.LogicTopViewBackgroundColor;
            var topFrameLayout = new FrameLayout
            #region  上面的布局代码
            TopView view = new TopView();
            this.AddChidren(view.TopRowView());
            view.toptitleNameBtn.Text = titlename;
            view.clickBtn.MouseDownEventHandler += (sender, e) => { RemoveFromParent(); };
            #endregion
            var middle = new FrameLayout
            {
                Height = Application.GetRealHeight(140),
                Y = Application.GetRealHeight(80),
                Y = view.topRowLayout.Bottom,
                Height = Application.GetRealHeight(Method.H - 184),
                BackgroundColor = ZigbeeColor.Current.LogicMiddleBackgroundColor,
            };
            AddChidren(topFrameLayout);
            var titleName = new Button
            {
                TextID = MyInternationalizationString.cycle,
                TextSize = 17,
                TextColor=ZigbeeColor.Current.LogicTextBlackColor,
            };
            topFrameLayout.AddChidren(titleName);
            var hdl = new Button
            {
                Width = Application.GetRealWidth(154),
                Height = Application.GetRealHeight(90),
                X = Application.GetRealWidth(1080-170),
                Gravity = Gravity.CenterVertical,
                UnSelectedImagePath = "Logo/Logo.png",
            };
            //topFrameLayout.AddChidren(hdl);
            var back = new Button
            {
                Width = Application.GetRealWidth(110),
                Height = Application.GetRealHeight(110),
                X = Application.GetRealWidth(20),
                Gravity = Gravity.CenterVertical,
                UnSelectedImagePath = "ZigeeLogic/Back.png",
            };
            topFrameLayout.AddChidren(back);
            back.MouseDownEventHandler += (sender, e) =>
            {
                RemoveFromParent();
            };
            var titlerl = new RowLayout
            {
                Height = Application.GetRealHeight(180),
                //BackgroundColor = 0xff0f0f0f,
                Y = Application.GetRealHeight(220),
            };
            AddChidren(titlerl);
            titlerl.AddChidren(
              new Button
              {
                  X = Application.GetRealWidth(40),
                  //Text = "请选择重复执行周期",
                  TextID = MyInternationalizationString.repeat,
                  TextSize = 17,
                  TextAlignment = TextAlignment.CenterLeft,
                TextColor = ZigbeeColor.Current.LogicTextBlackColor,
              }
            );
            var middle = new VerticalScrolViewLayout();
            middle.Y = titlerl.Bottom;
            middle.Height = Application.GetRealHeight(1920 - 220 - 180);
            middle.BackgroundColor = ZigbeeColor.Current.LogicBackgroundColor;
            this.AddChidren(middle);
            var startdaterow = new RowLayout
            var frameLayout = new FrameLayout
            {
                Height = Application.GetRealHeight(180),
                Y = Application.GetRealHeight(80),
                X = Application.GetRealWidth(50),
                Width = Application.GetRealWidth(1080 - 100),
                Height = Application.GetRealHeight(180 * 5 + 50),
                BackgroundColor = ZigbeeColor.Current.LogicBackgroundColor,
            };
            middle.AddChidren(startdaterow);
            var btnstartdatetext = new Button
            middle.AddChidren(frameLayout);
            var saveBtn = new Button
            {
                TextAlignment = TextAlignment.CenterLeft,
                Width = Application.GetRealWidth(300),
                X = Application.GetRealWidth(30),
                TextID = MyInternationalizationString.startdate,
                TextColor = ZigbeeColor.Current.LogicTextBlackColor,
                Y = middle.Height - Application.GetRealHeight(260),
                X = Application.GetRealWidth(85),
                Height = Application.GetRealHeight(130),//194
                Width = Application.GetRealWidth(910),
                Radius = (uint)Application.GetRealHeight(60),
                BackgroundColor = ZigbeeColor.Current.LogicBtnSaveBackgroundColor,
                TextID = MyInternationalizationString.Save,
                TextColor = ZigbeeColor.Current.LogicBtnSaveTextColor,
                TextSize = 16,
            };
            startdaterow.AddChidren(btnstartdatetext);
            middle.AddChidren(saveBtn);
            var btnstartdate = new Button
            var monselectedlist = new List<string>();
            monselectedlist.Clear();
            if (Common.Logic.CurrentLogic.TimeAttribute.Repeat == 3)
            {
                X = Application.GetRealWidth(330),
                Gravity = Gravity.CenterVertical,
                Width = Application.GetRealWidth(600),
                TextAlignment = TextAlignment.CenterLeft,
                Tag = "0",
                TextColor = ZigbeeColor.Current.LogicTextBlackColor,
            };
            startdaterow.AddChidren(btnstartdate);
            var btnstartback = new Button
            {
                Width = Application.GetRealWidth(110),
                Height = Application.GetRealHeight(110),
                UnSelectedImagePath = "ZigeeLogic/next.png",
                SelectedImagePath = "ZigeeLogic/NextSelecte.png",
                X = Application.GetRealWidth(1080 - 140),
                Gravity = Gravity.CenterVertical,
            };
            startdaterow.AddChidren(btnstartback);
            var enddaterow = new RowLayout
            {
                Height = Application.GetRealHeight(180),
            };
            middle.AddChidren(enddaterow);
            var btnenddatetext = new Button
            {
                TextAlignment = TextAlignment.CenterLeft,
                Width = Application.GetRealWidth(300),
                X = Application.GetRealWidth(30),
                TextID = MyInternationalizationString.enddate,
                TextColor = ZigbeeColor.Current.LogicTextBlackColor,
            };
            enddaterow.AddChidren(btnenddatetext);
            var btnenddate = new Button
            {
                X = Application.GetRealWidth(330),
                Gravity = Gravity.CenterVertical,
                Width = Application.GetRealWidth(600),
                TextAlignment = TextAlignment.CenterLeft,
                Tag = "0",
                TextColor = ZigbeeColor.Current.LogicTextBlackColor,
            };
            enddaterow.AddChidren(btnenddate);
            var btnendtimeback = new Button
            {
                Width = Application.GetRealWidth(110),
                Height = Application.GetRealHeight(110),
                UnSelectedImagePath = "ZigeeLogic/next.png",
                SelectedImagePath = "ZigeeLogic/NextSelecte.png",
                X = Application.GetRealWidth(1080 - 140),
                Gravity=Gravity.CenterVertical,
            };
            enddaterow.AddChidren(btnendtimeback);
            EventHandler<MouseEventArgs> startdateclick = (sender33, e33) =>
            {
                var list = new List<string> { };
                for (int day = 1; day <= 31; day++)
                {
                    list.Add(day.ToString() + " " + Language.StringByID(MyInternationalizationString.day));
                }
                PickerView.Show(list, (obj) =>
                {
                    var day = obj.Split(' ')[0];
                    if (btnenddate.Tag.ToString() != "0" && int.Parse(btnenddate.Tag.ToString()) < int.Parse(day))
                    {
                        var alert = new Alert(Language.StringByID(MyInternationalizationString.Prompt),
                                               Language.StringByID(MyInternationalizationString.monthday),
                                               Language.StringByID(MyInternationalizationString.OK));
                        alert.Show();
                    }
                    else
                    {
                        btnstartdate.Text = Language.StringByID(MyInternationalizationString.monthly) + day + Language.StringByID(MyInternationalizationString.day);
                        btnstartdate.Tag = day;
                        if (string.IsNullOrEmpty(btnenddate.Text))
                        {
                            btnenddate.Text = Language.StringByID(MyInternationalizationString.monthly) + day + Language.StringByID(MyInternationalizationString.day);
                            btnenddate.Tag = day;
                        }
                        Common.Logic.CurrentLogic.TimeAttribute.Repeat = 3;
                        int a = int.Parse(btnstartdate.Tag.ToString());
                        int b = int.Parse(btnenddate.Tag.ToString());
                        string s = "";
                        for (int i = 32; i > 0; i--)
                        {
                            if (i >=a  && i <= b)
                            {
                                s += "1";
                            }
                            else
                            {
                                s += "0";
                            }
                        }
                        var intvalue = Convert.ToInt32(s, 2);
                        Common.Logic.CurrentLogic.TimeAttribute.MonthDate = intvalue;
                    }
                }, Language.StringByID(MyInternationalizationString.complete), "112");
            };
            startdaterow.MouseUpEventHandler += startdateclick;
            btnstartdate.MouseUpEventHandler += startdateclick;
            btnstartdatetext.MouseUpEventHandler += startdateclick;
            btnstartback.MouseUpEventHandler += startdateclick;
            EventHandler<MouseEventArgs> enddateclick = (sender33, e33) =>
            {
                var list = new List<string> { };
                for (int day = 1; day <= 31; day++)
                {
                    list.Add(day.ToString() + " " + Language.StringByID(MyInternationalizationString.day));
                }
                PickerView.Show(list, (obj) =>
                {
                    var day = obj.Split(' ')[0];
                    if (btnstartdate.Tag.ToString() != "0" && int.Parse(btnstartdate.Tag.ToString()) > int.Parse(day))
                    {
                        var alert = new Alert(Language.StringByID(MyInternationalizationString.Prompt),
                                               Language.StringByID(MyInternationalizationString.monthday),
                                               Language.StringByID(MyInternationalizationString.OK));
                        alert.Show();
                    }
                    else
                    {
                        btnenddate.Text = Language.StringByID(MyInternationalizationString.monthly) + day + Language.StringByID(MyInternationalizationString.day);
                        btnenddate.Tag = day;
                        if (string.IsNullOrEmpty(btnstartdate.Text))
                        {
                            btnstartdate.Text = Language.StringByID(MyInternationalizationString.monthly) + day + Language.StringByID(MyInternationalizationString.day);
                            btnstartdate.Tag = day;
                        }
                        Common.Logic.CurrentLogic.TimeAttribute.Repeat = 3;
                        int a = int.Parse(btnstartdate.Tag.ToString());
                        int b = int.Parse(btnenddate.Tag.ToString());
                        string s = "";
                        for (int i = 32; i > 0; i--)
                        {
                            if (i >= a && i <= b)
                            {
                                s += "1";
                            }
                            else
                            {
                                s += "0";
                            }
                        }
                        var intvalue = Convert.ToInt32(s, 2);
                        Common.Logic.CurrentLogic.TimeAttribute.MonthDate = intvalue;
                    }
                }, Language.StringByID(MyInternationalizationString.complete), "112");
            };
            enddaterow.MouseUpEventHandler += enddateclick;
            btnenddate.MouseUpEventHandler += enddateclick;
            btnenddatetext.MouseUpEventHandler += enddateclick;
            btnendtimeback.MouseUpEventHandler += enddateclick;
            if(Common.Logic.CurrentLogic.TimeAttribute.Repeat==3){
                if (Common.Logic.CurrentLogic.TimeAttribute.MonthDate != 0)
                {
                    string len = "";
                    int minvalue = 0;
                    var maxvalue = Convert.ToString(Common.Logic.CurrentLogic.TimeAttribute.MonthDate, 2);
                    var str = maxvalue.Insert(0, new string('0', 32 - maxvalue.Length));
                    for (int j = 31; j >= 0; j--)
@@ -278,20 +80,121 @@
                        var strvalue = len.Substring(j, 1);
                        if (strvalue == "1")
                        {
                            minvalue = j + 1;
                            break;
                            monselectedlist.Add((j + 1).ToString());
                        }
                    }
                    btnstartdate.Text = Language.StringByID(MyInternationalizationString.monthly) + minvalue.ToString() + Language.StringByID(MyInternationalizationString.day);
                    btnstartdate.Tag = minvalue.ToString();
                    btnenddate.Text = Language.StringByID(MyInternationalizationString.monthly) + maxvalue.Length.ToString() + Language.StringByID(MyInternationalizationString.day);
                    btnenddate.Tag = maxvalue.Length.ToString();
                }
            }
            int k = 1;
            for (int i = 0; i < 5; i++)
            {
                var timeRow = new RowLayout
                {
                    Height = Application.GetRealHeight(180),
                    Y = Application.GetRealHeight(180 * i),
                    LineColor = ZigbeeColor.Current.LogicBackgroundColor,
                };
                frameLayout.AddChidren(timeRow);
                for (int j = 1; j < 8; j++)
                {
                    if (k > 31)
                    {
                        continue;
                    }
                    var monBtn = new Button
                    {
                        Text = k.ToString().Length == 1 ? "0" + k.ToString() : k.ToString(),
                        Y = Application.GetRealHeight(40),
                        Height = Application.GetMinRealAverage(100),
                        Width = Application.GetMinRealAverage(100),
                        X = Application.GetRealWidth(35 * j) + Application.GetRealWidth(100 * (j - 1)),
                        TextColor = ZigbeeColor.Current.LogicTextBlackColor,
                        SelectedTextColor = ZigbeeColor.Current.LogicBlankBackgroundColor,
                        Radius = (uint)Application.GetMinRealAverage(50),
                        BackgroundColor = ZigbeeColor.Current.LogicBackgroundColor,
                        SelectedBackgroundColor = ZigbeeColor.Current.LogicAddColor,
                        Tag = k,
                    };
                    timeRow.AddChidren(monBtn);
                    if (monselectedlist.Contains(k.ToString()))
                    {
                        monBtn.IsSelected = true;
                    }
                    k++;
                    monBtn.MouseDownEventHandler += (sender, e) =>
                    {
                        monBtn.IsSelected = !monBtn.IsSelected;
                        var selectedmon = monselectedlist.Find((c) => { return c == monBtn.Tag.ToString(); });
                        if (monBtn.IsSelected)
                        {
                            if (selectedmon == null)
                            {
                                monselectedlist.Add(monBtn.Tag.ToString());
                            }
                        }
                        else
                        {
                            if (selectedmon != null)
                            {
                                monselectedlist.Remove(monBtn.Tag.ToString());
                            }
                        }
                    };
                }
            }
            saveBtn.MouseUpEventHandler += (sedder, e) =>
            {
                if (monselectedlist.Count == 0)
                {
                    var alert = new UserCenter.ShowMsgControl(UserCenter.ShowMsgType.Normal,
                          Language.StringByID(MyInternationalizationString.selectweek),
                         Language.StringByID(MyInternationalizationString.confrim));
                    alert.Show();
                    return;
                }
                string s = "";
                for (int i = 32; i > 0; i--)
                {
                    var selectedmon = monselectedlist.Find((a) => { return a == i.ToString(); });
                    if (selectedmon != null)
                    {
                        s += "1";
                    }
                    else
                    {
                        s += "0";
                    }
                }
                var intvalue = Convert.ToInt32(s, 2);
                Common.Logic.CurrentLogic.TimeAttribute.Repeat = 3;
                Common.Logic.CurrentLogic.TimeAttribute.MonthDate = intvalue;
                var logicCommunalPage = new LogicCommunalPage();
                UserView.HomePage.Instance.AddChidren(logicCommunalPage);
                UserView.HomePage.Instance.PageIndex += 1;
                logicCommunalPage.Show(() => { });
            };
        }
    }
}
}