wei
2021-08-27 eda3fb873e59544ff36301b51e05aef64f87b0f9
HDL_ON/UI/UI2/3-Intelligence/Automation/TimeTpye.cs
@@ -49,6 +49,17 @@
            timeHorizonView.btnText.TextID = StringId.timeHorizon;
            viewLayout.AddChidren(timeHorizonView.FLayoutView());
            //日出/日落/正午
            LogicView.SelectTypeView timeSpecialView = new LogicView.SelectTypeView();
            timeSpecialView.frameLayout.Y = timeHorizonView.frameLayout.Bottom;
            timeSpecialView.btnIcon.Visible = false;
            timeSpecialView.btnText.X = Application.GetRealWidth(16);
            timeSpecialView.btnLine.X = Application.GetRealWidth(16);
            timeSpecialView.btnLine.Width = Application.GetRealWidth(375 - 16 - 16);
            timeSpecialView.btnText.TextID = StringId.timespecia;
            viewLayout.AddChidren(timeSpecialView.FLayoutView());
            #endregion
            #region  时间点  时间范围点击事件
@@ -74,9 +85,19 @@
                };
                //添加主界面
                this.AddChidren(fLayout);
                //var fLayout = GetFrame(this,"2");
                TimeHorizon(fLayout, false, 0);
            };
            //日出/日落/正午点击事件
            timeSpecialView.btnClick.MouseUpEventHandler += (sen, e) =>
            {
                SpeciaTime speciaTime = new SpeciaTime();
                MainPage.BasePageView.AddChidren(speciaTime);
                speciaTime.Show();
                MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1;
            };
            #endregion
        }
@@ -88,23 +109,8 @@
        /// <param name="index">编辑条件的索引</param>
        public void TimePoint(FrameLayout fLayout, bool edit, int index)
        {
            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";
            //编辑之前的时间状态值
            string editTime= "";
            if (edit)
            {
                Input inputs = Logic.currlogic.input[index];
@@ -114,54 +120,26 @@
                    foreach (var dic in dicList)
                    {
                        string timeValue = dic["value"];
                        int hIndex = timePointView.GetValueIndex(timeValue, 0, 1, timePointView.GethIntList());
                        int mIndex = timePointView.GetValueIndex(timeValue, 1, 0, timePointView.GetmIntList());
                        //更新初始状态
                        timePointView.mUIPickerView.setCurrentItems(hIndex - 1, mIndex, 0);
                        timepoint = timeValue;
                        editTime = timeValue;
                        break;
                    }
                }
            }
            //选中时间回调方法,时间变化一次回调一次
            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) =>
            {
            LogicView.TimeView timePointView = new LogicView.TimeView();
            timePointView.FLayoutView(fLayout);
            timePointView.TimePoint(fLayout, editTime, (timeValue)=>{
                Input inputTime = new Input();
                inputTime.sid = LogicMethod.NewSid();
                inputTime.sid = LogicMethod.CurrLogicMethod.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);
                LogicMethod.CurrLogicMethod.dictionary(dic, "key", "timepoint");
                LogicMethod.CurrLogicMethod.dictionary(dic, "comparator", "=");
                LogicMethod.CurrLogicMethod.dictionary(dic, "data_type", "string");
                LogicMethod.CurrLogicMethod.dictionary(dic, "value", timeValue);
                inputTime.condition.Add(dic);
                if (edit)
                {
                    //移除旧数据
                    Logic.currlogic.input.RemoveAt(index);
                    //新数据插入旧数据的位置;
                    Logic.currlogic.input.Insert(index, inputTime);
                }
                else
                {
                    //添加一个新的时间点条件
                    Logic.currlogic.input.Add(inputTime);
                }
                LogicMethod.RemoveAllView();
                AddLogic addLogic = new AddLogic();
                MainPage.BasePageView.AddChidren(addLogic);
                addLogic.Show();
                MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1;
            };
                AddCondition(inputTime, edit, index);
            });
        }
        /// <summary>
        /// 时间范围方法
@@ -169,7 +147,7 @@
        /// <param name="fLayout">在哪个界面显示</param>
        /// <param name="edit">(true=编辑;false=新建)</param>
        /// <param name="index">编辑条件的索引</param>
        public void TimeHorizon(FrameLayout fLayout,bool edit,int index)
        public void TimeHorizon(FrameLayout fLayout, bool edit, int index)
        {
            #region 界面布局
            LogicView.TimeHorizonView timeHorizonView = new LogicView.TimeHorizonView();
@@ -188,11 +166,11 @@
            Button btnStartTimeText = new Button
            {
                TextSize = LogicView.TextSize.text12,
                Width = Application.GetRealWidth(32 + 3),
                Height = Application.GetRealHeight(20),
                Width = Application.GetRealWidth(32 + 3+20),
                Height = Application.GetRealHeight(17),
                TextColor = CSS.CSS_Color.textCancelColor,
                Y = Application.GetRealHeight(17),
                X = Application.GetRealWidth(260),
                X = Application.GetRealWidth(260-20),
                Tag = "0",
            };
            startTimeView.frameLayout.AddChidren(btnStartTimeText);
@@ -211,11 +189,11 @@
            Button btnEndTimeText = new Button
            {
                TextSize = LogicView.TextSize.text12,
                Width = Application.GetRealWidth(32 + 3),
                Height = Application.GetRealHeight(20),
                Width = Application.GetRealWidth(32 + 3+20),
                Height = Application.GetRealHeight(17),
                TextColor = CSS.CSS_Color.textCancelColor,
                Y = Application.GetRealHeight(17),
                X = Application.GetRealWidth(260),
                X = Application.GetRealWidth(260-20),
                Tag = "0",
            };
            endTimeView.frameLayout.AddChidren(btnEndTimeText);
@@ -224,66 +202,65 @@
            #region 点击事件
            //开始时间点击事件
            startTimeView.btnClick.MouseUpEventHandler += (sender, e) =>
            {
            EventHandler<MouseEventArgs> StartTimeClick = (sender,e) => {
                SelectedTimeHorizon(fLayout, btnStartTimeText);
            };
            startTimeView.btnClick.MouseUpEventHandler += StartTimeClick;
            btnStartTimeText.MouseUpEventHandler += StartTimeClick;
            //结束时间点击事件
            endTimeView.btnClick.MouseUpEventHandler += (sender, e) =>
            {
            EventHandler<MouseEventArgs> EndTimeClick = (sender, e) => {
                SelectedTimeHorizon(fLayout, btnEndTimeText);
            };
            endTimeView.btnClick.MouseUpEventHandler += EndTimeClick;
            btnEndTimeText.MouseUpEventHandler += EndTimeClick;
            //确定点击事件
            timeHorizonView.btnConfirm.MouseUpEventHandler += (sender, e) =>
            {
                if (btnStartTimeText.Tag.ToString() == "0"&& btnEndTimeText.Tag.ToString() == "0")
                {
                    //提示:时间未设置,请设置时间。
                    new LogicView.TipPopView().TipBox(StringId.tip, StringId.timeNoSet);
                    return;
                }
                if (btnStartTimeText.Tag.ToString() == "0")
                {
                    //提示:请选中开始时间
                    //提示:开始时间未设置,请设置开始时间。
                    new LogicView.TipPopView().TipBox(StringId.tip,StringId.setStartTime);
                    return;
                }
                if (btnEndTimeText.Tag.ToString() == "0")
                {
                    //提示:请选中结束时间
                    //提示:结束时间未设置,请设置结束时间。
                    new LogicView.TipPopView().TipBox(StringId.tip, StringId.setEndTime);
                    return;
                }
                if (btnStartTimeText.Tag.ToString() == btnEndTimeText.Tag.ToString())
                {
                    //提示:时间一样的
                    //提示:开始时间和结束时间不能一样。
                    new LogicView.TipPopView().TipBox(StringId.tip, StringId.unlikeTime);
                    return;
                }
                if (int.Parse(btnStartTimeText.Tag.ToString()) > int.Parse(btnEndTimeText.Tag.ToString()))
                {
                    //提示:开始时间不能大于结束时间
                    //提示:开始时间不能大于结束时间。
                    new LogicView.TipPopView().TipBox(StringId.tip, StringId.startTimeLessThanEndTime);
                    return;
                }
                Input inputTime = new Input();
                inputTime.sid = LogicMethod.NewSid();
                inputTime.sid = LogicMethod.CurrLogicMethod.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);
                LogicMethod.CurrLogicMethod.dictionary(dic, "key", "timesection");
                LogicMethod.CurrLogicMethod.dictionary(dic, "comparator", "=");
                LogicMethod.CurrLogicMethod.dictionary(dic, "data_type", "string");
                LogicMethod.CurrLogicMethod.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);
                }
                LogicMethod.RemoveAllView();
                AddLogic addLogic = new AddLogic();
                MainPage.BasePageView.AddChidren(addLogic);
                addLogic.Show();
                MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1;
                AddCondition(inputTime, edit, index);
            };
@@ -298,8 +275,8 @@
                    foreach (var dic in dicList)
                    {
                        string value = dic["value"];
                        string startTime = value.Split('~')[0];
                        string endtTime = value.Split('~')[1];
                        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;
@@ -309,34 +286,18 @@
            }
        }
        /// <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;
            //编辑之前的时间状态值
            string editTime = "";
            if (btn.Tag.ToString() != "0")
            {
                string h = "", m = "";
                sumTime = int.Parse(btn.Tag.ToString());
               int  sumTime = int.Parse(btn.Tag.ToString());
                if ((sumTime / 60) < 10)
                {
                    h = "0" + (sumTime / 60).ToString();
@@ -354,33 +315,74 @@
                {
                    m = (sumTime % 60).ToString();
                }
                timepoint = h + ":" + m;
                editTime = h + ":" + m;
            }
            LogicView.TimeView timePointView = new LogicView.TimeView();
            timePointView.FLayoutView(fLayout);
            timePointView.TimePoint(timePointView.frameLayout, editTime, (timeValue) =>
            {
                int hour = int.Parse(timeValue.Split(':')[0]);
                int minuet = int.Parse(timeValue.Split(':')[1]);
                int intValueTag = hour * 60 + minuet;
                //标记值,用于比较开始时间和结束时间大小;
                btn.Tag = intValueTag;
                //显示时间文本
                btn.Text = timeValue;
            });
        }
        /// <summary>
        /// 添加条件
        /// </summary>
        /// <param name="input"></param>
        private void AddCondition(Input input,bool edit,int index)
        {
            if (edit)
            {
                //移除旧数据
                Logic.currlogic.input.RemoveAt(index);
                //新数据插入旧数据的位置
                Logic.currlogic.input.Insert(index, input);
            }
            else
            {
                //添加一个新的时间条件
                Logic.currlogic.input.Add(input);
            }
            LogicMethod.CurrLogicMethod.RemoveAllView();
            AddLogic addLogic = new AddLogic();
            MainPage.BasePageView.AddChidren(addLogic);
            addLogic.Show();
            MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1;
                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);
        }
        /// <summary>
        /// 灰色弹框父控件
        /// </summary>
        /// <param name="frame">显示在哪个界面</param>
        /// <returns></returns>
        public FrameLayout GetFrame(FrameLayout frame, string tagKey)
        {
            for (int i = 0; i < frame.ChildrenCount; i++)
            {
                var fra = frame.GetChildren(i);
                if (fra != null)
                {
                    fra.RemoveFromParent();
                }
            }
            //选中时间回调方法,时间变化一次回调一次
            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);
            FrameLayout fLayout = new FrameLayout()
            {
                BackgroundColor = CSS.CSS_Color.viewTrans60lucence,
            };
            //确定点击事件
            timePointView.btnConfirm.MouseUpEventHandler += (sender1, e3) =>
            {
                btn.Tag = sumTime;
                btn.Text = timepoint;
                //只移除时间弹窗界面
                timePointView.frameLayout.RemoveFromParent();
            };
            frame.AddChidren(fLayout);
            return fLayout;
        }
    }
}