Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
160 changes: 85 additions & 75 deletions Product.cs
Original file line number Diff line number Diff line change
@@ -1,75 +1,85 @@
using System;

namespace Events
{
/// <summary>
/// Класс должен описывать представление о товаре.
/// В рамках лабораторной работы должен являться
/// источником события
/// </summary>
class Product
{

#region Variables
/// <summary>
/// Наименование
/// </summary>
private string name;
/// <summary>
/// Стоимость
/// </summary>
private decimal price;

#endregion

#region Properties

/// <summary>
/// Наименование
/// </summary>
public string Name
{
get { return name; }
set
{
name = value;
/*
* TODO #4 Инициировать уведомление об
* изменении наименования
*/
}
}
/// <summary>
/// Стоимость
/// </summary>
public decimal Price
{
get { return price; }
set
{
price = value;
/*
* TODO #5 Инициировать уведомление об
* изменении стоимости
*/
}
}

#endregion

#region Events

/*
* TODO #3 Добавить определение событий
*/

#endregion

public Product(string name, decimal price)
{
Name = name;
Price = price;
}

}
}
using System;

namespace Events
{
/// <summary>
/// Класс должен описывать представление о товаре.
/// В рамках лабораторной работы должен являться
/// источником события
/// </summary>
class Product
{

#region Variables
/// <summary>
/// Наименование
/// </summary>
private string name;
/// <summary>
/// Стоимость
/// </summary>
private decimal price;

#endregion

#region Properties

/// <summary>
/// Наименование
/// </summary>
public string Name
{
get { return name; }
set
{
name = value;
/*
* TODO #4 Инициировать уведомление об
* изменении наименования
*/
if(NameChanged != null)
{
NameChanged(this, new ProductEventArgs(name, value));
}
}
}
/// <summary>
/// Стоимость
/// </summary>
public decimal Price
{
get { return price; }
set
{
price = value;
/*
* TODO #5 Инициировать уведомление об
* изменении стоимости
*/
if(PriceChanged != null)
{
PriceChanged(this, new ProductEventArgs(price, value));
}
}
}

#endregion

#region Events

/*
* TODO #3 Добавить определение событий
*/
public event EventHandler<ProductEventArgs> NameChanged;
public event EventHandler<ProductEventArgs> PriceChanged;

#endregion

public Product(string name, decimal price)
{
Name = name;
Price = price;
}

}
}
44 changes: 26 additions & 18 deletions ProductEventArgs.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
namespace Events
{
/// <summary>
/// Класс, который служит для передачи аргументов
/// в обработчик событий, возникающих в классе
/// <seealso cref="Product">Product</seealso>
/// </summary>
/*
* TODO #1 Закончить определение класса ProductEventArgs
*/
class ProductEventArgs
{
/*
* TODO #2 Добавить определение необходимых компонент
* класса ProductEventArgs
*/
}
}
namespace Events
{
/// <summary>
/// Класс, который служит для передачи аргументов
/// в обработчик событий, возникающих в классе
/// <seealso cref="Product">Product</seealso>
/// </summary>
/*
* TODO #1 Закончить определение класса ProductEventArgs
*/
class ProductEventArgs : EventArgs
{
/*
* TODO #2 Добавить определение необходимых компонент
* класса ProductEventArgs
*/
public string OldName { get; }
public decimal OldPrice { get; }

public ProductEventArgs(string oldName, decimal oldPrice)
{
OldName = oldName;
OldPrice = oldPrice;
}
}
}
79 changes: 47 additions & 32 deletions Program.cs
Original file line number Diff line number Diff line change
@@ -1,37 +1,52 @@
namespace Events
{
class Program
{
internal Product Product
namespace Events
{
class Program
{
internal Product Product
{
get
{
throw new System.NotImplementedException();
}

set
{
throw new System.NotImplementedException();
}
}

static void Main(string[] args)
{
Product product = new Product("Some product name", 0);

/*
* TODO #6 Назначить обработчики событий в текущем контексте
*/
Product product = new Product("Библия C#", 736);
product.NameChanged += OnProductNameChanged;
product.PriceChanged += OnProductPriceChanged;

/*
* TODO #7 Выполнить с экземпляром класса Product действия,
* приводящие к возникновению описанных Вами событий
*/
product.Name = "Философия Java";
product.Price = 1499;

}

/*
* TODO #8 Добавить определение обработчиков событий
*/
private static void OnProductNameChanged(object sender, ProductEventArgs e)
{
get
{
throw new System.NotImplementedException();
}

set
{
throw new System.NotImplementedException();
}
Console.WriteLine("Имя продукта было изменено с '{0}' на '{1}'", e.OldName, e.Product.Name);
}

static void Main(string[] args)
private static void OnProductPriceChanged(object sender, ProductEventArgs e)
{
Product product = new Product("Some product name", 0);

/*
* TODO #6 Назначить обработчики событий в текущем контексте
*/

/*
* TODO #7 Выполнить с экземпляром класса Product действия,
* приводящие к возникновению описанных Вами событий
*/
Console.WriteLine("Цена продукта была изменена с '{0}' на '{1}'", e.OldName, e.Product.Price);
}

/*
* TODO #8 Добавить определение обработчиков событий
*/

}
}
}
}
}