using System;
|
namespace Shared.SimpleControl.Phone
|
{
|
public class SystemRCU : FrameLayout
|
{
|
|
public override void RemoveFromParent ()
|
{
|
SystemMiddle.curGatewayMAC = "";
|
SystemMiddle.curGatewayIP = "";
|
base.RemoveFromParent ();
|
}
|
byte [] gatewayInfo;
|
void UpdateBaseInfo (RCU gateway)
|
{
|
System.Threading.Tasks.Task.Run (() => {
|
Application.RunOnMainThread (() => {
|
MainPage.Loading.Start ("Sending...");
|
});
|
if (gatewayInfo == null) {
|
CommonPage.RandomHigh = (byte)new Random ().Next (255);
|
CommonPage.RandomLow = (byte)new Random ().Next (255);
|
gatewayInfo = Control.ControlBytesSendHasReturn (Command.ReadGateway, gateway.SubnetID, gateway.DeviceID, new byte [] { CommonPage.RandomHigh, CommonPage.RandomLow });
|
}
|
if (gatewayInfo == null) {
|
Application.RunOnMainThread (() => {
|
MainPage.Loading.Hide ();
|
new Alert (Language.StringByID (R.MyInternationalizationString.Tip),
|
Language.StringByID (R.MyInternationalizationString.TipEquipmentNotOnline),
|
Language.StringByID (R.MyInternationalizationString.Close)).Show ();
|
});
|
return;
|
}
|
byte [] bytes = new byte [gatewayInfo.Length - 2];
|
Array.Copy (gatewayInfo, 2, bytes, 0, gatewayInfo.Length - 2);
|
//Remark需要解码
|
byte [] ddd = new byte [20];
|
byte [] ddd2 = CommonPage.MyEncodingGB2312.GetBytes (gateway.Name);
|
Array.Copy (ddd2, 0, ddd, 0, 20 < ddd2.Length ? 20 : ddd2.Length);
|
Array.Copy (ddd, 0, bytes, 11, 20 < ddd.Length ? 20 : ddd.Length);
|
string [] ipAddress = gateway.IPAddress.Split ('.');
|
for (int i = 0; i < ipAddress.Length; i++)
|
bytes [i + 31] = byte.Parse (ipAddress [i]);
|
string [] r = gateway.RouteIPAddress.Split ('.');
|
for (int i = 0; i < r.Length; i++)
|
bytes [i + 35] = byte.Parse (r [i]);
|
string [] subnetMask = gateway.SubnetMask.Split ('.');
|
for (int i = 0; i < subnetMask.Length; i++)
|
bytes [i + 45] = byte.Parse (subnetMask [i]);
|
bytes [49] = gateway.DHCP == true ? (byte)1 : (byte)0;
|
var reBytes = Control.ControlBytesSendHasReturn (Command.SetGateway, gateway.SubnetID, gateway.DeviceID, bytes);
|
if (reBytes == null) {
|
Application.RunOnMainThread (() => {
|
MainPage.Loading.Hide ();
|
new Alert (Language.StringByID (R.MyInternationalizationString.Tip),
|
Language.StringByID (R.MyInternationalizationString.TipEquipmentNotOnline),
|
Language.StringByID (R.MyInternationalizationString.Close)).Show ();
|
});
|
} else {
|
Application.RunOnMainThread (() => {
|
IO.FileUtils.SaveEquipmentMessage (gateway);
|
MainPage.Loading.Hide ();
|
});
|
}
|
});
|
}
|
|
public void ShowRCU (RCU gatewayDevice)
|
{
|
RemoveAll ();
|
MainPage.Loading.Start (Language.StringByID(R.MyInternationalizationString.load));
|
|
CommonPage.FindGatewayChilrenIPAddress = gatewayDevice.IPAddress;
|
CommonPage.RandomHigh = (byte)new Random ().Next (255);
|
CommonPage.RandomLow = (byte)new Random ().Next (255);
|
System.Threading.Tasks.Task.Run (() => {
|
gatewayInfo = Control.ControlBytesSendHasReturn (Command.ReadGateway, gatewayDevice.SubnetID, gatewayDevice.DeviceID, new byte [] { CommonPage.RandomHigh, CommonPage.RandomLow });
|
Application.RunOnMainThread (() => {
|
MainPage.Loading.Hide ();
|
if (gatewayInfo == null) {
|
new Alert (Language.StringByID (R.MyInternationalizationString.Tip),
|
Language.StringByID (R.MyInternationalizationString.TipEquipmentNotOnline),
|
Language.StringByID (R.MyInternationalizationString.Close)).Show ();
|
return;
|
} else {
|
var one = IO.FileUtils.ReadEquipmentMessage (gatewayDevice);
|
gatewayDevice = Newtonsoft.Json.JsonConvert.DeserializeObject<RCU> (one);
|
SystemMiddle.curGatewayMAC = gatewayDevice.MAC;
|
SystemMiddle.curGatewayIP = gatewayDevice.IPAddress;
|
VerticalScrolViewLayout sView = new VerticalScrolViewLayout () {
|
Height = Application.GetRealHeight (844),
|
};
|
AddChidren (sView);
|
#region title
|
RowLayout frameLayout = new RowLayout () {
|
Height = Application.GetRealHeight (100),
|
Width = LayoutParams.MatchParent,
|
BackgroundColor = SkinStyle.Current.MainColor
|
};
|
sView.AddChidren (frameLayout);
|
|
Button backButton = new Button () {
|
Height = Application.GetRealHeight (90),
|
Width = Application.GetRealWidth (85),
|
UnSelectedImagePath = "Item/Back.png",
|
SelectedImagePath = "Item/BackSelected.png",
|
Gravity = Gravity.CenterVertical,
|
};
|
backButton.MouseUpEventHandler += (sender, e) => {
|
(Parent as PageLayout).PageIndex -= 1;
|
SystemMiddle.curGatewayMAC = gatewayDevice.MAC;
|
new SystemMiddle ().ShowGateWayView ();
|
};
|
frameLayout.AddChidren (backButton);
|
string strOnePortWirelessFRRemark = gatewayDevice.Name.ToString ();
|
EditText textButton = new EditText () {
|
X = Application.GetRealWidth (11) + backButton.Right,
|
Height = Application.GetRealHeight (50),
|
Width = Application.GetRealWidth (370),
|
Text = strOnePortWirelessFRRemark,
|
Gravity = Gravity.CenterVertical,
|
Enable = false,
|
BackgroundColor = SkinStyle.Current.Transparent,
|
SelectedBackgroundColor = SkinStyle.Current.SysEditBox,
|
TextColor = SkinStyle.Current.TextColor1
|
};
|
frameLayout.AddChidren (textButton);
|
|
Button editor = new Button () {
|
X = Application.GetRealWidth (640 - 70 - 30),
|
Height = Application.GetRealHeight (90),
|
Width = Application.GetRealWidth (70),
|
UnSelectedImagePath = "Item/Editor.png",
|
SelectedImagePath = "Item/EditorSelected.png",
|
Gravity = Gravity.CenterVertical,
|
};
|
frameLayout.AddChidren (editor);
|
editor.MouseUpEventHandler += (sender, e) => {//---------------修改Remark----------------
|
if (editor.IsSelected == true) {
|
MainPage.Loading.Start ();
|
gatewayDevice.Name = textButton.Text.Trim ();
|
UpdateBaseInfo (gatewayDevice);
|
editor.IsSelected = false;
|
textButton.Enable = false;
|
textButton.IsSelected = false;
|
MainPage.Loading.Hide ();
|
} else {
|
textButton.Enable = textButton.IsSelected = editor.IsSelected = true;
|
}
|
};
|
|
Button gatewayInfoSwitch = new Button () {
|
Height = Application.GetRealHeight (90),
|
Width = Application.GetRealWidth (90),
|
UnSelectedImagePath = "Item/GatwayInfoHide.png",
|
SelectedImagePath = "Item/GatwayInfoShow.png",
|
Gravity = Gravity.CenterVertical,
|
X = editor.Right + Application.GetRealWidth (5)
|
};
|
frameLayout.AddChidren (gatewayInfoSwitch);
|
#endregion
|
|
#region GatewayID
|
RowLayout frameLayoutGatewayID = new RowLayout () {
|
Height = Application.GetRealHeight (98),
|
Width = LayoutParams.MatchParent,
|
BackgroundColor = SkinStyle.Current.MainColor
|
};
|
sView.AddChidren (frameLayoutGatewayID);
|
|
Button gatewayIDText = new Button () {
|
X = Application.GetRealWidth (15),
|
Height = Application.GetRealHeight (66),
|
Width = Application.GetRealWidth (66),
|
UnSelectedImagePath = "Item/OnePort.png",
|
SelectedImagePath = "Item/OnePortSelected.png",
|
Gravity = Gravity.CenterVertical,
|
};
|
frameLayoutGatewayID.AddChidren (gatewayIDText);
|
Button gatewayIDName = new Button () {
|
X = backButton.Right,
|
Height = Application.GetRealHeight (41),
|
Width = Application.GetRealWidth (150),
|
TextID = R.MyInternationalizationString.GatewayID,
|
Gravity = Gravity.CenterVertical,
|
TextAlignment = TextAlignment.CenterLeft,
|
TextColor = SkinStyle.Current.TextColor1
|
};
|
frameLayoutGatewayID.AddChidren (gatewayIDName);
|
EditText etGatewayID = new EditText () {
|
Height = Application.GetRealHeight (52),
|
Width = Application.GetRealWidth (62),
|
X = gatewayIDName.Right,
|
Gravity = Gravity.CenterVertical,
|
TextAlignment = TextAlignment.Center,
|
Text = gatewayDevice.SubnetID.ToString (),
|
SelectedBackgroundColor = SkinStyle.Current.SysEditBox,
|
BackgroundColor = SkinStyle.Current.Transparent,
|
Enable = false,
|
TextColor = SkinStyle.Current.TextColor1
|
};
|
frameLayoutGatewayID.AddChidren (etGatewayID);
|
|
Button gatewayIDEdit = new Button () {
|
Height = Application.GetRealHeight (90),
|
Width = Application.GetRealWidth (70),
|
UnSelectedImagePath = "Item/Editor.png",
|
SelectedImagePath = "Item/EditorSelected.png",
|
Gravity = Gravity.CenterVertical,
|
};
|
gatewayIDEdit.X = frameLayout.Width - gatewayIDEdit.Width - Application.GetRealWidth (30);
|
#region 更改网关设备号
|
|
gatewayIDEdit.MouseUpEventHandler += (sender, e) => {
|
string [] macAddress = gatewayDevice.MAC.Split ('.');
|
if (etGatewayID.Enable) {
|
gatewayIDEdit.IsSelected = etGatewayID.Enable = etGatewayID.IsSelected = false;
|
byte [] Musics = new byte [10];
|
for (int i = 0; i < macAddress.Length; i++) {
|
Musics [i] = Convert.ToByte (macAddress [i], 16);
|
}
|
try {
|
Musics [8] = Convert.ToByte (Convert.ToInt32 (etGatewayID.Text.Trim ()));
|
if (Musics [8] < 0 || Musics [8] > 255) {
|
throw new Exception ();
|
}
|
} catch {
|
new Alert (Language.StringByID (R.MyInternationalizationString.Tip), Language.StringByID (R.MyInternationalizationString.TipPleaseEnterTheCorrectData), Language.StringByID (R.MyInternationalizationString.Close)).Show ();
|
return;
|
}
|
Control.ControlBytesSend (Command.SetDeviceSubnetID, gatewayDevice.SubnetID, gatewayDevice.DeviceID, Musics);
|
foreach (string ss in IO.FileUtils.ReadFiles ()) {
|
if (ss.Contains ("Equipment_")) {
|
if (ss.Contains ("_" + Musics [8].ToString () + "_") || ss.Contains ("_" + gatewayDevice.SubnetID.ToString () + "_")) {
|
IO.FileUtils.DeleteFile (ss);
|
}
|
}
|
}
|
gatewayDevice.SubnetID = Musics [8];
|
UpdateBaseInfo (gatewayDevice);
|
} else {
|
gatewayIDEdit.IsSelected = etGatewayID.IsSelected = etGatewayID.Enable = true;
|
}
|
};
|
#endregion
|
frameLayoutGatewayID.AddChidren (gatewayIDEdit);
|
#endregion
|
|
#region--------------NetWork--------------------------
|
RowLayout flNewWorkTop = new RowLayout () {
|
Height = Application.GetRealHeight (98),
|
Width = LayoutParams.MatchParent,
|
BackgroundColor = SkinStyle.Current.MainColor
|
};
|
sView.AddChidren (flNewWorkTop);
|
|
Button netParameterSeleted = new Button () {
|
X = Application.GetRealWidth (15),
|
Height = Application.GetRealHeight (66),
|
Width = Application.GetRealWidth (66),
|
UnSelectedImagePath = "Item/NetParameter.png",
|
SelectedImagePath = "Item/NetParameterSelected.png",
|
Gravity = Gravity.CenterVertical,
|
};
|
flNewWorkTop.AddChidren (netParameterSeleted);
|
Button textButton1 = new Button () {
|
X = backButton.Right,
|
Height = Application.GetRealHeight (41),
|
Width = Application.GetRealWidth (300),
|
TextID = R.MyInternationalizationString.NetwordParameters,
|
Gravity = Gravity.CenterVertical,
|
TextAlignment = TextAlignment.CenterLeft,
|
TextColor = SkinStyle.Current.TextColor1
|
};
|
flNewWorkTop.AddChidren (textButton1);
|
Button btnNetWorkHelp = new Button () {
|
Height = Application.GetMinRealAverage (100),
|
Width = Application.GetMinRealAverage (76),
|
UnSelectedImagePath = "Item/Help.png",
|
SelectedImagePath = "Item/HelpSelected.png",
|
Gravity = Gravity.CenterVertical,
|
};
|
btnNetWorkHelp.X = frameLayout.Width - btnNetWorkHelp.Width - Application.GetRealWidth (30);
|
btnNetWorkHelp.MouseUpEventHandler += (sender, e) => {
|
new Tip () { MaxWidth = 150, Text = Language.StringByID (R.MyInternationalizationString.HelpNetWork), Direction = AMPopTipDirection.Down, CloseTime = 4 }.Show ((View)sender);
|
};
|
flNewWorkTop.AddChidren (btnNetWorkHelp);
|
|
//---------------------------------------------------------------------------------------------------------------------------------
|
RowLayout frameLayout2 = new RowLayout () {
|
Height = Application.GetRealHeight (798),
|
Width = LayoutParams.MatchParent,
|
};
|
sView.AddChidren (frameLayout2);
|
Button btnDHCP = new Button () {
|
X = Application.GetRealWidth (100),
|
TextAlignment = TextAlignment.CenterLeft,
|
Height = Application.GetRealHeight (40),
|
Width = Application.GetRealWidth (360),
|
Text = "DHCP:",
|
Y = Application.GetRealHeight (20),
|
TextColor = SkinStyle.Current.TextColor1
|
};
|
frameLayout2.AddChidren (btnDHCP);
|
Button btnDHCPCheck = new Button () {
|
X = Application.GetRealWidth (640 - 176),
|
Height = Application.GetMinRealAverage (98),
|
Width = Application.GetMinRealAverage (76),
|
UnSelectedImagePath = "Item/Check.png",
|
SelectedImagePath = "Item/CheckSelected.png",
|
Y = Application.GetRealHeight (20),
|
IsSelected = gatewayDevice.DHCP,
|
TextColor = SkinStyle.Current.TextColor1
|
};
|
frameLayout2.AddChidren (btnDHCPCheck);
|
|
Button lblIPAddresses = new Button () {
|
X = Application.GetRealWidth (100),
|
TextAlignment = TextAlignment.CenterLeft,
|
Height = Application.GetRealHeight (55),
|
Width = Application.GetRealWidth (239),
|
TextID = R.MyInternationalizationString.IPAddresses,
|
Y = btnDHCP.Bottom + Application.GetRealHeight (2),
|
TextColor = SkinStyle.Current.TextColor1
|
};
|
frameLayout2.AddChidren (lblIPAddresses);
|
|
EditText etIPAddresses = new EditText () {
|
X = btnDHCP.X,
|
TextAlignment = TextAlignment.CenterLeft,
|
Height = Application.GetRealHeight (55),
|
Width = Application.GetRealWidth (440),
|
Text = " " + gatewayDevice.IPAddress,
|
BackgroundColor = SkinStyle.Current.SysEditBox,
|
Y = lblIPAddresses.Bottom + Application.GetRealHeight (2),
|
TextColor = SkinStyle.Current.TextColor1
|
};
|
frameLayout2.AddChidren (etIPAddresses);
|
CommonPage.FindGatewayChilrenIPAddress = gatewayDevice.IPAddress;
|
|
Button lblSubnetMask = new Button () {
|
X = btnDHCP.X,
|
TextAlignment = TextAlignment.CenterLeft,
|
Height = Application.GetRealHeight (55),
|
Width = Application.GetRealWidth (440),
|
TextID = R.MyInternationalizationString.SubnetMask,
|
Y = etIPAddresses.Bottom + Application.GetRealHeight (2),
|
TextColor = SkinStyle.Current.TextColor1
|
};
|
frameLayout2.AddChidren (lblSubnetMask);
|
|
EditText etSubnetMask = new EditText () {
|
X = btnDHCP.X,
|
TextAlignment = TextAlignment.CenterLeft,
|
Height = Application.GetRealHeight (55),
|
Width = Application.GetRealWidth (440),
|
Text = " " + gatewayDevice.SubnetMask,
|
BackgroundColor = SkinStyle.Current.SysEditBox,
|
Y = lblSubnetMask.Bottom + Application.GetRealHeight (2),
|
TextColor = SkinStyle.Current.TextColor1
|
};
|
frameLayout2.AddChidren (etSubnetMask);
|
|
Button lblRoutingIP = new Button () {
|
X = btnDHCP.X,
|
TextAlignment = TextAlignment.CenterLeft,
|
Height = Application.GetRealHeight (55),
|
Width = Application.GetRealWidth (440),
|
TextID = R.MyInternationalizationString.RoutingIP,
|
Y = etSubnetMask.Bottom + Application.GetRealHeight (2),
|
TextColor = SkinStyle.Current.TextColor1
|
};
|
frameLayout2.AddChidren (lblRoutingIP);
|
|
EditText etRoutingIP = new EditText () {
|
X = btnDHCP.X,
|
TextAlignment = TextAlignment.CenterLeft,
|
Height = Application.GetRealHeight (55),
|
Width = Application.GetRealWidth (440),
|
Text = " " + gatewayDevice.RouteIPAddress,
|
BackgroundColor = SkinStyle.Current.SysEditBox,
|
Y = lblRoutingIP.Bottom + Application.GetRealHeight (2),
|
TextColor = SkinStyle.Current.TextColor1
|
};
|
frameLayout2.AddChidren (etRoutingIP);
|
|
|
Button btnDHCPSave = new Button () {
|
X = (Application.CurrentWidth / 2 - 30),
|
Height = Application.GetRealHeight (55),
|
Width = Application.GetRealWidth (100),
|
BackgroundColor = SkinStyle.Current.ButtonColor,
|
SelectedBackgroundColor = SkinStyle.Current.SelectedColor,
|
BorderWidth = 1,
|
Radius = 5,
|
BorderColor = SkinStyle.Current.Transparent,
|
TextID = R.MyInternationalizationString.SAVE,
|
Y = etRoutingIP.Bottom + Application.GetRealHeight (10),
|
TextColor = SkinStyle.Current.TextColor1
|
};
|
frameLayout2.AddChidren (btnDHCPSave);
|
frameLayout2.Height = btnDHCPSave.Bottom + Application.GetRealHeight (20);
|
|
btnDHCPCheck.MouseUpEventHandler += (sender, e) => {
|
if (btnDHCPCheck.IsSelected) {
|
btnDHCPCheck.IsSelected = false;
|
etIPAddresses.Enable = etSubnetMask.Enable = etRoutingIP.Enable = true;
|
btnDHCPSave.Visible = true;
|
} else {
|
btnDHCPCheck.IsSelected = true;
|
etIPAddresses.Enable = etSubnetMask.Enable = etRoutingIP.Enable = false;
|
btnDHCPSave.Visible = false;
|
}
|
gatewayDevice.IPAddress = etIPAddresses.Text.Trim ();
|
gatewayDevice.SubnetMask = etSubnetMask.Text.Trim ();
|
gatewayDevice.RouteIPAddress = etRoutingIP.Text.Trim ();
|
gatewayDevice.DHCP = btnDHCPCheck.IsSelected;
|
try {
|
byte [] bytes = new byte [21];
|
bytes [20] = gatewayDevice.DHCP == true ? (byte)1 : (byte)0;
|
System.Net.IPAddress address;
|
if (System.Net.IPAddress.TryParse (gatewayDevice.IPAddress, out address)) {
|
string [] ipAddress = gatewayDevice.IPAddress.Split ('.');
|
for (int i = 0; i < ipAddress.Length; i++) {
|
bytes [i] = byte.Parse (ipAddress [i]);
|
}
|
} else {
|
throw new Exception ();
|
}
|
|
if (System.Net.IPAddress.TryParse (gatewayDevice.RouteIPAddress, out address)) {
|
string [] r = gatewayDevice.RouteIPAddress.Split ('.');
|
for (int i = 0; i < r.Length; i++) {
|
bytes [i + 4] = byte.Parse (r [i]);
|
}
|
} else {
|
throw new Exception ();
|
}
|
string [] ipMac = gatewayDevice.IPMAC.Split ('.');
|
//ipMAC前三位HDL 需要特殊处理
|
bytes [0 + 8] = (byte)(ipMac [0].ToCharArray () [0]);
|
bytes [1 + 8] = (byte)(ipMac [1].ToCharArray () [0]);
|
bytes [2 + 8] = (byte)(ipMac [2].ToCharArray () [0]);
|
bytes [3 + 8] = byte.Parse (ipMac [3]);
|
bytes [4 + 8] = byte.Parse (ipMac [4]);
|
bytes [5 + 8] = byte.Parse (ipMac [5]);
|
string [] subnetMask = gatewayDevice.SubnetMask.Split ('.');
|
bytes [14] = 0x17;
|
bytes [15] = 0x70;
|
for (int i = 0; i < subnetMask.Length; i++) {
|
bytes [i + 16] = byte.Parse (subnetMask [i]);
|
}
|
if (Control.ControlBytesSendHasReturn (Command.UpdateGatewayIp,gatewayDevice.SubnetID, gatewayDevice.DeviceID, bytes) != null) {
|
IO.FileUtils.SaveEquipmentMessage (gatewayDevice);
|
}
|
//UpdateBaseInfo (gatewayDevice);
|
} catch {
|
new Alert (Language.StringByID (R.MyInternationalizationString.Tip), Language.StringByID (R.MyInternationalizationString.TipPleaseEnterTheCorrectData), Language.StringByID (R.MyInternationalizationString.Confrim)).Show ();
|
}
|
};
|
btnDHCPSave.MouseUpEventHandler += (sender, e) => {
|
gatewayDevice.IPAddress = etIPAddresses.Text.Trim ();
|
gatewayDevice.SubnetMask = etSubnetMask.Text.Trim ();
|
gatewayDevice.RouteIPAddress = etRoutingIP.Text.Trim ();
|
gatewayDevice.DHCP = btnDHCPCheck.IsSelected;
|
try {
|
byte [] bytes = new byte [21];
|
bytes [20] = gatewayDevice.DHCP == true ? (byte)1 : (byte)0;
|
System.Net.IPAddress address;
|
if (System.Net.IPAddress.TryParse (gatewayDevice.IPAddress, out address)) {
|
string [] ipAddress = gatewayDevice.IPAddress.Split ('.');
|
for (int i = 0; i < ipAddress.Length; i++) {
|
bytes [i] = byte.Parse (ipAddress [i]);
|
}
|
} else {
|
throw new Exception ();
|
}
|
if (System.Net.IPAddress.TryParse (gatewayDevice.RouteIPAddress, out address)) {
|
string [] r = gatewayDevice.RouteIPAddress.Split ('.');
|
for (int i = 0; i < r.Length; i++) {
|
bytes [i + 4] = byte.Parse (r [i]);
|
}
|
} else {
|
throw new Exception ();
|
}
|
string [] ipMac = gatewayDevice.IPMAC.Split ('.');
|
//ipMAC前三位HDL 需要特殊处理
|
bytes [0 + 8] = (byte)(ipMac [0].ToCharArray () [0]);
|
bytes [1 + 8] = (byte)(ipMac [1].ToCharArray () [0]);
|
bytes [2 + 8] = (byte)(ipMac [2].ToCharArray () [0]);
|
bytes [3 + 8] = byte.Parse (ipMac [3]);
|
bytes [4 + 8] = byte.Parse (ipMac [4]);
|
bytes [5 + 8] = byte.Parse (ipMac [5]);
|
string [] subnetMask = gatewayDevice.SubnetMask.Split ('.');
|
bytes [14] = 0x17;
|
bytes [15] = 0x70;
|
for (int i = 0; i < subnetMask.Length; i++) {
|
bytes [i + 16] = byte.Parse (subnetMask [i]);
|
}
|
if (Control.ControlBytesSendHasReturn (Command.UpdateGatewayIp,
|
gatewayDevice.SubnetID, gatewayDevice.DeviceID, bytes) != null) {
|
IO.FileUtils.SaveEquipmentMessage (gatewayDevice);
|
}
|
//UpdateBaseInfo (gatewayDevice);
|
} catch {
|
new Alert (Language.StringByID (R.MyInternationalizationString.Tip), Language.StringByID (R.MyInternationalizationString.TipPleaseEnterTheCorrectData), Language.StringByID (R.MyInternationalizationString.Confrim)).Show ();
|
}
|
};
|
if (gatewayDevice.DHCP) {
|
btnDHCPCheck.IsSelected = true;
|
etIPAddresses.Enable = etSubnetMask.Enable = etRoutingIP.Enable = false;
|
btnDHCPSave.Visible = false;
|
} else {
|
btnDHCPCheck.IsSelected = false;
|
etIPAddresses.Enable = etSubnetMask.Enable = etRoutingIP.Enable = true;
|
btnDHCPSave.Visible = true;
|
}
|
#endregion
|
|
|
#region--------------RemoteAccess---------------------
|
RowLayout flRemoteAccessTop = new RowLayout () {
|
Height = Application.GetRealHeight (100),
|
Width = LayoutParams.MatchParent,
|
BackgroundColor = SkinStyle.Current.MainColor
|
};
|
sView.AddChidren (flRemoteAccessTop);
|
|
Button RemoteAccessSeleted = new Button () {
|
X = Application.GetRealWidth (15),
|
Height = Application.GetRealHeight (66),
|
Width = Application.GetRealWidth (66),
|
UnSelectedImagePath = "Item/RemoteAccess.png",
|
SelectedImagePath = "Item/RemoteAccessSelected.png",
|
Gravity = Gravity.CenterVertical,
|
};
|
flRemoteAccessTop.AddChidren (RemoteAccessSeleted);
|
Button lblRemoteAccesss = new Button () {
|
X = Application.GetRealWidth (11) + RemoteAccessSeleted.Right,
|
Height = Application.GetRealHeight (41),
|
Width = Application.GetRealWidth (200),
|
TextID = R.MyInternationalizationString.RemoteAccess,
|
Gravity = Gravity.CenterVertical,
|
TextAlignment = TextAlignment.CenterLeft,
|
TextColor = SkinStyle.Current.TextColor1
|
};
|
flRemoteAccessTop.AddChidren (lblRemoteAccesss);
|
Button btnRemoteAccessHelp = new Button () {
|
Height = Application.GetMinRealAverage (98),
|
Width = Application.GetMinRealAverage (76),
|
UnSelectedImagePath = "Item/Help.png",
|
SelectedImagePath = "Item/HelpSelected.png",
|
Gravity = Gravity.CenterVertical,
|
};
|
btnRemoteAccessHelp.X = flRemoteAccessTop.Width - btnRemoteAccessHelp.Width - Application.GetRealWidth (30);
|
flRemoteAccessTop.AddChidren (btnRemoteAccessHelp);
|
Button btnRemoteAccessCheck = new Button () {
|
Height = Application.GetMinRealAverage (98),
|
Width = Application.GetMinRealAverage (76),
|
UnSelectedImagePath = "Item/Check.png",
|
SelectedImagePath = "Item/CheckSelected.png",
|
Y = btnRemoteAccessHelp.Y,
|
};
|
btnRemoteAccessCheck.X = flRemoteAccessTop.Width - btnRemoteAccessCheck.Width - Application.GetRealWidth (100);
|
btnRemoteAccessHelp.MouseUpEventHandler += (sender, e) => {
|
new Tip () { MaxWidth = 150, Text = Language.StringByID (R.MyInternationalizationString.HelpRemoteAccess), Direction = AMPopTipDirection.Down, CloseTime = 4 }.Show ((View)sender);
|
};
|
flRemoteAccessTop.AddChidren (btnRemoteAccessCheck);
|
|
FrameLayout flRemoteAccessBody = new FrameLayout () {
|
Height = Application.GetRealHeight (0),
|
Width = LayoutParams.MatchParent,
|
};
|
sView.AddChidren (flRemoteAccessBody);
|
|
FrameLayout flRemoteAutoSetting = new FrameLayout () {
|
Height = Application.GetRealHeight (90),
|
};
|
flRemoteAccessBody.AddChidren (flRemoteAutoSetting);
|
|
|
|
Button btnRemoteAutoCheck = new Button () {
|
Gravity = Gravity.Center,
|
Width = Application.GetRealWidth (300),
|
Height = Application.GetRealHeight (60),
|
BorderColor = SkinStyle.Current.BorderColor,
|
BorderWidth = 1,
|
Radius = 5,
|
TextColor = SkinStyle.Current.TextColor1,
|
SelectedTextColor = SkinStyle.Current.TextColor1,
|
TextID = R.MyInternationalizationString.AutomaticSetting,
|
TextAlignment = TextAlignment.Center,
|
//Text = "YES"
|
};
|
flRemoteAutoSetting.AddChidren (btnRemoteAutoCheck);
|
|
|
Button btnGroupName = new Button () {
|
X = gatewayIDName.X,
|
Y = flRemoteAutoSetting.Bottom + Application.GetRealHeight (20),
|
TextAlignment = TextAlignment.CenterLeft,
|
Height = Application.GetRealHeight (49),
|
Width = Application.GetRealWidth (360),
|
TextID = R.MyInternationalizationString.GroupName,
|
TextColor = SkinStyle.Current.TextColor1
|
};
|
flRemoteAccessBody.AddChidren (btnGroupName);
|
|
EditText etGroupName = new EditText () {
|
X = gatewayIDName.X,
|
TextAlignment = TextAlignment.CenterLeft,
|
Height = Application.GetRealHeight (55),
|
Width = Application.GetRealWidth (440),
|
Y = btnGroupName.Bottom + Application.GetRealHeight (2),
|
//BackgroundColor = SkinStyle.Current.SysEditBox,
|
BorderColor = SkinStyle.Current.BorderColor,
|
BorderWidth = 1,
|
Radius = 5,
|
TextColor = SkinStyle.Current.TextColor1
|
};
|
flRemoteAccessBody.AddChidren (etGroupName);
|
|
Button lblProjectName = new Button () {
|
X = gatewayIDName.X,
|
TextAlignment = TextAlignment.CenterLeft,
|
Height = Application.GetRealHeight (40),
|
Width = Application.GetRealWidth (360),
|
TextID = R.MyInternationalizationString.ProjectName,
|
Y = etGroupName.Bottom + Application.GetRealHeight (2),
|
TextColor = SkinStyle.Current.TextColor1
|
};
|
flRemoteAccessBody.AddChidren (lblProjectName);
|
|
EditText etProjectName = new EditText () {
|
X = gatewayIDName.X,
|
TextAlignment = TextAlignment.CenterLeft,
|
Height = Application.GetRealHeight (55),
|
Width = Application.GetRealWidth (440),
|
Y = lblProjectName.Bottom + Application.GetRealHeight (2),
|
//BackgroundColor = SkinStyle.Current.SysEditBox,
|
BorderColor = SkinStyle.Current.BorderColor,
|
BorderWidth = 1,
|
Radius = 5,
|
TextColor = SkinStyle.Current.TextColor1
|
};
|
flRemoteAccessBody.AddChidren (etProjectName);
|
|
Button lblUsername = new Button () {
|
X = lblProjectName.X,
|
TextAlignment = TextAlignment.CenterLeft,
|
Height = Application.GetRealHeight (55),
|
Width = Application.GetRealWidth (440),
|
TextID = R.MyInternationalizationString.UserName,
|
Y = etProjectName.Bottom + Application.GetRealHeight (2),
|
TextColor = SkinStyle.Current.TextColor1
|
};
|
flRemoteAccessBody.AddChidren (lblUsername);
|
|
EditText etUserName = new EditText () {
|
X = lblProjectName.X,
|
TextAlignment = TextAlignment.CenterLeft,
|
Height = Application.GetRealHeight (55),
|
Width = Application.GetRealWidth (440),
|
//BackgroundColor = SkinStyle.Current.SysEditBox,
|
BorderColor = SkinStyle.Current.BorderColor,
|
BorderWidth = 1,
|
Radius = 5,
|
Y = lblUsername.Bottom + Application.GetRealHeight (2),
|
TextColor = SkinStyle.Current.TextColor1
|
};
|
flRemoteAccessBody.AddChidren (etUserName);
|
|
Button btnGatewayPassword = new Button () {
|
X = lblProjectName.X,
|
Y = etUserName.Bottom + Application.GetRealHeight (2),
|
Height = Application.GetRealHeight (55),
|
Width = Application.GetRealWidth (440),
|
TextID = R.MyInternationalizationString.PassWrod,
|
TextAlignment = TextAlignment.CenterLeft,
|
TextColor = SkinStyle.Current.TextColor1
|
};
|
flRemoteAccessBody.AddChidren (btnGatewayPassword);
|
|
EditText etGatewayPassWrod = new EditText () {
|
X = lblProjectName.X,
|
Y = btnGatewayPassword.Bottom + Application.GetRealHeight (2),
|
TextAlignment = TextAlignment.CenterLeft,
|
Height = Application.GetRealHeight (55),
|
Width = Application.GetRealWidth (440),
|
Text = gatewayDevice.Remote_Password,
|
//BackgroundColor = SkinStyle.Current.SysEditBox,
|
BorderColor = SkinStyle.Current.BorderColor,
|
BorderWidth = 1,
|
Radius = 5,
|
TextColor = SkinStyle.Current.TextColor1
|
};
|
flRemoteAccessBody.AddChidren (etGatewayPassWrod);
|
|
Button btnServerIP = new Button () {
|
X = lblProjectName.X,
|
Y = etGatewayPassWrod.Bottom + Application.GetRealHeight (2),
|
Height = Application.GetRealHeight (55),
|
Width = Application.GetRealWidth (440),
|
TextID = R.MyInternationalizationString.ServerIP,
|
TextAlignment = TextAlignment.CenterLeft,
|
TextColor = SkinStyle.Current.TextColor1
|
};
|
flRemoteAccessBody.AddChidren (btnServerIP);
|
|
EditText etServerIP = new EditText () {
|
X = lblProjectName.X,
|
Y = btnServerIP.Bottom + Application.GetRealHeight (2),
|
TextAlignment = TextAlignment.CenterLeft,
|
Height = Application.GetRealHeight (55),
|
Width = Application.GetRealWidth (300),
|
//BackgroundColor = SkinStyle.Current.SysEditBox,
|
BorderColor = SkinStyle.Current.BorderColor,
|
BorderWidth = 1,
|
Radius = 5,
|
TextColor = SkinStyle.Current.TextColor1
|
};
|
flRemoteAccessBody.AddChidren (etServerIP);
|
|
EditText etServerIPPoint = new EditText () {
|
X = etServerIP.Right + 2,
|
Y = etServerIP.Y,
|
TextAlignment = TextAlignment.CenterLeft,
|
Height = Application.GetRealHeight (55),
|
Width = Application.GetRealWidth (140) - 2,
|
//BackgroundColor = SkinStyle.Current.SysEditBox,
|
BorderColor = SkinStyle.Current.BorderColor,
|
BorderWidth = 1,
|
Radius = 5,
|
TextColor = SkinStyle.Current.TextColor1
|
};
|
flRemoteAccessBody.AddChidren (etServerIPPoint);
|
|
Button btnAlternativeServerIP = new Button () {
|
X = lblProjectName.X,
|
Y = etServerIP.Bottom + Application.GetRealHeight (2),
|
Height = Application.GetRealHeight (55),
|
Width = Application.GetRealWidth (440),
|
TextID = R.MyInternationalizationString.AlternativeServerIP,
|
TextAlignment = TextAlignment.CenterLeft,
|
TextColor = SkinStyle.Current.TextColor1
|
};
|
flRemoteAccessBody.AddChidren (btnAlternativeServerIP);
|
|
EditText etAlternativeServerIP = new EditText () {
|
X = lblProjectName.X,
|
Y = btnAlternativeServerIP.Bottom + Application.GetRealHeight (2),
|
TextAlignment = TextAlignment.CenterLeft,
|
Height = Application.GetRealHeight (55),
|
Width = Application.GetRealWidth (300),
|
//BackgroundColor = SkinStyle.Current.SysEditBox,
|
BorderColor = SkinStyle.Current.BorderColor,
|
BorderWidth = 1,
|
Radius = 5,
|
TextColor = SkinStyle.Current.TextColor1
|
};
|
flRemoteAccessBody.AddChidren (etAlternativeServerIP);
|
EditText etAlternativeServerIPPoint = new EditText () {
|
X = etAlternativeServerIP.Right + 2,
|
Y = etAlternativeServerIP.Y,
|
TextAlignment = TextAlignment.CenterLeft,
|
Height = Application.GetRealHeight (55),
|
Width = Application.GetRealWidth (140) - 2,
|
//BackgroundColor = SkinStyle.Current.SysEditBox,
|
BorderColor = SkinStyle.Current.BorderColor,
|
BorderWidth = 1,
|
Radius = 5,
|
TextColor = SkinStyle.Current.TextColor1
|
};
|
flRemoteAccessBody.AddChidren (etAlternativeServerIPPoint);
|
|
Button btnGatewaySave = new Button () {
|
X = (Application.CurrentWidth / 2 - 30),
|
Height = Application.GetRealHeight (55),
|
Width = Application.GetRealWidth (100),
|
BackgroundColor = SkinStyle.Current.ButtonColor,
|
SelectedBackgroundColor = SkinStyle.Current.SelectedColor,
|
BorderWidth = 1,
|
Radius = 5,
|
BorderColor = SkinStyle.Current.Transparent,
|
TextID = R.MyInternationalizationString.SAVE,
|
Y = etAlternativeServerIP.Bottom + Application.GetRealHeight (20),
|
TextColor = SkinStyle.Current.TextColor1
|
};
|
flRemoteAccessBody.AddChidren (btnGatewaySave);
|
flRemoteAccessBody.Height = btnGatewaySave.Bottom + Application.GetRealHeight (20);
|
byte [] gatewayBytes = null;
|
byte [] serverIPBytes = null;
|
System.Threading.Tasks.Task.Run (() => {
|
gatewayBytes = Control.ControlBytesSendHasReturn (Command.ReadGateWayModelInfo, gatewayDevice.SubnetID, gatewayDevice.DeviceID, new byte [] { });
|
serverIPBytes = Control.ControlBytesSendHasReturn (Command.ReadGatewayServerIP, gatewayDevice.SubnetID, gatewayDevice.DeviceID, new byte [] { });
|
IO.FileUtils.WriteFileByBytes ("Remote_GatewayBytes_" + gatewayDevice.Name + "_" + gatewayDevice.SubnetID, gatewayBytes);
|
if (gatewayBytes != null && serverIPBytes != null) {
|
Application.RunOnMainThread (() => {
|
#region ---读取、设置组名工程名---
|
int model = gatewayBytes [0];
|
gatewayDevice.Remote_GroupName = CommonPage.MyEncodingGB2312.GetString (gatewayBytes, 1, 20).Trim ('\0');
|
gatewayDevice.Remote_ProjectName = CommonPage.MyEncodingGB2312.GetString (gatewayBytes, 21, 20).Trim ('\0');
|
gatewayDevice.Remote_UserName = CommonPage.MyEncodingGB2312.GetString (gatewayBytes, 41, 8).Trim ('\0');
|
gatewayDevice.Remote_Password = CommonPage.MyEncodingGB2312.GetString (gatewayBytes, 49, 8).Trim ('\0');
|
IO.FileUtils.SaveEquipmentMessage (gatewayDevice);
|
|
etGroupName.Text = gatewayDevice.Remote_GroupName;
|
etProjectName.Text = gatewayDevice.Remote_ProjectName;
|
etUserName.Text = gatewayDevice.Remote_UserName;
|
etGatewayPassWrod.Text = gatewayDevice.Remote_Password;
|
|
btnRemoteAccessCheck.MouseUpEventHandler += (sender, e) => {
|
if (!btnRemoteAccessCheck.IsSelected) {
|
flRemoteAccessBody.Height = btnGatewaySave.Bottom + Application.GetRealHeight (20);
|
btnRemoteAccessCheck.IsSelected = true;
|
gatewayDevice.RometoMode = gatewayBytes [0] = 2;
|
Control.ControlBytesSend (Command.SetGateWayModelInfo, gatewayDevice.SubnetID, gatewayDevice.DeviceID, gatewayBytes);
|
UserConfig.Instance.RemoteModeFile = "Equipment_" + gatewayDevice.Type.ToString () + "_" + gatewayDevice.SubnetID.ToString () + "_" + gatewayDevice.DeviceID.ToString ();
|
UserConfig.Instance.SaveUserConfig ();
|
} else {
|
flRemoteAccessBody.Height = Application.GetRealHeight (0);
|
btnRemoteAccessCheck.IsSelected = false;
|
gatewayDevice.RometoMode = gatewayBytes [0] = 0;
|
Control.ControlBytesSend (Command.SetGateWayModelInfo, gatewayDevice.SubnetID, gatewayDevice.DeviceID, gatewayBytes);
|
UserConfig.Instance.RemoteModeFile = "";
|
UserConfig.Instance.SaveUserConfig ();
|
}
|
IO.FileUtils.SaveEquipmentMessage (gatewayDevice);
|
};
|
#endregion
|
#region ---读取、设置 网关IP地址参数---
|
string serverIP1 = serverIPBytes [0].ToString () + "." + serverIPBytes [1].ToString () + "." +
|
serverIPBytes [2].ToString () + "." + serverIPBytes [3].ToString ();
|
string serverIP1Point = ((serverIPBytes [4] * 256) + serverIPBytes [5]).ToString ();
|
string serverIP2 = serverIPBytes [6].ToString () + "." + serverIPBytes [7].ToString () + "." +
|
serverIPBytes [8].ToString () + "." + serverIPBytes [9].ToString ();
|
string serverIP2Point = ((serverIPBytes [10] * 256) + serverIPBytes [11]).ToString ();
|
etServerIP.Text = serverIP1;
|
etServerIPPoint.Text = serverIP1Point == "0" ? "9999" : serverIP1Point;
|
serverIP1Point = etServerIPPoint.Text;
|
etAlternativeServerIP.Text = serverIP2;
|
etAlternativeServerIPPoint.Text = serverIP2Point == "0" ? "9999" : serverIP2Point;
|
serverIP2Point = etAlternativeServerIPPoint.Text;
|
btnGatewaySave.MouseUpEventHandler += (sender, e) => {
|
gatewayDevice.Remote_GroupName = etGroupName.Text.Trim ();// "james";//gatewayGroupName;
|
gatewayDevice.Remote_ProjectName = etProjectName.Text.Trim ();//"myhome";//gatewayProjectName;
|
gatewayDevice.Remote_UserName = etUserName.Text.Trim ();//"james";//gatewayUserName;
|
gatewayDevice.Remote_Password = etGatewayPassWrod.Text.Trim ();//"chy1125";//gatewayPassWord;
|
|
string [] strServerIP = etServerIP.Text.Split ('.');
|
string [] strServerIP1 = etAlternativeServerIP.Text.Split ('.');
|
IO.FileUtils.SaveEquipmentMessage (gatewayDevice);
|
System.Threading.Tasks.Task.Run (() => {
|
try {
|
Application.RunOnMainThread (() => {
|
MainPage.Loading.Start ("Sending...");
|
});
|
byte [] ggn = new byte [20];
|
byte [] b1 = CommonPage.MyEncodingGB2312.GetBytes (gatewayDevice.Remote_GroupName);
|
Array.Copy (b1, 0, ggn, 0, 20 < b1.Length ? 20 : b1.Length);
|
|
byte [] gpn = new byte [20];
|
byte [] b2 = CommonPage.MyEncodingGB2312.GetBytes (gatewayDevice.Remote_ProjectName);
|
Array.Copy (b2, 0, gpn, 0, 20 < b2.Length ? 20 : b2.Length);
|
|
byte [] gun = new byte [8];
|
byte [] b3 = CommonPage.MyEncodingGB2312.GetBytes (gatewayDevice.Remote_UserName);
|
Array.Copy (b3, 0, gun, 0, 8 < b3.Length ? 8 : b3.Length);
|
|
byte [] gpw = new byte [8];
|
byte [] b4 = CommonPage.MyEncodingGB2312.GetBytes (gatewayDevice.Remote_Password);
|
Array.Copy (b4, 0, gpw, 0, 8 < b4.Length ? 8 : b4.Length);
|
|
|
byte [] macAddress = Control.ControlBytesSendHasReturn (Command.ReadDeviceMac, gatewayDevice.SubnetID, gatewayDevice.DeviceID, new byte [] { });
|
byte [] sendServerBytes = new byte [56];
|
Array.Copy (gpn, 0, sendServerBytes, 0, 20 < gpn.Length ? 20 : gpn.Length);
|
Array.Copy (ggn, 0, sendServerBytes, 20, 20 < ggn.Length ? 20 : ggn.Length);
|
Array.Copy (gun, 0, sendServerBytes, 40, 8 < gun.Length ? 8 : gun.Length);
|
Array.Copy (macAddress, 0, sendServerBytes, 48, 8 < macAddress.Length ? 8 : macAddress.Length);
|
Control control = new Control ();
|
control.Send (new Target () {
|
IPEndPoint = new System.Net.IPEndPoint (System.Net.IPAddress.Parse (MainPage.SeviceIP), 9999),
|
Command = Command.SendRemoteInfoToServer,
|
SubnetID = 251,
|
DeviceID = 251,
|
AddData = sendServerBytes,
|
}, SendCount.Three, true);
|
var serverResult = control.UsefulBytes;
|
if (serverResult == null || serverResult [0] == 0) {
|
Application.RunOnMainThread (() => {
|
new Alert (Language.StringByID (R.MyInternationalizationString.Tip), Language.StringByID (R.MyInternationalizationString.OperationFailed),
|
Language.StringByID (R.MyInternationalizationString.Close)).Show ();
|
});
|
//} else if (serverResult [0] == 2) {
|
//Application.RunOnMainThread (() => {
|
// new Alert (Language.StringByID (R.MyInternationalizationString.Tip), Language.StringByID (R.MyInternationalizationString.HaveTheSame),
|
// Language.StringByID (R.MyInternationalizationString.Close)).Show ();
|
//});
|
} else {
|
Array.Copy (ggn, 0, gatewayBytes, 1, 20 < ggn.Length ? 20 : ggn.Length);
|
Array.Copy (gpn, 0, gatewayBytes, 21, 20 < gpn.Length ? 20 : gpn.Length);
|
Array.Copy (gun, 0, gatewayBytes, 41, 8 < gun.Length ? 8 : gun.Length);
|
Array.Copy (gpw, 0, gatewayBytes, 49, 8 < gpw.Length ? 8 : gpw.Length);
|
|
Control.ControlBytesSend (Command.SetGateWayModelInfo, gatewayDevice.SubnetID, gatewayDevice.DeviceID, gatewayBytes);
|
|
if (strServerIP.Length != 4 || strServerIP1.Length != 4) {
|
throw new Exception ();
|
} else {
|
serverIPBytes [0] = Convert.ToByte (strServerIP [0]);
|
serverIPBytes [1] = Convert.ToByte (strServerIP [1]);
|
serverIPBytes [2] = Convert.ToByte (strServerIP [2]);
|
serverIPBytes [3] = Convert.ToByte (strServerIP [3]);
|
int point1 = 9999;
|
if (!int.TryParse (serverIP1Point, out point1)) {
|
point1 = 9999;
|
}
|
serverIPBytes [4] = Convert.ToByte (point1 / 256);
|
serverIPBytes [5] = Convert.ToByte (point1 % 256);
|
|
serverIPBytes [6] = Convert.ToByte (strServerIP1 [0]);
|
serverIPBytes [7] = Convert.ToByte (strServerIP1 [1]);
|
serverIPBytes [8] = Convert.ToByte (strServerIP1 [2]);
|
serverIPBytes [9] = Convert.ToByte (strServerIP1 [3]); int point2 = 9999;
|
if (!int.TryParse (serverIP2Point, out point2)) {
|
point2 = 9999;
|
}
|
serverIPBytes [10] = Convert.ToByte (point2 / 256);
|
serverIPBytes [11] = Convert.ToByte (point2 % 256);
|
}
|
//远程ip地址的设置
|
var mobytes = Control.ControlBytesSendHasReturn (Command.SetGateWayModelInternetInfo, gatewayDevice.SubnetID, gatewayDevice.DeviceID, serverIPBytes);
|
if (mobytes == null || mobytes [0] == 0xF5) {
|
Application.RunOnMainThread (() => {
|
new Alert (Language.StringByID (R.MyInternationalizationString.Tip), Language.StringByID (R.MyInternationalizationString.OperationFailed),
|
Language.StringByID (R.MyInternationalizationString.Close)).Show ();
|
});
|
} else {
|
Application.RunOnMainThread (() => {
|
new Alert (Language.StringByID (R.MyInternationalizationString.Tip), Language.StringByID (R.MyInternationalizationString.ThePerationWasSuccessful), Language.StringByID (R.MyInternationalizationString.Confrim)).Show ();
|
});
|
}
|
}
|
} catch {
|
Application.RunOnMainThread (() => {
|
new Alert (Language.StringByID (R.MyInternationalizationString.Tip), Language.StringByID (R.MyInternationalizationString.TipPleaseEnterTheCorrectData), Language.StringByID (R.MyInternationalizationString.Close)).Show ();
|
});
|
} finally {
|
Application.RunOnMainThread (() => {
|
MainPage.Loading.Hide ();
|
});
|
}
|
});
|
};
|
#endregion
|
|
if (model == 0) {
|
flRemoteAccessBody.Height = Application.GetRealHeight (0);
|
btnRemoteAccessCheck.IsSelected = false;
|
} else {
|
flRemoteAccessBody.Height = btnGatewaySave.Bottom + Application.GetRealHeight (20);
|
btnRemoteAccessCheck.IsSelected = true;
|
UserConfig.Instance.RemoteModeFile = "Equipment_" + gatewayDevice.Type.ToString () + "_" + gatewayDevice.SubnetID.ToString () + "_" + gatewayDevice.DeviceID.ToString ();
|
UserConfig.Instance.SaveUserConfig ();
|
gatewayBytes [0] = 2;
|
}
|
});
|
}
|
});
|
|
|
btnRemoteAutoCheck.MouseUpEventHandler += (sender, e) => {
|
Dialog dialogRemoteAuto = new Dialog ();
|
|
FrameLayout remoteAutoView = new FrameLayout () {
|
Width = Application.GetRealWidth (400),
|
Height = Application.GetRealHeight (270 + 100),
|
Gravity = Gravity.Center,
|
Radius = 5,
|
BorderColor = SkinStyle.Current.Transparent,
|
BorderWidth = 0,
|
BackgroundColor = SkinStyle.Current.DialogColor,
|
};
|
dialogRemoteAuto.AddChidren (remoteAutoView);
|
|
|
Button remoteAutoTitle = new Button () {
|
Height = Application.GetRealHeight (80),
|
BackgroundColor = SkinStyle.Current.DialogTitle,
|
TextID = R.MyInternationalizationString.RemotePassword,
|
TextColor = SkinStyle.Current.DialogTextColor,
|
TextAlignment = TextAlignment.Center,
|
};
|
remoteAutoView.AddChidren (remoteAutoTitle);
|
|
|
EditText etRemoteAutoPW = new EditText () {
|
Gravity = Gravity.Center,
|
Height = Application.GetRealHeight (55),
|
Width = Application.GetRealWidth (300),
|
//BackgroundColor = SkinStyle.Current.SysEditBox,
|
BorderColor = SkinStyle.Current.BorderColor,
|
TextAlignment = TextAlignment.Center,
|
BorderWidth = 1,
|
Radius = 5,
|
TextColor = SkinStyle.Current.TextColor
|
};
|
remoteAutoView.AddChidren (etRemoteAutoPW);
|
|
FrameLayout remoteAutoBottom = new FrameLayout () {
|
Y = Application.GetRealHeight (270 + 20),
|
Height = Application.GetRealHeight (83),
|
BackgroundColor = SkinStyle.Current.LineColor,
|
};
|
remoteAutoView.AddChidren (remoteAutoBottom);
|
|
Button btnCancel = new Button () {
|
Width = Application.GetRealWidth (200),
|
BackgroundColor = SkinStyle.Current.DialogTitle,
|
TextID = R.MyInternationalizationString.cancel,
|
TextAlignment = TextAlignment.Center,
|
};
|
remoteAutoBottom.AddChidren (btnCancel);
|
btnCancel.MouseUpEventHandler += (ssd, de) => {
|
dialogRemoteAuto.Close ();
|
};
|
|
Button btnConfrim = new Button () {
|
X = btnCancel.Right + 1,
|
Width = Application.GetRealWidth (200),
|
BackgroundColor = SkinStyle.Current.DialogTitle,
|
TextID = R.MyInternationalizationString.Confrim,
|
TextAlignment = TextAlignment.Center,
|
};
|
remoteAutoBottom.AddChidren (btnConfrim);
|
|
btnConfrim.MouseUpEventHandler += (ssd, de) => {
|
if (etRemoteAutoPW.Text.Trim ().Length < 6) {
|
new Tip () { MaxWidth = 250, Text = Language.StringByID (R.MyInternationalizationString.PasswordLenghtTip), Direction = AMPopTipDirection.Down, CloseTime = 3 }.Show (etRemoteAutoPW);
|
return;
|
}
|
|
gatewayDevice.Remote_GroupName = etGroupName.Text = UserConfig.Instance.CurrentRegion.RegionName;
|
gatewayDevice.Remote_ProjectName = etProjectName.Text = UserConfig.Instance.CurrentRegion.RegionName;
|
gatewayDevice.Remote_UserName = etUserName.Text = "Admin";
|
gatewayDevice.Remote_Password = etGatewayPassWrod.Text = etRemoteAutoPW.Text.Trim ();
|
|
string [] strServerIP = (MainPage.SeviceIP).Split ('.');
|
string [] strServerIP1 = (MainPage.SeviceIP).Split ('.');
|
etServerIP.Text = etAlternativeServerIP.Text = MainPage.SeviceIP;
|
etServerIPPoint.Text = etAlternativeServerIPPoint.Text = "9999";
|
System.Threading.Tasks.Task.Run (() => {
|
try {
|
Application.RunOnMainThread (() => {
|
MainPage.Loading.Start ("Sending...");
|
});
|
byte [] ggn = new byte [20];
|
byte [] b1 = CommonPage.MyEncodingGB2312.GetBytes (gatewayDevice.Remote_GroupName);
|
Array.Copy (b1, 0, ggn, 0, 20 < b1.Length ? 20 : b1.Length);
|
|
byte [] gpn = new byte [20];
|
byte [] b2 = CommonPage.MyEncodingGB2312.GetBytes (gatewayDevice.Remote_ProjectName);
|
Array.Copy (b2, 0, gpn, 0, 20 < b2.Length ? 20 : b2.Length);
|
|
byte [] gun = new byte [8];
|
byte [] b3 = CommonPage.MyEncodingGB2312.GetBytes (gatewayDevice.Remote_UserName);
|
Array.Copy (b3, 0, gun, 0, 8 < b3.Length ? 8 : b3.Length);
|
|
byte [] gpw = new byte [8];
|
byte [] b4 = CommonPage.MyEncodingGB2312.GetBytes (gatewayDevice.Remote_Password);
|
Array.Copy (b4, 0, gpw, 0, 8 < b4.Length ? 8 : b4.Length);
|
|
|
byte [] macAddress = Control.ControlBytesSendHasReturn (Command.ReadDeviceMac, gatewayDevice.SubnetID, gatewayDevice.DeviceID, new byte [] { });
|
byte [] sendServerBytes = new byte [56];
|
Array.Copy (gpn, 0, sendServerBytes, 0, 20 < gpn.Length ? 20 : gpn.Length);
|
Array.Copy (ggn, 0, sendServerBytes, 20, 20 < ggn.Length ? 20 : ggn.Length);
|
Array.Copy (gun, 0, sendServerBytes, 40, 8 < gun.Length ? 8 : gun.Length);
|
Array.Copy (macAddress, 0, sendServerBytes, 48, 8 < macAddress.Length ? 8 : macAddress.Length);
|
Control control = new Control ();
|
control.Send (new Target () {
|
IPEndPoint = new System.Net.IPEndPoint (System.Net.IPAddress.Parse (MainPage.SeviceIP), 9999),
|
Command = Command.SendRemoteInfoToServer,
|
SubnetID = 251,
|
DeviceID = 251,
|
AddData = sendServerBytes,
|
}, SendCount.Three, true);
|
var serverResult = control.UsefulBytes;
|
if (serverResult == null || serverResult [0] == 0) {
|
Application.RunOnMainThread (() => {
|
new Alert (Language.StringByID (R.MyInternationalizationString.Tip), Language.StringByID (R.MyInternationalizationString.OperationFailed),
|
Language.StringByID (R.MyInternationalizationString.Close)).Show ();
|
});
|
} else {
|
Array.Copy (ggn, 0, gatewayBytes, 1, 20 < ggn.Length ? 20 : ggn.Length);
|
Array.Copy (gpn, 0, gatewayBytes, 21, 20 < gpn.Length ? 20 : gpn.Length);
|
Array.Copy (gun, 0, gatewayBytes, 41, 8 < gun.Length ? 8 : gun.Length);
|
Array.Copy (gpw, 0, gatewayBytes, 49, 8 < gpw.Length ? 8 : gpw.Length);
|
|
Control.ControlBytesSend (Command.SetGateWayModelInfo, gatewayDevice.SubnetID, gatewayDevice.DeviceID, gatewayBytes);
|
|
if (strServerIP.Length != 4 || strServerIP1.Length != 4) {
|
throw new Exception ();
|
} else {
|
serverIPBytes [0] = Convert.ToByte (strServerIP [0]);
|
serverIPBytes [1] = Convert.ToByte (strServerIP [1]);
|
serverIPBytes [2] = Convert.ToByte (strServerIP [2]);
|
serverIPBytes [3] = Convert.ToByte (strServerIP [3]);
|
int point1 = 9999;
|
|
serverIPBytes [4] = Convert.ToByte (point1 / 256);
|
serverIPBytes [5] = Convert.ToByte (point1 % 256);
|
|
serverIPBytes [6] = Convert.ToByte (strServerIP1 [0]);
|
serverIPBytes [7] = Convert.ToByte (strServerIP1 [1]);
|
serverIPBytes [8] = Convert.ToByte (strServerIP1 [2]);
|
serverIPBytes [9] = Convert.ToByte (strServerIP1 [3]);
|
int point2 = 9999;
|
|
serverIPBytes [10] = Convert.ToByte (point2 / 256);
|
serverIPBytes [11] = Convert.ToByte (point2 % 256);
|
}
|
//远程ip地址的设置
|
var mobytes = Control.ControlBytesSendHasReturn (Command.SetGateWayModelInternetInfo, gatewayDevice.SubnetID, gatewayDevice.DeviceID, serverIPBytes);
|
if (mobytes == null || mobytes [0] == 0xF5) {
|
Application.RunOnMainThread (() => {
|
new Alert (Language.StringByID (R.MyInternationalizationString.Tip), Language.StringByID (R.MyInternationalizationString.OperationFailed),
|
Language.StringByID (R.MyInternationalizationString.Close)).Show ();
|
});
|
} else {
|
Application.RunOnMainThread (() => {
|
new Alert (Language.StringByID (R.MyInternationalizationString.Tip), Language.StringByID (R.MyInternationalizationString.ThePerationWasSuccessful), Language.StringByID (R.MyInternationalizationString.Confrim)).Show ();
|
IO.FileUtils.SaveEquipmentMessage (gatewayDevice);
|
dialogRemoteAuto.Close ();
|
});
|
}
|
}
|
} catch {
|
Application.RunOnMainThread (() => {
|
new Alert (Language.StringByID (R.MyInternationalizationString.Tip), Language.StringByID (R.MyInternationalizationString.TipPleaseEnterTheCorrectData), Language.StringByID (R.MyInternationalizationString.Close)).Show ();
|
});
|
} finally {
|
Application.RunOnMainThread (() => {
|
MainPage.Loading.Hide ();
|
});
|
}
|
});
|
};
|
|
dialogRemoteAuto.Show ();
|
};
|
|
#endregion
|
|
|
gatewayInfoSwitch.MouseUpEventHandler += (sender, e) => {
|
gatewayInfoSwitch.IsSelected = !gatewayInfoSwitch.IsSelected;
|
if (gatewayInfoSwitch.IsSelected) {
|
sView.Height = flRemoteAccessBody.Bottom - frameLayoutGatewayID.X;
|
} else {
|
sView.Height = 0;
|
}
|
};
|
|
#region ----Add a connection to the Gateway List-----
|
RowLayout flGatewayMapping = new RowLayout () {
|
Height = Application.GetRealHeight (100),
|
Width = LayoutParams.MatchParent,
|
BackgroundColor = SkinStyle.Current.MainColor
|
};
|
sView.AddChidren (flGatewayMapping);
|
Button btnGatewayMappingAdd = new Button () {
|
X = Application.GetRealWidth (17),
|
Height = Application.GetRealHeight (55),
|
Width = Application.GetRealWidth (55),
|
UnSelectedImagePath = "Item/+.png",
|
SelectedImagePath = "Item/+Selected.png",
|
Gravity = Gravity.CenterVertical,
|
};
|
flGatewayMapping.AddChidren (btnGatewayMappingAdd);
|
|
Button rpMappingAdd = new Button () {
|
X = backButton.Right,
|
Height = Application.GetRealHeight (41),
|
Width = Application.GetRealWidth (400),
|
TextID = R.MyInternationalizationString.GatewayList,
|
Gravity = Gravity.CenterVertical,
|
TextAlignment = TextAlignment.CenterLeft,
|
TextColor = SkinStyle.Current.TextColor1
|
};
|
flGatewayMapping.AddChidren (rpMappingAdd);
|
Button btnGatewayMappingHelp = new Button () {
|
Height = Application.GetMinRealAverage (100),
|
Width = Application.GetMinRealAverage (76),
|
UnSelectedImagePath = "Item/Help.png",
|
SelectedImagePath = "Item/HelpSelected.png",
|
Gravity = Gravity.CenterVertical,
|
X = btnNetWorkHelp.X,
|
};
|
btnGatewayMappingHelp.MouseUpEventHandler += (sender, e) => {
|
new Tip () { MaxWidth = 150, Text = Language.StringByID (R.MyInternationalizationString.DistributionMACHelp), Direction = AMPopTipDirection.Down, CloseTime = 4 }.Show ((View)sender);
|
};
|
flGatewayMapping.AddChidren (btnGatewayMappingHelp);
|
|
FrameLayout flGatewayMapping4 = new FrameLayout () {
|
Height = Application.GetRealHeight (60),
|
Width = LayoutParams.MatchParent,
|
};
|
|
EventHandler<MouseEventArgs> handler = (sender, e) => {
|
SystemWirelessGateway.UpdataGatewayList (btnGatewayMappingHelp.X, flGatewayMapping4, gatewayDevice.MAC);
|
};
|
btnGatewayMappingAdd.MouseUpEventHandler += handler;
|
rpMappingAdd.MouseUpEventHandler += handler;
|
|
sView.AddChidren (flGatewayMapping4);
|
#endregion
|
//},true);
|
|
// 刷新当前一端口交换机
|
var sysBottomView = new FrameLayout () {
|
Height = Application.GetRealHeight (90),
|
Y = Application.GetRealHeight (844)
|
};
|
AddChidren (sysBottomView);
|
|
Button AddSystemEquipmentButton = new Button () {
|
Width = LayoutParams.MatchParent,
|
Height = LayoutParams.MatchParent,
|
TextID = R.MyInternationalizationString.ReFresh,
|
TextAlignment = TextAlignment.Center,
|
TextColor = SkinStyle.Current.TextColor1,
|
BackgroundColor = SkinStyle.Current.MainColor
|
};
|
sysBottomView.AddChidren (AddSystemEquipmentButton);
|
AddSystemEquipmentButton.MouseUpEventHandler += (sender, e) => {
|
MainPage.Loading.Start ();
|
System.Threading.Tasks.Task.Run (() => {
|
CommonPage.GateWayList.Clear ();
|
CommonPage.RandomHigh = (byte)new Random ().Next (255);
|
CommonPage.RandomLow = (byte)new Random ().Next (255);
|
gatewayInfo = Control.ControlBytesSendHasReturn (Command.ReadGateway, gatewayDevice.SubnetID, gatewayDevice.DeviceID, new byte [] { CommonPage.RandomHigh, CommonPage.RandomLow });
|
var deviceBytes = IO.FileUtils.ReadEquipmentMessage (gatewayDevice);
|
var gatewayDevice1 = Newtonsoft.Json.JsonConvert.DeserializeObject<RCU> (deviceBytes);
|
if (gatewayDevice1 != null)
|
Application.RunOnMainThread (() => {
|
this.ShowRCU (gatewayDevice1);
|
});
|
});
|
};
|
sysBottomView.AddChidren (new Button () { Height = 1, BackgroundColor = SkinStyle.Current.White20Transparent });
|
}
|
});
|
});
|
}
|
/// <summary>
|
/// 弹出确认分配设备地址的窗口
|
/// </summary>
|
static void ShowAssignedAddressDialog (byte subnetID, byte deviceID)
|
{
|
SystemWirelessGateway.ShowAssignedAddressDialog (subnetID, deviceID);
|
}
|
}
|
}
|