コード例 #1
0
        public static bool AddCountryToCountryDatabase(Country CountryToAdd)
        {
            try
            {
                using (StreamWriter writer = new StreamWriter(FilePath, true))
                {
                    writer.WriteLine(CountryToAdd);
                }

                return true;
            }
            catch (Exception)
            {

                return false;
            }
        }
コード例 #2
0
        public static List<Country> ReadCountrysFromDatabase()
        {
            var listOfCountrys = new List<Country>();

            using (StreamReader reader = new StreamReader(FilePath))
            {
                var currentLine = reader.ReadLine();

                while (currentLine != null)
                {
                    var currentCountry = currentLine.Split('|');
                    var country = new Country(currentCountry[0].Trim(),
                        currentCountry[1].Trim(),
                        int.Parse(currentCountry[2].Trim()));
                    listOfCountrys.Add(country);

                    currentLine = reader.ReadLine();

                }
            }

            return listOfCountrys;
        }
コード例 #3
0
        protected void btnAdd_Click(object sender, EventArgs e)
        {
            var country = new Country(this.txtCountry.Text, this.txtCapital.Text, int.Parse(this.txtPopulation.Text));

            var listOfCountries = FileOperations.ReadCountrysFromDatabase();

            

            if (FileOperations.AddCountryToCountryDatabase(country))
            {
                lblMessage.Text = "Country successfuly added.";
                this.txtCountry.Text = "";
                this.txtCapital.Text = "";
                this.txtPopulation.Text = "";
            }
            else
            {
                lblMessage.Text = "Country already ecsists";
                this.txtCountry.Text = "";
                this.txtCapital.Text = "";
                this.txtPopulation.Text = "";
            }
        }