232 lines
6.4 KiB
C#
232 lines
6.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
using System.IO;
|
|
|
|
namespace WindowsFormsApp1
|
|
{
|
|
public partial class Form1 : Form
|
|
{
|
|
public Form1()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
private void Form1_Load(object sender, EventArgs e)
|
|
{
|
|
string path = "cuki.txt";
|
|
FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read);
|
|
StreamReader streamReader = new StreamReader(fs);
|
|
|
|
string line = streamReader.ReadLine();
|
|
while (line != null)
|
|
{
|
|
string[] datas = line.Split(';');
|
|
bool dijazott = BoolErtek(datas[2]);
|
|
int ertek = Convert.ToInt32(datas[3]);
|
|
Suti suti = new Suti(datas[0], datas[1], dijazott, ertek, datas[4]);
|
|
Data.adatok.Add(suti);
|
|
line = streamReader.ReadLine();
|
|
if (dijazott)
|
|
{
|
|
Data.dijnyertesek++;
|
|
}
|
|
}
|
|
|
|
|
|
streamReader.Close();
|
|
fs.Close();
|
|
|
|
Random random = new Random();
|
|
int index = random.Next(0, Data.adatok.Count);
|
|
Mai_ajanlat.Text = $"A mai ajánlatunk:{Data.adatok[index].nev}";
|
|
int legolcsobb = legolcsobb_index();
|
|
int legdragabb = legdragabb_index();
|
|
|
|
Legdragabb.Text = $"{Data.adatok[legdragabb].nev}";
|
|
Legolcsobb.Text = $"{Data.adatok[legolcsobb].nev}";
|
|
|
|
legdragabb_stat.Text = $"{Data.adatok[legdragabb].ar} Ft/{Data.adatok[legdragabb].egyseg}";
|
|
legolcsobb_stat.Text = $"{Data.adatok[legolcsobb].ar} Ft/{Data.adatok[legolcsobb].egyseg}";
|
|
|
|
|
|
dijnyertes.Text = $"{Data.dijnyertesek} féle díjnyertes édességből választhat.";
|
|
}
|
|
|
|
public bool BoolErtek(string ertek)
|
|
{
|
|
if (ertek == "false")
|
|
{
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
public int legdragabb_index()
|
|
{
|
|
int index = 0;
|
|
for (int i = 0; i < Data.adatok.Count; i++)
|
|
{
|
|
if (Data.adatok[index].ar < Data.adatok[i].ar)
|
|
{
|
|
index = i;
|
|
}
|
|
}
|
|
|
|
return index;
|
|
}
|
|
|
|
public int legolcsobb_index()
|
|
{
|
|
int index = 0;
|
|
for (int i = 0; i < Data.adatok.Count; i++)
|
|
{
|
|
if (Data.adatok[index].ar > Data.adatok[i].ar)
|
|
{
|
|
index = i;
|
|
}
|
|
}
|
|
|
|
return index;
|
|
}
|
|
|
|
|
|
private void Legdragabb_TextChanged(object sender, EventArgs e)
|
|
{
|
|
|
|
}
|
|
|
|
private void textBox5_TextChanged(object sender, EventArgs e)
|
|
{
|
|
|
|
}
|
|
|
|
private void Mai_ajanlat_TextChanged(object sender, EventArgs e)
|
|
{
|
|
|
|
}
|
|
|
|
private void button1_Click(object sender, EventArgs e)
|
|
{
|
|
if (tipus_ajanlat.Text == "")
|
|
{
|
|
MessageBox.Show("Nem írtál be süteményt!");
|
|
}
|
|
else if (contains(tipus_ajanlat.Text))
|
|
{
|
|
ajanlat(tipus_ajanlat.Text);
|
|
|
|
MessageBox.Show($"{Data.db} süti lett az ajánlathoz adva.\nÁtlagár:{Data.ossz / Data.db} Ft");
|
|
}
|
|
else
|
|
{
|
|
MessageBox.Show("Nincs megfelelő sütink. Kérjük válassz mást!");
|
|
}
|
|
|
|
}
|
|
|
|
public bool contains(string searched)
|
|
{
|
|
foreach (var item in Data.adatok)
|
|
{
|
|
if (searched == item.tipus)
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
public void ajanlat(string searched)
|
|
{
|
|
FileStream fileStream = new FileStream("ajanlat.txt", FileMode.Create, FileAccess.Write);
|
|
StreamWriter streamWriter = new StreamWriter(fileStream);
|
|
|
|
foreach (var item in Data.adatok)
|
|
{
|
|
if (item.tipus == searched)
|
|
{
|
|
streamWriter.WriteLine($"{item.nev};{item.ar};{item.egyseg}");
|
|
Data.db++;
|
|
Data.ossz += item.ar;
|
|
}
|
|
}
|
|
|
|
streamWriter.Close();
|
|
fileStream.Close();
|
|
}
|
|
|
|
private void button2_Click(object sender, EventArgs e)
|
|
{
|
|
if (suti_nev.Text != "" && suti_tipus.Text != "" && suti_ar.Text != "" && suti_egyseg.Text != "")
|
|
{
|
|
Suti ujsuti = new Suti(suti_nev.Text, suti_tipus.Text, Dijazott_check.Checked, Convert.ToInt32(suti_ar.Text), suti_egyseg.Text);
|
|
FileStream fs = new FileStream("cuki.txt", FileMode.Open, FileAccess.Write);
|
|
StreamWriter writer = new StreamWriter(fs);
|
|
|
|
string text = $"{ujsuti.nev};{ujsuti.tipus};";
|
|
if (ujsuti.dijazott)
|
|
{
|
|
text += $"true;";
|
|
}
|
|
else
|
|
{
|
|
text += $"false;";
|
|
}
|
|
text += $"{ujsuti.ar};{ujsuti.egyseg}";
|
|
writer.WriteLine(text);
|
|
|
|
writer.Close();
|
|
fs.Close();
|
|
|
|
MessageBox.Show("A sütit felkerült a listára!");
|
|
}
|
|
else
|
|
{
|
|
MessageBox.Show("Az adatok hiányosak.");
|
|
}
|
|
|
|
|
|
}
|
|
|
|
private void textBox2_TextChanged(object sender, EventArgs e)
|
|
{
|
|
|
|
}
|
|
}
|
|
|
|
public class Suti
|
|
{
|
|
public string nev;
|
|
public string tipus;
|
|
public bool dijazott;
|
|
public int ar;
|
|
public string egyseg;
|
|
|
|
public Suti(string nev, string tipus, bool dijazott, int ar, string egyseg)
|
|
{
|
|
this.nev = nev;
|
|
this.tipus = tipus;
|
|
this.dijazott = dijazott;
|
|
this.ar = ar;
|
|
this.egyseg = egyseg;
|
|
|
|
}
|
|
}
|
|
public static class Data
|
|
{
|
|
public static List<Suti> adatok = new List<Suti>();
|
|
public static int db = 0;
|
|
public static int ossz = 0;
|
|
public static int dijnyertesek = 0;
|
|
}
|
|
}
|