Commit 986ed41d by zxw

Merge branch 'feature/充电台新增时间同步功能' into develop

parents 3d36b9c8 9d6d4ed2
......@@ -126,6 +126,61 @@ namespace LiteChannel.Commons
}
/// <summary>
/// 与服务器同步时间
/// </summary>
/// <returns></returns>
public static bool SetLocalTime()
{
try
{
var json = HttpGet(LiteCaChe.SysConfig.DomainUrl + Config.GetServerime);
if (string.IsNullOrEmpty(json))
{
Log.WorkLog("服务器时间获取失败", "获取失败");
return default;
}
else
{
var res_data = JsonConvert.DeserializeObject<respone<DateTime>>(json);
if (res_data == null || res_data.code != 10000)
{
Log.WorkLog("服务器时间获取失败", "获取失败");
return default;
}
else
{
Log.WorkLog("服务器时间获取成功", "获取成功");
if (res_data.data != null && res_data.data != default)
{
SYSTEMTIME _time = new SYSTEMTIME();
_time.FromDateTime(res_data.data);
var res = Win32API.SetLocalTime(ref _time);
if (res)
{
Log.WorkLog("时间同步成功", "同步成功");
}
else
{
Log.WorkLog($"时间同步失败,时间:{res_data.data.ToString("yyyy-MM-dd HH:mm:ss")}", "同步失败");
}
return res;
}
else
{
return false;
}
}
}
}
catch (Exception ex)
{
Log.ErrorLog(ex.ToString());
return false;
}
}
/// <summary>
/// 获取物资信息
/// </summary>
/// <returns></returns>
......
using System;
using System.Runtime.InteropServices;
namespace LiteChannel.Commons
{
public class Win32API
{
[DllImport("Kernel32.dll")]
public static extern bool SetLocalTime(ref SYSTEMTIME Time);
[DllImport("Kernel32.dll")]
public static extern void GetLocalTime(ref SYSTEMTIME Time);
}
/// <summary>
///
/// </summary>
public struct SYSTEMTIME
{
public ushort wYear;
public ushort wMonth;
public ushort wDayOfWeek;
public ushort wDay;
public ushort wHour;
public ushort wMinute;
public ushort wSecond;
public ushort wMilliseconds;
/// <summary>
/// 从System.DateTime转换。
/// </summary>
/// <param name="time">System.DateTime类型的时间。</param>
public void FromDateTime(DateTime time)
{
wYear = (ushort)time.Year;
wMonth = (ushort)time.Month;
wDayOfWeek = (ushort)time.DayOfWeek;
wDay = (ushort)time.Day;
wHour = (ushort)time.Hour;
wMinute = (ushort)time.Minute;
wSecond = (ushort)time.Second;
wMilliseconds = (ushort)time.Millisecond;
}
/// <summary>
/// 转换为System.DateTime类型。
/// </summary>
/// <returns></returns>
public DateTime ToDateTime()
{
return new DateTime(wYear, wMonth, wDay, wHour, wMinute, wSecond, wMilliseconds);
}
/// <summary>
/// 静态方法。转换为System.DateTime类型。
/// </summary>
/// <param name="time">SYSTEMTIME类型的时间。</param>
/// <returns></returns>
public static DateTime ToDateTime(SYSTEMTIME time)
{
return time.ToDateTime();
}
}
}
......@@ -101,6 +101,7 @@ namespace LiteChannel
public const string GetAllInventoryList = "/api/Inventory/GetAllInventoryList";
public const string AddAndApprovalBorrowOrder = "/api/Borrow/AddAndApprovalBorrowOrder";
public const string AddAndApprovalBorrowJYOrder = "/api/Borrow/AddAndApprovalBorrowJYOrder";
public const string GetServerime = "/api/ChannelCfg/GetServerTime";
public Config()
{
......
......@@ -126,6 +126,7 @@
<SubType>Designer</SubType>
</ApplicationDefinition>
<Compile Include="Commons\ReaderHelper.cs" />
<Compile Include="Commons\Win32API.cs" />
<Compile Include="SelectPoliceWindow.xaml.cs">
<DependentUpon>SelectPoliceWindow.xaml</DependentUpon>
</Compile>
......
......@@ -114,7 +114,8 @@ namespace LiteChannel
});
}
//设置系统时间
HttpHelper.SetLocalTime();
}
private void MainWindowLoaded(object sender, RoutedEventArgs e)
......@@ -152,7 +153,7 @@ namespace LiteChannel
if (!IsLoaded)
return;
cbo_warehouse.ItemsSource = StoreList.Where(t => t.name.Contains(e.Text));
}
private void cbo_warehouse_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
......
......@@ -51,5 +51,5 @@ using System.Windows;
//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值
//通过使用 "*",如下所示:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.2.14.01030")]
[assembly: AssemblyFileVersion("1.2.14.01030")]
[assembly: AssemblyVersion("1.2.15.03080")]
[assembly: AssemblyFileVersion("1.2.15.03080")]
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论