-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
122 lines (95 loc) · 4.15 KB
/
Program.cs
File metadata and controls
122 lines (95 loc) · 4.15 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
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TodoApp
{
internal class Program
{
static void Main(string[] args)
{
SqlConnection connection = new SqlConnection("Data Source=localhost\\evaleyn5;Initial Catalog=TblTodo;Integrated Security=True");
while (true)
{
Console.Clear();
Console.WriteLine("*****Todo Uygulaması*****");
Console.WriteLine("1- Görev Ekle");
Console.WriteLine("2- Görevleri Listele");
Console.WriteLine("3- Görev Sil");
Console.WriteLine("4- Görev Tamamlandı Yap");
Console.WriteLine("0- Çıkış");
Console.Write("Seçiminiz: ");
int choice = int.Parse(Console.ReadLine());
if (choice == 0)
{
Console.WriteLine("Çıkış yapılıyor...");
break;
}
#region Görev Ekle
if (choice == 1)
{
Console.Write("Görev Adı: ");
string name = Console.ReadLine();
connection.Open();
SqlCommand command = new SqlCommand("INSERT INTO TbsTask (TaskName, IsCompleted) VALUES (@name, 0)", connection);
command.Parameters.AddWithValue("@name", name);
command.ExecuteNonQuery();
connection.Close();
Console.WriteLine("Görev eklendi!");
Console.ReadKey();
}
#endregion
#region Görev Listele
if (choice == 2)
{
connection.Open();
SqlCommand command = new SqlCommand("SELECT * FROM TbsTask", connection);
SqlDataAdapter adapter = new SqlDataAdapter(command);
DataTable table = new DataTable();
adapter.Fill(table);
connection.Close();
Console.WriteLine("*****Görev Listesi*****");
foreach (DataRow row in table.Rows)
{
string status = (bool)row["IsCompleted"] ? "✔️" : "❌";
Console.WriteLine($"{row["TaskId"],-5} | {row["TaskName"],-30} | {status}");
}
Console.WriteLine("********************************");
Console.ReadKey();
}
#endregion
#region Görev Sil
if (choice == 3)
{
Console.Write("Silinecek Görev ID'si: ");
int id = int.Parse(Console.ReadLine());
connection.Open();
SqlCommand command = new SqlCommand("DELETE FROM TbsTask WHERE TaskId = @id", connection);
command.Parameters.AddWithValue("@id", id);
command.ExecuteNonQuery();
connection.Close();
Console.WriteLine("Görev Silindi!");
Console.ReadKey();
}
#endregion
#region Görev Tamamlandı Yap
if (choice == 4)
{
Console.Write("Tamamlanacak Görev ID'si: ");
int id = int.Parse(Console.ReadLine());
connection.Open();
SqlCommand command = new SqlCommand("UPDATE TbsTask SET IsCompleted = 1 WHERE TaskId = @id", connection);
command.Parameters.AddWithValue("@id", id);
command.ExecuteNonQuery();
connection.Close();
Console.WriteLine("Görev tamamlandı olarak işaretlendi!");
Console.ReadKey();
}
#endregion
}
}
}
}