예제 #1
0
파일: Data.cs 프로젝트: vesna98/Web
        public static List <Karta> ReadKarte(string path)
        {
            List <Karta> fests = new List <Karta>();

            path = HostingEnvironment.MapPath(path);
            FileStream   stream = new FileStream(path, FileMode.Open);
            StreamReader sr     = new StreamReader(stream);
            string       line   = "";

            while ((line = sr.ReadLine()) != null)
            {
                string[] tokens = line.Split(';');

                bool obr;
                bool.TryParse(tokens[7], out obr);

                bool odustanak;
                bool.TryParse(tokens[9], out odustanak);

                //string nazivmanifestacije, string datummanifestacije, double cena, string kupac, string korisnikid, StatusKarte status, TypeKarte tipkarte

                Karta p = new Karta(tokens[5], tokens[6], double.Parse(tokens[4]), tokens[8], tokens[1], (StatusKarte)Enum.Parse(typeof(StatusKarte), tokens[3]), (TypeKarte)Enum.Parse(typeof(TypeKarte), tokens[2]), tokens[0], obr, odustanak, tokens[10]);
                fests.Add(p);
            }
            sr.Close();
            stream.Close();

            return(fests);
        }
예제 #2
0
파일: Data.cs 프로젝트: vesna98/Web
        public static void SaveKartu(Karta p)
        {
            string putanja = HostingEnvironment.MapPath("~/App_Data/karte.txt");

            string[] lines = System.IO.File.ReadAllLines(putanja);

            bool   izmeni = false;
            string nova   = "";

            for (int i = 0; i < lines.Count(); i++)
            {
                string[] tokens = lines[i].Split(';');

                if (tokens[0].Equals(p.Idkarte))//jednaki id
                {
                    nova     = p.ToString();
                    lines[i] = nova;
                    izmeni   = true;
                    break;
                }
            }

            if (izmeni)//menja postojeca
            {
                System.IO.File.WriteAllLines(putanja, lines);
            }
            else
            {
                //dopisuje
                FileStream   fs  = new FileStream(putanja, FileMode.Append, FileAccess.Write);
                StreamWriter sw  = new StreamWriter(fs);
                string       str = p.ToString();
                sw.WriteLine(str);
                sw.Close();
                fs.Close();
            }
        }