Advertisement
Guest User

Untitled

a guest
Dec 10th, 2018
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.61 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.IO;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using System.Windows.Forms;
  11.  
  12. namespace testu3_rezolvat_cu_fisiere
  13. {
  14. public partial class Form1 : Form
  15. {
  16. static float totalVanzari;
  17. List<Floare> lista = new List<Floare>();
  18. public Form1()
  19. {
  20. //FormLogin f = new FormLogin();
  21. //if (f.ShowDialog() == DialogResult.OK)
  22. //{
  23. InitializeComponent();
  24. string path = @"D:\\MUENORBI";
  25. DirectoryInfo di = new DirectoryInfo(path);
  26. if (di.Exists)
  27. {
  28. FileInfo[] files = di.GetFiles("*.txt");
  29. for (int i = 0; i < files.Length; i++)
  30. {
  31. string aux = File.ReadAllText(files[i].FullName);
  32. string[] parts = aux.Split(' ');
  33. if (parts.Length == 6)
  34. {
  35. Floare f = new Floare(DateTime.ParseExact(parts[1], "ddMMyy", null), parts[2] + " " + parts[3] + " " + parts[4], Int32.Parse(parts[5]), parts[0]);
  36. lista.Add(f);
  37. listBox1.Items.Add("Denumire:" + f.Denumire + " Data:" + f.Data.ToString("dd/MM/yyyy") + " Categorie:" + f.Categorie + " Pret:" + f.Pret);
  38. }
  39. else if (parts.Length == 5)
  40. {
  41. Floare f = new Floare(DateTime.ParseExact(parts[1], "ddMMyy", null), parts[2] + " " + parts[3], Int32.Parse(parts[4]), parts[0]);
  42. lista.Add(f);
  43. listBox1.Items.Add("Denumire:" + f.Denumire + " Data:" + f.Data.ToString("dd/MM/yyyy") + " Categorie:" + f.Categorie + " Pret:" + f.Pret);
  44. }
  45. else if (parts.Length == 4)
  46. {
  47. Floare f = new Floare(DateTime.ParseExact(parts[1], "ddMMyy", null), parts[2], Int32.Parse(parts[3]), parts[0]);
  48. lista.Add(f);
  49. listBox1.Items.Add("Denumire:" + f.Denumire + " Data:" + f.Data.ToString("dd/MM/yyyy") + " Categorie:" + f.Categorie + " Pret:" + f.Pret);
  50. }
  51. }
  52. }
  53. //}
  54. }
  55.  
  56. private void adaugareButton_Click(object sender, EventArgs e)
  57. {
  58. Floare f = new Floare(dataAdaugariiDateTimePicker.Value, categorieComboBox.Text, float.Parse((pretTextBox.Text)), denumireTextBox.Text);
  59. lista.Add(f);
  60. listBox1.Items.Add("Denumire:"+f.Denumire+" Data:"+f.Data.ToString("dd/MM/yyyy")+" Categorie:"+f.Categorie+" Pret:"+f.Pret);
  61. }
  62.  
  63. private void salvareFisierButton_Click(object sender, EventArgs e)
  64. {
  65. string path = @"D:\\MUENORBI";
  66. var dir = new DirectoryInfo(path);
  67. if (dir.Exists)
  68. dir.Delete(true);
  69. dir = Directory.CreateDirectory(path);
  70. foreach(Floare f in lista)
  71. {
  72. StreamWriter sw = new StreamWriter(path+"\\" + f.Denumire +".txt", false);
  73.  
  74. sw.WriteLine(f.Denumire + " " + f.Data.ToString("ddMMyy") + " " + f.Categorie + " " + f.Pret);
  75. sw.Close();
  76. }
  77. }
  78.  
  79. private void vanzareButton_Click(object sender, EventArgs e)
  80. {
  81. string aux = listBox1.SelectedItem.ToString().Substring(9);
  82. string[] aux2 = aux.Split(' ');
  83. aux = aux2[0];
  84. int remove = 0;
  85. // lista.RemoveAll(o => o.Denumire.Equals(aux));
  86. foreach (Floare f in lista)
  87. {
  88. if(f.Denumire.Equals(aux))
  89. {
  90. totalVanzari += f.Pret;
  91. calculVanzariTextBox.Text = totalVanzari.ToString();
  92. remove = lista.IndexOf(f);
  93. }
  94. }
  95. lista.RemoveAt(remove);
  96. listBox1.Items.Clear();
  97. foreach(Floare f in lista)
  98. {
  99. listBox1.Items.Add("Denumire:" + f.Denumire + " Data:" + f.Data.ToString("dd/MM/yyyy") + " Categorie:" + f.Categorie + " Pret:" + f.Pret);
  100. }
  101. }
  102.  
  103. private void cautareButton_Click(object sender, EventArgs e)
  104. {
  105. foreach (Floare f in lista)
  106. {
  107. if (f.Denumire.Equals(cautareTextBox.Text))
  108. {
  109. propertyGrid1.SelectedObject = f;
  110. }
  111. }
  112. }
  113.  
  114. }
  115. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement