Administrator 2 months ago
parent
commit
94d1fb6a5d
  1. 80
      Class/HttpServer.cs
  2. 4
      InfoChemicalStatistics.xaml
  3. 2
      InfoChemicalStatistics.xaml.cs
  4. 2
      InfoDetail.xaml
  5. 16
      InfoDetail.xaml.cs
  6. 3
      Models/DataSource.cs
  7. 8
      QueryDetail.xaml
  8. 8
      QueryDetail.xaml.cs

80
Class/HttpServer.cs

@ -40,52 +40,62 @@ namespace SunlightAggregationTerminal.Class
else else
{ {
await HttpClient(DataReceived.ServerIP); await HttpClient(DataReceived.ServerIP);
HttpTransmit("{\"Command\":\"Log\"}");
} }
} }
public static async Task HttpClient(string url) public static async Task HttpClient(string url)
{ {
var config = new TouchSocketConfig(); try
#region Http设置远程服务器地址
config.SetRemoteIPHost("http://" + url);
#endregion
#region Http客户端获取断线通知
config.ConfigurePlugins(a =>
{ {
//处理连接断开 var config = new TouchSocketConfig();
a.AddTcpClosedPlugin(async (c, e) => #region Http设置远程服务器地址
{ config.SetRemoteIPHost("http://" + url);
//MainThread.BeginInvokeOnMainThread(() => #endregion
// {
// Application.Current!.Windows[0].Page!.DisplayAlertAsync("", "客户端断开连接", "是"); #region Http客户端获取断线通知
// }); config.ConfigurePlugins(a =>
// await e.InvokeNext();
});
//自动重连
a.UseReconnection<TouchSocket.Http.HttpClient>(options =>
{ {
options.PollingInterval = TimeSpan.FromSeconds(3); //处理连接断开
a.AddTcpClosedPlugin(async (c, e) =>
{
//MainThread.BeginInvokeOnMainThread(() =>
// {
// Application.Current!.Windows[0].Page!.DisplayAlertAsync("", "客户端断开连接", "是");
// });
// await e.InvokeNext();
});
//自动重连
a.UseReconnection<TouchSocket.Http.HttpClient>(options =>
{
options.PollingInterval = TimeSpan.FromSeconds(3);
});
//处理连接
a.AddTcpConnectedPlugin(async (c, e) =>
{
await e.InvokeNext();
});
}); });
//处理连接 #endregion
a.AddTcpConnectedPlugin(async (c, e) =>
if (httpclient.Online)//是否重置客户端
{ {
await e.InvokeNext(); await httpclient.CloseAsync();
}); }
});
#endregion
if (httpclient.Online)//是否重置客户端 //配置config
await httpclient.SetupAsync(config);
//连接
await httpclient.ConnectAsync();
HttpTransmit("{\"Command\":\"Log\"}");
}
catch (Exception ex)
{ {
await httpclient.CloseAsync(); MainThread.BeginInvokeOnMainThread(() =>
{
Application.Current!.Windows[0].Page!.DisplayAlertAsync("网络错误", ex.Message.ToString(), "是");
});
} }
//配置config
await httpclient.SetupAsync(config);
//连接
await httpclient.ConnectAsync();
} }
/***发送信息处理***/ /***发送信息处理***/
@ -142,7 +152,7 @@ namespace SunlightAggregationTerminal.Class
} }
finally finally
{ {
Start(); //Start();
} }
} }

4
InfoChemicalStatistics.xaml

@ -28,10 +28,12 @@
FontSize="22" TextColor="Black"/> FontSize="22" TextColor="Black"/>
</HorizontalStackLayout> </HorizontalStackLayout>
<HorizontalStackLayout> <HorizontalStackLayout>
<Label Text="用量(kg): " FontAttributes="Bold" <Label Text="用量: " FontAttributes="Bold"
FontSize="22" TextColor="Black"/> FontSize="22" TextColor="Black"/>
<Label Text="{Binding TotalDispenseGrams}" FontAttributes="Bold" <Label Text="{Binding TotalDispenseGrams}" FontAttributes="Bold"
FontSize="22" TextColor="Black"/> FontSize="22" TextColor="Black"/>
<Label Text="Kg" FontAttributes="Bold"
FontSize="22" TextColor="Black"/>
</HorizontalStackLayout> </HorizontalStackLayout>
</VerticalStackLayout> </VerticalStackLayout>
</Border> </Border>

