ВУЗ: Не указан
Категория: Не указан
Дисциплина: Не указана
Добавлен: 08.04.2024
Просмотров: 45
Скачиваний: 0
За допомогою цієї програми можна додавати, редагувати, видаляти комп’ютери, замовляти ремонт, відсилати дані на сервери та проводити ремонт деталі та виконувати замовлення.
СПИСОК ВИКОРИСТАНИХ ДЖЕРЕЛ
-
Словник іншомовних слів Мельничука [Електронний ресурс]- Режим доступа:
http://slovopedia.org.ua/42/53407/288564.html
-
Шилдт Г. C# 4.0 Полное руководство. [Текст] : Пер. с англ. – М.: ООО «И.Д.Вильямс», 2011. – 1056 с.
-
Алгоритм пошуку. [Електронний ресурс] – Режим доступа: https://uk.wikipedia.org/wiki/Алгоритм_пошуку
-
Microsoft Docs [Електронний ресурс]- Режим доступа:
https://docs.microsoft.com/uk-ua/
-
Windows Presentation Foundation [Електронний ресурс] – Режим доступа:
https://en.wikipedia.org/wiki/Windows_Presentation_Foundation
-
Вікіпедія ООП [Електронний ресурс]- Режим доступа:
https://uk.wikipedia.org/wiki/Об%27єктно-орієнтоване_програмування
-
Парадигма програмування [Електронний ресурс] – Режи доступа:
https://uk.wikipedia.org/wiki/Парадигма_програмування
-
Вікіпедія Компонентно-орієнтоване програмування [Електронний ресурс]- Режим доступа:
https://uk.wikipedia.org/wiki/Компонентно-орієнтоване_програмування
-
Model-View-ViewModel [Електронний ресурс]- Режим доступа:
https://uk.wikipedia.org/wiki/Model-View-ViewModel
-
Принципи solid [Електронний ресурс]- Режим доступа:
https://uk.wikipedia.org/wiki/SOLID_(об%27єктно-орієнтоване_програмування)
-
Microsoft SQL Server [Електронний ресурс]- Режим доступа:
https://uk.wikipedia.org/wiki/Microsoft_SQL_Server
-
UML [Електронний ресурс]- Режим доступа:
https://www.uml.org/
-
Діаграма прецидентів [Електронний ресурс]- Режим доступа:
https://uk.wikipedia.org/wiki/Діаграма_прецедентів
-
Діаграма класів [Електронний ресурс]- Режим доступа:
https://uk.wikipedia.org/wiki/Діаграма_класів
-
Repository [Електронний ресурс]- Режим доступа:
https://uk.wikipedia.org/wiki/Repository
-
Методичні матеріали з дисципліни «Технології розроблення програмного забезпечення-2» [Електронний ресурс]- Режим доступа:
https://studfile.net/preview/5065022/page:3/
-
What is LocalDB? [Електронний ресурс]- Режим доступа:
https://expressdb.io/sql-server-express-vs-localdb.html
-
Методичні матеріали з дисципліни «ПРОГРАМНЕ ЗАБЕЗПЕЧЕННЯ» [Електронний ресурс]- Режим доступа:
https://studfile.net/preview/5462335/
-
METANIT.COM [Електронний ресурс]- Режим доступа:
https://metanit.com/
-
Windows Presentation Foundation [Електронний ресурс]- Режим доступа:
https://uk.wikipedia.org/wiki/Windows_Presentation_Foundation
-
Stackoverflow [Електронний ресурс]- Режим доступа:
https://stackoverflow.com/
ДОДАТОК А (ЛІСТИНГ ПРОГРАМИ)
Тест програми «Ремонт комп’ютерів»
Лістинг А.1 – Клас «GenericRepository» (файл GenericRepository.cs)
public class GenericRepository<TEntity> : IGenericRepository<TEntity> where TEntity : class
{
public ApplicationContext Context { get; set; }
public DbSet<TEntity> DbSet
{
get { return Context.Set<TEntity>(); }
}
public GenericRepository(ApplicationContext context)
{
Context = context;
}
public void Create(TEntity entity)
{
DbSet.Add(entity);
Context.SaveChanges();
}
public void Delete(TEntity entity)
{
DbSet.Remove(entity);
Context.SaveChanges();
}
public IEnumerable<TEntity> GetAll()
{
return DbSet.ToList();
}
public TEntity GetById(int id)
{
return DbSet.Find(id);
}
public void Update(TEntity entity)
{
Context.Entry(entity).State = EntityState.Modified;
Context.SaveChanges();
}
}
Лістинг А.2 – Клас «ItemRepositoryADO» (файл ItemRepositoryADO.cs)
public class ItemRepositoryADO : IRepository<Item>
{
private readonly string connectionString;
SqlDataAdapter adapter;
DataTable itemsTable;
string error;
DataTable detailsTable;
public List<Detail> GetDetails(int itemId)
{
detailsTable = new DataTable();
string sql = "select * from detail " +
"where Item_Id = @itemId";
List<Detail> result = new List<Detail>();
try
{
SqlConnection connection = new SqlConnection(connectionString);
SqlCommand command = new SqlCommand(sql, connection);
SqlParameter itemIdParam = new SqlParameter("@itemId", itemId);
command.Parameters.Add(itemIdParam);
adapter = new SqlDataAdapter(command);
connection.Open();
adapter.Fill(detailsTable);
foreach (DataRow row in detailsTable.Rows)
{
var el = new Detail
{
Company = row["Company"].ToString(),
ImagePath = row["ImagePath"].ToString(),
Title = row["Title"].ToString(),
Price = Convert.ToInt32(row["Price"]),
Id = Convert.ToInt32(row["Id"]),
Item_Id = Convert.ToInt32(row["Item_Id"]),
Status = Convert.ToInt32(row["Status"]) == 1 ? true : false
};
result.Add(el);
}
if (connection != null)
connection.Close();
if (detailsTable != null)
detailsTable.Clear();
}
catch (Exception ex)
{
}
return result;
}
public void RepairDetail(int detailId)
{
string sql = "Update detail set status = 1 " +
"where id = @detailId";
try
{
using (SqlConnection conn = new SqlConnection(connectionString))
{
conn.Open();
SqlCommand command = new SqlCommand(sql, conn);
SqlParameter detailIdParam = new SqlParameter("@detailId", detailId);
command.Parameters.Add(detailIdParam);
int num = command.ExecuteNonQuery();
command.Dispose();
if (conn != null)
conn.Close();
}
}
catch (Exception ex)
{
}
}
public List<Item> GetOrderedComputers()
{
string sqlQuery =
"select * from Items " +
"where Id in " +
"(select Item_Id from OrderItems)";
return GetItemsFromQuery(sqlQuery);
}
public void RepairComputer(int ItemId, int OrderId)
{
string query =
"Delete from OrderItems " +
"where Order_Id = @orderId " +
"and Item_Id = @ItemId";
try
{
using (SqlConnection conn = new SqlConnection(connectionString))
{
conn.Open();
SqlCommand comm = new SqlCommand(query, conn);
SqlParameter idParam = new SqlParameter("@orderId",OrderId);
comm.Parameters.Add(idParam);
SqlParameter idItemParam = new SqlParameter("@ItemId", ItemId);
comm.Parameters.Add(idItemParam);
int num = comm.ExecuteNonQuery();
comm.Dispose();
if (conn != null)
conn.Close();
}
}
catch (Exception ex)
{
}
}
public List<ItemAndOrderId> GetOrderedComputersAndOrderId()
{
List<Item> items = GetOrderedComputers();
List<ItemAndOrderId> itemandOrderId = new List<ItemAndOrderId>();
List<OrderItem> OrderIdItemId = new List<OrderItem>();
string query =
"select * from OrderItems";
try
{
DataTable orderItemsDataTable = new DataTable();
using (SqlConnection connection = new SqlConnection(connectionString))
{
SqlCommand command = new SqlCommand(query, connection);
adapter = new SqlDataAdapter(command);
connection.Open();
adapter.Fill(orderItemsDataTable);
foreach (DataRow row in orderItemsDataTable.Rows)
{
var el = new OrderItem
{
OrderId = Convert.ToInt32(row["Order_Id"]),
ItemId = Convert.ToInt32(row["Item_Id"])
};
OrderIdItemId.Add(el);
}
connection.Close();
}
}
catch (Exception ex)
{
}
foreach(var el in OrderIdItemId)
{
foreach(var ordItem in items)
{
if(el.ItemId == ordItem.Id)
{
itemandOrderId.Add(new ItemAndOrderId
{
item= ordItem,
OrderId = el.OrderId
});
}
}
}
return itemandOrderId;
}
public ItemRepositoryADO()
{
try
{
connectionString = ConfigurationManager.ConnectionStrings["MvvmAppDb"].ConnectionString;
}
catch (Exception ex)
{
error = ex.Message.ToString();
}
}
#region
//private void ExecuteQuery(string sqlQuery)
//{
// using (SqlConnection conn = new SqlConnection(connectionString))
// {
// conn.Open();
// SqlCommand comm = new SqlCommand(sqlQuery, conn);
// int num = comm.ExecuteNonQuery();
// comm.Dispose();
// if (conn != null)
// conn.Close();
// if(itemsTable!=null)
// itemsTable.Clear();
// }
//}
#endregion
public void Create(Item item)
{
//ExecuteQuery(sqlQuery);
string sqlQueryParametrized =
"Insert into Items (Title,ImagePath,Price,Company)" +
"Values (@Title,@ImagePath,@Price,@Company)";
using (SqlConnection conn = new SqlConnection(connectionString))
{
conn.Open();
SqlCommand comm = new SqlCommand(sqlQueryParametrized, conn);
SqlParameter titleParam = new SqlParameter("@Title", item.Title);
comm.Parameters.Add(titleParam);
SqlParameter ImagePathParam = new SqlParameter("@ImagePath", item.ImagePath);
comm.Parameters.Add(ImagePathParam);
SqlParameter PriceParam = new SqlParameter("@Price", item.Price);
comm.Parameters.Add(PriceParam);
SqlParameter CompanyParam = new SqlParameter("@Company", item.Company);
comm.Parameters.Add(CompanyParam);
int num = comm.ExecuteNonQuery();
comm.Dispose();
if (conn != null)
conn.Close();
}
}
public void Delete(int id)
{
string sqlQuery =
"Delete from Items " +
"Where id = @Id";
using (SqlConnection conn = new SqlConnection(connectionString))
{
conn.Open();
SqlCommand comm = new SqlCommand(sqlQuery, conn);
SqlParameter idParam = new SqlParameter("@Id",id);
comm.Parameters.Add(idParam);
int num = comm.ExecuteNonQuery();
comm.Dispose();
if (conn != null)
conn.Close();
}
}
private List<Item> GetItemsFromQuery(string sql)
{
var result = new List<Item>();
try
{
itemsTable = new DataTable();
SqlConnection connection = new SqlConnection(connectionString);
SqlCommand command = new SqlCommand(sql, connection);
adapter = new SqlDataAdapter(command);
connection.Open();
adapter.Fill(itemsTable);
foreach (DataRow row in itemsTable.Rows)
{
var el = new Item
{
Company = row["Company"].ToString(),
ImagePath = row["ImagePath"].ToString(),
Title = row["Title"].ToString(),
Price = Convert.ToInt32(row["Price"]),
Id = Convert.ToInt32(row["Id"])
};
result.Add(el);
}
if (connection != null)
connection.Close();
if (itemsTable != null)
itemsTable.Clear();
}
catch (Exception ex)
{
}
return result;
}
public IEnumerable<Item> GetAllItems()
{
string sql = "Select * from Items";
return GetItemsFromQuery(sql);
}
public async Task<IEnumerable<Item>> GetAllItemsAsync()
{
string sql = "Select * from Items";
itemsTable = new DataTable();
using (SqlConnection connection = new SqlConnection(connectionString))
{
SqlCommand command = new SqlCommand(sql, connection);
adapter = new SqlDataAdapter(command);
await connection.OpenAsync();
adapter.Fill(itemsTable);
var result = new List<Item>();
foreach (DataRow row in itemsTable.Rows)
{
var el = new Item
{
Company = row["Company"].ToString(),
ImagePath = row["ImagePath"].ToString(),
Title = row["Title"].ToString(),
Price = Convert.ToInt32(row["Price"]),
Id = Convert.ToInt32(row["Id"])
};
result.Add(el);
}
if (connection != null)
connection.Close();
return result;
}
}
public Item GetItem(int id)
{
string sql = "Select * from Items " +
"where id = @Id";
var res = new Item();
itemsTable = new DataTable();
try
{
using (SqlConnection connection = new SqlConnection(connectionString))
{
SqlCommand command = new SqlCommand(sql, connection);
SqlParameter idParam = new SqlParameter("@Id", id);
command.Parameters.Add(idParam);
adapter = new SqlDataAdapter(command);
connection.Open();
adapter.Fill(itemsTable);
foreach (DataRow row in itemsTable.Rows)
{
var el = new Item
{
Company = row["Company"].ToString(),
ImagePath = row["ImagePath"].ToString(),
Title = row["Title"].ToString(),
Price = Convert.ToInt32(row["Price"]),
Id = Convert.ToInt32(row["Id"])
};
res = el;
}
connection.Close();
if (itemsTable != null)
itemsTable.Clear();
}
}
catch (Exception ex)
{
}