Advertisement
Guest User

Untitled

a guest
Nov 19th, 2018
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.64 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10.  
  11.  
  12. // This is the code for your desktop app.
  13. // Press Ctrl+F5 (or go to Debug > Start Without Debugging) to run your app.
  14.  
  15. namespace CostumerRegistry
  16. {
  17. public partial class ContactForm : Form
  18. {
  19. private bool closeForm;
  20. private Contact contact = new Contact();
  21. private Email mail;
  22. private Phone tel = new Phone();
  23. private Adress address = new Adress();
  24.  
  25.  
  26.  
  27. public ContactForm()
  28. {
  29. InitializeComponent();
  30.  
  31. InitializeGUI();
  32. }
  33.  
  34. private void InitializeGUI()
  35. {
  36. cmbCountry.DataSource = Enum.GetNames(typeof(Countries));
  37. closeForm = true;
  38.  
  39. txtCellPhone.Text = "";
  40. txtCity.Text = "";
  41. txtEmail.Text = "";
  42. txtFirstName.Text = "";
  43. txtHomePhone.Text = "";
  44. txtLastName.Text = "";
  45. txtStreet.Text = "";
  46. txtWorkEmail.Text = "";
  47. txtZip.Text = "";
  48. cmbCountry.SelectedIndex = (int)Countries.Sverige;
  49.  
  50. }
  51.  
  52. private void hello ()
  53. {
  54. txtCellPhone.Text = "12345678910";
  55. txtCity.Text = "town";
  56. txtEmail.Text = "email@email.com";
  57. txtFirstName.Text = "Name";
  58. txtHomePhone.Text = "123456789";
  59. txtLastName.Text = "Namesson";
  60. txtStreet.Text = "Streety";
  61. txtWorkEmail.Text = "WorkMail@email.com";
  62. txtZip.Text = "1234567";
  63. }
  64.  
  65. private Contact contactData
  66. {
  67. get { return contactData; }
  68. set
  69. {
  70. if (value != null)
  71. contactData = value;
  72. }
  73.  
  74. }
  75.  
  76. private void btnOk_Click(object sender, EventArgs e)
  77. {
  78. mail = new Email();
  79. bool ok = ValidateData();
  80.  
  81. if (ok)
  82. {
  83. //if (MessageBox.Show("Are you sure?", "Confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  84. {
  85. MessageBox.Show(contact.ToString(), "info");
  86. }
  87.  
  88.  
  89. }
  90.  
  91. }
  92.  
  93. private void btnCancel_Click(object sender, EventArgs e)
  94. {
  95. if (MessageBox.Show("Do you want to discard your information?", "Confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  96. InitializeGUI();
  97. }
  98.  
  99. private bool ValidateData()
  100. {
  101. bool ok;
  102. bool ok1 = ReadNames();
  103. bool ok2 = ReadEmailAndPhones();
  104. bool ok3 = ReadAddress();
  105.  
  106. if (ok1 && ok2 && ok3)
  107. ok = true;
  108. else
  109. ok = false;
  110. return ok;
  111. }
  112.  
  113. private bool ReadAddress()
  114. {
  115. bool ok = true;
  116. if (string.IsNullOrEmpty(txtZip.Text) || string.IsNullOrEmpty(txtStreet.Text) || string.IsNullOrEmpty(txtCity.Text))
  117. {
  118. ok = false;
  119. MessageBox.Show("Invalid Adress values", "error");
  120. }
  121. else
  122. {
  123.  
  124. address.City = txtCity.Text.ToString();
  125. //address.Country = cmbCountry.SelectedIndex;
  126. address.Zip = txtZip.Text.ToString();
  127. address.Street = txtStreet.Text.ToString();
  128. MessageBox.Show(txtZip.Text);
  129. ok = true;
  130. }
  131. return ok;
  132. }
  133. private bool ReadEmailAndPhones()
  134. {
  135. bool ok = true;
  136.  
  137. if (string.IsNullOrEmpty(txtEmail.Text) || string.IsNullOrEmpty(txtCellPhone.Text) || string.IsNullOrEmpty(txtHomePhone.Text))
  138. {
  139. ok = false;
  140. MessageBox.Show("Invalid email and phones value", "error");
  141. }
  142. else
  143. {
  144. tel.Cell = txtCellPhone.Text;
  145. tel.Home = txtHomePhone.Text;
  146. mail.Personal = txtEmail.Text;
  147. mail.Work = txtWorkEmail.Text;
  148. int.TryParse(txtZip.Text, out int zip);
  149. mail.Test = zip;
  150. Console.WriteLine(zip);
  151. ok = true;
  152. }
  153. return ok;
  154. }
  155.  
  156. private bool ReadNames()
  157. {
  158. bool ok = true;
  159.  
  160. if (string.IsNullOrEmpty(txtFirstName.Text) || string.IsNullOrEmpty(txtLastName.Text))
  161. {
  162. ok = false;
  163. MessageBox.Show("Invalid Name values", "error");
  164. }
  165. else
  166. {
  167. contact.FirstName = txtFirstName.Text;
  168. contact.LastName = txtLastName.Text;
  169. ok = true;
  170. }
  171.  
  172. return ok;
  173.  
  174. }
  175.  
  176. private void button1_Click(object sender, EventArgs e)
  177. {
  178. hello();
  179. }
  180.  
  181. private void ContactForm_FormClosing(object sender, FormClosingEventArgs e)
  182. {
  183. if (closeForm)
  184. e.Cancel = false;
  185. else
  186. e.Cancel = true;
  187. }
  188. }
  189. }
  190. //////////////////////////////////////////////////// second class
  191.  
  192. using System;
  193. using System.Collections.Generic;
  194. using System.Linq;
  195. using System.Text;
  196. using System.Threading.Tasks;
  197.  
  198. namespace CostumerRegistry
  199. {
  200. class Contact
  201. {
  202. private string firstName = string.Empty;
  203. private string lastName = "";
  204. private string email;
  205. private string fullName;
  206.  
  207. private Adress address = new Adress();
  208. private Email mail = new Email();
  209. private Phone tel = new Phone();
  210.  
  211. public Contact()
  212. {
  213. address = new Adress();
  214. mail = new Email();
  215. tel = new Phone();
  216. }
  217.  
  218. public Contact(string firstName, string lastName, Adress adr, Phone tel, Email mail)
  219. {
  220. }
  221.  
  222. public Contact (Contact theOther)
  223. {
  224. this.firstName = theOther.firstName;
  225. this.lastName = theOther.lastName;
  226. this.address = new Adress(theOther.address);
  227. this.mail = new Email(theOther.email);
  228. this.tel = new Phone(theOther.tel);
  229. }
  230. public Phone phoneData
  231. {
  232. get { return phoneData; }
  233. set
  234. {
  235. phoneData = value;
  236. }
  237. }
  238.  
  239. public Email emailData
  240. {
  241. get { return emailData; }
  242. set { emailData = value; }
  243. }
  244. public Adress adressData
  245. {
  246. get { return adressData; }
  247. set
  248. {
  249. adressData = value;
  250. }
  251. }
  252. public string FirstName
  253. {
  254. get { return firstName; }
  255. set {
  256. if (!string.IsNullOrEmpty(value))
  257. firstName = value;
  258. }
  259. }
  260. public string LastName
  261. {
  262. get { return lastName; }
  263. set
  264. {
  265. if (!string.IsNullOrEmpty(value))
  266. lastName = value;
  267. }
  268. }
  269. public string Email
  270. {
  271. get { return email; }
  272. set
  273. {
  274. if (!string.IsNullOrEmpty(value))
  275. email = value;
  276. }
  277. }
  278.  
  279. public string FullName
  280. {
  281. get { return fullName = FirstName + lastName; }
  282. }
  283.  
  284. public override string ToString()
  285. {
  286. Console.WriteLine("working" + mail.testString());
  287. string strOut = string.Format("{0} {1} {2} {3}", fullName, mail.ToString(), tel.ToString(), address.ToString());
  288. return strOut;
  289. }
  290. }
  291. }
  292. ////////////////////////////////////////////////////// third class
  293. using System;
  294. using System.Collections.Generic;
  295. using System.Linq;
  296. using System.Text;
  297. using System.Threading.Tasks;
  298.  
  299. namespace CostumerRegistry
  300. {
  301. class Adress
  302. {
  303.  
  304. private string street;
  305. private string zip;
  306. private string city;
  307. private Countries country;
  308.  
  309. public Adress()
  310. {
  311. }
  312.  
  313. public Adress (Adress theOther)
  314. {
  315. this.street = theOther.street;
  316. this.zip = theOther.zip;
  317. this.city = theOther.zip;
  318. this.country = theOther.country;
  319. }
  320.  
  321. public Adress(string street, string zip, string city, Countries country)
  322. {
  323.  
  324. }
  325.  
  326. public Adress (string street, string zip, string city): this(street, zip, city, Countries.Sverige)
  327. {
  328. this.street = street;
  329. this.zip = zip;
  330. this.city = city;
  331. this.country = Countries.Sverige;
  332.  
  333.  
  334. }
  335.  
  336. public string Street
  337. {
  338. get { return Street; }
  339. set
  340. {
  341. if (!string.IsNullOrEmpty(value))
  342. street = value;
  343. }
  344. }
  345.  
  346. public string Zip
  347. {
  348. get { return zip; }
  349. set
  350. {
  351. if (!string.IsNullOrEmpty(value))
  352. zip = value;
  353. }
  354. }
  355.  
  356. public string City
  357. {
  358. get { return city; }
  359. set
  360. {
  361. if (!string.IsNullOrEmpty(value))
  362. city = value;
  363. }
  364. }
  365.  
  366.  
  367. public Countries Country
  368. {
  369. get { return country; }
  370. set
  371. {
  372. country = value;
  373. }
  374. }
  375.  
  376. public bool CheckData()
  377. {
  378. bool ok;
  379. string m_strErrMessage;
  380.  
  381. if (string.IsNullOrEmpty(city) || string.IsNullOrEmpty(street) || string.IsNullOrEmpty(zip))
  382. {
  383. m_strErrMessage = "Invalid input";
  384. ok = false;
  385. }
  386. else
  387. ok = true;
  388.  
  389. return ok;
  390.  
  391. }
  392.  
  393. public string GetCountryString()
  394. {
  395. string strCountry = country.ToString();
  396. strCountry = strCountry.Replace("_", "");
  397. return strCountry;
  398. }
  399.  
  400. public override string ToString()
  401. {
  402. return String.Format("{0, -25} {1,-8} {2,-10} {3}",
  403. street, zip, city, country, GetCountryString());
  404.  
  405. }
  406. }
  407. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement