Commit 12d783ae by zxw

init

parent 3d36b9c8
...@@ -126,6 +126,61 @@ namespace LiteChannel.Commons ...@@ -126,6 +126,61 @@ namespace LiteChannel.Commons
} }
/// <summary> /// <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> /// </summary>
/// <returns></returns> /// <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 ...@@ -101,6 +101,7 @@ namespace LiteChannel
public const string GetAllInventoryList = "/api/Inventory/GetAllInventoryList"; public const string GetAllInventoryList = "/api/Inventory/GetAllInventoryList";
public const string AddAndApprovalBorrowOrder = "/api/Borrow/AddAndApprovalBorrowOrder"; public const string AddAndApprovalBorrowOrder = "/api/Borrow/AddAndApprovalBorrowOrder";
public const string AddAndApprovalBorrowJYOrder = "/api/Borrow/AddAndApprovalBorrowJYOrder"; public const string AddAndApprovalBorrowJYOrder = "/api/Borrow/AddAndApprovalBorrowJYOrder";
public const string GetServerime = "/api/ChannelCfg/GetServerTime";
public Config() public Config()
{ {
......
...@@ -126,6 +126,7 @@ ...@@ -126,6 +126,7 @@
<SubType>Designer</SubType> <SubType>Designer</SubType>
</ApplicationDefinition> </ApplicationDefinition>
<Compile Include="Commons\ReaderHelper.cs" /> <Compile Include="Commons\ReaderHelper.cs" />
<Compile Include="Commons\Win32API.cs" />
<Compile Include="SelectPoliceWindow.xaml.cs"> <Compile Include="SelectPoliceWindow.xaml.cs">
<DependentUpon>SelectPoliceWindow.xaml</DependentUpon> <DependentUpon>SelectPoliceWindow.xaml</DependentUpon>
</Compile> </Compile>
......
...@@ -114,7 +114,8 @@ namespace LiteChannel ...@@ -114,7 +114,8 @@ namespace LiteChannel
}); });
} }
//设置系统时间
HttpHelper.SetLocalTime();
} }
private void MainWindowLoaded(object sender, RoutedEventArgs e) private void MainWindowLoaded(object sender, RoutedEventArgs e)
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论