using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Collections; namespace VP { public partial class VehicleTravel : Form { private bool RefreshOnce = false; private string type; private string model; private string brand; private string isBooked; private string price; public VehicleTravel(string type, string model, string brand, string isBooked, string price) { InitializeComponent(); this.type = type; this.model = model; this.brand = brand; this.isBooked = isBooked; this.price = price; } private void VehicleTravel_Load(object sender, EventArgs e) { label6.Text = type; label7.Text = model; label8.Text = brand; label9.Text = isBooked.ToString(); label10.Text = price.ToString(); CostLabel.Text = ""; listView1_SelectedIndexChanged(null, null); } private void listView1_SelectedIndexChanged(object sender, EventArgs e) { if (RefreshOnce == false) { listView1.Items.Clear(); AllTravel all = Model.getAllTravel(); ArrayList liste = all.getAllTravel(); foreach (Travel t in liste) { if ((t.getVehicle().getType().CompareTo(this.type)==0) && (t.getVehicle().getNom().CompareTo(this.model) == 0) && (t.getVehicle().getMarque().CompareTo(this.brand) == 0)) { // Ici j'ai trouvé dans tous les voyages, un voyage qui correspond à la personne, // On l'ajoute à la liste /**************************************************************/ /* On met la date dans le format qu'on veut (sans les heures) */ /**************************************************************/ string shortDate1; string shortDate2; DateTime dt1 = new DateTime(); DateTime dt2 = new DateTime(); dt1 = t.getDateD(); dt2 = t.getDateF(); shortDate1 = dt1.ToShortDateString(); shortDate2 = dt2.ToShortDateString(); /**************************************************************/ string[] travel = new string[] { t.getDestination(), t.getDuree().ToString(), shortDate1, shortDate2, t.getKm().ToString() }; ListViewItem item = new ListViewItem(travel); listView1.Items.Add(item); } } RefreshOnce = true; } // On affiche le cout du voyage selectionne dans le Label : // On récupère le voyage sélectionné et on l'envoie à la nouvelle fenêtre ListView.SelectedListViewItemCollection ligne = listView1.SelectedItems; string km = ""; foreach (ListViewItem item in ligne) { km = item.SubItems[4].Text; } // Calcule cout int kms = 0; int.TryParse(km, out kms); int prixparkm = 0; int.TryParse(price, out prixparkm); int calcule = kms * prixparkm; // Affichage du cout CostLabel.Text = calcule.ToString(); } } }