Пример #1
0
        public override string[] printProperties(int ProductPlace)
        {
            Magazine     myMagazine = new Magazine();
            StreamReader readcustomerfile;

            readcustomerfile = File.OpenText(@"Products.txt");
            string[] properties = new string[5];
            string   info       = "";
            string   line;
            int      control = 0;
            int      first, last;

            while ((line = readcustomerfile.ReadLine()) != null)
            {
                control = line.IndexOf("ID : " + (200 + ProductPlace));
                if (control != -1)
                {
                    //Set ID To Magazine With Read Text File
                    first = line.IndexOf("ID : ") + "ID : ".Length;
                    last  = line.IndexOf(",Name");
                    info  = line.Substring(first, last - first);
                    myMagazine.setID(Convert.ToInt32(info));
                    properties[0] = myMagazine.getID().ToString();

                    //Set Name To Magazine With Read Text File
                    first = line.IndexOf("Name : ") + "Name : ".Length;
                    last  = line.IndexOf(",Price");
                    info  = line.Substring(first, last - first);
                    myMagazine.setName(info);
                    properties[1] = myMagazine.getName();


                    //Set Price To Magazine With Read Text File
                    first = line.IndexOf("Price : ") + "Price : ".Length;
                    last  = line.IndexOf(",Issue");
                    info  = line.Substring(first, last - first);
                    myMagazine.setPrice(Convert.ToInt32(info));
                    properties[2] = myMagazine.getPrice().ToString();


                    //Set Issue To Magazine With Read Text File
                    first = line.IndexOf("Issue : ") + "Issue : ".Length;
                    last  = line.IndexOf(",Type");
                    info  = line.Substring(first, last - first);
                    myMagazine.setissue(info);
                    properties[3] = myMagazine.getissue();


                    //Set Type To Magazine With Read Text File
                    first = line.IndexOf("Type : ") + "Type : ".Length;
                    last  = line.Length;
                    info  = line.Substring(first, last - first);
                    myMagazine.setType(info);
                    properties[4] = myMagazine.getType();
                }
            }
            return(properties);
        }