Label print: box & test labelsas api calls

This commit is contained in:
Stoyan Zlatev 2024-06-26 08:05:20 +02:00
parent 7ce0109618
commit 2c927aa46e
11 changed files with 469 additions and 14 deletions

View File

@ -59,21 +59,7 @@
var inspectionOrder = default(InspectionOrder);
var inspectionOrderRows = this.sql
.CreateCommand($@"
DECLARE @search INT = @{nameof(identorpono)};
DECLARE @identnr INT;
DECLARE @fertnr INT;
SELECT @identnr = [aap].[IdentNr]
, @fertnr = [aap].[FertigungsauftragNr]
FROM [AlleAuftragPositionen] AS [aap]
WHERE [aap].[FertigungsauftragNr] = @search
IF @identnr IS NULL
BEGIN
SELECT @identnr = [idn].[IdentNr]
FROM [Identnr] AS [idn]
WHERE [idn].[IdentNr] = @search
END
SELECT [d].[Id]
, [aap].[AuftragNr]

View File

@ -0,0 +1,85 @@
<?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>{E8FCD0A3-714D-4436-9A20-B098E6A5537D}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>LaaProduction.Console</RootNamespace>
<AssemblyName>LaaProduction.Console</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
<TargetFrameworkProfile />
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.IO, Version=2.6.10.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Bcl.1.1.10\lib\net40\System.IO.dll</HintPath>
</Reference>
<Reference Include="System.Net.Http, Version=2.2.29.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Net.Http.2.2.29\lib\net40\System.Net.Http.dll</HintPath>
</Reference>
<Reference Include="System.Net.Http.Extensions, Version=2.2.29.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Net.Http.2.2.29\lib\net40\System.Net.Http.Extensions.dll</HintPath>
</Reference>
<Reference Include="System.Net.Http.Primitives, Version=2.2.29.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Net.Http.2.2.29\lib\net40\System.Net.Http.Primitives.dll</HintPath>
</Reference>
<Reference Include="System.Net.Http.WebRequest, Version=2.2.29.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Net.Http.2.2.29\lib\net40\System.Net.Http.WebRequest.dll</HintPath>
</Reference>
<Reference Include="System.Runtime, Version=2.6.10.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Bcl.1.1.10\lib\net40\System.Runtime.dll</HintPath>
</Reference>
<Reference Include="System.Threading.Tasks, Version=2.6.10.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Bcl.1.1.10\lib\net40\System.Threading.Tasks.dll</HintPath>
</Reference>
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="app.config" />
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets" Condition="Exists('..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets'))" />
</Target>
</Project>

View File

@ -0,0 +1,28 @@
namespace LaaProduction.Console
{
using System;
using System.Collections.Generic;
using System.Net.Http;
public class Program
{
public static void Main(string[] args)
{
Console.ReadKey();
using (var request = new HttpRequestMessage(HttpMethod.Post, "http://localhost:57680/api.aspx?action=getlabel"))
{
request.Content = new FormUrlEncodedContent(new Dictionary<string, string>
{
{ "BUILD_INFO", "816232411982" }
});
using (var response = new HttpClient().SendAsync(request).Result)
{
Console.WriteLine(response.Content.ReadAsStringAsync().Result);
}
}
}
}
}

View File

