Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace testu3_rezolvat_cu_fisiere
- {
- public partial class Form1 : Form
- {
- static float totalVanzari;
- List<Floare> lista = new List<Floare>();
- public Form1()
- {
- //FormLogin f = new FormLogin();
- //if (f.ShowDialog() == DialogResult.OK)
- //{
- InitializeComponent();
- string path = @"D:\\MUENORBI";
- DirectoryInfo di = new DirectoryInfo(path);
- if (di.Exists)
- {
- FileInfo[] files = di.GetFiles("*.txt");
- for (int i = 0; i < files.Length; i++)
- {
- string aux = File.ReadAllText(files[i].FullName);
- string[] parts = aux.Split(' ');
- if (parts.Length == 6)
- {
- Floare f = new Floare(DateTime.ParseExact(parts[1], "ddMMyy", null), parts[2] + " " + parts[3] + " " + parts[4], Int32.Parse(parts[5]), parts[0]);
- lista.Add(f);
- listBox1.Items.Add("Denumire:" + f.Denumire + " Data:" + f.Data.ToString("dd/MM/yyyy") + " Categorie:" + f.Categorie + " Pret:" + f.Pret);
- }
- else if (parts.Length == 5)
- {
- Floare f = new Floare(DateTime.ParseExact(parts[1], "ddMMyy", null), parts[2] + " " + parts[3], Int32.Parse(parts[4]), parts[0]);
- lista.Add(f);
- listBox1.Items.Add("Denumire:" + f.Denumire + " Data:" + f.Data.ToString("dd/MM/yyyy") + " Categorie:" + f.Categorie + " Pret:" + f.Pret);
- }
- else if (parts.Length == 4)
- {
- Floare f = new Floare(DateTime.ParseExact(parts[1], "ddMMyy", null), parts[2], Int32.Parse(parts[3]), parts[0]);
- lista.Add(f);
- listBox1.Items.Add("Denumire:" + f.Denumire + " Data:" + f.Data.ToString("dd/MM/yyyy") + " Categorie:" + f.Categorie + " Pret:" + f.Pret);
- }
- }
- }
- //}
- }
- private void adaugareButton_Click(object sender, EventArgs e)
- {
- Floare f = new Floare(dataAdaugariiDateTimePicker.Value, categorieComboBox.Text, float.Parse((pretTextBox.Text)), denumireTextBox.Text);
- lista.Add(f);
- listBox1.Items.Add("Denumire:"+f.Denumire+" Data:"+f.Data.ToString("dd/MM/yyyy")+" Categorie:"+f.Categorie+" Pret:"+f.Pret);
- }
- private void salvareFisierButton_Click(object sender, EventArgs e)
- {
- string path = @"D:\\MUENORBI";
- var dir = new DirectoryInfo(path);
- if (dir.Exists)
- dir.Delete(true);
- dir = Directory.CreateDirectory(path);
- foreach(Floare f in lista)
- {
- StreamWriter sw = new StreamWriter(path+"\\" + f.Denumire +".txt", false);
- sw.WriteLine(f.Denumire + " " + f.Data.ToString("ddMMyy") + " " + f.Categorie + " " + f.Pret);
- sw.Close();
- }
- }
- private void vanzareButton_Click(object sender, EventArgs e)
- {
- string aux = listBox1.SelectedItem.ToString().Substring(9);
- string[] aux2 = aux.Split(' ');
- aux = aux2[0];
- int remove = 0;
- // lista.RemoveAll(o => o.Denumire.Equals(aux));
- foreach (Floare f in lista)
- {
- if(f.Denumire.Equals(aux))
- {
- totalVanzari += f.Pret;
- calculVanzariTextBox.Text = totalVanzari.ToString();
- remove = lista.IndexOf(f);
- }
- }
- lista.RemoveAt(remove);
- listBox1.Items.Clear();
- foreach(Floare f in lista)
- {
- listBox1.Items.Add("Denumire:" + f.Denumire + " Data:" + f.Data.ToString("dd/MM/yyyy") + " Categorie:" + f.Categorie + " Pret:" + f.Pret);
- }
- }
- private void cautareButton_Click(object sender, EventArgs e)
- {
- foreach (Floare f in lista)
- {
- if (f.Denumire.Equals(cautareTextBox.Text))
- {
- propertyGrid1.SelectedObject = f;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement