Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 25 additions & 5 deletions Barcode Writer/1D/Code128.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Barcodes
/// </summary>
public class Code128 : BarcodeBase
{
private const int STOP = 106;
private readonly int STOP = Code128Helper.STOP;
protected int AiMarker = 156;

protected override void Init()
Expand Down Expand Up @@ -172,7 +172,7 @@ private Pattern ParseCode(string value)

protected override string ParseText(string value, CodedValueCollection codes)
{
char variant = Code128Helper.StartVariantB;
char variant = Code128Helper.CODEB;
int i = 0;
bool shifted = false;

Expand Down Expand Up @@ -373,8 +373,28 @@ protected string AutoFormat(string value)
}
else
{
v = Code128Helper.CODEB;
s.Append(Code128Helper.StartVariantB);
switch (value[0])
{
case Code128Helper.StartVariantA:
v = Code128Helper.CODEA;
s.Append(Code128Helper.StartVariantA);
++i;
break;
case Code128Helper.StartVariantC:
v = Code128Helper.CODEC;
s.Append(Code128Helper.StartVariantC);
++i;
break;
case Code128Helper.StartVariantB:
v = Code128Helper.CODEB;
s.Append(Code128Helper.StartVariantB);
++i;
break;
default:
v = Code128Helper.CODEB;
s.Append(Code128Helper.StartVariantB);
break;
}
}

bool switched = false;
Expand Down Expand Up @@ -416,7 +436,7 @@ protected string AutoFormat(string value)

s.Append(value[i]);
i++;
if (v == Code128Helper.CODEC)
if (i < value.Length && v == Code128Helper.CODEC)
{
s.Append(value[i]);
i++;
Expand Down
5 changes: 5 additions & 0 deletions Barcode Writer/1D/Code128Helper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,10 @@ public static class Code128Helper
/// Shifts the next value between A & B
/// </summary>
public const char SHIFT = (char)148;

/// <summary>
/// Stop character
/// </summary>
public const int STOP = 106;
}
}
54 changes: 47 additions & 7 deletions Barcode Writer/1D/EAN128.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,55 @@ public Bitmap Generate(GS1.GS1Builder value, BarcodeSettings settings)

protected override string ParseText(string value, CodedValueCollection codes)
{
value = base.ParseText(value, codes);
if (_Value == null)
{
return base.ParseText(value, codes);
}
else
{
if (_Value.ToString() != value)
base.ParseText(value, codes);
else
{
int i = 0;
foreach(var element_string in _Value.CalculateElementStrings())
{
var cds = new CodedValueCollection();
if (!element_string.EndsWith(char.ToString(Code128Helper.FNC1)))
{
base.ParseText(element_string, cds);
cds.RemoveAt(cds.Count - 1);
}
else
{
base.ParseText(element_string.Substring(0, element_string.Length - 1), cds);
cds.RemoveAt(cds.Count - 1);
cds.Add(Code128Helper.FNC1 - 50);
}

if (_Value != null)
{
value = _Value.ToDisplayString();
_Value = null;
}
if (i == 0)
cds.Insert(1, Code128Helper.FNC1 - 50);
else if (codes[0] == cds[0])
cds.RemoveAt(0);
else
{
var r = cds[0];
cds.RemoveAt(0);
var ai = _Value.AICollection[i].ToString("{0:00}");
cds.Insert(ai.Length, r);
}

codes.AddRange(cds);
++i;
}
codes.Add(Code128Helper.STOP);
}

var ret = _Value.ToDisplayString();
_Value = null;
return ret;
}

return value;
}

//public string CreateEAN128(int aiCode, string value)
Expand Down
84 changes: 74 additions & 10 deletions Barcode Writer/GS1/GS1Builder.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;

