Advertisement
futog

ocena.asmx.cs drugi zadatak

Mar 5th, 2017
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
ASP 2.02 KB | None | 0 0
  1. [System.Web.Services.WebMethod]
  2.         public double ucitajOcenu(string Ime, string Prezime)
  3.         {
  4.             List<string> lista = ucitajUcenike();
  5.             double ProsecnaOcena = 0;
  6.             string[] podatak;
  7.  
  8.             foreach (string line in lista)
  9.             {
  10.                 podatak = line.Split('|');
  11.                 if (Ime.Contains(podatak[0]) && Prezime.Contains(podatak[1]))
  12.                 {
  13.                     ProsecnaOcena = Double.Parse(podatak[2]);
  14.                 }
  15.             }
  16.  
  17.             return ProsecnaOcena;
  18.         }
  19.  
  20.         [System.Web.Services.WebMethod]
  21.         public bool dodajUcenike(string Ime, string Prezime, double ProsecnaOcena)
  22.         {
  23.             List<string> lista = ucitajUcenike();
  24.             string line = Ime + "|" + Prezime + "|" + ProsecnaOcena;
  25.             lista.Add(line);
  26.             try
  27.             {
  28.                 StreamWriter sw = new StreamWriter(HttpContext.Current.Server.MapPath("~/Ucenici.txt"));
  29.                 foreach (string l in lista)
  30.                 {
  31.                     sw.WriteLine(l);
  32.                 }
  33.                 sw.Close();
  34.             }
  35.             catch (Exception e)
  36.             {
  37.                 Console.WriteLine(e);
  38.             }
  39.             return true;
  40.         }
  41.  
  42.         [System.Web.Services.WebMethod]
  43.         public List<string> ucitajUcenike()
  44.         {
  45.             List<string> lista = new List<string>();
  46.             try
  47.             {
  48.                 StreamReader sr = new StreamReader(HttpContext.Current.Server.MapPath("~/Ucenici.txt"));
  49.                 string line = sr.ReadLine();
  50.                 while (!string.IsNullOrEmpty(line))
  51.                 {
  52.                     //string[] polje = line.Split('|');
  53.                     lista.Add(line);
  54.                     line = sr.ReadLine();
  55.                 }
  56.                 sr.Close();
  57.             }
  58.             catch (Exception e)
  59.             {
  60.                 Console.WriteLine(e.Message);
  61.             }
  62.             return lista;
  63.         }
  64.     }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement