-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWindow1.xaml.cs
160 lines (139 loc) · 5.57 KB
/
Window1.xaml.cs
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
156
157
158
159
160
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
namespace Bomba
{
/// <summary>
/// Interaction logic for Window1.xaml
/// </summary>
public partial class Window1 : Window
{
static List<string> PrisijungimuKiekis = new List<string>();
string connectionString = (@"Data Source =DESKTOP-FGIOSI5\SQLEXPRESS; Initial Catalog = Bomba; Integrated Security=true");
public static Window1 instance;
public TextBlock User;
DataSet ds2 = new DataSet();
public Window1()
{
InitializeComponent();
instance = this;
User = usernamui;
DuomenuIeskojimas();
}
public void DuomenuIeskojimas()
{
using (SqlConnection FindingData = new SqlConnection(connectionString))
{
FindingData.Open();
SqlCommand cmd2 = new SqlCommand("SELECT COUNT(UserName) " +
"FROM tblBomba WHERE UserName ='asd'", FindingData);
//+ usernamui.Text +
//" + usernamui.Text +
//SqlDataAdapter da2 = new SqlDataAdapter(cmd2);
//da2.Fill(ds2);
//int k = ds2.Tables[0].Rows[0][0].ToString();
int row = cmd2.ExecuteNonQuery();
TavoPrisijungimai.Text = row.ToString();
// PrisijungimuKiekis.Add(k.ToString());
string path = @"C:\Users\Namai\OneDrive\Desktop\wpf\WpfApp3\ZaidimoRezultai.txt";
using (StreamWriter sw = new StreamWriter(path))
{
foreach (var s in PrisijungimuKiekis)
{
sw.Write($" {s}");
}
sw.Close();
}
}
}
private void Button_Click(object sender, RoutedEventArgs e)
{
Piano piano = new Piano();
piano.Show();
Piano.instance.vardas.Text = usernamui.Text;
if (Piano.instance.vardas.Text== string.Empty)
{
string prisijunkite = "Neprisijunges";
Piano.instance.vardas.Text = prisijunkite;
}
}
private void migtukas3_Click(object sender, RoutedEventArgs e)
{
using (SqlConnection userID = new SqlConnection(connectionString))
{
if (userID.State == System.Data.ConnectionState.Closed)
userID.Open();
string query = @"DELETE FROM tblUser WHERE UserName='" + usernamui.Text + "'";
SqlCommand cmd2 = new SqlCommand(query, userID);
int row = cmd2.ExecuteNonQuery();
if (row > 0)
{
MessageBox.Show("Logout succesfully", "My Box");
}
}
this.Close();
}
private void Bandom_Click(object sender, RoutedEventArgs e)
{
}
private void lOGOUT_Click(object sender, RoutedEventArgs e)
{
MessageBoxResult messageBoxResult = MessageBox.Show(usernamui.Text + " You Sure Want To Leave?", "My Box", MessageBoxButton.YesNoCancel);
switch (messageBoxResult)
{
case MessageBoxResult.No:
MessageBox.Show(usernamui.Text + " Pasirinkai Teisingai", "My Box");
break;
case MessageBoxResult.Cancel:
MessageBox.Show(usernamui.Text + " Pasirinkai Teisingai", "My Box");
break;
case MessageBoxResult.Yes:
MessageBox.Show(usernamui.Text + " Kaip Tu Dristi Palikti Mus?", "My Box");
using (SqlConnection userID = new SqlConnection(connectionString))
{
if (userID.State == System.Data.ConnectionState.Closed)
userID.Open();
string query = @"DELETE FROM tblUser WHERE UserName='" + usernamui.Text + "'";
SqlCommand cmd2 = new SqlCommand(query, userID);
int row = cmd2.ExecuteNonQuery();
if (row > 0)
{
MessageBox.Show("Logout succesfully", "My Box");
}
}
LoginScreen loginscreen = new LoginScreen();
loginscreen.Show();
loginscreen.Focus();
this.Close();
break;
}
}
private void Button_Click_1(object sender, RoutedEventArgs e)
{
Game game = new Game();
game.Show();
game.Focus();
Game.instanceGame.VardasPatvirtinimui.Text = usernamui.Text;
}
private void Button_Click_2(object sender, RoutedEventArgs e)
{
Virus virus = new Virus();
virus.Show();
virus.Focus();
//this.Close();
}
}
}