using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace Baza_Reklam.Classes
{
    class XTGFile
    {
        /// <summary>
        /// Zczytuje reklamy z pliku xtg // UWAGA : w przypadku gieldy i autosalonu wpisuje rowniez strony dla autosalonu
        /// dla zamowienin o tej samej nazwie np. CCC001 i GCCC001
        /// </summary>
        public List<Reklama> zczytajStronyZplikuXTG(string filename)
        {
            List<Reklama> lista = new List<Reklama>();

            StreamReader st = new StreamReader(filename);

            string read = null;
            string[] read2 = new string[20];

            while ((read = st.ReadLine()) != null)
            {
                Reklama nowa = new Reklama();

                if (read.Contains("REKLAMAFILES"))
                {
                    read = read.Trim();
                    read = read.Substring(read.Length - 10, 6);
                    nowa.nrRek = read;

                    read = st.ReadLine();

                    read2 = read.Split("\t".ToCharArray(), 20);

                    for (int i = 0; i < read2.Length; i++)
                    {
                        if (read2[i] != "")
                        {
                            nowa.costam.Add(read2[i]);
                        }
                    }
                    lista.Add(nowa);
                }
            }

            st.Close();

            return lista;
        }
    }



    #region Nested type: Reklama

    /// <summary>
    /// Klasa pomocnicza,używana przy zczytywaniu stron z pliku xtg
    /// </summary>
    public class Reklama
    {
        public List<string> costam = new List<string>();
        public string nrRek;
        public bool wpisana = false;
    }

    #endregion
}
