Example #1
0
        public DataSet LoadData(string fileName)
        {
            const int    GRID_COLUMN_NUM  = 2;
            const string DELIMETER_SYMBOL = ",";
            const string CALLS_GRID_NAME  = "gridCalls";

            StreamReader sReader = null;
            DataSet      dataset = new DataSet();

            Globals.LCalls = new List <Calls>();

            try
            {
                sReader = new StreamReader(fileName);
                dataset.Tables.Add(CALLS_GRID_NAME);
                // The phone number
                dataset.Tables[CALLS_GRID_NAME].Columns.Add("Phone Number");
                // The call duration in seconds
                dataset.Tables[CALLS_GRID_NAME].Columns.Add("Call Duration (seconds)");

                string   allData = sReader.ReadToEnd();
                string[] rows    = allData.Split(Globals.LINE_FOLDING.ToCharArray());

                foreach (string row in rows)
                {
                    if (row.Length == 0)
                    {
                        continue;
                    }
                    string[] columns = row.Split(DELIMETER_SYMBOL.ToCharArray());
                    if (columns.Length != GRID_COLUMN_NUM)
                    {
                        throw new DataException("Invalid " + fileName + " file format.");
                    }

                    dataset.Tables[CALLS_GRID_NAME].Rows.Add(columns);

                    string phone    = columns[0].ToString().Trim();
                    string duration = columns[1].ToString().Trim();

                    Calls call = new Calls(phone, duration);
                    Globals.LCalls.Add(call);
                }
            }
            catch (DirectoryNotFoundException e)
            {
                Console.WriteLine(e);
            }
            catch (IOException e)
            {
                Console.WriteLine(e);
            }
            finally
            {
                sReader.Close();
                sReader.Dispose();
            }

            return(dataset);
        }
Example #2
0
        public DataSet LoadData(string fileName)
        {
            const int    GRID_COLUMN_NUM  = 3;
            const string DELIMETER_SYMBOL = ";";
            const string RATES_GRID_NAME  = "gridRates";

            StreamReader sReader = null;
            DataSet      dataset = new DataSet();

            Globals.DFixedRates  = new Dictionary <string, FixedRates>();
            Globals.DMobileRates = new Dictionary <string, MobileRates>();

            try
            {
                sReader = new StreamReader(fileName);
                dataset.Tables.Add(RATES_GRID_NAME);
                // The direction name
                dataset.Tables[RATES_GRID_NAME].Columns.Add("Direction");
                // The price per minute for mobile networks
                dataset.Tables[RATES_GRID_NAME].Columns.Add("Price per minute / Mobile");
                // The price per minute for fixed networks
                dataset.Tables[RATES_GRID_NAME].Columns.Add("Price per minute / Fixed");

                string   allData = sReader.ReadToEnd();
                string[] rows    = allData.Split(Globals.LINE_FOLDING.ToCharArray());

                foreach (string row in rows)
                {
                    if (row.Length == 0)
                    {
                        continue;
                    }
                    string[] columns = row.Split(DELIMETER_SYMBOL.ToCharArray());
                    if (columns.Length != GRID_COLUMN_NUM)
                    {
                        throw new DataException("Invalid 'rates.csv' file format.");
                    }

                    dataset.Tables[RATES_GRID_NAME].Rows.Add(columns);

                    string direction = columns[0].ToString().Trim();
                    string fPrice    = columns[1].ToString().Trim();
                    string mPrice    = columns[2].ToString().Trim();

                    FixedRates fRates = new FixedRates(direction, fPrice);
                    Globals.DFixedRates.Add(fRates.Direction, fRates);

                    MobileRates mRates = new MobileRates(string.Format("{0} {1}", direction, Globals.MOBILE_VALUE), mPrice);
                    Globals.DMobileRates.Add(mRates.Direction, mRates);
                }
            }
            catch (DirectoryNotFoundException e)
            {
                Console.WriteLine(e);
            }
            catch (IOException e)
            {
                Console.WriteLine(e);
            }
            finally
            {
                sReader.Close();
                sReader.Dispose();
            }

            return(dataset);
        }
Example #3
0
        public DataSet LoadData(string fileName)
        {
            const int    GRID_COLUMN_NUM   = 3;
            const string DELIMETER_SYMBOL  = ",";
            const string COUNTRY_GRID_NAME = "gridCountry";
            const string PERSONAL_VALUE    = "Personal";
            const string PREMIUM_VALUE     = "Premium";

            StreamReader sReader = null;
            DataSet      dataset = new DataSet();

            Globals.LCountry = new List <Country>();

            try
            {
                sReader = new StreamReader(fileName);
                dataset.Tables.Add(COUNTRY_GRID_NAME);
                // The phone code
                dataset.Tables[COUNTRY_GRID_NAME].Columns.Add("Code");
                // The full name of the direction
                dataset.Tables[COUNTRY_GRID_NAME].Columns.Add("Full Direction");
                // The direction name
                dataset.Tables[COUNTRY_GRID_NAME].Columns.Add("Direction");

                string   allData = sReader.ReadToEnd();
                string[] rows    = allData.Split(Globals.LINE_FOLDING.ToCharArray());

                foreach (string row in rows)
                {
                    if (row.Length == 0)
                    {
                        continue;
                    }
                    string[] columns = row.Split(DELIMETER_SYMBOL.ToCharArray());
                    if (columns.Length != GRID_COLUMN_NUM)
                    {
                        throw new DataException("Invalid 'country.txt' file format.");
                    }

                    dataset.Tables[COUNTRY_GRID_NAME].Rows.Add(columns);

                    string code          = columns[0].ToString().Trim();
                    string fullDirection = columns[1].ToString().Trim();
                    string direction     = columns[2].ToString().Trim();

                    if ((fullDirection.Contains(PERSONAL_VALUE)) || (fullDirection.Contains(PREMIUM_VALUE)))
                    {
                        continue;
                    }
                    Country country = new Country(code, fullDirection, direction);
                    Globals.LCountry.Add(country);
                }
            }
            catch (DirectoryNotFoundException e)
            {
                Console.WriteLine(e);
            }
            catch (IOException e)
            {
                Console.WriteLine(e);
            }
            finally
            {
                sReader.Close();
                sReader.Dispose();
            }

            return(dataset);
        }