Advertisement
Guest User

Untitled

a guest
Nov 10th, 2017
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.03 KB | None | 0 0
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Data;
  6. using System.Drawing;
  7. using System.IO;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. using System.Windows.Forms;
  12.  
  13. namespace BungetPetru
  14. {
  15. public partial class Form1 : Form
  16. {
  17. public static int id = 0;
  18. public static float sum = 0;
  19. private List<Electrocasnice> electrocasnice = new List<Electrocasnice>();
  20.  
  21. public Form1()
  22. {
  23. InitializeComponent();
  24. citire_fiser();
  25. }
  26. public void Update_listBox()
  27. {
  28. listBox1.Items.Clear();
  29. foreach(Electrocasnice item in electrocasnice)
  30. {
  31. AparatFoto af = (AparatFoto)item;
  32. string text = af.toFileString();
  33.  
  34. listBox1.Items.Add(text);
  35. }
  36. }
  37.  
  38. public void citire_fiser()
  39. {
  40. string path = "electrocasnice.txt";
  41. StreamReader sr = new StreamReader(path);
  42. try
  43. {
  44.  
  45.  
  46. string line = "";
  47. while ((line = sr.ReadLine()) != null)
  48. {
  49. string[] el = line.Split(';');
  50.  
  51. DateTime date = Convert.ToDateTime(el[2]);
  52. DateTime newDate = new DateTime(date.Year, date.Month, date.Day);
  53.  
  54. AparatFoto af = new AparatFoto(el[1], newDate, (float)Convert.ToDouble(el[4]), Convert.ToInt32(el[5]), el[3]);
  55. electrocasnice.Add(af);
  56. }
  57.  
  58. sr.Close();
  59. Update_listBox();
  60.  
  61. }
  62. catch(Exception ex)
  63. {
  64. sr.Close();
  65. }
  66. Update_listBox();
  67. }
  68. public void adaugare_fisier(string text)
  69. {
  70. string path = "electrocasnice.txt";
  71. StreamWriter sw = new StreamWriter(path, true);
  72.  
  73. sw.WriteLine(text);
  74. sw.Close();
  75. }
  76. public void stergere_fisier(string id)
  77. {
  78. string path = "electrocasnice.txt";
  79. StreamReader sr = new StreamReader(path);
  80. string line = "";
  81. string newText = "";
  82.  
  83. string[] arr = new string[100];
  84. int ind = 0;
  85. while ((line = sr.ReadLine()) != null)
  86. {
  87.  
  88. if (line.Split(';')[0] == id)
  89. {
  90. //newText += "\n";
  91. //continue;
  92. }
  93. else
  94. {
  95. //newText += "\n";
  96. //newText += line;
  97. arr[ind++] = line;
  98. }
  99. }
  100. sr.Close();
  101. try
  102. {
  103. StreamWriter sw = new StreamWriter("electrocasnice.txt");
  104. //sw.WriteLine(newText);
  105.  
  106. for (int j = 0; j < arr.Length; j++)
  107. {
  108. sw.WriteLine(arr[j]);
  109. }
  110. sw.Close();
  111. }
  112. catch (Exception ex)
  113. {
  114.  
  115. }
  116.  
  117.  
  118. }
  119. private void buttonAdaugare_Click(object sender, EventArgs e)
  120. {
  121. try
  122. {
  123. string denumire = textBoxDenumire.Text;
  124. DateTime data = dateTimePicker.Value;
  125. int stoc = Convert.ToInt32(textBoxStoc.Text);
  126. float pret = (float)Convert.ToDouble(textBoxPret.Text);
  127. string tip = comboBoxTip.Text;
  128.  
  129. AparatFoto af = new AparatFoto(denumire, data, pret, stoc, tip);
  130.  
  131. electrocasnice.Add(af);
  132.  
  133.  
  134. Update_listBox();
  135.  
  136.  
  137. string text = af.toFileString();
  138. adaugare_fisier(text);
  139. }
  140. catch
  141. {
  142. //MessageBox.Show("Adaugare esuata!");
  143. }
  144. }
  145.  
  146. class CompararePret : IComparer<AparatFoto>
  147. {
  148. public int Compare(AparatFoto x, AparatFoto y)
  149. {
  150. if (x.getPret() > y.getPret()) { return 1; }
  151. else if (x.getPret() < y.getPret()) { return -1; }
  152. else return 0;
  153. }
  154. }
  155.  
  156. class ComparareStoc : IComparer<AparatFoto>
  157. {
  158. public int Compare(AparatFoto x, AparatFoto y)
  159. {
  160. if (x.getStoc() > y.getStoc()) { return 1; }
  161. else if (x.getStoc() < y.getStoc()) { return -1; }
  162. else return 0;
  163. }
  164. }
  165.  
  166. private void buttonOrdonare_Click(object sender, EventArgs e)
  167. {
  168. List<AparatFoto> aparate = new List<AparatFoto>();
  169. foreach(Electrocasnice el in electrocasnice)
  170. {
  171. aparate.Add((AparatFoto)el);
  172. }
  173. if(checkBoxPret.Checked)
  174. {
  175. aparate.Sort(new CompararePret());
  176.  
  177. listBox2.Items.Clear();
  178. foreach (AparatFoto item in aparate)
  179. {
  180. listBox2.Items.Add(item.toFileString());
  181. }
  182. }
  183. if (checkBoxStoc.Checked)
  184. {
  185. aparate.Sort(new ComparareStoc());
  186.  
  187. listBox2.Items.Clear();
  188. foreach (AparatFoto item in aparate)
  189. {
  190. listBox2.Items.Add(item.toFileString());
  191. }
  192. }
  193. }
  194.  
  195. private void buttonVanzare_Click(object sender, EventArgs e)
  196. {
  197. string line = listBox1.SelectedItem.ToString();
  198. string[] el = line.Split(';');
  199. int index = 0;
  200.  
  201. foreach(Electrocasnice item in electrocasnice)
  202. {
  203. if (item.getId() == el[0])
  204. {
  205. index = electrocasnice.IndexOf(item);
  206. AparatFoto af = (AparatFoto)item;
  207. sum += af.getPret();
  208. }
  209. }
  210.  
  211. electrocasnice.RemoveAt(index);
  212. stergere_fisier(el[0]);
  213. Update_listBox();
  214. }
  215.  
  216. private void buttonTotalVanzari_Click(object sender, EventArgs e)
  217. {
  218. textBox1.Text = sum.ToString();
  219. }
  220.  
  221. }
  222. }
  223.  
  224.  
  225. ==========================================
  226.  
  227.  
  228. using System;
  229. using System.Collections.Generic;
  230. using System.ComponentModel;
  231. using System.Data;
  232. using System.Drawing;
  233. using System.IO;
  234. using System.Linq;
  235. using System.Text;
  236. using System.Threading.Tasks;
  237. using System.Windows.Forms;
  238.  
  239. namespace BungetPetru
  240. {
  241. public partial class LoginForm : Form
  242. {
  243.  
  244. public LoginForm()
  245. {
  246. InitializeComponent();
  247. }
  248.  
  249. private void button1_Click(object sender, EventArgs e)
  250. {
  251.  
  252. timer1.Tick += Timer1_Tick;
  253. timer1.Interval = 100;
  254.  
  255.  
  256. StreamReader sr = new StreamReader("users.txt");
  257. String line = "";
  258. while ((line = sr.ReadLine()) != null)
  259. {
  260. string[] el = line.Split(';');
  261. string username = el[0];
  262. string password = el[1];
  263.  
  264. if ((textBox1.Text == username) && textBox2.Text == password)
  265. {
  266.  
  267. progressBar1.Minimum = 0;
  268. progressBar1.Maximum = 20;
  269. progressBar1.Value = 0;
  270.  
  271.  
  272. timer1.Start();
  273. }
  274. }
  275. sr.Close();
  276. }
  277.  
  278. private void Timer1_Tick(object sender, EventArgs e)
  279. {
  280. if(progressBar1.Value < progressBar1.Maximum)
  281. {
  282. progressBar1.Value++;
  283. }
  284. if (progressBar1.Value == progressBar1.Maximum)
  285. {
  286. timer1.Stop();
  287. this.Hide();
  288. Form1 f = new Form1();
  289. //f.Activate();
  290. f.Show();
  291. }
  292. }
  293. }
  294. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement