128 lines
3.4 KiB
C#
128 lines
3.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Runtime.InteropServices.ComTypes;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
|
|
namespace HegyekMO_GUI
|
|
{
|
|
public partial class Form1 : Form
|
|
{
|
|
const string path = @"hegyekMo.txt";
|
|
public Form1()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
private void Form1_Load(object sender, EventArgs e)
|
|
{
|
|
DataRead();
|
|
ListBoxFill();
|
|
}
|
|
|
|
public void ListBoxFill()
|
|
{
|
|
string header_str = $"{Data.header[0]}\t{Data.header[1]}\t{Data.header[2]}";
|
|
hegyek_LB.Items.Add(header_str);
|
|
|
|
foreach (var item in Data.hegyek)
|
|
{
|
|
string line = $"{item.HegycsucsNev}\t{item.Hegyseg}\t{item.Magassag}";
|
|
hegyek_LB.Items.Add(line);
|
|
}
|
|
}
|
|
|
|
public void DataWrite(Hegy item)
|
|
{
|
|
string line = $"{item.HegycsucsNev};{item.Hegyseg};{item.Magassag}";
|
|
File.AppendAllText(path, line);
|
|
}
|
|
|
|
|
|
public static void DataRead()
|
|
{
|
|
|
|
FileStream fileStream = new FileStream(path, FileMode.Open, FileAccess.Read);
|
|
StreamReader streamReader = new StreamReader(fileStream);
|
|
|
|
string line = streamReader.ReadLine();
|
|
Data.header = line.Split(';');
|
|
line = streamReader.ReadLine();
|
|
|
|
while (line != null)
|
|
{
|
|
string[] datas = line.Split(';');
|
|
|
|
|
|
Hegy hegy = new Hegy(datas[0], datas[1], Convert.ToInt32(datas[2]));
|
|
Data.hegyek.Add(hegy);
|
|
|
|
line = streamReader.ReadLine();
|
|
}
|
|
|
|
streamReader.Close();
|
|
fileStream.Close();
|
|
}
|
|
|
|
private void label1_Click(object sender, EventArgs e)
|
|
{
|
|
|
|
}
|
|
|
|
private void button1_Click(object sender, EventArgs e)
|
|
{
|
|
if (IsEverythingFilled() && IsHeightANumber())
|
|
{
|
|
Hegy hegy = new Hegy(hegycsucs_TB.Text, hegyseg_TB.Text, Convert.ToInt32(magassag_TB.Text));
|
|
DataWrite(hegy);
|
|
MessageBox.Show("Az állomány bővítése sikeres volt!");
|
|
}
|
|
}
|
|
|
|
private bool IsEverythingFilled()
|
|
{
|
|
if (hegycsucs_TB.Text != "" && hegyseg_TB.Text != "" && magassag_TB.Text != "")
|
|
{
|
|
return true;
|
|
}
|
|
MessageBox.Show("Kérem minden mezőt töltsön ki!");
|
|
return false;
|
|
}
|
|
|
|
private bool IsHeightANumber()
|
|
{
|
|
bool asd = Int32.TryParse(magassag_TB.Text, out int n);
|
|
if (!asd)
|
|
{
|
|
MessageBox.Show("Nem számot adtál meg!");
|
|
}
|
|
return asd;
|
|
}
|
|
}
|
|
|
|
public static class Data
|
|
{
|
|
public static string[] header = new string[1];
|
|
public static List<Hegy> hegyek = new List<Hegy>();
|
|
}
|
|
public class Hegy
|
|
{
|
|
public string HegycsucsNev { get; private set; }
|
|
public string Hegyseg { get; private set; }
|
|
public int Magassag { get; private set; }
|
|
|
|
public Hegy(string hegycsucsnev, string hegyseg, int magassag)
|
|
{
|
|
HegycsucsNev = hegycsucsnev;
|
|
Hegyseg = hegyseg;
|
|
Magassag = magassag;
|
|
}
|
|
}
|
|
}
|