รู้ได้ยังไงว่ามันมีถึง 1000 line เผื่อมันเกิน หรือ มัน ไม่ถึงละ
Code (C#)
private List<string> array = new List<string>();
foreach (string s in System.IO.File.ReadAllText(@"F:\TestCSharp\Net Work\Loadwebtoons\Loadwebtoons\TextFile1.txt").Trim())
{
array.Add(s);
}
private bool Check(string input)
{
bool b = false;
foreach (string s in System.IO.File.ReadAllText(@"TextFile1.txt").Trim())
{
if (s == input)
{
b = true;
return b;
}
}
return b;
}
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.Text.RegularExpressions;
namespace CheckStock1
{
public partial class SR : Form
{
public string A { get; set; }
public string B { get; set; }
public SR(string data,string data2)
{
InitializeComponent();
A = data;
B = data2;
}
private bool Check(string input)
{
bool b = false;
foreach (string s in System.IO.File.OpenText(@"CheckStock.txt").ReadToEnd())
{
if(s==input)
{
b = true;
return b;
}
}
return b;
}
private List<string> array = new List<string>();
private void SR_Load(object sender, EventArgs e)
{
//string log = "CheckStock.txt";
//StreamReader sr = new StreamReader(log);
//string line = string.Empty;
//int i = 0;
//while((line = sr.ReadLine()) != null)
//{
// array.Add(line);
//}
//string text = "CheckStock.txt";
//StreamReader sr = new StreamReader(text);
//String line = String.Empty;
//while ((line = sr.ReadLine()) != null)
//{
// for (int i = 0; i <= 1000; i++)
// {
// array[i] = Convert.ToInt32(line);
// }
//}
//foreach (string s in System.IO.File.ReadAllText(@"CheckStock.txt"))
//{
// array.Add(s);
//}
textBox1.Focus();
textBox3.Text = "0";
}
private FileInfo f;
private void button1_Click_1(object sender, EventArgs e)
{
Menu m1 = new Menu();
m1.Show();
this.Hide();
}
string C = DateTime.Now.ToString("dd/MM/yyyy");
private void textBox1_KeyDown_1(object sender,KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
if (textBox1.Text.Length >= 15 || textBox1.Text.Length < 5)
{
MessageBox.Show("Number Invalid");
textBox1.Text = "";
return;
}
string str = ((TextBox) sender).Text;
if (!array.Contains(str))
{
array.Add(str);
int Number = Convert.ToInt32(textBox3.Text.ToString());
string nb = (++Number).ToString();
textBox3.Text = nb;
textBox2.Text = textBox1.Text.Substring(0, 4);
label5.Text = textBox1.Text;
string log = "CheckStock.txt";
this.textBox1.Multiline = true;
if (File.Exists(log) == true)
{
f = new FileInfo(log);
StreamWriter sw = f.AppendText();
sw.WriteLine(C + "\t" + A + "\t" + B + "\t" + textBox1.Text + "\t" + textBox2.Text + "\t" + "1");
textBox1.Text = "";
sw.Close();
}
else if (File.Exists(log) == false)
{
f = new FileInfo(log);
StreamWriter sw = f.CreateText();
sw.WriteLine(C + "\t" + A + "\t" + B + "\t" + textBox1.Text + "\t" + textBox2.Text + "\t" + "1");
textBox1.Text = "";
sw.Close();
}
}
else
{
MessageBox.Show("Scan Again");
textBox1.Text = "";
return;
}
}
}
}
}
นี่ครับโค้ดของผม แต่ที่พี่ไห้มา foreach (string s in System.IO.File.ReadAllText(@"CheckStock.txt")) error ครับ ขึ้นมา cannot convert type char to string
private bool Check(string input)
{
bool b = false;
foreach (string s in System.IO.File.ReadAllText(@"TextFile1.txt").Trim().ToList<string>)
{
if (s == input)
{
b = true;
return b;
}
}
return b;
}