namespace Barcodes.GS1
{
public class GS1Builder
public class GS1Builder
{
#region AI Constants

Expand All @@ -29,6 +30,7 @@ public class GS1Builder
public const int ReferenceToSourceEntity = 251;
public const int GDTI = 253;
public const int GLNExtension = 254;
public const int GlobalCouponNumber = 255;
public const int CountofItems = 30;
public const int ProductNetWeightKg = 310;
public const int ProductLengthMeters = 311;
Expand Down Expand Up @@ -109,6 +111,7 @@ public class GS1Builder
public const int UNCutClassification = 7002;
public const int ExpirationDateTime = 7003;
public const int ActivePotency = 7004;
public const int ProcessorApproval = 703;
public const int RollProducts = 8001;
public const int CellularMobileID = 8002;
public const int GRAI = 8003;
Expand All @@ -123,6 +126,7 @@ public class GS1Builder
public const int CouponExtendedCodeEndofOffer = 8101;
public const int CouponExtendedCode0 = 8102;
public const int CouponCodeIDNorthAmerica = 8110;
public const int ExtendedPackagingURL = 8200;
public const int TradingPartners = 90;
public const int InternalCompanyCodes1 = 91;
public const int InternalCompanyCodes2 = 92;
Expand Down Expand Up @@ -166,6 +170,56 @@ public GS1Builder(char fnc1)
FNC1 = fnc1;
}

private bool IsVariable(int ai)
{
return ai == BatchNumbers ||
ai == SerialNumber ||
ai == HIBCCQuantity ||
ai == SecondaryDataField ||
ai == LotNumber ||
ai == AdditionalItemIdentification ||
ai == CustomerPartNumber ||
ai == MadeToOrderVariationNumber ||
ai == SecondSerialNumber ||
ai == ReferenceToSourceEntity ||
ai == GDTI ||
ai == GLNExtension ||
ai == GlobalCouponNumber ||
ai == CountofItems ||
ai == CountofTradeItems ||
ai == AmountPayable ||
ai == AmountPayableISO ||
ai == AmountPayableArea ||
ai == AmountPayableAreaISO ||
ai == CustomerPurchaseOrderNumber ||
ai == GINC ||
ai == RoutingCode ||
ai == ShipToPostalCode ||
ai == ShipToPostalCodeISO ||
ai == CountryOfInitialProcessing ||
ai == UNCutClassification ||
ai == ActivePotency ||
ai == ProcessorApproval ||
ai == CellularMobileID ||
ai == GRAI ||
ai == GIAI ||
ai == IBAN ||
ai == ProductionDateTime ||
ai == PaymentSlipReference ||
ai == CouponCodeIDNorthAmerica ||
ai == ExtendedPackagingURL ||
ai == TradingPartners ||
ai == InternalCompanyCodes1 ||
ai == InternalCompanyCodes2 ||
ai == InternalCompanyCodes3 ||
ai == InternalCompanyCodes4 ||
ai == InternalCompanyCodes5 ||
ai == InternalCompanyCoeds6 ||
ai == InternalCompanyCodes7 ||
ai == InternalCompanyCodes8 ||
ai == InternalCompanyCodes9;
}

public void Add(int ai, string value)
{
Validate(ai, value);
Expand Down Expand Up @@ -413,14 +467,12 @@ public override string ToString()
{
StringBuilder sb = new StringBuilder();

for (int i = 0; i < _Ais.Count; i++)
{
sb.Append(FNC1);
sb.Append(_Ais[i]);
sb.Append(_Values[i]);
}
sb.Append(FNC1);
CalculateElementStrings()
.ToList()
.ForEach((v) => sb.Append(v));

return sb.ToString();
return sb.ToString();
}

public string ToString(char fnc1)
Expand All @@ -435,11 +487,23 @@ public string ToDisplayString()

for (int i = 0; i < _Ais.Count; i++)
{
sb.AppendFormat("({0})", _Ais[i]);
sb.AppendFormat("({0:00})", _Ais[i]);
sb.Append(_Values[i]);
}

return sb.ToString();
}
}
public IEnumerable<String> CalculateElementStrings()
{
for (int i = 0; i < _Ais.Count; i++)
{
StringBuilder sb = new StringBuilder();
sb.AppendFormat("{0:00}", _Ais[i]);
sb.Append(_Values[i]);
if (IsVariable(_Ais[i]))
sb.Append(FNC1);
yield return sb.ToString();
}
}
}
}
98 changes: 98 additions & 0 deletions BarcodeWriterTests/BarcodeWriterTests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{D694DBF2-F65C-4C92-9ACC-629A40214D7D}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>BarcodeWriterTests</RootNamespace>
<AssemblyName>BarcodeWriterTests</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
<ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages</ReferencePath>
<IsCodedUITest>False</IsCodedUITest>
<TestProjectType>UnitTest</TestProjectType>
<TargetFrameworkProfile />
</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>
<Prefer32Bit>false</Prefer32Bit>
</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>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Drawing" />
</ItemGroup>
<Choose>
<When Condition="('$(VisualStudioVersion)' == '10.0' or '$(VisualStudioVersion)' == '') and '$(TargetFrameworkVersion)' == 'v3.5'">
<ItemGroup>
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
</ItemGroup>
</When>
<Otherwise>
<ItemGroup>
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework">
<Private>False</Private>
</Reference>
</ItemGroup>
</Otherwise>
</Choose>
<ItemGroup>
<Compile Include="GS1\GS1BuilderTest.cs" />
<Compile Include="Helpers\ImageHelper.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="EAN128Test.cs" />
<Compile Include="Code128Test.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Barcode Writer\Barcode Writer.csproj">
<Project>{7130d5a2-8818-4300-9d1a-80c929059a2d}</Project>
<Name>Barcode Writer</Name>
</ProjectReference>
</ItemGroup>
<Choose>
<When Condition="'$(VisualStudioVersion)' == '10.0' And '$(IsCodedUITest)' == 'True'">
<ItemGroup>
<Reference Include="Microsoft.VisualStudio.QualityTools.CodedUITestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<Private>False</Private>
</Reference>
<Reference Include="Microsoft.VisualStudio.TestTools.UITest.Common, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<Private>False</Private>
</Reference>
<Reference Include="Microsoft.VisualStudio.TestTools.UITest.Extension, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<Private>False</Private>
</Reference>
<Reference Include="Microsoft.VisualStudio.TestTools.UITesting, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<Private>False</Private>
</Reference>
</ItemGroup>
</When>
</Choose>
<Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
Loading