Example #1
0
        //functie care se executa la click
        private void button1_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(textBox_Id.Text))
            {
                MessageBox.Show("Id cannot be empty!");
                return;
            }

            if (string.IsNullOrEmpty(textBox_Name.Text))
            {
                MessageBox.Show("Name cannot be empty!");
                return;
            }

            if (string.IsNullOrEmpty(textBox_Faculty.Text))
            {
                MessageBox.Show("Faculty cannot be empty!");
                return;
            }

            int id = 0; //conversie string ==> int

            if (!int.TryParse(textBox_Id.Text, out id))
            {
                MessageBox.Show(string.Format("{0} is not a number!", textBox_Id.Text));
                return;
            }

            sl.Add(new Student()
            {
                Id      = id,
                Name    = textBox_Name.Text,
                Faculty = textBox_Faculty.Text
            });

            richTextBox1.Clear();
            richTextBox1.Text = sl.ToString();
        }
Example #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(textBoxID.Text))
            {
                MessageBox.Show("ID cannot be empty!");
                return;
            }

            if (string.IsNullOrEmpty(textBoxModel.Text))
            {
                MessageBox.Show("Model cannot be empty!");
                return;
            }

            if (string.IsNullOrEmpty(textBoxManufacturer.Text))
            {
                MessageBox.Show("Manufacturer cannot be empty!");
                return;
            }

            int id = 0; //conversie string ==> int

            if (!int.TryParse(textBoxID.Text, out id))
            {
                MessageBox.Show(string.Format("{0} is not a number!", textBoxID.Text));
                return;
            }

            int year = 0; //conversie string ==> int

            if (!int.TryParse(textBoxYear.Text, out year))
            {
                MessageBox.Show(string.Format("{0} is not a number!", textBoxYear.Text));
                return;
            }

            ap.Add(new Car()
            {
                Id           = id,
                Model        = textBoxModel.Text,
                Manufacturer = textBoxManufacturer.Text,
                Year         = year
            });

            richTextBox1.Clear();
            richTextBox1.Text = ap.ToString();
        }