using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
using System.Text.RegularExpressions;
namespace JAN解析
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
int i = 1;
string path = Application.StartupPath + @"\jan";
StreamWriter sw = new StreamWriter(Application.StartupPath + @"\out.txt", false, Encoding.GetEncoding("shift_jis"));
foreach (string fileName in Directory.GetFiles(path))
{
this.Text = i.ToString();
using (StreamReader sr = new StreamReader(fileName, Encoding.GetEncoding("shift_jis")))
{
string line = "";
string date = "";
string staff_name = "";
string point = "";
string card_no = "";
while (sr.Peek() > -1)
{
line = sr.ReadLine();
if (new Regex("--------------------------------").IsMatch(line))
{
date = "";
staff_name = "";
point = "";
card_no = "";
}
else if (new Regex(@"^\d{4}年\d{2}月\d{2}日").IsMatch(line))
{
Match m = new Regex(@"^\d{4}年\d{2}月\d{2}日").Match(line);
date = m.Groups[0].Value;
}
else if (new Regex(@"^No00[0-9]\S*").IsMatch(line))
{
Match m = new Regex(@"^No00[0-9](\S*)").Match(line);
staff_name = m.Groups[1].Value;
}
else if (new Regex(@"^\s訂正ポイント\s*[0-9]*点").IsMatch(line))
{
Match m = new Regex(@"^\s訂正ポイント\s*([0-9]*点)").Match(line);
point = m.Groups[1].Value;
}
else if (new Regex(@"^カ-ドNO[0-9]*").IsMatch(line))
{
Match m = new Regex(@"^カ-ドNO([0-9]*)").Match(line);
card_no = m.Groups[1].Value;
}
if (date != "" && staff_name != "" && point != "" && card_no != "")
{
string matched = date + "," + staff_name + "," + card_no + "," + point + "\r\n";
sw.Write(matched);
date = "";
staff_name = "";
point = "";
card_no = "";
}
}
}
i++;
}
sw.Close();
MessageBox.Show("完了");
}
private void button2_Click(object sender, EventArgs e)
{
int i = 1;
string path = Application.StartupPath + @"\jan";
StreamWriter sw = new StreamWriter(Application.StartupPath + @"\out.txt", false, Encoding.GetEncoding("shift_jis"));
foreach (string fileName in Directory.GetFiles(path))
{
this.Text = i.ToString();
using (StreamReader sr = new StreamReader(fileName, Encoding.GetEncoding("shift_jis")))
{
string line = "";
string date = "";
string staff_name = "";
string point = "";
string card_no = "";
while (sr.Peek() > -1)
{
line = sr.ReadLine();
if (new Regex("--------------------------------").IsMatch(line))
{
date = "";
staff_name = "";
point = "";
card_no = "";
}
else if (new Regex(@"^\d{4}年\d{2}月\d{2}日").IsMatch(line))
{
Match m = new Regex(@"^\d{4}年\d{2}月\d{2}日").Match(line);
date = m.Groups[0].Value;
}
else if (new Regex(@"^No00[0-9]\S*").IsMatch(line))
{
Match m = new Regex(@"^No00[0-9](\S*)").Match(line);
staff_name = m.Groups[1].Value;
}
else if (new Regex(@"^\s割引券\s*[0-9]*点").IsMatch(line))
{
Match m = new Regex(@"^\s割引券\s*([0-9]*)点").Match(line);
point = m.Groups[1].Value;
}
else if (new Regex(@"^カ-ドNO[0-9]*").IsMatch(line))
{
Match m = new Regex(@"^カ-ドNO([0-9]*)").Match(line);
card_no = m.Groups[1].Value;
}
if (date != "" && staff_name != "" && point != "" && card_no != "")
{
string matched = date + "," + staff_name + "," + card_no + "," + point + "\r\n";
sw.Write(matched);
date = "";
staff_name = "";
point = "";
card_no = "";
}
}
}
i++;
}
sw.Close();
MessageBox.Show("完了");
}
private void button3_Click(object sender, EventArgs e)
{
int i = 1;
string path = Application.StartupPath + @"\jan";
StreamWriter sw = new StreamWriter(Application.StartupPath + @"\out.txt", false, Encoding.GetEncoding("shift_jis"));
foreach (string fileName in Directory.GetFiles(path))
{
this.Text = i.ToString();
using (StreamReader sr = new StreamReader(fileName, Encoding.GetEncoding("shift_jis")))
{
string line = "";
string date = "";
string staff_name = "";
string amount = "";
string card_no = "";
while (sr.Peek() > -1)
{
line = sr.ReadLine();
if (new Regex("--------------------------------").IsMatch(line))
{
date = "";
staff_name = "";
amount = "";
card_no = "";
}
else if (new Regex(@"^\d{4}年\d{2}月\d{2}日").IsMatch(line))
{
Match m = new Regex(@"^\d{4}年\d{2}月\d{2}日").Match(line);
date = m.Groups[0].Value;
}
else if (new Regex(@"^No00[0-9]\S*").IsMatch(line))
{
Match m = new Regex(@"^No00[0-9](\S*)").Match(line);
staff_name = m.Groups[1].Value;
}
else if (new Regex(@"^合計\s*\\[0-9,]*").IsMatch(line))
{
Match m = new Regex(@"^合計\s*(\\[0-9,]*)").Match(line);
amount = m.Groups[1].Value;
amount = amount.Replace(",", "");
}
else if (new Regex(@"^カ-ドNO[0-9]*").IsMatch(line))
{
Match m = new Regex(@"^カ-ドNO([0-9]*)").Match(line);
card_no = m.Groups[1].Value;
if (card_no != textBox1.Text) card_no = "";
}
if (date != "" && staff_name != "" && amount != "" && card_no != "")
{
string matched = date + "," + staff_name + "," + card_no + "," + amount + "\r\n";
sw.Write(matched);
date = "";
staff_name = "";
amount = "";
card_no = "";
}
}
}
i++;
}
sw.Close();
MessageBox.Show("完了");
}
}
}