using Shared.Common;
|
using ZigBee.Device;
|
namespace Shared.Phone.UserCenter.DevicePanel
|
{
|
public class DataCorrectionForm : EditorCommonForm
|
{
|
#region ■ 变量声明___________________________
|
/// <summary>
|
/// 面板的回路
|
/// </summary>
|
private CommonDevice device;
|
/// <summary>
|
/// 保存完成按钮
|
/// </summary>
|
Button btnFinifh;
|
/// <summary>
|
/// 校正温度值
|
/// </summary>
|
double correctTValue = 0;
|
/// <summary>
|
/// 校正湿度值
|
/// </summary>
|
double correctHValue = 0;
|
/// <summary>
|
/// 有效文本
|
/// </summary>
|
private string invalidText1 = "";
|
/// <summary>
|
/// 有效文本
|
/// </summary>
|
private string invalidText2 = "";
|
#endregion
|
|
#region ■ 初始化____________________________
|
|
/// <summary>
|
/// 画面显示(底层会固定调用此方法,借以完成画面创建)
|
/// </summary>
|
/// <param name="i_device">设备的某一回路</param>
|
public void ShowForm(CommonDevice device)
|
{
|
this.device = device;
|
|
//设置头部信息
|
base.SetTitleText(Language.StringByID(R.MyInternationalizationString.DataCorrection));
|
|
//初始化中部信息
|
this.InitMiddleFrame();
|
}
|
|
/// <summary>
|
/// 初始化中部信息
|
/// </summary>
|
private async void InitMiddleFrame()
|
{
|
//清空bodyFrame
|
this.ClearBodyFrame();
|
TemperatureDataUI();
|
TipUI();
|
}
|
|
#endregion
|
|
#region ■ 温度设置_______________________
|
/// <summary>
|
/// 温度设置
|
/// </summary>
|
private void TemperatureDataUI()
|
{
|
var listview = new VerticalScrolViewLayout();
|
listview.Height = Application.GetRealHeight(320);
|
bodyFrameLayout.AddChidren(listview);
|
listview.ScrollEnabled = false;
|
|
for (int i = 0; i < 2; i++)
|
{
|
var rowLayout = new FrameLayout()
|
{
|
Height = Application.GetRealHeight(23 + 127),
|
BackgroundColor = Shared.Common.ZigbeeColor.Current.XMWhite,
|
};
|
listview.AddChidren(rowLayout);
|
|
var devicePic = new Button()
|
{
|
X = Application.GetRealWidth(58),
|
Y = Application.GetRealHeight(46),
|
Width = Application.GetMinRealAverage(81),
|
Height = Application.GetMinRealAverage(81),
|
};
|
rowLayout.AddChidren(devicePic);
|
|
var btnName = new Button()
|
{
|
Width = Application.GetRealWidth(790),
|
X = devicePic.Right + Application.GetRealWidth(20),
|
TextColor = Shared.Common.ZigbeeColor.Current.TextBlack,
|
TextAlignment = TextAlignment.CenterLeft,
|
TextSize = 15,
|
};
|
rowLayout.AddChidren(btnName);
|
|
var tframeLayout = new FrameLayout()
|
{
|
X = Application.GetRealWidth(714 - 29),
|
Y = Application.GetRealHeight(35),
|
Width = Application.GetMinRealAverage(118 + 98 * 2),
|
Height = Application.GetMinRealAverage(81),
|
BackgroundImagePath = "BindPic/CorrectTemperatureBackGround.png",
|
};
|
rowLayout.AddChidren(tframeLayout);
|
|
var btnReduction = new Button()
|
{
|
Width = Application.GetMinRealAverage(98),
|
Height = Application.GetMinRealAverage(81),
|
};
|
tframeLayout.AddChidren(btnReduction);
|
|
var btnNum = new EditText()
|
{
|
Width = Application.GetMinReal(115),
|
Height = Application.GetRealHeight(80),
|
X = Application.GetRealWidth(98),
|
Text = "0",
|
PlaceholderTextColor = Shared.Common.ZigbeeColor.Current.XMGray3,
|
TextColor = Shared.Common.ZigbeeColor.Current.XMBlack,
|
TextSize = 20,
|
TextAlignment = TextAlignment.Center,
|
};
|
tframeLayout.AddChidren(btnNum);
|
|
var btnAdd = new Button()
|
{
|
X = Application.GetRealWidth(98 + 118),
|
Width = Application.GetMinRealAverage(98),
|
Height = Application.GetMinRealAverage(81),
|
};
|
tframeLayout.AddChidren(btnAdd);
|
|
var line2 = new Button()
|
{
|
Y = rowLayout.Height - 1,
|
X = devicePic.Right + Application.GetRealWidth(20),
|
Width = Application.GetRealWidth(965 - 116),
|
Height = 1,
|
BackgroundColor = Shared.Common.ZigbeeColor.Current.XMRowLine,
|
};
|
rowLayout.AddChidren(line2);
|
|
int curIndex = i;
|
if (curIndex == 0)
|
{
|
devicePic.UnSelectedImagePath = "Device/SensorTemperature.png";
|
btnName.Text = Language.StringByID(R.MyInternationalizationString.Temperature) + " (℃)";
|
invalidText1 = btnNum.Text;
|
}
|
else
|
{
|
line2.Visible = false;
|
devicePic.UnSelectedImagePath = "Device/SensorHumidity.png";
|
btnName.Text = Language.StringByID(R.MyInternationalizationString.Humidity) + " (%)";
|
invalidText2 = btnNum.Text;
|
}
|
|
btnNum.TextChangeEventHandler += (sender, e) =>
|
{
|
if (!string.IsNullOrEmpty((sender as EditText).Text))
|
{
|
var curText = (sender as EditText).Text;
|
var textFir = curText.Substring(0, 1);
|
double curV;
|
var res = double.TryParse(curText, out curV);
|
if (!res)
|
{
|
if (textFir != "-")
|
{
|
curV = 0D;
|
new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.NumTip), Direction = AMPopTipDirection.None, CloseTime = 1 }.Show(Common.CommonPage.Instance);
|
return;
|
}
|
}
|
if (curIndex == 0)
|
{
|
correctTValue = curV;
|
}
|
else
|
{
|
correctHValue = curV;
|
}
|
}
|
if (curIndex == 0)
|
{
|
invalidText1 = btnNum.Text;
|
}
|
else
|
{
|
invalidText2 = btnNum.Text;
|
}
|
|
};
|
|
btnReduction.MouseDownEventHandler += async (sender, e) =>
|
{
|
if(!string.IsNullOrEmpty(btnNum.Text))
|
{
|
double vTemp = double.Parse(btnNum.Text);
|
vTemp -= 0.1;
|
btnNum.Text = vTemp.ToString();
|
if (curIndex == 0)
|
{
|
correctTValue = double.Parse(btnNum.Text);
|
}
|
else
|
{
|
correctHValue = double.Parse(btnNum.Text);
|
}
|
}
|
if (curIndex == 0)
|
{
|
invalidText1 = btnNum.Text;
|
}
|
else
|
{
|
invalidText2 = btnNum.Text;
|
}
|
};
|
|
btnAdd.MouseDownEventHandler += async (sender, e) =>
|
{
|
if (!string.IsNullOrEmpty(btnNum.Text))
|
{
|
double vTemp = double.Parse(btnNum.Text);
|
vTemp += 0.1;
|
btnNum.Text = vTemp.ToString();
|
if (curIndex == 0)
|
{
|
correctTValue = double.Parse(btnNum.Text);
|
}
|
else
|
{
|
correctHValue = double.Parse(btnNum.Text);
|
}
|
}
|
if (curIndex == 0)
|
{
|
invalidText1 = btnNum.Text;
|
}
|
else
|
{
|
invalidText2 = btnNum.Text;
|
}
|
};
|
}
|
}
|
#endregion
|
|
#region ■ 底部提示_______________________
|
/// <summary>
|
/// 底部提示
|
/// </summary>
|
private void TipUI()
|
{
|
var bottomFrameLayout = new FrameLayout()
|
{
|
Y = Application.GetRealHeight(1426),
|
Height = Application.GetMinRealAverage(58),
|
};
|
bodyFrameLayout.AddChidren(bottomFrameLayout);
|
|
var temperatureAttentionPic = new Button()
|
{
|
Width = Application.GetMinRealAverage(58),
|
Height = Application.GetMinRealAverage(58),
|
UnSelectedImagePath = "BindPic/TemperaTureAttention.png"
|
};
|
bottomFrameLayout.AddChidren(temperatureAttentionPic);
|
|
var btnText = new Button()
|
{
|
Width = Application.GetRealWidth(790),
|
X = Application.GetRealWidth(56),
|
TextColor = Shared.Common.ZigbeeColor.Current.XMGray3,
|
TextAlignment = TextAlignment.CenterLeft,
|
TextSize = 12,
|
Text = Language.StringByID(R.MyInternationalizationString.DataCorrectionTip),
|
};
|
bottomFrameLayout.AddChidren(btnText);
|
|
btnFinifh = new Button()
|
{
|
Width = Application.GetRealWidth(907),
|
Height = Application.GetRealHeight(127),
|
Y = Application.GetRealHeight(1426 + 58 + 12),
|
Gravity = Gravity.CenterHorizontal,
|
Radius = (uint)Application.GetRealHeight(127) / 2,
|
TextID = R.MyInternationalizationString.Save,
|
BackgroundColor = Shared.Common.ZigbeeColor.Current.XMBlack,
|
TextColor = Shared.Common.ZigbeeColor.Current.XMWhite,
|
IsBold = true,
|
TextSize = 16,
|
};
|
bodyFrameLayout.AddChidren(btnFinifh);
|
btnFinifh.MouseUpEventHandler += (sender, e) =>
|
{
|
SaveTarget();
|
};
|
|
bottomFrameLayout.Width = temperatureAttentionPic.Width + Application.GetRealWidth(10) + btnText.GetTextWidth();
|
bottomFrameLayout.Gravity = Gravity.CenterHorizontal;
|
}
|
#endregion
|
|
#region ■ 保存_______________________
|
/// <summary>
|
/// 保存
|
/// </summary>
|
/// <param name="curControlDev"></param>
|
void SaveTarget()
|
{
|
System.Threading.Tasks.Task.Run(async () =>
|
{
|
try
|
{
|
if (string.IsNullOrEmpty(invalidText1) )
|
{
|
Application.RunOnMainThread(() =>
|
{
|
new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.TNumTip), Direction = AMPopTipDirection.None, CloseTime = 1 }.Show(Common.CommonPage.Instance);
|
});
|
return;
|
}
|
if ( string.IsNullOrEmpty(invalidText2))
|
{
|
Application.RunOnMainThread(() =>
|
{
|
new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.HNumTip), Direction = AMPopTipDirection.None, CloseTime = 1 }.Show(Common.CommonPage.Instance);
|
});
|
return;
|
}
|
Application.RunOnMainThread(() =>
|
{
|
CommonPage.Loading.Start();
|
});
|
this.ShowProgressBar();
|
bool result = false;
|
int direction = 0;
|
double sendValue = 0;
|
//温度
|
sendValue = correctTValue;
|
if (correctTValue > 0)
|
{
|
direction = 1;
|
}
|
else if (correctTValue < 0)
|
{
|
direction = 2;
|
sendValue = System.Math.Abs(correctTValue);
|
}
|
|
result = await HdlDevicePanelLogic.Current.CorrectTemperature(device, sendValue, direction, 0);
|
if (result == false)
|
{
|
Application.RunOnMainThread(() =>
|
{
|
CommonPage.Loading.Hide();
|
});
|
return;
|
}
|
//湿度
|
direction = 0;
|
sendValue = correctHValue;
|
if (correctHValue > 0)
|
{
|
direction = 1;
|
}
|
else if (correctHValue < 0)
|
{
|
direction = 2;
|
sendValue = (-1) * correctHValue;
|
}
|
result = await HdlDevicePanelLogic.Current.CorrectTemperature(device, sendValue, direction, 1);
|
if (result == false)
|
{
|
Application.RunOnMainThread(() =>
|
{
|
CommonPage.Loading.Hide();
|
});
|
return;
|
}
|
Application.RunOnMainThread(() =>
|
{
|
new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.SetSuccessXm), Direction = AMPopTipDirection.None, CloseTime = 1 }.Show(Common.CommonPage.Instance);
|
CommonPage.Loading.Hide();
|
});
|
}
|
catch { }
|
});
|
}
|
#endregion
|
}
|
}
|