@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("LaaProduction.Console")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("LaaProduction.Console")]
[assembly: AssemblyCopyright("Copyright © 2024")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("e8fcd0a3-714d-4436-9a20-b098e6a5537d")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

View File

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0" /></startup>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.2.29.0" newVersion="2.2.29.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Microsoft.Bcl" version="1.1.10" targetFramework="net40" />
<package id="Microsoft.Bcl.Build" version="1.0.21" targetFramework="net40" />
<package id="Microsoft.Net.Http" version="2.2.29" targetFramework="net40" />
</packages>

View File

@ -0,0 +1 @@
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="API.aspx.cs" Inherits="LaaProductionVFM.API" %>

View File

@ -0,0 +1,288 @@
namespace LaaProductionVFM
{
using System;
using System.Collections.Specialized;
using System.Configuration;
using System.IO;
using System.Linq;
using System.Net;
using System.Reflection;
using System.Text;
using System.Web.UI;
public partial class API : Page
{
protected void Page_Load(object sender, EventArgs e)
{
var actionString = this.Request.QueryString.Get("action");
if (!string.IsNullOrWhiteSpace(actionString))
{
var action = this.GetType()
.GetMethods(BindingFlags.Instance | BindingFlags.NonPublic)
.Where(method => method.Name.Equals(actionString, StringComparison.OrdinalIgnoreCase))
.FirstOrDefault();
if (action != null)
{
this.Response.Clear();
this.Response.ContentType = "application/json";
action.Invoke(this, null);
this.Response.Flush();
}
}
}
/*****************************************************************************************
*
* A new control variable @IMAGE_MODE allows you to dynamically change the configuration
* of the sentinel for the next print job.
* If set to 0, the sentinel prints a label. -
* If set to 1, the sentinel generates a preview image of the label but does not print it.
* If set to 2, the sentinel prints the label and generates a preview image of the label.
*
*****************************************************************************************/
protected void PrintTestLabel()
{
try
{
var form = this.FormData<TestLabel>();
var builder = new StringBuilder();
builder.AppendLine(string.Format("@JOB_NAME = \"testlabel_{0}\"", form.PcbId));
builder.AppendLine(string.Format("@PRINTER_NAME = \"{0}\"", Appsettings.TestLabelPrinter));
builder.AppendLine(string.Format("@LABEL_NAME = \"{0}\"", Appsettings.TestLabel));
builder.AppendLine(string.Format("@IMAGE_MODE = \"{0}\"", 0));
builder.AppendLine(string.Format("ORDERNO = \"{0}\"", form.Orderno));
builder.AppendLine(string.Format("POSNO = \"{0}\"", form.Posno));
builder.AppendLine(string.Format("TESTDATE = \"{0}\"", form.TestDate));
builder.AppendLine(string.Format("PARTNO = \"{0}\"", form.Partno));
builder.AppendLine(string.Format("DESCL1 = \"{0}\"", form.DescriptionL1));
builder.AppendLine(string.Format("DESCL2 = \"{0}\"", form.DescriptionL2));
builder.AppendLine(string.Format("CUSTSN = \"{0}\"", form.CustId));
builder.AppendLine(string.Format("REGSN = \"{0}\"", form.FactId));
builder.AppendLine(string.Format("QMAXGPM = \"{0}\"", form.QmaxGPM));
builder.AppendLine(string.Format("QMIDGPM = \"{0}\"", form.QmidGPM));
builder.AppendLine(string.Format("QMINGPM = \"{0}\"", form.QminGPM));
builder.AppendLine(string.Format("QMAXACC = \"{0}\"", form.QmaxACC));
builder.AppendLine(string.Format("QMIDACC = \"{0}\"", form.QmidACC));
builder.AppendLine(string.Format("QMINACC = \"{0}\"", form.QminACC));
if (!string.IsNullOrWhiteSpace(Appsettings.TestLabelTxt))
{
var testDataTxt = string.Format(Appsettings.TestLabelTxt, form.PcbId);
var testLabelContent = builder.ToString();
File.WriteAllText(testDataTxt, testLabelContent);
this.Response.StatusCode = (int)HttpStatusCode.OK;
}
else
{
this.Response.StatusCode = (int)HttpStatusCode.BadRequest;
}
}
catch (Exception e)
{
this.Response.StatusCode = (int)HttpStatusCode.InternalServerError;
this.Response.Write(e.ToString());
}
}
/*****************************************************************************************
*
* A new control variable @IMAGE_MODE allows you to dynamically change the configuration
* of the sentinel for the next print job.
* If set to 0, the sentinel prints a label. -
* If set to 1, the sentinel generates a preview image of the label but does not print it.
* If set to 2, the sentinel prints the label and generates a preview image of the label.
*
*****************************************************************************************/
protected void PrintBoxLabel()
{
try
{
var form = this.FormData<BoxLabel>();
var builder = new StringBuilder();
builder.AppendLine(string.Format("@JOB_NAME = \"boxlabel_{0}\"", form.CustId));
builder.AppendLine(string.Format("@PRINTER_NAME = \"{0}\"", Appsettings.BoxLabelPrinter));
builder.AppendLine(string.Format("@LABEL_NAME = \"{0}\"", Appsettings.BoxLabel));
builder.AppendLine(string.Format("@IMAGE_MODE = \"{0}\"", 0));
builder.AppendLine(string.Format("TITLE = \"{0}\"", form.Title));
builder.AppendLine(string.Format("DESCL1 = \"{0}\"", form.DescriptionL1));
builder.AppendLine(string.Format("DESCL2 = \"{0}\"", form.DescriptionL2));
builder.AppendLine(string.Format("PARTNO = \"{0}\"", form.Partno));
builder.AppendLine(string.Format("ORDERNO = \"{0}\"", form.Orderno));
builder.AppendLine(string.Format("CUSTSN = \"{0}\"", form.CustId));
builder.AppendLine(string.Format("BOXDATE = \"{0}\"", form.BoxDate));
builder.AppendLine(string.Format("BOXNO = \"{0}\"", form.Boxno));
builder.AppendLine(string.Format("QUANTITY = \"{0}\"", form.Quantity));
if (!string.IsNullOrWhiteSpace(Appsettings.BoxLabelTxt))
{
var boxDataTxt = string.Format(Appsettings.BoxLabelTxt, form.CustId);
var boxLabelContent = builder.ToString();
File.WriteAllText(boxDataTxt, boxLabelContent);
this.Response.StatusCode = (int)HttpStatusCode.OK;
}
else
{
this.Response.StatusCode = (int)HttpStatusCode.BadRequest;
}
}
catch (Exception e)
{
this.Response.StatusCode = (int)HttpStatusCode.InternalServerError;
this.Response.Write(e.ToString());
}
}
private T FormData<T>() where T : new()
{
var expectedResult = new T();
var properties = expectedResult
.GetType()
.GetProperties(BindingFlags.Public | BindingFlags.Instance)
.ToDictionary(x => x.Name.ToLower(), x => (Action<object, object>)x.SetValue);
var buffer = new Byte[this.Request.InputStream.Length];
var dataLength = this.Request.InputStream.Read(buffer, 0, buffer.Length);
var data = new Byte[dataLength];
Array.Copy(buffer, 0, data, 0, dataLength);
var content = Encoding.UTF8.GetString(data);
if (string.IsNullOrWhiteSpace(content))
{
return expectedResult;
}
content = content.Trim('"');
var parts = content.Split(new[] { ';', '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries);
foreach (var part in parts)
{
if (string.IsNullOrWhiteSpace(part))
{
continue;
}
var tokens = part.Split(new[] { '=' }, StringSplitOptions.RemoveEmptyEntries);
if (tokens.Length != 2)
{
continue;
}
var key = tokens[0];
var value = tokens[1];
if (string.IsNullOrWhiteSpace(key) || string.IsNullOrWhiteSpace(value))
{
continue;
}
key = key.ToLower().Trim();
value = value.Trim();
if (properties.ContainsKey(key))
{
properties[key](expectedResult, value);
}
}
return expectedResult;
}
public class TestLabel
{
public string PcbId { get; set; }
public string Orderno { get; set; }
public string Posno { get; set; }
public string TestDate { get; set; }
public string Partno { get; set; }
public string DescriptionL1 { get; set; }
public string DescriptionL2 { get; set; }
public string CustId { get; set; }
public string FactId { get; set; }
public string QmaxGPM { get; set; }
public string QmidGPM { get; set; }
public string QminGPM { get; set; }
public string QmaxACC { get; set; }
public string QmidACC { get; set; }
public string QminACC { get; set; }
}
public class BoxLabel
{
public string CustId { get; set; }
public string Title { get; set; }
public string DescriptionL1 { get; set; }
public string DescriptionL2 { get; set; }
public string Partno { get; set; }
public string Orderno { get; set; }
public string BoxDate { get; set; }
public string Boxno { get; set; }
public string Quantity { get; set; }
}
public class Appsettings
{
public const string ERROR_MSG = "ERROR_MSG";
private static readonly NameValueCollection appsettings
= ConfigurationManager.AppSettings;
public static readonly string SQLServer = ConfigurationManager
.ConnectionStrings["DefaultConnection"]
.ConnectionString;
public static readonly string BoxLabel = appsettings["BoxLabel"];
public static readonly string BoxLabelPrinter = appsettings["BoxLabelPrinter"];
public static readonly string BoxLabelTxt = appsettings["BoxLabelTxt"];
public static readonly string BoxLabelJpg = appsettings["BoxLabelJpg"];
public static readonly string TestLabel = appsettings["TestLabel"];
public static readonly string TestLabelPrinter = appsettings["TestLabelPrinter"];
public static readonly string TestLabelTxt = appsettings["TestLabelTxt"];
public static readonly string TestLabelJpg = appsettings["TestLabelJpg"];
public static readonly string CurrentDirectory = appsettings["CurrentDirectory"];
}
}
}

View File

@ -7,6 +7,7 @@
{
protected void Page_Load(object sender, EventArgs e)
{
}
}
}

View File

@ -24,6 +24,12 @@
<system.web>
<identity impersonate="false"/>
<customErrors mode="Off"/>
<webServices>
<protocols>
<add name="HttpGet"/>
<add name="HttpPost"/>
</protocols>
</webServices>
</system.web>
<appSettings>
<add key="BoxLabel" value="E:\omni\boxlabel.lab"/>

View File

@ -54,6 +54,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LaaProduction.Data.Omni", "
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LaaProduction.Data.Inspection", "Data\LaaProduction.Data.Inspection\LaaProduction.Data.Inspection.csproj", "{25BACE1B-1961-411A-8AC0-1375A1898F8F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LaaProduction.Console", "LaaProduction.Console\LaaProduction.Console.csproj", "{E8FCD0A3-714D-4436-9A20-B098E6A5537D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -116,6 +118,10 @@ Global
{25BACE1B-1961-411A-8AC0-1375A1898F8F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{25BACE1B-1961-411A-8AC0-1375A1898F8F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{25BACE1B-1961-411A-8AC0-1375A1898F8F}.Release|Any CPU.Build.0 = Release|Any CPU
{E8FCD0A3-714D-4436-9A20-B098E6A5537D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E8FCD0A3-714D-4436-9A20-B098E6A5537D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E8FCD0A3-714D-4436-9A20-B098E6A5537D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E8FCD0A3-714D-4436-9A20-B098E6A5537D}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE