Exemplo n.º 1
0
        //Writes and stores the total seats available for events for further bookings.
        private void WriteAndStoreData()
        {
            StreamWriter WriteData;

            //Clears the file to store a whole new data.
            using (var fs = new FileStream("AvailPlaces", FileMode.Truncate))
            {
                fs.Close();
            }
            WriteData = File.AppendText("AvailPlaces");

            for (int i = 0; i < 10; i++)
            {
                for (int j = 0; j < 5; j++)
                {
                    WriteData.WriteLine(result[i, j].ToString());
                }
            }
            WriteData.Close();
        }
Exemplo n.º 2
0
        //Writes the data into the file.
        private void FileDetailsWrite()
        {
            StreamWriter WriteData;

            string MyFileName = String.Format(DateTime.Now.ToString(DATEFORMAT), "MyFileName");

            if (File.Exists(MyFileName))
            {   //checks if the file exists for that day and writes the data
                if (MyFileName != DateTime.Now.ToString(DATEFORMAT))
                {
                    string NewFile = DateTime.Now.ToString(DATEFORMAT);
                    WriteData = File.CreateText(NewFile);
                    WriteData.Close();
                    WriteData = File.AppendText(NewFile);
                    for (int i = 0; i < EventNameList.Count; i++)
                    {
                        //both the if and else according to the condition writes all the multiple bookings made into file
                        WriteData.WriteLine(TransactionList[i].ToString());
                        WriteData.WriteLine(TotalSeatList[i].ToString());
                        WriteData.WriteLine(EventNameList[i]);
                        WriteData.WriteLine(LocationNameList[i]);
                        WriteData.WriteLine(MealPlanNameList[i]);
                        WriteData.WriteLine(TotalAmountList[i].ToString());
                        WriteData.WriteLine("                    ");
                    }
                    WriteData.Close();
                }
                else
                {
                    WriteData = File.AppendText(MyFileName);
                    for (int i = 0; i < EventNameList.Count; i++)
                    {
                        WriteData.WriteLine(TransactionList[i].ToString());
                        WriteData.WriteLine(TotalSeatList[i].ToString());
                        WriteData.WriteLine(EventNameList[i]);
                        WriteData.WriteLine(LocationNameList[i]);
                        WriteData.WriteLine(MealPlanNameList[i]);
                        WriteData.WriteLine(TotalAmountList[i].ToString());
                        WriteData.WriteLine("                    ");
                    }
                    WriteData.Close();
                }
            }
            else
            {
                WriteData = File.CreateText(MyFileName);
                WriteData.Close();
                WriteData = File.AppendText(MyFileName);

                for (int i = 0; i < EventNameList.Count; i++)
                {
                    WriteData.WriteLine(TransactionList[i].ToString());
                    WriteData.WriteLine(TotalSeatList[i].ToString());
                    WriteData.WriteLine(EventNameList[i]);
                    WriteData.WriteLine(LocationNameList[i]);
                    WriteData.WriteLine(MealPlanNameList[i]);
                    WriteData.WriteLine(TotalAmountList[i].ToString());
                    WriteData.WriteLine("                    ");
                }
                WriteData.Close();
            }
        }