001.
using
System;
002.
using
System.Linq;
003.
using
System.Collections.Generic;
004.
using
System.ComponentModel;
005.
using
System.Data;
006.
using
System.Drawing;
007.
using
System.Text;
008.
using
System.Windows.Forms;
009.
using
System.IO;
010.
using
System.Configuration;
011.
using
System.Text.RegularExpressions;
012.
013.
namespace
CheckStock1
014.
{
015.
public
partial
class
UNF : Form
016.
{
017.
public
string
A {
get
;
set
; }
018.
public
string
B {
get
;
set
; }
019.
public
UNF(
string
data,
string
data2)
020.
{
021.
InitializeComponent();
022.
A = data;
023.
B = data2;
024.
}
025.
private
void
UNF_Load(
object
sender, EventArgs e)
026.
{
027.
DataGridTableStyle tabStyle =
new
DataGridTableStyle();
028.
tabStyle.MappingName =
"UNF"
;
029.
030.
DataGridTextBoxColumn col =
new
DataGridTextBoxColumn();
031.
col.MappingName =
"U"
;
032.
col.HeaderText =
"UNF"
;
033.
col.Width = 70;
034.
035.
DataGridTextBoxColumn col1 =
new
DataGridTextBoxColumn();
036.
col1.MappingName =
"A"
;
037.
col1.HeaderText =
"Amount"
;
038.
col1.Width = 107;
039.
040.
tabStyle.GridColumnStyles.Add(col);
041.
tabStyle.GridColumnStyles.Add(col1);
042.
043.
this
.dataGrid1.TableStyles.Clear();
044.
this
.dataGrid1.TableStyles.Add(tabStyle);
045.
046.
string
log =
"CheckStock.txt"
;
047.
StreamReader sr =
new
StreamReader(log);
048.
string
[] columnnames = sr.ReadLine().Split(
'\t'
);
049.
DataTable dt =
new
DataTable(
"UNF"
);
050.
dt.Columns.Add(
"U"
);
051.
dt.Columns.Add(
"A"
);
052.
foreach
(
string
c
in
columnnames)
053.
{
054.
dt.Columns.Add(c);
055.
}
056.
if
(File.Exists(log) ==
false
)
057.
{
058.
return
;
059.
}
060.
sr =
new
StreamReader(log);
061.
string
line;
062.
List<ReportUNF> reportList =
new
List<ReportUNF>();
063.
ReportUNF reportUnf;
064.
string
unf;
065.
string
orderNo;
066.
string
containerNo;
067.
while
((line = sr.ReadLine()) !=
null
)
068.
{
069.
int
tab_target = line.Split(
'\t'
).Length - 2;
070.
071.
int
indOfUnf = line.IndexOf(line.Substring(45,4));
072.
unf = line.Substring(indOfUnf,4);
073.
074.
int
indOfOrder = line.IndexOf(line.Substring(11, 10));
075.
orderNo = line.Substring(indOfOrder, 10);
076.
077.
int
indOfContainer = line.IndexOf(line.Substring(22, 11));
078.
containerNo = line.Substring(indOfContainer, 11);
079.
080.
if
(orderNo == A && containerNo == B)
081.
{
082.
if
(reportList.Where(v => v.unf == unf).FirstOrDefault() !=
null
)
083.
{
084.
foreach
(var r
in
reportList.Where(v => v.unf == unf))
085.
{
086.
r.amount += 1;
087.
}
088.
}
089.
else
090.
{
091.
reportUnf =
new
ReportUNF();
092.
reportUnf.unf = unf;
093.
reportUnf.amount += 1;
094.
reportList.Add(reportUnf);
095.
}
096.
}
097.
}
098.
sr.Close();
099.
List<ReportUNF> reportAll =
new
List<ReportUNF>();
100.
this
.dataGrid1.DataSource = dt;
101.
}
102.
private
void
btn_Menu_Click(
object
sender, EventArgs e)
103.
{
104.
Menu m1 =
new
Menu();
105.
m1.Show();
106.
this
.Hide();
107.
}
108.
}
109.
public
class
ReportUNF
110.
{
111.
public
virtual
string
unf {
get
;
set
; }
112.
public
virtual
int
amount {
get
;
set
; }
113.
}
114.
}