2
InfoChemicalStatistics.xaml.cs

@ -59,7 +59,7 @@ public partial class InfoChemicalStatistics : ContentPage
{ {
foreach (var item in data) foreach (var item in data)
{ {
item.TotalDispenseGrams = item.TotalDispenseGrams / 1000; item.TotalDispenseGrams = MathF.Round((float)item.TotalDispenseGrams! / 1000, 5);
ChemicalTotals.Add(item); ChemicalTotals.Add(item);
} }

2
InfoDetail.xaml

@ -136,7 +136,7 @@
<HorizontalStackLayout> <HorizontalStackLayout>
<Label Text="呼叫时间: " FontAttributes="Bold" <Label Text="呼叫时间: " FontAttributes="Bold"
FontSize="22" TextColor="Black"/> FontSize="22" TextColor="Black"/>
<Label Text="{Binding UsageTime}" FontAttributes="Bold" <Label Text="{Binding CallTime}" FontAttributes="Bold"
FontSize="22" TextColor="Black"/> FontSize="22" TextColor="Black"/>
</HorizontalStackLayout> </HorizontalStackLayout>
<HorizontalStackLayout> <HorizontalStackLayout>

16
InfoDetail.xaml.cs

@ -496,7 +496,13 @@ public class InfoMachineItem
} }
dyelotDetailsItem.DispenseStartTime = item.GetValue("DispenseStartTime").ToString()!.Replace("T", " "); dyelotDetailsItem.DispenseStartTime = item.GetValue("DispenseStartTime").ToString()!.Replace("T", " ");
dyelotDetailsItem.DispenseEndTime = item.GetValue("DispenseEndTime").ToString()!.Replace("T", " "); dyelotDetailsItem.DispenseEndTime = item.GetValue("DispenseEndTime").ToString()!.Replace("T", " ");
dyelotDetailsItem.UsageTime = item.GetValue("CallTime").ToString()!.Replace("T", " "); if (item!.TryGetValue("CallTime", out var _CallTime) && _CallTime != null)
{
if (DateTime.TryParse(_CallTime.ToString(), out DateTime dtc))
{
dyelotDetailsItem.CallTime = dtc.ToString("yyyy-MM-dd HH:mm:ss");
}
}
InfoDyelotHistoryItems.Add(dyelotDetailsItem); InfoDyelotHistoryItems.Add(dyelotDetailsItem);
} }
if (InfoDyelotHistoryItems.Count == 0) InfoDyelotHistoryItems.Add(new DyelotDetailsItem()); if (InfoDyelotHistoryItems.Count == 0) InfoDyelotHistoryItems.Add(new DyelotDetailsItem());
@ -569,7 +575,13 @@ public class InfoMachineItem
} }
dyelotDetailsItem.DispenseStartTime = item.GetValue("DispenseStartTime").ToString()!.Replace("T", " "); dyelotDetailsItem.DispenseStartTime = item.GetValue("DispenseStartTime").ToString()!.Replace("T", " ");
dyelotDetailsItem.DispenseEndTime = item.GetValue("DispenseEndTime").ToString()!.Replace("T", " "); dyelotDetailsItem.DispenseEndTime = item.GetValue("DispenseEndTime").ToString()!.Replace("T", " ");
dyelotDetailsItem.UsageTime = item.GetValue("CallTime").ToString()!.Replace("T", " "); if (item!.TryGetValue("CallTime", out var _CallTime) && _CallTime != null)
{
if (DateTime.TryParse(_CallTime.ToString(), out DateTime dtc))
{
dyelotDetailsItem.CallTime = dtc.ToString("yyyy-MM-dd HH:mm:ss");
}
}
InfoDyelotHistoryItems.Add(dyelotDetailsItem); InfoDyelotHistoryItems.Add(dyelotDetailsItem);
} }
if (InfoDyelotHistoryItems.Count == 0) InfoDyelotHistoryItems.Add(new DyelotDetailsItem()); if (InfoDyelotHistoryItems.Count == 0) InfoDyelotHistoryItems.Add(new DyelotDetailsItem());

