public fenetreWagon(CGestionTrain gestionTrain, CWagon wagon) // modifier le wagon existant { InitializeComponent(); this._mode = 1; this._gestionTrain = gestionTrain; TB_ID.Text = wagon.ID.ToString(); TB_PoidsAVide.Text = wagon.poidsAvide.ToString(); TB_Location.Text = wagon.longueur.ToString(); this.Show(); }
private void BTN_modifierWagon_Click(object sender, RoutedEventArgs e) { CWagon wagon = new CWagon(); wagon.ID = TB_ID.Text; wagon.location = TB_Location.Text; wagon.longueur = (this.TB_longueur.Text == "") ? 0: Convert.ToInt32(this.TB_longueur.Text); wagon.poidsAvide = (this.TB_PoidsAVide.Text == "") ? 0 : Convert.ToInt32(TB_PoidsAVide.Text); wagon.poidsRempli = (this.TB_PoidsRempli.Text == "") ? 0 : Convert.ToInt32(TB_PoidsRempli.Text); if (this._mode == 0) { this._gestionTrain.creerWagon(wagon); } else if (this._mode == 1) { this._gestionTrain.modifierParamWagon(wagon); } }
public void supprWagon(CWagon wagon) { CCommunicationRocrail.envoyerTrame("<model cmd=\"remove\">" + CXml.Serialize(wagon) + "</model>"); }
public void modifierParamWagon(CWagon wagon) { CCommunicationRocrail.envoyerTrame(CXml.Serialize(wagon)); MessageBox.Show("Commande envoyée au serveur : \n\n" + CXml.Serialize(wagon)); }
// wagons \\ public void creerWagon(CWagon wagon) { CCommunicationRocrail.envoyerTrame("<model cmd=\"add\">" + CXml.Serialize(wagon) + "</model>"); MessageBox.Show("Commande envoyée au serveur : \n\n" + "<model cmd=\"add\">" + CXml.Serialize(wagon) + "</model>"); }
private static void OnTrameReceived(object sender, TrameEventArgs e) { if (!planRecu) return; string r = e.Datas; XmlDocument d = new XmlDocument(); if (r.Contains("<model cmd=")) { // Ajout d'un élément if (r.Contains("\"add\"")) { string aRetirer1 = "<model cmd=\"add\">\r\n "; string aRetirer2 = "\r </model>"; r = r.Remove(0, aRetirer1.Length); r = r.Remove(r.Length - aRetirer2.Length, aRetirer2.Length); d.LoadXml(r); if (d.DocumentElement.Name == "car") { CWagon wagon = new CWagon(); wagon.ID = d.DocumentElement.Attributes["id"].Value; if (d.DocumentElement.Attributes["weight_empty"] != null) wagon.poidsAvide = Convert.ToInt32(d.DocumentElement.Attributes["weight_empty"].Value); if (d.DocumentElement.Attributes["weight_loaded"] != null) wagon.poidsRempli = Convert.ToInt32(d.DocumentElement.Attributes["weight_loaded"].Value); if (d.DocumentElement.Attributes["location"] != null) wagon.location = d.DocumentElement.Attributes["location"].Value; if (d.DocumentElement.Attributes["len"] != null) wagon.longueur = Convert.ToInt32(d.DocumentElement.Attributes["len"].Value); res.listeWagon.Add(wagon); } else if (d.DocumentElement.Name == "lc") { CLoco loco = new CLoco(); loco.ID = d.DocumentElement.Attributes["id"].Value; if (d.DocumentElement.Attributes["blockid"] != null) loco.blockid = d.DocumentElement.Attributes["blockid"].Value; if (d.DocumentElement.Attributes["V"] != null) loco.vitesse = Convert.ToInt32(d.DocumentElement.Attributes["V"].Value); if (d.DocumentElement.Attributes["dir"] != null) loco.direction = Convert.ToBoolean(d.DocumentElement.Attributes["dir"].Value); if (d.DocumentElement.Attributes["V_mid"] != null) loco.vitesseMoy = Convert.ToInt32(d.DocumentElement.Attributes["V_mid"].Value); if (d.DocumentElement.Attributes["blockenterside"] != null) loco.blockEnterSide = Convert.ToBoolean(d.DocumentElement.Attributes["blockenterside"].Value); if (d.DocumentElement.Attributes["mass"] != null) loco.masse = Convert.ToInt32(d.DocumentElement.Attributes["mass"].Value); if (d.DocumentElement.Attributes["nrcars"] != null) loco.nrcars = Convert.ToInt32(d.DocumentElement.Attributes["nrcars"].Value); if (d.DocumentElement.Attributes["number"] != null) loco.number = d.DocumentElement.Attributes["number"].Value; if (d.DocumentElement.Attributes["len"] != null) loco.longueur = Convert.ToInt32(d.DocumentElement.Attributes["len"].Value); res.listeLoco.Add(loco); } } // Suppression d'un élément else if (r.Contains("\"remove\"")) { string aRetirer1 = "<model cmd=\"remove\" controlcode=\"\" slavecode=\"\" server=\"infw03A5B7AC\">\r\n "; string aRetirer2 = "\r </model>"; r = r.Remove(0, aRetirer1.Length); r = r.Remove(r.Length - aRetirer2.Length, aRetirer2.Length); d.LoadXml(r); if (d.DocumentElement.Name == "car") { foreach (CWagon wagon in res.listeWagon) { if (wagon.ID == d.DocumentElement.Attributes["id"].Value) { res.listeWagon.Remove(wagon); break; } } } else if (d.DocumentElement.Name == "lc") { foreach (CLoco loco in res.listeLoco) { if (loco.ID == d.DocumentElement.Attributes["id"].Value) { res.listeLoco.Remove(loco); break; } } } } } }