コード例 #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            List <Country> list = db.Countries.ToList();
            int            key  = 0;
            string         name = comboBox1.Text;

            foreach (var thing in list)
            {
                if (String.Compare(thing.Name, name, true) == 0)
                {
                    break;
                }
                key += 1;
            }
            db.Countries.Remove(list[key]);
            db.SaveChanges();
            Close();
        }
コード例 #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            Country a            = new Country();
            bool    failedtoset  = false;
            bool    failedtoset2 = false;

            if (textBox1.Text != "")
            {
                a.Code = textBox1.Text;
            }
            else
            {
                failedtoset2 = true;
            }
            if (textBox2.Text != "")
            {
                a.Name = textBox2.Text;
            }
            else
            {
                failedtoset2 = true;
            }
            if (textBox3.Text != "")
            {
                a.Continent = textBox3.Text;
            }
            else
            {
                failedtoset2 = true;
            }
            if (float.TryParse(textBox4.Text, out float result))
            {
                a.SurfaceArea = float.Parse(textBox4.Text);
            }
            else if (textBox4.Text == "")
            {
                a.SurfaceArea = null;
            }
            else
            {
                failedtoset = true;
            }

            if (float.TryParse(textBox5.Text, out float result2))
            {
                a.Population = int.Parse(textBox5.Text);
            }
            else if (textBox5.Text == "")
            {
                a.Population = null;
            }
            else
            {
                failedtoset = true;
            }

            if (float.TryParse(textBox6.Text, out float result3))
            {
                a.LifeExpectancy = float.Parse(textBox6.Text);
            }
            else if (textBox6.Text == "")
            {
                a.LifeExpectancy = null;
            }
            else
            {
                failedtoset = true;
            }

            if (float.TryParse(textBox7.Text, out float result4))
            {
                a.GNP = float.Parse(textBox7.Text);
            }
            else if (textBox7.Text == "")
            {
                a.GNP = null;
            }
            else
            {
                failedtoset = true;
            }

            if (textBox8.Text == "")
            {
                a.HeadOfState = null;
            }
            else
            {
                a.HeadOfState = textBox8.Text;
            }

            if (failedtoset)
            {
                MessageBox.Show("Could not parse a value. Please try again.");
            }
            else if (failedtoset2)
            {
                MessageBox.Show("Code, Name, and Continent must have a value.");
            }
            else
            {
                db.Countries.Add(a);
                db.SaveChanges();
                Close();
            }
        }
コード例 #3
0
        private void button1_Click(object sender, EventArgs e)
        {
            List <Country> list     = db.Countries.ToList();
            string         name     = comboBox1.Text;
            string         property = comboBox2.Text;
            string         newvalue = textBox1.Text;
            int            key      = 0;
            float          result;

            foreach (var thing in list)
            {
                if (String.Compare(thing.Name, name, true) == 0)
                {
                    break;
                }
                key += 1;
            }

            if (String.Compare(property, "Code", true) == 0)
            {
                if (textBox1.Text != "")
                {
                    list[key].Code = newvalue;
                    db.SaveChanges();
                    Close();
                }
                else
                {
                    MessageBox.Show("Code, Name, and Continent must have a value.");
                }
            }
            else if (String.Compare(property, "Name", true) == 0)
            {
                if (textBox1.Text != "")
                {
                    list[key].Name = newvalue;
                    db.SaveChanges();
                    Close();
                }
                else
                {
                    MessageBox.Show("Code, Name, and Continent must have a value.");
                }
            }
            else if (String.Compare(property, "Continent", true) == 0)
            {
                if (textBox1.Text != "")
                {
                    list[key].Continent = newvalue;
                    db.SaveChanges();
                    Close();
                }
                else
                {
                    MessageBox.Show("Code, Name, and Continent must have a value.");
                }
            }
            else if (String.Compare(property, "Surface Area", true) == 0)
            {
                if (float.TryParse(newvalue, out result))
                {
                    list[key].SurfaceArea = float.Parse(newvalue);
                    db.SaveChanges();
                    Close();
                }
                else if (newvalue == "")
                {
                    list[key].SurfaceArea = null;
                    db.SaveChanges();
                    Close();
                }
                else
                {
                    MessageBox.Show("Could not parse property. Please try again.");
                }
            }
            else if (String.Compare(property, "Population", true) == 0)
            {
                if (int.TryParse(newvalue, out int result2))
                {
                    list[key].Population = int.Parse(newvalue);
                    db.SaveChanges();
                    Close();
                }
                else if (newvalue == "")
                {
                    list[key].Population = null;
                    db.SaveChanges();
                    Close();
                }
                else
                {
                    MessageBox.Show("Could not parse property. Please try again.");
                }
            }
            else if (String.Compare(property, "Life Expectancy", true) == 0)
            {
                if (float.TryParse(newvalue, out result))
                {
                    list[key].LifeExpectancy = float.Parse(newvalue);
                    db.SaveChanges();
                    Close();
                }
                else if (newvalue == "")
                {
                    list[key].LifeExpectancy = null;
                    db.SaveChanges();
                    Close();
                }
                else
                {
                    MessageBox.Show("Could not parse property. Please try again.");
                }
            }
            else if (String.Compare(property, "GNP", true) == 0)
            {
                if (float.TryParse(newvalue, out result))
                {
                    list[key].GNP = float.Parse(newvalue);
                    db.SaveChanges();
                    Close();
                }
                else if (newvalue == "")
                {
                    list[key].GNP = null;
                    db.SaveChanges();
                    Close();
                }
                else
                {
                    MessageBox.Show("Could not parse property. Please try again.");
                }
            }
            else if (String.Compare(property, "Head of State", true) == 0)
            {
                if (newvalue == "")
                {
                    list[key].HeadOfState = null;
                    db.SaveChanges();
                    Close();
                }
                else
                {
                    list[key].HeadOfState = newvalue;
                    db.SaveChanges();
                    Close();
                }
            }
        }