gxc
2019-11-04 b7b3e92bed9c4553e30e2901a1877f088a5f8823
ZigbeeApp/Shared/Phone/UserCenter/Gateway/Add/GatewayInfoAddForm.cs
New file
@@ -0,0 +1,225 @@
using System;
using System.Collections.Generic;
using System.Text;
using ZigBee.Device;
namespace Shared.Phone.UserCenter.GatewayAdd
{
    /// <summary>
    /// 编辑新添加的网关信息的画面UI
    /// </summary>
    public class GatewayInfoAddForm : EditorCommonForm
    {
        #region ■ 变量声明___________________________
        /// <summary>
        /// 网关名称控件
        /// </summary>
        private FrameCaptionInputControl rowGateway = null;
        /// <summary>
        /// 网关名字修改后的回调函数
        /// </summary>
        public Action<ZbGateway> ActionGatewayReName = null;
        /// <summary>
        /// 当前选择的网关
        /// </summary>
        private ZbGateway zbGateway = null;
        /// <summary>
        /// 设备明细列表控件的桌布
        /// </summary>
        private DeviceInformationListControl listDeviceControl = null;
        #endregion
        #region ■ 初始化_____________________________
        /// <summary>
        /// 画面显示(底层会固定调用此方法,借以完成画面创建)
        /// </summary>
        /// <param name="i_zbGateway">当前选择的网关</param>
        public void ShowForm(ZbGateway i_zbGateway)
        {
            this.zbGateway = i_zbGateway;
            //设置标题信息
            base.SetTitleText(Language.StringByID(R.MyInternationalizationString.uEditorGatewayInformation));
            //网关定位
            var btnIcon = new MostRightIconControl(69, 69);
            btnIcon.UnSelectedImagePath = "Item/Test.png";
            topFrameLayout.AddChidren(btnIcon);
            btnIcon.InitControl();
            btnIcon.ButtonClickEvent += (sender, e) =>
            {
                //测试
                HdlGatewayLogic.Current.SetTestCommand(i_zbGateway);
            };
            //初始化中部控件
            this.InitMiddleFrame();
        }
        /// <summary>
        /// 初始化中部控件
        /// </summary>
        private void InitMiddleFrame()
        {
            //清空bodyFrame
            this.ClearBodyFrame();
            //图片上下的间距(上下间距一致)
            int picSpcae = Application.GetRealHeight(100);
            //图片
            var btnImage = new PicViewControl(838, 530, true);
            btnImage.Y = picSpcae;
            btnImage.Gravity = Gravity.CenterHorizontal;
            HdlGatewayLogic.Current.SetRealGatewayPictrue(btnImage, zbGateway);
            bodyFrameLayout.AddChidren(btnImage);
            //完成按钮
            var btnFinish = new BottomClickButton();
            btnFinish.TextID = R.MyInternationalizationString.uFinish;
            bodyFrameLayout.AddChidren(btnFinish);
            btnFinish.MouseUpEventHandler += (sender, e) =>
            {
                //完成按钮按下
                this.FinishButtonClick();
            };
            //白色底部背景
            var frameBottomWhite = new FrameLayout();
            frameBottomWhite.Y = btnFinish.Y - ControlCommonResourse.BottomButtonAndListViewSpace;
            frameBottomWhite.Height = bodyFrameLayout.Height - btnFinish.Y + ControlCommonResourse.BottomButtonAndListViewSpace;
            frameBottomWhite.BackgroundColor = UserCenterColor.Current.White;
            bodyFrameLayout.AddChidren(frameBottomWhite);
            //将完成按钮置顶
            btnFinish.BringToFront();
            //自定义的设备列表容器
            this.listDeviceControl = new DeviceInformationListControl();
            //列表控件最大的高度(完成按钮的Y轴 - 设置的间隔 - 图片Y轴 - 图片的三分之一)
            int listViewMaxHeight = btnFinish.Y - ControlCommonResourse.BottomButtonAndListViewSpace - btnImage.Y - btnImage.Height / 3;
            //明细Frame的最小高度(底部frame的Y轴 - 图片底部 - 图片与弧度圆的间距 - 弧度圆高度)
            int minDetailHeight = frameBottomWhite.Y - btnImage.Bottom - picSpcae - listDeviceControl.halfRoundHeigth;
            //初始化控件
            listDeviceControl.InitControl(bodyFrameLayout, frameBottomWhite.Height, listViewMaxHeight, minDetailHeight, 3);
            //设备编辑
            var btnTitle = new DetailTitleControl(Application.GetRealWidth(800), listDeviceControl.titleHeight, false);
            btnTitle.TextID = R.MyInternationalizationString.uDeviceEditor;
            listDeviceControl.AddChidren(btnTitle);
            //添加全部菜单行
            this.AddAllMenuRow();
        }
        #endregion
        #region ■ 添加全部菜单行_____________________
        /// <summary>
        /// 添加全部菜单行
        /// </summary>
        private void AddAllMenuRow()
        {
            //网关名称
            string caption = Language.StringByID(R.MyInternationalizationString.uGatewayName);
            string nameValue = HdlGatewayLogic.Current.GetGatewayName(zbGateway);
            this.rowGateway = new FrameCaptionInputControl(caption, nameValue);
            listDeviceControl.AddChidren(rowGateway);
            rowGateway.InitControl();
            rowGateway.AddBottomLine();
            //网关IP
            caption = Language.StringByID(R.MyInternationalizationString.uGatewayIP);
            nameValue = HdlGatewayLogic.Current.GetGatewayBaseInfoAttribute(zbGateway, "IpAddress").ToString();
            var btnIp = new FrameCaptionViewControl(caption, nameValue);
            listDeviceControl.AddChidren(btnIp);
            btnIp.InitControl();
            btnIp.txtView.TextColor = UserCenterColor.Current.TextGrayColor;
            btnIp.AddBottomLine();
            //网关类型
            caption = Language.StringByID(R.MyInternationalizationString.uGatewayType);
            nameValue = HdlGatewayLogic.Current.GetGatewayImageText(this.zbGateway);
            var btnObject = new FrameCaptionViewControl(caption, nameValue);
            listDeviceControl.AddChidren(btnObject);
            btnObject.InitControl();
            btnObject.txtView.TextColor = UserCenterColor.Current.TextGrayColor;
            btnObject.AddBottomLine();
        }
        #endregion
        #region ■ 完成按钮按下_______________________
        /// <summary>
        /// 完成按钮按下
        /// </summary>
        private void FinishButtonClick()
        {
            if (string.IsNullOrEmpty(this.rowGateway.Text) == true)
            {
                //请输入网关名称
                this.rowGateway.Text = string.Empty;
                string msg = Language.StringByID(R.MyInternationalizationString.uGatewayNameMastInput);
                this.ShowMassage(ShowMsgType.Error, msg);
                return;
            }
            string nameValue = HdlGatewayLogic.Current.GetGatewayName(zbGateway);
            if (nameValue == this.rowGateway.Text)
            {
                //同名不需要处理
                this.CloseForm();
                return;
            }
            //修改名字
            this.SetGatewayName(this.rowGateway.Text);
        }
        #endregion
        #region ■ 修改名字___________________________
        /// <summary>
        /// 设置网关名字
        /// </summary>
        /// <param name="gatewayName">网关名称</param>
        private async void SetGatewayName(string gatewayName)
        {
            //打开进度条
            this.ShowProgressBar();
            //修改本地网关名
            var result = await HdlGatewayLogic.Current.ReName(zbGateway, gatewayName);
            //关闭进度条
            this.CloseProgressBar();
            //网关修改失败
            if (result == false)
            {
                return;
            }
            Application.RunOnMainThread(() =>
            {
                this.ActionGatewayReName?.Invoke(zbGateway);
                //关闭界面
                this.CloseForm();
            });
        }
        #endregion
        #region ■ 关闭界面___________________________
        /// <summary>
        /// 画面关闭
        /// </summary>
        public override void CloseForm()
        {
            this.ActionGatewayReName = null;
            base.CloseForm();
        }
        #endregion
    }
}