using System;
|
using System.Collections.Generic;
|
|
namespace Shared.SimpleControl.Phone
|
{
|
public class GuideAddResidence : FrameLayout
|
{
|
public GuideAddResidence ()
|
{
|
BackgroundColor = SkinStyle.Current.MainColor;
|
}
|
|
public void ShowHomeList (bool showDialog = true)
|
{
|
new System.Threading.Thread (() => {
|
bool needHide = true;
|
try {
|
Application.RunOnMainThread (() => {
|
MainPage.Loading.Start ("Please wait...");
|
new System.Threading.Thread (() => {
|
System.Threading.Thread.Sleep (10000);
|
if (needHide) {
|
MainPage.Loading.MouseUpEventHandler += (sd, dd) => {
|
Application.RunOnMainThread (() => {
|
this.RemoveFromParent ();
|
MainPage.Loading.Hide ();
|
needHide = false;
|
});
|
};
|
}
|
}) { IsBackground = true }.Start ();
|
});
|
// 读取住宅列表
|
var requestJson2 = Newtonsoft.Json.JsonConvert.SerializeObject (new HomeListObj ());
|
var revertObj2 = MainPage.RequestHttps ("HomeList", requestJson2);
|
if (revertObj2.StateCode == "SUCCESS") {
|
var responseDataObj = Newtonsoft.Json.JsonConvert.DeserializeObject<List<RegionInfoRes>> (revertObj2.ResponseData.ToString ());
|
UserConfig.Instance.HomeLists = responseDataObj;
|
if (UserConfig.Instance.HomeLists.Count > 0) {
|
if (string.IsNullOrEmpty (UserConfig.Instance.HomeLists [0].RegionName)) {
|
Application.RunOnMainThread (() => {
|
MainPage.Loading.Hide ();
|
this.RemoveFromParent ();
|
return;
|
});
|
}
|
UserConfig.Instance.SaveUserConfig ();
|
UserConfig.Instance.CurrentRegion = responseDataObj.Find ((obj) => obj.RegionName == UserConfig.Instance.CurrentRegion.RegionName);
|
} else {
|
Application.RunOnMainThread (() => {
|
MainPage.Loading.Hide ();
|
this.RemoveFromParent ();
|
});
|
return;
|
}
|
} else {
|
Application.RunOnMainThread (() => {
|
MainPage.Loading.Hide ();
|
this.RemoveFromParent ();
|
return;
|
});
|
}
|
//加载住宅界面
|
Application.RunOnMainThread (() => {
|
MainPage.Loading.Hide ();
|
ShowHomeListView (showDialog);
|
});
|
} catch (Exception ex) {
|
Application.RunOnMainThread (() => {
|
MainPage.Loading.Hide ();
|
this.RemoveFromParent ();
|
needHide = false;
|
});
|
Console.WriteLine (ex.Message);
|
} finally {
|
needHide = false;
|
}
|
}) { IsBackground = true }.Start ();
|
}
|
|
void ShowHomeListView (bool showDialog = true)
|
{
|
RemoveAll ();
|
#region 标题
|
var topView = new FrameLayout () {
|
Y = Application.GetRealHeight (36),
|
Height = Application.GetRealHeight (90),
|
};
|
AddChidren (topView);
|
|
var title = new Button () {
|
TextAlignment = TextAlignment.Center,
|
Text= "Zones/Residences",
|
TextSize = 19,
|
TextColor = SkinStyle.Current.TextColor1
|
};
|
topView.AddChidren (title);
|
|
Button ItemButton = new Button () {
|
Width = Application.GetRealWidth (55),
|
Height = Application.GetRealHeight (55),
|
UnSelectedImagePath = "Item/+.png",
|
SelectedImagePath = "Item/+.png",
|
Y = Application.GetRealHeight (17),
|
X = Application.GetRealWidth (640 - 80),
|
};
|
topView.AddChidren (ItemButton);
|
ItemButton.MouseUpEventHandler += (sender1, e1) => {
|
GuideAddHomeDialog (new RegionInfoRes () { RegionID = 0, RegionName = "" }, false);
|
};
|
if (showDialog) {
|
var back = new Button () {
|
Height = Application.GetRealHeight (90),
|
Width = Application.GetRealWidth (85),
|
UnSelectedImagePath = "Item/Back.png",
|
SelectedImagePath = "Item/BackSelected.png",
|
};
|
topView.AddChidren (back);
|
back.MouseUpEventHandler += (sender, e) => {
|
(Parent as PageLayout).PageIndex -= 1;
|
};
|
}
|
#endregion
|
|
var BodyView = new FrameLayout () {
|
Width = LayoutParams.MatchParent,
|
Height = Application.GetRealHeight (1136 - 126),
|
Y = topView.Bottom,
|
BackgroundColor = SkinStyle.Current.ViewColor,
|
};
|
AddChidren (BodyView);
|
|
VerticalScrolViewLayout VerticalScrolViewMiddle = new VerticalScrolViewLayout ();
|
BodyView.AddChidren (VerticalScrolViewMiddle);
|
|
try {
|
foreach (var tempHome in UserConfig.Instance.HomeLists) {
|
AddResidenceListRow (tempHome, VerticalScrolViewMiddle);
|
}
|
} catch { }
|
|
if (UserConfig.Instance.GatewayList !=null && UserConfig.Instance.GatewayList.Count == 0) {
|
if (showDialog) {
|
GuideAddHomeDialog (UserConfig.Instance.HomeLists [0], true);
|
UserConfig.Instance.CurrentRegion = UserConfig.Instance.HomeLists [0];
|
}
|
}
|
}
|
|
/// <summary>
|
/// 加载界面
|
/// </summary>
|
/// <param name="home">Home.</param>
|
/// <param name="VerticalScrolViewMiddle">Vertical scrol view middle.</param>
|
void AddResidenceListRow (RegionInfoRes home, VerticalScrolViewLayout VerticalScrolViewMiddle )
|
{
|
var rowView = new RowLayout () {
|
Height = Application.GetRealHeight (110),
|
};
|
VerticalScrolViewMiddle.AddChidren (rowView);
|
|
Button btnRowLine = new Button () {
|
Y = Application.GetRealHeight (107),
|
Height = Application.GetRealHeight (3),
|
BackgroundColor = SkinStyle.Current.Black50Transparent
|
};
|
rowView.AddChidren (btnRowLine);
|
|
var btnPoint = new Button () {
|
Width = Application.GetRealWidth (10),
|
Height = Application.GetRealHeight (10),
|
X = Application.GetRealWidth (50),
|
Gravity = Gravity.CenterVertical,
|
UnSelectedImagePath = "Item/Point.png",
|
SelectedImagePath = "Item/Point.png",
|
Visible = home.RegionID != UserConfig.Instance.CurrentRegion.RegionID
|
};
|
rowView.AddChidren (btnPoint);
|
|
var btnName = new Button () {
|
Width = Application.GetRealWidth (390),
|
Text = home.RegionName,
|
TextAlignment = TextAlignment.CenterLeft,
|
X = Application.GetRealWidth (90),
|
TextColor = SkinStyle.Current.TextColor1,
|
};
|
rowView.AddChidren (btnName);
|
|
var goNextButton = new Button () {
|
X = Application.GetRealWidth (500),
|
Width = Application.GetRealWidth (120),
|
};
|
rowView.AddChidren (goNextButton);
|
|
|
Button rightButton1 = new Button () {
|
X = Application.GetRealWidth (550),
|
Width = Application.GetRealWidth (28),
|
Height = Application.GetRealHeight (40),
|
Gravity = Gravity.CenterVertical,
|
UnSelectedImagePath = "Item/Right.png",
|
SelectedImagePath = "Item/RightSelected.png",
|
};
|
rowView.AddChidren (rightButton1);
|
EventHandler<MouseEventArgs> eHandler = (sender, e) => {
|
if (home.RegionID == UserConfig.Instance.CurrentRegion.RegionID) {
|
//UserConfig.Instance.GatewayMAC = gatewayMAC;
|
var addGatewayDialog = new GuideAddGateway ();
|
(Parent as PageLayout).AddChidren (addGatewayDialog);
|
addGatewayDialog.ShowPage (home);
|
(Parent as PageLayout).PageIndex = (Parent as PageLayout).ChildrenCount - 1;
|
} else {
|
ChangeRegion (home);
|
}
|
};
|
rightButton1.MouseUpEventHandler += eHandler;
|
goNextButton.MouseUpEventHandler += eHandler;
|
btnName.MouseUpEventHandler += (sender,e)=> {
|
if (home.RegionID == UserConfig.Instance.CurrentRegion.RegionID) {
|
GuideAddHomeDialog (home, false,true, btnName);
|
} else {
|
ChangeRegion (home);
|
}
|
};
|
|
if (home.RegionID == UserConfig.Instance.CurrentRegion.RegionID) {
|
Button btnCheck = new Button () {
|
X = Application.GetRealWidth (20),
|
Y = Application.GetRealHeight (25),
|
Width = Application.GetRealWidth (72),
|
Height = Application.GetRealHeight (61),
|
UnSelectedImagePath = "Skin/Check.png",
|
};
|
rowView.AddChidren (btnCheck);
|
}
|
if (UserConfig.Instance.CurrentRegion.RegionID != home.RegionID && MainPage.LoginUser.AccountType != 1) {
|
Button btnDel = new Button () {
|
TextID = R.MyInternationalizationString.Del,
|
BackgroundColor = SkinStyle.Current.DelColor,
|
};
|
rowView.AddRightView (btnDel);
|
btnDel.MouseUpEventHandler += (sd, ee) => {
|
Dialog dialog = new Dialog ();
|
|
FrameLayout dialogBody = new FrameLayout () {
|
Width = Application.GetRealWidth (500),
|
Height = Application.GetRealHeight (400),
|
Radius = 5,
|
BorderColor = SkinStyle.Current.Transparent,
|
BorderWidth = 0,
|
BackgroundColor = SkinStyle.Current.DialogColor,
|
Gravity = Gravity.Center,
|
};
|
dialog.AddChidren (dialogBody);
|
|
Button btnTitle = new Button () {
|
Height = Application.GetRealHeight (80),
|
BackgroundColor = SkinStyle.Current.DialogTitle,
|
TextAlignment = TextAlignment.Center,
|
TextID = R.MyInternationalizationString.DeleteTheArea,
|
TextColor = SkinStyle.Current.DialogTextColor,
|
};
|
dialogBody.AddChidren (btnTitle);
|
TextView btnTip = new TextView () {
|
X = Application.GetRealWidth (50),
|
Y = btnTitle.Bottom,
|
Width = Application.GetRealWidth (400),
|
Height = Application.GetRealHeight (120),
|
TextColor = SkinStyle.Current.TextColor,
|
TextID = R.MyInternationalizationString.TipDelArea,
|
Enable = false,
|
TextSize = 14,
|
IsMoreLines = true,
|
};
|
dialogBody.AddChidren (btnTip);
|
btnTip.IsMoreLines = true;
|
EditText etPw = new EditText () {
|
X = Application.GetRealWidth (50),
|
Y = btnTip.Bottom + Application.GetRealHeight (10),
|
Width = Application.GetRealWidth (400),
|
Height = Application.GetRealHeight (70),
|
TextColor = SkinStyle.Current.TextColor,
|
Radius = 5,
|
BorderColor = SkinStyle.Current.BorderColor,
|
BorderWidth = 1,
|
SecureTextEntry = true,
|
};
|
dialogBody.AddChidren (etPw);
|
etPw.EditorEnterAction += (sender) => {
|
Application.HideSoftInput ();
|
};
|
|
FrameLayout bottomView = new FrameLayout () {
|
Y = Application.GetRealHeight (400 - 88),
|
Height = Application.GetRealHeight (90),
|
BackgroundColor = SkinStyle.Current.Black50Transparent,
|
};
|
dialogBody.AddChidren (bottomView);
|
|
Button btnClose = new Button () {
|
Width = Application.GetRealWidth (250),
|
TextAlignment = TextAlignment.Center,
|
TextColor = SkinStyle.Current.DialogTextColor,
|
TextID = R.MyInternationalizationString.Close,
|
BackgroundColor = SkinStyle.Current.DialogTitle,
|
};
|
bottomView.AddChidren (btnClose);
|
btnClose.MouseUpEventHandler += (asdf, eell) => {
|
dialog.Close ();
|
};
|
Button btnConfirm = new Button () {
|
X = Application.GetRealWidth (252),
|
Width = Application.GetRealWidth (250),
|
TextColor = SkinStyle.Current.DialogTextColor,
|
TextID = R.MyInternationalizationString.confirm,
|
BackgroundColor = SkinStyle.Current.DialogTitle,
|
TextAlignment = TextAlignment.Center,
|
};
|
bottomView.AddChidren (btnConfirm);
|
btnConfirm.MouseUpEventHandler += (dou, ni) => {
|
string password = etPw.Text.Trim ();
|
if (string.IsNullOrEmpty (password)) {
|
return;
|
}
|
System.Threading.Tasks.Task.Run (() => {
|
try {
|
Application.RunOnMainThread (() => {
|
MainPage.Loading.Start ("Please wait...");
|
});
|
var requestObj = new LoginObj () { Account = MainPage.LoginUser.AccountString, Password = password };
|
var requestJson = Newtonsoft.Json.JsonConvert.SerializeObject (requestObj);
|
var revertObj = MainPage.RequestHttps ("Login", requestJson, false, false);
|
if (revertObj.StateCode == "SUCCESS") {
|
var requestObj2 = new DeleteHomeObj () { Id = home.RegionID };
|
var requestJson2 = Newtonsoft.Json.JsonConvert.SerializeObject (requestObj2);
|
var revertObj2 = MainPage.RequestHttps ("DeleteHome", requestJson2);
|
if (revertObj2.StateCode == "SUCCESS") {
|
Application.RunOnMainThread (() => {
|
ShowHomeList ();
|
});
|
}
|
} else {
|
Application.RunOnMainThread (() => {
|
new Alert ("", "Password error, deletion failed.", "Close").Show ();
|
});
|
}
|
} catch {
|
MainPage.FailureToServer ();
|
} finally {
|
Application.RunOnMainThread (() => {
|
MainPage.Loading.Hide ();
|
dialog.Close ();
|
});
|
}
|
});
|
};
|
|
dialog.Show ();
|
};
|
}
|
|
}
|
|
/// <summary>
|
/// 更换本地区域
|
/// </summary>
|
/// <param name="home">Home.</param>
|
/// <param name="gatewayMAC">Gateway mac.</param>
|
void ChangeRegion (RegionInfoRes home, bool goHomePage = true)
|
{
|
MainPage.Loading.Start ("Please wait...");
|
System.Threading.Tasks.Task.Run (() => {
|
try {
|
//if (home.RegionID != UserConfig.Instance.CurrentRegion.RegionID) {
|
var backuplist = IO.FileUtils.ReadFiles ();
|
int index = 0;
|
if (string.IsNullOrEmpty (UserConfig.Instance.CurrentRegion.RegionName)) {
|
UserConfig.Instance.CurrentRegion = UserConfig.Instance.HomeLists [0];
|
}
|
string oldRegionRootPath = IO.FileUtils.CreateRegionBackup (UserConfig.Instance.CurrentRegion.RegionName);
|
IO.FileUtils.DeleteRegionFiles (oldRegionRootPath);
|
foreach (var fileName in backuplist) {
|
System.IO.FileInfo fileInfo = new System.IO.FileInfo (IO.FileUtils.RootPath + fileName);
|
if (fileInfo.Exists) {
|
fileInfo.MoveTo (oldRegionRootPath + fileName);
|
Console.WriteLine ("move file : " + fileName);
|
}
|
index++;
|
Application.RunOnMainThread (() => {
|
int pro = (int)(index * 1.0 / backuplist.Count * 50);
|
MainPage.Loading.Text = pro.ToString () + "%";
|
});
|
}
|
IO.FileUtils.DeleteAllFile ();
|
string newRegionRootPath = IO.FileUtils.CreateRegionBackup (home.RegionName);
|
IO.FileUtils.RestoreRegionFiles (newRegionRootPath);
|
UserConfig.Instance.CurrentRegion = home;
|
UserConfig.Instance.SaveUserConfig ();
|
Room.InitAllRoom ();
|
Application.RunOnMainThread (() => {
|
ShowHomeList ();
|
if (goHomePage) {
|
UserConfig.Instance.RefreshUserConfig ();
|
new Alert ("", Language.StringByID (R.MyInternationalizationString.SwitchRegionSuccessfully),
|
Language.StringByID (R.MyInternationalizationString.Close)).Show ();
|
//this.RemoveFromParent ();
|
CommonPage.IsRemote = false;
|
EquipmentPublicClass.CheckLinkRemote (2);
|
}
|
});
|
MainPage.LoginUser.SaveUserInfo ();
|
//}
|
} catch (Exception ex) {
|
Application.RunOnMainThread (() => {
|
new Alert ("", Language.StringByID (R.MyInternationalizationString.CheckInternet),
|
Language.StringByID (R.MyInternationalizationString.Close)).Show ();
|
});
|
Console.WriteLine (ex.Message);
|
} finally {
|
Application.RunOnMainThread (() => {
|
MainPage.Loading.Hide ();
|
});
|
}
|
});
|
}
|
|
/// <summary>
|
/// 引导添加住宅
|
/// </summary>
|
void GuideAddHomeDialog (RegionInfoRes home, bool guide, bool isChangeName = false, Button button = null)
|
{
|
Dialog dialog = new Dialog ();
|
|
var dialogView = new FrameLayout ();
|
dialogView.MouseUpEventHandler += (sn, dd) => {
|
if (guide)
|
return;
|
Application.HideSoftInput ();
|
};
|
dialog.AddChidren (dialogView);
|
var bodyView = new FrameLayout () {
|
Gravity = Gravity.Center,
|
Width = Application.GetRealWidth (500),
|
Height = Application.GetRealHeight (400),
|
Radius = 5,
|
BorderColor = SkinStyle.Current.Transparent,
|
BorderWidth = 0,
|
BackgroundColor = SkinStyle.Current.DialogColor,
|
};
|
dialogView.AddChidren (bodyView);
|
|
var btnTitle = new Button () {
|
Height = Application.GetRealHeight (80),
|
TextAlignment = TextAlignment.Center,
|
TextID = R.MyInternationalizationString.HonseManagement,
|
TextColor = SkinStyle.Current.DialogTextColor,
|
BackgroundColor = SkinStyle.Current.DialogTitle,
|
};
|
bodyView.AddChidren (btnTitle);
|
|
var btnZoneName = new Button () {
|
X = Application.GetRealWidth (50),
|
Y = btnTitle.Bottom + Application.GetRealHeight (10),
|
Width = Application.GetRealWidth (400),
|
Height = Application.GetRealHeight (80),
|
TextAlignment = TextAlignment.CenterLeft,
|
TextColor = SkinStyle.Current.TextColor,
|
TextID = R.MyInternationalizationString.ResidentialName
|
};
|
bodyView.AddChidren (btnZoneName);
|
|
var etZoneName = new EditText () {
|
X = Application.GetRealWidth (50),
|
Y = btnZoneName.Bottom + Application.GetRealHeight (10),
|
Width = Application.GetRealWidth (400),
|
Height = Application.GetRealHeight (80),
|
TextColor = SkinStyle.Current.TextColor,
|
TextAlignment = TextAlignment.Center,
|
Radius = 5,
|
BorderColor = SkinStyle.Current.BorderColor,
|
BorderWidth = 2,
|
Text = home.RegionName,
|
};
|
bodyView.AddChidren (etZoneName);
|
|
etZoneName.EditorEnterAction += (obj) => {
|
Application.HideSoftInput ();
|
};
|
if (MainPage.LoginUser.AccountType == 1) {
|
etZoneName.Enable = false;
|
etZoneName.BorderWidth = 0;
|
}
|
|
var BottomView = new FrameLayout () {
|
Y = Application.GetRealHeight (400 - 88),
|
Height = Application.GetRealHeight (90),
|
BackgroundColor = SkinStyle.Current.Black50Transparent,
|
};
|
bodyView.AddChidren (BottomView);
|
|
var btnOption = new Button () {
|
TextID = R.MyInternationalizationString.OK,
|
TextColor = SkinStyle.Current.DialogTextColor,
|
BackgroundColor = SkinStyle.Current.DialogTitle,
|
TextAlignment = TextAlignment.Center,
|
};
|
btnOption.MouseUpEventHandler += (sdf, fds) => {
|
dialog.Close ();
|
if (etZoneName.Text.Trim () == "") {
|
new Alert ("", Language.StringByID (R.MyInternationalizationString.PleaseEnterZoneName), Language.StringByID (R.MyInternationalizationString.Close)).Show ();
|
return;
|
}
|
if (isChangeName) {
|
home.RegionName = button.Text = etZoneName.Text;
|
var requestObj2 = new EditHomeObj () { Id = home.RegionID, Name = home.RegionName };
|
var requestJson2 = Newtonsoft.Json.JsonConvert.SerializeObject (requestObj2);
|
var revertObj2 = MainPage.RequestHttps ("EditHome", requestJson2);
|
IO.FileUtils.ReNameFoler (UserConfig.Instance.CurrentRegion.RegionName, home.RegionName);
|
return;
|
}
|
ChangeRegion (home, false);
|
var addGatewayDialog = new GuideAddGateway ();
|
if (guide) {
|
EditResidence (home, etZoneName.Text.Trim ());
|
UserMiddle.guidePageView.AddChidren (addGatewayDialog);
|
addGatewayDialog.ShowPage (home);//guidePageView
|
UserMiddle.guidePageView.PageIndex = 1;
|
} else {
|
EditResidence (home, etZoneName.Text.Trim ());
|
UserMiddle.SettingPageView.AddChidren (addGatewayDialog);
|
addGatewayDialog.ShowPage (home);
|
UserMiddle.SettingPageView.PageIndex = 2;
|
}
|
};
|
|
if(!guide)
|
{
|
var btnClose = new Button () {
|
Width = Application.GetRealWidth(250),
|
TextID = R.MyInternationalizationString.cancel,
|
TextColor = SkinStyle.Current.DialogTextColor,
|
BackgroundColor = SkinStyle.Current.DialogTitle,
|
TextAlignment = TextAlignment.Center,
|
};
|
BottomView.AddChidren (btnClose);
|
btnClose.MouseUpEventHandler += (bb, cc) => {
|
dialog.Close ();
|
};
|
|
btnOption.X = btnClose.Right + 1;
|
btnOption.Width = Application.GetRealWidth (250);
|
|
}
|
BottomView.AddChidren (btnOption);
|
|
dialog.Show ();
|
|
}
|
|
/// <summary>
|
/// 添加住宅,完成之后进入搜索网关界面
|
/// </summary>
|
/// <param name="home">Home.</param>
|
/// <param name="residenceName">Et zone name string.</param>
|
bool EditResidence (RegionInfoRes home,string residenceName)
|
{
|
if (home.RegionName != residenceName) {
|
home.RegionName = residenceName;
|
if (home.RegionID == 0) {
|
var requestObj21 = new AddHomeObj () { Name = residenceName };
|
var requestJson21 = Newtonsoft.Json.JsonConvert.SerializeObject (requestObj21);
|
var revertObj21 = MainPage.RequestHttps ("AddHome", requestJson21);
|
if ( revertObj21.StateCode != "SUCCESS") {
|
return false;
|
}
|
} else {
|
var requestObj2 = new EditHomeObj () { Id = home.RegionID, Name = home.RegionName };
|
var requestJson2 = Newtonsoft.Json.JsonConvert.SerializeObject (requestObj2);
|
var revertObj2 = MainPage.RequestHttps ("EditHome", requestJson2);
|
IO.FileUtils.ReNameFoler (UserConfig.Instance.CurrentRegion.RegionName, home.RegionName);
|
if (revertObj2.StateCode != "SUCCESS") {
|
return false;
|
}
|
}
|
UserConfig.Instance.CurrentRegion = home;
|
UserConfig.Instance.SaveUserConfig ();
|
}
|
if (Room.Lists.FindAll ((obj) => obj.Name == "Living Room" || obj.Name == "Bedroom").Count == 0) {
|
Room room = new Room ();
|
string newRoomFilePath = typeof (Room).Name + "_Living Room";
|
room.Name = "Living Room";
|
room.BackGroundImage = "Room/r1.png";
|
room.Add (newRoomFilePath);
|
room.Save (newRoomFilePath);
|
Room.Lists.Add (room);
|
|
room = new Room ();
|
newRoomFilePath = typeof (Room).Name + "_Bedroom";
|
room.Name = "Bedroom";
|
room.BackGroundImage = "Room/r5.png";
|
room.Add (newRoomFilePath);
|
room.Save (newRoomFilePath);
|
Room.Lists.Add (room);
|
}
|
if (home.RegionName != residenceName) {
|
ShowHomeList ();
|
}
|
return true;
|
|
}
|
}
|
}
|