3
Models/DataSource.cs

@ -78,7 +78,8 @@ namespace SunlightAggregationTerminal.Models
public string? DispenseTime { get; set; } public string? DispenseTime { get; set; }
public string? CallTime { get; set; } public string? CallTime { get; set; }
public string? UsageTime { get; set; } public string? UsageTime { get; set; }
public string? Tank { get; set; } public string? Tank { get; set; }
public object? PowderTargetTank { get; set; }
public double? DispenseGrams { get; set; } public double? DispenseGrams { get; set; }
public string DispenseGramsDisplay => DispenseGrams?.ToString("F2") ?? ""; public string DispenseGramsDisplay => DispenseGrams?.ToString("F2") ?? "";
public int? DispenseResult { get; set; } public int? DispenseResult { get; set; }

8
QueryDetail.xaml

@ -60,8 +60,6 @@
FontSize="22" TextColor="Black"/> FontSize="22" TextColor="Black"/>
<Label Text="{Binding StepNumber}" FontAttributes="Bold" <Label Text="{Binding StepNumber}" FontAttributes="Bold"
FontSize="22" TextColor="Black"/> FontSize="22" TextColor="Black"/>
<Label Text="{Binding Tank}" FontAttributes="Bold"
FontSize="22" TextColor="Black"/>
</HorizontalStackLayout> </HorizontalStackLayout>
<HorizontalStackLayout> <HorizontalStackLayout>
<Label Text="呼叫时间: " FontAttributes="Bold" <Label Text="呼叫时间: " FontAttributes="Bold"
@ -81,6 +79,12 @@
<Label Text="{Binding UsageTime}" FontAttributes="Bold" <Label Text="{Binding UsageTime}" FontAttributes="Bold"
FontSize="22" TextColor="Black"/> FontSize="22" TextColor="Black"/>
</HorizontalStackLayout> </HorizontalStackLayout>
<HorizontalStackLayout>
<Label Text="目标地址: " FontAttributes="Bold" FontSize="22" TextColor="Black"
IsVisible="{Binding Path=Tank, Converter={StaticResource StringToBoolConverter}}"/>
<Label Text="{Binding Tank}" FontAttributes="Bold" FontSize="22" TextColor="Black"
IsVisible="{Binding Path=Tank, Converter={StaticResource StringToBoolConverter}}"/>
</HorizontalStackLayout>
<HorizontalStackLayout> <HorizontalStackLayout>
<Label Text="溶解流程: " FontAttributes="Bold" FontSize="22" TextColor="Black" <Label Text="溶解流程: " FontAttributes="Bold" FontSize="22" TextColor="Black"
IsVisible="{Binding Path=Process, Converter={StaticResource StringToBoolConverter}}"/> IsVisible="{Binding Path=Process, Converter={StaticResource StringToBoolConverter}}"/>

8
QueryDetail.xaml.cs

@ -114,8 +114,12 @@ public partial class QueryDetail : ContentPage
item.UsageTime = $"{(int)(dte - dtr).TotalMinutes}:{(dte - dtr).Seconds:D2}"; item.UsageTime = $"{(int)(dte - dtr).TotalMinutes}:{(dte - dtr).Seconds:D2}";
} }
} }
if (DateTime.TryParse(item.CallTime, out DateTime dtc))
{
item.CallTime = dtc.ToString("yyyy-MM-dd HH:mm:ss");
}
if (item.ProductType == 1 && item.Process == null) item.Process = "未知"; if (item.ProductType == 1 && item.Process == null) item.Process = "未知";
if (item.Tank != null) item.Tank ="@" + item.Tank; if (item.ProductType == 3) item.Tank = item.PowderTargetTank.ToString();
//行信息 //行信息
QueryDetailDyelotDetailsItems.Add(item); QueryDetailDyelotDetailsItems.Add(item);
@ -127,7 +131,7 @@ public partial class QueryDetail : ContentPage
} }
} }
} }
catch (Exception) catch (Exception ex)
{ {
} }
} }

Loading…
Cancel
Save