Beispiel #1
0
        public void itemToList(string i, string type)
        {
            string next, id, desc, pub, med, mod, pla;
            int    pos, sto;
            double co;

            pos = i.IndexOf(',');
            id  = i.Substring(1, pos - 1);

            next = i.Substring(pos + 1);
            pos  = next.IndexOf(',');
            desc = next.Substring(0, pos);

            next = next.Substring(pos + 1);
            pos  = next.IndexOf(',');
            sto  = int.Parse(next.Substring(0, pos));

            next = next.Substring(pos + 1);
            pos  = next.IndexOf(',');
            co   = double.Parse(next.Substring(0, pos));

            next = next.Substring(pos + 1);
            pos  = next.IndexOf(',');

            if (type == "g")
            {
                pub = next.Substring(0, pos);

                next = next.Substring(pos + 1);
                med  = next;

                Games ga = new Games(id, desc, sto, co, pub, med);
            }
            else if (type == "p")
            {
                mod = next;

                Platform pl = new Platform(id, desc, sto, co, mod);
            }
            else
            {
                pla = next;
                Accessories ac = new Accessories(id, desc, sto, co, pla);
            }
        }
Beispiel #2
0
        public void saveProducts()
        {
            BinaryWriter bw;

            try
            {
                bw = new BinaryWriter(new FileStream("product.bin", FileMode.Create));
                foreach (Item i in Item.items)
                {
                    try
                    {
                        if (i.GetType() == typeof(Games))
                        {
                            Games g = (Games)i;
                            bw.Write(g.ToString());
                        }
                        else if (i.GetType() == typeof(Platform))
                        {
                            Platform p = (Platform)i;
                            bw.Write(p.ToString());
                        }
                        else
                        {
                            Accessories a = (Accessories)i;
                            bw.Write(a.ToString());
                        }
                    }
                    catch (Exception fe)
                    {
                        return;
                    }
                }
            }
            catch (Exception fe)
            {
                MessageBox.Show(fe.Message + "\n Cannot save products to file");
                return;
            }
            bw.Close();
        }