private void maingrid_CurrentCellChanged(object sender, EventArgs e) { try { MyTrain clicktonumber = maingrid.CurrentRow.DataBoundItem as MyTrain; textbox_clicknumber.Text = clicktonumber.trainname.ToString(); } catch (Exception) { } }
public static void Find(string box1, string box2) { Search.Clear(); try { string trainOutput = File.ReadAllText(@"./Trains.xml"); XElement trainXElement = XElement.Parse(trainOutput); foreach (var item in trainXElement.Descendants("train")) { int temptrainnumber = int.Parse(item.Element("trainnumber").Value); string temptrainname = item.Element("trainname").Value; string tempstartroute = item.Element("startroute").Value; string tempendroute = item.Element("endroute").Value; string tempstarttime = item.Element("starttime").Value; string tempendtime = item.Element("endtime").Value; int temppay = int.Parse(item.Element("pay").Value); if (tempstartroute == box1 && tempendroute == box2) { MyTrain search = new MyTrain() { trainnumber = temptrainnumber, trainname = temptrainname, startroute = tempstartroute, endroute = tempendroute, starttime = tempstarttime, endtime = tempendtime, pay = temppay }; Search.Add(search); } } } catch (Exception excp) { } }
public static void Load() { try { string trainOutput = File.ReadAllText(@"./Trains.xml"); XElement trainXElement = XElement.Parse(trainOutput); foreach (var item in trainXElement.Descendants("train")) { int temptrainnumber = int.Parse(item.Element("trainnumber").Value); string temptrainname = item.Element("trainname").Value; string tempstartroute = item.Element("startroute").Value; string tempendroute = item.Element("endroute").Value; string tempstarttime = item.Element("starttime").Value; string tempendtime = item.Element("endtime").Value; int temppay = int.Parse(item.Element("pay").Value); MyTrain tempTrain = new MyTrain() { trainnumber = temptrainnumber, trainname = temptrainname, startroute = tempstartroute, endroute = tempendroute, starttime = tempstarttime, endtime = tempendtime, pay = temppay }; Trains.Add(tempTrain); } } catch (Exception excp) { } }