Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- // This is the code for your desktop app.
- // Press Ctrl+F5 (or go to Debug > Start Without Debugging) to run your app.
- namespace CostumerRegistry
- {
- public partial class ContactForm : Form
- {
- private bool closeForm;
- private Contact contact = new Contact();
- private Email mail;
- private Phone tel = new Phone();
- private Adress address = new Adress();
- public ContactForm()
- {
- InitializeComponent();
- InitializeGUI();
- }
- private void InitializeGUI()
- {
- cmbCountry.DataSource = Enum.GetNames(typeof(Countries));
- closeForm = true;
- txtCellPhone.Text = "";
- txtCity.Text = "";
- txtEmail.Text = "";
- txtFirstName.Text = "";
- txtHomePhone.Text = "";
- txtLastName.Text = "";
- txtStreet.Text = "";
- txtWorkEmail.Text = "";
- txtZip.Text = "";
- cmbCountry.SelectedIndex = (int)Countries.Sverige;
- }
- private void hello ()
- {
- txtCellPhone.Text = "12345678910";
- txtCity.Text = "town";
- txtEmail.Text = "email@email.com";
- txtFirstName.Text = "Name";
- txtHomePhone.Text = "123456789";
- txtLastName.Text = "Namesson";
- txtStreet.Text = "Streety";
- txtWorkEmail.Text = "WorkMail@email.com";
- txtZip.Text = "1234567";
- }
- private Contact contactData
- {
- get { return contactData; }
- set
- {
- if (value != null)
- contactData = value;
- }
- }
- private void btnOk_Click(object sender, EventArgs e)
- {
- mail = new Email();
- bool ok = ValidateData();
- if (ok)
- {
- //if (MessageBox.Show("Are you sure?", "Confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
- {
- MessageBox.Show(contact.ToString(), "info");
- }
- }
- }
- private void btnCancel_Click(object sender, EventArgs e)
- {
- if (MessageBox.Show("Do you want to discard your information?", "Confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
- InitializeGUI();
- }
- private bool ValidateData()
- {
- bool ok;
- bool ok1 = ReadNames();
- bool ok2 = ReadEmailAndPhones();
- bool ok3 = ReadAddress();
- if (ok1 && ok2 && ok3)
- ok = true;
- else
- ok = false;
- return ok;
- }
- private bool ReadAddress()
- {
- bool ok = true;
- if (string.IsNullOrEmpty(txtZip.Text) || string.IsNullOrEmpty(txtStreet.Text) || string.IsNullOrEmpty(txtCity.Text))
- {
- ok = false;
- MessageBox.Show("Invalid Adress values", "error");
- }
- else
- {
- address.City = txtCity.Text.ToString();
- //address.Country = cmbCountry.SelectedIndex;
- address.Zip = txtZip.Text.ToString();
- address.Street = txtStreet.Text.ToString();
- MessageBox.Show(txtZip.Text);
- ok = true;
- }
- return ok;
- }
- private bool ReadEmailAndPhones()
- {
- bool ok = true;
- if (string.IsNullOrEmpty(txtEmail.Text) || string.IsNullOrEmpty(txtCellPhone.Text) || string.IsNullOrEmpty(txtHomePhone.Text))
- {
- ok = false;
- MessageBox.Show("Invalid email and phones value", "error");
- }
- else
- {
- tel.Cell = txtCellPhone.Text;
- tel.Home = txtHomePhone.Text;
- mail.Personal = txtEmail.Text;
- mail.Work = txtWorkEmail.Text;
- int.TryParse(txtZip.Text, out int zip);
- mail.Test = zip;
- Console.WriteLine(zip);
- ok = true;
- }
- return ok;
- }
- private bool ReadNames()
- {
- bool ok = true;
- if (string.IsNullOrEmpty(txtFirstName.Text) || string.IsNullOrEmpty(txtLastName.Text))
- {
- ok = false;
- MessageBox.Show("Invalid Name values", "error");
- }
- else
- {
- contact.FirstName = txtFirstName.Text;
- contact.LastName = txtLastName.Text;
- ok = true;
- }
- return ok;
- }
- private void button1_Click(object sender, EventArgs e)
- {
- hello();
- }
- private void ContactForm_FormClosing(object sender, FormClosingEventArgs e)
- {
- if (closeForm)
- e.Cancel = false;
- else
- e.Cancel = true;
- }
- }
- }
- //////////////////////////////////////////////////// second class
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace CostumerRegistry
- {
- class Contact
- {
- private string firstName = string.Empty;
- private string lastName = "";
- private string email;
- private string fullName;
- private Adress address = new Adress();
- private Email mail = new Email();
- private Phone tel = new Phone();
- public Contact()
- {
- address = new Adress();
- mail = new Email();
- tel = new Phone();
- }
- public Contact(string firstName, string lastName, Adress adr, Phone tel, Email mail)
- {
- }
- public Contact (Contact theOther)
- {
- this.firstName = theOther.firstName;
- this.lastName = theOther.lastName;
- this.address = new Adress(theOther.address);
- this.mail = new Email(theOther.email);
- this.tel = new Phone(theOther.tel);
- }
- public Phone phoneData
- {
- get { return phoneData; }
- set
- {
- phoneData = value;
- }
- }
- public Email emailData
- {
- get { return emailData; }
- set { emailData = value; }
- }
- public Adress adressData
- {
- get { return adressData; }
- set
- {
- adressData = value;
- }
- }
- public string FirstName
- {
- get { return firstName; }
- set {
- if (!string.IsNullOrEmpty(value))
- firstName = value;
- }
- }
- public string LastName
- {
- get { return lastName; }
- set
- {
- if (!string.IsNullOrEmpty(value))
- lastName = value;
- }
- }
- public string Email
- {
- get { return email; }
- set
- {
- if (!string.IsNullOrEmpty(value))
- email = value;
- }
- }
- public string FullName
- {
- get { return fullName = FirstName + lastName; }
- }
- public override string ToString()
- {
- Console.WriteLine("working" + mail.testString());
- string strOut = string.Format("{0} {1} {2} {3}", fullName, mail.ToString(), tel.ToString(), address.ToString());
- return strOut;
- }
- }
- }
- ////////////////////////////////////////////////////// third class
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace CostumerRegistry
- {
- class Adress
- {
- private string street;
- private string zip;
- private string city;
- private Countries country;
- public Adress()
- {
- }
- public Adress (Adress theOther)
- {
- this.street = theOther.street;
- this.zip = theOther.zip;
- this.city = theOther.zip;
- this.country = theOther.country;
- }
- public Adress(string street, string zip, string city, Countries country)
- {
- }
- public Adress (string street, string zip, string city): this(street, zip, city, Countries.Sverige)
- {
- this.street = street;
- this.zip = zip;
- this.city = city;
- this.country = Countries.Sverige;
- }
- public string Street
- {
- get { return Street; }
- set
- {
- if (!string.IsNullOrEmpty(value))
- street = value;
- }
- }
- public string Zip
- {
- get { return zip; }
- set
- {
- if (!string.IsNullOrEmpty(value))
- zip = value;
- }
- }
- public string City
- {
- get { return city; }
- set
- {
- if (!string.IsNullOrEmpty(value))
- city = value;
- }
- }
- public Countries Country
- {
- get { return country; }
- set
- {
- country = value;
- }
- }
- public bool CheckData()
- {
- bool ok;
- string m_strErrMessage;
- if (string.IsNullOrEmpty(city) || string.IsNullOrEmpty(street) || string.IsNullOrEmpty(zip))
- {
- m_strErrMessage = "Invalid input";
- ok = false;
- }
- else
- ok = true;
- return ok;
- }
- public string GetCountryString()
- {
- string strCountry = country.ToString();
- strCountry = strCountry.Replace("_", "");
- return strCountry;
- }
- public override string ToString()
- {
- return String.Format("{0, -25} {1,-8} {2,-10} {3}",
- street, zip, city, country, GetCountryString());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement