Advertisement
kolarov

Untitled

Feb 17th, 2015
280
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.39 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using _09.Common_Type_System;
  7.  
  8.  
  9. class Customer : ICloneable, IComparable<Customer>
  10. {
  11.     public string FirstName { get; set; }
  12.     public string MiddleName { get; set; }
  13.     public string LastName { get; set; }
  14.     public string EGN { get; set; }
  15.     public string Address { get; set; }
  16.     public string MobilePhone { get; set; }
  17.     public string Email { get; set; }
  18.     public List<Payment> Payments { get; set; }
  19.  
  20.     public CustomerType CustType;
  21.  
  22.     public Customer()
  23.     {
  24.  
  25.     }
  26.     public Customer(string FirstName, string MiddleName, string LastName, string EGN, string Address, string MobilePhone, string Email, List<Payment> Payments, CustomerType customer)
  27.     {
  28.         this.FirstName = FirstName;
  29.         this.MiddleName = MiddleName;
  30.         this.LastName = LastName;
  31.         this.EGN = EGN;
  32.         this.Address = Address;
  33.         this.MobilePhone = MobilePhone;
  34.         this.Email = Email;
  35.         this.Payments = Payments;
  36.         this.CustType = customer;
  37.     }
  38.     public override bool Equals(object obj)
  39.     {
  40.         Customer customer = obj as Customer;
  41.         if (!Object.Equals(this.FirstName, customer.FirstName))
  42.         {
  43.             return false;
  44.         }
  45.         if (!Object.Equals(this.MiddleName, customer.MiddleName))
  46.         {
  47.             return false;
  48.         }
  49.         if (!Object.Equals(this.LastName, customer.LastName))
  50.         {
  51.             return false;
  52.         }
  53.         if (!Object.Equals(this.EGN, customer.EGN))
  54.         {
  55.             return false;
  56.         }
  57.         if (!Object.Equals(this.Address, customer.Address))
  58.         {
  59.             return false;
  60.         }
  61.         if (!Object.Equals(this.MobilePhone, customer.MobilePhone))
  62.         {
  63.             return false;
  64.         }
  65.         if (!Object.Equals(this.Email, customer.Email))
  66.         {
  67.             return false;
  68.         }
  69.         if (!Object.Equals(this.Payments, customer.Payments))
  70.         {
  71.             return false;
  72.         }
  73.         if (!Object.Equals(this.CustType, customer.CustType))
  74.         {
  75.             return false;
  76.         }
  77.         return true;
  78.     }
  79.     public static bool operator ==(Customer customer1, Customer customer2)
  80.     {
  81.         return customer1.Equals(customer2);
  82.     }
  83.     public static bool operator !=(Customer customer1, Customer customer2)
  84.     {
  85.         return !(customer1.Equals(customer2));
  86.     }
  87.     public override int GetHashCode()
  88.     {
  89.          string hashCode = this.FirstName + this.LastName + this.MiddleName + this.EGN;
  90.             return hashCode.GetHashCode();
  91.     }
  92.     public object Clone()
  93.     {
  94.         Customer newCustomer = new Customer();
  95.         newCustomer.FirstName = (string)this.FirstName;
  96.         newCustomer.MiddleName = (string)this.MiddleName;
  97.         newCustomer.LastName = (string)this.LastName;
  98.         newCustomer.EGN = (string)this.EGN;
  99.         newCustomer.Address = (string)this.Address;
  100.         newCustomer.MobilePhone = (string)this.MobilePhone;
  101.         newCustomer.Email = (string)this.Email;
  102.         newCustomer.CustType = this.CustType;
  103.  
  104.         Payment pay1 = new Payment("Motherboard", 254.99m);
  105.         newCustomer.Payments.Add(pay1);
  106.  
  107.         //foreach (var element in this.Payments)
  108.         //{
  109.         //    newCustomer.Payments.Add(new Payment { ProductName = element.ProductName, Price = element.Price });
  110.         //}
  111.  
  112.         return newCustomer;
  113.     }
  114.     public int CompareTo(Customer other)
  115.     {
  116.         string thisFullName = string.Format("{0} {1} {2}", this.FirstName, this.MiddleName, this.LastName);
  117.         string otherFullName = string.Format("{0} {1} {2}", other.FirstName, other.MiddleName, other.LastName);
  118.  
  119.         if (thisFullName.CompareTo(otherFullName) != 0)
  120.         {
  121.             return thisFullName.CompareTo(otherFullName);
  122.         }
  123.         else
  124.         {
  125.             return this.EGN.CompareTo(other.EGN);
  126.         }
  127.     }
  128.     //public override string ToString()
  129.     //{
  130.     //    string Payments = this.Payments.ToString();
  131.     //    return String.Format("Firstname: {0} Middlename: {1} Lastname: {2} EGN: {3} Address: {4} Mobile Phone: {5} Email: {6} Payments: {7} Customer Type: {8}", this.FirstName, this.MiddleName, this.LastName, this.EGN, this.Address, this.MobilePhone, this.Email, Payments, this.CustType);
  132.     //}
  133.  
  134.  
  135.    
  136. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement