Построить описание класса, содержащего информацию о почтовом адресе организации - C#
Формулировка задачи:
Построить описание класса, содержащего информацию о почтовом адресе организации. Предусмотреть возможность проверки вводимых значений, в случае ввода неверного значения в textbox выкинуть исключение в label, что вводимые значения верны или неверны. То есть надо проверить в текстбоксах на вводимость правильных значений. В первом и втором текстбоксе будут строковые значения (город, улица), в третьем и четвёртом числовые (дом, индекс).
Помогите пожалуйста, вот мои наработки:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
class my
{
public string a, b;
public double c, q;
public double k;
public void run()
{
}
public void run(string a, string b, double c, double q)
{
this.a = a;
this.b = b;
this.c = c;
this.q = q;
}
private void button1_Click(object sender, EventArgs e)
{
string a, b;
double q, c;
a = Convert.ToString(textBox1.Text);
b = Convert.ToString(textBox2.Text);
c = Convert.ToDouble(textBox3.Text);
q = Convert.ToDouble(textBox4.Text);
my x = new my(a, b, c, q);
if (x.run() == false)
{
label1.Text = "Введённые данные неверны";
}
else
{
label1.Text = "Введённые данные верны";
}
}
}
}
}
Так что, никто не поможет с такой простой задачкой? Сразу скажу я не асс, а тут я так думал - професионалы
Решение задачи: «Построить описание класса, содержащего информацию о почтовом адресе организации»
textual
Листинг программы
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using System.Windows.Forms;
namespace Test
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void InitializeComponent()
{
this.Name = "Address Form";
this.street_box.Location = new System.Drawing.Point(0, 50);
this.street_box.Width += 50;
this.house_box.Location = new System.Drawing.Point(0, 100);
this.index_box.Location = new System.Drawing.Point(0, 150);
this.error_label.ForeColor = System.Drawing.Color.Red;
this.error_label.Location = new System.Drawing.Point(Width / 2, Height / 2);
Button check_button = new Button();
check_button.Text = "Check";
check_button.Click += OnCheckButton_click;
check_button.Location = new System.Drawing.Point(150, 0);
this.Controls.AddRange (new Control[]
{city_box, street_box, house_box, index_box, error_label, check_button});
this.Show ();
}
private void OnCheckButton_click(object sender, EventArgs e)
{
string error_location = string.Empty;
bool error = false;
if (Regex.IsMatch (city_box.Text, @"^(\w|\d|-|\s)+$") == false)
{
error_location = "City";
error = true;
}
if (error == false && Regex.IsMatch (street_box.Text, @"^(\w|\d|-|\s)+$") == false)
{
error_location = "Street";
error = true;
}
if (error == false && (house_box.Text == string.Empty ||
house_box.Text.Any((x) => Char.IsDigit(x) == false)))
{
error_location = "House";
error = true;
}
if (error == false && (index_box.Text == string.Empty ||
index_box.Text.Any ((x) => Char.IsDigit (x) == false)))
{
error_location = "Index";
error = true;
}
if (error == true)
{
error_label.Text = "Error in " + error_location;
error_label.Show ();
}
else
{
error_label.Hide ();
}
}
private TextBox city_box = new TextBox();
private TextBox street_box = new TextBox();
private TextBox house_box = new TextBox();
private TextBox index_box = new TextBox();
private Label error_label = new Label();
}
class Program
{
static void Main()
{
Application.Run (new Form1());
}
}
}