Exemple #1
0
        private void OdczytBBtn_Click(object sender, EventArgs e)
        {
            Stream str;

            WczytajWnd.Filter           = "csv files (.csv)|*.csv| txt files (.txt)|*.txt";
            WczytajWnd.RestoreDirectory = true;
            WczytajWnd.FilterIndex      = 2;

            if (WczytajWnd.ShowDialog() == DialogResult.OK)
            {
                if ((str = WczytajWnd.OpenFile()) != null)
                {
                    string [] temp = new string [5];
                    Kontakty.Clear();
                    ListaKontaktow.VirtualListSize = 0;
                    string[] buff = new string[5];
                    using (BinaryReader br = new BinaryReader(str))
                    {
                        while (br.PeekChar() != -1)
                        {
                            temp[0] = br.ReadString();
                            temp[1] = br.ReadString();
                            temp[2] = br.ReadString();
                            temp[3] = br.ReadString();
                            temp[4] = Convert.ToString(br.ReadInt32());

                            DodajDoListyV2(temp);
                        }
                    }
                }
            }
        }
Exemple #2
0
        private void WczytajBtn_Click(object sender, EventArgs e)
        {
            Stream str;
            string line;

            WczytajWnd.Filter           = "csv files (.csv)|*.csv| txt files (.txt)|*.txt";
            WczytajWnd.RestoreDirectory = true;
            WczytajWnd.FilterIndex      = 2;

            if (WczytajWnd.ShowDialog() == DialogResult.OK)
            {
                if ((str = WczytajWnd.OpenFile()) != null)
                {
                    Kontakty.Clear();
                    ListaKontaktow.VirtualListSize = 0;
                    string[] buff = new string[5];
                    using (StreamReader sr = new StreamReader(str))
                    {
                        while ((line = sr.ReadLine()) != null)
                        {
                            buff = line.Split(Sep);
                            DodajDoListyV2(buff);
                        }
                    }
                }
            }
        }
Exemple #3
0
        private void XMLOdBtn_Click(object sender, EventArgs e)
        {
            Stream str;

            WczytajWnd.Filter           = "XML files (.xml)|*.xml";
            WczytajWnd.RestoreDirectory = true;

            if (WczytajWnd.ShowDialog() == DialogResult.OK)
            {
                if ((str = WczytajWnd.OpenFile()) != null)
                {
                    Kontakty.Clear();
                    ListaKontaktow.VirtualListSize = 0;
                    Kontakt nowy = new Kontakt();
                    int     i    = 0;
                    using (XmlTextReader xr = new XmlTextReader(str))
                    {
                        xr.MoveToContent();
                        while (xr.Read())
                        {
                            if (xr.IsStartElement())
                            {
                                if (xr.Name == "Kontakt")
                                {
                                    for (; ;)
                                    {
                                        if (xr.IsStartElement())
                                        {
                                            xr.Read();
                                            if (xr.Value != "\r\n    ")
                                            {
                                                switch (i)
                                                {
                                                case 0: nowy.Imie = xr.Value;
                                                    break;

                                                case 1: nowy.Nazwisko = xr.Value;
                                                    break;

                                                case 2: nowy.Telefon = xr.Value;
                                                    break;

                                                case 3: nowy.Email = xr.Value;
                                                    break;

                                                case 4: nowy.Wiek = Convert.ToInt32(xr.Value);
                                                    break;
                                                }
                                                i++;
                                                xr.Read();
                                                xr.Read();
                                                if (i == 5)
                                                {
                                                    i = 0;
                                                    Kontakty.Add(nowy);
                                                    nowy = new Kontakt();
                                                    ListaKontaktow.VirtualListSize++;
                                                    break;
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }

                    /* XmlDataDocument doc = new XmlDataDocument();
                     * XmlTextReader xr = new XmlTextReader(str);
                     * XmlNodeList node;
                     * Kontakt nowy = new Kontakt();
                     * ListaKontaktow.VirtualListSize = 0;
                     * Kontakty.Clear();
                     * //doc.DataSet.ReadXmlSchema(".\\schem.xsd");
                     * xr.MoveToContent();
                     * doc.Load(xr);
                     * node = doc.SelectNodes("//Kontakt");
                     *
                     * for (int i = 0; i < node.Count; i++)
                     * {
                     *   nowy.Imie = node.Item(i).ChildNodes.Item(0).InnerText;
                     *   nowy.Nazwisko = node.Item(i).ChildNodes.Item(1).InnerText;
                     *   nowy.Telefon = node.Item(i).ChildNodes.Item(2).InnerText;
                     *   nowy.Email = node.Item(i).ChildNodes.Item(3).InnerText;
                     *   nowy.Wiek = Convert.ToInt32(node.Item(i).ChildNodes.Item(4).InnerText);
                     *   Kontakty.Add(nowy);
                     *   nowy = new Kontakt();
                     *   ListaKontaktow.VirtualListSize++;
                     *
                     * }*/
                    /* for (int x = 0; x < doc.ChildNodes.Count; x++)
                     * {
                     *   node = doc.DocumentElement.ChildNodes.Item(x);
                     * }*/
                    //node = i;

                    /*var custs = from c in XElement.Load(str).Elements("Kontakty")
                     *          select c;*/
                }
            }
        }