Skip to content

Commit

Permalink
-
Browse files Browse the repository at this point in the history
  • Loading branch information
mass10 committed Jun 1, 2024
1 parent e3553c0 commit e880cf7
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 14 deletions.
50 changes: 48 additions & 2 deletions Application.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,28 @@ public Application()
/// <param name="conf"></param>
public void Run(ConfigurationManager conf)
{
if (conf.addressFiles.Count == 0)
{
MyLogger.Error("アドレス帳ファイルが指定されていません。");
return;
}

foreach (var filepath in conf.addressFiles)
{
// 印刷を実行します。
Print(filepath, conf.dryrun);
}
}

/// <summary>
/// 印刷を実行します。
/// </summary>
/// <param name="filepath">アドレス帳ファイル</param>
/// <param name="dryrun"></param>
private void Print(string filepath, bool dryrun)
{
MyLogger.Info("テンプレート [", filepath, "] を印字中...");

// ドキュメントオブジェクトを初期化
var document = new BrotherPrinterDocument();

Expand All @@ -48,54 +62,87 @@ private void Print(string filepath, bool dryrun)
{
var line = reader.ReadLine();
if (line == null)
{
// EOF
break;
}
if (line == "")
{
// 無視
continue;
}
if (line[0] == '#')
{
// 無視
continue;
}

// 行を分解
var fields = ParseAddressLine(line);
if (fields == null)
{
// 無視
MyLogger.Error("次の行は無視されました。[", line, "]");
continue;
}

if (dryrun)
{
// 印刷しない
continue;
}

// 印刷
MyLogger.Info("(印字中)");
document.Print(fields);
}
}
finally
{
MyLogger.Info("ドキュメントをクローズしています...");
document.Close();
}
}

/// <summary>
/// アドレス帳の行をパースします。
/// </summary>
/// <param name="line">行</param>
/// <returns>ディクショナリー</returns>
private static Dictionary<string, string> ParseAddressLine(string line)
{
var columns = line.Split('\t');

// 郵便番号
var postCode = StringUtility.At(columns, 0);
if (postCode == "")
{
// フォーマットが無効
return null;
}

// 住所
var address = StringUtility.At(columns, 1);
if (address == "")
{
// フォーマットが無効
return null;
}

// お名前
var name = StringUtility.At(columns, 2);
if (name == "")
{
// フォーマットが無効
return null;
}

// 電話番号(もしあれば)
var phoneNumber = StringUtility.At(columns, 3);

// 製品名(もしあれば)
var productName = StringUtility.At(columns, 4);

// サイズ(もしあれば)
var size = StringUtility.At(columns, 5);

Expand All @@ -107,8 +154,7 @@ private static Dictionary<string, string> ParseAddressLine(string line)
// 配送会社向け連絡先
fields["PhoneText"] = StringUtility.FormatPhoneNumber(phoneNumber);

Console.WriteLine("[DEBUG] 住所: [{0}], 氏名: [{1}], 電話: [{2}]",
fields["AddressText"], fields["NameText"], fields["PhoneText"]);
MyLogger.Info("住所: [", fields["AddressText"], "], 氏名: [", fields["NameText"], "], 電話: [", fields["PhoneText"], "]");

return fields;
}
Expand Down
26 changes: 14 additions & 12 deletions PtouchPrintSender.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,14 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<PlatformTarget>x86</PlatformTarget>
<DebugType>none</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
Expand All @@ -61,24 +62,14 @@
<Compile Include="Application.cs" />
<Compile Include="BrotherPrinterDocument.cs" />
<Compile Include="ConfigurationManager.cs" />
<Compile Include="MyLogger.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="StringUtility.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<ItemGroup>
<COMReference Include="bpac">
<Guid>{90359D74-B7D9-467F-B938-3883F4CAB582}</Guid>
<VersionMajor>1</VersionMajor>
<VersionMinor>3</VersionMinor>
<Lcid>0</Lcid>
<WrapperTool>tlbimp</WrapperTool>
<Isolated>False</Isolated>
<EmbedInteropTypes>True</EmbedInteropTypes>
</COMReference>
</ItemGroup>
<ItemGroup>
<BootstrapperPackage Include=".NETFramework,Version=v4.7.2">
<Visible>False</Visible>
Expand All @@ -91,5 +82,16 @@
<Install>false</Install>
</BootstrapperPackage>
</ItemGroup>
<ItemGroup>
<COMReference Include="bpac">
<Guid>{90359D74-B7D9-467F-B938-3883F4CAB582}</Guid>
<VersionMajor>1</VersionMajor>
<VersionMinor>3</VersionMinor>
<Lcid>0</Lcid>
<WrapperTool>tlbimp</WrapperTool>
<Isolated>False</Isolated>
<EmbedInteropTypes>True</EmbedInteropTypes>
</COMReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

0 comments on commit e880cf7

Please sign in to comment.