using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Configuration;
using System.Text.RegularExpressions;
using System.Diagnostics;
namespace CheckStock1
{
public partial class UNF : Form
{
public string A { get; set; }
public string B { get; set; }
public UNF(string data, string data2)
{
InitializeComponent();
A = data;
B = data2;
}
string log = "CheckStock.txt";
private void UNF_Load(object sender, EventArgs e)
{
List<ReportUNF> reportList = new List<ReportUNF>();
DataGridTableStyle tableS = new DataGridTableStyle();
tableS.MappingName = reportList.GetType().Name;
DataGridTextBoxColumn tbcName = new DataGridTextBoxColumn();
tbcName.MappingName = "UNF";
tbcName.HeaderText = "UNF";
tbcName.Width = 74;
tableS.GridColumnStyles.Add(tbcName);
DataGridTableStyle tableS1 = new DataGridTableStyle();
tableS.MappingName = reportList.GetType().Name;
DataGridTextBoxColumn tbcName1 = new DataGridTextBoxColumn();
tbcName1.MappingName = "AMOUNT";
tbcName1.HeaderText = "AMOUNT";
tbcName1.Width = 104;
tableS.GridColumnStyles.Add(tbcName1);
dataGrid1.TableStyles.Clear();
dataGrid1.TableStyles.Add(tableS);
dataGrid1.TableStyles.Add(tableS1);
StreamReader sr = new StreamReader(log);
if (File.Exists(log) == false)
{
return;
}
sr = new StreamReader(log);
string line1;
ReportUNF reportUnf;
string unf;
string dateTime;
string orderNo;
string dat = "";
string containerNo;
string serial1;
while ((line1 = sr.ReadLine()) != null)
{
int tab_target = line1.Split('\t').Length - 2;
int start = 0;
dateTime = line1.Substring(start, line1.IndexOf('\t', start) - start);
dat = dateTime + '\t';
start = line1.IndexOf('\t', 0) + 1;
orderNo = line1.Substring(start, line1.IndexOf('\t', start) - start);
dat += orderNo + '\t';
start = line1.IndexOf('\t', start) + 1;
containerNo = line1.Substring(start, line1.IndexOf('\t', start) - start);
dat += containerNo + '\t';
start = line1.IndexOf('\t', start) + 1;
serial1 = line1.Substring(start, line1.IndexOf('\t', start) - start);
dat += serial1 + '\t';
start = line1.IndexOf('\t', start) + 1;
unf = line1.Substring(start, line1.IndexOf('\t', start) - start);
dat += unf + '\t';
start = line1.IndexOf('\t', start) + 1;
if (orderNo == A && containerNo == B)
{
if (reportList.Where(v => v.UNF == unf).FirstOrDefault() != null)
{
foreach (var r in reportList.Where(v => v.UNF == unf))
{
r.AMOUNT += 1;
}
}
else
{
reportUnf = new ReportUNF();
reportUnf.UNF = unf;
reportUnf.AMOUNT += 1;
reportList.Add(reportUnf);
}
}
}
this.dataGrid1.DataSource = reportList;
sr.Close();
}
private void btn_Menu_Click(object sender, EventArgs e)
{
Menu m1 = new Menu();
m1.Show();
this.Hide();
}
}
public class ReportUNF
{
public virtual string UNF { get; set; }
public virtual int AMOUNT { get; set; }
}
}
คือตัว text file มันยังทำงานอยู่อ่าครับ หลังจากออกจากหน้านี้ไป พอไปเช็คเพื่อจะเขียนข้อมูลต่อจากของเดิมAppendTextแล้วมันฟ้องว่า file text ยัง process อยู่อ่าครับ