using System; using System.Collections.Generic; using System.Text; using ZigBee.Device; namespace Shared.Phone.UserCenter.Safety { /// /// 添加胁迫联系人 /// public class AddCoerceContactForm : EditorCommonForm { /// /// 信息提示控件 /// private NormalViewControl txtMsg = null; /// /// 电话列表 /// private List listPhoneData = null; /// /// 画面显示(底层会固定调用此方法,借以完成画面创建) /// /// public void ShowForm(List listData) { this.listPhoneData = listData; //设置头部信息 base.SetTitleText(Language.StringByID(R.MyInternationalizationString.uAddContactPersion)); //初始化中部信息 this.InitMiddleFrame(); } /// /// 初始化中部信息 /// private void InitMiddleFrame() { //清空bodyFrame this.ClearBodyFrame(); var row = new RowLayout(); row.Height = ControlCommonResourse.ListViewRowHeight; bodyFrameLayout.AddChidren(row); //联系电话 //var txtPhone = new PhoneAreaControl(); //txtPhone.Gravity = Gravity.CenterVertical; //row.AddChidren(txtPhone); //txtPhone.InitControl(this); //txtPhone.txtPhone.PlaceholderText = Language.StringByID(R.MyInternationalizationString.uPleaseInputContactWay); //提示信息 this.txtMsg = new NormalViewControl(800, true); txtMsg.X = ControlCommonResourse.XXLeft; txtMsg.Y = row.Bottom + Application.GetRealHeight(5); txtMsg.TextColor = UserCenterColor.Current.Red; bodyFrameLayout.AddChidren(txtMsg); //完成 //var btnfinish = new TopLayoutFinshView(); //topFrameLayout.AddChidren(btnfinish); //btnfinish.MouseUpEventHandler += (sender, e) => //{ // //执行保存手机操作 // this.SavePhoneNumber(txtPhone.AreaCode, txtPhone.PhoneNumber); //}; } /// /// 执行保存手机操作 /// private void SavePhoneNumber(string areaCode, string phoneNum) { //手机号检测 if (this.CheckPhoneNumber(areaCode, phoneNum) == false) { return; } //变更联系人方式 this.ChangedCoercePhoneNumber(areaCode, phoneNum); } /// /// 变更联系人方式 /// /// /// private async void ChangedCoercePhoneNumber(string areaCode, string phoneNum) { Dictionary dicPhone = new Dictionary(); dicPhone[phoneNum] = areaCode; //变更 var result = await HdlSafeguardLogic.Current.SetCoercePhoneNumber(dicPhone); if (result == false) { return; } Application.RunOnMainThread(() => { var data = new ZigBee.Device.Safeguard.PushTargetInfo(); data.PushNumber = areaCode + "-" + phoneNum; this.listPhoneData.Add(data); //添加明细行 this.LoadFormMethodByName("CoerceContactSettionForm", "AddPhoneNumRowLayout", data); //刷新主界面 this.LoadFormMethodByName("CoercePasswordMainForm", "InitMiddleFrame"); this.CloseForm(); }); } /// /// 检测手机号 /// /// /// private bool CheckPhoneNumber(string areaCode, string phone) { //输入为空 if (phone == string.Empty) { //请输入联系方式 txtMsg.Text = Language.StringByID(R.MyInternationalizationString.uPleaseInputContactWay); return false; } //检测手机号格式 if (HdlCheckLogic.Current.CheckPhoneNumber(phone, areaCode) == false) { //这不是一个有效的手机号 txtMsg.Text = Language.StringByID(R.MyInternationalizationString.uThisIsNotPhoneNumberType); return false; } foreach (var data in this.listPhoneData) { if (data.PushNumber == areaCode + "-" + phone) { //联系方式已经存在 txtMsg.Text = Language.StringByID(R.MyInternationalizationString.uThePhoneNumIsRepeat); return false; } } txtMsg.Text = string.Empty; return true; } } }