init - 初始化仓库

master
wenjy 9 months ago
parent b8f586a68e
commit 524ad14e75

@ -0,0 +1,145 @@
using SlnMesnac.LabelPrint.BarTender;
using SlnMesnac.LabelPrint.Common;
using SlnMesnac.LabelPrint.Log4net;
using SlnMesnac.LabelPrint.TaskQueue;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace SlnMesnac.LabelPrint.Timer
{
public class PrintTimer
{
private readonly LogHelper logHelper = LogHelper.Instance;
private readonly TaskHelper taskHelper = TaskHelper.Instance;
private readonly PrintManager printManager = PrintManager.Instance;
private readonly JsonChange jsonChange = JsonChange.Instance;
private System.Timers.Timer timer = new System.Timers.Timer(2000);
/// <summary>
/// 日志刷新
/// </summary>
/// <param name="massage"></param>
public delegate void LogRefresh(string massage);
public event LogRefresh LogRefreshEvent;
#region 单例实现
private static readonly Lazy<PrintTimer> lazy = new Lazy<PrintTimer>(() => new PrintTimer());
public static PrintTimer Instance
{
get
{
return lazy.Value;
}
}
#endregion
private PrintTimer() { }
/// <summary>
/// 开启自动打印
/// </summary>
/// <returns></returns>
public bool StartPrint()
{
bool result = false;
try
{
if (!timer.Enabled)
{
timer.Elapsed += new System.Timers.ElapsedEventHandler(ReadRfidByTimer);
timer.AutoReset = true;
timer.Enabled = false;
timer.Start();
this.PrintMessageToListBox("开启定时任务自动执行标签打印");
}
result = true;
}catch(Exception ex)
{
logHelper.Error("自动打印定时任务启动异常", ex);
this.PrintMessageToListBox($"自动打印定时任务启动异常:{ex.Message}");
}
return result;
}
private void ReadRfidByTimer(object source, System.Timers.ElapsedEventArgs e)
{
try
{
var info = taskHelper.GetTask();
if (info == null)
{
this.PrintMessageToListBox("未获取到需要打印的任务");
}
else
{
this.PrintMessageToListBox($"开始打印标签信息:{jsonChange.ModeToJson(info)}");
Thread.Sleep(200);
if (info.column_A == null)
{
this.PrintMessageToListBox($"{info.productType}打印任务执行失败A列数据为空");
return;
}
var printResult = printManager.Print(info);
if (printResult)
{
this.PrintMessageToListBox($"{info.productType}打印{info.column_A.ToString()};打印成功");
}
else
{
this.PrintMessageToListBox($"{info.column_A.ToString()};打印失败");
}
taskHelper.RemoveTask(info);
}
}catch(Exception ex)
{
logHelper.Error("自动打印任务执行异常", ex);
this.PrintMessageToListBox($"自动打印任务执行异常:{ex.Message}");
}
}
/// <summary>
/// 停止自动打印
/// </summary>
/// <returns></returns>
public bool StopPrint()
{
bool result = false;
try
{
this.PrintMessageToListBox("停止自动打印,并释放定时任务");
if (timer.Enabled)
{
timer.Stop();
timer.Close();
timer.Dispose();
timer = new System.Timers.Timer(2000);
}
result = true;
}
catch (Exception ex)
{
logHelper.Error("自动打印定时任务停止异常", ex);
this.PrintMessageToListBox($"自动打印定时任务停止异常:{ex.Message}");
}
return result;
}
/// <summary>
/// 日志打印
/// </summary>
/// <param name="message"></param>
private void PrintMessageToListBox(string message)
{
LogRefreshEvent?.Invoke(message);
}
}
}

