Guest User

CORNCUCIOCO

a guest
Jan 12th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 28.90 KB | None | 0 0
  1. private void FormLogin_Load(object sender, EventArgs e)
  2.         {
  3.             button1.Enabled = false;
  4.         }
  5.  
  6.         private void textBox2_TextChanged(object sender, EventArgs e)
  7.         {
  8.             if (textBox1.TextLength > 0 && textBox2.TextLength>0)
  9.             {
  10.                 button1.Enabled = true;
  11.             }
  12.             else
  13.             {
  14.                 button1.Enabled = false;
  15.             }
  16.         }
  17.  
  18.         private void timer1_Tick(object sender, EventArgs e)
  19.         {
  20.             progressBar1.Value++;
  21.             if (progressBar1.Value == progressBar1.Maximum)
  22.             {
  23.                 timer1.Stop();
  24.                 this.DialogResult = DialogResult.OK;
  25.             }
  26.         }
  27.  
  28.         private void button1_Click(object sender, EventArgs e)
  29.         {
  30.             timer1.Start();
  31.         }
  32.     }
  33.  
  34. PP:
  35.  private void Form1_Load(object sender, EventArgs e)
  36.         {
  37.             FormLogin log = new FormLogin();
  38.             if (log.ShowDialog() == DialogResult.Cancel)
  39.             {
  40.                 this.Close();
  41.             }
  42.            
  43.             /* DateTime data = Convert.ToDateTime("0/0/0");
  44.              listBox1.Items.Add(data);
  45.              */
  46.             parent1.Text = "An I";
  47.             treeView1.Nodes.Add(parent1);
  48.  
  49.   TreeNode child;
  50.  
  51. f (m.An == "I")
  52.                 {
  53.                     child = new TreeNode();
  54.                     child.Text = m.Denumire;
  55.                     parent1.Nodes.Add(child);
  56.                     foreach(Prezentare prez in lista_p)
  57.                     {
  58.                         TreeNode child2 = new TreeNode();
  59.                         child2.Text = prez.Nr_prezentare;
  60.                         child.Nodes.Add(child2);
  61.                     }
  62.                    
  63.  
  64.                 }
  65.  private void button1_Click(object sender, EventArgs e)
  66.         {
  67.            
  68.             foreach (Materie mat in lista_m)
  69.             {
  70.                 int nr_rest_mat = 0;
  71.                 foreach (Prezentare pr in mat.Prezentari)
  72.                 {
  73.                    
  74.                     if (pr.Nota_examen < 5)
  75.                     {
  76.                         nr_rest_mat++;
  77.                        
  78.                     }
  79.                 }
  80.                 if (nr_rest_mat >= 2)
  81.                 {
  82.                     listBox1.Items.Add(mat.Denumire);
  83.                 }
  84.             }
  85.         }
  86.  
  87.  
  88. CLASS:
  89.         private string denumire;
  90.           private List<Prezentare> prezentari;
  91.  
  92.         public Materie (string denumire, string an, double nota_lab, List<Prezentare> prezentari)
  93.         {
  94.             this.denumire = denumire;
  95.             this.an = an;
  96.             this.nota_lab = nota_lab;
  97.             this.prezentari = prezentari;
  98.             if (calculMedie() != 0)
  99.             {
  100.                 nota_finala = (nota_lab + calculMedie()) / 2;
  101.             }
  102.         }
  103.         [Description("Denumire materie"), Category("Informatii materie")]
  104.         public string Denumire
  105.         {
  106.             get { return denumire; }
  107.         }
  108.  
  109.  
  110. TEST2::
  111. namespace Test_florarie
  112. {
  113.     public partial class Form1 : Form
  114.     {
  115.         private List<Floare> lista = new List<Floare>();
  116.         private double total_vanzari = 0;
  117.         System.IO.StreamReader file = new System.IO.StreamReader("fisier_plante.txt");
  118.         private string linie;
  119.         public Form1()
  120.         {
  121.             InitializeComponent();
  122.             listBox1.MouseDoubleClick += new MouseEventHandler(listBox1_DoubleClick);
  123.         }
  124.  
  125.         private void button1_Click(object sender, EventArgs e)
  126.         {
  127.             Floare f = new Floare(dateTimePicker1.Value, comboBox1.Text, Convert.ToDouble(textBox2.Text), textBox1.Text);
  128.             lista.Add(f);
  129.             listBox1.Items.Add(textBox1.Text);
  130.         }
  131.  
  132.         private void listBox1_DoubleClick(object sender, MouseEventArgs e)
  133.         {
  134.             foreach (Floare f in lista)
  135.             {
  136.                 if (listBox1.SelectedItem.ToString() == f.Denumire)
  137.                 {
  138.                     propertyGrid1.SelectedObject = f;
  139.                     if (f.calculZile() >= 3)
  140.                     {
  141.                         if (f.Categorie == "Flori taiate")
  142.                         {
  143.                             MessageBox.Show("Floarea este ofilita!!!", "Alerta", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
  144.      
  145.                         }
  146.  
  147.                         if (f.Categorie == "Plante in ghiveci")
  148.                         {
  149.                             if (MessageBox.Show("Floarea trebuie udata!!!\n Doriti sa o udati?", "Alerta", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == DialogResult.Yes)
  150.                             {
  151.                                 f.Data = DateTime.Now;
  152.                             }
  153.                         }
  154.                     }
  155.                 }
  156.             }
  157.         }
  158.  
  159.             private void button3_Click(object sender, EventArgs e)
  160.             {
  161.                 listBox1.Items.Add("\n");
  162.                 foreach (Floare f in lista)
  163.                 {
  164.                     if (string.Compare(f.Denumire, textBox3.Text) == 0)
  165.                     {
  166.                         listBox1.Items.Add(f.Denumire);
  167.                     }
  168.                 }
  169.             }
  170.  
  171.             private void button4_Click(object sender, EventArgs e)
  172.             {
  173.                 listBox1.SelectionMode = SelectionMode.One;
  174.                 if (this.listBox1.SelectedIndex >= 0)
  175.                 {
  176.                     foreach (Floare f in lista)
  177.                     {
  178.                         if (listBox1.SelectedItem.ToString() == f.Denumire)
  179.                         {
  180.                             total_vanzari += f.Pret;
  181.                             this.listBox1.Items.RemoveAt(this.listBox1.SelectedIndex);
  182.                             lista.Remove(f);
  183.                             break;
  184.                         }
  185.                     }
  186.                 }
  187.             }
  188.  
  189.             private void button5_Click(object sender, EventArgs e)
  190.             {
  191.                 textBox4.Clear();
  192.                 textBox4.AppendText(total_vanzari.ToString());
  193.             }
  194.  
  195.         private void button2_Click(object sender, EventArgs e)
  196.         {
  197.             while ((linie = file.ReadLine()) != null)
  198.             {
  199.                 String[] parts = linie.Split(';');
  200.  
  201.                 Floare f = new Floare(Convert.ToDateTime(parts[1]), parts[2], Convert.ToDouble(parts[3]), parts[0]);
  202.                 lista.Add(f);
  203.                 listBox1.Items.Add(f.Denumire);
  204.             }
  205.         }
  206.  
  207.         private void Form1_Load(object sender, EventArgs e)
  208.         {
  209.             Login log = new Login();
  210.             if (log.ShowDialog() == DialogResult.Cancel)
  211.                 this.Close();
  212.         }
  213.     }
  214.     }
  215.  
  216. TETS3::
  217. namespace Test_studenti_carti
  218. {
  219.     public partial class Form1 : Form
  220.     {
  221.         System.IO.StreamReader file1 = new System.IO.StreamReader("fisier_studenti.txt");
  222.         System.IO.StreamReader file2 = new System.IO.StreamReader("fisier_carti.txt");
  223.         private String linie1;
  224.         private String linie2;
  225.         private List<Student> lista_s = new List<Student>();
  226.  
  227.         TreeNode parent1;
  228.         TreeNode parent2;
  229.         TreeNode parent3;
  230.         TreeNode parent4;
  231.  
  232.         TreeNode nodSelectat = null;
  233.         //int indexNodSelectat = 0;
  234.  
  235.         public Form1()
  236.         {
  237.             InitializeComponent();
  238.         }
  239.  
  240.         private void Form1_Load(object sender, EventArgs e)
  241.         {
  242.             FormLogin log = new FormLogin();
  243.             if(log.ShowDialog() == DialogResult.Cancel)
  244.             {
  245.                 this.Close();
  246.             }
  247.            
  248.             //creare noduri in TreeView
  249.  
  250.             parent1 = new TreeNode();
  251.             parent1.Text = "Anul I";
  252.             treeView1.Nodes.Add(parent1);
  253.  
  254.             parent2 = new TreeNode();
  255.             parent2.Text = "Anul II";
  256.             treeView1.Nodes.Add(parent2);
  257.  
  258.             parent3 = new TreeNode();
  259.             parent3.Text = "Anul III";
  260.             treeView1.Nodes.Add(parent3);
  261.  
  262.             parent4 = new TreeNode();
  263.             parent4.Text = "Anul IV";
  264.             treeView1.Nodes.Add(parent4);
  265.  
  266.  
  267.  
  268.             //citire din fisier
  269.  
  270.             while ((linie1 = file1.ReadLine()) != null)
  271.             {
  272.                 string[] parts1 = linie1.Split(';');
  273.                 List<Carte> lista_c = new List<Carte>();
  274.                 while ((linie2 = file2.ReadLine()) != null)
  275.                 {
  276.                    
  277.                     string[] parts2 = linie2.Split(';');
  278.                     if (parts1[0] == parts2[0])
  279.                     {
  280.                         Carte c = new Carte(parts2[1], parts2[2], parts2[3], Convert.ToDateTime(parts2[4]), Convert.ToDateTime(parts2[5]));
  281.  
  282.                         lista_c.Add(c);
  283.  
  284.                     }
  285.                 }
  286.                 file2.DiscardBufferedData();
  287.                 file2.BaseStream.Seek(0, System.IO.SeekOrigin.Begin);
  288.                 Student s = new Student(parts1[1], parts1[2], parts1[3], parts1[4], Convert.ToDateTime(parts1[5]), lista_c);
  289.                 lista_s.Add(s);
  290.  
  291.                 //adaugare student in TreeView in functie de an
  292.  
  293.                 TreeNode child = new TreeNode();
  294.              
  295.  
  296.                 if (s.An == "I")
  297.                 {
  298.                    
  299.                     child.Text = s.Nume;
  300.                     parent1.Nodes.Add(child);
  301.                     foreach (Carte car in lista_c)
  302.                     {
  303.                         TreeNode child2 = new TreeNode();
  304.                         child2.Text = car.Titlu;
  305.                         child.Nodes.Add(child2);
  306.                     }
  307.                 }
  308.  
  309.                 if (s.An == "II")
  310.                 {
  311.                    
  312.                     child.Text = s.Nume;
  313.                     parent2.Nodes.Add(child);
  314.                     foreach (Carte car in lista_c)
  315.                     {
  316.                         TreeNode child2 = new TreeNode();
  317.                         child2.Text = car.Titlu;
  318.                         child.Nodes.Add(child2);
  319.                     }
  320.                 }
  321.  
  322.                 if (s.An == "III")
  323.                 {
  324.                    
  325.                     child.Text = s.Nume;
  326.                     parent3.Nodes.Add(child);
  327.                     foreach (Carte car in lista_c)
  328.                     {
  329.                         TreeNode child2 = new TreeNode();
  330.                         child2.Text = car.Titlu;
  331.                         child.Nodes.Add(child2);
  332.                     }
  333.                 }
  334.  
  335.                 if (s.An == "IV")
  336.                 {
  337.                    
  338.                     child.Text = s.Nume;
  339.                     parent4.Nodes.Add(child);
  340.                     foreach (Carte car in lista_c)
  341.                     {
  342.                         TreeNode child2 = new TreeNode();
  343.                         child2.Text = car.Titlu;
  344.                         child.Nodes.Add(child2);
  345.                     }
  346.                 }
  347.  
  348.             }
  349.            
  350.         }
  351.  
  352.         private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
  353.         {
  354.             nodSelectat = e.Node;
  355.             foreach (Student stud in lista_s)
  356.             {
  357.                
  358.                     if (e.Node.Text == stud.Nume)
  359.                     {
  360.                         //indexNodSelectat = e.Node.Index;
  361.                         propertyGrid1.SelectedObject = stud;
  362.                     break;
  363.  
  364.                     }
  365.                     foreach (Carte car in stud.Carti)
  366.                     {
  367.  
  368.                             if (e.Node.Text == car.Titlu)
  369.                             {
  370.                                 //indexNodSelectat = e.Node.Index;
  371.                                 propertyGrid1.SelectedObject = car;
  372.                                 if (car.calculIntarziere() > 0)
  373.                                 {
  374.                                     propertyGrid1.ViewForeColor = Color.Red;
  375.                                     break;
  376.                                 }
  377.                                 else
  378.                                 {
  379.                                     propertyGrid1.ViewForeColor = Color.Black;
  380.                                 }
  381.                            
  382.                             }
  383.  
  384.                     }
  385.                    
  386.                
  387.             }
  388.  
  389.         }
  390.  
  391.         private void button2_Click(object sender, EventArgs e)
  392.         {
  393.             listBox1.Items.Clear();
  394.             foreach (Student stud in lista_s)
  395.             {
  396.                 int nr_carti_termen_depasit = 0;
  397.                 foreach (Carte carte in stud.Carti)
  398.                 {
  399.                     if (carte.calculIntarziere() > 0)
  400.                     {
  401.                         nr_carti_termen_depasit++;
  402.                     }
  403.                 }
  404.  
  405.                 if (nr_carti_termen_depasit > 0)
  406.                 {
  407.                     listBox1.Items.Add(stud.Nume + " " + nr_carti_termen_depasit + " carti");
  408.                    
  409.                 }
  410.             }
  411.         }
  412.  
  413.         private void button1_Click(object sender, EventArgs e)
  414.         {
  415.             foreach (Student stud in lista_s)
  416.             {
  417.                 foreach (Carte car in stud.Carti)
  418.                 {
  419.                     if (nodSelectat.Text == car.Titlu)
  420.                     {
  421.                         stud.Carti.Remove(car);
  422.                         treeView1.Nodes.Remove(nodSelectat);
  423.                         propertyGrid1.SelectedObject = null;
  424.                         break;
  425.                     }
  426.                 }
  427.             }
  428.         }
  429.     }
  430. }
  431. namespace Test_studenti_carti
  432. {
  433.     public partial class Form1 : Form
  434.     {
  435.         System.IO.StreamReader file1 = new System.IO.StreamReader("fisier_studenti.txt");
  436.         System.IO.StreamReader file2 = new System.IO.StreamReader("fisier_carti.txt");
  437.         private String linie1;
  438.         private String linie2;
  439.         private List<Student> lista_s = new List<Student>();
  440.  
  441.         TreeNode parent1;
  442.         TreeNode parent2;
  443.         TreeNode parent3;
  444.         TreeNode parent4;
  445.  
  446.         TreeNode nodSelectat = null;
  447.         //int indexNodSelectat = 0;
  448.  
  449.         public Form1()
  450.         {
  451.             InitializeComponent();
  452.         }
  453.  
  454.         private void Form1_Load(object sender, EventArgs e)
  455.         {
  456.             FormLogin log = new FormLogin();
  457.             if(log.ShowDialog() == DialogResult.Cancel)
  458.             {
  459.                 this.Close();
  460.             }
  461.            
  462.             //creare noduri in TreeView
  463.  
  464.             parent1 = new TreeNode();
  465.             parent1.Text = "Anul I";
  466.             treeView1.Nodes.Add(parent1);
  467.  
  468.             parent2 = new TreeNode();
  469.             parent2.Text = "Anul II";
  470.             treeView1.Nodes.Add(parent2);
  471.  
  472.             parent3 = new TreeNode();
  473.             parent3.Text = "Anul III";
  474.             treeView1.Nodes.Add(parent3);
  475.  
  476.             parent4 = new TreeNode();
  477.             parent4.Text = "Anul IV";
  478.             treeView1.Nodes.Add(parent4);
  479.  
  480.  
  481.  
  482.             //citire din fisier
  483.  
  484.             while ((linie1 = file1.ReadLine()) != null)
  485.             {
  486.                 string[] parts1 = linie1.Split(';');
  487.                 List<Carte> lista_c = new List<Carte>();
  488.                 while ((linie2 = file2.ReadLine()) != null)
  489.                 {
  490.                    
  491.                     string[] parts2 = linie2.Split(';');
  492.                     if (parts1[0] == parts2[0])
  493.                     {
  494.                         Carte c = new Carte(parts2[1], parts2[2], parts2[3], Convert.ToDateTime(parts2[4]), Convert.ToDateTime(parts2[5]));
  495.  
  496.                         lista_c.Add(c);
  497.  
  498.                     }
  499.                 }
  500.                 file2.DiscardBufferedData();
  501.                 file2.BaseStream.Seek(0, System.IO.SeekOrigin.Begin);
  502.                 Student s = new Student(parts1[1], parts1[2], parts1[3], parts1[4], Convert.ToDateTime(parts1[5]), lista_c);
  503.                 lista_s.Add(s);
  504.  
  505.                 //adaugare student in TreeView in functie de an
  506.  
  507.                 TreeNode child = new TreeNode();
  508.              
  509.  
  510.                 if (s.An == "I")
  511.                 {
  512.                    
  513.                     child.Text = s.Nume;
  514.                     parent1.Nodes.Add(child);
  515.                     foreach (Carte car in lista_c)
  516.                     {
  517.                         TreeNode child2 = new TreeNode();
  518.                         child2.Text = car.Titlu;
  519.                         child.Nodes.Add(child2);
  520.                     }
  521.                 }
  522.  
  523.                 if (s.An == "II")
  524.                 {
  525.                    
  526.                     child.Text = s.Nume;
  527.                     parent2.Nodes.Add(child);
  528.                     foreach (Carte car in lista_c)
  529.                     {
  530.                         TreeNode child2 = new TreeNode();
  531.                         child2.Text = car.Titlu;
  532.                         child.Nodes.Add(child2);
  533.                     }
  534.                 }
  535.  
  536.                 if (s.An == "III")
  537.                 {
  538.                    
  539.                     child.Text = s.Nume;
  540.                     parent3.Nodes.Add(child);
  541.                     foreach (Carte car in lista_c)
  542.                     {
  543.                         TreeNode child2 = new TreeNode();
  544.                         child2.Text = car.Titlu;
  545.                         child.Nodes.Add(child2);
  546.                     }
  547.                 }
  548.  
  549.                 if (s.An == "IV")
  550.                 {
  551.                    
  552.                     child.Text = s.Nume;
  553.                     parent4.Nodes.Add(child);
  554.                     foreach (Carte car in lista_c)
  555.                     {
  556.                         TreeNode child2 = new TreeNode();
  557.                         child2.Text = car.Titlu;
  558.                         child.Nodes.Add(child2);
  559.                     }
  560.                 }
  561.  
  562.             }
  563.            
  564.         }
  565.  
  566.         private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
  567.         {
  568.             nodSelectat = e.Node;
  569.             foreach (Student stud in lista_s)
  570.             {
  571.                
  572.                     if (e.Node.Text == stud.Nume)
  573.                     {
  574.                         //indexNodSelectat = e.Node.Index;
  575.                         propertyGrid1.SelectedObject = stud;
  576.                     break;
  577.  
  578.                     }
  579.                     foreach (Carte car in stud.Carti)
  580.                     {
  581.  
  582.                             if (e.Node.Text == car.Titlu)
  583.                             {
  584.                                 //indexNodSelectat = e.Node.Index;
  585.                                 propertyGrid1.SelectedObject = car;
  586.                                 if (car.calculIntarziere() > 0)
  587.                                 {
  588.                                     propertyGrid1.ViewForeColor = Color.Red;
  589.                                     break;
  590.                                 }
  591.                                 else
  592.                                 {
  593.                                     propertyGrid1.ViewForeColor = Color.Black;
  594.                                 }
  595.                            
  596.                             }
  597.  
  598.                     }
  599.                    
  600.                
  601.             }
  602.  
  603.         }
  604.  
  605.         private void button2_Click(object sender, EventArgs e)
  606.         {
  607.             listBox1.Items.Clear();
  608.             foreach (Student stud in lista_s)
  609.             {
  610.                 int nr_carti_termen_depasit = 0;
  611.                 foreach (Carte carte in stud.Carti)
  612.                 {
  613.                     if (carte.calculIntarziere() > 0)
  614.                     {
  615.                         nr_carti_termen_depasit++;
  616.                     }
  617.                 }
  618.  
  619.                 if (nr_carti_termen_depasit > 0)
  620.                 {
  621.                     listBox1.Items.Add(stud.Nume + " " + nr_carti_termen_depasit + " carti");
  622.                    
  623.                 }
  624.             }
  625.         }
  626.  
  627.         private void button1_Click(object sender, EventArgs e)
  628.         {
  629.             foreach (Student stud in lista_s)
  630.             {
  631.                 foreach (Carte car in stud.Carti)
  632.                 {
  633.                     if (nodSelectat.Text == car.Titlu)
  634.                     {
  635.                         stud.Carti.Remove(car);
  636.                         treeView1.Nodes.Remove(nodSelectat);
  637.                         propertyGrid1.SelectedObject = null;
  638.                         break;
  639.                     }
  640.                 }
  641.             }
  642.         }
  643.     }
  644. }
  645.  
  646.  
  647.  
  648. TEST 4:::
  649. namespace MTP_L1
  650. {
  651.     public partial class Form1 : Form
  652.     {
  653.         public Form1()
  654.         {
  655.             InitializeComponent();
  656.         }
  657.  
  658.         private void Form1_Load(object sender, EventArgs e)
  659.         {
  660.  
  661.         }
  662.  
  663.         private List<Student> lista = new List<Student>();
  664.  
  665.         private void button1_Click(object sender, EventArgs e)
  666.         {
  667.             byte[] note = new byte[5];
  668.             note[0] = Convert.ToByte(comboBox2.Text);
  669.             note[1] = Convert.ToByte(comboBox3.Text);
  670.             note[2] = Convert.ToByte(comboBox4.Text);
  671.             note[3] = Convert.ToByte(comboBox5.Text);
  672.             note[4] = Convert.ToByte(comboBox6.Text);
  673.             Student s = new Student(Convert.ToByte(cmbAn.Text), note, txtNume.Text, (byte)numVarsta.Value);
  674.             lista.Add(s);
  675.             listBox1.Items.Add(s.AfisareStudent());
  676.  
  677.         }
  678.  
  679.         private void button3_Click(object sender, EventArgs e)
  680.         {
  681.             listBox1.Items.Add("\n");
  682.             ComparaMedie cm = new ComparaMedie();
  683.             lista.Sort(cm);
  684.             foreach (Student s in lista)
  685.                 listBox1.Items.Add(s.AfisareStudent());
  686.         }
  687.  
  688.         private void button2_Click(object sender, EventArgs e)
  689.         {
  690.             listBox1.Items.Add("\n");
  691.             ComparaNume cn = new ComparaNume();
  692.             lista.Sort(cn);
  693.             foreach (Student s in lista)
  694.                 listBox1.Items.Add(s.AfisareStudent());
  695.         }
  696.  
  697.         private void button4_Click(object sender, EventArgs e)
  698.         {
  699.             listBox1.Items.Add("\n");
  700.             byte an = Convert.ToByte(comboBox7.Text);
  701.             foreach (Student s in lista)
  702.                 if (s.AnStudiu == an)
  703.                     listBox1.Items.Add(s.AfisareStudent());
  704.  
  705.         }
  706.  
  707.         private void button5_Click(object sender, EventArgs e)
  708.         {
  709.             listBox1.Items.Add("\n");
  710.             foreach (Student s in lista)
  711.                 if (string.Compare(s.NumeStudent, textBox2.Text) == 0)
  712.                     listBox1.Items.Add(s.AfisareStudent());
  713.         }
  714.  
  715.         private void button6_Click(object sender, EventArgs e)
  716.         {
  717.             listBox1.SelectionMode = SelectionMode.MultiExtended;
  718.             if (this.listBox1.SelectedIndex >= 0)
  719.                 this.listBox1.Items.RemoveAt(this.listBox1.SelectedIndex);
  720.         }
  721.     }
  722. }
  723. namespace MTP_L1
  724. {
  725.     class ComparaMedie : IComparer<Student>
  726.     {
  727.         public int Compare(Student x, Student y)
  728.         {
  729.             if (x.Medie() > y.Medie())
  730.                 return 1;
  731.             else if (x.Medie() == y.Medie())
  732.                 return 0;
  733.             else
  734.                 return -1;
  735.         }
  736.     }
  737. }
  738.  
  739.  
  740.  
  741.  
  742. TEST5:::
  743.  
  744. namespace MTP_L2
  745. {
  746.     public partial class Form1 : Form
  747.     {
  748.         TreeNode parent1;
  749.         TreeNode parent2;
  750.         TreeNode parent3;
  751.         TreeNode parent4;
  752.  
  753.         TreeNode nodDeSters = null;
  754.         int indexDeSters = 0;
  755.         int index = 0;
  756.  
  757.         List<Persoana> agenda = new List<Persoana>();
  758.  
  759.  
  760.  
  761.         public Form1()
  762.         {
  763.             InitializeComponent();
  764.         }
  765.  
  766.         private void Form1_Load(object sender, EventArgs e)
  767.         {
  768.             parent1 = new TreeNode();
  769.             parent1.Text = "Prieteni";
  770.             parent1.ImageIndex = 1;
  771.             tvwAgenda.Nodes.Add(parent1);
  772.  
  773.             parent2 = new TreeNode();
  774.             parent2.Text = "Colegi";
  775.             parent2.ImageIndex = 2;
  776.             tvwAgenda.Nodes.Add(parent2);
  777.  
  778.             parent3 = new TreeNode();
  779.             parent3.Text = "Rude";
  780.             parent3.ImageIndex = 3;
  781.             tvwAgenda.Nodes.Add(parent3);
  782.  
  783.             parent4 = new TreeNode();
  784.             parent4.Text = "Diversi";
  785.             parent4.ImageIndex = 4;
  786.             tvwAgenda.Nodes.Add(parent4);
  787.  
  788.         }
  789.  
  790.         private void buttonAdauga_Click(object sender, EventArgs e)
  791.         {
  792.             if (agenda.Exists(x => x.Nume.Equals(textBoxNume.Text)))
  793.             {
  794.                 MessageBox.Show("Persoana pe care doriti sa o introduceti exista deja in agenda", "Eroare", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
  795.             }
  796.               else
  797.             {
  798.                 index++;
  799.  
  800.                 Persoana p = new Persoana(index, textBoxNume.Text, dateTimePicker1.Value, textBoxTelefon.Text, textBoxAdresa.Text, (Categorie)comboBoxCategorie.SelectedIndex);
  801.  
  802.                 agenda.Add(p);
  803.  
  804.                 TreeNode child = new TreeNode();
  805.  
  806.                 if (comboBoxCategorie.Text == "Prieteni")
  807.                 {
  808.                     child.Name = index.ToString();
  809.                     child.Text = textBoxNume.Text;
  810.                     child.ImageIndex = 1;
  811.                     parent1.Nodes.Add(child);
  812.                 }
  813.                 if (comboBoxCategorie.Text == "Colegi")
  814.                 {
  815.                     child.Name = index.ToString();
  816.                     child.Text = textBoxNume.Text;
  817.                     child.ImageIndex = 2;
  818.                     parent2.Nodes.Add(child);
  819.                 }
  820.                 if (comboBoxCategorie.Text == "Rude")
  821.                 {
  822.                     child.Name = index.ToString();
  823.                     child.Text = textBoxNume.Text;
  824.                     child.ImageIndex = 3;
  825.                     parent3.Nodes.Add(child);
  826.                 }
  827.                 if (comboBoxCategorie.Text == "Diversi")
  828.                 {
  829.                     child.Name = index.ToString();
  830.                     child.Text = textBoxNume.Text;
  831.                     child.ImageIndex = 4;
  832.                     parent4.Nodes.Add(child);
  833.                 }
  834.  
  835.             }
  836.  
  837.         }
  838.  
  839.         private void tvwAgenda_AfterSelect(object sender, TreeViewEventArgs e)
  840.         {
  841.             nodDeSters = e.Node; //pentru selectia nodului de sters
  842.             foreach (Persoana p in agenda)
  843.             {
  844.                 if (e.Node.Text == p.Nume)
  845.                 {
  846.                     indexDeSters = Convert.ToInt16(e.Node.Name); //retine indexul nodului selectat
  847.                     propertyGrid1.SelectedObject = p;
  848.                     break;
  849.                 }
  850.  
  851.             }
  852.         }
  853.  
  854.         private void buttonCauta_Click(object sender, EventArgs e)
  855.         {
  856.             foreach (Persoana p in agenda)
  857.             {
  858.                 if (textBoxCautare.Text == p.Nume)
  859.                 {
  860.                     propertyGrid1.SelectedObject = p;
  861.                     break;
  862.                 }
  863.  
  864.             }
  865.         }
  866.  
  867.         private void buttonSterge_Click(object sender, EventArgs e)
  868.         {
  869.  
  870.             foreach (Persoana p in agenda)
  871.             {
  872.                 if (indexDeSters == p.Index)
  873.                 {
  874.                     if (MessageBox.Show("Doriti sa stergeti persoana [" + p.Nume + "]?", "Intrebare", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.Yes)
  875.                     {
  876.                         agenda.Remove(p); //sterge din lista
  877.                         tvwAgenda.Nodes.Remove(nodDeSters); //sterge nodul din treeview
  878.                         propertyGrid1.SelectedObject = null; //sterge informatiile din propertygrid
  879.                         break;
  880.                     }
  881.                 }
  882.             }
  883.         }
  884.  
  885.         string dir = Application.StartupPath;
  886.         private void buttonSalveazaFisier_Click(object sender, EventArgs e)
  887.         {
  888.  
  889.             StreamWriter sw = new StreamWriter(dir + "\\agenda.txt", true);
  890.  
  891.             foreach (Persoana p in agenda)
  892.             {
  893.                 if (indexDeSters == p.Index) //indexul nodului selectat
  894.                 {
  895.                     sw.WriteLine("Nume: " + p.Nume);
  896.                     sw.WriteLine("Categorie: " + p.Categorie.ToString());
  897.                     sw.WriteLine("Data nasterii: " + p.DataNasterii);
  898.                     sw.WriteLine("Telefon: " + p.Telefon);
  899.                     sw.WriteLine("Adresa: " + p.Adresa);
  900.                     sw.WriteLine("----------------------------------------");
  901.                     sw.Close();
  902.                     break;
  903.                 }
  904.             }
  905.  
  906.             //Process.Start("notepad.exe", dir + "\\agenda.txt"); // deschide fisierul de fiecare data cand salvez o persoana in el
  907.         }
  908.  
  909.     }
  910. }
  911.  
  912.  
  913.  
  914. namespace MTP_L2
  915. {
  916.     enum Categorie : int
  917.     {
  918.         Prieteni,
  919.         Colegi,
  920.         Rude,
  921.         Diversi
  922.     };
  923. }
Advertisement
Add Comment
Please, Sign In to add comment