陈嘉乐
2020-11-20 35a33afeeb29466c20ee39dc34e0468d687afce9
HDL_ON/UI/UI2/3-Intelligence/Automation/TimeTpye.cs
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using Shared;
namespace HDL_ON.UI.UI2.Intelligence.Automation
{
@@ -6,12 +7,14 @@
    {
        public TimeTpye()
        {
            Tag = "Logic";
        }
        public void Show()
        {
            LogicView.TopView topView = new LogicView.TopView();
            this.AddChidren(topView.TopFLayoutView());
            this.AddChidren(topView.FLayoutView());
            topView.clickBackBtn.MouseUpEventHandler += (e, sen) =>
            {
                RemoveFromParent();
@@ -28,18 +31,320 @@
            this.AddChidren(viewLayout);
            //时刻
            LogicView.SelectType timeView = new LogicView.SelectType();
            timeView.btnIcon.Visible = false;
            timeView.btnText.X = Application.GetRealWidth(16);
            timeView.btnText.TextID = StringId.hour;
            viewLayout.AddChidren(timeView.FLayoutView());
            LogicView.SelectTypeView timepointView = new LogicView.SelectTypeView();
            timepointView.btnIcon.Visible = false;
            timepointView.btnText.X = Application.GetRealWidth(16);
            timepointView.btnLine.X = Application.GetRealWidth(16);
            timepointView.btnLine.Width = Application.GetRealWidth(375 - 16 - 16);
            timepointView.btnText.TextID = StringId.hour;
            viewLayout.AddChidren(timepointView.FLayoutView());
            //时间范围
            LogicView.SelectType functionView = new LogicView.SelectType();
            functionView.frameLayout.Y = timeView.frameLayout.Bottom;
            functionView.btnIcon.Visible = false;
            functionView.btnText.X = Application.GetRealWidth(16);
            functionView.btnText.TextID = StringId.timeHorizon;
            viewLayout.AddChidren(functionView.FLayoutView());
            LogicView.SelectTypeView timeHorizonView = new LogicView.SelectTypeView();
            timeHorizonView.frameLayout.Y = timepointView.frameLayout.Bottom;
            timeHorizonView.btnIcon.Visible = false;
            timeHorizonView.btnText.X = Application.GetRealWidth(16);
            timeHorizonView.btnLine.X = Application.GetRealWidth(16);
            timeHorizonView.btnLine.Width = Application.GetRealWidth(375 - 16 - 16);
            timeHorizonView.btnText.TextID = StringId.timeHorizon;
            viewLayout.AddChidren(timeHorizonView.FLayoutView());
            //时间点点击事件
            timepointView.btnClick.MouseUpEventHandler += (sen, e) =>
            {
                //主界面控件
                FrameLayout fLayout = new FrameLayout
                {
                    BackgroundColor = CSS.CSS_Color.viewTrans60lucence,
                };
                this.AddChidren(fLayout);
                TimePoint(fLayout);
            };
            //时间范围点击事件
            timeHorizonView.btnClick.MouseUpEventHandler += (sen, e) =>
            {
                //主界面控件
                FrameLayout fLayout = new FrameLayout
                {
                    BackgroundColor = CSS.CSS_Color.viewTrans60lucence,
                };
                //添加主界面
                this.AddChidren(fLayout);
                TimeHorizon(fLayout,false,0);
            };
        }
        /// <summary>
        /// 时间点方法
        /// </summary>
        /// <param name="fLayout">在哪个界面显示</param>
        public void TimePoint(FrameLayout fLayout)
        {
            LogicView.TimeView timePointView = new LogicView.TimeView();
            timePointView.FLayoutView(fLayout);
            EventHandler<MouseEventArgs> RemovefLayout = (sender, e1) =>
             {
                //移除fLayout界面
                fLayout.RemoveFromParent();
             };
            //取消点击事件
            timePointView.btnCancel.MouseUpEventHandler += RemovefLayout;
            //加载数据界面的设置方法(列表互不联动)
            timePointView.mUIPickerView.setNPicker(timePointView.GethStringList(), timePointView.GetmStringList(), null);
            //默认初始选中状态
            timePointView.mUIPickerView.setCurrentItems(0, 30, 0);
            //定义一个局部变量记录选中时间
            string timepoint = "01:30";
            //选中时间回调方法,时间变化一次回调一次
            timePointView.mUIPickerView.OnSelectChangeEvent += (index1, index2, index3) =>
            {
                string hour = timePointView.GethStringList()[index1].Split(' ')[0];
                string minuet = timePointView.GetmStringList()[index2].Split(' ')[0];
                timepoint = hour + ":" + minuet;
            };
            //确定点击事件
            timePointView.btnConfirm.MouseUpEventHandler += (sender, e3) =>
            {
                Input inputTime = new Input();
                inputTime.sid = LogicMethod.NewSid();
                inputTime.condition_type = "1";
                Dictionary<string, string> dic = new Dictionary<string, string>();
                LogicMethod.dictionary(dic, "key", "timepoint");
                LogicMethod.dictionary(dic, "comparator", "=");
                LogicMethod.dictionary(dic, "data_type", "string");
                LogicMethod.dictionary(dic, "value", timepoint);
                inputTime.condition.Add(dic);
                //添加一个新的时间点条件
                Logic.currlogic.input.Add(inputTime);
                RemoveViewByTag("Logic");
                AddLogic addLogic = new AddLogic();
                MainPage.BasePageView.AddChidren(addLogic);
                addLogic.Show();
                MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1;
            };
        }
        /// <summary>
        /// 时间范围方法
        /// </summary>
        /// <param name="fLayout">在哪个界面显示</param>
        public void TimeHorizon(FrameLayout fLayout,bool edit,int index)
        {
            #region 界面布局
            LogicView.TimeHorizonView timeHorizonView = new LogicView.TimeHorizonView();
            timeHorizonView.frameLayout.SetCornerWithSameRadius(12, HDLUtils.RectCornerTopLeft | HDLUtils.RectCornerTopRight | HDLUtils.RectCornerBottomLeft | HDLUtils.RectCornerBottomRight);
            timeHorizonView.FLayoutView(fLayout);
            //开始时间
            LogicView.SelectTypeView startTimeView = new LogicView.SelectTypeView();
            startTimeView.frameLayout.Y = Application.GetRealHeight(87);
            startTimeView.btnIcon.Visible = false;
            startTimeView.btnText.X = Application.GetRealWidth(16);
            startTimeView.btnText.TextID = StringId.startTime;
            startTimeView.btnLine.X = Application.GetRealWidth(16);
            startTimeView.btnLine.Width = Application.GetRealWidth(375 - 16 - 16);
            startTimeView.btnNextIcon.X = Application.GetRealWidth(307);
            timeHorizonView.frameLayout.AddChidren(startTimeView.FLayoutView());
            //显示开始时间文本
            Button btnStartTimeText = new Button
            {
                TextSize = LogicView.TextSize.text12,
                Width = Application.GetRealWidth(32 + 3),
                Height = Application.GetRealHeight(20),
                TextColor = CSS.CSS_Color.textCancelColor,
                Y = Application.GetRealHeight(17),
                X = Application.GetRealWidth(260),
                Tag = "0",
            };
            startTimeView.frameLayout.AddChidren(btnStartTimeText);
            //结束时间
            LogicView.SelectTypeView endTimeView = new LogicView.SelectTypeView();
            endTimeView.frameLayout.SetCornerWithSameRadius(12, HDLUtils.RectCornerBottomLeft | HDLUtils.RectCornerBottomRight);
            endTimeView.frameLayout.Y = startTimeView.frameLayout.Bottom;
            endTimeView.btnIcon.Visible = false;
            endTimeView.btnLine.Visible = false;
            endTimeView.btnText.X = Application.GetRealWidth(16);
            endTimeView.btnText.TextID = StringId.endTime;
            endTimeView.btnNextIcon.X = Application.GetRealWidth(307);
            timeHorizonView.frameLayout.AddChidren(endTimeView.FLayoutView());
            //显示结束时间文本
            Button btnEndTimeText = new Button
            {
                TextSize = LogicView.TextSize.text12,
                Width = Application.GetRealWidth(32 + 3),
                Height = Application.GetRealHeight(20),
                TextColor = CSS.CSS_Color.textCancelColor,
                Y = Application.GetRealHeight(17),
                X = Application.GetRealWidth(260),
                Tag = "0",
            };
            endTimeView.frameLayout.AddChidren(btnEndTimeText);
            #endregion
            #region 点击事件
            //开始时间点击事件
            startTimeView.btnClick.MouseUpEventHandler += (sender, e) =>
            {
                SelectedTimeHorizon(fLayout, btnStartTimeText);
            };
            //结束时间点击事件
            endTimeView.btnClick.MouseUpEventHandler += (sender, e) =>
            {
                SelectedTimeHorizon(fLayout, btnEndTimeText);
            };
            //确定点击事件
            timeHorizonView.btnConfirm.MouseUpEventHandler += (sender, e) =>
            {
                if (btnStartTimeText.Tag.ToString() == "0")
                {
                    //提示:请选中开始时间
                    return;
                }
                if (btnEndTimeText.Tag.ToString() == "0")
                {
                    //提示:请选中结束时间
                    return;
                }
                if (btnStartTimeText.Tag.ToString() == btnEndTimeText.Tag.ToString())
                {
                    //提示:时间一样的
                    return;
                }
                if (int.Parse(btnStartTimeText.Tag.ToString()) > int.Parse(btnEndTimeText.Tag.ToString()))
                {
                    //提示:开始时间不能大于结束时间
                    return;
                }
                Input inputTime = new Input();
                inputTime.sid = LogicMethod.NewSid();
                inputTime.condition_type = "2";
                Dictionary<string, string> dic = new Dictionary<string, string>();
                LogicMethod.dictionary(dic, "key", "timesection");
                LogicMethod.dictionary(dic, "comparator", "=");
                LogicMethod.dictionary(dic, "data_type", "string");
                LogicMethod.dictionary(dic, "value", btnStartTimeText.Text+"~"+btnEndTimeText.Text);
                inputTime.condition.Add(dic);
                if (edit)
                {
                    //移除旧数据
                    Logic.currlogic.input.RemoveAt(index);
                    //新数据插入旧数据的位置
                    Logic.currlogic.input.Insert(index, inputTime);
                    fLayout.RemoveFromParent();
                }
                else
                {
                    //添加一个新的时间点条件
                    Logic.currlogic.input.Add(inputTime);
                }
                RemoveViewByTag("Logic");
                AddLogic addLogic = new AddLogic();
                MainPage.BasePageView.AddChidren(addLogic);
                addLogic.Show();
                MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1;
            };
            #endregion
            if (edit)
            {
                Input inputs = Logic.currlogic.input[index];
                if (inputs.condition_type == "2")
                {
                    List<Dictionary<string, string>> dicList = inputs.condition as List<Dictionary<string, string>>;
                    foreach (var dic in dicList)
                    {
                        string value = dic["value"];
                        string startTime = value.Split('~')[0];
                        string endtTime = value.Split('~')[1];
                        btnStartTimeText.Text = startTime;
                        btnStartTimeText.Tag = int.Parse(startTime.Split(':')[0]) * 60 + int.Parse(startTime.Split(':')[1]);
                        btnEndTimeText.Text = endtTime;
                        btnEndTimeText.Tag = int.Parse(endtTime.Split(':')[0]) * 60 + int.Parse(endtTime.Split(':')[1]);
                    }
                }
            }
        }
        /// <summary>
        /// 设置时间段时间的方法
        /// </summary>
        /// <param name="fLayout"></param>
        /// <param name="btn"></param>
        public void SelectedTimeHorizon(FrameLayout fLayout, Button btn)
        {
            LogicView.TimeView timePointView = new LogicView.TimeView();
            timePointView.FLayoutView(fLayout);
            EventHandler<MouseEventArgs> RemovefLayout = (sender, e1) =>
            {
                //只移除时间弹窗界面
                timePointView.frameLayout.RemoveFromParent();
            };
            //取消点击事件
            timePointView.btnCancel.MouseUpEventHandler += RemovefLayout;
            //加载数据界面的设置方法(列表互不联动)
            timePointView.mUIPickerView.setNPicker(timePointView.GethStringList(), timePointView.GetmStringList(), null);
            //默认初始选中状态
            timePointView.mUIPickerView.setCurrentItems(0, 30, 0);
            //定义一个局部变量记录选中时间
            string timepoint = "01:30";
            int sumTime = 90;
            if (btn.Tag.ToString() != "0")
            {
                string h = "", m = "";
                sumTime = int.Parse(btn.Tag.ToString());
                if ((sumTime / 60) < 10)
                {
                    h = "0" + (sumTime / 60).ToString();
                }
                else
                {
                    h = (sumTime / 60).ToString();
                }
                if ((sumTime % 60) < 10)
                {
                    m = "0" + (sumTime % 60).ToString();
                }
                else
                {
                    m = (sumTime % 60).ToString();
                }
                timepoint = h + ":" + m;
                int hourIndex = timePointView.GetValueIndex(timepoint, 0, 1, timePointView.GethIntList());
                int minuteIndex = timePointView.GetValueIndex(timepoint, 1, 0, timePointView.GetmIntList());
                //更新状态
                timePointView.mUIPickerView.setCurrentItems(hourIndex - 1, minuteIndex, 0);
            }
            //选中时间回调方法,时间变化一次回调一次
            timePointView.mUIPickerView.OnSelectChangeEvent += (index1, index2, index3) =>
            {
                string hour = timePointView.GethStringList()[index1].Split(' ')[0];
                string minuet = timePointView.GetmStringList()[index2].Split(' ')[0];
                timepoint = hour + ":" + minuet;
                sumTime = int.Parse(hour) * 60 + int.Parse(minuet);
            };
            //确定点击事件
            timePointView.btnConfirm.MouseUpEventHandler += (sender1, e3) =>
            {
                btn.Tag = sumTime;
                btn.Text = timepoint;
                //只移除时间弹窗界面
                timePointView.frameLayout.RemoveFromParent();
            };
        }
    }
}