Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ///Echipament.cs
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace AndricsakAlexandru_MTPT
- {
- class Echipament
- {
- private int nr_inv;
- private string model;
- private int an;
- private string categorie;
- private string nume;
- private string cnp;
- public Echipament(int nr_inv, string model, int an, string categorie, string nume, string cnp)
- {
- this.nr_inv = nr_inv;
- this.model = model;
- this.an = an;
- this.categorie = categorie;
- this.nume = nume;
- this.cnp = cnp;
- }
- public int Nr_inv { get => nr_inv; set => nr_inv = value; }
- public string Model { get => model; set => model = value; }
- public int An { get => an; set => an = value; }
- public string Categorie { get => categorie; set => categorie = value; }
- public string Nume { get => nume; set => nume = value; }
- public string Cnp { get => cnp; set => cnp = value; }
- public string toString()
- {
- return nr_inv + ", " + model + ", " + an + ", " + categorie + ", " + nume + ", " + cnp;
- }
- }
- }
- ///
- Form1.cs
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Globalization;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace AndricsakAlexandru_MTPT
- {
- public partial class Form1 : Form
- {
- List<Echipament> echipamente = new List<Echipament>();
- ErrorProvider errorCnp = new ErrorProvider();
- public Form1()
- {
- InitializeComponent();
- }
- private void btnAdauga_Click(object sender, EventArgs e)
- {
- int nr_inv = int.Parse(txtNrInv.Text);
- string model = txtModel.Text;
- int an = int.Parse(txtAn.Text);
- string categorie = cbCategorie.SelectedItem.ToString();
- string nume = txtNume.Text;
- string cnp = txtCnp.Text;
- string birthday = cnp.Substring(1, 6);
- DateTime datetest;
- if(cnp.Length.Equals(13) && DateTime.TryParseExact(birthday,"yyMMdd",CultureInfo.InvariantCulture,DateTimeStyles.None,out datetest))
- {
- Echipament ech = new Echipament(nr_inv, model, an, categorie, nume, cnp);
- echipamente.Add(ech);
- Button btnEch = new Button();
- btnEch.Text = model;
- btnEch.Height = 30;
- btnEch.Width = 80;
- btnEch.Click += BtnEch_Click;
- switch (categorie)
- {
- case "Calculator":
- flpCalculator.Controls.Add(btnEch);
- break;
- case "Imprimanta":
- flpImprimanta.Controls.Add(btnEch);
- break;
- case "Periferice":
- flpPeriferice.Controls.Add(btnEch);
- break;
- case "Televizoare":
- flpTelevizoare.Controls.Add(btnEch);
- break;
- case "Mobilier":
- flpMobilier.Controls.Add(btnEch);
- break;
- case "Electronice":
- flpElectronice.Controls.Add(btnEch);
- break;
- }
- }
- else
- {
- errorCnp.SetError(txtCnp,"Cnp-ul nu contine 13 cifre/Data nasterii nu e valida");
- }
- }
- private void BtnEch_Click(object sender, EventArgs e)
- {
- Button btn = (Button)sender;
- foreach(Echipament ech in echipamente)
- {
- if(btn.Text.Equals(ech.Model))
- {
- lbAfisare.Items.Add(ech.toString());
- }
- }
- }
- private void btnSalveaza_Click(object sender, EventArgs e)
- {
- foreach (Echipament ech in echipamente)
- {
- switch (ech.Categorie)
- {
- case "Calculator":
- Directory.CreateDirectory("D:\\Calculatoare").ToString();
- StreamWriter swC = new StreamWriter("D:\\Calculatoare\\" + ech.Model+".txt", append: true);
- swC.WriteLine(ech.Nr_inv);
- swC.WriteLine(ech.Model);
- swC.WriteLine(ech.An);
- swC.WriteLine(ech.Categorie);
- swC.WriteLine(ech.Nume);
- swC.WriteLine(ech.Cnp);
- swC.WriteLine("-------------");
- swC.Close();
- break;
- case "Imprimanta":
- Directory.CreateDirectory("D:\\Imprimante").ToString();
- StreamWriter swI = new StreamWriter("D:\\Imprimante\\" + ech.Model + ".txt", append: true);
- swI.WriteLine(ech.Nr_inv);
- swI.WriteLine(ech.Model);
- swI.WriteLine(ech.An);
- swI.WriteLine(ech.Categorie);
- swI.WriteLine(ech.Nume);
- swI.WriteLine(ech.Cnp);
- swI.WriteLine("-------------");
- swI.Close();
- break;
- case "Periferice":
- Directory.CreateDirectory("D:\\Periferice").ToString();
- StreamWriter swP = new StreamWriter("D:\\Periferice\\" + ech.Model + ".txt", append: true);
- swP.WriteLine(ech.Nr_inv);
- swP.WriteLine(ech.Model);
- swP.WriteLine(ech.An);
- swP.WriteLine(ech.Categorie);
- swP.WriteLine(ech.Nume);
- swP.WriteLine(ech.Cnp);
- swP.WriteLine("-------------");
- swP.Close();
- break;
- case "Televizoare":
- Directory.CreateDirectory("D:\\Televizoare").ToString();
- StreamWriter swT = new StreamWriter("D:\\Televizoare\\" + ech.Model + ".txt", append: true);
- swT.WriteLine(ech.Nr_inv);
- swT.WriteLine(ech.Model);
- swT.WriteLine(ech.An);
- swT.WriteLine(ech.Categorie);
- swT.WriteLine(ech.Nume);
- swT.WriteLine(ech.Cnp);
- swT.WriteLine("-------------");
- swT.Close();
- break;
- case "Mobilier":
- Directory.CreateDirectory("D:\\Mobilier").ToString();
- StreamWriter swM = new StreamWriter("D:\\Mobilier\\" + ech.Model + ".txt", append: true);
- swM.WriteLine(ech.Nr_inv);
- swM.WriteLine(ech.Model);
- swM.WriteLine(ech.An);
- swM.WriteLine(ech.Categorie);
- swM.WriteLine(ech.Nume);
- swM.WriteLine(ech.Cnp);
- swM.WriteLine("-------------");
- swM.Close();
- break;
- case "Electronice":
- Directory.CreateDirectory("D:\\Electronice").ToString();
- StreamWriter swE = new StreamWriter("D:\\Electronice\\" + ech.Model + ".txt", append: true);
- swE.WriteLine(ech.Nr_inv);
- swE.WriteLine(ech.Model);
- swE.WriteLine(ech.An);
- swE.WriteLine(ech.Categorie);
- swE.WriteLine(ech.Nume);
- swE.WriteLine(ech.Cnp);
- swE.WriteLine("-------------");
- swE.Close();
- break;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement