Пример #1
0
    void WriteData(bool full, string wr)
    {
        // Majors
        StreamReader sr   = new StreamReader(full ? file : file2);
        string       save = sr.ReadToEnd();

        sr.Close();

        StreamWriter sw = new StreamWriter(full ? file : file2);

        sw.Write(save + wr);
        sw.Close();


        // Friends

        // Check if file exists
        if (File.Exists(fD))
        {
            // Read all of the data on the file
            StreamReader sr2 = new StreamReader(fD);
            // store that read data to this string
            string fLoadAll = sr2.ReadToEnd();
            // close the file
            sr2.Close();

            // now we need a new string that will store the new data to add
            string[] temp = fLoadAll.Split('\n'); //day + "," + w.fM.retAll();

            string fLoadN = "Day," + w.fM.retAll();

            //
            for (int i = 1; i < temp.Length; i++)
            {
                fLoadN += "\n" + temp[i];
            }

            List <string> finder = w.fM.who;
            int[]         store  = new int[finder.Count];

            for (int i = 0; i < finder.Count; i++)
            {
                for (int j = 0; j < friends.Count; j++)
                {
                    if (finder[i] == friends[j].name + FriendManager.Additive(friends[j]))
                    {
                        store[i] = friends[j].relationship;
                    }
                }
            }

            string addTo = "";

            for (int i = 0; i < store.Length; i++)
            {
                addTo += store[i] + ",";
            }

            string newDataLine = "" + day + "," + addTo;

            fLoadN += "\n" + newDataLine;
            // find the new data line to add to file

            // write the new data line to the data file by first writing the previous data, & then new line, add fLoadN
            StreamWriter sw3 = new StreamWriter(fD);
            sw3.Write(fLoadN);
            sw3.Close();
        }
        else // create a new file with only the day column on it
        {
            StreamWriter sw2 = new StreamWriter(fD);
            sw2.Write("Day,");
            sw2.Close();
        }
    }