-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
155 lines (114 loc) · 5.71 KB
/
Program.cs
File metadata and controls
155 lines (114 loc) · 5.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CategoryManagementSystem
{
internal class Program
{
static void Main(string[] args)
{
SqlConnection connection = new SqlConnection("Data Source=localhost\\evaleyn5;initial catalog=SqlProject;integrated security=true");
while (true)
{
Console.Clear();
Console.WriteLine("****Restoran Menü Sipariş İşlem Paneli****");
Console.WriteLine();
Console.WriteLine("Yapmak İstediğiniz İşlemi Seçiniz: ");
Console.WriteLine("1- Ürün Ekle");
Console.WriteLine("2- Ürün Listele");
Console.WriteLine("3- Ürün Sil");
Console.WriteLine("4- Ürün Güncelle");
Console.WriteLine("0- Çıkış Yap");
Console.Write("Seçiminiz: ");
int choice = int.Parse(Console.ReadLine());
if (choice == 0)
{
Console.WriteLine("Programdan çıkılıyor...");
break;
}
#region Kategori Ekleme İşlemi
if (choice == 1)
{
Console.Write("Ürün Adı: ");
string name = Console.ReadLine();
Console.Write("Ürün Fiyatı: ");
decimal price = decimal.Parse(Console.ReadLine());
Console.WriteLine("Kategori Seç: ");
Console.WriteLine("1- Başlangıç");
Console.WriteLine("2-Ana Yemek");
Console.WriteLine("3-Tatlı");
int categoryId = int.Parse(Console.ReadLine());
connection.Open();
SqlCommand command = new SqlCommand("insert into TbsProduct (ProductName, ProductPrice, CategoryId) values (@pname, @pprice, @pcategoryid)", connection);
command.Parameters.AddWithValue("@pname", name);
command.Parameters.AddWithValue("@pprice", price);
command.Parameters.AddWithValue("@pcategoryid", categoryId);
command.ExecuteNonQuery();
connection.Close();
Console.WriteLine("Ürün kategoriyle birlikte eklendi!");
}
#endregion
#region Kategori Listeleme İşlemi
if (choice == 2)
{
connection.Open();
string query = "Select * From TbsProduct";
SqlCommand command = new SqlCommand(query, connection);
SqlDataAdapter adapter = new SqlDataAdapter(command);
DataTable dataTable = new DataTable();
adapter.Fill(dataTable);
connection.Close();
Console.WriteLine("******Ürün Listesi******");
foreach (DataRow row in dataTable.Rows)
{
Console.WriteLine($"{row["ProductId"],-5} | {row["ProductName"],-30} | {row["ProductPrice"]} | {row["CategoryId"]}");
}
Console.WriteLine("********************************");
}
#endregion
#region Kategori Silme İşlemi
if (choice == 3)
{
connection.Open();
Console.Write("Silmek istediğiniz ürünün ID'sini giriniz: ");
int id = int.Parse(Console.ReadLine());
string query = "Delete From TbsProduct Where ProductId = @pid";
SqlCommand command = new SqlCommand(query, connection);
command.Parameters.AddWithValue("@pid", id);
command.ExecuteNonQuery();
connection.Close();
Console.WriteLine("Ürün başarıyla silindi!");
}
#endregion
#region Kategori Güncelleme İşlemi
if (choice == 4)
{
connection.Open();
Console.Write("Güncellemek istediğiniz ürünün ID numarasını giriniz: ");
int id = int.Parse(Console.ReadLine());
Console.Write("Yeni Ürün Adı: ");
string name = Console.ReadLine();
Console.Write("Yeni Ürün Fiyatı: ");
decimal price = decimal.Parse(Console.ReadLine());
Console.WriteLine("Yeni Kategori ID: ");
int categoryId = int.Parse(Console.ReadLine());
string query = "Update TbsProduct Set ProductName = @pname, ProductPrice = @pprice, CategoryId = @pcategoryid Where ProductId = @pid";
SqlCommand command = new SqlCommand(query, connection);
command.Parameters.AddWithValue("@pname", name);
command.Parameters.AddWithValue("@pprice", price);
command.Parameters.AddWithValue("@pcategoryid", categoryId);
command.Parameters.AddWithValue("@pid", id);
command.ExecuteNonQuery();
connection.Close();
Console.WriteLine("Ürün başarıyla güncellendi!");
}
#endregion
Console.ReadKey();
}
}
}
}