|
|
|
C# จะอ่าน text file ทีละบรรทัด มาใส่ใน Array ยังไงครับ (มือใหม่ครับ) |
|
|
|
|
|
|
|
ได้้แล้วครับ ถามเองตอบเอง ห้าๆ
Code (C#)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace member_module
{
struct member_db{
//public int id_customer;
public string name_customer;
public string pid_customer;
public string sex_customer;
public int age_customer;
public string address_customer;
public int main_id;
};
class Program
{
public static void Main(string[] args)
{
int id_customer;
int count_if;
Console.WriteLine("Member Module");
check_filemember(out id_customer, out count_if);
find_member_module();
new_member_module(ref id_customer, ref count_if);
Console.WriteLine("End!!!!");
}
private static void find_member_module()
{
Console.Write("Member find Module \n");
Console.Write(" Menu-----> \nFind ID = ID\nFind Name = Name\nFindPersonal ID = personalid\n");
Console.Write("Enter mode : ");
string check;
check = Console.ReadLine();
//ID find
if (check == "ID" || check == "Id" || check == "id" || check == "iD")
{
string check_input = null,check_input_parse2=null;
int count_line = 0;
Console.Write("ID to find : ");
check_input = Console.ReadLine();
check_input_parse2 = "ID : " + check_input;
string[] readText = File.ReadAllLines("member.txt", Encoding.UTF8);
foreach (string s in readText)
{
if (s == check_input_parse2)
{
Console.WriteLine(s);
count_line++;
}
else if (count_line == 1)
{
Console.WriteLine(s);
count_line++;
}
else if (count_line == 2)
{
Console.WriteLine(s);
count_line++;
}
else if (count_line == 3)
{
Console.WriteLine(s);
count_line++;
}
else if (count_line == 4)
{
Console.WriteLine(s);
count_line++;
}
else if (count_line == 5)
{
Console.WriteLine(s);
count_line++;
}
}
}
//name find
if (check == "Name" || check == "name" || check == "n" || check == "NAME")
{
string check_input = null, check_input_parse2 = null;
int count_line = 0, count_id = 0;
Console.Write("ID to find : ");
check_input = Console.ReadLine();
check_input_parse2 = "Name : " + check_input;
string[] readText = File.ReadAllLines("member.txt", Encoding.UTF8);
foreach (string s in readText)
{
count_id++;
if (count_id == 7)
{
Console.WriteLine(s);
}
else if (s == check_input_parse2)
{
Console.WriteLine(s);
count_line++;
}
else if (count_line == 1)
{
Console.WriteLine(s);
count_line++;
}
else if (count_line == 2)
{
Console.WriteLine(s);
count_line++;
}
else if (count_line == 3)
{
Console.WriteLine(s);
count_line++;
}
else if (count_line == 4)
{
Console.WriteLine(s);
count_line++;
}
}
}
//Personal ID find
if (check == "Personal ID" || check == "personalid" || check == "p" || check == "personalid")
{
string check_input = null, check_input_parse2 = null;
int count_line = 0,count_id=0;
Console.Write("Personal ID to find : ");
check_input = Console.ReadLine();
check_input_parse2 = "Personal ID : " + check_input;
string[] readText = File.ReadAllLines("member.txt", Encoding.UTF8);
foreach (string s in readText)
{
count_id++;
if (count_id==7)
{
Console.WriteLine(s);
}
if (count_id == 8)
{
Console.WriteLine(s);
}
else if (s == check_input_parse2)
{
Console.WriteLine(s);
count_line++;
}
else if (count_line == 1)
{
Console.WriteLine(s);
count_line++;
}
else if (count_line == 2)
{
Console.WriteLine(s);
count_line++;
}
else if (count_line == 3)
{
Console.WriteLine(s);
count_line++;
}
}
}
}
//ระบบเช็กไฟล์ txt สมาชิก
private static void check_filemember(out int id_customer, out int count_if)
{
if (File.Exists("id_customer_txt.txt"))
{
string con;
Console.WriteLine(" [id_customer_txt.txt] ---> already exists!");
con = File.ReadAllText("id_customer_txt.txt");
id_customer = Convert.ToInt32(con);
Convert.ToInt32(id_customer);
count_if = 0;
}
else
{
id_customer = 1;
count_if = 0;
}
}
//ระบบสมัครสมาชิก
private static void new_member_module(ref int id_customer, ref int count_if)
{
string checker, exit;
member_db a;
a.main_id = id_customer;
member_db[] inp = new member_db[id_customer];
Console.Write("New Member? (Y/N): ");
checker = Console.ReadLine();
if (checker == "Y" || checker == "y" || checker == "yes" || checker == "Yes" || checker == "YES")
{
count_if = +1;
}
else
{
return;
}
for (int che = count_if; che > 0; che--)
{
for (int i = 0; i < id_customer; i = id_customer + 1)
{
StreamWriter txtmember = File.AppendText("member.txt");
string fileparth = "id_customer_txt.txt";
string filecon = Convert.ToString(id_customer);
File.WriteAllText(fileparth, filecon);
Convert.ToInt32(id_customer);
Console.WriteLine("a Newmember");
Console.Write("Please insert name : ");
inp[i].name_customer = Console.ReadLine();
Console.Write("Please insert Personal-ID : ");
inp[i].pid_customer = Console.ReadLine();
Console.Write("Please insert sex (M/F) : ");
inp[i].sex_customer = Console.ReadLine();
//while (inp[i].sex_customer != "M" || inp[i].sex_customer != "F")
//{
// Console.Write("Please insert sex again (M/F) : ");
// inp[i].sex_customer = Console.ReadLine();
//}
Console.Write("Please insert age : ");
inp[i].age_customer = int.Parse(Console.ReadLine());
//while (inp[i].age_customer < 0 && inp[i].age_customer > 99)
//{
// Console.Write("Please insert age again able 0 - 99: ");
// inp[i].age_customer = int.Parse(Console.ReadLine());
//}
Console.Write("Please insert address : ");
inp[i].address_customer = Console.ReadLine();
txtmember.WriteLine("ID : {0}", id_customer);
txtmember.WriteLine("Name : {0}", inp[i].name_customer);
txtmember.WriteLine("Personal ID : {0}", inp[i].pid_customer);
txtmember.WriteLine("Sex : {0}", inp[i].sex_customer);
txtmember.WriteLine("Age : {0}", inp[i].age_customer);
txtmember.WriteLine("Address : {0}", inp[i].address_customer);
//id_customer_txt2.Write(Convert.ToString(id_customer));
txtmember.Close();
//id_customer_txt2.Close();
id_customer++;
}
Console.Write("Exit ? : ");
exit = Console.ReadLine();
if (exit == "N" || exit == "n")
{
che = che + 1;
}
if (exit == "Y" || exit == "y")
{
che = 0;
}
}
}
}
}
|
|
|
|
|
Date :
2013-11-17 02:11:10 |
By :
โอภาส |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
เอ้ยผิดโพส
|
|
|
|
|
Date :
2013-11-17 02:12:34 |
By :
โอภาส |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
IEnumerable<string> readText = (from x in File.ReadAllLines(path, Encoding.Default) select x).ToList();
|
|
|
|
|
Date :
2013-11-18 15:18:14 |
By :
anucham |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 05
|