@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// 有关程序集的一般信息由以下
// 控制。更改这些特性值可修改
// 与程序集关联的信息。
[assembly: AssemblyTitle("SlnMesnac.LabelPrint.Timer")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("SlnMesnac.LabelPrint.Timer")]
[assembly: AssemblyCopyright("Copyright © 2023")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// 将 ComVisible 设置为 false 会使此程序集中的类型
//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型
//请将此类型的 ComVisible 特性设置为 true。
[assembly: ComVisible(false)]
// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
[assembly: Guid("7e94f635-c22c-4b38-94ec-6f21842e1333")]
// 程序集的版本信息由下列四个值组成:
//
// 主版本
// 次版本
// 生成号
// 修订号
//
//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值
//通过使用 "*",如下所示:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

@ -0,0 +1,74 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{7E94F635-C22C-4B38-94EC-6F21842E1333}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>SlnMesnac.LabelPrint.Timer</RootNamespace>
<AssemblyName>SlnMesnac.LabelPrint.Timer</AssemblyName>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<PlatformTarget>x64</PlatformTarget>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="PrintTimer.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<WCFMetadata Include="Connected Services\" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\SlnMesnac.LabelPrint.BarTender\SlnMesnac.LabelPrint.BarTender.csproj">
<Project>{6a110611-3f4c-46c2-a981-23a0145b1e9f}</Project>
<Name>SlnMesnac.LabelPrint.BarTender</Name>
</ProjectReference>
<ProjectReference Include="..\SlnMesnac.LabelPrint.Common\SlnMesnac.LabelPrint.Common.csproj">
<Project>{7232269d-60af-45f0-b614-8f9c4061c529}</Project>
<Name>SlnMesnac.LabelPrint.Common</Name>
</ProjectReference>
<ProjectReference Include="..\SlnMesnac.LabelPrint.Log4net\SlnMesnac.LabelPrint.Log4net.csproj">
<Project>{fd6aa76e-79b1-4a0c-9cea-6ce09ccbdf9d}</Project>
<Name>SlnMesnac.LabelPrint.Log4net</Name>
</ProjectReference>
<ProjectReference Include="..\SlnMesnac.LabelPrint.Model\SlnMesnac.LabelPrint.Model.csproj">
<Project>{B68E5B08-F3E3-4AC0-A6ED-C31646956A0C}</Project>
<Name>SlnMesnac.LabelPrint.Model</Name>
</ProjectReference>
<ProjectReference Include="..\SlnMesnac.LabelPrint.TaskQueue\SlnMesnac.LabelPrint.TaskQueue.csproj">
<Project>{44b60510-5d95-4c48-949b-973b9b29dba6}</Project>
<Name>SlnMesnac.LabelPrint.TaskQueue</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

@ -17,6 +17,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SlnMesnac.LabelPrint.Log4ne
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SlnMesnac.LabelPrint.TaskQueue", "SlnMesnac.LabelPrint.TaskQueue\SlnMesnac.LabelPrint.TaskQueue.csproj", "{44B60510-5D95-4C48-949B-973B9B29DBA6}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SlnMesnac.LabelPrint.Timer", "SlnMesnac.LabelPrint.Timer\SlnMesnac.LabelPrint.Timer.csproj", "{7E94F635-C22C-4B38-94EC-6F21842E1333}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -51,6 +53,10 @@ Global
{44B60510-5D95-4C48-949B-973B9B29DBA6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{44B60510-5D95-4C48-949B-973B9B29DBA6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{44B60510-5D95-4C48-949B-973B9B29DBA6}.Release|Any CPU.Build.0 = Release|Any CPU
{7E94F635-C22C-4B38-94EC-6F21842E1333}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7E94F635-C22C-4B38-94EC-6F21842E1333}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7E94F635-C22C-4B38-94EC-6F21842E1333}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7E94F635-C22C-4B38-94EC-6F21842E1333}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

@ -22,9 +22,10 @@
<DropShadowEffect Color="Gray" ShadowDepth="0" BlurRadius="5" Opacity="0.3" Direction="0"></DropShadowEffect>
</Border.Effect>
<StackPanel VerticalAlignment="Center" HorizontalAlignment="Left" Orientation="Horizontal">
<Button Content="导入文件" x:Name="instoreInfo" Command="{Binding ImportFilesCommand}" Style="{StaticResource BUTTON_AGREE}" Width="100" Height="30" Background="#007DFA" BorderBrush="#007DFA" Margin="10,0,10,0"/>
<Button Content="开始打印" x:Name="outstoreInfo" Command="{Binding StartPrintCommand}" Style="{StaticResource BUTTON_AGREE}" Width="100" Height="30" Background="#009900" BorderBrush="#009900" Margin="0,0,10,0"/>
<Button Content="停止打印" x:Name="taskInfo" Command="{Binding StopPrintCommand}" Style="{StaticResource BUTTON_AGREE}" Width="100" Height="30" Background="#FF0033" BorderBrush="#FF0033" Margin="0,0,10,0"/>
<Button Content="导入文件" Command="{Binding ImportFilesCommand}" Style="{StaticResource BUTTON_AGREE}" Width="100" Height="30" Background="#007DFA" BorderBrush="#007DFA" Margin="10,0,10,0"/>
<Button Content="手动执行" Command="{Binding ManualExecutionCommand}" Style="{StaticResource BUTTON_AGREE}" Width="100" Height="30" Background="#CC9900" BorderBrush="#CC9900" Margin="0,0,10,0"/>
<Button Content="开始打印" Command="{Binding StartPrintCommand}" Style="{StaticResource BUTTON_AGREE}" Width="100" Height="30" Background="#009900" BorderBrush="#009900" Margin="0,0,10,0"/>
<Button Content="停止打印" Command="{Binding StopPrintCommand}" Style="{StaticResource BUTTON_AGREE}" Width="100" Height="30" Background="#FF0033" BorderBrush="#FF0033" Margin="0,0,10,0"/>
</StackPanel>
</Border>
<Border Grid.Row="1" BorderThickness="2" CornerRadius="5" Background="White" Margin="5">

