Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections;
- 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 BungetPetru
- {
- public partial class Form1 : Form
- {
- public static int id = 0;
- public static float sum = 0;
- private List<Electrocasnice> electrocasnice = new List<Electrocasnice>();
- public Form1()
- {
- InitializeComponent();
- citire_fiser();
- }
- public void Update_listBox()
- {
- listBox1.Items.Clear();
- foreach(Electrocasnice item in electrocasnice)
- {
- AparatFoto af = (AparatFoto)item;
- string text = af.toFileString();
- listBox1.Items.Add(text);
- }
- }
- public void citire_fiser()
- {
- string path = "electrocasnice.txt";
- StreamReader sr = new StreamReader(path);
- try
- {
- string line = "";
- while ((line = sr.ReadLine()) != null)
- {
- string[] el = line.Split(';');
- DateTime date = Convert.ToDateTime(el[2]);
- DateTime newDate = new DateTime(date.Year, date.Month, date.Day);
- AparatFoto af = new AparatFoto(el[1], newDate, (float)Convert.ToDouble(el[4]), Convert.ToInt32(el[5]), el[3]);
- electrocasnice.Add(af);
- }
- sr.Close();
- Update_listBox();
- }
- catch(Exception ex)
- {
- sr.Close();
- }
- Update_listBox();
- }
- public void adaugare_fisier(string text)
- {
- string path = "electrocasnice.txt";
- StreamWriter sw = new StreamWriter(path, true);
- sw.WriteLine(text);
- sw.Close();
- }
- public void stergere_fisier(string id)
- {
- string path = "electrocasnice.txt";
- StreamReader sr = new StreamReader(path);
- string line = "";
- string newText = "";
- string[] arr = new string[100];
- int ind = 0;
- while ((line = sr.ReadLine()) != null)
- {
- if (line.Split(';')[0] == id)
- {
- //newText += "\n";
- //continue;
- }
- else
- {
- //newText += "\n";
- //newText += line;
- arr[ind++] = line;
- }
- }
- sr.Close();
- try
- {
- StreamWriter sw = new StreamWriter("electrocasnice.txt");
- //sw.WriteLine(newText);
- for (int j = 0; j < arr.Length; j++)
- {
- sw.WriteLine(arr[j]);
- }
- sw.Close();
- }
- catch (Exception ex)
- {
- }
- }
- private void buttonAdaugare_Click(object sender, EventArgs e)
- {
- try
- {
- string denumire = textBoxDenumire.Text;
- DateTime data = dateTimePicker.Value;
- int stoc = Convert.ToInt32(textBoxStoc.Text);
- float pret = (float)Convert.ToDouble(textBoxPret.Text);
- string tip = comboBoxTip.Text;
- AparatFoto af = new AparatFoto(denumire, data, pret, stoc, tip);
- electrocasnice.Add(af);
- Update_listBox();
- string text = af.toFileString();
- adaugare_fisier(text);
- }
- catch
- {
- //MessageBox.Show("Adaugare esuata!");
- }
- }
- class CompararePret : IComparer<AparatFoto>
- {
- public int Compare(AparatFoto x, AparatFoto y)
- {
- if (x.getPret() > y.getPret()) { return 1; }
- else if (x.getPret() < y.getPret()) { return -1; }
- else return 0;
- }
- }
- class ComparareStoc : IComparer<AparatFoto>
- {
- public int Compare(AparatFoto x, AparatFoto y)
- {
- if (x.getStoc() > y.getStoc()) { return 1; }
- else if (x.getStoc() < y.getStoc()) { return -1; }
- else return 0;
- }
- }
- private void buttonOrdonare_Click(object sender, EventArgs e)
- {
- List<AparatFoto> aparate = new List<AparatFoto>();
- foreach(Electrocasnice el in electrocasnice)
- {
- aparate.Add((AparatFoto)el);
- }
- if(checkBoxPret.Checked)
- {
- aparate.Sort(new CompararePret());
- listBox2.Items.Clear();
- foreach (AparatFoto item in aparate)
- {
- listBox2.Items.Add(item.toFileString());
- }
- }
- if (checkBoxStoc.Checked)
- {
- aparate.Sort(new ComparareStoc());
- listBox2.Items.Clear();
- foreach (AparatFoto item in aparate)
- {
- listBox2.Items.Add(item.toFileString());
- }
- }
- }
- private void buttonVanzare_Click(object sender, EventArgs e)
- {
- string line = listBox1.SelectedItem.ToString();
- string[] el = line.Split(';');
- int index = 0;
- foreach(Electrocasnice item in electrocasnice)
- {
- if (item.getId() == el[0])
- {
- index = electrocasnice.IndexOf(item);
- AparatFoto af = (AparatFoto)item;
- sum += af.getPret();
- }
- }
- electrocasnice.RemoveAt(index);
- stergere_fisier(el[0]);
- Update_listBox();
- }
- private void buttonTotalVanzari_Click(object sender, EventArgs e)
- {
- textBox1.Text = sum.ToString();
- }
- }
- }
- ==========================================
- 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 BungetPetru
- {
- public partial class LoginForm : Form
- {
- public LoginForm()
- {
- InitializeComponent();
- }
- private void button1_Click(object sender, EventArgs e)
- {
- timer1.Tick += Timer1_Tick;
- timer1.Interval = 100;
- StreamReader sr = new StreamReader("users.txt");
- String line = "";
- while ((line = sr.ReadLine()) != null)
- {
- string[] el = line.Split(';');
- string username = el[0];
- string password = el[1];
- if ((textBox1.Text == username) && textBox2.Text == password)
- {
- progressBar1.Minimum = 0;
- progressBar1.Maximum = 20;
- progressBar1.Value = 0;
- timer1.Start();
- }
- }
- sr.Close();
- }
- private void Timer1_Tick(object sender, EventArgs e)
- {
- if(progressBar1.Value < progressBar1.Maximum)
- {
- progressBar1.Value++;
- }
- if (progressBar1.Value == progressBar1.Maximum)
- {
- timer1.Stop();
- this.Hide();
- Form1 f = new Form1();
- //f.Activate();
- f.Show();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement