using Shared.Common; using System; using System.Collections.Generic; namespace Shared.Phone.UserCenter.Residence { /// /// 住宅管理的画面★ /// public class ResidenceManagementForm : EditorCommonForm { #region ■ 变量声明___________________________ /// /// 列表控件 /// private VerticalScrolViewLayout listView = null; /// /// 住宅数据 /// private Dictionary dicResidenceData = null; #endregion #region ■ 初始化_____________________________ /// /// 画面显示(底层会固定调用此方法,借以完成画面创建) /// public void ShowForm() { //设置标题信息 base.SetTitleText(Language.StringByID(R.MyInternationalizationString.ResidenceManagement)); if (UserCenterResourse.UserInfo.AuthorityNo == 1) { //右上添加按钮 var btnTopIcon = new MostRightIconControl(69, 69); btnTopIcon.UnSelectedImagePath = "Item/Add.png"; topFrameLayout.AddChidren(btnTopIcon); btnTopIcon.InitControl(); btnTopIcon.ButtonClickEvent += (sender, e) => { //var info = new Common.ResponseEntity.ResidenceObj(); //this.ShowEditorForm(info); }; } //初始化中部控件 //this.InitMiddleFrame(); } ///// ///// 初始化中部控件 ///// //private void InitMiddleFrame() //{ // //清空bodyFrame // this.ClearBodyFrame(); // listView = new VerticalScrolViewLayout(); // listView.Height = bodyFrameLayout.Height; // bodyFrameLayout.AddChidren(listView); // new System.Threading.Thread(() => // { // //设置住宅信息 // this.SetResidenceInfo(); // }) // { IsBackground = true }.Start(); //} ///// ///// 设置住宅信息 ///// //private async void SetResidenceInfo() //{ // //开启进度条 // this.ShowProgressBar(); // Application.RunOnMainThread(() => // { // this.listView?.RemoveAll(); // }); // //获取住宅信息 // var Pra = new GetResidenceInfoPra(); // string resultData = await UserCenterLogic.GetResponseDataByRequestHttps("App/GetHomePager", false, Pra); // if (resultData == null) // { // //关闭进度条 // this.CloseProgressBar(ShowReLoadMode.YES); // return; // } // this.dicResidenceData = new Dictionary(); // var pageData = Newtonsoft.Json.JsonConvert.DeserializeObject(resultData); // foreach (Common.ResponseEntity.ResidenceObj info in pageData.PageData) // { // if (info.IsOthreShare == false) // { // //收集该账号所拥有的自己的住宅的数据 // this.dicResidenceData[info.Id] = info; // } // Application.RunOnMainThread(() => // { // if (this.Parent != null) // { // this.AddRowLayout(info); // } // }); // } // //关闭进度条 // this.CloseProgressBar(); //} #endregion //#region ■ 添加住宅的行_______________________ ///// ///// 添加住宅的行 ///// ///// //private void AddRowLayout(Common.ResponseEntity.ResidenceObj info) //{ // if (info.IsOthreShare == true) // { // return; // } // var rowLayout = new RowLayout(); // rowLayout.Height = ControlCommonResourse.ListViewRowHeight; // this.listView.AddChidren(rowLayout); // //图标 // var btnIcon = new RowLeftIconView(); // btnIcon.ChangedControlInPointMode(); // rowLayout.AddChidren(btnIcon); // //住宅 // var txtResidence = new RowCenterView(true); // txtResidence.Text = info.Name; // rowLayout.AddChidren(txtResidence); // txtResidence.X -= ControlCommonResourse.PointXXLeft; // //不是分享过来的住宅 // if (info.IsOthreShare == false) // { // //编辑 // var btnEditor = new RowEditorButton(); // rowLayout.AddRightView(btnEditor); // btnEditor.MouseUpEventHandler += (sender, e) => // { // this.ShowEditorForm(info); // }; // //不能删除当前正在操作的住宅 // if (Common.Config.Instance.HomeId != info.Id) // { // //删除 // var btnDelete = new RowDeleteButton(); // rowLayout.AddRightView(btnDelete); // btnDelete.MouseUpEventHandler += (sender, e) => // { // //检测能否删除住宅 // if (this.CheckIsCanDeleteResidence(info) == false) // { // return; // } // //确认要删除吗? // string msg = Language.StringByID(R.MyInternationalizationString.uShowDoDeleteMsg); // this.ShowConfirmMsg(msg, "DeleteResidence", info); // }; // } // } // //成员的管理员权限,只能编辑,不能删除 // //if (info.AccountType == 1) // //{ // // //编辑 // // var btnEditor = new RowEditorButton(); // // rowLayout.AddRightView(btnEditor); // // btnEditor.MouseUpEventHandler += (sender, e) => // // { // // this.ShowEditorForm(info); // // }; // //} //} //#endregion //#region ■ 显示编辑画面_______________________ ///// ///// 显示编辑画面 ///// ///// //private void ShowEditorForm(Common.ResponseEntity.ResidenceObj info) //{ // //生成一个弹窗画面 // var dialogForm = new DialogInputFrameControl(this, DialogFrameMode.OnlyInput); // if (string.IsNullOrEmpty(info.Name) == true) // { // //添加住宅 // dialogForm.SetTitleText(Language.StringByID(R.MyInternationalizationString.uAddResidence)); // } // else // { // //编辑住宅 // dialogForm.SetTitleText(Language.StringByID(R.MyInternationalizationString.uEditorResidence)); // } // //请输入住宅名称 // dialogForm.SetTipText(Language.StringByID(R.MyInternationalizationString.uPleaseInputResidenceName)); // if (info.Name != null) // { // dialogForm.InputText = info.Name; // } // //按下确认按钮 // dialogForm.ComfirmClickEvent += (()=> // { // string resiName = dialogForm.InputText; // if (resiName == string.Empty) // { // //请输入住宅名称 // string msg = Language.StringByID(R.MyInternationalizationString.uPleaseInputResidenceName); // this.ShowErrorMsg(msg); // return; // } // //画面关闭 // dialogForm.CloseDialog(); // if (info.Name != resiName) // { // //保存住宅 // this.SaveResidence(resiName, info, string.IsNullOrEmpty(info.Name) == false); // } // }); //} //#endregion //#region ■ 保存住宅___________________________ ///// ///// 保存住宅 ///// ///// ///// ///// ///// //private async void SaveResidence(string ResidenceName, Common.ResponseEntity.ResidenceObj info, bool isEditor) //{ // //检测能否保存住宅 // if (this.CheckIsCanSaveResidence(info.Id, ResidenceName, isEditor) == false) // { // return; // } // //开启进度条 // this.ShowProgressBar(); // if (isEditor == true) // { // var Pra = new EditorResidencePra(); // Pra.HomeId = info.Id; // Pra.Name = ResidenceName; // //编辑住宅 // bool flage = await UserCenterLogic.GetResultStatuByRequestHttps("App/EditHome", false, Pra); // if (flage == false) // { // //关闭进度条 // this.CloseProgressBar(); // return; // } // //刷新内存的住宅名 // House.EditorHouseByHouseId(info.Id, ResidenceName); // //重新刷新列表 // this.SetResidenceInfo(); // } // else // { // var Pra = new AddResidencePra(); // Pra.Name = ResidenceName; // //添加住宅 // string resultData = await UserCenterLogic.GetResponseDataByRequestHttps("App/AddHome", false, Pra); // if (resultData == null) // { // //关闭进度条 // this.CloseProgressBar(); // return; // } // var newInfo = Newtonsoft.Json.JsonConvert.DeserializeObject>(resultData); // House.AddHouse(newInfo[0].Id, ResidenceName, 0); // //重新刷新列表 // this.SetResidenceInfo(); // } //} //#endregion //#region ■ 删除住宅___________________________ ///// ///// 删除住宅 ///// ///// //public async void DeleteResidence(Common.ResponseEntity.ResidenceObj info) //{ // //开启进度条 // this.ShowProgressBar(); // var Pra = new DeleteResidencePra(); // Pra.HomeId = info.Id; // bool result = await UserCenterLogic.GetResultStatuByRequestHttps("App/DelHome", false, Pra); // if (result == false) // { // //关闭进度条 // this.CloseProgressBar(); // return; // } // House.DeleteHouseByHouseId(info.Id); // this.SetResidenceInfo(); //} //#endregion //#region ■ 一般方法___________________________ ///// ///// 检测能否删除住宅 ///// ///// ///// //private bool CheckIsCanDeleteResidence(Common.ResponseEntity.ResidenceObj info) //{ // if (this.dicResidenceData.Count == 1) // { // //如果此账号下只剩下唯一一个自己的住宅,当删除这个住宅时,提示不能删除 // //因为最少要有一个住宅 // if (this.dicResidenceData.ContainsKey(info.Id) == true) // { // //不能删除最后唯一的住宅 // string msg = Language.StringByID(R.MyInternationalizationString.uDoNotDeleteLastResidence); // this.ShowErrorMsg(msg); // return false; // } // } // return true; //} ///// ///// 检测能否保存住宅 ///// ///// 住宅ID ///// 住宅名 ///// isEditor ///// //private bool CheckIsCanSaveResidence(string residenceId, string residenceName, bool isEditor) //{ // //住宅名字重复检测 // foreach (string strId in this.dicResidenceData.Keys) // { // if (residenceId != strId && residenceName == this.dicResidenceData[strId].Name) // { // //住宅名字已经存在 // int msgId = isEditor == true ? R.MyInternationalizationString.EditZigbeeHome_Exist : R.MyInternationalizationString.AddZigbeeHome_Exist; // string msg = Language.StringByID(msgId); // this.ShowErrorMsg(msg); // return false; // } // } // return true; //} //#endregion //#region ■ 结构体_____________________________ ///// ///// 访问住宅信息接口的启动参数(查询专用) ///// //public class GetResidenceInfoPra:IfacePraCommon //{ // /// // /// RequestVersion // /// // public string RequestVersion = Common.CommonPage.RequestVersion; // /// // /// ReqDto // /// // public TokenInfo ReqDto = new TokenInfo(); //} ///// ///// 访问住宅信息接口的启动参数(查询专用) ///// //public class TokenInfo //{ // /// // /// LoginAccessToken // /// // public string LoginAccessToken = Common.Config.Instance.Token; // /// // /// PageSetting // /// // public PageSettingInfo PageSetting = new PageSettingInfo() // { // Page = 1, // PageSize = 500 // }; //} ///// ///// 添加住宅的启动参数 ///// //public class AddResidencePra:IfacePraCommon //{ // /// // /// RequestVersion // /// // public string RequestVersion = Common.CommonPage.RequestVersion; // /// // /// LoginAccessToken // /// // public string LoginAccessToken = Common.Config.Instance.Token; // /// // /// Name // /// // public string Name = string.Empty; //} ///// ///// 新住宅的信息 ///// //public class NewResidenceInfo //{ // /// // /// ZigbeeHomeGuid // /// // public string Id = string.Empty; //} ///// ///// 编辑住宅的启动参数 ///// //public class EditorResidencePra : IfacePraCommon //{ // /// // /// RequestVersion // /// // public string RequestVersion = Common.CommonPage.RequestVersion; // /// // /// LoginAccessToken // /// // public string LoginAccessToken = Common.Config.Instance.Token; // /// // /// ZigbeeHomeId // /// // public string HomeId = ""; // /// // /// Name // /// // public string Name = string.Empty; //} ///// ///// 删除住宅的启动参数 ///// //public class DeleteResidencePra : IfacePraCommon //{ // /// // /// RequestVersion // /// // public string RequestVersion = Common.CommonPage.RequestVersion; // /// // /// LoginAccessToken // /// // public string LoginAccessToken = Common.Config.Instance.Token; // /// // /// ZigbeeHomeId // /// // public string HomeId = ""; //} //#endregion } }