@ -143,6 +143,10 @@
<Project>{44B60510-5D95-4C48-949B-973B9B29DBA6}</Project>
<Name>SlnMesnac.LabelPrint.TaskQueue</Name>
</ProjectReference>
<ProjectReference Include="..\SlnMesnac.LabelPrint.Timer\SlnMesnac.LabelPrint.Timer.csproj">
<Project>{7E94F635-C22C-4B38-94EC-6F21842E1333}</Project>
<Name>SlnMesnac.LabelPrint.Timer</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Resource Include="templates\icon\Icon.png" />

@ -8,6 +8,7 @@ using SlnMesnac.LabelPrint.FileOperate;
using SlnMesnac.LabelPrint.Log4net;
using SlnMesnac.LabelPrint.Model;
using SlnMesnac.LabelPrint.TaskQueue;
using SlnMesnac.LabelPrint.Timer;
using System;
using System.Collections;
using System.Collections.Generic;
@ -24,6 +25,7 @@ namespace SlnMesnac.LabelPrint.viewModel
private readonly TaskHelper taskHelper = TaskHelper.Instance;
private readonly JsonChange jsonChange = JsonChange.Instance;
private readonly PrintManager printManager = PrintManager.Instance;
private readonly PrintTimer printTimer = PrintTimer.Instance;
private ObservableCollection<dynamic> listItems = new ObservableCollection<dynamic>();
private ObservableCollection<BaseLabelInfo> labelItems = new ObservableCollection<BaseLabelInfo>();
#region 参数定义
@ -56,6 +58,11 @@ namespace SlnMesnac.LabelPrint.viewModel
/// </summary>
public RelayCommand ImportFilesCommand { get; set; }
/// <summary>
/// 手动执行
/// </summary>
public RelayCommand ManualExecutionCommand { get; set; }
/// <summary>
/// 开始打印
/// </summary>
@ -73,7 +80,9 @@ namespace SlnMesnac.LabelPrint.viewModel
try
{
taskHelper.ClearLabelInfoDataGridEvent += ClearLabelInfoDataGrid;
printTimer.LogRefreshEvent += PrintMessageToListBox;
ImportFilesCommand = new RelayCommand(ImportFile);
ManualExecutionCommand = new RelayCommand(ManualExecution);
StartPrintCommand = new RelayCommand(StartPrint);
StopPrintCommand = new RelayCommand(StopPrint);
}catch(Exception ex)
@ -119,18 +128,19 @@ namespace SlnMesnac.LabelPrint.viewModel
}
/// <summary>
/// 开始打印事件实现
/// 手动打印
/// </summary>
private void StartPrint()
private void ManualExecution()
{
var info = taskHelper.GetTask();
if(info == null)
if (info == null)
{
this.PrintMessageToListBox("未获取到需要打印的任务");
}
else
{
this.PrintMessageToListBox($"开始打印标签信息:{jsonChange.ModeToJson(info)}");
Thread.Sleep(500);
if (info.column_A == null)
{
this.PrintMessageToListBox($"{info.productType}打印任务执行失败A列数据为空");
@ -145,10 +155,17 @@ namespace SlnMesnac.LabelPrint.viewModel
{
this.PrintMessageToListBox($"{info.column_A.ToString()};打印失败");
}
taskHelper.RemoveTask(info);
}
}
/// <summary>
/// 开始打印事件实现
/// </summary>
private void StartPrint()
{
printTimer.StartPrint();
}
/// <summary>
@ -156,8 +173,7 @@ namespace SlnMesnac.LabelPrint.viewModel
/// </summary>
private void StopPrint()
{
this.PrintMessageToListBox("停止打印事件实现");
printTimer.StopPrint();
}
/// <summary>
@ -201,15 +217,18 @@ namespace SlnMesnac.LabelPrint.viewModel
private void PrintMessageToListBox(string message)
{
try
lock (string.Empty)
{
listItems.Add($"{DateTime.Now.ToString("HH:mm:ss")}==>{message}");
try
{
listItems.Add($"{DateTime.Now.ToString("HH:mm:ss")}==>{message}");
LogInfoListBox = listItems.OrderByDescending(x => x);
}
catch (Exception ex)
{
logHelper.Error("日志数据绑定异常", ex);
LogInfoListBox = listItems.OrderByDescending(x => x);
}
catch (Exception ex)
{
logHelper.Error("日志数据绑定异常", ex);
}
}
}
}

Loading…
Cancel
Save