| | |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System;
|
| | | using System.Collections.Generic;
|
| | | using System.IO;
|
| | | using System.Threading.Tasks; |
| | | using ZigBee.Device; |
| | | |
| | | namespace Shared.Phone.UserCenter.GatewayAdd |
| | | { |
| | | /// <summary> |
| | | /// 网关搜索中 |
| | | /// </summary> |
| | | public class WiredGatewaySearchForm : EditorCommonForm |
| | | using System.Threading.Tasks;
|
| | | using ZigBee.Device;
|
| | |
|
| | | namespace Shared.Phone.UserCenter.GatewayAdd
|
| | | {
|
| | | /// <summary>
|
| | | /// 网关搜索中
|
| | | /// </summary>
|
| | | public class WiredGatewaySearchForm : EditorCommonForm
|
| | | {
|
| | | #region ■ 变量声明___________________________ |
| | | |
| | | /// <summary> |
| | | /// 列表控件 |
| | | /// </summary> |
| | | private VerticalScrolViewLayout listView = null; |
| | | /// <summary> |
| | | /// 这是个透明的控件 |
| | | /// </summary> |
| | | private FrameLayout frameTransparent = null; |
| | | /// <summary> |
| | | /// 线程执行中 |
| | | /// </summary> |
| | | private bool IsThreadAction = true; |
| | | /// <summary> |
| | | /// 搜索时间 |
| | | /// </summary> |
| | | private int searchTime = 60; |
| | | #region ■ 变量声明___________________________
|
| | |
|
| | | /// <summary>
|
| | | /// 列表控件
|
| | | /// </summary>
|
| | | private VerticalScrolViewLayout listView = null;
|
| | | /// <summary>
|
| | | /// 这是个透明的控件
|
| | | /// </summary>
|
| | | private FrameLayout frameTransparent = null;
|
| | | /// <summary>
|
| | | /// 线程执行中
|
| | | /// </summary>
|
| | | private bool IsThreadAction = true;
|
| | | /// <summary>
|
| | | /// 搜索时间
|
| | | /// </summary>
|
| | | private int searchTime = 60;
|
| | | /// <summary>
|
| | | /// 停止搜索的按键
|
| | | /// </summary> |
| | | private BottomClickButton btnStop = null; |
| | | /// </summary>
|
| | | private BottomClickButton btnStop = null;
|
| | | /// <summary>
|
| | | /// 网关的主键(value:剩余检测次数,用于对应异常的网关)
|
| | | /// </summary> |
| | | /// </summary>
|
| | | private Dictionary<string, int> dicGatewayId = new Dictionary<string, int>();
|
| | |
|
| | | #endregion |
| | | #endregion
|
| | |
|
| | | #region ■ 初始化_____________________________
|
| | |
|
| | | /// <summary> |
| | | /// 画面显示(底层会固定调用此方法,借以完成画面创建) |
| | | /// </summary> |
| | | public void ShowForm() |
| | | { |
| | | //设置标题信息 |
| | | base.SetTitleText(Language.StringByID(R.MyInternationalizationString.uAddWiredGateway)); |
| | | |
| | | //初始化中部控件 |
| | | this.InitMiddleFrame(); |
| | | |
| | | //开启线程 |
| | | this.StartThread(); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 初始化中部控件 |
| | | /// </summary> |
| | | private void InitMiddleFrame() |
| | | { |
| | | //清空bodyFrame |
| | | this.ClearBodyFrame(); |
| | | |
| | | //网关列表,这个控件置于背部 |
| | | /// <summary>
|
| | | /// 画面显示(底层会固定调用此方法,借以完成画面创建)
|
| | | /// </summary>
|
| | | public void ShowForm()
|
| | | {
|
| | | //设置标题信息
|
| | | base.SetTitleText(Language.StringByID(R.MyInternationalizationString.uAddWiredGateway));
|
| | |
|
| | | //初始化中部控件
|
| | | this.InitMiddleFrame();
|
| | |
|
| | | //开启线程
|
| | | this.StartThread();
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 初始化中部控件
|
| | | /// </summary>
|
| | | private void InitMiddleFrame()
|
| | | {
|
| | | //清空bodyFrame
|
| | | this.ClearBodyFrame();
|
| | |
|
| | | //网关列表,这个控件置于背部
|
| | | listView = new VerticalScrolViewLayout();
|
| | | listView.Height = ControlCommonResourse.ListViewRowHeight * 5; |
| | | bodyFrameLayout.AddChidren(listView); |
| | | |
| | | //图片,背景要透明 |
| | | frameTransparent = new FrameLayout |
| | | { |
| | | Width = bodyFrameLayout.Width, |
| | | Height = bodyFrameLayout.Height, |
| | | Gravity = Gravity.CenterHorizontal, |
| | | BackgroundColor = UserCenterColor.Current.Transparent |
| | | }; |
| | | bodyFrameLayout.AddChidren(frameTransparent); |
| | | |
| | | //图片 |
| | | listView.Height = ControlCommonResourse.ListViewRowHeight * 5;
|
| | | bodyFrameLayout.AddChidren(listView);
|
| | |
|
| | | //图片,背景要透明
|
| | | frameTransparent = new FrameLayout
|
| | | {
|
| | | Width = bodyFrameLayout.Width,
|
| | | Height = bodyFrameLayout.Height,
|
| | | Gravity = Gravity.CenterHorizontal,
|
| | | BackgroundColor = UserCenterColor.Current.Transparent
|
| | | };
|
| | | bodyFrameLayout.AddChidren(frameTransparent);
|
| | |
|
| | | //图片
|
| | | var btnimage = new PicViewControl(620, 620);
|
| | | btnimage.Y = ControlCommonResourse.ListViewRowHeight * 2;
|
| | | btnimage.Gravity = Gravity.CenterHorizontal;
|
| | | btnimage.UnSelectedImagePath = "Gateway/SearchGateway.png"; |
| | | btnimage.UnSelectedImagePath = "Gateway/SearchGateway.png";
|
| | | frameTransparent.AddChidren(btnimage);
|
| | |
|
| | | //智能网关配置网络中
|
| | | var btnText1 = new NormalViewControl(bodyFrameLayout.Width, false);
|
| | | btnText1.Y = btnimage.Bottom + Application.GetRealHeight(60);
|
| | | btnText1.Gravity = Gravity.CenterHorizontal;
|
| | | btnText1.TextID = R.MyInternationalizationString.uGatewaySetting; |
| | | frameTransparent.AddChidren(btnText1); |
| | | |
| | | //请稍候 |
| | | btnText1.TextID = R.MyInternationalizationString.uGatewaySetting;
|
| | | frameTransparent.AddChidren(btnText1);
|
| | |
|
| | | //请稍候
|
| | | var btnText2 = new NormalViewControl(bodyFrameLayout.Width, false);
|
| | | btnText2.Y = btnText1.Bottom + Application.GetRealHeight(30);
|
| | | btnText2.Gravity = Gravity.CenterHorizontal;
|
| | | btnText2.TextID = R.MyInternationalizationString.uPleaseWait; |
| | | frameTransparent.AddChidren(btnText2); |
| | | |
| | | //停止搜索 |
| | | btnText2.TextID = R.MyInternationalizationString.uPleaseWait;
|
| | | frameTransparent.AddChidren(btnText2);
|
| | |
|
| | | //停止搜索
|
| | | btnStop = new BottomClickButton();
|
| | | btnStop.TextID = R.MyInternationalizationString.uStopSearch; |
| | | frameTransparent.AddChidren(btnStop); |
| | | |
| | | btnStop.MouseUpEventHandler += this.btnStop_MouseClick; |
| | | btnStop.TextID = R.MyInternationalizationString.uStopSearch;
|
| | | frameTransparent.AddChidren(btnStop);
|
| | |
|
| | | btnStop.MouseUpEventHandler += this.btnStop_MouseClick;
|
| | | }
|
| | |
|
| | | #endregion |
| | | #endregion
|
| | |
|
| | | #region ■ 开启线程___________________________
|
| | |
|
| | | /// <summary> |
| | | /// 开启搜索网关的子线程 |
| | | /// </summary> |
| | | private void StartThread() |
| | | /// <summary>
|
| | | /// 开启搜索网关的子线程
|
| | | /// </summary>
|
| | | private void StartThread()
|
| | | {
|
| | | string textValue = btnStop.Text;
|
| | | //清空保存的主键
|
| | |
| | |
|
| | | //清空全部列表
|
| | | HdlGatewayLogic.Current.ClearAllRealGateway();
|
| | | ZigBee.Common.Application.IsSearchingGateway = true; |
| | | |
| | | //开启倒计时线程 |
| | | this.StartTimeCountThread(textValue); |
| | | |
| | | new System.Threading.Thread(async () => |
| | | ZigBee.Common.Application.IsSearchingGateway = true;
|
| | |
|
| | | //开启倒计时线程
|
| | | this.StartTimeCountThread(textValue);
|
| | |
|
| | | HdlThreadLogic.Current.RunThread(async () =>
|
| | | {
|
| | | while (this.IsThreadAction)
|
| | | {
|
| | |
| | |
|
| | | //检测搜索到的网关,然后添加到画面的行里面
|
| | | await this.CheckZbGatewayAndSetRow();
|
| | | } |
| | | }) |
| | | { IsBackground = true }.Start(); |
| | | }
|
| | | });
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | |
| | | //搜索时间
|
| | | this.searchTime = 60;
|
| | |
|
| | | new System.Threading.Thread(() =>
|
| | | HdlThreadLogic.Current.RunThread(() =>
|
| | | {
|
| | | while (this.IsThreadAction)
|
| | | {
|
| | |
| | | btnStop.Text = textValue;
|
| | | }
|
| | | });
|
| | | })
|
| | | { IsBackground = true }.Start();
|
| | | });
|
| | | }
|
| | |
|
| | | #endregion |
| | | #endregion
|
| | |
|
| | | #region ■ 网关检测___________________________
|
| | |
|
| | | /// <summary> |
| | | /// 检测搜索到的网关,然后添加到画面的行里面 |
| | | /// </summary> |
| | | private async Task<bool> CheckZbGatewayAndSetRow() |
| | | /// <summary>
|
| | | /// 检测搜索到的网关,然后添加到画面的行里面
|
| | | /// </summary>
|
| | | private async Task<bool> CheckZbGatewayAndSetRow()
|
| | | {
|
| | | List<string> listId = new List<string>();
|
| | | for (int i = 0; i < ZbGateway.GateWayList.Count; i++)
|
| | |
| | | this.dicGatewayId[gwId] = this.dicGatewayId[gwId] - 1;
|
| | | listId.Add(gwId);
|
| | | }
|
| | | } |
| | | }
|
| | | if (listId.Count == 0)
|
| | | {
|
| | | //没有新的网关,或者次数已经用完
|
| | | return true;
|
| | | } |
| | | for (int i = 0; i < listId.Count; i++) |
| | | { |
| | | }
|
| | | for (int i = 0; i < listId.Count; i++)
|
| | | {
|
| | | ZbGateway way = ZbGateway.GateWayList.Find((obj) => HdlGatewayLogic.Current.GetGatewayId(obj) == listId[i]);
|
| | | if (way == null)
|
| | | {
|
| | |
| | | //添加搜索到的网关到画面
|
| | | this.AddRowLayout(way, mode);
|
| | | }
|
| | | }); |
| | | } |
| | | return true; |
| | | });
|
| | | }
|
| | | return true;
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
| | | #region ■ 添加网关行控件_____________________
|
| | |
|
| | | /// <summary>
|
| | | /// 添加搜索到的网关到画面 |
| | | /// </summary> |
| | | /// <param name="zbGateway">Zb gateway.</param> |
| | | /// <param name="mode">网关绑定模式</param> |
| | | private void AddRowLayout(ZbGateway zbGateway, GatewayBindMode mode) |
| | | /// 添加搜索到的网关到画面
|
| | | /// </summary>
|
| | | /// <param name="zbGateway">Zb gateway.</param>
|
| | | /// <param name="mode">网关绑定模式</param>
|
| | | private void AddRowLayout(ZbGateway zbGateway, GatewayBindMode mode)
|
| | | {
|
| | | if (listView == null)
|
| | | {
|
| | |
| | | this.OpenEditorGatewayForm(gatewayRow, mode);
|
| | | };
|
| | | //向右图标
|
| | | gatewayRow.frameTable.AddRightIconControl();
|
| | | gatewayRow.frameTable.AddRightArrow();
|
| | |
|
| | | //绑定
|
| | | var btnBind = gatewayRow.frameTable.AddMostRightView("", 300);
|
| | |
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 添加搜索到的网关到画面的行 |
| | | /// </summary> |
| | | /// <param name="zbGateway">Zb gateway.</param> |
| | | private void AddFailRowLayout(ZbGateway zbGateway) |
| | | /// 添加搜索到的网关到画面的行
|
| | | /// </summary>
|
| | | /// <param name="zbGateway">Zb gateway.</param>
|
| | | private void AddFailRowLayout(ZbGateway zbGateway)
|
| | | {
|
| | | if (listView == null)
|
| | | {
|
| | |
| | | btnBind.TextColor = UserCenterColor.Current.Red;
|
| | | }
|
| | |
|
| | | #endregion |
| | | #endregion
|
| | |
|
| | | #region ■ 执行网关保存_______________________
|
| | |
|
| | |
| | |
|
| | | #endregion
|
| | |
|
| | | #region ■ 按钮事件___________________________ |
| | | #region ■ 按钮事件___________________________
|
| | |
|
| | | /// <summary> |
| | | /// 停止按钮按下 |
| | | /// </summary> |
| | | /// <param name="sender">Sender.</param> |
| | | /// <param name="e">E.</param> |
| | | private void btnStop_MouseClick(object sender, MouseEventArgs e) |
| | | { |
| | | //存在误按的可能,画面开启的2秒前,禁止按下停止按钮 |
| | | if (this.searchTime >= 58 || this.Parent == null) |
| | | { |
| | | return; |
| | | /// <summary>
|
| | | /// 停止按钮按下
|
| | | /// </summary>
|
| | | /// <param name="sender">Sender.</param>
|
| | | /// <param name="e">E.</param>
|
| | | private void btnStop_MouseClick(object sender, MouseEventArgs e)
|
| | | {
|
| | | //存在误按的可能,画面开启的2秒前,禁止按下停止按钮
|
| | | if (this.searchTime >= 58 || this.Parent == null)
|
| | | {
|
| | | return;
|
| | | }
|
| | | //超时
|
| | | if (e == null && listView.ChildrenCount == 0)
|
| | |
| | | //没有发现新网关,请检查网关链接是否正常
|
| | | string msg = Language.StringByID(R.MyInternationalizationString.uNotFoundNewGatewayPleaseCheckMsg);
|
| | | this.ShowMassage(ShowMsgType.Tip, msg);
|
| | | } |
| | | Application.RunOnMainThread(() => |
| | | { |
| | | this.IsThreadAction = false; |
| | | }
|
| | | Application.RunOnMainThread(() =>
|
| | | {
|
| | | this.IsThreadAction = false;
|
| | | if (frameTransparent != null)
|
| | | {
|
| | | frameTransparent.Visible = false;
|
| | | } |
| | | }
|
| | | if (listView != null)
|
| | | {
|
| | | listView.Height = bodyFrameLayout.Height - Application.GetRealHeight(18);
|
| | | } |
| | | this.searchTime = 60; |
| | | }); |
| | | } |
| | | |
| | | }
|
| | | this.searchTime = 60;
|
| | | });
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
|
| | | #region ■ 界面关闭___________________________ |
| | | #region ■ 界面关闭___________________________
|
| | |
|
| | | /// <summary>
|
| | | /// 画面关闭
|
| | | /// </summary> |
| | | public override void CloseForm() |
| | | { |
| | | /// </summary>
|
| | | public override void CloseForm()
|
| | | {
|
| | | this.IsThreadAction = false;
|
| | |
|
| | | ZigBee.Common.Application.IsSearchingGateway = false;
|
| | |
| | | {
|
| | | //刷新主页
|
| | | UserView.UserPage.Instance.Fresh();
|
| | | } |
| | | |
| | | base.CloseForm(); |
| | | }
|
| | |
|
| | | base.CloseForm();
|
| | | }
|
| | |
|
| | | #endregion |
| | | #endregion
|
| | |
|
| | | #region ■ 一般方法___________________________
|
| | |
|
| | | #endregion |
| | | } |
| | | } |
| | | #endregion
|
| | | }
|
| | | }
|