Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [System.Web.Services.WebMethod]
- public double ucitajOcenu(string Ime, string Prezime)
- {
- List<string> lista = ucitajUcenike();
- double ProsecnaOcena = 0;
- string[] podatak;
- foreach (string line in lista)
- {
- podatak = line.Split('|');
- if (Ime.Contains(podatak[0]) && Prezime.Contains(podatak[1]))
- {
- ProsecnaOcena = Double.Parse(podatak[2]);
- }
- }
- return ProsecnaOcena;
- }
- [System.Web.Services.WebMethod]
- public bool dodajUcenike(string Ime, string Prezime, double ProsecnaOcena)
- {
- List<string> lista = ucitajUcenike();
- string line = Ime + "|" + Prezime + "|" + ProsecnaOcena;
- lista.Add(line);
- try
- {
- StreamWriter sw = new StreamWriter(HttpContext.Current.Server.MapPath("~/Ucenici.txt"));
- foreach (string l in lista)
- {
- sw.WriteLine(l);
- }
- sw.Close();
- }
- catch (Exception e)
- {
- Console.WriteLine(e);
- }
- return true;
- }
- [System.Web.Services.WebMethod]
- public List<string> ucitajUcenike()
- {
- List<string> lista = new List<string>();
- try
- {
- StreamReader sr = new StreamReader(HttpContext.Current.Server.MapPath("~/Ucenici.txt"));
- string line = sr.ReadLine();
- while (!string.IsNullOrEmpty(line))
- {
- //string[] polje = line.Split('|');
- lista.Add(line);
- line = sr.ReadLine();
- }
- sr.Close();
- }
- catch (Exception e)
- {
- Console.WriteLine(e.Message);
- }
- return lista;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement