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; private int idVehicle; private Vehicle vehicleForm; public VehicleTravel(int id, 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; this.idVehicle = id; } 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().getId() == idVehicle) { // 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(); } //_________________________________________________ //méthode : calculer le taux d'occupation d'un véhicule sur une période donnée //date : 26/11/2011 //_________________________________________________ public double CalculateRate(DateTime d, DateTime f) { string temp; DateTime temp2; int occupation = 0; bool isbusy = false; TimeSpan period = f - d; temp = period.ToString(); int nbJour = Convert.ToInt32(temp); for (int i = 0; i < nbJour; i++) { temp2 = d.AddDays(1); isbusy = vehicleForm.estLibre(d, temp2); if (isbusy == true) { occupation++; } } return (double)occupation / nbJour; } private void dateTimePicker1_ValueChanged(object sender, EventArgs e) { costRateLabel.Text = Convert.ToString(CalculateRate(dateTimePicker1.Value, dateTimePicker2.Value)); } private void dateTimePicker2_ValueChanged(object sender, EventArgs e) { costRateLabel.Text = Convert.ToString(CalculateRate(dateTimePicker1.Value, dateTimePicker2.Value)); } } }