Exemple #1
0
        static void Main(string[] args)
        {
            Address add1 = new Address
            {
                Number = "1",
                Street = "First Street",
                Town = "Glasgow",
                Postcode = "G99 9GL"
            };
            Customer cust1 = new Customer("Schumacher", "Michael", 0.1m, add1);

            Product prod1 = new Product("widget","P1", 10.99m);
            Product prod2 = new Product("gadget", "P2", 8.99m);
            Supplier supp1 = new Supplier("S1", "Acme", "Timo Glock");
            prod1.AddSupplier(supp1, 4.99m);
            prod1.AddSupplier(supp1, 2.99m);

            Order ord1 = new Order("O1", DateTime.Now, cust1);
            ord1.AddLine(3, prod1);
            ord1.AddLine(2, prod2);

            Invoice inv1 = ord1.RaiseInvoice();

            Console.WriteLine("Order price: {0:C}", ord1.CalcPrice());

            Console.ReadLine();
        }
Exemple #2
0
 /// <summary>
 /// constructor for objects of type Order
 /// </summary>
 /// <param name="ordNumber"></param>
 /// <param name="dateReceived"></param>
 /// <param name="customer"></param>
 public Order(string ordNumber, DateTime dateReceived, 
     Customer customer)
 {
     this.ordNumber = ordNumber;
     this.dateReceived = dateReceived;
     this.customer = customer;
     this.orderLines = new List<OrderLine>();
     customer.AddOrder(this);
 }
        public static void CheckandCreate()
        {
            if (File.Exists(FileCustomersPath))
            {

            }
            else
            {
                Customer C = new Customer();
                File.AppendAllText(FileCustomersPath, C.ToString() + Environment.NewLine);
            }
        }
 public static List<Customer> Read()
 {
     List<Customer> customers = new List<Customer>();
     Customer newcustomer;
     string[] lines = File.ReadAllLines(FileCustomersPath);
     foreach (string line in lines)
     {
         var columns = line.Split(',');
         newcustomer = new Customer(Convert.ToInt32(columns[0]), columns[1], columns[2], columns[3], columns[4]);
         customers.Add(newcustomer);
     }
     return customers;
 }
Exemple #5
0
        public void AddLineTest()
        {
            // Arrange
            string ordNumber = "O1";
            DateTime dateReceived = DateTime.Now;
            Customer customer = new Customer(null,null,0.0m,null);
            Order target = new Order(ordNumber, dateReceived, customer);
            int quantity = 5;
            Product product = new Product("PRODUCTNAME",null,0.0m);
            target.AddLine(quantity, product);

            // Act
            string result = target.OrderLines[0].Product.Name;

            // Assert
            Assert.AreEqual("PRODUCTNAME", result);
        }
Exemple #6
0
        public void CalcPriceTest()
        {
            // Arrange
            string ordNumber = "O2";
            DateTime dateReceived = DateTime.Now;
            Customer customer = new Customer(null, null, 0.10m, null);
            Order target = new Order(ordNumber, dateReceived, customer);
            Product product1 = new Product(null, null, 20.0m);
            Product product2 = new Product(null, null, 30.0m);
            target.AddLine(1, product1);
            target.AddLine(2, product2);

            // Act
            Decimal result = target.CalcPrice();

            // Assert
            Assert.AreEqual(72.0m, result);
        }
 public void Update(int ID, string FirstName, string LastName, string Telephone, string Address)
 {
     //Πρώτα πρέπει να πέρνω τα δεδομένα σε Customers obj
     List<Customer> customers = Read();
     // Φτιάνχω έναν νέο Customer με τα νέα στοιχεία τα οποία τα έχω περάσει σαν παραμέτρους.
     Customer Cust = new Customer(ID, FirstName, LastName, Telephone, Address);
     /*Τώρα θα πρέπει να συγκρίνω το ID του Customer με το ID μέσα στο List και να γράψω στο νέο αρχείο
     το οποίο θα κάνει override το παλιό*/
     try
     {
         foreach (Customer i in customers)
         {
             if (i.ID != Cust.ID)
             {
                 Add(i.ToString(), FileHelp);
             }
         }
         Add(Cust.ToString(), FileHelp);
     }
     catch (Exception e)
     {
         MessageBox.Show(e.ToString());
     }
     //Πρέπει να αντιγράψω το FileHelp στο FileCustomersPath και να το κάνω overwrite
     File.Copy(FileHelp, FileCustomersPath, true);
     //Πρέπει να σβήσω το File Help
     File.Delete(FileHelp);
 }