public static List<Auto> HaeAutot() { AutoLista autot = new AutoLista(); List<Auto> autoLista = new List<Auto>(); Serialisointi.DeSerialisoiXml(HttpContext.Current.Server.MapPath("~/data/WanhatAutot.xml"), ref autot); for (int i = 0; i < autot.Autot.Count; i++) { autoLista.Add(autot.Autot[i]); } return autoLista; }
public static List<Auto> getAutot() { AutoLista xmlista = new AutoLista(); List<Auto> autoLista = new List<Auto>(); Serialisointi.DeSerialisoiXml(HttpContext.Current.Server.MapPath("~/App_Data/WanhatAutot.xml"), ref xmlista); for(int i=0; i < xmlista.Autot.Count; i++) { autoLista.Add(xmlista.Autot[i]); } return autoLista; }
public static List <Auto> getAutot() { AutoLista xmlista = new AutoLista(); List <Auto> autoLista = new List <Auto>(); Serialisointi.DeSerialisoiXml(HttpContext.Current.Server.MapPath("~/App_Data/WanhatAutot.xml"), ref xmlista); for (int i = 0; i < xmlista.Autot.Count; i++) { autoLista.Add(xmlista.Autot[i]); } return(autoLista); }
// Serialisointi public static void SerialisoiXml(string tiedosto, AutoLista autot) { XmlSerializer xs = new XmlSerializer(autot.GetType()); TextWriter tw = new StreamWriter(tiedosto); try { xs.Serialize(tw, autot); } catch (Exception e) { throw e; } finally { tw.Close(); } }
public static void SerialisoiXml(string tiedosto, AutoLista autot) { XmlSerializer xs = new XmlSerializer(autot.GetType()); TextWriter tw = new StreamWriter(tiedosto); try { xs.Serialize(tw, autot); } catch (Exception e) { throw e; } finally { tw.Close(); } }
public static void DeSerialisoiXml(string filePath, ref AutoLista autot) { XmlSerializer deserializer = new XmlSerializer(typeof(AutoLista)); try { FileStream xmlFile = new FileStream(filePath, FileMode.Open); autot = (AutoLista)deserializer.Deserialize(xmlFile); xmlFile.Close(); } catch (Exception ex) { throw ex; } finally { } }
// Deserialisointi public static void DeSerialisoiXml(string filePath, ref AutoLista autot) { XmlSerializer deserializer = new XmlSerializer(typeof(AutoLista)); try { FileStream xmlFile = new FileStream(filePath, FileMode.Open); autot = (AutoLista)deserializer.Deserialize(xmlFile); xmlFile.Close(); } catch (Exception ex) { throw ex; } finally { } }
protected void initMyStuff() { try { AutoLista autot = new AutoLista(); Serialisointi.DeSerialisoiXml(Server.MapPath("~/data/WanhatAutot.xml"), ref autot); Random rnd = new Random(); List<Auto> ekatNelja = new List<Auto>(); while (ekatNelja.Count < 4) { int luku = rnd.Next(0, autot.Autot.Count - 1); if (!ekatNelja.Contains(autot.Autot.ElementAt(luku))) { ekatNelja.Add(autot.Autot.ElementAt(luku)); } } Autot = autot.Autot; ViewState["AutotLista"] = Autot; List<string> merkit = new List<string>(); merkit.Add("Kaikki"); foreach (Auto auto in autot.Autot) { string merkki = auto.Merkki; if (!merkit.Contains(merkki)) { merkit.Add(merkki); } } ListBox1.DataSource = merkit; ListBox1.DataBind(); ListBox1.Height = 150; SortExpression = "DESC"; loadListWiew(ekatNelja); } catch (Exception ex) { er.InnerText = ex.Message; } }
private void initMyStuff() { try { AutoLista autot = new AutoLista(); Serialisointi.DeSerialisoiXml(Server.MapPath("~/App_Data/WanhatAutot.xml"), ref autot); Random random = new Random(); List <Auto> nelja = new List <Auto>(); while (nelja.Count < 4) { int luku = random.Next(0, autot.Autot.Count - 1); if (!nelja.Contains(autot.Autot.ElementAt(luku))) { nelja.Add(autot.Autot.ElementAt(luku)); } } Autot = autot.Autot; ViewState["AutotLista"] = Autot; List <string> merkit = new List <string>(); merkit.Add("Kaikki"); foreach (Auto auto in autot.Autot) { string merkki = auto.Merkki; if (!merkit.Contains(merkki)) { merkit.Add(merkki); } } ListBox1.DataSource = merkit; ListBox1.DataBind(); ListBox1.Height = 150; SortExpression = "DESC"; loadListWiew(nelja); } catch (Exception ex) { er.InnerText = ex.Message; } }
public static void VieAutot(List<Auto> autoLista) { AutoLista autot = new AutoLista(); foreach (Auto item in autoLista) { autot.Autot.Add(item); } Serialisointi.SerialisoiXml(HttpContext.Current.Server.MapPath("~/App_Data/WanhatAutot.xml"), autot); }
public static void TallennaAutot(AutoLista autot) { Serialisointi.SerialisoiXml(HttpContext.Current.Server.MapPath("~/App_Data/WanhatAutot.xml"), autot); }