using System; using System.Collections.Generic; using System.IO; namespace Shared.SimpleControl.Pad { /// /// 弹出右边的菜单栏 /// public class UserListItem : Shared.Dialog { public UserListItem () { initSidebar (); } /// /// 用户界面侧边栏 /// void initSidebar () { FrameLayout main = new FrameLayout () ; main.MouseUpEventHandler += (sender, e) => { Close (); }; AddChidren (main); FrameLayout sidebarFrameLayout = new FrameLayout () { Width = Application.GetRealWidth (580), X = Application.GetRealWidth (Application.DesignWidth - 580), Y = Application.GetRealHeight (150), Height = Application.GetRealHeight (Application.DesignHeight - 150 - 120), }; main.AddChidren (sidebarFrameLayout); var sidebarView = new VerticalScrolViewLayout () { BackgroundColor = 0xFF333333 }; sidebarFrameLayout.AddChidren (sidebarView); #region ---系统--- Button btnSystem = new Button () { Width = LayoutParams.MatchParent, Height = Application.GetRealHeight (150), UnSelectedImagePath = "PadAdding/SidebarSystem.png", TextAlignment = TextAlignment.Center, Text = Language.StringByID (R.MyInternationalizationString.System), TextSize = 16 }; sidebarView.AddChidren (btnSystem); btnSystem.MouseUpEventHandler += (sender, e) => { Close (); GoSystem (); }; Button btnLineData = new Button () { Width = LayoutParams.MatchParent, Height = 1, BackgroundColor = 0xFFDBDDDF, }; sidebarView.AddChidren (btnLineData); #endregion #region ---设备模式--- Button btnEquipmentModel = new Button () { Width = LayoutParams.MatchParent, Height = Application.GetRealHeight (150), UnSelectedImagePath = "PadAdding/SidebarDevice.png", TextAlignment = TextAlignment.Center, Text = Language.StringByID (R.MyInternationalizationString.Device), TextSize = 16 //Padding = new Padding (0, 45, 0, 0) }; //sidebarView.AddChidren (btnEquipmentModel); btnEquipmentModel.MouseUpEventHandler += (sender, e) => { Close (); UserMiddle.DeviceMode (); }; Button btnLine = new Button () { Width = LayoutParams.MatchParent, Height = 1, BackgroundColor = 0xFFDBDDDF, }; //sidebarView.AddChidren (btnLine); #endregion #region ---房间模式--- Button btnRoomModel = new Button () { Width = LayoutParams.MatchParent, Height = Application.GetRealHeight (150), TextAlignment = TextAlignment.Center, UnSelectedImagePath = "PadAdding/SidebarRoom.png", //Padding = new Padding (0, 45, 0, 0), Text = Language.StringByID (R.MyInternationalizationString.Room), TextSize = 16 }; //sidebarView.AddChidren (btnRoomModel); btnRoomModel.MouseUpEventHandler += (sender, e) => { Close (); }; Button btnLine3 = new Button () { Width = LayoutParams.MatchParent, Height = 1, BackgroundColor = 0xFFDBDDDF, }; //sidebarView.AddChidren (btnLine3); #endregion #region ---账号登陆--- Button account = new Button () { Width = LayoutParams.MatchParent, Height = Application.GetRealHeight (150), TextAlignment = TextAlignment.Center, UnSelectedImagePath = "PadAdding/Register_Account.png", Text = Language.StringByID (R.MyInternationalizationString.Account), TextSize = 16 }; sidebarView.AddChidren (account); account.MouseUpEventHandler += (sender, e) => { if (MainPage.LoginUser == null || !MainPage.LoginUser.IsLogin) { new Register ().Show (); } else { new AccountManagement ().Show (); } Close (); }; Button btnLine5 = new Button () { Width = LayoutParams.MatchParent, Height = 1, BackgroundColor = 0xFFDBDDDF, }; sidebarView.AddChidren (btnLine5); #endregion #region ---数据云备份--- Button bakeup = new Button () { Width = LayoutParams.MatchParent, Height = Application.GetRealHeight (150), TextAlignment = TextAlignment.Center, UnSelectedImagePath = "PadAdding/Backup_.png", Text = Language.StringByID (R.MyInternationalizationString.Backup), TextSize = 16 }; sidebarView.AddChidren (bakeup); bakeup.MouseUpEventHandler += (sender, e) => { if (MainPage.LoginUser == null || !MainPage.LoginUser.IsLogin) { new Register ().Show (); } else { new Databackup ().Show (); } }; Button btnLineSystem = new Button () { Width = LayoutParams.MatchParent, Height = 1, BackgroundColor = 0xFFDBDDDF, }; sidebarView.AddChidren (btnLineSystem); #endregion #region ---RemoteMsg--- Button btnRemoteMsg = new Button () { Width = LayoutParams.MatchParent, Height = Application.GetRealHeight (150), TextAlignment = TextAlignment.Center, UnSelectedImagePath = "PadAdding/RemoteIcon.png", TextID = R.MyInternationalizationString.MessageAlert, TextSize = 16 }; sidebarView.AddChidren (btnRemoteMsg); btnRemoteMsg.MouseUpEventHandler += (sender, e) => { WarningList.ShowWarningListPage (); }; Button btnRemoteMsgLine = new Button () { Width = LayoutParams.MatchParent, Height = 1, BackgroundColor = 0xFFDBDDDF }; sidebarView.AddChidren (btnRemoteMsgLine); #endregion #region ---数据共享--- Button btnData = new Button () { Width = LayoutParams.MatchParent, Height = Application.GetRealHeight (150), UnSelectedImagePath = "PadAdding/SidebarData.png", TextID = R.MyInternationalizationString.DataReception, TextSize = 16 }; sidebarView.AddChidren (btnData); btnData.MouseUpEventHandler += (sender, e) => { Close (); GoData (); }; Button btnLineZone = new Button () { Width = LayoutParams.MatchParent, Height = 1, BackgroundColor = 0xFFDBDDDF, }; sidebarView.AddChidren (btnLineZone); #endregion #region ---区域--- Button btnZone = new Button () { Width = LayoutParams.MatchParent, Height = Application.GetRealHeight (150), UnSelectedImagePath = "PadAdding/SidebarZoneControl.png", TextAlignment = TextAlignment.Center, TextID = R.MyInternationalizationString.RegionalManagement , TextSize = 16 }; sidebarView.AddChidren (btnZone); btnZone.MouseUpEventHandler += (sender5, e5) => { Close (); GoZone (); }; #endregion Button btnVersion = new Button () { Y = Application.GetRealHeight (Application.DesignHeight - 120), Width = LayoutParams.MatchParent, Height = Application.GetRealHeight (120), TextID = R.MyInternationalizationString.Version, BackgroundColor = 0xFF333333, Enable = false }; btnVersion.Text += MainPage.CodeIDString; main.AddChidren (btnVersion); } void GoData () { Dialog dialog = new Dialog (); FrameLayout MianBody = new FrameLayout (); dialog.AddChidren (MianBody); FrameLayout bodyView = new FrameLayout () { Width = Application.GetRealWidth (600), Height = Application.GetRealHeight (500), Gravity = Gravity.CenterHorizontal, Y = Application.GetRealHeight (250), Radius = 5, BorderColor = SkinStyle.Current.Transparent, BorderWidth = 2, BackgroundColor = 0xFF333333 }; MianBody.AddChidren (bodyView); Button topButton = new Button () { Height = Application.GetRealHeight (120), BackgroundColor = SkinStyle.Current.MainColor, TextSize = 20, TextAlignment = TextAlignment.Center }; bodyView.AddChidren (topButton); Button btnIP = new Button () { Width = Application.GetRealWidth (400), Height = Application.GetRealHeight (100), X = Application.GetRealWidth (50), Y = topButton.Bottom, TextAlignment = TextAlignment.CenterLeft }; bodyView.AddChidren (btnIP); EditText etIP = new EditText () { Width = Application.GetRealWidth (500), Height = Application.GetRealHeight (80), X = Application.GetRealWidth (50), Y = btnIP.Bottom, TextAlignment = TextAlignment.Center, Radius = 5, BorderColor = 0xFF333333, BorderWidth = 2, }; bodyView.AddChidren (etIP); CommonPage.InitHttpListener (); topButton.TextID = R.MyInternationalizationString.DataReception; string ipAddressString = new Net.NetWiFi ().IpAddress == null ? "null" : new Net.NetWiFi ().IpAddress.ToString (); btnIP.TextID = R.MyInternationalizationString.IPAddresses; etIP.Text = ipAddressString; etIP.Enable = false; Button btnCloseSharing = new Button () { X = Application.GetRealWidth (50), Y = etIP.Bottom + Application.GetRealHeight (80), Width = Application.GetRealWidth (500), Height = Application.GetRealHeight (80), SelectedBackgroundColor = 0xFFDBDDDF, BackgroundColor = SkinStyle.Current.SelectedColor, TextSize = 16, Radius = 5, BorderColor = SkinStyle.Current.Transparent, BorderWidth = 2, TextID = R.MyInternationalizationString.CloseDataSharing, }; bodyView.AddChidren (btnCloseSharing); btnCloseSharing.MouseDownEventHandler += (sender2, e2) => { btnCloseSharing.IsSelected = true; }; btnCloseSharing.MouseUpEventHandler += (sender2, e2) => { btnCloseSharing.IsSelected = false; CommonPage.CloseHttpListener (); dialog.Close (); }; dialog.Show (); } /// /// 进入后台 /// void GoSystem () { SystemHomePage.FrameLayoutMain.Visible = true; UserHomePage.FrameLayoutMain.Visible = false; SystemHomePage.Init (); } /// /// 增加区域 /// void AddZone (VerticalScrolViewLayout scrolView, string [] dirs, Dialog dialog) { scrolView.RemoveAll (); foreach (var d in dirs) { RowLayout regionView = new RowLayout () { Height = Application.GetRealHeight (100), }; scrolView.AddChidren (regionView); string text = d.Substring (d.LastIndexOf ('/')).Replace ('/', ' '); Button btnRegion = new Button () { Text = text.Trim (), TextAlignment = TextAlignment.Center, TextColor = 0xFF000000 }; regionView.AddChidren (btnRegion); Button btnSwitch = new Button () { TextID = R.MyInternationalizationString.Change, BackgroundColor = 0xFF333333, }; regionView.AddRightView (btnSwitch); btnSwitch.MouseUpEventHandler += (sender, e) => { IO.FileUtils.DeleteAllFile (); string RootPath = System.IO.Path.Combine (Application.RootPath, "AppRegion") + @"/" + btnRegion.Text.Trim (); System.IO.DirectoryInfo TheFolder = new System.IO.DirectoryInfo (RootPath); foreach (FileInfo NextFile in TheFolder.GetFiles ()) { NextFile.CopyTo (Application.RootPath + NextFile.Name, true); Console.WriteLine (Application.RootPath + NextFile.Name); } dirs = Directory.GetDirectories (System.IO.Path.Combine (Application.RootPath, "AppRegion")); //addZone (scrolView, dirs, dialog); new Alert (Language.StringByID (R.MyInternationalizationString.Tip), Language.StringByID (R.MyInternationalizationString.SwitchSuccessfullyRestartTheApplication), Language.StringByID (R.MyInternationalizationString.Close)).Show (); dialog.Close (); UserHomePage.Init (); }; Button btnUpdate = new Button () { TextID = R.MyInternationalizationString.Update, BackgroundColor = SkinStyle.Current.SelectedColor, }; regionView.AddRightView (btnUpdate); btnUpdate.MouseUpEventHandler += (sender, e) => { Alert alert = new Alert (Language.StringByID (R.MyInternationalizationString.Tip), Language.StringByID (R.MyInternationalizationString.UpdateZone), Language.StringByID (R.MyInternationalizationString.Cancel), Language.StringByID (R.MyInternationalizationString.Confrim)); alert.Show (); alert.ResultEventHandler += (sender2, e2) => { if (e2) { string regionName = btnRegion.Text.Trim (); string RootPath = System.IO.Path.Combine (Application.RootPath, "AppRegion") + @"/" + regionName; System.IO.DirectoryInfo di = new System.IO.DirectoryInfo (RootPath); di.Delete (true); var fileList = IO.FileUtils.ReadFiles (); foreach (var file in fileList) { System.IO.FileInfo fileInfo = new System.IO.FileInfo (Application.RootPath + file); if (!Directory.Exists (System.IO.Path.Combine (Application.RootPath, "AppRegion") + @"/" + regionName)) { System.IO.DirectoryInfo dir2 = new System.IO.DirectoryInfo (System.IO.Path.Combine (Application.RootPath, "AppRegion")); dir2.CreateSubdirectory (regionName); } fileInfo.CopyTo (System.IO.Path.Combine (Application.RootPath, "AppRegion") + @"/" + regionName + @"/" + file); } dirs = Directory.GetDirectories (System.IO.Path.Combine (Application.RootPath, "AppRegion")); AddZone (scrolView, dirs, dialog); //dialog.Close (); } }; }; Button btnDel = new Button () { TextID = R.MyInternationalizationString.Del, BackgroundColor = SkinStyle.Current.DelColor, }; regionView.AddRightView (btnDel); btnDel.MouseUpEventHandler += (sender, e) => { Alert alert = new Alert (Language.StringByID (R.MyInternationalizationString.Tip), Language.StringByID (R.MyInternationalizationString.DelZone), Language.StringByID (R.MyInternationalizationString.Cancel), Language.StringByID (R.MyInternationalizationString.Confrim)); alert.Show (); alert.ResultEventHandler += (sender2, e2) => { if (e2) { string regionName = btnRegion.Text.Trim (); string RootPath = System.IO.Path.Combine (Application.RootPath, "AppRegion") + @"/" + regionName; System.IO.DirectoryInfo di = new System.IO.DirectoryInfo (RootPath); di.Delete (true); } dirs = Directory.GetDirectories (System.IO.Path.Combine (Application.RootPath, "AppRegion")); AddZone (scrolView, dirs, dialog); }; }; } } /// /// 显示区域列表 /// void GoZone () { System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo (Application.RootPath); if (!Directory.Exists (System.IO.Path.Combine (Application.RootPath, "AppRegion"))) { dir.CreateSubdirectory ("AppRegion"); } string [] dirs = Directory.GetDirectories (System.IO.Path.Combine (Application.RootPath, "AppRegion")); Dialog dialog = new Dialog (); FrameLayout MianBody = new FrameLayout (); MianBody.MouseUpEventHandler += (sender2, e2) => { dialog.Close (); }; dialog.AddChidren (MianBody); FrameLayout bodyView = new FrameLayout () { Width = Application.GetRealWidth (700), Height = Application.GetRealHeight (800), Gravity = Gravity.Center, Radius = 5, BorderWidth = 2, BorderColor = SkinStyle.Current.Transparent, BackgroundColor = 0xFF333333 }; MianBody.AddChidren (bodyView); bodyView.MouseUpEventHandler += (sender, e) => { Console.WriteLine ("xx"); }; Button btnTitle = new Button () { Height = Application.GetRealHeight (120), TextAlignment = TextAlignment.Center, BackgroundColor = SkinStyle.Current.MainColor, TextID = R.MyInternationalizationString.SwitchingRegion, TextSize = 20 }; bodyView.AddChidren (btnTitle); VerticalScrolViewLayout scrolView = new VerticalScrolViewLayout () { Y = btnTitle.Bottom, Height = Application.GetRealHeight (800-240), BackgroundColor = 0xFF333333, }; bodyView.AddChidren (scrolView); AddZone (scrolView, dirs, dialog); FrameLayout createRegionView = new FrameLayout () { Height = Application.GetRealHeight (120), Y = bodyView.Height - Application.GetRealHeight (120), BackgroundColor = 0xFF000000 }; bodyView.AddChidren (createRegionView); EditText etNewRegion = new EditText () { X = Application.GetRealWidth (20), Y = Application.GetRealHeight (10), Gravity = Gravity.CenterVertical, Width = Application.GetRealWidth (500), Height = Application.GetRealHeight (70), BackgroundColor = 0xFF333333, BorderColor = SkinStyle.Current.Transparent, PlaceholderText = Language.StringByID (R.MyInternationalizationString.PleaseEnterZoneName), PlaceholderTextColor = 0xFFDBDDDF, BorderWidth = 1, Radius = 5 }; createRegionView.AddChidren (etNewRegion); Button btnNewRegion = new Button () { X = etNewRegion.Right, Width = Application.GetRealWidth (150), TextAlignment = TextAlignment.Center, TextID = R.MyInternationalizationString.New, //BackgroundColor = SkinStyle.Current.TextColor2, }; createRegionView.AddChidren (btnNewRegion); btnNewRegion.MouseUpEventHandler += (sender, e) => { string newRegionName = etNewRegion.Text.Trim (); if (string.IsNullOrEmpty (newRegionName)) { new Alert (Language.StringByID (R.MyInternationalizationString.Tip), Language.StringByID (R.MyInternationalizationString.PleaseEnterZoneName), Language.StringByID (R.MyInternationalizationString.Close)).Show (); return; } foreach (var ds in dirs) { var d = ds.Split ('/'); if (d [d.Length - 1] == newRegionName) { new Alert (Language.StringByID (R.MyInternationalizationString.Tip), Language.StringByID (R.MyInternationalizationString.HaveTheSame), Language.StringByID (R.MyInternationalizationString.Close)).Show (); return; } } var fileList = IO.FileUtils.ReadFiles (); foreach (var file in fileList) { System.IO.FileInfo fileInfo = new System.IO.FileInfo (Application.RootPath + file); if (!Directory.Exists (System.IO.Path.Combine (Application.RootPath, "AppRegion") + @"/" + newRegionName)) { System.IO.DirectoryInfo dir2 = new System.IO.DirectoryInfo (System.IO.Path.Combine (Application.RootPath, "AppRegion")); dir2.CreateSubdirectory (newRegionName); } fileInfo.CopyTo (System.IO.Path.Combine (Application.RootPath, "AppRegion") + @"/" + newRegionName + @"/" + file); } dirs = Directory.GetDirectories (System.IO.Path.Combine (Application.RootPath, "AppRegion")); AddZone (scrolView, dirs, dialog); }; dialog.Show (); } } }